ProofFriends.C

Go to the documentation of this file.
00001 #define ProofFriends_cxx
00002 // The class definition in ProofFriends.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 every time 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("ProofFriends.C")
00022 // Root > T->Process("ProofFriends.C","some options")
00023 // Root > T->Process("ProofFriends.C+")
00024 //
00025 
00026 #include "ProofFriends.h"
00027 #include "TCanvas.h"
00028 #include "TColor.h"
00029 #include "TH1F.h"
00030 #include "TH2F.h"
00031 #include "TList.h"
00032 #include "TMath.h"
00033 #include "TString.h"
00034 #include "TStyle.h"
00035 
00036 //_____________________________________________________________________________
00037 ProofFriends::ProofFriends()
00038 {
00039    // Constructor
00040 
00041    fXY = 0;
00042    fZ = 0;
00043    fR = 0;
00044    fRZ = 0;
00045 }
00046 
00047 void ProofFriends::Begin(TTree * /*tree*/)
00048 {
00049    // The Begin() function is called at the start of the query.
00050    // When running with PROOF Begin() is only called on the client.
00051    // The tree argument is deprecated (on PROOF 0 is passed).
00052 
00053    TString option = GetOption();
00054 
00055 }
00056 
00057 void ProofFriends::SlaveBegin(TTree * /*tree*/)
00058 {
00059    // The SlaveBegin() function is called after the Begin() function.
00060    // When running with PROOF SlaveBegin() is called on each slave server.
00061    // The tree argument is deprecated (on PROOF 0 is passed).
00062 
00063    TString option = GetOption();
00064 
00065    // Histograms
00066    fXY = new TH2F("histo1", "y:x", 50, 5., 15., 50, 10., 30.);
00067    fZ = new TH1F("histo2", "z , sqrt(dx*dx+dy*dy) < 1", 50, 0., 5.);
00068    fR = new TH1F("histo3", "Tfrnd.r , sqrt(dx*dx+dy*dy) < 1, z < 1", 50, 5., 15.);
00069    fRZ = new TH2F("histo4", "Tfrnd.r:z , sqrt(dx*dx+dy*dy) < 1, z < 1", 50, 0., 1., 50, 5., 15.);
00070    fZ->SetFillColor(kBlue);
00071    fR->SetFillColor(kRed);
00072    fOutput->Add(fXY);
00073    fOutput->Add(fZ);
00074    fOutput->Add(fR);
00075    fOutput->Add(fRZ);
00076 
00077 }
00078 
00079 Bool_t ProofFriends::Process(Long64_t entry)
00080 {
00081    // The Process() function is called for each entry in the tree (or possibly
00082    // keyed object in the case of PROOF) to be processed. The entry argument
00083    // specifies which entry in the currently loaded tree is to be processed.
00084    // It can be passed to either ProofFriends::GetEntry() or TBranch::GetEntry()
00085    // to read either all or the required parts of the data. When processing
00086    // keyed objects with PROOF, the object is already loaded and is available
00087    // via the fObject pointer.
00088    //
00089    // This function should contain the "body" of the analysis. It can contain
00090    // simple or elaborate selection criteria, run algorithms on the data
00091    // of the event and typically fill histograms.
00092    //
00093    // The processing can be stopped by calling Abort().
00094    //
00095    // Use fStatus to set the return value of TTree::Process().
00096    //
00097    // The return value is currently not used.
00098 
00099    // Read x and y, fill and apply cut
00100    b_x->GetEntry(entry);
00101    b_y->GetEntry(entry);
00102    fXY->Fill(x, y, 1.);
00103    Double_t dx = x-10.;
00104    Double_t dy = y-20.;
00105    Double_t xpy = TMath::Sqrt(dx*dx + dy*dy);
00106    if (xpy > 1.) return kFALSE;
00107 
00108    // Read z, fill and apply cut
00109    b_z->GetEntry(entry);
00110    fZ->Fill(z, 1.);
00111    if (z > 1.) return kFALSE;
00112 
00113    // Read r and fill
00114    b_r->GetEntry(entry);
00115    fR->Fill(r, 1.);
00116    fRZ->Fill(z, r, 1.);
00117 
00118    return kTRUE;
00119 }
00120 
00121 void ProofFriends::SlaveTerminate()
00122 {
00123    // The SlaveTerminate() function is called after all entries or objects
00124    // have been processed. When running with PROOF SlaveTerminate() is called
00125    // on each slave server.
00126 
00127 }
00128 
00129 void ProofFriends::Terminate()
00130 {
00131    // The Terminate() function is the last function to be called during
00132    // a query. It always runs on the client, it can be used to present
00133    // the results graphically or save the results to file.
00134 
00135    gStyle->SetOptStat(1110);
00136    // Create canvas
00137    TCanvas *c1 = new TCanvas("c1","Proof ProofFriends canvas",200,10,700,700);
00138    // Overall background
00139    Int_t cb = TColor::GetColor("#ccffff");
00140    c1->SetFillColor(cb);
00141    c1->SetBorderMode(0);
00142    // 4 pads
00143    c1->Divide(2, 2);
00144 
00145    Int_t cf = TColor::GetColor("#99cccc");
00146    TPad *p1 = 0;
00147    if ((fXY = dynamic_cast<TH2F *>(fOutput->FindObject("histo1")))) {
00148       p1 = (TPad *) c1->cd(1);
00149       p1->SetBorderMode(0);
00150       p1->SetFrameFillColor(cf);
00151       fXY->GetXaxis()->SetTitle("x");
00152       fXY->GetYaxis()->SetTitle("y");
00153       fXY->Draw("");
00154    }
00155 
00156    if ((fZ = dynamic_cast<TH1F *>(fOutput->FindObject("histo2")))) {
00157       p1 = (TPad *) c1->cd(2);
00158       p1->SetBorderMode(0);
00159       p1->SetFrameFillColor(cf);
00160       fZ->GetXaxis()->SetTitle("z");
00161       fZ->GetYaxis()->SetTitle("N / 0.1");
00162       fZ->Draw("");
00163    }
00164 
00165    if ((fR = dynamic_cast<TH1F *>(fOutput->FindObject("histo3")))) {
00166       p1 = (TPad *) c1->cd(3);
00167       p1->SetBorderMode(0);
00168       p1->SetFrameFillColor(cf);
00169       fR->GetXaxis()->SetTitle("Tfrnd.r");
00170       fR->GetYaxis()->SetTitle("N / 0.2");
00171       fR->Draw();
00172    }
00173 
00174    if ((fRZ = dynamic_cast<TH2F *>(fOutput->FindObject("histo4")))) {
00175       p1 = (TPad *) c1->cd(4);
00176       p1->SetBorderMode(0);
00177       p1->SetFrameFillColor(cf);
00178       fRZ->GetXaxis()->SetTitle("z");
00179       fRZ->GetXaxis()->CenterTitle(1);
00180       fRZ->GetXaxis()->SetTitleOffset(1.5);
00181       fRZ->GetYaxis()->SetTitle("Tfrnd.r");
00182       fRZ->GetYaxis()->CenterTitle(1);
00183       fRZ->GetYaxis()->SetTitleOffset(1.75);
00184       fRZ->GetZaxis()->SetTitle("N / 0.1 / 0.2");
00185       fRZ->GetZaxis()->SetTitleOffset(1.25);
00186       fRZ->Draw("lego");
00187    }
00188 
00189    // Final update
00190    c1->cd();
00191    c1->Update();
00192 
00193 }

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