New MUON data container AliMUONData implementation
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
CommitLineData
6309cf6e 1
2
3//Root includes
4
5//AliRoot includes
6#include "AliMUONData.h"
7#include "AliMUONDigit.h"
8#include "AliMUONHit.h"
9#include "AliMUONLocalTrigger.h"
10#include "AliMUONGlobalTrigger.h"
11#include "AliMUONRawCluster.h"
12
13ClassImp(AliMUONData)
14
15//_____________________________________________________________________________
16AliMUONData::AliMUONData():TNamed()
17{
18 fLoader = 0x0;
19 fHits = 0x0; // One event in treeH per primary track
20 fDigits = 0x0; // One event in treeH per detection plane
ce3f5e87 21 fNdigits = 0x0;
6309cf6e 22 fRawClusters = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
23 fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
24 fLocalTrigger = 0x0; //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
25//default constructor
26}
27//_____________________________________________________________________________
28AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
29 TNamed(name,title)
30{
31 fLoader = loader;
32 fHits = new TClonesArray("AliMUONHit",1000);
33 fNhits = 0;
34 fDigits = new TObjArray(AliMUONConstants::NCh());
35 fNdigits = new Int_t[AliMUONConstants::NCh()];
36 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
37 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane);
38 fNdigits[iDetectionPlane]=0;
39 }
40 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
41 fNrawclusters = new Int_t[AliMUONConstants::NTrackingCh()];
42 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
43 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane);
44 fNrawclusters[iDetectionPlane]=0;
45 }
46 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
47 fNglobaltrigger =0;
48 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
49 fNlocaltrigger = 0;
50 //default constructor
51}
52//_____________________________________________________________________________
53AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
54{
55 // Dummy copy constructor
56 ;
57}
58//_____________________________________________________________________________
59AliMUONData::~AliMUONData()
60{
61 if (fHits) {
62 fHits->Delete();
63 delete fHits;
64 }
65 if (fDigits) {
66 fDigits->Delete();
67 delete fDigits;
68 }
69 if (fRawClusters) {
70 fRawClusters->Delete();
71 delete fRawClusters;
72 }
73 if (fGlobalTrigger){
74 fGlobalTrigger->Delete();
75 delete fGlobalTrigger;
76 }
77 if (fLocalTrigger){
78 fLocalTrigger->Delete();
79 delete fLocalTrigger;
80 }
81 //detructor
82}
83//_____________________________________________________________________________
84void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
85{
86 //
87 // Add a MUON digit to the list of Digits of the detection plane id
88 //
ce3f5e87 89 TClonesArray &ldigits = * Digits(id,0) ;
6309cf6e 90 new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
91}
92//_____________________________________________________________________________
93void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
94 Int_t *singleUndef,
95 Int_t *pairUnlike, Int_t *pairLike)
96{
97 // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
98 TClonesArray &globalTrigger = *fGlobalTrigger;
99 new(globalTrigger[fNglobaltrigger++])
100 AliMUONGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
101}
102//_____________________________________________________________________________
103void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber,
104 Int_t idpart, Float_t X, Float_t Y, Float_t Z,
105 Float_t tof, Float_t momentum, Float_t theta,
106 Float_t phi, Float_t length, Float_t destep)
107{
108 TClonesArray &lhits = *fHits;
109 new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber,
110 idpart, X, Y, Z,
111 tof, momentum, theta,
112 phi, length, destep);
113}
114//____________________________________________________________________________
115void AliMUONData::AddLocalTrigger(Int_t *localtr)
116{
117 // add a MUON Local Trigger to the list
118 TClonesArray &localTrigger = *fLocalTrigger;
119 new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
120}
121//_____________________________________________________________________________
122void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
123{
124 //
125 // Add a MUON rawcluster to the list in the detection plane id
126 //
127 TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
128 new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
129}
ce3f5e87 130//____________________________________________________________________________
6309cf6e 131void AliMUONData::MakeBranch(Option_t* option)
132{
133 //
134 // Create Tree branches for the MUON.
135 //
136 const Int_t kBufferSize = 4000;
137 char branchname[30];
138
139 const char *cH = strstr(option,"H");
140 const char *cD = strstr(option,"D"); // Digits branches in TreeD
141 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
142 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
143 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
144 const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
145
146 TBranch * branch = 0x0;
147
148 // Creating Branches for Hits
149 if (TreeH() && cH) {
150 if (fHits == 0x0) fHits = new TClonesArray("AliMUONHit",1000);
151 fNhits = 0;
152 sprintf(branchname,"%sHits",GetName());
153 branch = TreeH()->GetBranch(branchname);
154 if (branch) {
155 Info("MakeBranch","Branch %s is already in tree.",GetName());
156 return ;
157 }
158 branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
159 Info("MakeBranch","Making Branch %s for hits \n",branchname);
160 }
161
162 //Creating Branches for Digits
163 if (TreeD() && cD ) {
164 // one branch for digits per chamber
165 if (fDigits == 0x0) {
ce3f5e87 166 fDigits = new TObjArray(AliMUONConstants::NCh());
6309cf6e 167 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
168 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane);
ce3f5e87 169 }
170 }
171 if (fNdigits == 0x0) {
172 fNdigits = new Int_t[AliMUONConstants::NCh()];
173 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
6309cf6e 174 fNdigits[iDetectionPlane]=0;
175 }
176 }
177 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
178 sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
179 branch = 0x0;
180 branch = TreeD()->GetBranch(branchname);
181 if (branch) {
182 Info("MakeBranch","Branch %s is already in tree.",GetName());
183 return;
184 }
ce3f5e87 185 TClonesArray * digits = Digits(iDetectionPlane,0);
186 branch = TreeD()->Branch(branchname, &digits, kBufferSize);
6309cf6e 187 Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
188 }
189 }
190
191 if (TreeR() && cRC ) {
192 // one branch for raw clusters per tracking detection plane
193 //
194 Int_t i;
195 if (fRawClusters == 0x0) {
196 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
6309cf6e 197 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
198 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
ce3f5e87 199 }
200 }
201
202 if (fNrawclusters == 0x0) {
203 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
204 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
6309cf6e 205 fNrawclusters[i]=0;
206 }
207 }
208
209 for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
210 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
211 branch = 0x0;
212 branch = TreeR()->GetBranch(branchname);
213 if (branch) {
214 Info("MakeBranch","Branch %s is already in tree.",GetName());
215 return;
216 }
217 branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
218 Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
219 }
220 }
221
222 if (TreeR() && cGLT ) {
223 //
224 // one branch for global trigger
225 //
226 sprintf(branchname,"%sGlobalTrigger",GetName());
227 branch = 0x0;
228
229 if (fGlobalTrigger == 0x0) {
230 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
231 fNglobaltrigger = 0;
232 }
233 branch = TreeR()->GetBranch(branchname);
234 if (branch) {
235 Info("MakeBranch","Branch %s is already in tree.",GetName());
236 return ;
237 }
238 branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
239 Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
240
241 //
242 // one branch for local trigger
243 //
244 sprintf(branchname,"%sLocalTrigger",GetName());
245 branch = 0x0;
246
247 if (fLocalTrigger == 0x0) {
248 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
249 fNlocaltrigger = 0;
250 }
251 branch = TreeR()->GetBranch(branchname);
252 if (branch) {
253 Info("MakeBranch","Branch %s is already in tree.",GetName());
254 return;
255 }
256 branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
257 Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
258 }
259
260 if (TreeR() && cRT ) {
261 Info("MakeBranch","Making Branch for TreeT is not yet ready. \n");
262 }
263 if (TreeR() && cRP ) {
264 Info("MakeBranch","Making Branch for TreeP is not yet ready. \n");
265 }
266}
267
268//____________________________________________________________________________
269void AliMUONData::ResetDigits()
270{
271 //
272 // Reset number of digits and the digits array for this detector
273 //
274 if (fDigits == 0x0) return;
275 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
276 if ((*fDigits)[i]) ((TClonesArray*)fDigits->At(i))->Clear();
277 if (fNdigits) fNdigits[i]=0;
278 }
279}
280//______________________________________________________________________________
281void AliMUONData::ResetHits()
282{
283 // Reset number of clusters and the cluster array for this detector
284 fNhits = 0;
285 if (fHits) fHits->Clear();
286}
287//_______________________________________________________________________________
288void AliMUONData::ResetRawClusters()
289{
290 // Reset number of raw clusters and the raw clust array for this detector
291 //
292 for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
293 if ((*fRawClusters)[i]) ((TClonesArray*)fRawClusters->At(i))->Clear();
294 if (fNrawclusters) fNrawclusters[i]=0;
295 }
296}
297//_______________________________________________________________________________
298void AliMUONData::ResetTrigger()
299{
300 // Reset Local and Global Trigger
301 fNglobaltrigger = 0;
302 if (fGlobalTrigger) fGlobalTrigger->Clear();
303 fNlocaltrigger = 0;
304 if (fLocalTrigger) fLocalTrigger->Clear();
305}
306//_____________________________________________________________________________
ce3f5e87 307void AliMUONData::SetTreeAddress(Option_t* option)
6309cf6e 308{
ce3f5e87 309 const char *cH = strstr(option,"H");
310 const char *cD = strstr(option,"D"); // Digits branches in TreeD
311 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
312 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
313 // const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
314 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
315
6309cf6e 316 // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
317 char branchname[30];
318 TBranch * branch = 0x0;
319
320 //
321 // Branch address for hit tree
ce3f5e87 322 if ( TreeH() && cH ) {
6309cf6e 323 if (fHits == 0x0) fHits = new TClonesArray("AliMUONHit",1000);
324 fNhits =0;
325 }
ce3f5e87 326 if (TreeH() && fHits && cH) {
6309cf6e 327 sprintf(branchname,"%sHits",GetName());
328 branch = TreeH()->GetBranch(branchname);
329 if (branch) {
330 Info("SetTreeAddress","(%s) Setting for Hits",GetName());
331 branch->SetAddress(&fHits);
332 }
333 else { //can be invoked before branch creation
334 Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
335 }
336 }
337
338 //
339 // Branch address for digit tree
ce3f5e87 340 if ( TreeD() && cD) {
6309cf6e 341 if (fDigits == 0x0) {
342 fDigits = new TObjArray(AliMUONConstants::NCh());
343 fNdigits= new Int_t[AliMUONConstants::NCh()];
344 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
345 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i);
346 fNdigits[i]=0;
347 }
348 }
349 }
350
ce3f5e87 351 if (TreeD() && fDigits && cD) {
6309cf6e 352 for (int i=0; i<AliMUONConstants::NCh(); i++) {
353 sprintf(branchname,"%sDigits%d",GetName(),i+1);
354 branch = TreeD()->GetBranch(branchname);
ce3f5e87 355 TClonesArray * digits = Digits(i,0);
356 if (branch) branch->SetAddress( &digits );
6309cf6e 357 else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
358 }
359 }
360
361 //
362 // Branch address for rawclusters, globaltrigger and local trigger tree
363 if (TreeR() ) {
ce3f5e87 364 if (fRawClusters == 0x0 && cRC) {
6309cf6e 365 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
366 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
367 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
368 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
369 fNrawclusters[i]=0;
370 }
371 }
ce3f5e87 372 if (fLocalTrigger == 0x0 && cGLT) {
6309cf6e 373 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
374 }
ce3f5e87 375 if (fGlobalTrigger== 0x0 && cGLT) {
6309cf6e 376 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
377 }
378
379 }
ce3f5e87 380 if ( TreeR() && fRawClusters && cRC) {
6309cf6e 381 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
382 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
383 if (fRawClusters) {
384 branch = TreeR()->GetBranch(branchname);
385 if (branch) branch->SetAddress(&((*fRawClusters)[i]));
386 else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
387 }
388 }
389 }
ce3f5e87 390 if ( TreeR() && fLocalTrigger && cGLT) {
6309cf6e 391 sprintf(branchname,"%sLocalTrigger",GetName());
392 branch = TreeR()->GetBranch(branchname);
393 if (branch) branch->SetAddress(&fLocalTrigger);
394 else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
395 }
ce3f5e87 396 if ( TreeR() && fGlobalTrigger && cGLT) {
6309cf6e 397 sprintf(branchname,"%sGlobalTrigger",GetName());
398 branch = TreeR()->GetBranch(branchname);
399 if (branch) branch->SetAddress(&fGlobalTrigger);
400 else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
401 }
402}
403//_____________________________________________________________________________