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