]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
Regenerated with modifying geometry (adding mother volumes)
[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
18 /// AliMUONData class
19 ///
20 /// Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
21 /// The classe makes the lik between the MUON data lists and the event trees from loaders
22 ///
23 /// Gines Martinez, Subatech,  September 2003
24 ///
25
26 #include "AliMUONData.h"
27
28 #include "AliLog.h"
29 #include "AliMUONConstants.h"
30 #include "AliMUONDigit.h"
31 #include "AliMUONGlobalTrigger.h"
32 #include "AliMUONHit.h"
33 #include "AliMUONLocalTrigger.h"
34 #include "AliMUONRawCluster.h"
35 #include "AliMUONTrack.h"
36 #include "AliMUONTriggerTrack.h"
37 #include "AliRunLoader.h"
38 #include "TArrayI.h"
39 #include "TString.h"
40
41 ClassImp(AliMUONData)
42  
43 //_____________________________________________________________________________
44   AliMUONData::AliMUONData():
45     TNamed(),
46     fLoader(0x0),
47     fHits(0x0),
48     fDigits(0x0),
49     fSDigits(0x0),
50     fRawClusters(0x0),
51     fGlobalTrigger(0x0),
52     fLocalTrigger(0x0),
53     fRecTracks(0x0),
54     fRecTriggerTracks(0x0),
55     fNhits(0),
56     fNdigits(0x0),
57     fNSdigits(0x0),
58     fNrawclusters(0x0),
59     fNglobaltrigger(0),
60     fNlocaltrigger(0),
61     fNrectracks(0),
62     fNrectriggertracks(0),
63     fSplitLevel(0),
64     fCurrentEvent(-1)
65 {
66   // Default constructor
67 }
68 //_____________________________________________________________________________
69 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
70   TNamed(name,title),
71     fLoader(loader),
72     fHits(0x0),
73     fDigits(0x0),
74     fSDigits(0x0),
75     fRawClusters(0x0),
76     fGlobalTrigger(0x0),
77     fLocalTrigger(0x0),
78     fRecTracks(0x0),
79     fRecTriggerTracks(0x0),
80     fNhits(0),
81     fNdigits(0x0),
82     fNSdigits(0x0),
83     fNrawclusters(0x0),
84     fNglobaltrigger(0),
85     fNlocaltrigger(0),
86     fNrectracks(0),
87     fNrectriggertracks(0),
88     fSplitLevel(0),
89     fCurrentEvent(-1)
90 {
91   // Constructor for AliMUONData
92 }
93
94 //_____________________________________________________________________________
95 AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
96 {
97 // Protected copy constructor
98
99   AliFatal("Not implemented.");
100 }
101
102 //_____________________________________________________________________________
103 AliMUONData::~AliMUONData()
104 {
105   // Destructor for AliMUONData
106   if (fHits) {
107     fHits->Delete();
108     delete fHits;
109   }
110   
111   if (fDigits) {
112     fDigits->Delete();
113     delete fDigits;
114   }
115   if (fSDigits) {
116     fSDigits->Delete();
117     delete fSDigits;
118   }
119   if (fRawClusters) {
120     fRawClusters->Delete();
121     delete fRawClusters;
122   }
123   if (fGlobalTrigger){
124     fGlobalTrigger->Delete();
125     delete fGlobalTrigger;
126   }  
127   if (fLocalTrigger){
128     fLocalTrigger->Delete();
129     delete fLocalTrigger;
130   }
131   if (fRecTracks){
132     fRecTracks->Delete();
133     delete fRecTracks;
134   }
135   if (fRecTriggerTracks){
136     fRecTriggerTracks->Delete();
137     delete fRecTriggerTracks;
138   }
139 }
140
141 //_____________________________________________________________________________
142 AliMUONData& AliMUONData::operator=(const AliMUONData& rhs)
143 {
144 // Protected assignement operator
145
146   if (this == &rhs) return *this;
147
148   AliFatal("Not implemented.");
149     
150   return *this;  
151 }    
152           
153
154 //_____________________________________________________________________________
155 void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
156 {
157   //
158   // Add a MUON digit to the list of Digits of the detection plane id
159   //
160   TClonesArray &ldigits = * Digits(id) ; 
161   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
162 }
163 //_____________________________________________________________________________
164 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
165 {
166   //
167   // Add a MUON digit to the list of Digits of the detection plane id
168   //
169   TClonesArray &ldigits = * Digits(id) ; 
170   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
171 }
172 //_____________________________________________________________________________
173 void AliMUONData::AddSDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *sdigits)
174 {
175   //
176   // Add a MUON Sdigit to the list of SDigits of the detection plane id
177   //
178   TClonesArray &lSdigits = * SDigits(id) ; 
179   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(tracks,charges,sdigits);
180 }
181 //_____________________________________________________________________________
182 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
183 {
184   //
185   // Add a MUON Sdigit to the list of SDigits of the detection plane id
186   //
187   TClonesArray &lSdigits = * SDigits(id) ; 
188   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
189 }
190 //_____________________________________________________________________________
191 void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
192                                    Int_t *singleUndef,
193                                    Int_t *pairUnlike, Int_t *pairLike)
194 {
195   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
196  
197   TClonesArray &globalTrigger = *fGlobalTrigger;
198   new(globalTrigger[fNglobaltrigger++]) 
199     AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, pairLike);
200 }
201 //_____________________________________________________________________________
202 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
203 {
204   // add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
205   TClonesArray &globalTrigger = *fGlobalTrigger;
206   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
207 }
208 //____________________________________________________________________________
209 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
210                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
211                          Float_t tof, Float_t momentum, Float_t theta, 
212                          Float_t phi, Float_t length, Float_t destep,
213                          Float_t Xref,Float_t Yref,Float_t Zref)
214 {
215  // Add new hit to the hit list
216   TClonesArray &lhits = *fHits;
217   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
218                                   idpart, X, Y, Z, 
219                                   tof, momentum, theta, 
220                                   phi, length, destep,
221                                   Xref,Yref,Zref);
222 }
223 //____________________________________________________________________________
224 void AliMUONData::AddHit2(Int_t fIshunt, Int_t track, Int_t detElemId, 
225                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
226                          Float_t tof, Float_t momentum, Float_t theta, 
227                          Float_t phi, Float_t length, Float_t destep,
228                          Float_t Xref,Float_t Yref,Float_t Zref)
229 {
230  // Add new hit to the hit list
231   TClonesArray &lhits = *fHits;
232   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, detElemId, 
233                                   idpart, X, Y, Z, 
234                                   tof, momentum, theta, 
235                                   phi, length, destep,
236                                   Xref,Yref,Zref, true);
237 }
238 //____________________________________________________________________________
239 void AliMUONData::AddLocalTrigger(const Int_t *localtr, const TArrayI& digits)
240 {
241   // add a MUON Local Trigger to the list
242   TClonesArray &localTrigger = *fLocalTrigger;
243   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr, digits);
244 }
245 //____________________________________________________________________________
246 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
247 {
248   // add a MUON Local Trigger to the list
249   TClonesArray &localTrigger = *fLocalTrigger;
250   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
251 }
252 //_____________________________________________________________________________
253 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
254 {
255   //
256   // Add a MUON rawcluster to the list in the detection plane id
257   //
258   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
259   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
260 }
261 //_____________________________________________________________________________
262 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
263 {
264   //
265   // Add a MUON rectrack
266   //
267   TClonesArray &lrectracks = *fRecTracks;
268   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
269   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
270 }
271 //_____________________________________________________________________________
272 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
273 {
274   //
275   // Add a MUON triggerrectrack
276   //
277   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
278   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
279   //  printf("TTTTTT %d ,\n",((AliMUONTrack*)fRecTracks->At(fNrectracks-1))->GetNTrackHits());
280 }
281
282 //____________________________________________________________________________
283 TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) const
284 {
285   //Getting List of Digits
286   if (fDigits)
287     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
288   else
289     return NULL;
290 }
291 //____________________________________________________________________________
292 TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) const
293 {
294   //Getting List of SDigits
295   if (fSDigits)
296     return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
297   else
298     return NULL;
299 }
300 //____________________________________________________________________________
301 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
302 {
303   // Checking if there are RawCluster Branches In TreeR
304   if (TreeR()==0x0) {
305     AliError("No treeR in memory");
306     return kFALSE;
307   }
308   else {
309      char branchname[30];
310      sprintf(branchname,"%sRawClusters1",GetName());
311      TBranch * branch = 0x0;
312      branch = TreeR()->GetBranch(branchname);
313      if (branch)  return kTRUE;
314      else return kFALSE;    
315   }
316 }
317 //____________________________________________________________________________
318 Bool_t   AliMUONData::IsDigitsBranchesInTree()
319 {
320   // Checking if there are RawCluster Branches In TreeR
321   if (TreeD()==0x0) {
322     AliError("No treeD in memory");
323     return kFALSE;
324   }
325   else {
326      char branchname[30];
327      sprintf(branchname,"%sDigits1",GetName());
328      TBranch * branch = 0x0;
329      branch = TreeD()->GetBranch(branchname);
330      if (branch)  return kTRUE;
331      else return kFALSE;    
332   }
333 }
334 //____________________________________________________________________________
335 Bool_t   AliMUONData::IsTriggerBranchesInTree()
336 {
337   // Checking if there are Trigger Branches In TreeR
338  if (TreeR()==0x0) {
339     AliError("No treeR in memory");
340     return kFALSE;
341   }
342   else {
343      char branchname[30];
344      sprintf(branchname,"%sLocalTrigger",GetName());
345      TBranch * branch = 0x0;
346      branch = TreeR()->GetBranch(branchname);
347      if (branch)  return kTRUE;
348      else return kFALSE;    
349   }
350 }
351 //____________________________________________________________________________
352 Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
353 {
354   // Checking if there are Trigger Branches In TreeR
355  if (TreeD()==0x0) {
356     AliError("No treeD in memory");
357     return kFALSE;
358   }
359   else {
360      char branchname[30];
361      sprintf(branchname,"%sLocalTrigger",GetName());
362      TBranch * branch = 0x0;
363      branch = TreeD()->GetBranch(branchname);
364      if (branch)  return kTRUE;
365      else return kFALSE;    
366   }
367 }
368
369 //____________________________________________________________________________
370 Bool_t   AliMUONData::IsTrackBranchesInTree()
371 {
372   // Checking if there are Track Branches In TreeT
373   if (TreeT()==0x0) {
374     AliError("No treeT in memory");
375     return kFALSE;
376   }
377   else {
378      char branchname[30];
379      sprintf(branchname,"%sTrack",GetName());
380      TBranch * branch = 0x0;
381      branch = TreeT()->GetBranch(branchname);
382      if (branch)  return kTRUE;
383      else return kFALSE;    
384   }
385 }
386 //____________________________________________________________________________
387 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
388 {
389   // Checking if there are TriggerTrack 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,"%sTriggerTrack",GetName());
397      TBranch * branch = 0x0;
398      branch = TreeT()->GetBranch(branchname);
399      if (branch)  return kTRUE;
400      else return kFALSE;    
401   }
402 }
403 //____________________________________________________________________________
404 void AliMUONData::Fill(Option_t* option)
405 {
406   // Method to fill the trees
407   const char *cH   = strstr(option,"H");
408   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
409   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
410   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
411   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
412   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
413   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
414   const char *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
415
416   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
417   
418   char branchname[30];
419   TBranch * branch = 0x0;
420
421   // Filling TreeH
422   if ( TreeH() && cH ) 
423   {
424     TreeH()->Fill();
425   }  
426  
427   // Filling TreeD
428
429   if ( TreeD() && cD && cGLT )
430   {
431     // Writing digits and (global+local) trigger at once.
432     TreeD()->Fill();
433   }
434   else
435   {
436     if ( TreeD() && cD ) 
437     {
438       if ( IsTriggerBranchesInTreeD() ) 
439       {
440         for (int i=0; i<AliMUONConstants::NCh(); i++) 
441         {
442           sprintf(branchname,"%sDigits%d",GetName(),i+1);
443           branch = TreeD()->GetBranch(branchname);
444           branch->Fill();
445         }
446       } 
447       else
448       {
449         TreeD()->Fill();
450       }
451     }
452     
453     if ( TreeD() && cGLT ) 
454     {
455       if ( IsDigitsBranchesInTree() ) 
456       {
457         sprintf(branchname,"%sLocalTrigger",GetName());
458         branch = TreeD()->GetBranch(branchname); 
459         branch->Fill();
460         sprintf(branchname,"%sGlobalTrigger",GetName());
461         branch = TreeD()->GetBranch(branchname);
462         branch->Fill();
463       } 
464       else
465       {
466         TreeD()->Fill();
467       }
468     }
469   } // end of TreeD() handling.
470
471   // Filling TreeS
472   if ( TreeS() && cS) 
473   {
474     TreeS()->Fill();
475   }
476
477   // Filling TreeR
478   
479   if ( TreeR() && cRC && cTC )
480   {
481     TreeR()->Fill();
482   }
483   else
484   {  
485     if ( TreeR()  && cRC ) 
486     {
487       if ( IsTriggerBranchesInTree() ) 
488       {
489       // Branch per branch filling
490         for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) 
491         {
492           sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
493           branch = TreeR()->GetBranch(branchname);
494           branch->Fill();
495         }
496       }
497       else  
498       {
499         TreeR()->Fill();
500       }
501     }
502     
503     if ( TreeR()  && cTC) 
504     {
505       if (IsRawClusterBranchesInTree()) 
506       {
507         // Branch per branch filling
508         sprintf(branchname,"%sLocalTrigger",GetName());
509         branch = TreeR()->GetBranch(branchname); 
510         branch->Fill();
511         sprintf(branchname,"%sGlobalTrigger",GetName());
512         branch = TreeR()->GetBranch(branchname);
513         branch->Fill();
514       }
515       else
516       {
517         TreeR()->Fill();
518       }
519     }
520   }
521
522   // Filling TreeT
523   
524   if ( TreeT() && cRT && cRL )
525   {
526     TreeT()->Fill();
527   }
528   else
529   {
530     if ( TreeT() && cRT ) 
531     {
532       if (IsTriggerTrackBranchesInTree()) 
533       {
534         sprintf(branchname,"%sTrack",GetName());  
535         branch = TreeT()->GetBranch(branchname);
536         branch->Fill();
537       }
538       else 
539       {
540         TreeT()->Fill();
541       }
542     }
543
544     if ( TreeT() && cRL ) 
545     {
546       if (IsTrackBranchesInTree()) 
547       {
548         sprintf(branchname,"%sTriggerTrack",GetName());  
549         branch = TreeT()->GetBranch(branchname);
550         branch->Fill();
551       }    
552       else 
553       {
554         TreeT()->Fill();
555       }
556     }
557   }
558 }
559
560 //_____________________________________________________________________________
561 void AliMUONData::MakeBranch(Option_t* option)
562 {
563   //
564   // Create Tree branches for the MUON.
565   //
566   const Int_t kBufferSize = 4000;
567   char branchname[30];
568   
569   
570   const char *cH   = strstr(option,"H");
571   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
572   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
573   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
574   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
575   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
576   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
577   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
578                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
579   
580   TBranch * branch = 0x0;
581   
582   // Creating Branches for Hits
583   if (TreeH() && cH) {
584     
585     if (fHits == 0x0)  {
586       fHits = new TClonesArray("AliMUONHit",1000);
587       //        if (gAlice->GetMCApp())
588       //          gAlice->GetMCApp()->AddHitList (fHits);
589     }
590     
591     fNhits = 0;
592     sprintf(branchname,"%sHits",GetName());  
593     branch = TreeH()->GetBranch(branchname);
594     if (branch) {  
595       AliInfo(Form("MakeBranch","Branch %s is already in tree.",branchname));
596       return ;
597     }
598     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
599     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
600   }  
601   
602   //Creating Branches for Digits
603   TTree* treeD = 0x0;
604   if ( cD || cGLT )
605   {
606     treeD = TreeD();
607   }
608
609   if ( treeD && cD ) 
610   {
611     // one branch for digits per chamber
612     if (fDigits  == 0x0) 
613     {
614       fDigits  = new TObjArray(AliMUONConstants::NCh());
615       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
616       {
617         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
618         tca->SetOwner();
619         fDigits->AddAt(tca,iDetectionPlane); 
620       }
621     }
622     if (fNdigits == 0x0) 
623     {
624       fNdigits = new Int_t[AliMUONConstants::NCh()];
625       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
626       {
627         fNdigits[iDetectionPlane]=0;
628       }
629     }
630     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
631     {
632       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
633       branch = treeD->GetBranch(branchname);
634       if (branch) 
635       {  
636         AliInfo(Form("Branch %s is already in tree.",branchname));
637         return;
638       }
639       TClonesArray * digits = Digits(iDetectionPlane); 
640       branch = treeD->Branch(branchname, &digits, kBufferSize,1);
641     }
642   }
643   
644   if ( treeD && cGLT ) 
645   {
646     //
647     // one branch for global trigger
648     //
649     sprintf(branchname,"%sGlobalTrigger",GetName());
650     
651     if (fGlobalTrigger == 0x0) 
652     {
653       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
654       fNglobaltrigger = 0;
655     }
656     branch = treeD->GetBranch(branchname);
657     if (branch) 
658     {  
659       AliInfo(Form("Branch GlobalTrigger is already in treeD."));
660       return ;
661     }
662     branch = treeD->Branch(branchname, &fGlobalTrigger, kBufferSize);
663
664     //
665     // one branch for local trigger
666     //  
667     sprintf(branchname,"%sLocalTrigger",GetName());
668     branch = 0x0;
669     
670     if (fLocalTrigger == 0x0) 
671     {
672       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
673       fNlocaltrigger = 0;
674     }
675     branch = treeD->GetBranch(branchname);
676     if (branch) 
677     {  
678       AliInfo(Form("Branch LocalTrigger is already in treeD."));
679       return;
680     }
681     branch = treeD->Branch(branchname, &fLocalTrigger, kBufferSize);
682   }
683     
684   //Creating Branches for SDigits
685   if (TreeS() && cS ) {
686     // one branch for Sdigits per chamber
687     if (fSDigits  == 0x0) {
688       fSDigits  = new TObjArray(AliMUONConstants::NCh());
689       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
690         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
691         tca->SetOwner();
692         fSDigits->AddAt(tca,iDetectionPlane); 
693       }
694     }
695     if (fNSdigits == 0x0) {
696       fNSdigits = new Int_t[AliMUONConstants::NCh()];
697       for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
698         fNSdigits[iDetectionPlane]=0;
699       }
700     }
701     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
702       sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
703       branch = 0x0;
704       branch = TreeS()->GetBranch(branchname);
705       if (branch) {  
706         AliInfo(Form("Branch %s is already in tree.",branchname));
707         return;
708       }
709       TClonesArray * sdigits = SDigits(iDetectionPlane); 
710       branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
711       //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
712     }
713   }
714   
715   if (TreeR() && cRC ) {
716     //  one branch for raw clusters per tracking detection plane
717     //        
718     Int_t i;
719     if (fRawClusters == 0x0) {
720       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
721       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
722         TClonesArray * tca = new TClonesArray("AliMUONRawCluster",1000);
723         tca->SetOwner();
724         fRawClusters->AddAt(tca,i); 
725       }
726     }
727     
728     if (fNrawclusters == 0x0) {
729       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
730       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
731         fNrawclusters[i]=0;
732       }
733     }
734     
735     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
736       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
737       branch = 0x0;
738       branch = TreeR()->GetBranch(branchname);
739       if (branch) {  
740         AliInfo(Form("Branch %s is already in tree.",branchname));
741         return;
742       }
743       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
744       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
745     }
746   }
747   
748   if (TreeR() && cTC ) {
749     //
750     // one branch for global trigger
751     //
752     sprintf(branchname,"%sGlobalTrigger",GetName());
753     branch = 0x0;
754     
755     if (fGlobalTrigger == 0x0) {
756       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger"); 
757       fNglobaltrigger = 0;
758     }
759     branch = TreeR()->GetBranch(branchname);
760     if (branch) {  
761       AliInfo(Form("Branch GlobalTrigger is already in treeR."));
762       return ;
763     }
764     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
765     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
766     
767     //
768     // one branch for local trigger
769     //  
770     sprintf(branchname,"%sLocalTrigger",GetName());
771     branch = 0x0;
772     
773     if (fLocalTrigger == 0x0) {
774       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
775       fNlocaltrigger = 0;
776     }
777     branch = TreeR()->GetBranch(branchname);
778     if (branch) {  
779       AliInfo(Form("Branch LocalTrigger is already in treeR."));
780       return;
781     }
782     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
783     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
784   }
785   
786   if (TreeT() && cRT ) {
787     if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",100);
788     fNrectracks = 0;
789     sprintf(branchname,"%sTrack",GetName());  
790     branch = TreeT()->GetBranch(branchname);
791     if (branch) {  
792       AliInfo(Form("Branch %s is already in tree.",GetName()));
793       return ;
794     }
795     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
796     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
797   }  
798   // trigger tracks
799   if (TreeT() && cRL ) {
800     if (fRecTriggerTracks == 0x0)  fRecTriggerTracks = new TClonesArray("AliMUONTriggerTrack",100);
801     fNrectriggertracks = 0;
802     sprintf(branchname,"%sTriggerTrack",GetName());  
803     branch = TreeT()->GetBranch(branchname);
804     if (branch) {  
805       AliInfo(Form("Branch %s is already in tree.",GetName()));
806       return ;
807     }
808     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
809     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
810   }  
811 }
812 //____________________________________________________________________________
813 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
814 {
815   // Getting Raw Clusters
816   if (fRawClusters) 
817     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
818   else
819     return NULL;
820 }
821
822 //____________________________________________________________________________
823 TClonesArray*  
824 AliMUONData::LocalTrigger() const
825 {
826   return fLocalTrigger;
827 }
828
829 //____________________________________________________________________________
830 void
831 AliMUONData::GetDigits() const 
832 {
833   // Load the digits from TreeD for the current event.
834   Int_t event = fLoader->GetRunLoader()->GetEventNumber();
835   if ( fCurrentEvent != event )
836   {
837     fLoader->TreeD()->GetEvent(0);
838     fCurrentEvent = event;
839   }
840 }
841
842 //____________________________________________________________________________
843 TClonesArray*  
844 AliMUONData::GlobalTrigger() const
845 {
846   // Return the global trigger 
847   return fGlobalTrigger;
848 }
849
850 //____________________________________________________________________________
851 void AliMUONData::ResetDigits()
852 {
853     //
854     // Reset number of digits and the digits array for this detector
855     //
856     if (fDigits == 0x0) return;
857     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
858       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear("C");
859       if (fNdigits)  fNdigits[i]=0;
860     }
861 }
862 //____________________________________________________________________________
863 void AliMUONData::ResetSDigits()
864 {
865     //
866     // Reset number of Sdigits and the Sdigits array for this detector
867     //
868     if (fSDigits == 0x0) return;
869     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
870       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
871       if (fNSdigits)  fNSdigits[i]=0;
872     }
873 }
874 //______________________________________________________________________________
875 void AliMUONData::ResetHits()
876 {
877   // Reset number of clusters and the cluster array for this detector
878   fNhits   = 0;
879   if (fHits) fHits->Clear();
880 }
881 //_______________________________________________________________________________
882 void AliMUONData::ResetRawClusters()
883 {
884     // Reset number of raw clusters and the raw clust array for this detector
885     //
886   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
887     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
888     if (fNrawclusters)  fNrawclusters[i]=0;
889   }
890 }
891 //_______________________________________________________________________________
892 void AliMUONData::ResetTrigger()
893 {
894   //  Reset Local and Global Trigger 
895   fNglobaltrigger = 0;
896   if (fGlobalTrigger) fGlobalTrigger->Clear();
897   fNlocaltrigger = 0;
898   if (fLocalTrigger) fLocalTrigger->Clear();
899 }
900 //____________________________________________________________________________
901 void AliMUONData::ResetRecTracks()
902 {
903   // Reset tracks information
904   fNrectracks = 0;
905   if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
906 }
907 //____________________________________________________________________________
908 void AliMUONData::ResetRecTriggerTracks()
909 {
910   // Reset tracks information
911   fNrectriggertracks = 0;
912   if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
913 }
914 //_____________________________________________________________________________
915 void AliMUONData::SetTreeAddress(Option_t* option)
916 {
917   //Setting Addresses to the events trees
918   const char *cH   = strstr(option,"H");
919   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
920   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
921   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
922   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
923   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
924   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
925   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
926                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
927   
928   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
929   char branchname[30];
930   TBranch * branch = 0x0;
931   
932   AliDebug(1,Form("option=%s",option));
933   //
934   // Branch address for hit tree
935   if ( TreeH() && cH ) {
936     if (fHits == 0x0) {
937       fHits     = new TClonesArray("AliMUONHit",1000);
938       //        if (gAlice->GetMCApp())
939       //  gAlice->GetMCApp()->AddHitList (fHits);  Moved to AliMUON
940     }
941     fNhits =0;
942   } 
943   if (TreeH() && fHits && cH) {
944     sprintf(branchname,"%sHits",GetName());  
945     branch = TreeH()->GetBranch(branchname);
946     if (branch) {
947       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
948       branch->SetAddress(&fHits);
949     }
950     else { //can be invoked before branch creation
951       AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
952     }
953   }
954   
955   //
956   // Branch address for digit tree
957   if ( TreeD() ) {      
958     if (fDigits == 0x0 && cD) {
959       fDigits = new TObjArray(AliMUONConstants::NCh());
960       fNdigits= new Int_t[AliMUONConstants::NCh()];
961       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
962         fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
963         fNdigits[i]=0;
964       }
965     }
966     if (fLocalTrigger == 0x0 && cGLT) {
967       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
968     }
969     if (fGlobalTrigger== 0x0 && cGLT) {
970       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
971     }
972   }
973   
974   if (TreeD() && fDigits && cD) {
975     for (int i=0; i<AliMUONConstants::NCh(); i++) {
976       sprintf(branchname,"%sDigits%d",GetName(),i+1);
977       if (fDigits) {
978         branch = TreeD()->GetBranch(branchname);
979         TClonesArray * digits = Digits(i);
980         if (branch) {
981           branch->SetAddress( &digits );
982         }
983         else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
984       }
985     }
986   }
987   if ( TreeD()  && fLocalTrigger && cGLT) {
988     sprintf(branchname,"%sLocalTrigger",GetName());
989     branch = TreeD()->GetBranch(branchname);
990     if (branch) branch->SetAddress(&fLocalTrigger);
991     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
992   }
993   if ( TreeD() && fGlobalTrigger && cGLT) {
994     sprintf(branchname,"%sGlobalTrigger",GetName());
995     branch = TreeD()->GetBranch(branchname);
996     if (branch) branch->SetAddress(&fGlobalTrigger);
997     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
998   }
999   
1000   //
1001   // Branch address for Sdigit tree
1002   if ( TreeS() && cS) 
1003   {
1004     if (fSDigits == 0x0) 
1005     { 
1006       AliDebug(1,"Creating fSDigits TObjArray");
1007       fSDigits = new TObjArray(AliMUONConstants::NCh());
1008       fNSdigits= new Int_t[AliMUONConstants::NCh()];
1009       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) 
1010       {
1011         TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
1012         fSDigits->AddAt(a,i);
1013         AliDebug(1,Form("fSDigits[%d]=%p",i,a));
1014         fNSdigits[i]=0;
1015       }
1016     }
1017     else
1018     {
1019       AliDebug(1,Form("fSDigits already there = %p",fSDigits));
1020     }
1021   }
1022   
1023   if (TreeS() && fSDigits && cS) {
1024     AliDebug(1,"Setting branch addresses");
1025     for (int i=0; i<AliMUONConstants::NCh(); i++) {
1026       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
1027       if (fSDigits) {
1028         AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
1029                         TreeS(),i,branchname));
1030         branch = TreeS()->GetBranch(branchname);
1031         TClonesArray * sdigits = SDigits(i);
1032         if (branch) branch->SetAddress( &sdigits );
1033         else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
1034       }
1035     }
1036   }
1037   
1038   //
1039   // Branch address for rawclusters, globaltrigger and local trigger tree
1040   if (TreeR() ) {
1041     if (fRawClusters == 0x0 && cRC) {
1042       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
1043       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
1044       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
1045         fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
1046         fNrawclusters[i]=0;
1047       }
1048     }
1049     if (fLocalTrigger == 0x0 && cTC) {
1050       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
1051     }
1052     if (fGlobalTrigger== 0x0 && cTC) {
1053       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
1054     }
1055     
1056   }
1057   if ( TreeR()  && fRawClusters && cRC && !strstr(cRC,"RCC")) {
1058     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
1059       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
1060       if (fRawClusters) {
1061         branch = TreeR()->GetBranch(branchname);
1062         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
1063         else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
1064       }
1065     }
1066   }
1067   if ( TreeR()  && fLocalTrigger && cTC) {
1068     sprintf(branchname,"%sLocalTrigger",GetName());
1069     branch = TreeR()->GetBranch(branchname);
1070     if (branch) branch->SetAddress(&fLocalTrigger);
1071     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
1072   }
1073   if ( TreeR() && fGlobalTrigger && cTC) {
1074     sprintf(branchname,"%sGlobalTrigger",GetName());
1075     branch = TreeR()->GetBranch(branchname);
1076     if (branch) branch->SetAddress(&fGlobalTrigger);
1077     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
1078   }
1079   
1080   if ( TreeT() ) {
1081     if (fRecTracks == 0x0 && cRT)  {
1082       fRecTracks  = new TClonesArray("AliMUONTrack",100);
1083     }
1084     
1085   }
1086   if ( TreeT() && fRecTracks && cRT ) {
1087     sprintf(branchname,"%sTrack",GetName());  
1088     branch = TreeT()->GetBranch(branchname);
1089     if (branch) branch->SetAddress(&fRecTracks);
1090     else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
1091   }
1092   // trigger tracks
1093   if ( TreeT() ) {
1094     if (fRecTriggerTracks == 0x0 && cRL)  {
1095       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
1096     }
1097     
1098   }
1099   if ( TreeT() && fRecTriggerTracks && cRL ) {
1100     sprintf(branchname,"%sTriggerTrack",GetName());  
1101     branch = TreeT()->GetBranch(branchname);
1102     if (branch) branch->SetAddress(&fRecTriggerTracks);
1103     else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
1104   }
1105   
1106   
1107 }
1108
1109 //_____________________________________________________________________________
1110 void
1111 AliMUONData::Print(Option_t* opt) const
1112 {
1113   // Dump object on screen
1114   TString options(opt);
1115   options.ToUpper();
1116   
1117   if ( options.Contains("D") )
1118   {
1119     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1120     {
1121       TClonesArray* digits = Digits(ich);
1122       Int_t ndigits = digits->GetEntriesFast();
1123       for ( Int_t id = 0; id < ndigits; ++id )
1124       {
1125         AliMUONDigit* digit = 
1126           static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1127         digit->Print();
1128       }
1129     }
1130   }
1131   
1132   if ( options.Contains("S") )
1133   {
1134     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1135     {
1136       TClonesArray* digits = SDigits(ich);
1137       Int_t ndigits = digits->GetEntriesFast();
1138       for ( Int_t id = 0; id < ndigits; ++id )
1139       {
1140         AliMUONDigit* digit = 
1141         static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1142         digit->Print();
1143       }
1144     }
1145   }
1146   
1147 }