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