00001 #define EventTree_Proc_cxx 00002 // The class definition in EventTree_Proc.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_Proc.C") 00022 // Root > T->Process("EventTree_Proc.C","some options") 00023 // Root > T->Process("EventTree_Proc.C+") 00024 // 00025 00026 #include "EventTree_Proc.h" 00027 #include <TH2.h> 00028 #include <TStyle.h> 00029 #include "TCanvas.h" 00030 00031 00032 void EventTree_Proc::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_Proc::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 00068 Bool_t EventTree_Proc::Process(Long64_t entry) 00069 { 00070 // The Process() function is called for each entry in the tree (or possibly 00071 // keyed object in the case of PROOF) to be processed. The entry argument 00072 // specifies which entry in the currently loaded tree is to be processed. 00073 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry() 00074 // to read either all or the required parts of the data. When processing 00075 // keyed objects with PROOF, the object is already loaded and is available 00076 // via the fObject pointer. 00077 // 00078 // This function should contain the "body" of the analysis. It can contain 00079 // simple or elaborate selection criteria, run algorithms on the data 00080 // of the event and typically fill histograms. 00081 00082 // WARNING when a selector is used with a TChain, you must use 00083 // the pointer to the current TTree to call GetEntry(entry). 00084 // The entry is always the local entry number in the current tree. 00085 // Assuming that fChain is the pointer to the TChain being processed, 00086 // use fChain->GetTree()->GetEntry(entry). 00087 00088 fChain->GetTree()->GetEntry(entry); 00089 00090 fNTracksHist->Fill(fNtrack); 00091 00092 for(Int_t j=0;j<fTracks->GetEntries();j++){ 00093 Track* curtrack = dynamic_cast<Track*>(fTracks->At(j)); 00094 fPtHist->Fill(curtrack->GetPt(),1./curtrack->GetPt()); 00095 } 00096 fTracks->Clear("C"); 00097 00098 return kTRUE; 00099 } 00100 00101 void EventTree_Proc::SlaveTerminate() 00102 { 00103 // The SlaveTerminate() function is called after all entries or objects 00104 // have been processed. When running with PROOF SlaveTerminate() is called 00105 // on each slave server. 00106 00107 } 00108 00109 void EventTree_Proc::Terminate() 00110 { 00111 // The Terminate() function is the last function to be called during 00112 // a query. It always runs on the client, it can be used to present 00113 // the results graphically or save the results to file. 00114 00115 TCanvas* canvas = new TCanvas("can","can",800,600); 00116 canvas->SetBorderMode(0); 00117 canvas->SetLogy(); 00118 TH1F* h = dynamic_cast<TH1F*>(fOutput->FindObject("pt_dist")); 00119 if (h) h->DrawCopy(); 00120 else Warning("Terminate", "no pt dist found"); 00121 00122 }