]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
- Revised comments and adapted them for Doxygen
[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 "AliMUONDigit.h"
31 #include "AliMUONGlobalTrigger.h"
32 #include "AliMUONHit.h"
33 #include "AliMUONLocalTrigger.h"
34 #include "AliMUONRawCluster.h"
35 #include "AliMUONTrack.h"
36 #include "AliMUONTriggerTrack.h"
37 #include "AliRunLoader.h"
38 #include "TArrayI.h"
39 #include "TString.h"
40
41 /// \cond CLASSIMP
42 ClassImp(AliMUONData)
43 /// \endcond
44  
45 //_____________________________________________________________________________
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),
65     fSplitLevel(0),
66     fCurrentEvent(-1)
67 {
68   // Default constructor
69 }
70 //_____________________________________________________________________________
71 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
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),
90     fSplitLevel(0),
91     fCurrentEvent(-1)
92 {
93 /// Standard constructor
94 }
95
96 //_____________________________________________________________________________
97 AliMUONData::~AliMUONData()
98 {
99 /// Destructor for AliMUONData
100   if (fHits) {
101     fHits->Delete();
102     delete fHits;
103   }
104   
105   if (fDigits) {
106     fDigits->Delete();
107     delete fDigits;
108   }
109   if (fSDigits) {
110     fSDigits->Delete();
111     delete fSDigits;
112   }
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   }
125   if (fRecTracks){
126     fRecTracks->Delete();
127     delete fRecTracks;
128   }
129   if (fRecTriggerTracks){
130     fRecTriggerTracks->Delete();
131     delete fRecTriggerTracks;
132   }
133 }
134
135 //_____________________________________________________________________________
136 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
137 {
138 /// Add a MUON digit to the list of Digits of the detection plane id
139  
140   TClonesArray &ldigits = * Digits(id) ; 
141   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
142 }
143 //_____________________________________________________________________________
144 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
145 {
146 /// Add a MUON digit to the list of Digits of the detection plane id
147
148   TClonesArray &ldigits = * Digits(id) ; 
149   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
150 }
151 //_____________________________________________________________________________
152 void AliMUONData::AddSDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *sdigits)
153 {
154 /// Add a MUON Sdigit to the list of SDigits of the detection plane id
155
156   TClonesArray &lSdigits = * SDigits(id) ; 
157   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(tracks,charges,sdigits);
158 }
159 //_____________________________________________________________________________
160 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
161 {
162 /// Add a MUON Sdigit to the list of SDigits of the detection plane id
163
164   TClonesArray &lSdigits = * SDigits(id) ; 
165   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
166 }
167
168 //_____________________________________________________________________________
169 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
170 {
171 /// Add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
172
173   TClonesArray &globalTrigger = *fGlobalTrigger;
174   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
175 }
176 //____________________________________________________________________________
177 void 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, 
180                          Float_t phi, Float_t length, Float_t destep,
181                          Float_t Xref,Float_t Yref,Float_t Zref)
182 {
183 /// Add new hit to the hit list
184
185   TClonesArray &lhits = *fHits;
186   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
187                                   idpart, X, Y, Z, 
188                                   tof, momentum, theta, 
189                                   phi, length, destep,
190                                   Xref,Yref,Zref);
191 }
192 //____________________________________________________________________________
193 void AliMUONData::AddHit2(Int_t fIshunt, Int_t track, Int_t detElemId, 
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 {
199  // Add new hit to the hit list
200
201   TClonesArray &lhits = *fHits;
202   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, detElemId, 
203                                   idpart, X, Y, Z, 
204                                   tof, momentum, theta, 
205                                   phi, length, destep,
206                                   Xref,Yref,Zref, true);
207 }
208 //____________________________________________________________________________
209 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
210 {
211 /// add a MUON Local Trigger to the list
212
213   TClonesArray &localTrigger = *fLocalTrigger;
214   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
215 }
216 //_____________________________________________________________________________
217 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
218 {
219 /// Add a MUON rawcluster to the list in the detection plane id
220
221   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
222   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
223 }
224 //_____________________________________________________________________________
225 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
226 {
227 /// Add a MUON rectrack
228
229   TClonesArray &lrectracks = *fRecTracks;
230   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
231 }
232 //_____________________________________________________________________________
233 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
234 {
235 /// Add a MUON triggerrectrack
236
237   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
238   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
239 }
240 //____________________________________________________________________________
241 TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) const
242 {
243 /// Getting List of Digits
244
245   if (fDigits)
246     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
247   else
248     return NULL;
249 }
250 //____________________________________________________________________________
251 TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) const
252 {
253 /// Getting List of SDigits
254
255   if (fSDigits)
256     return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
257   else
258     return NULL;
259 }
260 //____________________________________________________________________________
261 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
262 {
263 /// Checking if there are RawCluster Branches In TreeR
264
265   if (TreeR()==0x0) {
266     AliError("No treeR in memory");
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 //____________________________________________________________________________
279 Bool_t   AliMUONData::IsDigitsBranchesInTree()
280 {
281 /// Checking if there are RawCluster Branches In TreeR
282
283   if (TreeD()==0x0) {
284     AliError("No treeD in memory");
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 //____________________________________________________________________________
297 Bool_t   AliMUONData::IsTriggerBranchesInTree()
298 {
299 /// Checking if there are Trigger Branches In TreeR
300  if (TreeR()==0x0) {
301     AliError("No treeR in memory");
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 }
313 //____________________________________________________________________________
314 Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
315 {
316 /// Checking if there are Trigger Branches In TreeR
317  if (TreeD()==0x0) {
318     AliError("No treeD in memory");
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
331 //____________________________________________________________________________
332 Bool_t   AliMUONData::IsTrackBranchesInTree()
333 {
334 /// Checking if there are Track Branches In TreeT
335   if (TreeT()==0x0) {
336     AliError("No treeT in memory");
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 //____________________________________________________________________________
349 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
350 {
351 /// Checking if there are TriggerTrack 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,"%sTriggerTrack",GetName());
359      TBranch * branch = 0x0;
360      branch = TreeT()->GetBranch(branchname);
361      if (branch)  return kTRUE;
362      else return kFALSE;    
363   }
364 }
365 //____________________________________________________________________________
366 void AliMUONData::Fill(Option_t* option)
367 {
368 /// Method to fill the trees
369   const char *cH   = strstr(option,"H");
370   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
371   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
372   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
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
375   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
376   const char *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
377
378   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
379   
380   char branchname[30];
381   TBranch * branch = 0x0;
382
383   // Filling TreeH
384   if ( TreeH() && cH ) 
385   {
386     TreeH()->Fill();
387   }  
388  
389   // Filling TreeD
390
391   if ( TreeD() && cD && cGLT )
392   {
393     // Writing digits and (global+local) trigger at once.
394     TreeD()->Fill();
395   }
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();
412       }
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.
432
433   // Filling TreeS
434   if ( TreeS() && cS) 
435   {
436     TreeS()->Fill();
437   }
438
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       {
451       // Branch per branch filling
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();
480       }
481     }
482   }
483
484   // Filling TreeT
485   
486   if ( TreeT() && cRT && cRL )
487   {
488     TreeT()->Fill();
489   }
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       }
518     }
519   }
520 }
521
522 //_____________________________________________________________________________
523 void AliMUONData::MakeBranch(Option_t* option)
524 {
525 /// Create Tree branches for the MUON.
526
527   const Int_t kBufferSize = 4000;
528   char branchname[30];
529   
530   
531   const char *cH   = strstr(option,"H");
532   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
533   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
534   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
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
537   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
538   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
539                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
540   
541   TBranch * branch = 0x0;
542   
543   // Creating Branches for Hits
544   if (TreeH() && cH) {
545     
546     if (fHits == 0x0)  {
547       fHits = new TClonesArray("AliMUONHit",1000);
548       //        if (gAlice->GetMCApp())
549       //          gAlice->GetMCApp()->AddHitList (fHits);
550     }
551     
552     fNhits = 0;
553     sprintf(branchname,"%sHits",GetName());  
554     branch = TreeH()->GetBranch(branchname);
555     if (branch) {  
556       AliInfo(Form("MakeBranch","Branch %s is already in tree.",branchname));
557       return ;
558     }
559     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
560     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
561   }  
562   
563   //Creating Branches for Digits
564   TTree* treeD = 0x0;
565   if ( cD || cGLT )
566   {
567     treeD = TreeD();
568   }
569
570   if ( treeD && cD ) 
571   {
572     // one branch for digits per chamber
573     if (fDigits  == 0x0) 
574     {
575       fDigits  = new TObjArray(AliMUONConstants::NCh());
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); 
581       }
582     }
583     if (fNdigits == 0x0) 
584     {
585       fNdigits = new Int_t[AliMUONConstants::NCh()];
586       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
587       {
588         fNdigits[iDetectionPlane]=0;
589       }
590     }
591     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
592     {
593       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
594       branch = treeD->GetBranch(branchname);
595       if (branch) 
596       {  
597         AliInfo(Form("Branch %s is already in tree.",branchname));
598         return;
599       }
600       TClonesArray * digits = Digits(iDetectionPlane); 
601       branch = treeD->Branch(branchname, &digits, kBufferSize,1);
602     }
603   }
604   
605   if ( treeD && cGLT ) 
606   {
607     //
608     // one branch for global trigger
609     //
610     sprintf(branchname,"%sGlobalTrigger",GetName());
611     
612     if (fGlobalTrigger == 0x0) 
613     {
614       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
615       fNglobaltrigger = 0;
616     }
617     branch = treeD->GetBranch(branchname);
618     if (branch) 
619     {  
620       AliInfo(Form("Branch GlobalTrigger is already in treeD."));
621       return ;
622     }
623     branch = treeD->Branch(branchname, &fGlobalTrigger, kBufferSize);
624
625     //
626     // one branch for local trigger
627     //  
628     sprintf(branchname,"%sLocalTrigger",GetName());
629     branch = 0x0;
630     
631     if (fLocalTrigger == 0x0) 
632     {
633       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
634       fNlocaltrigger = 0;
635     }
636     branch = treeD->GetBranch(branchname);
637     if (branch) 
638     {  
639       AliInfo(Form("Branch LocalTrigger is already in treeD."));
640       return;
641     }
642     branch = treeD->Branch(branchname, &fLocalTrigger, kBufferSize);
643   }
644     
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++) {
651         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
652         tca->SetOwner();
653         fSDigits->AddAt(tca,iDetectionPlane); 
654       }
655     }
656     if (fNSdigits == 0x0) {
657       fNSdigits = new Int_t[AliMUONConstants::NCh()];
658       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
659         fNSdigits[iDetectionPlane]=0;
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) {  
667         AliInfo(Form("Branch %s is already in tree.",branchname));
668         return;
669       }
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);
673     }
674   }
675   
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());
682       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
683         TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
684         tca->SetOwner();
685         fRawClusters->AddAt(tca,i); 
686       }
687     }
688     
689     if (fNrawclusters == 0x0) {
690       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
691       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
692         fNrawclusters[i]=0;
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) {  
701         AliInfo(Form("Branch %s is already in tree.",branchname));
702         return;
703       }
704       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
705       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
706     }
707   }
708   
709   if (TreeR() && cTC ) {
710     //
711     // one branch for global trigger
712     //
713     sprintf(branchname,"%sGlobalTrigger",GetName());
714     branch = 0x0;
715     
716     if (fGlobalTrigger == 0x0) {
717       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
718       fNglobaltrigger = 0;
719     }
720     branch = TreeR()->GetBranch(branchname);
721     if (branch) {  
722       AliInfo(Form("Branch GlobalTrigger is already in treeR."));
723       return ;
724     }
725     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
726     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
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) {  
740       AliInfo(Form("Branch LocalTrigger is already in treeR."));
741       return;
742     }
743     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
744     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
745   }
746   
747   if (TreeT() && cRT ) {
748     if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",100);
749     fNrectracks = 0;
750     sprintf(branchname,"%sTrack",GetName());  
751     branch = TreeT()->GetBranch(branchname);
752     if (branch) {  
753       AliInfo(Form("Branch %s is already in tree.",GetName()));
754       return ;
755     }
756     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
757     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
758   }  
759   // trigger tracks
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) {  
766       AliInfo(Form("Branch %s is already in tree.",GetName()));
767       return ;
768     }
769     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
770     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
771   }  
772 }
773 //____________________________________________________________________________
774 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
775 {
776 /// Getting Raw Clusters
777
778   if (fRawClusters) 
779     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
780   else
781     return NULL;
782 }
783
784 //____________________________________________________________________________
785 TClonesArray*  
786 AliMUONData::LocalTrigger() const
787 {
788 /// Getting local trigger
789
790   return fLocalTrigger;
791 }
792
793 //____________________________________________________________________________
794 void
795 AliMUONData::GetDigits() const 
796 {
797 /// Load the digits from TreeD for the current event.
798
799   Int_t event = fLoader->GetRunLoader()->GetEventNumber();
800   if ( fCurrentEvent != event )
801   {
802     fLoader->TreeD()->GetEvent(0);
803     fCurrentEvent = event;
804   }
805 }
806
807 //____________________________________________________________________________
808 TClonesArray*  
809 AliMUONData::GlobalTrigger() const
810 {
811 /// Return the global trigger 
812
813   return fGlobalTrigger;
814 }
815
816 //____________________________________________________________________________
817 void AliMUONData::ResetDigits()
818 {
819 /// Reset number of digits and the digits array for this detector
820
821     if (fDigits == 0x0) return;
822     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
823       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear("C");
824       if (fNdigits)  fNdigits[i]=0;
825     }
826 }
827 //____________________________________________________________________________
828 void AliMUONData::ResetSDigits()
829 {
830 /// Reset number of Sdigits and the Sdigits array for this detector
831
832     if (fSDigits == 0x0) return;
833     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
834       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
835       if (fNSdigits)  fNSdigits[i]=0;
836     }
837 }
838 //______________________________________________________________________________
839 void AliMUONData::ResetHits()
840 {
841 /// Reset number of clusters and the cluster array for this detector
842
843   fNhits   = 0;
844   if (fHits) fHits->Clear();
845 }
846 //_______________________________________________________________________________
847 void AliMUONData::ResetRawClusters()
848 {
849 /// Reset number of raw clusters and the raw clust array for this detector
850
851   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
852     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
853     if (fNrawclusters)  fNrawclusters[i]=0;
854   }
855 }
856 //_______________________________________________________________________________
857 void AliMUONData::ResetTrigger()
858 {
859 /// Reset Local and Global Trigger 
860
861   fNglobaltrigger = 0;
862   if (fGlobalTrigger) fGlobalTrigger->Clear();
863   fNlocaltrigger = 0;
864   if (fLocalTrigger) fLocalTrigger->Clear();
865 }
866 //____________________________________________________________________________
867 void AliMUONData::ResetRecTracks()
868 {
869 /// Reset tracks information
870
871   fNrectracks = 0;
872   if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
873 }
874 //____________________________________________________________________________
875 void AliMUONData::ResetRecTriggerTracks()
876 {
877 /// Reset tracks information
878
879   fNrectriggertracks = 0;
880   if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
881 }
882 //_____________________________________________________________________________
883 void AliMUONData::SetTreeAddress(Option_t* option)
884 {
885 /// Setting Addresses to the events trees
886
887   const char *cH   = strstr(option,"H");
888   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
889   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
890   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
891   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
892   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
893   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
894   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
895                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
896   
897   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
898   char branchname[30];
899   TBranch * branch = 0x0;
900   
901   AliDebug(1,Form("option=%s",option));
902   //
903   // Branch address for hit tree
904   if ( TreeH() && cH ) {
905     if (fHits == 0x0) {
906       fHits     = new TClonesArray("AliMUONHit",1000);
907       //        if (gAlice->GetMCApp())
908       //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
909     }
910     fNhits =0;
911   } 
912   if (TreeH() && fHits && cH) {
913     sprintf(branchname,"%sHits",GetName());  
914     branch = TreeH()->GetBranch(branchname);
915     if (branch) {
916       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
917       branch->SetAddress(&fHits);
918     }
919     else { //can be invoked before branch creation
920       AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
921     }
922   }
923   
924   //
925   // Branch address for digit tree
926   if ( TreeD() ) {      
927     if (fDigits == 0x0 && cD) {
928       fDigits = new TObjArray(AliMUONConstants::NCh());
929       fNdigits= new Int_t[AliMUONConstants::NCh()];
930       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
931         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
932         fNdigits[i]=0;
933       }
934     }
935     if (fLocalTrigger == 0x0 && cGLT) {
936       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
937     }
938     if (fGlobalTrigger== 0x0 && cGLT) {
939       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
940     }
941   }
942   
943   if (TreeD() && fDigits && cD) {
944     for (int i=0; i<AliMUONConstants::NCh(); i++) {
945       sprintf(branchname,"%sDigits%d",GetName(),i+1);
946       if (fDigits) {
947         branch = TreeD()->GetBranch(branchname);
948         TClonesArray * digits = Digits(i);
949         if (branch) {
950           branch->SetAddress( &digits );
951         }
952         else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
953       }
954     }
955   }
956   if ( TreeD()  && fLocalTrigger && cGLT) {
957     sprintf(branchname,"%sLocalTrigger",GetName());
958     branch = TreeD()->GetBranch(branchname);
959     if (branch) branch->SetAddress(&fLocalTrigger);
960     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
961   }
962   if ( TreeD() && fGlobalTrigger && cGLT) {
963     sprintf(branchname,"%sGlobalTrigger",GetName());
964     branch = TreeD()->GetBranch(branchname);
965     if (branch) branch->SetAddress(&fGlobalTrigger);
966     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
967   }
968   
969   //
970   // Branch address for Sdigit tree
971   if ( TreeS() && cS) 
972   {
973     if (fSDigits == 0x0) 
974     { 
975       AliDebug(1,"Creating fSDigits TObjArray");
976       fSDigits = new TObjArray(AliMUONConstants::NCh());
977       fNSdigits= new Int_t[AliMUONConstants::NCh()];
978       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) 
979       {
980         TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
981         fSDigits->AddAt(a,i);
982         AliDebug(1,Form("fSDigits[%d]=%p",i,a));
983         fNSdigits[i]=0;
984       }
985     }
986     else
987     {
988       AliDebug(1,Form("fSDigits already there = %p",fSDigits));
989     }
990   }
991   
992   if (TreeS() && fSDigits && cS) {
993     AliDebug(1,"Setting branch addresses");
994     for (int i=0; i<AliMUONConstants::NCh(); i++) {
995       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
996       if (fSDigits) {
997         AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
998                         TreeS(),i,branchname));
999         branch = TreeS()->GetBranch(branchname);
1000         TClonesArray * sdigits = SDigits(i);
1001         if (branch) branch->SetAddress( &sdigits );
1002         else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
1003       }
1004     }
1005   }
1006   
1007   //
1008   // Branch address for rawclusters, globaltrigger and local trigger tree
1009   if (TreeR() ) {
1010     if (fRawClusters == 0x0 && cRC) {
1011       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
1012       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
1013       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
1014         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
1015         fNrawclusters[i]=0;
1016       }
1017     }
1018     if (fLocalTrigger == 0x0 && cTC) {
1019       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
1020     }
1021     if (fGlobalTrigger== 0x0 && cTC) {
1022       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
1023     }
1024     
1025   }
1026   if ( TreeR()  && fRawClusters && cRC && !strstr(cRC,"RCC")) {
1027     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
1028       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
1029       if (fRawClusters) {
1030         branch = TreeR()->GetBranch(branchname);
1031         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
1032         else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
1033       }
1034     }
1035   }
1036   if ( TreeR()  && fLocalTrigger && cTC) {
1037     sprintf(branchname,"%sLocalTrigger",GetName());
1038     branch = TreeR()->GetBranch(branchname);
1039     if (branch) branch->SetAddress(&fLocalTrigger);
1040     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
1041   }
1042   if ( TreeR() && fGlobalTrigger && cTC) {
1043     sprintf(branchname,"%sGlobalTrigger",GetName());
1044     branch = TreeR()->GetBranch(branchname);
1045     if (branch) branch->SetAddress(&fGlobalTrigger);
1046     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
1047   }
1048   
1049   if ( TreeT() ) {
1050     if (fRecTracks == 0x0 && cRT)  {
1051       fRecTracks  = new TClonesArray("AliMUONTrack",100);
1052     }
1053     
1054   }
1055   if ( TreeT() && fRecTracks && cRT ) {
1056     sprintf(branchname,"%sTrack",GetName());  
1057     branch = TreeT()->GetBranch(branchname);
1058     if (branch) branch->SetAddress(&fRecTracks);
1059     else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
1060   }
1061   // trigger tracks
1062   if ( TreeT() ) {
1063     if (fRecTriggerTracks == 0x0 && cRL)  {
1064       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
1065     }
1066     
1067   }
1068   if ( TreeT() && fRecTriggerTracks && cRL ) {
1069     sprintf(branchname,"%sTriggerTrack",GetName());  
1070     branch = TreeT()->GetBranch(branchname);
1071     if (branch) branch->SetAddress(&fRecTriggerTracks);
1072     else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
1073   }
1074   
1075   
1076 }
1077
1078 //_____________________________________________________________________________
1079 void
1080 AliMUONData::Print(Option_t* opt) const
1081 {
1082 /// Dump object on screen
1083
1084   TString options(opt);
1085   options.ToUpper();
1086   
1087   if ( options.Contains("D") )
1088   {
1089     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1090     {
1091       TClonesArray* digits = Digits(ich);
1092       Int_t ndigits = digits->GetEntriesFast();
1093       for ( Int_t id = 0; id < ndigits; ++id )
1094       {
1095         AliMUONDigit* digit = 
1096           static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1097         digit->Print();
1098       }
1099     }
1100   }
1101   
1102   if ( options.Contains("S") )
1103   {
1104     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1105     {
1106       TClonesArray* digits = SDigits(ich);
1107       Int_t ndigits = digits->GetEntriesFast();
1108       for ( Int_t id = 0; id < ndigits; ++id )
1109       {
1110         AliMUONDigit* digit = 
1111         static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1112         digit->Print();
1113       }
1114     }
1115   }
1116   
1117 }