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