00001 #define EventTree_ProcOpt_cxx 00002 // The class definition in EventTree_ProcOpt.h has been generated automatically 00003 // by the ROOT utility TTree::MakeSelector(). This class is derived 00004 // from the ROOT class TSelector. For more information on the TSelector 00005 // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual. 00006 00007 // The following methods are defined in this file: 00008 // Begin(): called everytime a loop on the tree starts, 00009 // a convenient place to create your histograms. 00010 // SlaveBegin(): called after Begin(), when on PROOF called only on the 00011 // slave servers. 00012 // Process(): called for each event, in this function you decide what 00013 // to read and fill your histograms. 00014 // SlaveTerminate: called at the end of the loop on the tree, when on PROOF 00015 // called only on the slave servers. 00016 // Terminate(): called at the end of the loop on the tree, 00017 // a convenient place to draw/fit your histograms. 00018 // 00019 // To use this file, try the following session on your Tree T: 00020 // 00021 // Root > T->Process("EventTree_ProcOpt.C") 00022 // Root > T->Process("EventTree_ProcOpt.C","some options") 00023 // Root > T->Process("EventTree_ProcOpt.C+") 00024 // 00025 00026 #include "EventTree_ProcOpt.h" 00027 #include <TH2.h> 00028 #include <TStyle.h> 00029 #include "TCanvas.h" 00030 00031 00032 void EventTree_ProcOpt::Begin(TTree *) 00033 { 00034 // The Begin() function is called at the start of the query. 00035 // When running with PROOF Begin() is only called on the client. 00036 // The tree argument is deprecated (on PROOF 0 is passed). 00037 00038 TString option = GetOption(); 00039 00040 } 00041 00042 void EventTree_ProcOpt::SlaveBegin(TTree *tree) 00043 { 00044 // The SlaveBegin() function is called after the Begin() function. 00045 // When running with PROOF SlaveBegin() is called on each slave server. 00046 // The tree argument is deprecated (on PROOF 0 is passed). 00047 00048 Init(tree); 00049 00050 TString option = GetOption(); 00051 00052 fPtHist = new TH1F("pt_dist","p_{T} Distribution",100,0,5); 00053 fPtHist->SetDirectory(0); 00054 fPtHist->GetXaxis()->SetTitle("p_{T}"); 00055 fPtHist->GetYaxis()->SetTitle("dN/p_{T}dp_{T}"); 00056 00057 fOutput->Add(fPtHist); 00058 00059 fNTracksHist = new TH1I("ntracks_dist","N_{Tracks} per Event Distribution",5,0,5); 00060 fNTracksHist->SetDirectory(0); 00061 fNTracksHist->GetXaxis()->SetTitle("N_{Tracks}"); 00062 fNTracksHist->GetYaxis()->SetTitle("N_{Events}"); 00063 00064 fOutput->Add(fNTracksHist); 00065 } 00066 00067 Bool_t EventTree_ProcOpt::Process(Long64_t entry) 00068 { 00069 // The Process() function is called for each entry in the tree (or possibly 00070 // keyed object in the case of PROOF) to be processed. The entry argument 00071 // specifies which entry in the currently loaded tree is to be processed. 00072 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry() 00073 // to read either all or the required parts of the data. When processing 00074 // keyed objects with PROOF, the object is already loaded and is available 00075 // via the fObject pointer. 00076 // 00077 // This function should contain the "body" of the analysis. It can contain 00078 // simple or elaborate selection criteria, run algorithms on the data 00079 // of the event and typically fill histograms. 00080 00081 // WARNING when a selector is used with a TChain, you must use 00082 // the pointer to the current TTree to call GetEntry(entry). 00083 // The entry is always the local entry number in the current tree. 00084 // Assuming that fChain is the pointer to the TChain being processed, 00085 // use fChain->GetTree()->GetEntry(entry). 00086 00087 b_event_fNtrack->GetEntry(entry); 00088 00089 fNTracksHist->Fill(fNtrack); 00090 00091 if (fNtrack>0) { 00092 b_fTracks->GetEntry(entry); 00093 for(Int_t j=0;j<fTracks->GetEntries();j++){ 00094 Track* curtrack = dynamic_cast<Track*>(fTracks->At(j)); 00095 fPtHist->Fill(curtrack->GetPt(),1./curtrack->GetPt()); 00096 } 00097 fTracks->Clear("C"); 00098 } 00099 00100 return kTRUE; 00101 } 00102 00103 void EventTree_ProcOpt::SlaveTerminate() 00104 { 00105 // The SlaveTerminate() function is called after all entries or objects 00106 // have been processed. When running with PROOF SlaveTerminate() is called 00107 // on each slave server. 00108 00109 } 00110 00111 void EventTree_ProcOpt::Terminate() 00112 { 00113 // The Terminate() function is the last function to be called during 00114 // a query. It always runs on the client, it can be used to present 00115 // the results graphically or save the results to file. 00116 00117 TCanvas* canvas = new TCanvas("can","can",800,600); 00118 canvas->SetBorderMode(0); 00119 canvas->SetLogy(); 00120 TH1F* h = dynamic_cast<TH1F*>(fOutput->FindObject("pt_dist")); 00121 if (h) h->DrawCopy(); 00122 else Warning("Terminate", "no pt dist found"); 00123 00124 }