Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ProofEventProc.h
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_ProofEventProc
3///
4/// Selector to process trees containing Event structures
5///
6/// \macro_code
7///
8/// \author Gerardo Ganis (gerardo.ganis@cern.ch)
9
10#ifndef ProofEventProc_h
11#define ProofEventProc_h
12
13#include <TROOT.h>
14#include <TChain.h>
15#include <TFile.h>
16#include <TSelector.h>
17#include "Event.h"
18#include "ProcFileElements.h"
19
20class TH1F;
21class TH2F;
22
23class ProofEventProc : public TSelector {
24public :
25 TTree *fChain; //!pointer to the analyzed TTree or TChain
26
27 // Declaration of leave types
28 Event *event;
29 Char_t fType[20];
30 Char_t *fEventName;
31 Int_t fNtrack;
32 Int_t fNseg;
33 Int_t fNvertex;
34 UInt_t fFlag;
35 Double32_t fTemperature;
36 Int_t fMeasures[10];
37 Double32_t fMatrix[4][4];
38 Double32_t fClosestDistance[21]; //[fNvertex]
39 EventHeader fEvtHdr;
40 TClonesArray *fTracks;
41 TRefArray *fHighPt;
42 TRefArray *fMuons;
43 TRef fLastTrack;
44 TRef fWebHistogram;
45 TH1F *fH;
46 TBits fTriggerBits;
47 Bool_t fIsValid;
48 void InitEvent() { event = 0 ; fEventName = 0; fTracks = 0;
49 fHighPt = 0; fMuons = 0; fH = 0; fIsValid = kFALSE; }
50
51 // Read controller
52 Bool_t fFullRead;
53
54 // Abortion test
55 Int_t fTestAbort; // -1 none, 0 init, 1 file
56
57 // Event ranges
58 Long64_t fEntMin; // Min entry num of the current element
59 Long64_t fEntMax; // Max entry num of the current element
60 TList *fProcElems; // List of ProcFileElements processed so far
61 ProcFileElements *fProcElem; // Element currently processed
62 void CheckRanges();
63
64 //Output hist
65 TH1F* fPtHist;
66 TH1F* fPzHist;
67 TH2F* fPxPyHist;
68
69 // List of branches
70 TBranch *b_event_fType; //!
71 TBranch *b_fEventName; //!
72 TBranch *b_event_fNtrack; //!
73 TBranch *b_event_fNseg; //!
74 TBranch *b_event_fNvertex; //!
75 TBranch *b_event_fFlag; //!
76 TBranch *b_event_fTemperature; //!
77 TBranch *b_event_fMeasures; //!
78 TBranch *b_event_fMatrix; //!
79 TBranch *b_fClosestDistance; //!
80 TBranch *b_event_fEvtHdr; //!
81 TBranch *b_fTracks; //!
82 TBranch *b_fHighPt; //!
83 TBranch *b_fMuons; //!
84 TBranch *b_event_fLastTrack; //!
85 TBranch *b_event_fWebHistogram; //!
86 TBranch *b_fH; //!
87 TBranch *b_event_fTriggerBits; //!
88 TBranch *b_event_fIsValid; //!
89
90 ProofEventProc(TTree *) { InitEvent(); fFullRead = kTRUE; fTestAbort = -1;
91 fPtHist = 0; fPzHist = 0; fPxPyHist = 0;
92 fEntMin = -1; fEntMax = -1; fProcElems = 0; fProcElem = 0;}
93 ProofEventProc() { InitEvent(); fFullRead = kTRUE; fTestAbort = -1;
94 fPtHist = 0; fPzHist = 0; fPxPyHist = 0;
95 fEntMin = -1; fEntMax = -1; fProcElems = 0; fProcElem = 0;}
96 virtual ~ProofEventProc() {if (fProcElems) { fProcElems->SetOwner(kFALSE);
97 delete fProcElems;} }
98 virtual Int_t Version() const {return 2;}
99 virtual void Begin(TTree *);
100 virtual void SlaveBegin(TTree *tree);
101 virtual void Init(TTree *tree);
102 virtual Bool_t Notify();
103 virtual Bool_t Process(Long64_t entry);
104 virtual void SetOption(const char *option) { fOption = option; }
105 virtual void SetObject(TObject *obj) { fObject = obj; }
106 virtual void SetInputList(TList *input) {fInput = input;}
107 virtual TList *GetOutputList() const { return fOutput; }
108 virtual void SlaveTerminate();
109 virtual void Terminate();
110
111 ClassDef(ProofEventProc,0);
112};
113
114#endif
115
116#ifdef ProofEventProc_cxx
117void ProofEventProc::Init(TTree *tree)
118{
119 // The Init() function is called when the selector needs to initialize
120 // a new tree or chain. Typically here the branch addresses of the tree
121 // will be set. It is normaly not necessary to make changes to the
122 // generated code, but the routine can be extended by the user if needed.
123 // Init() will be called many times when running with PROOF.
124
125 // Set branch addresses
126 fEventName=0;
127 fTracks=0;
128 fHighPt=0;
129 fMuons=0;
130 fH=0;
131 if (tree == 0) return;
132 fChain = tree;
133 fChain->SetMakeClass(1);
134
135 fChain->SetBranchAddress("fType[20]",fType);
136 fChain->SetBranchAddress("fEventName",fEventName);
137 fChain->SetBranchAddress("fNtrack",&fNtrack);
138 fChain->SetBranchAddress("fNseg",&fNseg);
139 fChain->SetBranchAddress("fNvertex",&fNvertex);
140 fChain->SetBranchAddress("fFlag",&fFlag);
141 fChain->SetBranchAddress("fTemperature",&fTemperature);
142 fChain->SetBranchAddress("fMeasures[10]",fMeasures);
143 fChain->SetBranchAddress("fMatrix[4][4]",fMatrix);
144 fChain->SetBranchAddress("fClosestDistance",fClosestDistance);
145 fChain->SetBranchAddress("fEvtHdr",&fEvtHdr);
146 fChain->SetBranchAddress("fTracks",&fTracks);
147 fChain->SetBranchAddress("fHighPt",&fHighPt);
148 fChain->SetBranchAddress("fMuons",&fMuons);
149 fChain->SetBranchAddress("fLastTrack",&fLastTrack);
150 fChain->SetBranchAddress("fWebHistogram",&fWebHistogram);
151 fChain->SetBranchAddress("fH",&fH);
152 fChain->SetBranchAddress("fTriggerBits",&fTriggerBits);
153 fChain->SetBranchAddress("fIsValid",&fIsValid);
154}
155
156Bool_t ProofEventProc::Notify()
157{
158 // The Notify() function is called when a new file is opened. This
159 // can be either for a new TTree in a TChain or when when a new TTree
160 // is started when using PROOF. Typically here the branch pointers
161 // will be retrieved. It is normaly not necessary to make changes
162 // to the generated code, but the routine can be extended by the
163 // user if needed.
164
165 TString fn;
166 if (fChain) {
167 fn = fChain->GetCurrentFile()->GetName();
168 Info("Notify", "processing file: %s", fn.Data());
169 }
170
171 // Save information about previous element, if any
172 if (fProcElem) fProcElem->Add(fEntMin, fEntMax);
173
174 // Reset counters
175 fEntMin = -1;
176 fEntMax = -1;
177
178 // Point to current element
179 if (fProcElems) fProcElem = (ProcFileElements *) fProcElems->FindObject(fn);
180 if (!fProcElem) {
181 Info("Notify", "assigned new file: create ProcFileElements entry");
182 fProcElem = new ProcFileElements(fn.Data());
183 if (!fProcElems) fProcElems = new TList;
184 if (fProcElems) fProcElems->Add(fProcElem);
185 }
186
187 // Get branch pointers
188 b_event_fType = fChain->GetBranch("fType[20]");
189 b_fEventName = fChain->GetBranch("fEventName");
190 b_event_fNtrack = fChain->GetBranch("fNtrack");
191 b_event_fNseg = fChain->GetBranch("fNseg");
192 b_event_fNvertex = fChain->GetBranch("fNvertex");
193 b_event_fFlag = fChain->GetBranch("fFlag");
194 b_event_fTemperature = fChain->GetBranch("fTemperature");
195 b_event_fMeasures = fChain->GetBranch("fMeasures[10]");
196 b_event_fMatrix = fChain->GetBranch("fMatrix[4][4]");
197 b_fClosestDistance = fChain->GetBranch("fClosestDistance");
198 b_event_fEvtHdr = fChain->GetBranch("fEvtHdr");
199 b_fTracks = fChain->GetBranch("fTracks");
200 b_fHighPt = fChain->GetBranch("fHighPt");
201 b_fMuons = fChain->GetBranch("fMuons");
202 b_event_fLastTrack = fChain->GetBranch("fLastTrack");
203 b_event_fWebHistogram = fChain->GetBranch("fWebHistogram");
204 b_fH = fChain->GetBranch("fH");
205 b_event_fTriggerBits = fChain->GetBranch("fTriggerBits");
206 b_event_fIsValid = fChain->GetBranch("fIsValid");
207
208 return kTRUE;
209}
210
211#endif // #ifdef ProofEventProc_cxx
Class to hold information about the processed elements of a file.
double Double32_t
Definition RtypesCore.h:60
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
bool Bool_t
Definition RtypesCore.h:63
long long Long64_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:325
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:220
Container of bits.
Definition TBits.h:26
A TTree is a list of TBranches.
Definition TBranch.h:89
An array of clone (identical) objects.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:251
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
An array of references to TObjects.
Definition TRefArray.h:33
Persistent Reference link to a TObject A TRef is a lightweight object pointing to any TObject.
Definition TRef.h:32
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition TSelector.h:31
virtual void SetObject(TObject *obj)
Definition TSelector.h:65
virtual void Init(TTree *)
Definition TSelector.h:53
virtual int Version() const
Definition TSelector.h:52
TSelectorList * fOutput
! List of objects created during processing
Definition TSelector.h:42
virtual Bool_t Process(Long64_t)
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
virtual void SlaveBegin(TTree *)
Definition TSelector.h:55
virtual void SetOption(const char *option)
Definition TSelector.h:64
virtual void SetInputList(TList *input)
Definition TSelector.h:66
virtual TList * GetOutputList() const
Definition TSelector.h:69
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition TSelector.h:56
virtual void SlaveTerminate()
Definition TSelector.h:70
virtual void Begin(TTree *)
Definition TSelector.h:54
virtual void Terminate()
Definition TSelector.h:71
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5279
TFile * GetCurrentFile() const
Return pointer to the current file.
Definition TTree.cxx:5463
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8356
virtual void SetMakeClass(Int_t make)
Set all the branches in this TTree to be in decomposed object mode (also known as MakeClass mode).
Definition TTree.cxx:9143
Definition tree.py:1