]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/RecAna.h
Using dinamic array for times of flight
[u/mrichter/AliRoot.git] / PHOS / RecAna.h
1 //////////////////////////////////////////////////////////
2 //  A Demo Macro that shows how to analyze the 
3 //  reconstructed Tree
4 //
5 //  Y. Schutz (SUBATECH)
6 //////////////////////////////////////////////////////////
7
8
9 #ifndef RecAna_h
10 #define RecAna_h
11
12 #if !defined(__CINT__) || defined(__MAKECINT__)
13 #include <TTree.h>
14 #include <TFile.h>
15 #endif
16
17 const Int_t kMaxPHOSTS = 9;
18 const Int_t kMaxPHOSRP = 9;
19
20 class RecAna {
21   public:
22   AliPHOSv0 * fPHOS ; 
23   TTree          *fTree;    //pointer to the analyzed TTree or TChain
24   TTree          *fCurrent; //pointer to the current TTree
25   //Declaration of leaves types
26   TObjArray       *PHOSEmcRP;
27   TObjArray       *PHOSPpsdRP;
28   Int_t           PHOSTS_;
29   Int_t           PHOSTS_fEmcRecPoint[kMaxPHOSTS];
30   Int_t           PHOSTS_fPpsdLowRecPoint[kMaxPHOSTS];
31   Int_t           PHOSTS_fPpsdUpRecPoint[kMaxPHOSTS];
32   UInt_t          PHOSTS_fUniqueID[kMaxPHOSTS];
33   UInt_t          PHOSTS_fBits[kMaxPHOSTS];
34   Int_t           PHOSRP_;
35   Int_t           PHOSRP_fPHOSTrackSegment[kMaxPHOSRP];
36   Int_t           PHOSRP_fIndexInList[kMaxPHOSRP];
37   Int_t           PHOSRP_fPrimary[kMaxPHOSRP];
38   Int_t           PHOSRP_fType[kMaxPHOSRP];
39   Int_t           PHOSRP_fPdgCode[kMaxPHOSRP];
40   Int_t           PHOSRP_fStatusCode[kMaxPHOSRP];
41   Int_t           PHOSRP_fMother[2][kMaxPHOSRP];
42   Int_t           PHOSRP_fDaughter[2][kMaxPHOSRP];
43   Float_t         PHOSRP_fWeight[kMaxPHOSRP];
44   Double_t        PHOSRP_fCalcMass[kMaxPHOSRP];
45   Double_t        PHOSRP_fPx[kMaxPHOSRP];
46   Double_t        PHOSRP_fPy[kMaxPHOSRP];
47   Double_t        PHOSRP_fPz[kMaxPHOSRP];
48   Double_t        PHOSRP_fE[kMaxPHOSRP];
49   Double_t        PHOSRP_fVx[kMaxPHOSRP];
50   Double_t        PHOSRP_fVy[kMaxPHOSRP];
51   Double_t        PHOSRP_fVz[kMaxPHOSRP];
52   Double_t        PHOSRP_fVt[kMaxPHOSRP];
53   Double_t        PHOSRP_fPolarTheta[kMaxPHOSRP];
54   Double_t        PHOSRP_fPolarPhi[kMaxPHOSRP];
55   UInt_t          PHOSRP_fUniqueID[kMaxPHOSRP];
56   UInt_t          PHOSRP_fBits[kMaxPHOSRP];
57   Short_t         PHOSRP_fLineColor[kMaxPHOSRP];
58   Short_t         PHOSRP_fLineStyle[kMaxPHOSRP];
59   Short_t         PHOSRP_fLineWidth[kMaxPHOSRP];
60   
61   //List of branches
62   TBranch        *b_PHOSEmcRP;
63   TBranch        *b_PHOSPpsdRP;
64   TBranch        *b_PHOSTS_;
65   TBranch        *b_PHOSTS_fEmcRecPoint;
66   TBranch        *b_PHOSTS_fPpsdLowRecPoint;
67   TBranch        *b_PHOSTS_fPpsdUpRecPoint;
68   TBranch        *b_PHOSTS_fUniqueID;
69   TBranch        *b_PHOSTS_fBits;
70   TBranch        *b_PHOSRP_;
71   TBranch        *b_PHOSRP_fPHOSTrackSegment;
72   TBranch        *b_PHOSRP_fIndexInList;
73   TBranch        *b_PHOSRP_fPrimary;
74   TBranch        *b_PHOSRP_fType;
75   TBranch        *b_PHOSRP_fPdgCode;
76   TBranch        *b_PHOSRP_fStatusCode;
77   TBranch        *b_PHOSRP_fMother;
78   TBranch        *b_PHOSRP_fDaughter;
79   TBranch        *b_PHOSRP_fWeight;
80   TBranch        *b_PHOSRP_fCalcMass;
81   TBranch        *b_PHOSRP_fPx;
82   TBranch        *b_PHOSRP_fPy;
83   TBranch        *b_PHOSRP_fPz;
84   TBranch        *b_PHOSRP_fE;
85   TBranch        *b_PHOSRP_fVx;
86   TBranch        *b_PHOSRP_fVy;
87   TBranch        *b_PHOSRP_fVz;
88   TBranch        *b_PHOSRP_fVt;
89   TBranch        *b_PHOSRP_fPolarTheta;
90   TBranch        *b_PHOSRP_fPolarPhi;
91   TBranch        *b_PHOSRP_fUniqueID;
92   TBranch        *b_PHOSRP_fBits;
93   TBranch        *b_PHOSRP_fLineColor;
94   TBranch        *b_PHOSRP_fLineStyle;
95   TBranch        *b_PHOSRP_fLineWidth;
96   
97   RecAna() {};
98   RecAna(char * filename);
99   RecAna(TTree *tree) {};
100   ~RecAna() {;}
101   Int_t GetEntry(Int_t entry = 0);
102   Int_t GetEvent(Int_t evt);
103   Int_t LoadTree(Int_t entry = 0);
104   void  Init(TTree *tree);
105   void  Loop();
106   void  Notify();
107   void  Show(Int_t entry = -1);
108 };
109
110 #endif
111
112 #ifdef RecAna_cxx
113 RecAna::RecAna(char * filename)
114 {
115   // connect the file used to generate this class and read the Tree.
116   
117   TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
118   if (!f) 
119     f = new TFile(filename);
120   
121   // setup the gAlice evironment
122   
123   gAlice = (AliRun*) f->Get("gAlice") ;   
124   
125   // get the PHOS detectector, the geometry instance and the index to object converter instance
126   
127   fPHOS  = (AliPHOSv0 *)gAlice->GetDetector("PHOS") ;     
128   AliPHOSGeometry::GetInstance( fPHOS->GetGeometry()->GetName(), fPHOS->GetGeometry()->GetTitle() );
129   AliPHOSIndexToObject::GetInstance(fPHOS) ;
130 }
131
132 Int_t RecAna::GetEntry(Int_t entry)
133 {
134   // Read contents of entry, always = 0.
135   
136   if (!fTree) 
137     return 0;
138   
139   return fTree->GetEntry(entry);
140 }
141
142 Int_t RecAna::GetEvent(Int_t evt)
143 {
144   // get the selected event
145   
146   gAlice->GetEvent(evt);
147   
148   // connect to the Reconstruction tree
149   
150   fTree = gAlice->TreeR();     
151   
152   // set the branches 
153   
154   Init(fTree);
155   
156   // gets the data
157   
158   GetEntry(0); 
159   cout << "macro EmcRecpoints = " << fPHOS->EmcRecPoints() << endl ; 
160 }
161
162 Int_t RecAna::LoadTree(Int_t entry)
163 {
164   // Set the environment to read one entry, always = 0.
165   
166   if (!fTree) 
167     return -5;
168   Int_t centry = fTree->LoadTree(entry);
169   if (centry < 0) 
170     return centry;
171   if (fTree->GetTree() != fCurrent) {
172     fCurrent = fTree->GetTree();
173     Notify();
174   }
175   return centry;
176 }
177
178 void RecAna::Init(TTree *tree)
179 {
180   //   Set branch addresses
181   if (tree == 0) return;
182   fTree    = tree;
183   fCurrent = 0;
184   
185   fTree->SetBranchAddress("PHOSEmcRP",&PHOSEmcRP);
186   fTree->SetBranchAddress("PHOSPpsdRP",&PHOSPpsdRP);
187   fTree->SetBranchAddress("PHOSTS_",&PHOSTS_);
188   fTree->SetBranchAddress("PHOSTS.fEmcRecPoint",PHOSTS_fEmcRecPoint);
189   fTree->SetBranchAddress("PHOSTS.fPpsdLowRecPoint",PHOSTS_fPpsdLowRecPoint);
190   fTree->SetBranchAddress("PHOSTS.fPpsdUpRecPoint",PHOSTS_fPpsdUpRecPoint);
191   fTree->SetBranchAddress("PHOSTS.fUniqueID",PHOSTS_fUniqueID);
192   fTree->SetBranchAddress("PHOSTS.fBits",PHOSTS_fBits);
193   fTree->SetBranchAddress("PHOSRP_",&PHOSRP_);
194   fTree->SetBranchAddress("PHOSRP.fPHOSTrackSegment",PHOSRP_fPHOSTrackSegment);
195   fTree->SetBranchAddress("PHOSRP.fIndexInList",PHOSRP_fIndexInList);
196   fTree->SetBranchAddress("PHOSRP.fPrimary",PHOSRP_fPrimary);
197   fTree->SetBranchAddress("PHOSRP.fType",PHOSRP_fType);
198   fTree->SetBranchAddress("PHOSRP.fPdgCode",PHOSRP_fPdgCode);
199   fTree->SetBranchAddress("PHOSRP.fStatusCode",PHOSRP_fStatusCode);
200   fTree->SetBranchAddress("PHOSRP.fMother[2]",PHOSRP_fMother);
201   fTree->SetBranchAddress("PHOSRP.fDaughter[2]",PHOSRP_fDaughter);
202   fTree->SetBranchAddress("PHOSRP.fWeight",PHOSRP_fWeight);
203   fTree->SetBranchAddress("PHOSRP.fCalcMass",PHOSRP_fCalcMass);
204   fTree->SetBranchAddress("PHOSRP.fPx",PHOSRP_fPx);
205   fTree->SetBranchAddress("PHOSRP.fPy",PHOSRP_fPy);
206   fTree->SetBranchAddress("PHOSRP.fPz",PHOSRP_fPz);
207   fTree->SetBranchAddress("PHOSRP.fE",PHOSRP_fE);
208   fTree->SetBranchAddress("PHOSRP.fVx",PHOSRP_fVx);
209   fTree->SetBranchAddress("PHOSRP.fVy",PHOSRP_fVy);
210   fTree->SetBranchAddress("PHOSRP.fVz",PHOSRP_fVz);
211   fTree->SetBranchAddress("PHOSRP.fVt",PHOSRP_fVt);
212   fTree->SetBranchAddress("PHOSRP.fPolarTheta",PHOSRP_fPolarTheta);
213   fTree->SetBranchAddress("PHOSRP.fPolarPhi",PHOSRP_fPolarPhi);
214   fTree->SetBranchAddress("PHOSRP.fUniqueID",PHOSRP_fUniqueID);
215   fTree->SetBranchAddress("PHOSRP.fBits",PHOSRP_fBits);
216   fTree->SetBranchAddress("PHOSRP.fLineColor",PHOSRP_fLineColor);
217   fTree->SetBranchAddress("PHOSRP.fLineStyle",PHOSRP_fLineStyle);
218   fTree->SetBranchAddress("PHOSRP.fLineWidth",PHOSRP_fLineWidth);
219 }
220
221 void RecAna::Notify()
222 {
223   //   called by LoadTree when loading a new file
224   //   get branch pointers
225   b_PHOSEmcRP = fTree->GetBranch("PHOSEmcRP");
226   b_PHOSPpsdRP = fTree->GetBranch("PHOSPpsdRP");
227   b_PHOSTS_ = fTree->GetBranch("PHOSTS_");
228   b_PHOSTS_fEmcRecPoint = fTree->GetBranch("PHOSTS.fEmcRecPoint");
229   b_PHOSTS_fPpsdLowRecPoint = fTree->GetBranch("PHOSTS.fPpsdLowRecPoint");
230   b_PHOSTS_fPpsdUpRecPoint = fTree->GetBranch("PHOSTS.fPpsdUpRecPoint");
231   b_PHOSTS_fUniqueID = fTree->GetBranch("PHOSTS.fUniqueID");
232   b_PHOSTS_fBits = fTree->GetBranch("PHOSTS.fBits");
233   b_PHOSRP_ = fTree->GetBranch("PHOSRP_");
234   b_PHOSRP_fPHOSTrackSegment = fTree->GetBranch("PHOSRP.fPHOSTrackSegment");
235   b_PHOSRP_fIndexInList = fTree->GetBranch("PHOSRP.fIndexInList");
236   b_PHOSRP_fPrimary = fTree->GetBranch("PHOSRP.fPrimary");
237   b_PHOSRP_fType = fTree->GetBranch("PHOSRP.fType");
238   b_PHOSRP_fPdgCode = fTree->GetBranch("PHOSRP.fPdgCode");
239   b_PHOSRP_fStatusCode = fTree->GetBranch("PHOSRP.fStatusCode");
240   b_PHOSRP_fMother = fTree->GetBranch("PHOSRP.fMother[2]");
241   b_PHOSRP_fDaughter = fTree->GetBranch("PHOSRP.fDaughter[2]");
242   b_PHOSRP_fWeight = fTree->GetBranch("PHOSRP.fWeight");
243   b_PHOSRP_fCalcMass = fTree->GetBranch("PHOSRP.fCalcMass");
244   b_PHOSRP_fPx = fTree->GetBranch("PHOSRP.fPx");
245   b_PHOSRP_fPy = fTree->GetBranch("PHOSRP.fPy");
246   b_PHOSRP_fPz = fTree->GetBranch("PHOSRP.fPz");
247   b_PHOSRP_fE = fTree->GetBranch("PHOSRP.fE");
248   b_PHOSRP_fVx = fTree->GetBranch("PHOSRP.fVx");
249   b_PHOSRP_fVy = fTree->GetBranch("PHOSRP.fVy");
250   b_PHOSRP_fVz = fTree->GetBranch("PHOSRP.fVz");
251   b_PHOSRP_fVt = fTree->GetBranch("PHOSRP.fVt");
252   b_PHOSRP_fPolarTheta = fTree->GetBranch("PHOSRP.fPolarTheta");
253   b_PHOSRP_fPolarPhi = fTree->GetBranch("PHOSRP.fPolarPhi");
254   b_PHOSRP_fUniqueID = fTree->GetBranch("PHOSRP.fUniqueID");
255   b_PHOSRP_fBits = fTree->GetBranch("PHOSRP.fBits");
256   b_PHOSRP_fLineColor = fTree->GetBranch("PHOSRP.fLineColor");
257   b_PHOSRP_fLineStyle = fTree->GetBranch("PHOSRP.fLineStyle");
258   b_PHOSRP_fLineWidth = fTree->GetBranch("PHOSRP.fLineWidth");
259 }
260
261 void RecAna::Show(Int_t entry)
262 {
263   // Print contents of entry.
264   // If entry is not specified, print current entry
265   if (!fTree) return;
266   fTree->Show(entry);
267 }
268 #endif // #ifdef RecAna_cxx
269