ProofSimple.C

Go to the documentation of this file.
00001 #define ProofSimple_cxx
00002 //////////////////////////////////////////////////////////
00003 //
00004 // Example of TSelector implementation to do generic
00005 // processing (filling a set of histograms in this case).
00006 // See tutorials/proof/runProof.C, option "simple", for an
00007 // example of how to run this selector.
00008 //
00009 //////////////////////////////////////////////////////////
00010 
00011 #include "ProofSimple.h"
00012 #include <TCanvas.h>
00013 #include <TFrame.h>
00014 #include <TPaveText.h>
00015 #include <TFormula.h>
00016 #include <TF1.h>
00017 #include <TH1F.h>
00018 #include <TMath.h>
00019 #include <TRandom3.h>
00020 #include <TString.h>
00021 #include <TStyle.h>
00022 #include <TSystem.h>
00023 #include <TParameter.h>
00024 
00025 //_____________________________________________________________________________
00026 ProofSimple::ProofSimple()
00027 {
00028    // Constructor
00029 
00030    fNhist = -1;
00031    fHist = 0;
00032    fRandom = 0;
00033 }
00034 
00035 //_____________________________________________________________________________
00036 ProofSimple::~ProofSimple()
00037 {
00038    // Destructor
00039 
00040    if (fRandom) delete fRandom;
00041 }
00042 
00043 //_____________________________________________________________________________
00044 void ProofSimple::Begin(TTree * /*tree*/)
00045 {
00046    // The Begin() function is called at the start of the query.
00047    // When running with PROOF Begin() is only called on the client.
00048    // The tree argument is deprecated (on PROOF 0 is passed).
00049 
00050    TString option = GetOption();
00051 
00052    // Histos array
00053    fNhist = 100;
00054    if (fInput->FindObject("ProofSimple_NHist")) {
00055       TParameter<Long_t> *p =
00056          dynamic_cast<TParameter<Long_t>*>(fInput->FindObject("ProofSimple_NHist"));
00057       fNhist = (p) ? (Int_t) p->GetVal() : fNhist;
00058    }
00059    fHist = new TH1F*[fNhist];
00060 }
00061 
00062 //_____________________________________________________________________________
00063 void ProofSimple::SlaveBegin(TTree * /*tree*/)
00064 {
00065    // The SlaveBegin() function is called after the Begin() function.
00066    // When running with PROOF SlaveBegin() is called on each slave server.
00067    // The tree argument is deprecated (on PROOF 0 is passed).
00068 
00069    TString option = GetOption();
00070 
00071    // Histos array
00072    fNhist = 100;
00073    if (fInput->FindObject("ProofSimple_NHist")) {
00074       TParameter<Long_t> *p =
00075          dynamic_cast<TParameter<Long_t>*>(fInput->FindObject("ProofSimple_NHist"));
00076       fNhist = (p) ? (Int_t) p->GetVal() : fNhist;
00077    }
00078    fHist = new TH1F*[fNhist];
00079 
00080    // Create the histogram
00081    for (Int_t i=0; i < fNhist; i++) {
00082       fHist[i] = new TH1F(Form("h%d",i), Form("h%d",i), 100, -3., 3.);
00083       fHist[i]->SetFillColor(kRed);
00084       fOutput->Add(fHist[i]);
00085    }
00086 
00087    // Set random seed
00088    fRandom = new TRandom3(0);
00089 }
00090 
00091 //_____________________________________________________________________________
00092 Bool_t ProofSimple::Process(Long64_t)
00093 {
00094    // The Process() function is called for each entry in the tree (or possibly
00095    // keyed object in the case of PROOF) to be processed. The entry argument
00096    // specifies which entry in the currently loaded tree is to be processed.
00097    // It can be passed to either ProofSimple::GetEntry() or TBranch::GetEntry()
00098    // to read either all or the required parts of the data. When processing
00099    // keyed objects with PROOF, the object is already loaded and is available
00100    // via the fObject pointer.
00101    //
00102    // This function should contain the "body" of the analysis. It can contain
00103    // simple or elaborate selection criteria, run algorithms on the data
00104    // of the event and typically fill histograms.
00105    //
00106    // The processing can be stopped by calling Abort().
00107    //
00108    // Use fStatus to set the return value of TTree::Process().
00109    //
00110    // The return value is currently not used.
00111 
00112    for (Int_t i=0; i < fNhist; i++) {
00113       if (fRandom && fHist[i]) {
00114          Double_t x = fRandom->Gaus(0.,1.);
00115          fHist[i]->Fill(x);
00116       }
00117    }
00118 
00119    return kTRUE;
00120 }
00121 
00122 //_____________________________________________________________________________
00123 void ProofSimple::SlaveTerminate()
00124 {
00125    // The SlaveTerminate() function is called after all entries or objects
00126    // have been processed. When running with PROOF SlaveTerminate() is called
00127    // on each slave server.
00128 
00129 }
00130 
00131 //_____________________________________________________________________________
00132 void ProofSimple::Terminate()
00133 {
00134    // The Terminate() function is the last function to be called during
00135    // a query. It always runs on the client, it can be used to present
00136    // the results graphically or save the results to file.
00137 
00138    //
00139    // Create a canvas, with 100 pads
00140    //
00141    TCanvas *c1 = new TCanvas("c1","Proof ProofSimple canvas",200,10,700,700);
00142    Int_t nside = (Int_t)TMath::Sqrt((Float_t)fNhist);
00143    nside = (nside*nside < fNhist) ? nside+1 : nside;
00144    c1->Divide(nside,nside,0,0);
00145 
00146    for (Int_t i=0; i < fNhist; i++) {
00147       fHist[i] = dynamic_cast<TH1F *>(fOutput->FindObject(Form("h%d",i)));
00148       c1->cd(i+1);
00149       if (fHist[i])
00150          fHist[i]->Draw();
00151    }
00152 
00153    // Final update
00154    c1->cd();
00155    c1->Update();
00156 }

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