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