]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
Problem with AliMUNDisplay. Removing gAlice->GetMCApp()->AddHitList from AliMUONData
[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 // AliMUONData classes
18 // Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
19 // The classe makes the lik between the MUON data lists and the event trees from loaders
20 // Gines Martinez, Subatech,  September 2003
21 //
22
23 //Root includes
24 #include "TNamed.h"
25 //AliRoot include
26 #include "AliRun.h"
27 #include "AliMC.h" 
28 #include "AliLoader.h" 
29 #include "AliMUONConstants.h"
30 #include "AliMUONData.h"
31 #include "AliMUONDigit.h"
32 #include "AliMUONHit.h"
33 #include "AliMUONLocalTrigger.h"
34 #include "AliMUONGlobalTrigger.h"
35 #include "AliMUONRawCluster.h"
36 #include "AliMUONTrack.h"
37 #include "AliMUONTriggerTrack.h"
38 ClassImp(AliMUONData)
39  
40 //_____________________________________________________________________________
41 AliMUONData::AliMUONData():TNamed()
42 {
43   // Default constructor
44   fLoader        = 0x0;
45   fHits          = 0x0;    // One event in treeH per primary track
46   fDigits        = 0x0;  // One event in treeH per detection plane
47   fNdigits       = 0x0;
48   fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
49   fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
50   fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
51   fRecTracks     = 0x0;       
52   fRecTriggerTracks     = 0x0;       
53   fSplitLevel    = 0;
54 //default constructor
55 }
56 //_____________________________________________________________________________
57 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
58   TNamed(name,title)
59 {
60   // Constructor for AliMUONData
61   fLoader        = loader;
62   fHits          = 0x0;    // One event in treeH per primary track
63   fDigits        = 0x0;  // One event in treeH per detection plane
64   fNdigits       = 0x0;
65   fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
66   fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
67   fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
68   fRecTracks     = 0x0;    
69   fRecTriggerTracks     = 0x0;    
70   fNhits         = 0;
71   fNglobaltrigger =0;
72   fNlocaltrigger = 0;
73   fNrectracks    = 0;  
74   fNrectriggertracks    = 0;  
75   fSplitLevel    = 0;
76 //   fHits          = new TClonesArray("AliMUONHit",1000);
77 //   fNhits         = 0;
78 //   fDigits        = new TObjArray(AliMUONConstants::NCh());
79 //   fNdigits       = new Int_t[AliMUONConstants::NCh()];
80 //   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
81 //     fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
82 //     fNdigits[iDetectionPlane]=0;
83 //   }
84 //   fRawClusters   = new TObjArray(AliMUONConstants::NTrackingCh());
85 //   fNrawclusters  = new Int_t[AliMUONConstants::NTrackingCh()];
86 //   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
87 //     fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane); 
88 //     fNrawclusters[iDetectionPlane]=0;
89 //   }
90 //   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
91 //   fNglobaltrigger =0;
92 //   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);   
93 //   fNlocaltrigger = 0;
94 //   fRecTracks     = new TClonesArray("AliMUONTrack", 100);
95 //   fNrectracks    = 0; // really needed or GetEntriesFast sufficient ????
96
97
98   //default constructor
99 }
100 //_____________________________________________________________________________
101 AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
102 {
103   // Dummy copy constructor
104   ;
105 }
106 //_____________________________________________________________________________
107 AliMUONData::~AliMUONData()
108 {
109   // Destructor for AliMUONData
110   if (fHits) {
111     fHits->Delete();
112     delete fHits;
113   }
114   if (fDigits) {
115     fDigits->Delete();
116     delete fDigits;
117   }
118   if (fRawClusters) {
119     fRawClusters->Delete();
120     delete fRawClusters;
121   }
122   if (fGlobalTrigger){
123     fGlobalTrigger->Delete();
124     delete fGlobalTrigger;
125   }  
126   if (fLocalTrigger){
127     fLocalTrigger->Delete();
128     delete fLocalTrigger;
129   }
130   if (fRecTracks){
131     fRecTracks->Delete();
132     delete fRecTracks;
133   }
134   if (fRecTriggerTracks){
135     fRecTriggerTracks->Delete();
136     delete fRecTriggerTracks;
137   }
138   //detructor 
139 }
140 //_____________________________________________________________________________
141 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
142 {
143   //
144   // Add a MUON digit to the list of Digits of the detection plane id
145   //
146   TClonesArray &ldigits = * Digits(id) ; 
147   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
148 }
149 //_____________________________________________________________________________
150 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
151 {
152   //
153   // Add a MUON digit to the list of Digits of the detection plane id
154   //
155   TClonesArray &ldigits = * Digits(id) ; 
156   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
157 }
158 //_____________________________________________________________________________
159 void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
160                                    Int_t *singleUndef,
161                                    Int_t *pairUnlike, Int_t *pairLike)
162 {
163   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
164   TClonesArray &globalTrigger = *fGlobalTrigger;
165   new(globalTrigger[fNglobaltrigger++]) 
166     AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, pairLike);
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   TClonesArray &globalTrigger = *fGlobalTrigger;
173   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
174 }
175 //_____________________________________________________________________________
176 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
177                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
178                          Float_t tof, Float_t momentum, Float_t theta, 
179                          Float_t phi, Float_t length, Float_t destep)
180 {
181   // Add new hit to the hit list
182   TClonesArray &lhits = *fHits;
183   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
184                                   idpart, X, Y, Z, 
185                                   tof, momentum, theta, 
186                                   phi, length, destep);
187 }
188 //____________________________________________________________________________
189 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
190                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
191                          Float_t tof, Float_t momentum, Float_t theta, 
192                          Float_t phi, Float_t length, Float_t destep,
193                          Float_t Xref,Float_t Yref,Float_t Zref)
194 {
195  // Add new hit to the hit list
196   TClonesArray &lhits = *fHits;
197   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
198                                   idpart, X, Y, Z, 
199                                   tof, momentum, theta, 
200                                   phi, length, destep,
201                                   Xref,Yref,Zref);
202 }
203 //____________________________________________________________________________
204 void AliMUONData::AddHit(const AliMUONHit& hit)
205 {
206   TClonesArray &lhits = *fHits;
207   new(lhits[fNhits++]) AliMUONHit(hit);
208 }
209 //____________________________________________________________________________
210 void AliMUONData::AddLocalTrigger(Int_t *localtr)
211 {
212   // add a MUON Local Trigger to the list
213   TClonesArray &localTrigger = *fLocalTrigger;
214   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
215 }
216 //____________________________________________________________________________
217 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
218 {
219   // add a MUON Local Trigger to the list
220   TClonesArray &localTrigger = *fLocalTrigger;
221   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
222 }
223 //_____________________________________________________________________________
224 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
225 {
226   //
227   // Add a MUON rawcluster to the list in the detection plane id
228   //
229   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
230   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
231 }
232 //_____________________________________________________________________________
233 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
234 {
235   //
236   // Add a MUON rectrack
237   //
238   TClonesArray &lrectracks = *fRecTracks;
239   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
240   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
241 }
242 //_____________________________________________________________________________
243 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
244 {
245   //
246   // Add a MUON triggerrectrack
247   //
248   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
249   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
250   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
251 }
252
253 //____________________________________________________________________________
254 TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) 
255 {
256   //Getting List of Digits
257   if (fDigits)
258     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
259   else
260     return NULL;
261 }
262 //____________________________________________________________________________
263 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
264 {
265   // Checking if there are RawCluster Branches In TreeR
266   if (TreeR()==0x0) {
267     Error("TreeR","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::IsTriggerBranchesInTree()
281 {
282   // Checking if there are Trigger Branches In TreeR
283  if (TreeR()==0x0) {
284     Error("TreeR","No treeR in memory");
285     return kFALSE;
286   }
287   else {
288      char branchname[30];
289      sprintf(branchname,"%sLocalTrigger",GetName());
290      TBranch * branch = 0x0;
291      branch = TreeR()->GetBranch(branchname);
292      if (branch)  return kTRUE;
293      else return kFALSE;    
294   }
295 }
296 //____________________________________________________________________________
297 Bool_t   AliMUONData::IsTrackBranchesInTree()
298 {
299   // Checking if there are Track Branches In TreeT
300   if (TreeT()==0x0) {
301     Error("TreeT","No treeT in memory");
302     return kFALSE;
303   }
304   else {
305      char branchname[30];
306      sprintf(branchname,"%sTrack",GetName());
307      TBranch * branch = 0x0;
308      branch = TreeT()->GetBranch(branchname);
309      if (branch)  return kTRUE;
310      else return kFALSE;    
311   }
312 }
313 //____________________________________________________________________________
314 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
315 {
316   // Checking if there are TriggerTrack Branches In TreeT
317   if (TreeT()==0x0) {
318     Error("TreeT","No treeT in memory");
319     return kFALSE;
320   }
321   else {
322      char branchname[30];
323      sprintf(branchname,"%sTriggerTrack",GetName());
324      TBranch * branch = 0x0;
325      branch = TreeT()->GetBranch(branchname);
326      if (branch)  return kTRUE;
327      else return kFALSE;    
328   }
329 }
330 //____________________________________________________________________________
331 void AliMUONData::Fill(Option_t* option)
332 {
333   // Method to fill the trees
334   const char *cH   = strstr(option,"H");
335   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
336   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
337   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
338   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
339   const char *cRL = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
340
341   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
342   
343   char branchname[30];
344   TBranch * branch = 0x0;
345
346   //
347   // Filling TreeH
348   if ( TreeH() && cH ) {
349     TreeH()->Fill();
350   }  
351   //
352   // Filling TreeD
353   if ( TreeD() && cD) {
354     TreeD()->Fill();
355   }
356
357   //
358   // filling rawclusters
359   if ( TreeR()  && cRC ) {
360     if ( IsTriggerBranchesInTree() ) {
361       // Branch per branch filling
362       for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
363         sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
364         branch = TreeR()->GetBranch(branchname);
365         branch->Fill();
366       }
367     }
368     else  TreeR()->Fill();
369   }
370   
371  //
372   // filling trigger 
373   if ( TreeR()  && cGLT) {
374     if (IsRawClusterBranchesInTree()) {
375       // Branch per branch filling
376       sprintf(branchname,"%sLocalTrigger",GetName());
377       branch = TreeR()->GetBranch(branchname); 
378       branch->Fill();
379       sprintf(branchname,"%sGlobalTrigger",GetName());
380       branch = TreeR()->GetBranch(branchname);
381       branch->Fill();
382     }
383     else  TreeR()->Fill();
384   }
385   //
386   // filling tracks
387   if ( TreeT() && cRT ) {
388     if (IsTriggerTrackBranchesInTree()) {
389         sprintf(branchname,"%sTrack",GetName());  
390         branch = TreeT()->GetBranch(branchname);
391         branch->Fill();
392     }
393     else  TreeT()->Fill();
394   }
395   // filling trigger tracks
396   if ( TreeT() && cRL ) {
397     if (IsTrackBranchesInTree()) {
398         sprintf(branchname,"%sTriggerTrack",GetName());  
399         branch = TreeT()->GetBranch(branchname);
400         branch->Fill();
401     }    
402     else TreeT()->Fill();
403   }
404 //   if ( TreeT() && cRL ) {
405 //     sprintf(branchname,"%sTrackTrig",GetName());  
406 //     TreeT()->Fill();
407 //   }
408 }
409 //_____________________________________________________________________________
410 void AliMUONData::MakeBranch(Option_t* option)
411 {
412   //
413   // Create Tree branches for the MUON.
414   //
415   const Int_t kBufferSize = 4000;
416   char branchname[30];
417   
418
419   const char *cH   = strstr(option,"H");
420   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
421   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
422   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
423   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
424   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
425   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
426
427   TBranch * branch = 0x0;
428   
429   // Creating Branches for Hits
430   if (TreeH() && cH) {
431
432     if (fHits == 0x0)  {
433         fHits = new TClonesArray("AliMUONHit",1000);
434 //      if (gAlice->GetMCApp())
435 //        gAlice->GetMCApp()->AddHitList (fHits);
436     }
437             
438     fNhits = 0;
439     sprintf(branchname,"%sHits",GetName());  
440     branch = TreeH()->GetBranch(branchname);
441     if (branch) {  
442       Info("MakeBranch","Branch %s is already in tree.",GetName());
443       return ;
444     }
445     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
446     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
447   }  
448   
449   //Creating Branches for Digits
450   if (TreeD() && cD ) {
451     // one branch for digits per chamber
452     if (fDigits  == 0x0) {
453       fDigits  = new TObjArray(AliMUONConstants::NCh());
454       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
455         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
456       }
457     }
458     if (fNdigits == 0x0) {
459       fNdigits = new Int_t[AliMUONConstants::NCh()];
460       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
461         fNdigits[iDetectionPlane]=0;
462       }
463     }
464     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
465       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
466       branch = 0x0;
467       branch = TreeD()->GetBranch(branchname);
468       if (branch) {  
469         Info("MakeBranch","Branch %s is already in tree.",GetName());
470         return;
471       }
472       TClonesArray * digits = Digits(iDetectionPlane); 
473       branch = TreeD()->Branch(branchname, &digits, kBufferSize,1);
474       //Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
475       }
476   }
477   
478   if (TreeR() && cRC ) {
479     //  one branch for raw clusters per tracking detection plane
480     //        
481     Int_t i;
482     if (fRawClusters == 0x0) {
483       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
484       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
485         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",1000),i); 
486       }
487     }
488
489     if (fNrawclusters == 0x0) {
490       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
491       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
492         fNrawclusters[i]=0;
493       }
494     }
495     
496     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
497       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
498       branch = 0x0;
499       branch = TreeR()->GetBranch(branchname);
500       if (branch) {  
501         Info("MakeBranch","Branch %s is already in tree.",GetName());
502         return;
503       }
504       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
505       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
506     }
507   }
508
509   if (TreeR() && cGLT ) {
510     //
511     // one branch for global trigger
512     //
513     sprintf(branchname,"%sGlobalTrigger",GetName());
514     branch = 0x0;
515     
516     if (fGlobalTrigger == 0x0) {
517       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
518       fNglobaltrigger = 0;
519     }
520     branch = TreeR()->GetBranch(branchname);
521     if (branch) {  
522       Info("MakeBranch","Branch %s is already in tree.",GetName());
523       return ;
524     }
525     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
526     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
527     
528     //
529     // one branch for local trigger
530     //  
531     sprintf(branchname,"%sLocalTrigger",GetName());
532     branch = 0x0;
533     
534     if (fLocalTrigger == 0x0) {
535       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
536       fNlocaltrigger = 0;
537     }
538     branch = TreeR()->GetBranch(branchname);
539     if (branch) {  
540       Info("MakeBranch","Branch %s is already in tree.",GetName());
541       return;
542     }
543     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
544     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
545   }
546   
547   if (TreeT() && cRT ) {
548     if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",100);
549     fNrectracks = 0;
550     sprintf(branchname,"%sTrack",GetName());  
551     branch = TreeT()->GetBranch(branchname);
552     if (branch) {  
553       Info("MakeBranch","Branch %s is already in tree.",GetName());
554       return ;
555     }
556     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
557     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
558   }  
559 // trigger tracks
560   if (TreeT() && cRL ) {
561     if (fRecTriggerTracks == 0x0)  fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
562     fNrectriggertracks = 0;
563     sprintf(branchname,"%sTriggerTrack",GetName());  
564     branch = TreeT()->GetBranch(branchname);
565     if (branch) {  
566       Info("MakeBranch","Branch %s is already in tree.",GetName());
567       return ;
568     }
569     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
570     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
571   }  
572 }
573 //____________________________________________________________________________
574 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
575 {
576   // Getting Raw Clusters
577   if (fRawClusters) 
578     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
579   else
580     return NULL;
581 }
582 //____________________________________________________________________________
583 TClonesArray*  AliMUONData::LocalTrigger()
584 {
585   // Getting Local Trigger
586   if (fLocalTrigger) 
587     return ( (TClonesArray*) fLocalTrigger );
588   else
589     return NULL;
590 }
591 //____________________________________________________________________________
592 TClonesArray*  AliMUONData::GlobalTrigger()
593 {
594   // Getting Global Trigger
595   if (fGlobalTrigger) 
596     return ( (TClonesArray*) fGlobalTrigger );
597   else
598     return NULL;
599 }
600 //____________________________________________________________________________
601 void AliMUONData::ResetDigits()
602 {
603     //
604     // Reset number of digits and the digits array for this detector
605     //
606     if (fDigits == 0x0) return;
607     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
608       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear();
609       if (fNdigits)  fNdigits[i]=0;
610     }
611 }
612 //______________________________________________________________________________
613 void AliMUONData::ResetHits()
614 {
615   // Reset number of clusters and the cluster array for this detector
616   fNhits   = 0;
617   if (fHits) fHits->Clear();
618 }
619 //_______________________________________________________________________________
620 void AliMUONData::ResetRawClusters()
621 {
622     // Reset number of raw clusters and the raw clust array for this detector
623     //
624   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
625     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
626     if (fNrawclusters)  fNrawclusters[i]=0;
627   }
628 }
629 //_______________________________________________________________________________
630 void AliMUONData::ResetTrigger()
631 {
632   //  Reset Local and Global Trigger 
633   fNglobaltrigger = 0;
634   if (fGlobalTrigger) fGlobalTrigger->Clear();
635   fNlocaltrigger = 0;
636   if (fLocalTrigger) fLocalTrigger->Clear();
637 }
638 //____________________________________________________________________________
639 void AliMUONData::ResetRecTracks()
640 {
641   // Reset tracks information
642   fNrectracks = 0;
643   if (fRecTracks) fRecTracks->Clear();
644 }
645 //____________________________________________________________________________
646 void AliMUONData::ResetRecTriggerTracks()
647 {
648   // Reset tracks information
649   fNrectriggertracks = 0;
650   if (fRecTriggerTracks) fRecTriggerTracks->Clear();
651 }
652 //_____________________________________________________________________________
653 void AliMUONData::SetTreeAddress(Option_t* option)
654 {
655   //Setting Addresses to the events trees
656   const char *cH   = strstr(option,"H");
657   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
658   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
659   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
660   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
661   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
662   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
663   
664   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
665   char branchname[30];
666   TBranch * branch = 0x0;
667
668   //
669   // Branch address for hit tree
670   if ( TreeH() && cH ) {
671       if (fHits == 0x0) {
672         fHits     = new TClonesArray("AliMUONHit",1000);
673         if (gAlice->GetMCApp())
674           gAlice->GetMCApp()->AddHitList (fHits);
675     }
676     fNhits =0;
677   } 
678   if (TreeH() && fHits && cH) {
679     sprintf(branchname,"%sHits",GetName());  
680     branch = TreeH()->GetBranch(branchname);
681     if (branch) {
682       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
683       branch->SetAddress(&fHits);
684     }
685     else { //can be invoked before branch creation
686       Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
687     }
688   }
689   
690   //
691   // Branch address for digit tree
692   if ( TreeD() && cD) {
693     if (fDigits == 0x0) { 
694       fDigits = new TObjArray(AliMUONConstants::NCh());
695       fNdigits= new Int_t[AliMUONConstants::NCh()];
696       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
697         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
698         fNdigits[i]=0;
699       }
700     }
701   }
702
703   if (TreeD() && fDigits && cD) {
704     for (int i=0; i<AliMUONConstants::NCh(); i++) {
705       sprintf(branchname,"%sDigits%d",GetName(),i+1);
706       if (fDigits) {
707         branch = TreeD()->GetBranch(branchname);
708         TClonesArray * digits = Digits(i);
709         if (branch) branch->SetAddress( &digits );
710         else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
711       }
712     }
713   }
714   
715   //
716   // Branch address for rawclusters, globaltrigger and local trigger tree
717   if (TreeR() ) {
718     if (fRawClusters == 0x0 && cRC) {
719       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
720       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
721       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
722         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
723         fNrawclusters[i]=0;
724       }
725     }
726     if (fLocalTrigger == 0x0 && cGLT) {
727       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
728     }
729     if (fGlobalTrigger== 0x0 && cGLT) {
730         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
731     }
732
733   }
734   if ( TreeR()  && fRawClusters && cRC) {
735     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
736       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
737       if (fRawClusters) {
738         branch = TreeR()->GetBranch(branchname);
739         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
740         else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
741       }
742     }
743   }
744   if ( TreeR()  && fLocalTrigger && cGLT) {
745     sprintf(branchname,"%sLocalTrigger",GetName());
746     branch = TreeR()->GetBranch(branchname);
747     if (branch) branch->SetAddress(&fLocalTrigger);
748     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
749   }
750   if ( TreeR() && fGlobalTrigger && cGLT) {
751     sprintf(branchname,"%sGlobalTrigger",GetName());
752     branch = TreeR()->GetBranch(branchname);
753     if (branch) branch->SetAddress(&fGlobalTrigger);
754     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
755   }
756
757   if ( TreeT() ) {
758     if (fRecTracks == 0x0 && cRT)  {
759       fRecTracks  = new TClonesArray("AliMUONTrack",100);
760     }
761
762   }
763   if ( TreeT() && fRecTracks && cRT ) {
764     sprintf(branchname,"%sTrack",GetName());  
765     branch = TreeT()->GetBranch(branchname);
766     if (branch) branch->SetAddress(&fRecTracks);
767     else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
768   }
769 // trigger tracks
770   if ( TreeT() ) {
771     if (fRecTriggerTracks == 0x0 && cRL)  {
772       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
773     }
774
775   }
776   if ( TreeT() && fRecTriggerTracks && cRL ) {
777     sprintf(branchname,"%sTriggerTrack",GetName());  
778     branch = TreeT()->GetBranch(branchname);
779     if (branch) branch->SetAddress(&fRecTriggerTracks);
780     else Warning("SetTreeAddress","(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName());
781   }
782
783
784 }
785 //_____________________________________________________________________________