Add support for 64 bits
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
CommitLineData
6309cf6e 1
6309cf6e 2//Root includes
1a1cdff8 3#include "TNamed.h"
6309cf6e 4//AliRoot includes
1a1cdff8 5#include "AliLoader.h"
6#include "AliMUONConstants.h"
6309cf6e 7#include "AliMUONData.h"
8#include "AliMUONDigit.h"
9#include "AliMUONHit.h"
10#include "AliMUONLocalTrigger.h"
11#include "AliMUONGlobalTrigger.h"
12#include "AliMUONRawCluster.h"
dcd2690d 13#include "AliMUONTrack.h"
6309cf6e 14
15ClassImp(AliMUONData)
16
17//_____________________________________________________________________________
18AliMUONData::AliMUONData():TNamed()
19{
20 fLoader = 0x0;
21 fHits = 0x0; // One event in treeH per primary track
22 fDigits = 0x0; // One event in treeH per detection plane
ce3f5e87 23 fNdigits = 0x0;
6309cf6e 24 fRawClusters = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
25 fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
dcd2690d 26 fLocalTrigger = 0x0; //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
27 fRecTracks = 0x0;
6309cf6e 28//default constructor
29}
30//_____________________________________________________________________________
31AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
32 TNamed(name,title)
33{
34 fLoader = loader;
35 fHits = new TClonesArray("AliMUONHit",1000);
36 fNhits = 0;
37 fDigits = new TObjArray(AliMUONConstants::NCh());
38 fNdigits = new Int_t[AliMUONConstants::NCh()];
39 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
40 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane);
41 fNdigits[iDetectionPlane]=0;
42 }
43 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
44 fNrawclusters = new Int_t[AliMUONConstants::NTrackingCh()];
45 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
46 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane);
47 fNrawclusters[iDetectionPlane]=0;
48 }
49 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
50 fNglobaltrigger =0;
51 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
52 fNlocaltrigger = 0;
dcd2690d 53 fRecTracks = new TClonesArray("AliMUONTrack", 10);
54 fNrectracks = 0; // really needed or GetEntriesFast sufficient ????
6309cf6e 55 //default constructor
56}
57//_____________________________________________________________________________
58AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
59{
60 // Dummy copy constructor
61 ;
62}
63//_____________________________________________________________________________
64AliMUONData::~AliMUONData()
65{
66 if (fHits) {
67 fHits->Delete();
68 delete fHits;
69 }
70 if (fDigits) {
71 fDigits->Delete();
72 delete fDigits;
73 }
74 if (fRawClusters) {
75 fRawClusters->Delete();
76 delete fRawClusters;
77 }
78 if (fGlobalTrigger){
79 fGlobalTrigger->Delete();
80 delete fGlobalTrigger;
81 }
82 if (fLocalTrigger){
83 fLocalTrigger->Delete();
84 delete fLocalTrigger;
85 }
dcd2690d 86 if (fRecTracks){
87 fRecTracks->Delete();
88 delete fRecTracks;
89 }
6309cf6e 90 //detructor
91}
92//_____________________________________________________________________________
93void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
94{
95 //
96 // Add a MUON digit to the list of Digits of the detection plane id
97 //
1a1cdff8 98 TClonesArray &ldigits = * Digits(id) ;
6309cf6e 99 new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
100}
101//_____________________________________________________________________________
102void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
103 Int_t *singleUndef,
104 Int_t *pairUnlike, Int_t *pairLike)
105{
106 // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
107 TClonesArray &globalTrigger = *fGlobalTrigger;
108 new(globalTrigger[fNglobaltrigger++])
109 AliMUONGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
110}
111//_____________________________________________________________________________
112void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber,
113 Int_t idpart, Float_t X, Float_t Y, Float_t Z,
114 Float_t tof, Float_t momentum, Float_t theta,
115 Float_t phi, Float_t length, Float_t destep)
116{
117 TClonesArray &lhits = *fHits;
118 new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber,
119 idpart, X, Y, Z,
120 tof, momentum, theta,
121 phi, length, destep);
122}
123//____________________________________________________________________________
124void AliMUONData::AddLocalTrigger(Int_t *localtr)
125{
126 // add a MUON Local Trigger to the list
127 TClonesArray &localTrigger = *fLocalTrigger;
128 new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
129}
130//_____________________________________________________________________________
131void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
132{
133 //
134 // Add a MUON rawcluster to the list in the detection plane id
135 //
136 TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
137 new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
138}
dcd2690d 139//_____________________________________________________________________________
140void AliMUONData::AddRecTrack(const AliMUONTrack& track)
141{
142 //
143 // Add a MUON rectrack
144 //
145 TClonesArray &lrectracks = *fRecTracks;
146 new(lrectracks[fNrectracks++]) AliMUONTrack(track);
147}
ce3f5e87 148//____________________________________________________________________________
c1d45bdf 149Bool_t AliMUONData::IsRawClusterBranchesInTree()
150{
151 if (TreeR()==0x0) {
152 Error("TreeR","No treeR in memory");
153 return kFALSE;
154 }
155 else {
156 char branchname[30];
157 sprintf(branchname,"%sRawClusters1",GetName());
158 TBranch * branch = 0x0;
159 branch = TreeR()->GetBranch(branchname);
160 if (branch) return kTRUE;
161 else return kFALSE;
162 }
163}
164//____________________________________________________________________________
165Bool_t AliMUONData::IsTriggerBranchesInTree()
166{
167 if (TreeR()==0x0) {
168 Error("TreeR","No treeR in memory");
169 return kFALSE;
170 }
171 else {
172 char branchname[30];
173 sprintf(branchname,"%sLocalTrigger",GetName());
174 TBranch * branch = 0x0;
175 branch = TreeR()->GetBranch(branchname);
176 if (branch) return kTRUE;
177 else return kFALSE;
178 }
179}
180//____________________________________________________________________________
1a1cdff8 181void AliMUONData::Fill(Option_t* option)
182{
183 // Method to fill the trees
184 const char *cH = strstr(option,"H");
185 const char *cD = strstr(option,"D"); // Digits branches in TreeD
186 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
187 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
188 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
189 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
190
191 char branchname[30];
192 TBranch * branch = 0x0;
193
194 //
195 // Filling TreeH
196 if ( TreeH() && cH ) {
197 TreeH()->Fill();
198 }
199 //
200 // Filling TreeD
201 if ( TreeD() && cD) {
202 TreeD()->Fill();
203 }
c1d45bdf 204
1a1cdff8 205 //
206 // filling rawclusters
c1d45bdf 207 if ( TreeR() && cRC ) {
208 if ( IsTriggerBranchesInTree() ) {
209 // Branch per branch filling
210 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
211 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
212 branch = TreeR()->GetBranch(branchname);
213 branch->Fill();
214 }
215 }
216 else TreeR()->Fill();
1a1cdff8 217 }
c1d45bdf 218
1a1cdff8 219 //
220 // filling trigger
221 if ( TreeR() && cGLT) {
346357f4 222 if (IsRawClusterBranchesInTree()) {
c1d45bdf 223 // Branch per branch filling
224 sprintf(branchname,"%sLocalTrigger",GetName());
225 branch = TreeR()->GetBranch(branchname);
226 branch->Fill();
227 sprintf(branchname,"%sGlobalTrigger",GetName());
228 branch = TreeR()->GetBranch(branchname);
229 branch->Fill();
230 }
231 else TreeR()->Fill();
1a1cdff8 232 }
233 //
234 // filling tracks
235 if ( TreeT() && cRT ) {
236 sprintf(branchname,"%sTrack",GetName());
237 branch = TreeT()->GetBranch(branchname);
238 branch->Fill();
239 }
240}
241//_____________________________________________________________________________
6309cf6e 242void AliMUONData::MakeBranch(Option_t* option)
243{
244 //
245 // Create Tree branches for the MUON.
246 //
247 const Int_t kBufferSize = 4000;
248 char branchname[30];
249
250 const char *cH = strstr(option,"H");
251 const char *cD = strstr(option,"D"); // Digits branches in TreeD
252 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
253 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
254 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
255 const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
256
257 TBranch * branch = 0x0;
258
259 // Creating Branches for Hits
260 if (TreeH() && cH) {
261 if (fHits == 0x0) fHits = new TClonesArray("AliMUONHit",1000);
262 fNhits = 0;
263 sprintf(branchname,"%sHits",GetName());
264 branch = TreeH()->GetBranch(branchname);
265 if (branch) {
266 Info("MakeBranch","Branch %s is already in tree.",GetName());
267 return ;
268 }
269 branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
270 Info("MakeBranch","Making Branch %s for hits \n",branchname);
271 }
272
273 //Creating Branches for Digits
274 if (TreeD() && cD ) {
275 // one branch for digits per chamber
276 if (fDigits == 0x0) {
ce3f5e87 277 fDigits = new TObjArray(AliMUONConstants::NCh());
6309cf6e 278 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
279 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane);
ce3f5e87 280 }
281 }
282 if (fNdigits == 0x0) {
283 fNdigits = new Int_t[AliMUONConstants::NCh()];
284 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
6309cf6e 285 fNdigits[iDetectionPlane]=0;
286 }
287 }
288 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
289 sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
290 branch = 0x0;
291 branch = TreeD()->GetBranch(branchname);
292 if (branch) {
293 Info("MakeBranch","Branch %s is already in tree.",GetName());
294 return;
295 }
1a1cdff8 296 TClonesArray * digits = Digits(iDetectionPlane);
ce3f5e87 297 branch = TreeD()->Branch(branchname, &digits, kBufferSize);
6309cf6e 298 Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
299 }
300 }
301
302 if (TreeR() && cRC ) {
303 // one branch for raw clusters per tracking detection plane
304 //
305 Int_t i;
306 if (fRawClusters == 0x0) {
307 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
6309cf6e 308 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
309 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
ce3f5e87 310 }
311 }
312
313 if (fNrawclusters == 0x0) {
314 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
315 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
6309cf6e 316 fNrawclusters[i]=0;
317 }
318 }
319
320 for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
321 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
322 branch = 0x0;
323 branch = TreeR()->GetBranch(branchname);
324 if (branch) {
325 Info("MakeBranch","Branch %s is already in tree.",GetName());
326 return;
327 }
328 branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
329 Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
330 }
331 }
332
333 if (TreeR() && cGLT ) {
334 //
335 // one branch for global trigger
336 //
337 sprintf(branchname,"%sGlobalTrigger",GetName());
338 branch = 0x0;
339
340 if (fGlobalTrigger == 0x0) {
341 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
342 fNglobaltrigger = 0;
343 }
344 branch = TreeR()->GetBranch(branchname);
345 if (branch) {
346 Info("MakeBranch","Branch %s is already in tree.",GetName());
347 return ;
348 }
349 branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
350 Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
351
352 //
353 // one branch for local trigger
354 //
355 sprintf(branchname,"%sLocalTrigger",GetName());
356 branch = 0x0;
357
358 if (fLocalTrigger == 0x0) {
359 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
360 fNlocaltrigger = 0;
361 }
362 branch = TreeR()->GetBranch(branchname);
363 if (branch) {
364 Info("MakeBranch","Branch %s is already in tree.",GetName());
365 return;
366 }
367 branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
368 Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
369 }
370
dcd2690d 371 if (TreeT() && cRT ) {
372 if (fRecTracks == 0x0) fRecTracks = new TClonesArray("AliMUONTrack",10);
373 fNrectracks = 0;
374 sprintf(branchname,"%sTrack",GetName());
375 branch = TreeT()->GetBranch(branchname);
376 if (branch) {
377 Info("MakeBranch","Branch %s is already in tree.",GetName());
378 return ;
379 }
380 branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
381 Info("MakeBranch","Making Branch %s for tracks \n",branchname);
382 }
383
384 if (TreeP() && cRP ) {
6309cf6e 385 Info("MakeBranch","Making Branch for TreeP is not yet ready. \n");
386 }
387}
388
389//____________________________________________________________________________
390void AliMUONData::ResetDigits()
391{
392 //
393 // Reset number of digits and the digits array for this detector
394 //
395 if (fDigits == 0x0) return;
396 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
397 if ((*fDigits)[i]) ((TClonesArray*)fDigits->At(i))->Clear();
398 if (fNdigits) fNdigits[i]=0;
399 }
400}
401//______________________________________________________________________________
402void AliMUONData::ResetHits()
403{
404 // Reset number of clusters and the cluster array for this detector
405 fNhits = 0;
406 if (fHits) fHits->Clear();
407}
408//_______________________________________________________________________________
409void AliMUONData::ResetRawClusters()
410{
411 // Reset number of raw clusters and the raw clust array for this detector
412 //
413 for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
414 if ((*fRawClusters)[i]) ((TClonesArray*)fRawClusters->At(i))->Clear();
415 if (fNrawclusters) fNrawclusters[i]=0;
416 }
417}
418//_______________________________________________________________________________
419void AliMUONData::ResetTrigger()
420{
421 // Reset Local and Global Trigger
422 fNglobaltrigger = 0;
423 if (fGlobalTrigger) fGlobalTrigger->Clear();
424 fNlocaltrigger = 0;
425 if (fLocalTrigger) fLocalTrigger->Clear();
426}
dcd2690d 427//____________________________________________________________________________
428void AliMUONData::ResetRecTracks()
429{
430 // Reset tracks information
431 fNrectracks = 0;
432 if (fRecTracks) fRecTracks->Clear();
433}
6309cf6e 434//_____________________________________________________________________________
ce3f5e87 435void AliMUONData::SetTreeAddress(Option_t* option)
6309cf6e 436{
ce3f5e87 437 const char *cH = strstr(option,"H");
438 const char *cD = strstr(option,"D"); // Digits branches in TreeD
439 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
440 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
dcd2690d 441 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
ce3f5e87 442 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
443
6309cf6e 444 // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
445 char branchname[30];
446 TBranch * branch = 0x0;
447
448 //
449 // Branch address for hit tree
ce3f5e87 450 if ( TreeH() && cH ) {
6309cf6e 451 if (fHits == 0x0) fHits = new TClonesArray("AliMUONHit",1000);
452 fNhits =0;
453 }
ce3f5e87 454 if (TreeH() && fHits && cH) {
6309cf6e 455 sprintf(branchname,"%sHits",GetName());
456 branch = TreeH()->GetBranch(branchname);
457 if (branch) {
458 Info("SetTreeAddress","(%s) Setting for Hits",GetName());
459 branch->SetAddress(&fHits);
460 }
461 else { //can be invoked before branch creation
462 Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
463 }
464 }
465
466 //
467 // Branch address for digit tree
ce3f5e87 468 if ( TreeD() && cD) {
6309cf6e 469 if (fDigits == 0x0) {
470 fDigits = new TObjArray(AliMUONConstants::NCh());
471 fNdigits= new Int_t[AliMUONConstants::NCh()];
472 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
473 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i);
474 fNdigits[i]=0;
475 }
476 }
477 }
478
ce3f5e87 479 if (TreeD() && fDigits && cD) {
6309cf6e 480 for (int i=0; i<AliMUONConstants::NCh(); i++) {
481 sprintf(branchname,"%sDigits%d",GetName(),i+1);
482 branch = TreeD()->GetBranch(branchname);
1a1cdff8 483 TClonesArray * digits = Digits(i);
ce3f5e87 484 if (branch) branch->SetAddress( &digits );
6309cf6e 485 else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
486 }
487 }
488
489 //
490 // Branch address for rawclusters, globaltrigger and local trigger tree
491 if (TreeR() ) {
ce3f5e87 492 if (fRawClusters == 0x0 && cRC) {
6309cf6e 493 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
494 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
495 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
496 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
497 fNrawclusters[i]=0;
498 }
499 }
ce3f5e87 500 if (fLocalTrigger == 0x0 && cGLT) {
6309cf6e 501 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
502 }
ce3f5e87 503 if (fGlobalTrigger== 0x0 && cGLT) {
6309cf6e 504 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
505 }
506
507 }
ce3f5e87 508 if ( TreeR() && fRawClusters && cRC) {
6309cf6e 509 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
510 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
511 if (fRawClusters) {
512 branch = TreeR()->GetBranch(branchname);
513 if (branch) branch->SetAddress(&((*fRawClusters)[i]));
514 else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
515 }
516 }
517 }
ce3f5e87 518 if ( TreeR() && fLocalTrigger && cGLT) {
6309cf6e 519 sprintf(branchname,"%sLocalTrigger",GetName());
520 branch = TreeR()->GetBranch(branchname);
521 if (branch) branch->SetAddress(&fLocalTrigger);
522 else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
523 }
ce3f5e87 524 if ( TreeR() && fGlobalTrigger && cGLT) {
6309cf6e 525 sprintf(branchname,"%sGlobalTrigger",GetName());
526 branch = TreeR()->GetBranch(branchname);
527 if (branch) branch->SetAddress(&fGlobalTrigger);
528 else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
529 }
dcd2690d 530
531 if ( TreeT() && fRecTracks && cRT ) {
532 sprintf(branchname,"%sTrack",GetName());
533 branch = TreeT()->GetBranch(branchname);
534 if (branch) branch->SetAddress(&fRecTracks);
535 else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
536 }
6309cf6e 537}
538//_____________________________________________________________________________