Geometry builder classes moved from base to sim.
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
CommitLineData
50837721 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
f0945e46 17
18/// AliMUONData class
19///
20/// Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
21/// The classe makes the lik between the MUON data lists and the event trees from loaders
22///
23/// Gines Martinez, Subatech, September 2003
24///
9140dcef 25
6309cf6e 26#include "AliMUONData.h"
c82862d3 27
28#include "AliLog.h"
29#include "AliMUONConstants.h"
6309cf6e 30#include "AliMUONDigit.h"
c82862d3 31#include "AliMUONGlobalTrigger.h"
6309cf6e 32#include "AliMUONHit.h"
33#include "AliMUONLocalTrigger.h"
6309cf6e 34#include "AliMUONRawCluster.h"
dcd2690d 35#include "AliMUONTrack.h"
276c44b7 36#include "AliMUONTriggerTrack.h"
f0945e46 37#include "AliRunLoader.h"
38#include "TArrayI.h"
c82862d3 39#include "TString.h"
30178c30 40
6309cf6e 41ClassImp(AliMUONData)
42
43//_____________________________________________________________________________
1017e5bf 44 AliMUONData::AliMUONData():
45 TNamed(),
46 fLoader(0x0),
47 fHits(0x0),
48 fDigits(0x0),
49 fSDigits(0x0),
50 fRawClusters(0x0),
51 fGlobalTrigger(0x0),
52 fLocalTrigger(0x0),
53 fRecTracks(0x0),
54 fRecTriggerTracks(0x0),
55 fNhits(0),
56 fNdigits(0x0),
57 fNSdigits(0x0),
58 fNrawclusters(0x0),
59 fNglobaltrigger(0),
60 fNlocaltrigger(0),
61 fNrectracks(0),
62 fNrectriggertracks(0),
f0945e46 63 fSplitLevel(0),
64 fCurrentEvent(-1)
6309cf6e 65{
9140dcef 66 // Default constructor
6309cf6e 67}
68//_____________________________________________________________________________
69AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
1017e5bf 70 TNamed(name,title),
71 fLoader(loader),
72 fHits(0x0),
73 fDigits(0x0),
74 fSDigits(0x0),
75 fRawClusters(0x0),
76 fGlobalTrigger(0x0),
77 fLocalTrigger(0x0),
78 fRecTracks(0x0),
79 fRecTriggerTracks(0x0),
80 fNhits(0),
81 fNdigits(0x0),
82 fNSdigits(0x0),
83 fNrawclusters(0x0),
84 fNglobaltrigger(0),
85 fNlocaltrigger(0),
86 fNrectracks(0),
87 fNrectriggertracks(0),
f0945e46 88 fSplitLevel(0),
89 fCurrentEvent(-1)
6309cf6e 90{
9140dcef 91 // Constructor for AliMUONData
6309cf6e 92}
e3ea1889 93
6309cf6e 94//_____________________________________________________________________________
95AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
96{
e3ea1889 97// Protected copy constructor
98
8c343c7c 99 AliFatal("Not implemented.");
6309cf6e 100}
e3ea1889 101
6309cf6e 102//_____________________________________________________________________________
103AliMUONData::~AliMUONData()
104{
9140dcef 105 // Destructor for AliMUONData
6309cf6e 106 if (fHits) {
107 fHits->Delete();
108 delete fHits;
109 }
c82862d3 110
6309cf6e 111 if (fDigits) {
112 fDigits->Delete();
113 delete fDigits;
114 }
d1775029 115 if (fSDigits) {
116 fSDigits->Delete();
117 delete fSDigits;
118 }
6309cf6e 119 if (fRawClusters) {
120 fRawClusters->Delete();
121 delete fRawClusters;
122 }
123 if (fGlobalTrigger){
124 fGlobalTrigger->Delete();
125 delete fGlobalTrigger;
126 }
127 if (fLocalTrigger){
128 fLocalTrigger->Delete();
129 delete fLocalTrigger;
130 }
dcd2690d 131 if (fRecTracks){
132 fRecTracks->Delete();
133 delete fRecTracks;
134 }
276c44b7 135 if (fRecTriggerTracks){
136 fRecTriggerTracks->Delete();
137 delete fRecTriggerTracks;
138 }
6309cf6e 139}
e3ea1889 140
141//_____________________________________________________________________________
142AliMUONData& AliMUONData::operator=(const AliMUONData& rhs)
143{
144// Protected assignement operator
145
146 if (this == &rhs) return *this;
147
8c343c7c 148 AliFatal("Not implemented.");
e3ea1889 149
150 return *this;
151}
152
153
6309cf6e 154//_____________________________________________________________________________
155void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
156{
157 //
158 // Add a MUON digit to the list of Digits of the detection plane id
159 //
1a1cdff8 160 TClonesArray &ldigits = * Digits(id) ;
6309cf6e 161 new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
162}
163//_____________________________________________________________________________
61adb9bd 164void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
165{
166 //
167 // Add a MUON digit to the list of Digits of the detection plane id
168 //
169 TClonesArray &ldigits = * Digits(id) ;
170 new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
171}
172//_____________________________________________________________________________
30178c30 173void AliMUONData::AddSDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *sdigits)
d1775029 174{
175 //
176 // Add a MUON Sdigit to the list of SDigits of the detection plane id
177 //
178 TClonesArray &lSdigits = * SDigits(id) ;
30178c30 179 new(lSdigits[fNSdigits[id]++]) AliMUONDigit(tracks,charges,sdigits);
d1775029 180}
181//_____________________________________________________________________________
182void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
183{
184 //
185 // Add a MUON Sdigit to the list of SDigits of the detection plane id
186 //
187 TClonesArray &lSdigits = * SDigits(id) ;
188 new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
189}
2cf44ef3 190
6309cf6e 191//_____________________________________________________________________________
61adb9bd 192void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
193{
ce3e25a8 194 // add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
61adb9bd 195 TClonesArray &globalTrigger = *fGlobalTrigger;
196 new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
197}
d59b2ec3 198//____________________________________________________________________________
6309cf6e 199void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber,
200 Int_t idpart, Float_t X, Float_t Y, Float_t Z,
201 Float_t tof, Float_t momentum, Float_t theta,
d59b2ec3 202 Float_t phi, Float_t length, Float_t destep,
203 Float_t Xref,Float_t Yref,Float_t Zref)
6309cf6e 204{
d59b2ec3 205 // Add new hit to the hit list
6309cf6e 206 TClonesArray &lhits = *fHits;
207 new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber,
208 idpart, X, Y, Z,
209 tof, momentum, theta,
d59b2ec3 210 phi, length, destep,
8690a0a6 211 Xref,Yref,Zref);
6309cf6e 212}
213//____________________________________________________________________________
d59b2ec3 214void AliMUONData::AddHit2(Int_t fIshunt, Int_t track, Int_t detElemId,
1391e633 215 Int_t idpart, Float_t X, Float_t Y, Float_t Z,
216 Float_t tof, Float_t momentum, Float_t theta,
217 Float_t phi, Float_t length, Float_t destep,
218 Float_t Xref,Float_t Yref,Float_t Zref)
219{
9140dcef 220 // Add new hit to the hit list
1391e633 221 TClonesArray &lhits = *fHits;
d59b2ec3 222 new(lhits[fNhits++]) AliMUONHit(fIshunt, track, detElemId,
1391e633 223 idpart, X, Y, Z,
224 tof, momentum, theta,
225 phi, length, destep,
d59b2ec3 226 Xref,Yref,Zref, true);
61adb9bd 227}
228//____________________________________________________________________________
61adb9bd 229void AliMUONData::AddLocalTrigger(const AliMUONLocalTrigger& trigger)
230{
231 // add a MUON Local Trigger to the list
232 TClonesArray &localTrigger = *fLocalTrigger;
233 new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
234}
6309cf6e 235//_____________________________________________________________________________
236void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
237{
238 //
239 // Add a MUON rawcluster to the list in the detection plane id
240 //
241 TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
242 new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
243}
dcd2690d 244//_____________________________________________________________________________
245void AliMUONData::AddRecTrack(const AliMUONTrack& track)
246{
247 //
248 // Add a MUON rectrack
249 //
250 TClonesArray &lrectracks = *fRecTracks;
251 new(lrectracks[fNrectracks++]) AliMUONTrack(track);
252}
276c44b7 253//_____________________________________________________________________________
254void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
255{
256 //
257 // Add a MUON triggerrectrack
258 //
259 TClonesArray &lrectriggertracks = *fRecTriggerTracks;
260 new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
276c44b7 261}
ce3f5e87 262//____________________________________________________________________________
c82862d3 263TClonesArray* AliMUONData::Digits(Int_t DetectionPlane) const
1eccde20 264{
9140dcef 265 //Getting List of Digits
1eccde20 266 if (fDigits)
267 return ( (TClonesArray*) fDigits->At(DetectionPlane) );
268 else
269 return NULL;
270}
271//____________________________________________________________________________
c82862d3 272TClonesArray* AliMUONData::SDigits(Int_t DetectionPlane) const
d1775029 273{
274 //Getting List of SDigits
275 if (fSDigits)
276 return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
277 else
278 return NULL;
279}
280//____________________________________________________________________________
c1d45bdf 281Bool_t AliMUONData::IsRawClusterBranchesInTree()
282{
9140dcef 283 // Checking if there are RawCluster Branches In TreeR
c1d45bdf 284 if (TreeR()==0x0) {
8c343c7c 285 AliError("No treeR in memory");
c1d45bdf 286 return kFALSE;
287 }
288 else {
289 char branchname[30];
290 sprintf(branchname,"%sRawClusters1",GetName());
291 TBranch * branch = 0x0;
292 branch = TreeR()->GetBranch(branchname);
293 if (branch) return kTRUE;
294 else return kFALSE;
295 }
296}
297//____________________________________________________________________________
ce3e25a8 298Bool_t AliMUONData::IsDigitsBranchesInTree()
299{
300 // Checking if there are RawCluster Branches In TreeR
301 if (TreeD()==0x0) {
8c343c7c 302 AliError("No treeD in memory");
ce3e25a8 303 return kFALSE;
304 }
305 else {
306 char branchname[30];
307 sprintf(branchname,"%sDigits1",GetName());
308 TBranch * branch = 0x0;
309 branch = TreeD()->GetBranch(branchname);
310 if (branch) return kTRUE;
311 else return kFALSE;
312 }
313}
314//____________________________________________________________________________
c1d45bdf 315Bool_t AliMUONData::IsTriggerBranchesInTree()
316{
9140dcef 317 // Checking if there are Trigger Branches In TreeR
c1d45bdf 318 if (TreeR()==0x0) {
8c343c7c 319 AliError("No treeR in memory");
c1d45bdf 320 return kFALSE;
321 }
322 else {
323 char branchname[30];
324 sprintf(branchname,"%sLocalTrigger",GetName());
325 TBranch * branch = 0x0;
326 branch = TreeR()->GetBranch(branchname);
327 if (branch) return kTRUE;
328 else return kFALSE;
329 }
330}
ce3e25a8 331//____________________________________________________________________________
332Bool_t AliMUONData::IsTriggerBranchesInTreeD()
333{
334 // Checking if there are Trigger Branches In TreeR
335 if (TreeD()==0x0) {
8c343c7c 336 AliError("No treeD in memory");
ce3e25a8 337 return kFALSE;
338 }
339 else {
340 char branchname[30];
341 sprintf(branchname,"%sLocalTrigger",GetName());
342 TBranch * branch = 0x0;
343 branch = TreeD()->GetBranch(branchname);
344 if (branch) return kTRUE;
345 else return kFALSE;
346 }
347}
348
c1d45bdf 349//____________________________________________________________________________
276c44b7 350Bool_t AliMUONData::IsTrackBranchesInTree()
351{
352 // Checking if there are Track Branches In TreeT
353 if (TreeT()==0x0) {
8c343c7c 354 AliError("No treeT in memory");
276c44b7 355 return kFALSE;
356 }
357 else {
358 char branchname[30];
359 sprintf(branchname,"%sTrack",GetName());
360 TBranch * branch = 0x0;
361 branch = TreeT()->GetBranch(branchname);
362 if (branch) return kTRUE;
363 else return kFALSE;
364 }
365}
366//____________________________________________________________________________
367Bool_t AliMUONData::IsTriggerTrackBranchesInTree()
368{
369 // Checking if there are TriggerTrack Branches In TreeT
370 if (TreeT()==0x0) {
8c343c7c 371 AliError("No treeT in memory");
276c44b7 372 return kFALSE;
373 }
374 else {
375 char branchname[30];
376 sprintf(branchname,"%sTriggerTrack",GetName());
377 TBranch * branch = 0x0;
378 branch = TreeT()->GetBranch(branchname);
379 if (branch) return kTRUE;
380 else return kFALSE;
381 }
382}
383//____________________________________________________________________________
1a1cdff8 384void AliMUONData::Fill(Option_t* option)
385{
386 // Method to fill the trees
387 const char *cH = strstr(option,"H");
388 const char *cD = strstr(option,"D"); // Digits branches in TreeD
d1775029 389 const char *cS = strstr(option,"S"); // SDigits branches in TreeS
1a1cdff8 390 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
ce3e25a8 391 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
392 const char *cTC = strstr(option,"TC"); // global and local Trigger branches Copy in TreeR
1a1cdff8 393 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
ce3e25a8 394 const char *cRL = strstr(option,"RL"); // Reconstructed Trigger Track in TreeT
61adb9bd 395
1a1cdff8 396 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
397
398 char branchname[30];
399 TBranch * branch = 0x0;
400
1a1cdff8 401 // Filling TreeH
f0945e46 402 if ( TreeH() && cH )
403 {
1a1cdff8 404 TreeH()->Fill();
405 }
ce3e25a8 406
1a1cdff8 407 // Filling TreeD
ce3e25a8 408
c82862d3 409 if ( TreeD() && cD && cGLT )
410 {
f0945e46 411 // Writing digits and (global+local) trigger at once.
c82862d3 412 TreeD()->Fill();
413 }
f0945e46 414 else
415 {
416 if ( TreeD() && cD )
417 {
418 if ( IsTriggerBranchesInTreeD() )
419 {
420 for (int i=0; i<AliMUONConstants::NCh(); i++)
421 {
422 sprintf(branchname,"%sDigits%d",GetName(),i+1);
423 branch = TreeD()->GetBranch(branchname);
424 branch->Fill();
425 }
426 }
427 else
428 {
429 TreeD()->Fill();
ce3e25a8 430 }
f0945e46 431 }
432
433 if ( TreeD() && cGLT )
434 {
435 if ( IsDigitsBranchesInTree() )
436 {
437 sprintf(branchname,"%sLocalTrigger",GetName());
438 branch = TreeD()->GetBranch(branchname);
439 branch->Fill();
440 sprintf(branchname,"%sGlobalTrigger",GetName());
441 branch = TreeD()->GetBranch(branchname);
442 branch->Fill();
443 }
444 else
445 {
446 TreeD()->Fill();
447 }
448 }
449 } // end of TreeD() handling.
ce3e25a8 450
d1775029 451 // Filling TreeS
f0945e46 452 if ( TreeS() && cS)
453 {
d1775029 454 TreeS()->Fill();
455 }
c1d45bdf 456
f0945e46 457 // Filling TreeR
458
459 if ( TreeR() && cRC && cTC )
460 {
461 TreeR()->Fill();
462 }
463 else
464 {
465 if ( TreeR() && cRC )
466 {
467 if ( IsTriggerBranchesInTree() )
468 {
c1d45bdf 469 // Branch per branch filling
f0945e46 470 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++)
471 {
472 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
473 branch = TreeR()->GetBranch(branchname);
474 branch->Fill();
475 }
476 }
477 else
478 {
479 TreeR()->Fill();
480 }
481 }
482
483 if ( TreeR() && cTC)
484 {
485 if (IsRawClusterBranchesInTree())
486 {
487 // Branch per branch filling
488 sprintf(branchname,"%sLocalTrigger",GetName());
489 branch = TreeR()->GetBranch(branchname);
490 branch->Fill();
491 sprintf(branchname,"%sGlobalTrigger",GetName());
492 branch = TreeR()->GetBranch(branchname);
493 branch->Fill();
494 }
495 else
496 {
497 TreeR()->Fill();
c1d45bdf 498 }
499 }
1a1cdff8 500 }
f0945e46 501
502 // Filling TreeT
c1d45bdf 503
f0945e46 504 if ( TreeT() && cRT && cRL )
505 {
506 TreeT()->Fill();
1a1cdff8 507 }
f0945e46 508 else
509 {
510 if ( TreeT() && cRT )
511 {
512 if (IsTriggerTrackBranchesInTree())
513 {
514 sprintf(branchname,"%sTrack",GetName());
515 branch = TreeT()->GetBranch(branchname);
516 branch->Fill();
517 }
518 else
519 {
520 TreeT()->Fill();
521 }
522 }
523
524 if ( TreeT() && cRL )
525 {
526 if (IsTrackBranchesInTree())
527 {
528 sprintf(branchname,"%sTriggerTrack",GetName());
529 branch = TreeT()->GetBranch(branchname);
530 branch->Fill();
531 }
532 else
533 {
534 TreeT()->Fill();
535 }
276c44b7 536 }
1a1cdff8 537 }
538}
c82862d3 539
1a1cdff8 540//_____________________________________________________________________________
6309cf6e 541void AliMUONData::MakeBranch(Option_t* option)
542{
543 //
544 // Create Tree branches for the MUON.
545 //
546 const Int_t kBufferSize = 4000;
547 char branchname[30];
548
c82862d3 549
6309cf6e 550 const char *cH = strstr(option,"H");
551 const char *cD = strstr(option,"D"); // Digits branches in TreeD
d1775029 552 const char *cS = strstr(option,"S"); // Digits branches in TreeS
6309cf6e 553 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
ce3e25a8 554 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
555 const char *cTC = strstr(option,"TC"); // global and local Trigger branches Copy in TreeR
6309cf6e 556 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
276c44b7 557 const char *cRL = strstr(option,"RL"); // Reconstructed Trigger Track in TreeT
c82862d3 558 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
559
6309cf6e 560 TBranch * branch = 0x0;
561
562 // Creating Branches for Hits
563 if (TreeH() && cH) {
c82862d3 564
1988766a 565 if (fHits == 0x0) {
c82862d3 566 fHits = new TClonesArray("AliMUONHit",1000);
567 // if (gAlice->GetMCApp())
568 // gAlice->GetMCApp()->AddHitList (fHits);
1988766a 569 }
c82862d3 570
6309cf6e 571 fNhits = 0;
572 sprintf(branchname,"%sHits",GetName());
573 branch = TreeH()->GetBranch(branchname);
574 if (branch) {
f0945e46 575 AliInfo(Form("MakeBranch","Branch %s is already in tree.",branchname));
6309cf6e 576 return ;
577 }
c6ce342a 578 branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
cba99c31 579 //Info("MakeBranch","Making Branch %s for hits \n",branchname);
6309cf6e 580 }
581
582 //Creating Branches for Digits
c82862d3 583 TTree* treeD = 0x0;
584 if ( cD || cGLT )
585 {
586 treeD = TreeD();
587 }
588
589 if ( treeD && cD )
590 {
6309cf6e 591 // one branch for digits per chamber
c82862d3 592 if (fDigits == 0x0)
593 {
ce3f5e87 594 fDigits = new TObjArray(AliMUONConstants::NCh());
c82862d3 595 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++)
596 {
597 TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
598 tca->SetOwner();
599 fDigits->AddAt(tca,iDetectionPlane);
ce3f5e87 600 }
601 }
c82862d3 602 if (fNdigits == 0x0)
603 {
ce3f5e87 604 fNdigits = new Int_t[AliMUONConstants::NCh()];
c82862d3 605 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++)
606 {
607 fNdigits[iDetectionPlane]=0;
6309cf6e 608 }
609 }
c82862d3 610 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++)
611 {
6309cf6e 612 sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
c82862d3 613 branch = treeD->GetBranch(branchname);
614 if (branch)
615 {
f0945e46 616 AliInfo(Form("Branch %s is already in tree.",branchname));
c82862d3 617 return;
6309cf6e 618 }
1a1cdff8 619 TClonesArray * digits = Digits(iDetectionPlane);
c82862d3 620 branch = treeD->Branch(branchname, &digits, kBufferSize,1);
621 }
6309cf6e 622 }
c82862d3 623
624 if ( treeD && cGLT )
625 {
ce3e25a8 626 //
627 // one branch for global trigger
628 //
629 sprintf(branchname,"%sGlobalTrigger",GetName());
ce3e25a8 630
c82862d3 631 if (fGlobalTrigger == 0x0)
632 {
ce3e25a8 633 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger");
634 fNglobaltrigger = 0;
635 }
c82862d3 636 branch = treeD->GetBranch(branchname);
637 if (branch)
638 {
8c343c7c 639 AliInfo(Form("Branch GlobalTrigger is already in treeD."));
ce3e25a8 640 return ;
641 }
c82862d3 642 branch = treeD->Branch(branchname, &fGlobalTrigger, kBufferSize);
643
ce3e25a8 644 //
645 // one branch for local trigger
646 //
647 sprintf(branchname,"%sLocalTrigger",GetName());
648 branch = 0x0;
649
c82862d3 650 if (fLocalTrigger == 0x0)
651 {
ce3e25a8 652 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
653 fNlocaltrigger = 0;
654 }
c82862d3 655 branch = treeD->GetBranch(branchname);
656 if (branch)
657 {
8c343c7c 658 AliInfo(Form("Branch LocalTrigger is already in treeD."));
ce3e25a8 659 return;
660 }
c82862d3 661 branch = treeD->Branch(branchname, &fLocalTrigger, kBufferSize);
ce3e25a8 662 }
c82862d3 663
d1775029 664 //Creating Branches for SDigits
665 if (TreeS() && cS ) {
666 // one branch for Sdigits per chamber
667 if (fSDigits == 0x0) {
668 fSDigits = new TObjArray(AliMUONConstants::NCh());
669 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
c82862d3 670 TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
671 tca->SetOwner();
672 fSDigits->AddAt(tca,iDetectionPlane);
d1775029 673 }
674 }
675 if (fNSdigits == 0x0) {
676 fNSdigits = new Int_t[AliMUONConstants::NCh()];
677 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
c82862d3 678 fNSdigits[iDetectionPlane]=0;
d1775029 679 }
680 }
681 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
682 sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
683 branch = 0x0;
684 branch = TreeS()->GetBranch(branchname);
685 if (branch) {
f0945e46 686 AliInfo(Form("Branch %s is already in tree.",branchname));
c82862d3 687 return;
d1775029 688 }
30178c30 689 TClonesArray * sdigits = SDigits(iDetectionPlane);
690 branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
691 //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
c82862d3 692 }
d1775029 693 }
c82862d3 694
6309cf6e 695 if (TreeR() && cRC ) {
696 // one branch for raw clusters per tracking detection plane
697 //
698 Int_t i;
699 if (fRawClusters == 0x0) {
700 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
6309cf6e 701 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
c82862d3 702 TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
703 tca->SetOwner();
704 fRawClusters->AddAt(tca,i);
ce3f5e87 705 }
706 }
c82862d3 707
ce3f5e87 708 if (fNrawclusters == 0x0) {
709 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
710 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
c82862d3 711 fNrawclusters[i]=0;
6309cf6e 712 }
713 }
714
715 for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
716 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
717 branch = 0x0;
718 branch = TreeR()->GetBranch(branchname);
719 if (branch) {
f0945e46 720 AliInfo(Form("Branch %s is already in tree.",branchname));
c82862d3 721 return;
6309cf6e 722 }
c6ce342a 723 branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
cba99c31 724 //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
6309cf6e 725 }
726 }
c82862d3 727
ce3e25a8 728 if (TreeR() && cTC ) {
6309cf6e 729 //
730 // one branch for global trigger
731 //
732 sprintf(branchname,"%sGlobalTrigger",GetName());
733 branch = 0x0;
734
735 if (fGlobalTrigger == 0x0) {
c6ce342a 736 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger");
6309cf6e 737 fNglobaltrigger = 0;
738 }
739 branch = TreeR()->GetBranch(branchname);
740 if (branch) {
8c343c7c 741 AliInfo(Form("Branch GlobalTrigger is already in treeR."));
6309cf6e 742 return ;
743 }
c6ce342a 744 branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
cba99c31 745 //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
6309cf6e 746
747 //
748 // one branch for local trigger
749 //
750 sprintf(branchname,"%sLocalTrigger",GetName());
751 branch = 0x0;
752
753 if (fLocalTrigger == 0x0) {
754 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
755 fNlocaltrigger = 0;
756 }
757 branch = TreeR()->GetBranch(branchname);
758 if (branch) {
8c343c7c 759 AliInfo(Form("Branch LocalTrigger is already in treeR."));
6309cf6e 760 return;
761 }
c6ce342a 762 branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
cba99c31 763 //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
6309cf6e 764 }
765
dcd2690d 766 if (TreeT() && cRT ) {
374ebd7d 767 if (fRecTracks == 0x0) fRecTracks = new TClonesArray("AliMUONTrack",100);
dcd2690d 768 fNrectracks = 0;
769 sprintf(branchname,"%sTrack",GetName());
770 branch = TreeT()->GetBranch(branchname);
771 if (branch) {
8c343c7c 772 AliInfo(Form("Branch %s is already in tree.",GetName()));
dcd2690d 773 return ;
774 }
775 branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
cba99c31 776 //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
dcd2690d 777 }
c82862d3 778 // trigger tracks
276c44b7 779 if (TreeT() && cRL ) {
780 if (fRecTriggerTracks == 0x0) fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
781 fNrectriggertracks = 0;
782 sprintf(branchname,"%sTriggerTrack",GetName());
783 branch = TreeT()->GetBranch(branchname);
784 if (branch) {
8c343c7c 785 AliInfo(Form("Branch %s is already in tree.",GetName()));
276c44b7 786 return ;
787 }
788 branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
cba99c31 789 //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
276c44b7 790 }
6309cf6e 791}
1eccde20 792//____________________________________________________________________________
793TClonesArray* AliMUONData::RawClusters(Int_t DetectionPlane)
794{
9140dcef 795 // Getting Raw Clusters
1eccde20 796 if (fRawClusters)
797 return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
798 else
799 return NULL;
800}
f0945e46 801
6309cf6e 802//____________________________________________________________________________
f0945e46 803TClonesArray*
804AliMUONData::LocalTrigger() const
276c44b7 805{
f0945e46 806 return fLocalTrigger;
276c44b7 807}
f0945e46 808
276c44b7 809//____________________________________________________________________________
f0945e46 810void
811AliMUONData::GetDigits() const
276c44b7 812{
f0945e46 813 // Load the digits from TreeD for the current event.
814 Int_t event = fLoader->GetRunLoader()->GetEventNumber();
815 if ( fCurrentEvent != event )
816 {
817 fLoader->TreeD()->GetEvent(0);
818 fCurrentEvent = event;
819 }
276c44b7 820}
f0945e46 821
822//____________________________________________________________________________
823TClonesArray*
824AliMUONData::GlobalTrigger() const
825{
826 // Return the global trigger
827 return fGlobalTrigger;
828}
829
276c44b7 830//____________________________________________________________________________
6309cf6e 831void AliMUONData::ResetDigits()
832{
833 //
834 // Reset number of digits and the digits array for this detector
835 //
836 if (fDigits == 0x0) return;
837 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
f68d0cf6 838 if ((*fDigits)[i]) ((TClonesArray*)fDigits->At(i))->Clear("C");
6309cf6e 839 if (fNdigits) fNdigits[i]=0;
840 }
841}
d1775029 842//____________________________________________________________________________
843void AliMUONData::ResetSDigits()
844{
845 //
846 // Reset number of Sdigits and the Sdigits array for this detector
847 //
848 if (fSDigits == 0x0) return;
849 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
850 if ((*fSDigits)[i]) ((TClonesArray*)fSDigits->At(i))->Clear();
851 if (fNSdigits) fNSdigits[i]=0;
852 }
853}
6309cf6e 854//______________________________________________________________________________
855void AliMUONData::ResetHits()
856{
857 // Reset number of clusters and the cluster array for this detector
858 fNhits = 0;
859 if (fHits) fHits->Clear();
860}
861//_______________________________________________________________________________
862void AliMUONData::ResetRawClusters()
863{
864 // Reset number of raw clusters and the raw clust array for this detector
865 //
866 for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
867 if ((*fRawClusters)[i]) ((TClonesArray*)fRawClusters->At(i))->Clear();
868 if (fNrawclusters) fNrawclusters[i]=0;
869 }
870}
871//_______________________________________________________________________________
872void AliMUONData::ResetTrigger()
873{
874 // Reset Local and Global Trigger
875 fNglobaltrigger = 0;
876 if (fGlobalTrigger) fGlobalTrigger->Clear();
877 fNlocaltrigger = 0;
878 if (fLocalTrigger) fLocalTrigger->Clear();
879}
dcd2690d 880//____________________________________________________________________________
881void AliMUONData::ResetRecTracks()
882{
883 // Reset tracks information
884 fNrectracks = 0;
34f1bfa0 885 if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
dcd2690d 886}
276c44b7 887//____________________________________________________________________________
888void AliMUONData::ResetRecTriggerTracks()
889{
890 // Reset tracks information
891 fNrectriggertracks = 0;
34f1bfa0 892 if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
276c44b7 893}
6309cf6e 894//_____________________________________________________________________________
ce3f5e87 895void AliMUONData::SetTreeAddress(Option_t* option)
6309cf6e 896{
9140dcef 897 //Setting Addresses to the events trees
ce3f5e87 898 const char *cH = strstr(option,"H");
899 const char *cD = strstr(option,"D"); // Digits branches in TreeD
d1775029 900 const char *cS = strstr(option,"S"); // SDigits branches in TreeS
ce3f5e87 901 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
ce3e25a8 902 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
903 const char *cTC = strstr(option,"TC"); // global and local Trigger branches Copy in TreeR
dcd2690d 904 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
276c44b7 905 const char *cRL = strstr(option,"RL"); // Reconstructed Trigger Track in TreeT
c82862d3 906 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
ce3f5e87 907
6309cf6e 908 // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
909 char branchname[30];
910 TBranch * branch = 0x0;
c82862d3 911
912 AliDebug(1,Form("option=%s",option));
6309cf6e 913 //
914 // Branch address for hit tree
ce3f5e87 915 if ( TreeH() && cH ) {
c82862d3 916 if (fHits == 0x0) {
917 fHits = new TClonesArray("AliMUONHit",1000);
918 // if (gAlice->GetMCApp())
919 // gAlice->GetMCApp()->AddHitList (fHits); Moved to AliMUON
88cf591d 920 }
6309cf6e 921 fNhits =0;
922 }
ce3f5e87 923 if (TreeH() && fHits && cH) {
6309cf6e 924 sprintf(branchname,"%sHits",GetName());
925 branch = TreeH()->GetBranch(branchname);
926 if (branch) {
d652f85c 927 // Info("SetTreeAddress","(%s) Setting for Hits",GetName());
6309cf6e 928 branch->SetAddress(&fHits);
929 }
930 else { //can be invoked before branch creation
8c343c7c 931 AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
6309cf6e 932 }
933 }
934
935 //
936 // Branch address for digit tree
95e68a13 937 if ( TreeD() ) {
938 if (fDigits == 0x0 && cD) {
6309cf6e 939 fDigits = new TObjArray(AliMUONConstants::NCh());
940 fNdigits= new Int_t[AliMUONConstants::NCh()];
941 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
c82862d3 942 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i);
943 fNdigits[i]=0;
6309cf6e 944 }
945 }
ce3e25a8 946 if (fLocalTrigger == 0x0 && cGLT) {
947 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
948 }
949 if (fGlobalTrigger== 0x0 && cGLT) {
c82862d3 950 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
ce3e25a8 951 }
6309cf6e 952 }
c82862d3 953
ce3f5e87 954 if (TreeD() && fDigits && cD) {
6309cf6e 955 for (int i=0; i<AliMUONConstants::NCh(); i++) {
956 sprintf(branchname,"%sDigits%d",GetName(),i+1);
d652f85c 957 if (fDigits) {
c82862d3 958 branch = TreeD()->GetBranch(branchname);
959 TClonesArray * digits = Digits(i);
960 if (branch) {
961 branch->SetAddress( &digits );
962 }
963 else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
d652f85c 964 }
6309cf6e 965 }
966 }
ce3e25a8 967 if ( TreeD() && fLocalTrigger && cGLT) {
968 sprintf(branchname,"%sLocalTrigger",GetName());
969 branch = TreeD()->GetBranch(branchname);
970 if (branch) branch->SetAddress(&fLocalTrigger);
8c343c7c 971 else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
ce3e25a8 972 }
973 if ( TreeD() && fGlobalTrigger && cGLT) {
974 sprintf(branchname,"%sGlobalTrigger",GetName());
975 branch = TreeD()->GetBranch(branchname);
976 if (branch) branch->SetAddress(&fGlobalTrigger);
8c343c7c 977 else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
ce3e25a8 978 }
c82862d3 979
d1775029 980 //
981 // Branch address for Sdigit tree
c82862d3 982 if ( TreeS() && cS)
983 {
984 if (fSDigits == 0x0)
985 {
986 AliDebug(1,"Creating fSDigits TObjArray");
d1775029 987 fSDigits = new TObjArray(AliMUONConstants::NCh());
988 fNSdigits= new Int_t[AliMUONConstants::NCh()];
c82862d3 989 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++)
990 {
991 TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
992 fSDigits->AddAt(a,i);
993 AliDebug(1,Form("fSDigits[%d]=%p",i,a));
994 fNSdigits[i]=0;
d1775029 995 }
996 }
c82862d3 997 else
998 {
999 AliDebug(1,Form("fSDigits already there = %p",fSDigits));
1000 }
d1775029 1001 }
c82862d3 1002
d1775029 1003 if (TreeS() && fSDigits && cS) {
c82862d3 1004 AliDebug(1,"Setting branch addresses");
d1775029 1005 for (int i=0; i<AliMUONConstants::NCh(); i++) {
1006 sprintf(branchname,"%sSDigits%d",GetName(),i+1);
1007 if (fSDigits) {
c82862d3 1008 AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
1009 TreeS(),i,branchname));
1010 branch = TreeS()->GetBranch(branchname);
1011 TClonesArray * sdigits = SDigits(i);
1012 if (branch) branch->SetAddress( &sdigits );
1013 else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
d1775029 1014 }
1015 }
1016 }
6309cf6e 1017
1018 //
1019 // Branch address for rawclusters, globaltrigger and local trigger tree
1020 if (TreeR() ) {
ce3f5e87 1021 if (fRawClusters == 0x0 && cRC) {
6309cf6e 1022 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
1023 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
1024 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
c82862d3 1025 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
1026 fNrawclusters[i]=0;
6309cf6e 1027 }
1028 }
ce3e25a8 1029 if (fLocalTrigger == 0x0 && cTC) {
6309cf6e 1030 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
1031 }
ce3e25a8 1032 if (fGlobalTrigger== 0x0 && cTC) {
c82862d3 1033 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
6309cf6e 1034 }
c82862d3 1035
6309cf6e 1036 }
cc87ebcd 1037 if ( TreeR() && fRawClusters && cRC && !strstr(cRC,"RCC")) {
6309cf6e 1038 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
1039 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
1040 if (fRawClusters) {
c82862d3 1041 branch = TreeR()->GetBranch(branchname);
1042 if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
1043 else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
6309cf6e 1044 }
1045 }
1046 }
ce3e25a8 1047 if ( TreeR() && fLocalTrigger && cTC) {
6309cf6e 1048 sprintf(branchname,"%sLocalTrigger",GetName());
1049 branch = TreeR()->GetBranch(branchname);
1050 if (branch) branch->SetAddress(&fLocalTrigger);
8c343c7c 1051 else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
6309cf6e 1052 }
ce3e25a8 1053 if ( TreeR() && fGlobalTrigger && cTC) {
6309cf6e 1054 sprintf(branchname,"%sGlobalTrigger",GetName());
1055 branch = TreeR()->GetBranch(branchname);
1056 if (branch) branch->SetAddress(&fGlobalTrigger);
8c343c7c 1057 else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
6309cf6e 1058 }
c82862d3 1059
8547965d 1060 if ( TreeT() ) {
61adb9bd 1061 if (fRecTracks == 0x0 && cRT) {
8547965d 1062 fRecTracks = new TClonesArray("AliMUONTrack",100);
1063 }
c82862d3 1064
8547965d 1065 }
dcd2690d 1066 if ( TreeT() && fRecTracks && cRT ) {
1067 sprintf(branchname,"%sTrack",GetName());
1068 branch = TreeT()->GetBranch(branchname);
1069 if (branch) branch->SetAddress(&fRecTracks);
8c343c7c 1070 else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
dcd2690d 1071 }
c82862d3 1072 // trigger tracks
276c44b7 1073 if ( TreeT() ) {
1074 if (fRecTriggerTracks == 0x0 && cRL) {
1075 fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
1076 }
c82862d3 1077
276c44b7 1078 }
1079 if ( TreeT() && fRecTriggerTracks && cRL ) {
1080 sprintf(branchname,"%sTriggerTrack",GetName());
1081 branch = TreeT()->GetBranch(branchname);
1082 if (branch) branch->SetAddress(&fRecTriggerTracks);
8c343c7c 1083 else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
276c44b7 1084 }
c82862d3 1085
1086
6309cf6e 1087}
c82862d3 1088
6309cf6e 1089//_____________________________________________________________________________
c82862d3 1090void
1091AliMUONData::Print(Option_t* opt) const
1092{
f0945e46 1093 // Dump object on screen
c82862d3 1094 TString options(opt);
1095 options.ToUpper();
1096
1097 if ( options.Contains("D") )
1098 {
1099 for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1100 {
1101 TClonesArray* digits = Digits(ich);
1102 Int_t ndigits = digits->GetEntriesFast();
1103 for ( Int_t id = 0; id < ndigits; ++id )
1104 {
1105 AliMUONDigit* digit =
1106 static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1107 digit->Print();
1108 }
1109 }
1110 }
1111
1112 if ( options.Contains("S") )
1113 {
1114 for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1115 {
1116 TClonesArray* digits = SDigits(ich);
1117 Int_t ndigits = digits->GetEntriesFast();
1118 for ( Int_t id = 0; id < ndigits; ++id )
1119 {
1120 AliMUONDigit* digit =
1121 static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1122 digit->Print();
1123 }
1124 }
1125 }
1126
3cdccc77 1127}