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