]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
Casuality cuts added (Yu.Belikov)
[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 treeD per detection plane
47   fSDigits       = 0x0;    // One event in treeS per detection plane
48   fNdigits       = 0x0;
49   fNSdigits      = 0x0;
50   fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
51   fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
52   fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
53   fRecTracks     = 0x0;       
54   fRecTriggerTracks     = 0x0;       
55   fSplitLevel    = 0;
56 //default constructor
57 }
58 //_____________________________________________________________________________
59 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
60   TNamed(name,title)
61 {
62   // Constructor for AliMUONData
63   fLoader        = loader;
64   fHits          = 0x0;    // One event in treeH per primary track
65   fDigits        = 0x0;    // One event in treeD per detection plane
66   fSDigits       = 0x0;    // One event in treeS per detection plane
67   fNdigits       = 0x0;
68   fNSdigits      = 0x0;
69   fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
70   fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
71   fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
72   fRecTracks     = 0x0;    
73   fRecTriggerTracks     = 0x0;    
74   fNhits         = 0;
75   fNglobaltrigger =0;
76   fNlocaltrigger = 0;
77   fNrectracks    = 0;  
78   fNrectriggertracks    = 0;  
79   fSplitLevel    = 0;
80 //   fHits          = new TClonesArray("AliMUONHit",1000);
81 //   fNhits         = 0;
82 //   fDigits        = new TObjArray(AliMUONConstants::NCh());
83 //   fNdigits       = new Int_t[AliMUONConstants::NCh()];
84 //   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
85 //     fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
86 //     fNdigits[iDetectionPlane]=0;
87 //   }
88 //   fRawClusters   = new TObjArray(AliMUONConstants::NTrackingCh());
89 //   fNrawclusters  = new Int_t[AliMUONConstants::NTrackingCh()];
90 //   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
91 //     fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane); 
92 //     fNrawclusters[iDetectionPlane]=0;
93 //   }
94 //   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
95 //   fNglobaltrigger =0;
96 //   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);   
97 //   fNlocaltrigger = 0;
98 //   fRecTracks     = new TClonesArray("AliMUONTrack", 100);
99 //   fNrectracks    = 0; // really needed or GetEntriesFast sufficient ????
100
101
102   //default constructor
103 }
104 //_____________________________________________________________________________
105 AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
106 {
107   // Dummy copy constructor
108   ;
109 }
110 //_____________________________________________________________________________
111 AliMUONData::~AliMUONData()
112 {
113   // Destructor for AliMUONData
114   if (fHits) {
115     fHits->Delete();
116     delete fHits;
117   }
118   if (fDigits) {
119     fDigits->Delete();
120     delete fDigits;
121   }
122   if (fSDigits) {
123     fSDigits->Delete();
124     delete fSDigits;
125   }
126   if (fRawClusters) {
127     fRawClusters->Delete();
128     delete fRawClusters;
129   }
130   if (fGlobalTrigger){
131     fGlobalTrigger->Delete();
132     delete fGlobalTrigger;
133   }  
134   if (fLocalTrigger){
135     fLocalTrigger->Delete();
136     delete fLocalTrigger;
137   }
138   if (fRecTracks){
139     fRecTracks->Delete();
140     delete fRecTracks;
141   }
142   if (fRecTriggerTracks){
143     fRecTriggerTracks->Delete();
144     delete fRecTriggerTracks;
145   }
146   //detructor 
147 }
148 //_____________________________________________________________________________
149 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
150 {
151   //
152   // Add a MUON digit to the list of Digits of the detection plane id
153   //
154   TClonesArray &ldigits = * Digits(id) ; 
155   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
156 }
157 //_____________________________________________________________________________
158 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
159 {
160   //
161   // Add a MUON digit to the list of Digits of the detection plane id
162   //
163   TClonesArray &ldigits = * Digits(id) ; 
164   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
165 }
166 //_____________________________________________________________________________
167 void AliMUONData::AddSDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *Sdigits)
168 {
169   //
170   // Add a MUON Sdigit to the list of SDigits of the detection plane id
171   //
172   TClonesArray &lSdigits = * SDigits(id) ; 
173   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(tracks,charges,Sdigits);
174 }
175 //_____________________________________________________________________________
176 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
177 {
178   //
179   // Add a MUON Sdigit to the list of SDigits of the detection plane id
180   //
181   TClonesArray &lSdigits = * SDigits(id) ; 
182   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
183 }
184 //_____________________________________________________________________________
185 void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
186                                    Int_t *singleUndef,
187                                    Int_t *pairUnlike, Int_t *pairLike)
188 {
189   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
190   TClonesArray &globalTrigger = *fGlobalTrigger;
191   new(globalTrigger[fNglobaltrigger++]) 
192     AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, pairLike);
193 }
194 //_____________________________________________________________________________
195 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
196 {
197   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
198   TClonesArray &globalTrigger = *fGlobalTrigger;
199   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
200 }
201 //_____________________________________________________________________________
202 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
203                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
204                          Float_t tof, Float_t momentum, Float_t theta, 
205                          Float_t phi, Float_t length, Float_t destep)
206 {
207   // Add new hit to the hit list
208   TClonesArray &lhits = *fHits;
209   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
210                                   idpart, X, Y, Z, 
211                                   tof, momentum, theta, 
212                                   phi, length, destep);
213 }
214 //____________________________________________________________________________
215 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
216                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
217                          Float_t tof, Float_t momentum, Float_t theta, 
218                          Float_t phi, Float_t length, Float_t destep,
219                          Float_t Xref,Float_t Yref,Float_t Zref)
220 {
221  // Add new hit to the hit list
222   TClonesArray &lhits = *fHits;
223   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
224                                   idpart, X, Y, Z, 
225                                   tof, momentum, theta, 
226                                   phi, length, destep,
227                                   Xref,Yref,Zref);
228 }
229 //____________________________________________________________________________
230 void AliMUONData::AddHit(const AliMUONHit& hit)
231 {
232   TClonesArray &lhits = *fHits;
233   new(lhits[fNhits++]) AliMUONHit(hit);
234 }
235 //____________________________________________________________________________
236 void AliMUONData::AddLocalTrigger(Int_t *localtr)
237 {
238   // add a MUON Local Trigger to the list
239   TClonesArray &localTrigger = *fLocalTrigger;
240   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
241 }
242 //____________________________________________________________________________
243 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
244 {
245   // add a MUON Local Trigger to the list
246   TClonesArray &localTrigger = *fLocalTrigger;
247   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
248 }
249 //_____________________________________________________________________________
250 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
251 {
252   //
253   // Add a MUON rawcluster to the list in the detection plane id
254   //
255   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
256   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
257 }
258 //_____________________________________________________________________________
259 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
260 {
261   //
262   // Add a MUON rectrack
263   //
264   TClonesArray &lrectracks = *fRecTracks;
265   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
266   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
267 }
268 //_____________________________________________________________________________
269 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
270 {
271   //
272   // Add a MUON triggerrectrack
273   //
274   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
275   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
276   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
277 }
278
279 //____________________________________________________________________________
280 TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) 
281 {
282   //Getting List of Digits
283   if (fDigits)
284     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
285   else
286     return NULL;
287 }
288 //____________________________________________________________________________
289 TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) 
290 {
291   //Getting List of SDigits
292   if (fSDigits)
293     return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
294   else
295     return NULL;
296 }
297 //____________________________________________________________________________
298 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
299 {
300   // Checking if there are RawCluster Branches In TreeR
301   if (TreeR()==0x0) {
302     Error("TreeR","No treeR in memory");
303     return kFALSE;
304   }
305   else {
306      char branchname[30];
307      sprintf(branchname,"%sRawClusters1",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::IsTriggerBranchesInTree()
316 {
317   // Checking if there are Trigger Branches In TreeR
318  if (TreeR()==0x0) {
319     Error("TreeR","No treeR in memory");
320     return kFALSE;
321   }
322   else {
323      char branchname[30];
324      sprintf(branchname,"%sLocalTrigger",GetName());
325      TBranch * branch = 0x0;
326      branch = TreeR()->GetBranch(branchname);
327      if (branch)  return kTRUE;
328      else return kFALSE;    
329   }
330 }
331 //____________________________________________________________________________
332 Bool_t   AliMUONData::IsTrackBranchesInTree()
333 {
334   // Checking if there are Track Branches In TreeT
335   if (TreeT()==0x0) {
336     Error("TreeT","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     Error("TreeT","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 TreeR
374   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
375   const char *cRL = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
376
377   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
378   
379   char branchname[30];
380   TBranch * branch = 0x0;
381
382   //
383   // Filling TreeH
384   if ( TreeH() && cH ) {
385     TreeH()->Fill();
386   }  
387   //
388   // Filling TreeD
389   if ( TreeD() && cD) {
390     TreeD()->Fill();
391   }
392   // Filling TreeS
393   if ( TreeS() && cS) {
394     TreeS()->Fill();
395   }
396
397   //
398   // filling rawclusters
399   if ( TreeR()  && cRC ) {
400     if ( IsTriggerBranchesInTree() ) {
401       // Branch per branch filling
402       for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
403         sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
404         branch = TreeR()->GetBranch(branchname);
405         branch->Fill();
406       }
407     }
408     else  TreeR()->Fill();
409   }
410   
411  //
412   // filling trigger 
413   if ( TreeR()  && cGLT) {
414     if (IsRawClusterBranchesInTree()) {
415       // Branch per branch filling
416       sprintf(branchname,"%sLocalTrigger",GetName());
417       branch = TreeR()->GetBranch(branchname); 
418       branch->Fill();
419       sprintf(branchname,"%sGlobalTrigger",GetName());
420       branch = TreeR()->GetBranch(branchname);
421       branch->Fill();
422     }
423     else  TreeR()->Fill();
424   }
425   //
426   // filling tracks
427   if ( TreeT() && cRT ) {
428     if (IsTriggerTrackBranchesInTree()) {
429         sprintf(branchname,"%sTrack",GetName());  
430         branch = TreeT()->GetBranch(branchname);
431         branch->Fill();
432     }
433     else  TreeT()->Fill();
434   }
435   // filling trigger tracks
436   if ( TreeT() && cRL ) {
437     if (IsTrackBranchesInTree()) {
438         sprintf(branchname,"%sTriggerTrack",GetName());  
439         branch = TreeT()->GetBranch(branchname);
440         branch->Fill();
441     }    
442     else TreeT()->Fill();
443   }
444 //   if ( TreeT() && cRL ) {
445 //     sprintf(branchname,"%sTrackTrig",GetName());  
446 //     TreeT()->Fill();
447 //   }
448 }
449 //_____________________________________________________________________________
450 void AliMUONData::MakeBranch(Option_t* option)
451 {
452   //
453   // Create Tree branches for the MUON.
454   //
455   const Int_t kBufferSize = 4000;
456   char branchname[30];
457   
458
459   const char *cH   = strstr(option,"H");
460   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
461   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
462   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
463   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
464   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
465   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
466   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
467
468   TBranch * branch = 0x0;
469   
470   // Creating Branches for Hits
471   if (TreeH() && cH) {
472
473     if (fHits == 0x0)  {
474         fHits = new TClonesArray("AliMUONHit",1000);
475 //      if (gAlice->GetMCApp())
476 //        gAlice->GetMCApp()->AddHitList (fHits);
477     }
478             
479     fNhits = 0;
480     sprintf(branchname,"%sHits",GetName());  
481     branch = TreeH()->GetBranch(branchname);
482     if (branch) {  
483       Info("MakeBranch","Branch %s is already in tree.",GetName());
484       return ;
485     }
486     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
487     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
488   }  
489   
490   //Creating Branches for Digits
491   if (TreeD() && cD ) {
492     // one branch for digits per chamber
493     if (fDigits  == 0x0) {
494       fDigits  = new TObjArray(AliMUONConstants::NCh());
495       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
496         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
497       }
498     }
499     if (fNdigits == 0x0) {
500       fNdigits = new Int_t[AliMUONConstants::NCh()];
501       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
502         fNdigits[iDetectionPlane]=0;
503       }
504     }
505     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
506       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
507       branch = 0x0;
508       branch = TreeD()->GetBranch(branchname);
509       if (branch) {  
510         Info("MakeBranch","Branch %s is already in tree.",GetName());
511         return;
512       }
513       TClonesArray * digits = Digits(iDetectionPlane); 
514       branch = TreeD()->Branch(branchname, &digits, kBufferSize,1);
515       //Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
516       }
517   }
518   
519   //Creating Branches for SDigits
520   if (TreeS() && cS ) {
521     // one branch for Sdigits per chamber
522     if (fSDigits  == 0x0) {
523       fSDigits  = new TObjArray(AliMUONConstants::NCh());
524       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
525         fSDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
526       }
527     }
528     if (fNSdigits == 0x0) {
529       fNSdigits = new Int_t[AliMUONConstants::NCh()];
530       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
531         fNSdigits[iDetectionPlane]=0;
532       }
533     }
534     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
535       sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
536       branch = 0x0;
537       branch = TreeS()->GetBranch(branchname);
538       if (branch) {  
539         Info("MakeBranch","Branch %s is already in tree.",GetName());
540         return;
541       }
542       TClonesArray * Sdigits = SDigits(iDetectionPlane); 
543       branch = TreeS()->Branch(branchname, &Sdigits, kBufferSize,1);
544       //Info("MakeBranch","Making Branch %s for Sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
545       }
546   }
547
548   if (TreeR() && cRC ) {
549     //  one branch for raw clusters per tracking detection plane
550     //        
551     Int_t i;
552     if (fRawClusters == 0x0) {
553       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
554       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
555         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",1000),i); 
556       }
557     }
558
559     if (fNrawclusters == 0x0) {
560       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
561       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
562         fNrawclusters[i]=0;
563       }
564     }
565     
566     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
567       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
568       branch = 0x0;
569       branch = TreeR()->GetBranch(branchname);
570       if (branch) {  
571         Info("MakeBranch","Branch %s is already in tree.",GetName());
572         return;
573       }
574       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
575       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
576     }
577   }
578
579   if (TreeR() && cGLT ) {
580     //
581     // one branch for global trigger
582     //
583     sprintf(branchname,"%sGlobalTrigger",GetName());
584     branch = 0x0;
585     
586     if (fGlobalTrigger == 0x0) {
587       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
588       fNglobaltrigger = 0;
589     }
590     branch = TreeR()->GetBranch(branchname);
591     if (branch) {  
592       Info("MakeBranch","Branch %s is already in tree.",GetName());
593       return ;
594     }
595     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
596     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
597     
598     //
599     // one branch for local trigger
600     //  
601     sprintf(branchname,"%sLocalTrigger",GetName());
602     branch = 0x0;
603     
604     if (fLocalTrigger == 0x0) {
605       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
606       fNlocaltrigger = 0;
607     }
608     branch = TreeR()->GetBranch(branchname);
609     if (branch) {  
610       Info("MakeBranch","Branch %s is already in tree.",GetName());
611       return;
612     }
613     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
614     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
615   }
616   
617   if (TreeT() && cRT ) {
618     if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",100);
619     fNrectracks = 0;
620     sprintf(branchname,"%sTrack",GetName());  
621     branch = TreeT()->GetBranch(branchname);
622     if (branch) {  
623       Info("MakeBranch","Branch %s is already in tree.",GetName());
624       return ;
625     }
626     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
627     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
628   }  
629 // trigger tracks
630   if (TreeT() && cRL ) {
631     if (fRecTriggerTracks == 0x0)  fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
632     fNrectriggertracks = 0;
633     sprintf(branchname,"%sTriggerTrack",GetName());  
634     branch = TreeT()->GetBranch(branchname);
635     if (branch) {  
636       Info("MakeBranch","Branch %s is already in tree.",GetName());
637       return ;
638     }
639     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
640     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
641   }  
642 }
643 //____________________________________________________________________________
644 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
645 {
646   // Getting Raw Clusters
647   if (fRawClusters) 
648     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
649   else
650     return NULL;
651 }
652 //____________________________________________________________________________
653 TClonesArray*  AliMUONData::LocalTrigger()
654 {
655   // Getting Local Trigger
656   if (fLocalTrigger) 
657     return ( (TClonesArray*) fLocalTrigger );
658   else
659     return NULL;
660 }
661 //____________________________________________________________________________
662 TClonesArray*  AliMUONData::GlobalTrigger()
663 {
664   // Getting Global Trigger
665   if (fGlobalTrigger) 
666     return ( (TClonesArray*) fGlobalTrigger );
667   else
668     return NULL;
669 }
670 //____________________________________________________________________________
671 void AliMUONData::ResetDigits()
672 {
673     //
674     // Reset number of digits and the digits array for this detector
675     //
676     if (fDigits == 0x0) return;
677     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
678       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear();
679       if (fNdigits)  fNdigits[i]=0;
680     }
681 }
682 //____________________________________________________________________________
683 void AliMUONData::ResetSDigits()
684 {
685     //
686     // Reset number of Sdigits and the Sdigits array for this detector
687     //
688     if (fSDigits == 0x0) return;
689     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
690       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
691       if (fNSdigits)  fNSdigits[i]=0;
692     }
693 }
694 //______________________________________________________________________________
695 void AliMUONData::ResetHits()
696 {
697   // Reset number of clusters and the cluster array for this detector
698   fNhits   = 0;
699   if (fHits) fHits->Clear();
700 }
701 //_______________________________________________________________________________
702 void AliMUONData::ResetRawClusters()
703 {
704     // Reset number of raw clusters and the raw clust array for this detector
705     //
706   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
707     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
708     if (fNrawclusters)  fNrawclusters[i]=0;
709   }
710 }
711 //_______________________________________________________________________________
712 void AliMUONData::ResetTrigger()
713 {
714   //  Reset Local and Global Trigger 
715   fNglobaltrigger = 0;
716   if (fGlobalTrigger) fGlobalTrigger->Clear();
717   fNlocaltrigger = 0;
718   if (fLocalTrigger) fLocalTrigger->Clear();
719 }
720 //____________________________________________________________________________
721 void AliMUONData::ResetRecTracks()
722 {
723   // Reset tracks information
724   fNrectracks = 0;
725   if (fRecTracks) fRecTracks->Clear();
726 }
727 //____________________________________________________________________________
728 void AliMUONData::ResetRecTriggerTracks()
729 {
730   // Reset tracks information
731   fNrectriggertracks = 0;
732   if (fRecTriggerTracks) fRecTriggerTracks->Clear();
733 }
734 //_____________________________________________________________________________
735 void AliMUONData::SetTreeAddress(Option_t* option)
736 {
737   //Setting Addresses to the events trees
738   const char *cH   = strstr(option,"H");
739   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
740   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
741   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
742   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
743   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
744   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
745   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
746   
747   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
748   char branchname[30];
749   TBranch * branch = 0x0;
750
751   //
752   // Branch address for hit tree
753   if ( TreeH() && cH ) {
754       if (fHits == 0x0) {
755         fHits     = new TClonesArray("AliMUONHit",1000);
756         //      if (gAlice->GetMCApp())
757         //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
758     }
759     fNhits =0;
760   } 
761   if (TreeH() && fHits && cH) {
762     sprintf(branchname,"%sHits",GetName());  
763     branch = TreeH()->GetBranch(branchname);
764     if (branch) {
765       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
766       branch->SetAddress(&fHits);
767     }
768     else { //can be invoked before branch creation
769       Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
770     }
771   }
772   
773   //
774   // Branch address for digit tree
775   if ( TreeD() && cD) {
776     if (fDigits == 0x0) { 
777       fDigits = new TObjArray(AliMUONConstants::NCh());
778       fNdigits= new Int_t[AliMUONConstants::NCh()];
779       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
780         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
781         fNdigits[i]=0;
782       }
783     }
784   }
785
786   if (TreeD() && fDigits && cD) {
787     for (int i=0; i<AliMUONConstants::NCh(); i++) {
788       sprintf(branchname,"%sDigits%d",GetName(),i+1);
789       if (fDigits) {
790         branch = TreeD()->GetBranch(branchname);
791         TClonesArray * digits = Digits(i);
792         if (branch) {
793           branch->SetAddress( &digits );
794         }
795         else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
796       }
797     }
798   }
799   //
800   // Branch address for Sdigit tree
801   if ( TreeS() && cS) {
802     if (fSDigits == 0x0) { 
803       fSDigits = new TObjArray(AliMUONConstants::NCh());
804       fNSdigits= new Int_t[AliMUONConstants::NCh()];
805       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
806         fSDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
807         fNSdigits[i]=0;
808       }
809     }
810   }
811
812   if (TreeS() && fSDigits && cS) {
813     for (int i=0; i<AliMUONConstants::NCh(); i++) {
814       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
815       if (fSDigits) {
816         branch = TreeS()->GetBranch(branchname);
817         TClonesArray * Sdigits = SDigits(i);
818         if (branch) branch->SetAddress( &Sdigits );
819         else Warning("SetTreeAddress","(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i);
820       }
821     }
822   }
823   
824   //
825   // Branch address for rawclusters, globaltrigger and local trigger tree
826   if (TreeR() ) {
827     if (fRawClusters == 0x0 && cRC) {
828       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
829       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
830       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
831         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
832         fNrawclusters[i]=0;
833       }
834     }
835     if (fLocalTrigger == 0x0 && cGLT) {
836       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
837     }
838     if (fGlobalTrigger== 0x0 && cGLT) {
839         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
840     }
841
842   }
843   if ( TreeR()  && fRawClusters && cRC) {
844     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
845       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
846       if (fRawClusters) {
847         branch = TreeR()->GetBranch(branchname);
848         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
849         else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
850       }
851     }
852   }
853   if ( TreeR()  && fLocalTrigger && cGLT) {
854     sprintf(branchname,"%sLocalTrigger",GetName());
855     branch = TreeR()->GetBranch(branchname);
856     if (branch) branch->SetAddress(&fLocalTrigger);
857     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
858   }
859   if ( TreeR() && fGlobalTrigger && cGLT) {
860     sprintf(branchname,"%sGlobalTrigger",GetName());
861     branch = TreeR()->GetBranch(branchname);
862     if (branch) branch->SetAddress(&fGlobalTrigger);
863     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
864   }
865
866   if ( TreeT() ) {
867     if (fRecTracks == 0x0 && cRT)  {
868       fRecTracks  = new TClonesArray("AliMUONTrack",100);
869     }
870
871   }
872   if ( TreeT() && fRecTracks && cRT ) {
873     sprintf(branchname,"%sTrack",GetName());  
874     branch = TreeT()->GetBranch(branchname);
875     if (branch) branch->SetAddress(&fRecTracks);
876     else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
877   }
878 // trigger tracks
879   if ( TreeT() ) {
880     if (fRecTriggerTracks == 0x0 && cRL)  {
881       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
882     }
883
884   }
885   if ( TreeT() && fRecTriggerTracks && cRL ) {
886     sprintf(branchname,"%sTriggerTrack",GetName());  
887     branch = TreeT()->GetBranch(branchname);
888     if (branch) branch->SetAddress(&fRecTriggerTracks);
889     else Warning("SetTreeAddress","(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName());
890   }
891
892
893 }
894 //_____________________________________________________________________________