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