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