]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
b3d852b59a4923e6acaee67e0af89aae6996653b
[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 #include "AliLog.h"
36
37 ClassImp(AliMUONData)
38  
39 //_____________________________________________________________________________
40   AliMUONData::AliMUONData():
41     TNamed(),
42     fLoader(0x0),
43     fHits(0x0),
44     fDigits(0x0),
45     fSDigits(0x0),
46     fRawClusters(0x0),
47     fGlobalTrigger(0x0),
48     fLocalTrigger(0x0),
49     fRecTracks(0x0),
50     fRecTriggerTracks(0x0),
51     fNhits(0),
52     fNdigits(0x0),
53     fNSdigits(0x0),
54     fNrawclusters(0x0),
55     fNglobaltrigger(0),
56     fNlocaltrigger(0),
57     fNrectracks(0),
58     fNrectriggertracks(0),
59     fSplitLevel(0)
60 {
61   // Default constructor
62 }
63 //_____________________________________________________________________________
64 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
65   TNamed(name,title),
66     fLoader(loader),
67     fHits(0x0),
68     fDigits(0x0),
69     fSDigits(0x0),
70     fRawClusters(0x0),
71     fGlobalTrigger(0x0),
72     fLocalTrigger(0x0),
73     fRecTracks(0x0),
74     fRecTriggerTracks(0x0),
75     fNhits(0),
76     fNdigits(0x0),
77     fNSdigits(0x0),
78     fNrawclusters(0x0),
79     fNglobaltrigger(0),
80     fNlocaltrigger(0),
81     fNrectracks(0),
82     fNrectriggertracks(0),
83     fSplitLevel(0)
84 {
85   // Constructor for AliMUONData
86
87 //   fHits          = new TClonesArray("AliMUONHit",1000);
88 //   fNhits         = 0;
89 //   fDigits        = new TObjArray(AliMUONConstants::NCh());
90 //   fNdigits       = new Int_t[AliMUONConstants::NCh()];
91 //   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
92 //     fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
93 //     fNdigits[iDetectionPlane]=0;
94 //   }
95 //   fRawClusters   = new TObjArray(AliMUONConstants::NTrackingCh());
96 //   fNrawclusters  = new Int_t[AliMUONConstants::NTrackingCh()];
97 //   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
98 //     fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane); 
99 //     fNrawclusters[iDetectionPlane]=0;
100 //   }
101 //   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
102 //   fNglobaltrigger =0;
103 //   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);   
104 //   fNlocaltrigger = 0;
105 //   fRecTracks     = new TClonesArray("AliMUONTrack", 100);
106 //   fNrectracks    = 0; // really needed or GetEntriesFast sufficient ????
107
108
109 }
110
111 //_____________________________________________________________________________
112 AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
113 {
114 // Protected copy constructor
115
116   AliFatal("Not implemented.");
117 }
118
119 //_____________________________________________________________________________
120 AliMUONData::~AliMUONData()
121 {
122   // Destructor for AliMUONData
123   if (fHits) {
124     fHits->Delete();
125     delete fHits;
126   }
127   if (fDigits) {
128     fDigits->Delete();
129     delete fDigits;
130   }
131   if (fSDigits) {
132     fSDigits->Delete();
133     delete fSDigits;
134   }
135   if (fRawClusters) {
136     fRawClusters->Delete();
137     delete fRawClusters;
138   }
139   if (fGlobalTrigger){
140     fGlobalTrigger->Delete();
141     delete fGlobalTrigger;
142   }  
143   if (fLocalTrigger){
144     fLocalTrigger->Delete();
145     delete fLocalTrigger;
146   }
147   if (fRecTracks){
148     fRecTracks->Delete();
149     delete fRecTracks;
150   }
151   if (fRecTriggerTracks){
152     fRecTriggerTracks->Delete();
153     delete fRecTriggerTracks;
154   }
155   //detructor 
156 }
157
158 //_____________________________________________________________________________
159 AliMUONData& AliMUONData::operator=(const AliMUONData& rhs)
160 {
161 // Protected assignement operator
162
163   if (this == &rhs) return *this;
164
165   AliFatal("Not implemented.");
166     
167   return *this;  
168 }    
169           
170
171 //_____________________________________________________________________________
172 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
173 {
174   //
175   // Add a MUON digit to the list of Digits of the detection plane id
176   //
177   TClonesArray &ldigits = * Digits(id) ; 
178   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
179 }
180 //_____________________________________________________________________________
181 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
182 {
183   //
184   // Add a MUON digit to the list of Digits of the detection plane id
185   //
186   TClonesArray &ldigits = * Digits(id) ; 
187   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
188 }
189 //_____________________________________________________________________________
190 void AliMUONData::AddSDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *sdigits)
191 {
192   //
193   // Add a MUON Sdigit to the list of SDigits of the detection plane id
194   //
195   TClonesArray &lSdigits = * SDigits(id) ; 
196   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(tracks,charges,sdigits);
197 }
198 //_____________________________________________________________________________
199 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
200 {
201   //
202   // Add a MUON Sdigit to the list of SDigits of the detection plane id
203   //
204   TClonesArray &lSdigits = * SDigits(id) ; 
205   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
206 }
207 //_____________________________________________________________________________
208 void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
209                                    Int_t *singleUndef,
210                                    Int_t *pairUnlike, Int_t *pairLike)
211 {
212   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
213  
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     AliError("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::IsDigitsBranchesInTree()
340 {
341   // Checking if there are RawCluster Branches In TreeR
342   if (TreeD()==0x0) {
343     AliError("No treeD in memory");
344     return kFALSE;
345   }
346   else {
347      char branchname[30];
348      sprintf(branchname,"%sDigits1",GetName());
349      TBranch * branch = 0x0;
350      branch = TreeD()->GetBranch(branchname);
351      if (branch)  return kTRUE;
352      else return kFALSE;    
353   }
354 }
355 //____________________________________________________________________________
356 Bool_t   AliMUONData::IsTriggerBranchesInTree()
357 {
358   // Checking if there are Trigger Branches In TreeR
359  if (TreeR()==0x0) {
360     AliError("No treeR in memory");
361     return kFALSE;
362   }
363   else {
364      char branchname[30];
365      sprintf(branchname,"%sLocalTrigger",GetName());
366      TBranch * branch = 0x0;
367      branch = TreeR()->GetBranch(branchname);
368      if (branch)  return kTRUE;
369      else return kFALSE;    
370   }
371 }
372 //____________________________________________________________________________
373 Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
374 {
375   // Checking if there are Trigger Branches In TreeR
376  if (TreeD()==0x0) {
377     AliError("No treeD in memory");
378     return kFALSE;
379   }
380   else {
381      char branchname[30];
382      sprintf(branchname,"%sLocalTrigger",GetName());
383      TBranch * branch = 0x0;
384      branch = TreeD()->GetBranch(branchname);
385      if (branch)  return kTRUE;
386      else return kFALSE;    
387   }
388 }
389
390 //____________________________________________________________________________
391 Bool_t   AliMUONData::IsTrackBranchesInTree()
392 {
393   // Checking if there are Track Branches In TreeT
394   if (TreeT()==0x0) {
395     AliError("No treeT in memory");
396     return kFALSE;
397   }
398   else {
399      char branchname[30];
400      sprintf(branchname,"%sTrack",GetName());
401      TBranch * branch = 0x0;
402      branch = TreeT()->GetBranch(branchname);
403      if (branch)  return kTRUE;
404      else return kFALSE;    
405   }
406 }
407 //____________________________________________________________________________
408 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
409 {
410   // Checking if there are TriggerTrack Branches In TreeT
411   if (TreeT()==0x0) {
412     AliError("No treeT in memory");
413     return kFALSE;
414   }
415   else {
416      char branchname[30];
417      sprintf(branchname,"%sTriggerTrack",GetName());
418      TBranch * branch = 0x0;
419      branch = TreeT()->GetBranch(branchname);
420      if (branch)  return kTRUE;
421      else return kFALSE;    
422   }
423 }
424 //____________________________________________________________________________
425 void AliMUONData::Fill(Option_t* option)
426 {
427   // Method to fill the trees
428   const char *cH   = strstr(option,"H");
429   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
430   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
431   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
432   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
433   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
434   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
435   const char *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
436
437   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
438   
439   char branchname[30];
440   TBranch * branch = 0x0;
441
442   // Filling TreeH
443   if ( TreeH() && cH ) {
444     TreeH()->Fill();
445   }  
446  
447   // Filling TreeD
448
449   if ( TreeD() && cD ) {
450     if ( IsTriggerBranchesInTreeD() ) {
451       for (int i=0; i<AliMUONConstants::NCh(); i++) {
452         sprintf(branchname,"%sDigits%d",GetName(),i+1);
453         branch = TreeD()->GetBranch(branchname);
454         branch->Fill();
455       }
456     } else 
457       TreeD()->Fill();
458   }
459
460   // filling trigger
461   if ( TreeD() && cGLT ) {
462     if ( IsDigitsBranchesInTree() ) {
463       sprintf(branchname,"%sLocalTrigger",GetName());
464       branch = TreeD()->GetBranch(branchname); 
465       branch->Fill();
466       sprintf(branchname,"%sGlobalTrigger",GetName());
467       branch = TreeD()->GetBranch(branchname);
468       branch->Fill();
469     } else
470       TreeD()->Fill();
471   }
472
473   // Filling TreeS
474   if ( TreeS() && cS) {
475     TreeS()->Fill();
476   }
477
478   //
479   // filling rawclusters
480   if ( TreeR()  && cRC ) {
481     if ( IsTriggerBranchesInTree() ) {
482       // Branch per branch filling
483       for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
484         sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
485         branch = TreeR()->GetBranch(branchname);
486         branch->Fill();
487       }
488     }
489     else  TreeR()->Fill();
490   }
491   
492  //
493   // filling trigger 
494   if ( TreeR()  && cTC) {
495     if (IsRawClusterBranchesInTree()) {
496       // Branch per branch filling
497       sprintf(branchname,"%sLocalTrigger",GetName());
498       branch = TreeR()->GetBranch(branchname); 
499       branch->Fill();
500       sprintf(branchname,"%sGlobalTrigger",GetName());
501       branch = TreeR()->GetBranch(branchname);
502       branch->Fill();
503     }
504     else  TreeR()->Fill();
505   }
506   //
507   // filling tracks
508   if ( TreeT() && cRT ) {
509     if (IsTriggerTrackBranchesInTree()) {
510         sprintf(branchname,"%sTrack",GetName());  
511         branch = TreeT()->GetBranch(branchname);
512         branch->Fill();
513     }
514     else  TreeT()->Fill();
515   }
516   // filling trigger tracks
517   if ( TreeT() && cRL ) {
518     if (IsTrackBranchesInTree()) {
519         sprintf(branchname,"%sTriggerTrack",GetName());  
520         branch = TreeT()->GetBranch(branchname);
521         branch->Fill();
522     }    
523     else TreeT()->Fill();
524   }
525 //   if ( TreeT() && cRL ) {
526 //     sprintf(branchname,"%sTrackTrig",GetName());  
527 //     TreeT()->Fill();
528 //   }
529 }
530 //_____________________________________________________________________________
531 void AliMUONData::MakeBranch(Option_t* option)
532 {
533   //
534   // Create Tree branches for the MUON.
535   //
536   const Int_t kBufferSize = 4000;
537   char branchname[30];
538   
539
540   const char *cH   = strstr(option,"H");
541   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
542   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
543   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
544   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
545   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
546   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
547   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
548   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
549
550   TBranch * branch = 0x0;
551   
552   // Creating Branches for Hits
553   if (TreeH() && cH) {
554
555     if (fHits == 0x0)  {
556         fHits = new TClonesArray("AliMUONHit",1000);
557 //      if (gAlice->GetMCApp())
558 //        gAlice->GetMCApp()->AddHitList (fHits);
559     }
560             
561     fNhits = 0;
562     sprintf(branchname,"%sHits",GetName());  
563     branch = TreeH()->GetBranch(branchname);
564     if (branch) {  
565       AliInfo(Form("MakeBranch","Branch %s is already in tree.",GetName()));
566       return ;
567     }
568     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
569     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
570   }  
571   
572   //Creating Branches for Digits
573   if (TreeD() && cD ) {
574     // one branch for digits per chamber
575     if (fDigits  == 0x0) {
576       fDigits  = new TObjArray(AliMUONConstants::NCh());
577       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
578         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
579         tca->SetOwner();
580         fDigits->AddAt(tca,iDetectionPlane); 
581       }
582     }
583     if (fNdigits == 0x0) {
584       fNdigits = new Int_t[AliMUONConstants::NCh()];
585       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
586         fNdigits[iDetectionPlane]=0;
587       }
588     }
589     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
590       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
591       branch = 0x0;
592       branch = TreeD()->GetBranch(branchname);
593       if (branch) {  
594         AliInfo(Form("Branch %s is already in tree.",GetName()));
595         return;
596       }
597       TClonesArray * digits = Digits(iDetectionPlane); 
598       branch = TreeD()->Branch(branchname, &digits, kBufferSize,1);
599       //Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
600       }
601   }
602  
603    if (TreeD() && cGLT ) {
604     //
605     // one branch for global trigger
606     //
607     sprintf(branchname,"%sGlobalTrigger",GetName());
608     branch = 0x0;
609     
610     if (fGlobalTrigger == 0x0) {
611       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
612       fNglobaltrigger = 0;
613     }
614     branch = TreeD()->GetBranch(branchname);
615     if (branch) {  
616       AliInfo(Form("Branch GlobalTrigger is already in treeD."));
617       return ;
618     }
619     branch = TreeD()->Branch(branchname, &fGlobalTrigger, kBufferSize);
620     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
621     
622     //
623     // one branch for local trigger
624     //  
625     sprintf(branchname,"%sLocalTrigger",GetName());
626     branch = 0x0;
627     
628     if (fLocalTrigger == 0x0) {
629       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
630       fNlocaltrigger = 0;
631     }
632     branch = TreeD()->GetBranch(branchname);
633     if (branch) {  
634       AliInfo(Form("Branch LocalTrigger is already in treeD."));
635       return;
636     }
637     branch = TreeD()->Branch(branchname, &fLocalTrigger, kBufferSize);
638     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
639   }
640
641
642   //Creating Branches for SDigits
643   if (TreeS() && cS ) {
644     // one branch for Sdigits per chamber
645     if (fSDigits  == 0x0) {
646       fSDigits  = new TObjArray(AliMUONConstants::NCh());
647       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
648         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
649         tca->SetOwner();
650         fSDigits->AddAt(tca,iDetectionPlane); 
651       }
652     }
653     if (fNSdigits == 0x0) {
654       fNSdigits = new Int_t[AliMUONConstants::NCh()];
655       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
656         fNSdigits[iDetectionPlane]=0;
657       }
658     }
659     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
660       sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
661       branch = 0x0;
662       branch = TreeS()->GetBranch(branchname);
663       if (branch) {  
664         AliInfo(Form("Branch %s is already in tree.",GetName()));
665         return;
666       }
667       TClonesArray * sdigits = SDigits(iDetectionPlane); 
668       branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
669       //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
670       }
671   }
672
673   if (TreeR() && cRC ) {
674     //  one branch for raw clusters per tracking detection plane
675     //        
676     Int_t i;
677     if (fRawClusters == 0x0) {
678       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
679       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
680         TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
681         tca->SetOwner();
682         fRawClusters->AddAt(tca,i); 
683       }
684     }
685
686     if (fNrawclusters == 0x0) {
687       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
688       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
689         fNrawclusters[i]=0;
690       }
691     }
692     
693     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
694       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
695       branch = 0x0;
696       branch = TreeR()->GetBranch(branchname);
697       if (branch) {  
698         AliInfo(Form("Branch %s is already in tree.",GetName()));
699         return;
700       }
701       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
702       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
703     }
704   }
705
706   if (TreeR() && cTC ) {
707     //
708     // one branch for global trigger
709     //
710     sprintf(branchname,"%sGlobalTrigger",GetName());
711     branch = 0x0;
712     
713     if (fGlobalTrigger == 0x0) {
714       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
715       fNglobaltrigger = 0;
716     }
717     branch = TreeR()->GetBranch(branchname);
718     if (branch) {  
719       AliInfo(Form("Branch GlobalTrigger is already in treeR."));
720       return ;
721     }
722     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
723     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
724     
725     //
726     // one branch for local trigger
727     //  
728     sprintf(branchname,"%sLocalTrigger",GetName());
729     branch = 0x0;
730     
731     if (fLocalTrigger == 0x0) {
732       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
733       fNlocaltrigger = 0;
734     }
735     branch = TreeR()->GetBranch(branchname);
736     if (branch) {  
737       AliInfo(Form("Branch LocalTrigger is already in treeR."));
738       return;
739     }
740     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
741     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
742   }
743   
744   if (TreeT() && cRT ) {
745     if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",100);
746     fNrectracks = 0;
747     sprintf(branchname,"%sTrack",GetName());  
748     branch = TreeT()->GetBranch(branchname);
749     if (branch) {  
750       AliInfo(Form("Branch %s is already in tree.",GetName()));
751       return ;
752     }
753     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
754     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
755   }  
756 // trigger tracks
757   if (TreeT() && cRL ) {
758     if (fRecTriggerTracks == 0x0)  fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
759     fNrectriggertracks = 0;
760     sprintf(branchname,"%sTriggerTrack",GetName());  
761     branch = TreeT()->GetBranch(branchname);
762     if (branch) {  
763       AliInfo(Form("Branch %s is already in tree.",GetName()));
764       return ;
765     }
766     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
767     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
768   }  
769 }
770 //____________________________________________________________________________
771 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
772 {
773   // Getting Raw Clusters
774   if (fRawClusters) 
775     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
776   else
777     return NULL;
778 }
779 //____________________________________________________________________________
780 TClonesArray*  AliMUONData::LocalTrigger()
781 {
782   // Getting Local Trigger
783   if (fLocalTrigger) 
784     return ( (TClonesArray*) fLocalTrigger );
785   else
786     return NULL;
787 }
788 //____________________________________________________________________________
789 TClonesArray*  AliMUONData::GlobalTrigger()
790 {
791   // Getting Global Trigger
792   if (fGlobalTrigger) 
793     return ( (TClonesArray*) fGlobalTrigger );
794   else
795     return NULL;
796 }
797 //____________________________________________________________________________
798 void AliMUONData::ResetDigits()
799 {
800     //
801     // Reset number of digits and the digits array for this detector
802     //
803     if (fDigits == 0x0) return;
804     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
805       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear();
806       if (fNdigits)  fNdigits[i]=0;
807     }
808 }
809 //____________________________________________________________________________
810 void AliMUONData::ResetSDigits()
811 {
812     //
813     // Reset number of Sdigits and the Sdigits array for this detector
814     //
815     if (fSDigits == 0x0) return;
816     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
817       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
818       if (fNSdigits)  fNSdigits[i]=0;
819     }
820 }
821 //______________________________________________________________________________
822 void AliMUONData::ResetHits()
823 {
824   // Reset number of clusters and the cluster array for this detector
825   fNhits   = 0;
826   if (fHits) fHits->Clear();
827 }
828 //_______________________________________________________________________________
829 void AliMUONData::ResetRawClusters()
830 {
831     // Reset number of raw clusters and the raw clust array for this detector
832     //
833   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
834     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
835     if (fNrawclusters)  fNrawclusters[i]=0;
836   }
837 }
838 //_______________________________________________________________________________
839 void AliMUONData::ResetTrigger()
840 {
841   //  Reset Local and Global Trigger 
842   fNglobaltrigger = 0;
843   if (fGlobalTrigger) fGlobalTrigger->Clear();
844   fNlocaltrigger = 0;
845   if (fLocalTrigger) fLocalTrigger->Clear();
846 }
847 //____________________________________________________________________________
848 void AliMUONData::ResetRecTracks()
849 {
850   // Reset tracks information
851   fNrectracks = 0;
852   if (fRecTracks) fRecTracks->Clear();
853 }
854 //____________________________________________________________________________
855 void AliMUONData::ResetRecTriggerTracks()
856 {
857   // Reset tracks information
858   fNrectriggertracks = 0;
859   if (fRecTriggerTracks) fRecTriggerTracks->Clear();
860 }
861 //_____________________________________________________________________________
862 void AliMUONData::SetTreeAddress(Option_t* option)
863 {
864   //Setting Addresses to the events trees
865   const char *cH   = strstr(option,"H");
866   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
867   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
868   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
869   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
870   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
871   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
872   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
873   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
874   
875   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
876   char branchname[30];
877   TBranch * branch = 0x0;
878
879   //
880   // Branch address for hit tree
881   if ( TreeH() && cH ) {
882       if (fHits == 0x0) {
883         fHits     = new TClonesArray("AliMUONHit",1000);
884         //      if (gAlice->GetMCApp())
885         //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
886     }
887     fNhits =0;
888   } 
889   if (TreeH() && fHits && cH) {
890     sprintf(branchname,"%sHits",GetName());  
891     branch = TreeH()->GetBranch(branchname);
892     if (branch) {
893       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
894       branch->SetAddress(&fHits);
895     }
896     else { //can be invoked before branch creation
897       AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
898     }
899   }
900   
901   //
902   // Branch address for digit tree
903   if ( TreeD() ) {      
904     if (fDigits == 0x0 && cD) {
905       fDigits = new TObjArray(AliMUONConstants::NCh());
906       fNdigits= new Int_t[AliMUONConstants::NCh()];
907       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
908         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
909         fNdigits[i]=0;
910       }
911     }
912     if (fLocalTrigger == 0x0 && cGLT) {
913       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
914     }
915     if (fGlobalTrigger== 0x0 && cGLT) {
916         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
917     }
918   }
919
920   if (TreeD() && fDigits && cD) {
921     for (int i=0; i<AliMUONConstants::NCh(); i++) {
922       sprintf(branchname,"%sDigits%d",GetName(),i+1);
923       if (fDigits) {
924         branch = TreeD()->GetBranch(branchname);
925         TClonesArray * digits = Digits(i);
926         if (branch) {
927           branch->SetAddress( &digits );
928         }
929         else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
930       }
931     }
932   }
933   if ( TreeD()  && fLocalTrigger && cGLT) {
934     sprintf(branchname,"%sLocalTrigger",GetName());
935     branch = TreeD()->GetBranch(branchname);
936     if (branch) branch->SetAddress(&fLocalTrigger);
937     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
938   }
939   if ( TreeD() && fGlobalTrigger && cGLT) {
940     sprintf(branchname,"%sGlobalTrigger",GetName());
941     branch = TreeD()->GetBranch(branchname);
942     if (branch) branch->SetAddress(&fGlobalTrigger);
943     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
944   }
945
946   //
947   // Branch address for Sdigit tree
948   if ( TreeS() && cS) {
949     if (fSDigits == 0x0) { 
950       fSDigits = new TObjArray(AliMUONConstants::NCh());
951       fNSdigits= new Int_t[AliMUONConstants::NCh()];
952       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
953         fSDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
954         fNSdigits[i]=0;
955       }
956     }
957   }
958
959   if (TreeS() && fSDigits && cS) {
960     for (int i=0; i<AliMUONConstants::NCh(); i++) {
961       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
962       if (fSDigits) {
963         branch = TreeS()->GetBranch(branchname);
964         TClonesArray * sdigits = SDigits(i);
965         if (branch) branch->SetAddress( &sdigits );
966         else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
967       }
968     }
969   }
970   
971   //
972   // Branch address for rawclusters, globaltrigger and local trigger tree
973   if (TreeR() ) {
974     if (fRawClusters == 0x0 && cRC) {
975       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
976       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
977       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
978         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
979         fNrawclusters[i]=0;
980       }
981     }
982     if (fLocalTrigger == 0x0 && cTC) {
983       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
984     }
985     if (fGlobalTrigger== 0x0 && cTC) {
986         fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
987     }
988
989   }
990   if ( TreeR()  && fRawClusters && cRC) {
991     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
992       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
993       if (fRawClusters) {
994         branch = TreeR()->GetBranch(branchname);
995         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
996         else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
997       }
998     }
999   }
1000   if ( TreeR()  && fLocalTrigger && cTC) {
1001     sprintf(branchname,"%sLocalTrigger",GetName());
1002     branch = TreeR()->GetBranch(branchname);
1003     if (branch) branch->SetAddress(&fLocalTrigger);
1004     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
1005   }
1006   if ( TreeR() && fGlobalTrigger && cTC) {
1007     sprintf(branchname,"%sGlobalTrigger",GetName());
1008     branch = TreeR()->GetBranch(branchname);
1009     if (branch) branch->SetAddress(&fGlobalTrigger);
1010     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
1011   }
1012
1013   if ( TreeT() ) {
1014     if (fRecTracks == 0x0 && cRT)  {
1015       fRecTracks  = new TClonesArray("AliMUONTrack",100);
1016     }
1017
1018   }
1019   if ( TreeT() && fRecTracks && cRT ) {
1020     sprintf(branchname,"%sTrack",GetName());  
1021     branch = TreeT()->GetBranch(branchname);
1022     if (branch) branch->SetAddress(&fRecTracks);
1023     else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
1024   }
1025 // trigger tracks
1026   if ( TreeT() ) {
1027     if (fRecTriggerTracks == 0x0 && cRL)  {
1028       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
1029     }
1030
1031   }
1032   if ( TreeT() && fRecTriggerTracks && cRL ) {
1033     sprintf(branchname,"%sTriggerTrack",GetName());  
1034     branch = TreeT()->GetBranch(branchname);
1035     if (branch) branch->SetAddress(&fRecTriggerTracks);
1036     else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
1037   }
1038
1039
1040 }
1041 //_____________________________________________________________________________