#define AnalPersist_cxx // The class definition in AnalPersist.h has been generated automatically // by the ROOT utility TTree::MakeSelector(). // // This class is derived from the ROOT class TSelector. // The following members functions are called by the TTree::Process() functions: // Begin(): called everytime a loop on the tree starts, // a convenient place to create your histograms. // Notify(): this function is called at the first entry of a new Tree // in a chain. // Process(): called for each event. In this function you decide what // to read and you fill your histograms. // Terminate(): called at the end of a loop on the tree, // a convenient place to draw/fit your histograms. // // To use this file, try the following session on your Tree T // // Root > T->Process("AnalPersist.C") // Root > T->Process("AnalPersist.C","some options") // Root > T->Process("AnalPersist.C+") // #include "AnalPersist.h" #include "TH2.h" #include "TStyle.h" #include "TCanvas.h" void AnalPersist::Begin(TTree *tree) { // Function called before starting the event loop. // Initialize the tree branches. Init(tree); TString option = GetOption(); b__tp->SetB(50); new TH1F("h__a","A when IsOK",100,0.,100.); new TH1F("h__b","Value of B",100,0.,100.); } Bool_t AnalPersist::Process(Int_t entry) { // Processing function. This function is called // to process an event. It is the user's responsability to read // the corresponding entry in memory (may be just a partial read). // Once the entry is in memory one can apply a selection and if the // event is selected histograms can be filled. Processing stops // when this function returns kFALSE. This function combines the // next two functions in one, avoiding to have to maintain state // in the class to communicate between these two funtions. // You should not implement ProcessCut and ProcessFill if you write // this function. This method is used by PROOF. return kTRUE; } Bool_t AnalPersist::ProcessCut(Int_t entry) { // Selection function. // Entry is the entry number in the current tree. // Read only the necessary branches to select entries. // Return kFALSE as soon as a bad entry is detected. // To read complete event, call fChain->GetTree()->GetEntry(entry). return kTRUE; } void AnalPersist::ProcessFill(Int_t entry) { // Function called for selected entries only. // Entry is the entry number in the current tree. // Read branches not processed in ProcessCut() and fill histograms. // To read complete event, call fChain->GetTree()->GetEntry(entry). fChain->GetTree()->GetEntry(entry); TH1F *h = (TH1F*)gROOT->FindObject("h__a"); if(b__tp->IsOK()) h->Fill(b__tp->GetA()); h = (TH1F*)gROOT->FindObject("h__b"); h->Fill(b__tp->GetB()); } void AnalPersist::Terminate() { // Function called at the end of the event loop. TH1F *h = (TH1F*)gROOT->FindObject("h__a"); h->Draw(); gPad->Update(); new TCanvas("c","canvas 2"); h = (TH1F*)gROOT->FindObject("h__b"); h->Draw(); gPad->Update(); }