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