ProofEventProc.C

Go to the documentation of this file.
00001 #define ProofEventProc_cxx
00002 
00003 //////////////////////////////////////////////////////////
00004 //
00005 // Example of TSelector implementation to process trees
00006 // containing 'Event' structures, e.g. the files under
00007 // http://root.cern.ch/files/data .
00008 // See tutorials/proof/runProof.C, option "eventproc", for
00009 // an example of how to run this selector.
00010 //
00011 //////////////////////////////////////////////////////////
00012 
00013 #include "ProofEventProc.h"
00014 #include <TStyle.h>
00015 #include "TCanvas.h"
00016 #include "TPad.h"
00017 #include "TH1F.h"
00018 #include "TH2F.h"
00019 
00020 
00021 void ProofEventProc::Begin(TTree *)
00022 {
00023    // The Begin() function is called at the start of the query.
00024    // When running with PROOF Begin() is only called on the client.
00025    // The tree argument is deprecated (on PROOF 0 is passed).
00026 
00027    TString option = GetOption();
00028 
00029 }
00030 
00031 void ProofEventProc::SlaveBegin(TTree *tree)
00032 {
00033    // The SlaveBegin() function is called after the Begin() function.
00034    // When running with PROOF SlaveBegin() is called on each slave server.
00035    // The tree argument is deprecated (on PROOF 0 is passed).
00036 
00037    Init(tree);
00038 
00039    // How much to read
00040    fFullRead = kFALSE;
00041    TNamed *nm = 0;
00042    if (fInput) 
00043       nm = dynamic_cast<TNamed *>(fInput->FindObject("ProofEventProc_Read"));
00044    if (nm && !strcmp(nm->GetTitle(), "readall"))
00045       fFullRead = kTRUE;
00046    Info("SlaveBegin", "'%s' reading", (fFullRead ? "full" : "optimized"));
00047 
00048    TString option = GetOption();
00049 
00050    fPtHist = new TH1F("pt_dist","p_{T} Distribution",100,0,5);
00051    fPtHist->SetDirectory(0);
00052    fPtHist->GetXaxis()->SetTitle("p_{T}");
00053    fPtHist->GetYaxis()->SetTitle("dN/p_{T}dp_{T}");
00054 
00055    fOutput->Add(fPtHist);
00056 
00057    fPzHist = new TH1F("pz_dist","p_{Z} Distribution",100,0,5.);
00058    fPzHist->SetDirectory(0);
00059    fPzHist->GetXaxis()->SetTitle("p_{Z}");
00060    fPzHist->GetYaxis()->SetTitle("dN/dp_{Z}");
00061 
00062    fOutput->Add(fPzHist);
00063 
00064    fPxPyHist = new TH2F("px_py","p_{X} vs p_{Y} Distribution",100,-5.,5.,100,-5.,5.);
00065    fPxPyHist->SetDirectory(0);
00066    fPxPyHist->GetXaxis()->SetTitle("p_{X}");
00067    fPxPyHist->GetYaxis()->SetTitle("p_{Y}");
00068 
00069    fOutput->Add(fPxPyHist);
00070 
00071 }
00072 
00073 Bool_t ProofEventProc::Process(Long64_t entry)
00074 {
00075    // The Process() function is called for each entry in the tree (or possibly
00076    // keyed object in the case of PROOF) to be processed. The entry argument
00077    // specifies which entry in the currently loaded tree is to be processed.
00078    // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
00079    // to read either all or the required parts of the data. When processing
00080    // keyed objects with PROOF, the object is already loaded and is available
00081    // via the fObject pointer.
00082    //
00083    // This function should contain the "body" of the analysis. It can contain
00084    // simple or elaborate selection criteria, run algorithms on the data
00085    // of the event and typically fill histograms.
00086 
00087    // WARNING when a selector is used with a TChain, you must use
00088    //  the pointer to the current TTree to call GetEntry(entry).
00089    //  The entry is always the local entry number in the current tree.
00090    //  Assuming that fChain is the pointer to the TChain being processed,
00091    //  use fChain->GetTree()->GetEntry(entry).
00092 
00093    if (fFullRead) {
00094       fChain->GetTree()->GetEntry(entry);
00095    } else {
00096       b_event_fNtrack->GetEntry(entry);
00097    }
00098 
00099 
00100    if (fNtrack > 0) {
00101       if (!fFullRead) b_fTracks->GetEntry(entry);
00102       if (fTracks) {
00103          for (Int_t j=0;j<fTracks->GetEntries();j++){
00104             Track *curtrack = dynamic_cast<Track*>(fTracks->At(j));
00105             if (curtrack) {
00106                fPtHist->Fill(curtrack->GetPt(),1./curtrack->GetPt());
00107                fPxPyHist->Fill(curtrack->GetPx(),curtrack->GetPy());
00108                fPzHist->Fill(curtrack->GetPz());
00109             }
00110          }
00111          fTracks->Clear("C");
00112       }
00113    }
00114 
00115    return kTRUE;
00116 }
00117 
00118 void ProofEventProc::SlaveTerminate()
00119 {
00120    // The SlaveTerminate() function is called after all entries or objects
00121    // have been processed. When running with PROOF SlaveTerminate() is called
00122    // on each slave server.
00123 
00124 }
00125 
00126 void ProofEventProc::Terminate()
00127 {
00128    // The Terminate() function is the last function to be called during
00129    // a query. It always runs on the client, it can be used to present
00130    // the results graphically or save the results to file.
00131 
00132    TCanvas* canvas = new TCanvas("event","event",800,10,700,780);
00133    canvas->Divide(2,2);
00134    TPad *pad1 = (TPad *) canvas->GetPad(1);
00135    TPad *pad2 = (TPad *) canvas->GetPad(2);
00136    TPad *pad3 = (TPad *) canvas->GetPad(3);
00137    TPad *pad4 = (TPad *) canvas->GetPad(4);
00138 
00139    // The number of tracks
00140    pad1->cd();
00141    pad1->SetLogy();
00142    TH1F *hi = dynamic_cast<TH1F*>(fOutput->FindObject("pz_dist"));
00143    if (hi) {
00144       hi->SetFillColor(30);
00145       hi->SetLineColor(9);
00146       hi->SetLineWidth(2);
00147       hi->DrawCopy();
00148    } else { Warning("Terminate", "no pz dist found"); }
00149 
00150    // The Pt distribution
00151    pad2->cd();
00152    pad2->SetLogy();
00153    TH1F *hf = dynamic_cast<TH1F*>(fOutput->FindObject("pt_dist"));
00154    if (hf) {
00155       hf->SetFillColor(30);
00156       hf->SetLineColor(9);
00157       hf->SetLineWidth(2);
00158       hf->DrawCopy();
00159    } else { Warning("Terminate", "no pt dist found"); }
00160 
00161    // The Px,Py distribution, color surface
00162    TH2F *h2f = dynamic_cast<TH2F*>(fOutput->FindObject("px_py"));
00163    if (h2f) {
00164       // Color surface
00165       pad3->cd();
00166       h2f->DrawCopy("SURF1 ");
00167       // Lego
00168       pad4->cd();
00169       h2f->DrawCopy("CONT2COL");
00170    } else {
00171       Warning("Terminate", "no px py found");
00172    }
00173 
00174    // Final update
00175    canvas->cd();
00176    canvas->Update();
00177 }

Generated on Tue Jul 5 15:44:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1