////////////////////////////////////////////////////////// // This class has been automatically generated // (Fri Sep 26 09:48:38 2003 by ROOT version3.05/07) // from TTree t1/Tree with TestPersist objects // found on file: test_persist.root ////////////////////////////////////////////////////////// #ifndef AnalPersist_h #define AnalPersist_h #include #include #include #include #include "TestPersist.h" class AnalPersist : public TSelector { public : TTree *fChain; //!pointer to the analyzed TTree or TChain //Declaration of leaves types TestPersist *b__tp; //List of branches TBranch *b_b__tp; //! AnalPersist(TTree *tree=0) { } ~AnalPersist() { } void Begin(TTree *tree); void Init(TTree *tree); Bool_t Notify(); Bool_t Process(Int_t entry); Bool_t ProcessCut(Int_t entry); void ProcessFill(Int_t entry); void SetOption(const char *option) { fOption = option; } void SetObject(TObject *obj) { fObject = obj; } void SetInputList(TList *input) {fInput = input;} TList *GetOutputList() const { return fOutput; } void Terminate(); ClassDef(AnalPersist,0); }; #endif #ifdef AnalPersist_cxx void AnalPersist::Init(TTree *tree) { // Set object pointer b__tp = 0; // Set branch addresses if (tree == 0) return; fChain = tree; fChain->SetMakeClass(1); fChain->SetBranchAddress("b__tp",&b__tp); } Bool_t AnalPersist::Notify() { // Called when loading a new file. // Get branch pointers. b_b__tp = fChain->GetBranch("b__tp"); return kTRUE; } #endif // #ifdef AnalPersist_cxx #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(); }