]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
Reversing previous commit (Gines)
[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  
213   TClonesArray &globalTrigger = *fGlobalTrigger;
214   new(globalTrigger[fNglobaltrigger++]) 
215     AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, pairLike);
216 }
217 //_____________________________________________________________________________
218 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
219 {
220   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
221   TClonesArray &globalTrigger = *fGlobalTrigger;
222   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
223 }
224 //_____________________________________________________________________________
225 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
226                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
227                          Float_t tof, Float_t momentum, Float_t theta, 
228                          Float_t phi, Float_t length, Float_t destep)
229 {
230   // Add new hit to the hit list
231   TClonesArray &lhits = *fHits;
232   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
233                                   idpart, X, Y, Z, 
234                                   tof, momentum, theta, 
235                                   phi, length, destep);
236 }
237 //____________________________________________________________________________
238 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
239                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
240                          Float_t tof, Float_t momentum, Float_t theta, 
241                          Float_t phi, Float_t length, Float_t destep,
242                          Float_t Xref,Float_t Yref,Float_t Zref)
243 {
244  // Add new hit to the hit list
245   TClonesArray &lhits = *fHits;
246   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
247                                   idpart, X, Y, Z, 
248                                   tof, momentum, theta, 
249                                   phi, length, destep,
250                                   Xref,Yref,Zref);
251 }
252 //____________________________________________________________________________
253 void AliMUONData::AddHit(const AliMUONHit& hit)
254 {
255   TClonesArray &lhits = *fHits;
256   new(lhits[fNhits++]) AliMUONHit(hit);
257 }
258 //____________________________________________________________________________
259 void AliMUONData::AddLocalTrigger(Int_t *localtr)
260 {
261   // add a MUON Local Trigger to the list
262   TClonesArray &localTrigger = *fLocalTrigger;
263   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
264 }
265 //____________________________________________________________________________
266 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
267 {
268   // add a MUON Local Trigger to the list
269   TClonesArray &localTrigger = *fLocalTrigger;
270   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
271 }
272 //_____________________________________________________________________________
273 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
274 {
275   //
276   // Add a MUON rawcluster to the list in the detection plane id
277   //
278   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
279   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
280 }
281 //_____________________________________________________________________________
282 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
283 {
284   //
285   // Add a MUON rectrack
286   //
287   TClonesArray &lrectracks = *fRecTracks;
288   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
289   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
290 }
291 //_____________________________________________________________________________
292 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
293 {
294   //
295   // Add a MUON triggerrectrack
296   //
297   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
298   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
299   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
300 }
301
302 //____________________________________________________________________________
303 TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) 
304 {
305   //Getting List of Digits
306   if (fDigits)
307     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
308   else
309     return NULL;
310 }
311 //____________________________________________________________________________
312 TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) 
313 {
314   //Getting List of SDigits
315   if (fSDigits)
316     return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
317   else
318     return NULL;
319 }
320 //____________________________________________________________________________
321 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
322 {
323   // Checking if there are RawCluster Branches In TreeR
324   if (TreeR()==0x0) {
325     Error("TreeR","No treeR in memory");
326     return kFALSE;
327   }
328   else {
329      char branchname[30];
330      sprintf(branchname,"%sRawClusters1",GetName());
331      TBranch * branch = 0x0;
332      branch = TreeR()->GetBranch(branchname);
333      if (branch)  return kTRUE;
334      else return kFALSE;    
335   }
336 }
337 //____________________________________________________________________________
338 Bool_t   AliMUONData::IsDigitsBranchesInTree()
339 {
340   // Checking if there are RawCluster Branches In TreeR
341   if (TreeD()==0x0) {
342     Error("TreeD","No treeD in memory");
343     return kFALSE;
344   }
345   else {
346      char branchname[30];
347      sprintf(branchname,"%sDigits1",GetName());
348      TBranch * branch = 0x0;
349      branch = TreeD()->GetBranch(branchname);
350      if (branch)  return kTRUE;
351      else return kFALSE;    
352   }
353 }
354 //____________________________________________________________________________
355 Bool_t   AliMUONData::IsTriggerBranchesInTree()
356 {
357   // Checking if there are Trigger Branches In TreeR
358  if (TreeR()==0x0) {
359     Error("TreeR","No treeR in memory");
360     return kFALSE;
361   }
362   else {
363      char branchname[30];
364      sprintf(branchname,"%sLocalTrigger",GetName());
365      TBranch * branch = 0x0;
366      branch = TreeR()->GetBranch(branchname);
367      if (branch)  return kTRUE;
368      else return kFALSE;    
369   }
370 }
371 //____________________________________________________________________________
372 Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
373 {
374   // Checking if there are Trigger Branches In TreeR
375  if (TreeD()==0x0) {
376     Error("TreeD","No treeD in memory");
377     return kFALSE;
378   }
379   else {
380      char branchname[30];
381      sprintf(branchname,"%sLocalTrigger",GetName());
382      TBranch * branch = 0x0;
383      branch = TreeD()->GetBranch(branchname);
384      if (branch)  return kTRUE;
385      else return kFALSE;    
386   }
387 }
388
389 //____________________________________________________________________________
390 Bool_t   AliMUONData::IsTrackBranchesInTree()
391 {
392   // Checking if there are Track Branches In TreeT
393   if (TreeT()==0x0) {
394     Error("TreeT","No treeT in memory");
395     return kFALSE;
396   }
397   else {
398      char branchname[30];
399      sprintf(branchname,"%sTrack",GetName());
400      TBranch * branch = 0x0;
401      branch = TreeT()->GetBranch(branchname);
402      if (branch)  return kTRUE;
403      else return kFALSE;    
404   }
405 }
406 //____________________________________________________________________________
407 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
408 {
409   // Checking if there are TriggerTrack Branches In TreeT
410   if (TreeT()==0x0) {
411     Error("TreeT","No treeT in memory");
412     return kFALSE;
413   }
414   else {
415      char branchname[30];
416      sprintf(branchname,"%sTriggerTrack",GetName());
417      TBranch * branch = 0x0;
418      branch = TreeT()->GetBranch(branchname);
419      if (branch)  return kTRUE;
420      else return kFALSE;    
421   }
422 }
423 //____________________________________________________________________________
424 void AliMUONData::Fill(Option_t* option)
425 {
426   // Method to fill the trees
427   const char *cH   = strstr(option,"H");
428   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
429   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
430   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
431   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
432   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
433   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
434   const char *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
435
436   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
437   
438   char branchname[30];
439   TBranch * branch = 0x0;
440
441   // Filling TreeH
442   if ( TreeH() && cH ) {
443     TreeH()->Fill();
444   }  
445  
446   // Filling TreeD
447
448   if ( TreeD() && cD ) {
449     if ( IsTriggerBranchesInTreeD() ) {
450       for (int i=0; i<AliMUONConstants::NCh(); i++) {
451         sprintf(branchname,"%sDigits%d",GetName(),i+1);
452         branch = TreeD()->GetBranch(branchname);
453         branch->Fill();
454       }
455     } else 
456       TreeD()->Fill();
457   }
458
459   // filling trigger
460   if ( TreeD() && cGLT ) {
461     if ( IsDigitsBranchesInTree() ) {
462       sprintf(branchname,"%sLocalTrigger",GetName());
463       branch = TreeD()->GetBranch(branchname); 
464       branch->Fill();
465       sprintf(branchname,"%sGlobalTrigger",GetName());
466       branch = TreeD()->GetBranch(branchname);
467       branch->Fill();
468     } else
469       TreeD()->Fill();
470   }
471
472   // Filling TreeS
473   if ( TreeS() && cS) {
474     TreeS()->Fill();
475   }
476
477   //
478   // filling rawclusters
479   if ( TreeR()  && cRC ) {
480     if ( IsTriggerBranchesInTree() ) {
481       // Branch per branch filling
482       for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
483         sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
484         branch = TreeR()->GetBranch(branchname);
485         branch->Fill();
486       }
487     }
488     else  TreeR()->Fill();
489   }
490   
491  //
492   // filling trigger 
493   if ( TreeR()  && cTC) {
494     if (IsRawClusterBranchesInTree()) {
495       // Branch per branch filling
496       sprintf(branchname,"%sLocalTrigger",GetName());
497       branch = TreeR()->GetBranch(branchname); 
498       branch->Fill();
499       sprintf(branchname,"%sGlobalTrigger",GetName());
500       branch = TreeR()->GetBranch(branchname);
501       branch->Fill();
502     }
503     else  TreeR()->Fill();
504   }
505   //
506   // filling tracks
507   if ( TreeT() && cRT ) {
508     if (IsTriggerTrackBranchesInTree()) {
509         sprintf(branchname,"%sTrack",GetName());  
510         branch = TreeT()->GetBranch(branchname);
511         branch->Fill();
512     }
513     else  TreeT()->Fill();
514   }
515   // filling trigger tracks
516   if ( TreeT() && cRL ) {
517     if (IsTrackBranchesInTree()) {
518         sprintf(branchname,"%sTriggerTrack",GetName());  
519         branch = TreeT()->GetBranch(branchname);
520         branch->Fill();
521     }    
522     else TreeT()->Fill();
523   }
524 //   if ( TreeT() && cRL ) {
525 //     sprintf(branchname,"%sTrackTrig",GetName());  
526 //     TreeT()->Fill();
527 //   }
528 }
529 //_____________________________________________________________________________
530 void AliMUONData::MakeBranch(Option_t* option)
531 {
532   //
533   // Create Tree branches for the MUON.
534   //
535   const Int_t kBufferSize = 4000;
536   char branchname[30];
537   
538
539   const char *cH   = strstr(option,"H");
540   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
541   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
542   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
543   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
544   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
545   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
546   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
547   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
548
549   TBranch * branch = 0x0;
550   
551   // Creating Branches for Hits
552   if (TreeH() && cH) {
553
554     if (fHits == 0x0)  {
555         fHits = new TClonesArray("AliMUONHit",1000);
556 //      if (gAlice->GetMCApp())
557 //        gAlice->GetMCApp()->AddHitList (fHits);
558     }
559             
560     fNhits = 0;
561     sprintf(branchname,"%sHits",GetName());  
562     branch = TreeH()->GetBranch(branchname);
563     if (branch) {  
564       Info("MakeBranch","Branch %s is already in tree.",GetName());
565       return ;
566     }
567     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
568     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
569   }  
570   
571   //Creating Branches for Digits
572   if (TreeD() && cD ) {
573     // one branch for digits per chamber
574     if (fDigits  == 0x0) {
575       fDigits  = new TObjArray(AliMUONConstants::NCh());
576       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
577         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
578         tca->SetOwner();
579         fDigits->AddAt(tca,iDetectionPlane); 
580       }
581     }
582     if (fNdigits == 0x0) {
583       fNdigits = new Int_t[AliMUONConstants::NCh()];
584       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
585         fNdigits[iDetectionPlane]=0;
586       }
587     }
588     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
589       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
590       branch = 0x0;
591       branch = TreeD()->GetBranch(branchname);
592       if (branch) {  
593         Info("MakeBranch","Branch %s is already in tree.",GetName());
594         return;
595       }
596       TClonesArray * digits = Digits(iDetectionPlane); 
597       branch = TreeD()->Branch(branchname, &digits, kBufferSize,1);
598       //Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
599       }
600   }
601  
602    if (TreeD() && cGLT ) {
603     //
604     // one branch for global trigger
605     //
606     sprintf(branchname,"%sGlobalTrigger",GetName());
607     branch = 0x0;
608     
609     if (fGlobalTrigger == 0x0) {
610       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
611       fNglobaltrigger = 0;
612     }
613     branch = TreeD()->GetBranch(branchname);
614     if (branch) {  
615       Info("MakeBranch","Branch GlobalTrigger is already in treeD.");
616       return ;
617     }
618     branch = TreeD()->Branch(branchname, &fGlobalTrigger, kBufferSize);
619     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
620     
621     //
622     // one branch for local trigger
623     //  
624     sprintf(branchname,"%sLocalTrigger",GetName());
625     branch = 0x0;
626     
627     if (fLocalTrigger == 0x0) {
628       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
629       fNlocaltrigger = 0;
630     }
631     branch = TreeD()->GetBranch(branchname);
632     if (branch) {  
633       Info("MakeBranch","Branch LocalTrigger is already in treeD.");
634       return;
635     }
636     branch = TreeD()->Branch(branchname, &fLocalTrigger, kBufferSize);
637     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
638   }
639
640
641   //Creating Branches for SDigits
642   if (TreeS() && cS ) {
643     // one branch for Sdigits per chamber
644     if (fSDigits  == 0x0) {
645       fSDigits  = new TObjArray(AliMUONConstants::NCh());
646       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
647         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
648         tca->SetOwner();
649         fSDigits->AddAt(tca,iDetectionPlane); 
650       }
651     }
652     if (fNSdigits == 0x0) {
653       fNSdigits = new Int_t[AliMUONConstants::NCh()];
654       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
655         fNSdigits[iDetectionPlane]=0;
656       }
657     }
658     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
659       sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
660       branch = 0x0;
661       branch = TreeS()->GetBranch(branchname);
662       if (branch) {  
663         Info("MakeBranch","Branch %s is already in tree.",GetName());
664         return;
665       }
666       TClonesArray * sdigits = SDigits(iDetectionPlane); 
667       branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
668       //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
669       }
670   }
671
672   if (TreeR() && cRC ) {
673     //  one branch for raw clusters per tracking detection plane
674     //        
675     Int_t i;
676     if (fRawClusters == 0x0) {
677       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
678       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
679         TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
680         tca->SetOwner();
681         fRawClusters->AddAt(tca,i); 
682       }
683     }
684
685     if (fNrawclusters == 0x0) {
686       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
687       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
688         fNrawclusters[i]=0;
689       }
690     }
691     
692     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
693       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
694       branch = 0x0;
695       branch = TreeR()->GetBranch(branchname);
696       if (branch) {  
697         Info("MakeBranch","Branch %s is already in tree.",GetName());
698         return;
699       }
700       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
701       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
702     }
703   }
704
705   if (TreeR() && cTC ) {
706     //
707     // one branch for global trigger
708     //
709     sprintf(branchname,"%sGlobalTrigger",GetName());
710     branch = 0x0;
711     
712     if (fGlobalTrigger == 0x0) {
713       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
714       fNglobaltrigger = 0;
715     }
716     branch = TreeR()->GetBranch(branchname);
717     if (branch) {  
718       Info("MakeBranch","Branch GlobalTrigger is already in treeR.");
719       return ;
720     }
721     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
722     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
723     
724     //
725     // one branch for local trigger
726     //  
727     sprintf(branchname,"%sLocalTrigger",GetName());
728     branch = 0x0;
729     
730     if (fLocalTrigger == 0x0) {
731       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
732       fNlocaltrigger = 0;
733     }
734     branch = TreeR()->GetBranch(branchname);
735     if (branch) {  
736       Info("MakeBranch","Branch LocalTrigger is already in treeR.");
737       return;
738     }
739     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
740     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
741   }
742   
743   if (TreeT() && cRT ) {
744     if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",100);
745     fNrectracks = 0;
746     sprintf(branchname,"%sTrack",GetName());  
747     branch = TreeT()->GetBranch(branchname);
748     if (branch) {  
749       Info("MakeBranch","Branch %s is already in tree.",GetName());
750       return ;
751     }
752     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
753     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
754   }  
755 // trigger tracks
756   if (TreeT() && cRL ) {
757     if (fRecTriggerTracks == 0x0)  fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
758     fNrectriggertracks = 0;
759     sprintf(branchname,"%sTriggerTrack",GetName());  
760     branch = TreeT()->GetBranch(branchname);
761     if (branch) {  
762       Info("MakeBranch","Branch %s is already in tree.",GetName());
763       return ;
764     }
765     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
766     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
767   }  
768 }
769 //____________________________________________________________________________
770 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
771 {
772   // Getting Raw Clusters
773   if (fRawClusters) 
774     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
775   else
776     return NULL;
777 }
778 //____________________________________________________________________________
779 TClonesArray*  AliMUONData::LocalTrigger()
780 {
781   // Getting Local Trigger
782   if (fLocalTrigger) 
783     return ( (TClonesArray*) fLocalTrigger );
784   else
785     return NULL;
786 }
787 //____________________________________________________________________________
788 TClonesArray*  AliMUONData::GlobalTrigger()
789 {
790   // Getting Global Trigger
791   if (fGlobalTrigger) 
792     return ( (TClonesArray*) fGlobalTrigger );
793   else
794     return NULL;
795 }
796 //____________________________________________________________________________
797 void AliMUONData::ResetDigits()
798 {
799     //
800     // Reset number of digits and the digits array for this detector
801     //
802     if (fDigits == 0x0) return;
803     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
804       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear();
805       if (fNdigits)  fNdigits[i]=0;
806     }
807 }
808 //____________________________________________________________________________
809 void AliMUONData::ResetSDigits()
810 {
811     //
812     // Reset number of Sdigits and the Sdigits array for this detector
813     //
814     if (fSDigits == 0x0) return;
815     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
816       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
817       if (fNSdigits)  fNSdigits[i]=0;
818     }
819 }
820 //______________________________________________________________________________
821 void AliMUONData::ResetHits()
822 {
823   // Reset number of clusters and the cluster array for this detector
824   fNhits   = 0;
825   if (fHits) fHits->Clear();
826 }
827 //_______________________________________________________________________________
828 void AliMUONData::ResetRawClusters()
829 {
830     // Reset number of raw clusters and the raw clust array for this detector
831     //
832   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
833     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
834     if (fNrawclusters)  fNrawclusters[i]=0;
835   }
836 }
837 //_______________________________________________________________________________
838 void AliMUONData::ResetTrigger()
839 {
840   //  Reset Local and Global Trigger 
841   fNglobaltrigger = 0;
842   if (fGlobalTrigger) fGlobalTrigger->Clear();
843   fNlocaltrigger = 0;
844   if (fLocalTrigger) fLocalTrigger->Clear();
845 }
846 //____________________________________________________________________________
847 void AliMUONData::ResetRecTracks()
848 {
849   // Reset tracks information
850   fNrectracks = 0;
851   if (fRecTracks) fRecTracks->Clear();
852 }
853 //____________________________________________________________________________
854 void AliMUONData::ResetRecTriggerTracks()
855 {
856   // Reset tracks information
857   fNrectriggertracks = 0;
858   if (fRecTriggerTracks) fRecTriggerTracks->Clear();
859 }
860 //_____________________________________________________________________________
861 void AliMUONData::SetTreeAddress(Option_t* option)
862 {
863   //Setting Addresses to the events trees
864   const char *cH   = strstr(option,"H");
865   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
866   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
867   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
868   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
869   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
870   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
871   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
872   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
873   
874   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
875   char branchname[30];
876   TBranch * branch = 0x0;
877
878   //
879   // Branch address for hit tree
880   if ( TreeH() && cH ) {
881       if (fHits == 0x0) {
882         fHits     = new TClonesArray("AliMUONHit",1000);
883         //      if (gAlice->GetMCApp())
884         //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
885     }
886     fNhits =0;
887   } 
888   if (TreeH() && fHits && cH) {
889     sprintf(branchname,"%sHits",GetName());  
890     branch = TreeH()->GetBranch(branchname);
891     if (branch) {
892       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
893       branch->SetAddress(&fHits);
894     }
895     else { //can be invoked before branch creation
896       Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
897     }
898   }
899   
900   //
901   // Branch address for digit tree
902   if ( TreeD() ) {      
903     if (fDigits == 0x0 && cD) {
904       fDigits = new TObjArray(AliMUONConstants::NCh());
905       fNdigits= new Int_t[AliMUONConstants::NCh()];
906       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
907         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
908         fNdigits[i]=0;
909       }
910     }
911     if (fLocalTrigger == 0x0 && cGLT) {
912       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
913     }
914     if (fGlobalTrigger== 0x0 && cGLT) {
915         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
916     }
917   }
918
919   if (TreeD() && fDigits && cD) {
920     for (int i=0; i<AliMUONConstants::NCh(); i++) {
921       sprintf(branchname,"%sDigits%d",GetName(),i+1);
922       if (fDigits) {
923         branch = TreeD()->GetBranch(branchname);
924         TClonesArray * digits = Digits(i);
925         if (branch) {
926           branch->SetAddress( &digits );
927         }
928         else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
929       }
930     }
931   }
932   if ( TreeD()  && fLocalTrigger && cGLT) {
933     sprintf(branchname,"%sLocalTrigger",GetName());
934     branch = TreeD()->GetBranch(branchname);
935     if (branch) branch->SetAddress(&fLocalTrigger);
936     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName());
937   }
938   if ( TreeD() && fGlobalTrigger && cGLT) {
939     sprintf(branchname,"%sGlobalTrigger",GetName());
940     branch = TreeD()->GetBranch(branchname);
941     if (branch) branch->SetAddress(&fGlobalTrigger);
942     else Warning("SetTreeAddress","(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName());
943   }
944
945   //
946   // Branch address for Sdigit tree
947   if ( TreeS() && cS) {
948     if (fSDigits == 0x0) { 
949       fSDigits = new TObjArray(AliMUONConstants::NCh());
950       fNSdigits= new Int_t[AliMUONConstants::NCh()];
951       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
952         fSDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
953         fNSdigits[i]=0;
954       }
955     }
956   }
957
958   if (TreeS() && fSDigits && cS) {
959     for (int i=0; i<AliMUONConstants::NCh(); i++) {
960       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
961       if (fSDigits) {
962         branch = TreeS()->GetBranch(branchname);
963         TClonesArray * sdigits = SDigits(i);
964         if (branch) branch->SetAddress( &sdigits );
965         else Warning("SetTreeAddress","(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i);
966       }
967     }
968   }
969   
970   //
971   // Branch address for rawclusters, globaltrigger and local trigger tree
972   if (TreeR() ) {
973     if (fRawClusters == 0x0 && cRC) {
974       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
975       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
976       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
977         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
978         fNrawclusters[i]=0;
979       }
980     }
981     if (fLocalTrigger == 0x0 && cTC) {
982       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
983     }
984     if (fGlobalTrigger== 0x0 && cTC) {
985         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
986     }
987
988   }
989   if ( TreeR()  && fRawClusters && cRC) {
990     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
991       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
992       if (fRawClusters) {
993         branch = TreeR()->GetBranch(branchname);
994         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
995         else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
996       }
997     }
998   }
999   if ( TreeR()  && fLocalTrigger && cTC) {
1000     sprintf(branchname,"%sLocalTrigger",GetName());
1001     branch = TreeR()->GetBranch(branchname);
1002     if (branch) branch->SetAddress(&fLocalTrigger);
1003     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName());
1004   }
1005   if ( TreeR() && fGlobalTrigger && cTC) {
1006     sprintf(branchname,"%sGlobalTrigger",GetName());
1007     branch = TreeR()->GetBranch(branchname);
1008     if (branch) branch->SetAddress(&fGlobalTrigger);
1009     else Warning("SetTreeAddress","(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName());
1010   }
1011
1012   if ( TreeT() ) {
1013     if (fRecTracks == 0x0 && cRT)  {
1014       fRecTracks  = new TClonesArray("AliMUONTrack",100);
1015     }
1016
1017   }
1018   if ( TreeT() && fRecTracks && cRT ) {
1019     sprintf(branchname,"%sTrack",GetName());  
1020     branch = TreeT()->GetBranch(branchname);
1021     if (branch) branch->SetAddress(&fRecTracks);
1022     else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
1023   }
1024 // trigger tracks
1025   if ( TreeT() ) {
1026     if (fRecTriggerTracks == 0x0 && cRL)  {
1027       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
1028     }
1029
1030   }
1031   if ( TreeT() && fRecTriggerTracks && cRL ) {
1032     sprintf(branchname,"%sTriggerTrack",GetName());  
1033     branch = TreeT()->GetBranch(branchname);
1034     if (branch) branch->SetAddress(&fRecTriggerTracks);
1035     else Warning("SetTreeAddress","(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName());
1036   }
1037
1038
1039 }
1040 //_____________________________________________________________________________