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