]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
Some additional protections
[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     if (fLoader->TreeD()) {
803       fLoader->TreeD()->GetEvent(0);
804       fCurrentEvent = event;
805     }
806   }
807 }
808
809 //____________________________________________________________________________
810 TClonesArray*  
811 AliMUONData::GlobalTrigger() const
812 {
813 /// Return the global trigger 
814
815   return fGlobalTrigger;
816 }
817
818 //____________________________________________________________________________
819 void AliMUONData::ResetDigits()
820 {
821 /// Reset number of digits and the digits array for this detector
822
823     if (fDigits == 0x0) return;
824     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
825       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear("C");
826       if (fNdigits)  fNdigits[i]=0;
827     }
828 }
829 //____________________________________________________________________________
830 void AliMUONData::ResetSDigits()
831 {
832 /// Reset number of Sdigits and the Sdigits array for this detector
833
834     if (fSDigits == 0x0) return;
835     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
836       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
837       if (fNSdigits)  fNSdigits[i]=0;
838     }
839 }
840 //______________________________________________________________________________
841 void AliMUONData::ResetHits()
842 {
843 /// Reset number of clusters and the cluster array for this detector
844
845   fNhits   = 0;
846   if (fHits) fHits->Clear();
847 }
848 //_______________________________________________________________________________
849 void AliMUONData::ResetRawClusters()
850 {
851 /// Reset number of raw clusters and the raw clust array for this detector
852
853   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
854     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
855     if (fNrawclusters)  fNrawclusters[i]=0;
856   }
857 }
858 //_______________________________________________________________________________
859 void AliMUONData::ResetTrigger()
860 {
861 /// Reset Local and Global Trigger 
862
863   fNglobaltrigger = 0;
864   if (fGlobalTrigger) fGlobalTrigger->Clear();
865   fNlocaltrigger = 0;
866   if (fLocalTrigger) fLocalTrigger->Clear();
867 }
868 //____________________________________________________________________________
869 void AliMUONData::ResetRecTracks()
870 {
871 /// Reset tracks information
872
873   fNrectracks = 0;
874   if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
875 }
876 //____________________________________________________________________________
877 void AliMUONData::ResetRecTriggerTracks()
878 {
879 /// Reset tracks information
880
881   fNrectriggertracks = 0;
882   if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
883 }
884 //_____________________________________________________________________________
885 void AliMUONData::SetTreeAddress(Option_t* option)
886 {
887 /// Setting Addresses to the events trees
888
889   const char *cH   = strstr(option,"H");
890   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
891   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
892   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
893   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
894   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
895   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
896   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
897                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
898   
899   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
900   char branchname[30];
901   TBranch * branch = 0x0;
902   
903   AliDebug(1,Form("option=%s",option));
904   //
905   // Branch address for hit tree
906   if ( TreeH() && cH ) {
907     if (fHits == 0x0) {
908       fHits     = new TClonesArray("AliMUONHit",1000);
909       //        if (gAlice->GetMCApp())
910       //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
911     }
912     fNhits =0;
913   } 
914   if (TreeH() && fHits && cH) {
915     sprintf(branchname,"%sHits",GetName());  
916     branch = TreeH()->GetBranch(branchname);
917     if (branch) {
918       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
919       branch->SetAddress(&fHits);
920     }
921     else { //can be invoked before branch creation
922       AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
923     }
924   }
925   
926   //
927   // Branch address for digit tree
928   if ( TreeD() ) {      
929     if (fDigits == 0x0 && cD) {
930       fDigits = new TObjArray(AliMUONConstants::NCh());
931       fNdigits= new Int_t[AliMUONConstants::NCh()];
932       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
933         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
934         fNdigits[i]=0;
935       }
936     }
937     if (fLocalTrigger == 0x0 && cGLT) {
938       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
939     }
940     if (fGlobalTrigger== 0x0 && cGLT) {
941       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
942     }
943   }
944   
945   if (TreeD() && fDigits && cD) {
946     for (int i=0; i<AliMUONConstants::NCh(); i++) {
947       sprintf(branchname,"%sDigits%d",GetName(),i+1);
948       if (fDigits) {
949         branch = TreeD()->GetBranch(branchname);
950         TClonesArray * digits = Digits(i);
951         if (branch) {
952           branch->SetAddress( &digits );
953         }
954         else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
955       }
956     }
957   }
958   if ( TreeD()  && fLocalTrigger && cGLT) {
959     sprintf(branchname,"%sLocalTrigger",GetName());
960     branch = TreeD()->GetBranch(branchname);
961     if (branch) branch->SetAddress(&fLocalTrigger);
962     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
963   }
964   if ( TreeD() && fGlobalTrigger && cGLT) {
965     sprintf(branchname,"%sGlobalTrigger",GetName());
966     branch = TreeD()->GetBranch(branchname);
967     if (branch) branch->SetAddress(&fGlobalTrigger);
968     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
969   }
970   
971   //
972   // Branch address for Sdigit tree
973   if ( TreeS() && cS) 
974   {
975     if (fSDigits == 0x0) 
976     { 
977       AliDebug(1,"Creating fSDigits TObjArray");
978       fSDigits = new TObjArray(AliMUONConstants::NCh());
979       fNSdigits= new Int_t[AliMUONConstants::NCh()];
980       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) 
981       {
982         TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
983         fSDigits->AddAt(a,i);
984         AliDebug(1,Form("fSDigits[%d]=%p",i,a));
985         fNSdigits[i]=0;
986       }
987     }
988     else
989     {
990       AliDebug(1,Form("fSDigits already there = %p",fSDigits));
991     }
992   }
993   
994   if (TreeS() && fSDigits && cS) {
995     AliDebug(1,"Setting branch addresses");
996     for (int i=0; i<AliMUONConstants::NCh(); i++) {
997       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
998       if (fSDigits) {
999         AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
1000                         TreeS(),i,branchname));
1001         branch = TreeS()->GetBranch(branchname);
1002         TClonesArray * sdigits = SDigits(i);
1003         if (branch) branch->SetAddress( &sdigits );
1004         else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
1005       }
1006     }
1007   }
1008   
1009   //
1010   // Branch address for rawclusters, globaltrigger and local trigger tree
1011   if (TreeR() ) {
1012     if (fRawClusters == 0x0 && cRC) {
1013       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
1014       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
1015       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
1016         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
1017         fNrawclusters[i]=0;
1018       }
1019     }
1020     if (fLocalTrigger == 0x0 && cTC) {
1021       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
1022     }
1023     if (fGlobalTrigger== 0x0 && cTC) {
1024       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
1025     }
1026     
1027   }
1028   if ( TreeR()  && fRawClusters && cRC && !strstr(cRC,"RCC")) {
1029     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
1030       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
1031       if (fRawClusters) {
1032         branch = TreeR()->GetBranch(branchname);
1033         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
1034         else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
1035       }
1036     }
1037   }
1038   if ( TreeR()  && fLocalTrigger && cTC) {
1039     sprintf(branchname,"%sLocalTrigger",GetName());
1040     branch = TreeR()->GetBranch(branchname);
1041     if (branch) branch->SetAddress(&fLocalTrigger);
1042     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
1043   }
1044   if ( TreeR() && fGlobalTrigger && cTC) {
1045     sprintf(branchname,"%sGlobalTrigger",GetName());
1046     branch = TreeR()->GetBranch(branchname);
1047     if (branch) branch->SetAddress(&fGlobalTrigger);
1048     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
1049   }
1050   
1051   if ( TreeT() ) {
1052     if (fRecTracks == 0x0 && cRT)  {
1053       fRecTracks  = new TClonesArray("AliMUONTrack",100);
1054     }
1055     
1056   }
1057   if ( TreeT() && fRecTracks && cRT ) {
1058     sprintf(branchname,"%sTrack",GetName());  
1059     branch = TreeT()->GetBranch(branchname);
1060     if (branch) branch->SetAddress(&fRecTracks);
1061     else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
1062   }
1063   // trigger tracks
1064   if ( TreeT() ) {
1065     if (fRecTriggerTracks == 0x0 && cRL)  {
1066       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
1067     }
1068     
1069   }
1070   if ( TreeT() && fRecTriggerTracks && cRL ) {
1071     sprintf(branchname,"%sTriggerTrack",GetName());  
1072     branch = TreeT()->GetBranch(branchname);
1073     if (branch) branch->SetAddress(&fRecTriggerTracks);
1074     else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
1075   }
1076   
1077   
1078 }
1079
1080 //_____________________________________________________________________________
1081 void
1082 AliMUONData::Print(Option_t* opt) const
1083 {
1084 /// Dump object on screen
1085
1086   TString options(opt);
1087   options.ToUpper();
1088   
1089   if ( options.Contains("D") )
1090   {
1091     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1092     {
1093       TClonesArray* digits = Digits(ich);
1094       Int_t ndigits = digits->GetEntriesFast();
1095       for ( Int_t id = 0; id < ndigits; ++id )
1096       {
1097         AliMUONDigit* digit = 
1098           static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1099         digit->Print();
1100       }
1101     }
1102   }
1103   
1104   if ( options.Contains("S") )
1105   {
1106     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1107     {
1108       TClonesArray* digits = SDigits(ich);
1109       Int_t ndigits = digits->GetEntriesFast();
1110       for ( Int_t id = 0; id < ndigits; ++id )
1111       {
1112         AliMUONDigit* digit = 
1113         static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1114         digit->Print();
1115       }
1116     }
1117   }
1118   
1119 }