]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONData.cxx
Updated comments for Doxygen
[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 /// \class 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 /// \author Gines Martinez, Subatech,  September 2003
24 ///
25
26 #include "AliMUONData.h"
27 #include "AliMUONDataIterator.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONHit.h"
30 #include "AliMUONDigit.h"
31 #include "AliMUONGlobalTrigger.h"
32 #include "AliMUONLocalTrigger.h"
33 #include "AliMUONRegionalTrigger.h"
34 #include "AliMUONTriggerCrateStore.h"
35 #include "AliMUONTriggerCircuit.h"
36 #include "AliMUONGeometryTransformer.h"
37 #include "AliMUONRawCluster.h"
38
39 // This is from rec, classes in base should not depend on rec !!!
40 #include "AliMUONTrack.h"
41 #include "AliMUONTriggerTrack.h"
42
43 #include "AliRunLoader.h"
44 #include "AliStack.h"
45 #include "AliLog.h"
46
47 #include <TString.h>
48 #include <TParticle.h>
49 #include <TNtuple.h>
50 #include <Riostream.h>
51 #include <TFile.h>
52
53 /// \cond CLASSIMP
54 ClassImp(AliMUONData)
55 /// \endcond
56  
57 //_____________________________________________________________________________
58   AliMUONData::AliMUONData():
59     TNamed(),
60     fRunLoader(0x0),
61     fLoader(0x0),
62     fHits(0x0),
63     fDigits(0x0),
64     fSDigits(0x0),
65     fRawClusters(0x0),
66     fGlobalTrigger(0x0),
67     fLocalTrigger(0x0),
68     fRegionalTrigger(0x0),
69     fRecTracks(0x0),
70     fRecTriggerTracks(0x0),
71     fNhits(0),
72     fNdigits(0x0),
73     fNSdigits(0x0),
74     fNrawclusters(0x0),
75     fNglobaltrigger(0),
76     fNlocaltrigger(0),
77     fNregionaltrigger(0),
78     fNrectracks(0),
79     fNrectriggertracks(0),
80     fSplitLevel(0),
81     fCurrentEvent(-1)
82 {
83   // Default constructor
84 }
85 //_____________________________________________________________________________
86 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
87   TNamed(name,title),
88     fRunLoader(0x0),
89     fLoader(loader),
90     fHits(0x0),
91     fDigits(0x0),
92     fSDigits(0x0),
93     fRawClusters(0x0),
94     fGlobalTrigger(0x0),
95     fLocalTrigger(0x0),
96     fRegionalTrigger(0x0),
97     fRecTracks(0x0),
98     fRecTriggerTracks(0x0),
99     fNhits(0),
100     fNdigits(0x0),
101     fNSdigits(0x0),
102     fNrawclusters(0x0),
103     fNglobaltrigger(0),
104     fNlocaltrigger(0),
105     fNregionaltrigger(0),
106     fNrectracks(0),
107     fNrectriggertracks(0),
108     fSplitLevel(0),
109     fCurrentEvent(-1)
110 {
111 /// Standard constructor
112 }
113
114 //_____________________________________________________________________________
115 AliMUONData::AliMUONData(const char* galiceFile):
116   TNamed("MUON", "MUON"),
117     fRunLoader(0x0),
118     fLoader(0x0),
119     fHits(0x0),
120     fDigits(0x0),
121     fSDigits(0x0),
122     fRawClusters(0x0),
123     fGlobalTrigger(0x0),
124     fLocalTrigger(0x0),
125     fRegionalTrigger(0x0),
126     fRecTracks(0x0),
127     fRecTriggerTracks(0x0),
128     fNhits(0),
129     fNdigits(0x0),
130     fNSdigits(0x0),
131     fNrawclusters(0x0),
132     fNglobaltrigger(0),
133     fNlocaltrigger(0),
134     fNregionaltrigger(0),
135     fNrectracks(0),
136     fNrectriggertracks(0),
137     fSplitLevel(0),
138     fCurrentEvent(-1)
139 {
140 /// Constructor for loading data from gAlice file
141
142   fRunLoader = AliRunLoader::Open(galiceFile, "MUONFolder", "READ");
143   if (!fRunLoader) {
144     AliError(Form("Error opening %s file \n", galiceFile));
145     return;
146   }  
147
148   fLoader = fRunLoader->GetLoader("MUONLoader");
149   if ( ! fLoader ) {
150     AliError(Form("Could get MUONLoader"));
151     return;
152   }  
153 }
154
155 //_____________________________________________________________________________
156 AliMUONData::~AliMUONData()
157 {
158 /// Destructor for AliMUONData
159   if (fHits) {
160     fHits->Delete();
161     delete fHits;
162   }
163   
164   if (fDigits) {
165     fDigits->Delete();
166     delete fDigits;
167   }
168   if (fSDigits) {
169     fSDigits->Delete();
170     delete fSDigits;
171   }
172   if (fRawClusters) {
173     fRawClusters->Delete();
174     delete fRawClusters;
175   }
176   if (fGlobalTrigger){
177     fGlobalTrigger->Delete();
178     delete fGlobalTrigger;
179   }  
180   if (fRegionalTrigger){
181     fRegionalTrigger->Delete();
182     delete fRegionalTrigger;
183   }
184   if (fLocalTrigger){
185     fLocalTrigger->Delete();
186     delete fLocalTrigger;
187   }
188   if (fRecTracks){
189     fRecTracks->Delete();
190     delete fRecTracks;
191   }
192   if (fRecTriggerTracks){
193     fRecTriggerTracks->Delete();
194     delete fRecTriggerTracks;
195   }
196
197   if (fRunLoader) {
198     fRunLoader->UnloadAll();
199     delete fRunLoader;
200   }  
201 }
202 //____________________________________________________________________________
203 void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t detElemId, 
204                          Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
205                          Float_t tof, Float_t momentum, Float_t theta, 
206                          Float_t phi, Float_t length, Float_t destep,
207                          Float_t Xref,Float_t Yref,Float_t Zref)
208 {
209  // Add new hit to the hit list
210
211   TClonesArray &lhits = *fHits;
212   new(lhits[fNhits++]) AliMUONHit(fIshunt, track, detElemId, 
213                                   idpart, X, Y, Z, 
214                                   tof, momentum, theta, 
215                                   phi, length, destep,
216                                   Xref,Yref,Zref);
217 }
218 //_____________________________________________________________________________
219 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
220 {
221 /// Add a MUON digit to the list of Digits of the detection plane id
222
223   TClonesArray &ldigits = * Digits(id) ; 
224   new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
225 }
226 //_____________________________________________________________________________
227 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
228 {
229 /// Add a MUON Sdigit to the list of SDigits of the detection plane id
230
231   TClonesArray &lSdigits = * SDigits(id) ; 
232   new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
233 }
234
235 //_____________________________________________________________________________
236 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
237 {
238 /// Add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
239
240   TClonesArray &globalTrigger = *fGlobalTrigger;
241   new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
242 }
243
244 //____________________________________________________________________________
245 void AliMUONData::AddRegionalTrigger(const  AliMUONRegionalTrigger& trigger)
246 {
247 /// add a MUON regional Trigger to the list
248   TClonesArray &regionalTrigger = *fRegionalTrigger;
249   new(regionalTrigger[fNregionaltrigger++]) AliMUONRegionalTrigger(trigger);
250 }
251 //____________________________________________________________________________
252 void AliMUONData::AddLocalTrigger(const  AliMUONLocalTrigger& trigger)
253 {
254 /// add a MUON Local Trigger to the list
255
256   TClonesArray &localTrigger = *fLocalTrigger;
257   new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
258 }
259
260 //_____________________________________________________________________________
261 void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
262 {
263 /// Add a MUON rawcluster to the list in the detection plane id
264
265   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
266   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
267 }
268 //_____________________________________________________________________________
269 void AliMUONData::AddRecTrack(const AliMUONTrack& track)
270 {
271 /// Add a MUON rectrack
272
273   TClonesArray &lrectracks = *fRecTracks;
274   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
275 }
276 //_____________________________________________________________________________
277 void AliMUONData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
278 {
279 /// Add a MUON triggerrectrack
280
281   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
282   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
283 }
284 //____________________________________________________________________________
285 TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) const
286 {
287 /// Getting List of Digits
288
289   if (fDigits)
290     return ( (TClonesArray*) fDigits->At(DetectionPlane) );
291   else
292     return NULL;
293 }
294 //____________________________________________________________________________
295 TClonesArray*  AliMUONData::SDigits(Int_t DetectionPlane) const
296 {
297 /// Getting List of SDigits
298
299   if (fSDigits)
300     return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
301   else
302     return NULL;
303 }
304 //____________________________________________________________________________
305 Bool_t   AliMUONData::IsRawClusterBranchesInTree()
306 {
307 /// Checking if there are RawCluster Branches In TreeR
308
309   if (TreeR()==0x0) {
310     AliError("No treeR in memory");
311     return kFALSE;
312   }
313   else {
314      char branchname[30];
315      sprintf(branchname,"%sRawClusters1",GetName());
316      TBranch * branch = 0x0;
317      branch = TreeR()->GetBranch(branchname);
318      if (branch)  return kTRUE;
319      else return kFALSE;    
320   }
321 }
322 //____________________________________________________________________________
323 Bool_t   AliMUONData::IsDigitsBranchesInTree()
324 {
325 /// Checking if there are RawCluster Branches In TreeR
326
327   if (TreeD()==0x0) {
328     AliError("No treeD in memory");
329     return kFALSE;
330   }
331   else {
332      char branchname[30];
333      sprintf(branchname,"%sDigits1",GetName());
334      TBranch * branch = 0x0;
335      branch = TreeD()->GetBranch(branchname);
336      if (branch)  return kTRUE;
337      else return kFALSE;    
338   }
339 }
340 //____________________________________________________________________________
341 Bool_t   AliMUONData::IsTriggerBranchesInTree()
342 {
343 /// Checking if there are Trigger Branches In TreeR
344  if (TreeR()==0x0) {
345     AliError("No treeR in memory");
346     return kFALSE;
347   }
348   else {
349      char branchname[30];
350      sprintf(branchname,"%sLocalTrigger",GetName());
351      TBranch * branch = 0x0;
352      branch = TreeR()->GetBranch(branchname);
353      if (branch)  return kTRUE;
354      else return kFALSE;    
355   }
356 }
357 //____________________________________________________________________________
358 Bool_t   AliMUONData::IsTriggerBranchesInTreeD()
359 {
360 /// Checking if there are Trigger Branches In TreeR
361  if (TreeD()==0x0) {
362     AliError("No treeD in memory");
363     return kFALSE;
364   }
365   else {
366      char branchname[30];
367      sprintf(branchname,"%sLocalTrigger",GetName());
368      TBranch * branch = 0x0;
369      branch = TreeD()->GetBranch(branchname);
370      if (branch)  return kTRUE;
371      else return kFALSE;    
372   }
373 }
374
375 //____________________________________________________________________________
376 Bool_t   AliMUONData::IsTrackBranchesInTree()
377 {
378 /// Checking if there are Track Branches In TreeT
379   if (TreeT()==0x0) {
380     AliError("No treeT in memory");
381     return kFALSE;
382   }
383   else {
384      char branchname[30];
385      sprintf(branchname,"%sTrack",GetName());
386      TBranch * branch = 0x0;
387      branch = TreeT()->GetBranch(branchname);
388      if (branch)  return kTRUE;
389      else return kFALSE;    
390   }
391 }
392 //____________________________________________________________________________
393 Bool_t   AliMUONData::IsTriggerTrackBranchesInTree()
394 {
395 /// Checking if there are TriggerTrack Branches In TreeT
396   if (TreeT()==0x0) {
397     AliError("No treeT in memory");
398     return kFALSE;
399   }
400   else {
401      char branchname[30];
402      sprintf(branchname,"%sTriggerTrack",GetName());
403      TBranch * branch = 0x0;
404      branch = TreeT()->GetBranch(branchname);
405      if (branch)  return kTRUE;
406      else return kFALSE;    
407   }
408 }
409 //____________________________________________________________________________
410 void AliMUONData::Fill(Option_t* option)
411 {
412 /// Method to fill the trees
413   const char *cH   = strstr(option,"H");
414   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
415   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
416   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
417   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
418   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
419   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
420   const char *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
421
422   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
423   
424   char branchname[30];
425   TBranch * branch = 0x0;
426
427   // Filling TreeH
428   if ( TreeH() && cH ) 
429   {
430     TreeH()->Fill();
431   }  
432  
433   // Filling TreeD
434
435   if ( TreeD() && cD && cGLT )
436   {
437     // Writing digits and (global+local) trigger at once.
438     TreeD()->Fill();
439   }
440   else
441   {
442     if ( TreeD() && cD ) 
443     {
444       if ( IsTriggerBranchesInTreeD() ) 
445       {
446         for (int i=0; i<AliMUONConstants::NCh(); i++) 
447         {
448           sprintf(branchname,"%sDigits%d",GetName(),i+1);
449           branch = TreeD()->GetBranch(branchname);
450           branch->Fill();
451         }
452       } 
453       else
454       {
455         TreeD()->Fill();
456       }
457     }
458     
459     if ( TreeD() && cGLT ) 
460     {
461       if ( IsDigitsBranchesInTree() ) 
462       {
463         sprintf(branchname,"%sLocalTrigger",GetName());
464         branch = TreeD()->GetBranch(branchname); 
465         branch->Fill();
466         sprintf(branchname,"%sRegionalTrigger",GetName());
467         branch = TreeD()->GetBranch(branchname);
468         branch->Fill();
469         sprintf(branchname,"%sGlobalTrigger",GetName());
470         branch = TreeD()->GetBranch(branchname);
471         branch->Fill();
472
473       } 
474       else
475       {
476         TreeD()->Fill();
477       }
478     }
479   } // end of TreeD() handling.
480
481   // Filling TreeS
482   if ( TreeS() && cS) 
483   {
484     TreeS()->Fill();
485   }
486
487   // Filling TreeR
488   
489   if ( TreeR() && cRC && cTC )
490   {
491     TreeR()->Fill();
492   }
493   else
494   {  
495     if ( TreeR()  && cRC ) 
496     {
497       if ( IsTriggerBranchesInTree() ) 
498       {
499       // Branch per branch filling
500         for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) 
501         {
502           sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
503           branch = TreeR()->GetBranch(branchname);
504           branch->Fill();
505         }
506       }
507       else  
508       {
509         TreeR()->Fill();
510       }
511     }
512     
513     if ( TreeR()  && cTC) 
514     {
515       if (IsRawClusterBranchesInTree()) 
516       {
517         // Branch per branch filling
518         sprintf(branchname,"%sLocalTrigger",GetName());
519         branch = TreeR()->GetBranch(branchname); 
520         branch->Fill();
521         sprintf(branchname,"%sRegionalTrigger",GetName());
522         branch = TreeR()->GetBranch(branchname); 
523         branch->Fill();
524         sprintf(branchname,"%sGlobalTrigger",GetName());
525         branch = TreeR()->GetBranch(branchname);
526         branch->Fill();
527       }
528       else
529       {
530         TreeR()->Fill();
531       }
532     }
533   }
534
535   // Filling TreeT
536   
537   if ( TreeT() && cRT && cRL )
538   {
539     TreeT()->Fill();
540   }
541   else
542   {
543     if ( TreeT() && cRT ) 
544     {
545       if (IsTriggerTrackBranchesInTree()) 
546       {
547         sprintf(branchname,"%sTrack",GetName());  
548         branch = TreeT()->GetBranch(branchname);
549         branch->Fill();
550       }
551       else 
552       {
553         TreeT()->Fill();
554       }
555     }
556
557     if ( TreeT() && cRL ) 
558     {
559       if (IsTrackBranchesInTree()) 
560       {
561         sprintf(branchname,"%sTriggerTrack",GetName());  
562         branch = TreeT()->GetBranch(branchname);
563         branch->Fill();
564       }    
565       else 
566       {
567         TreeT()->Fill();
568       }
569     }
570   }
571 }
572
573 //_____________________________________________________________________________
574 void AliMUONData::MakeBranch(Option_t* option)
575 {
576 /// Create Tree branches for the MUON.
577
578   const Int_t kBufferSize = 4000;
579   char branchname[30];
580   
581   //Setting Data Container
582   SetDataContainer(option);  
583
584   const char *cH   = strstr(option,"H");
585   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
586   const char *cS   = strstr(option,"S");   // Digits branches in TreeS
587   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
588   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
589   const char *cTC  = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
590   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
591   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
592                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
593   
594   TBranch * branch = 0x0;
595   
596   // Creating Branches for Hits
597   if (TreeH() && cH) {
598     sprintf(branchname,"%sHits",GetName());  
599     branch = TreeH()->GetBranch(branchname);
600     if (branch) {  
601       AliInfo(Form("MakeBranch","Branch %s is already in tree.",branchname));
602       return ;
603     }
604     branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
605     //Info("MakeBranch","Making Branch %s for hits \n",branchname);
606   }  
607   
608   //Creating Branches for Digits
609   TTree* treeD = 0x0;
610   if ( cD || cGLT )
611   {
612     treeD = TreeD();
613   }
614
615   if ( treeD && cD ) 
616   {
617     // one branch for digits per chamber
618     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) 
619     {
620       sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
621       branch = treeD->GetBranch(branchname);
622       if (branch) 
623       {  
624         AliInfo(Form("Branch %s is already in tree.",branchname));
625         return;
626       }
627       TClonesArray * digits = Digits(iDetectionPlane); 
628       branch = treeD->Branch(branchname, &digits, kBufferSize,1);
629     }
630   }
631   
632   if ( treeD && cGLT ) 
633   {
634     //
635     // one branch for global trigger
636     //
637     sprintf(branchname,"%sGlobalTrigger",GetName());
638     branch = treeD->GetBranch(branchname);
639     if (branch) 
640     {  
641       AliInfo(Form("Branch GlobalTrigger is already in treeD."));
642       return ;
643     }
644     branch = treeD->Branch(branchname, &fGlobalTrigger, kBufferSize);
645
646   //
647     // one branch for regional trigger
648     //  
649     sprintf(branchname,"%sRegionalTrigger",GetName());
650     branch = 0x0;
651     branch = treeD->GetBranch(branchname);
652     if (branch) 
653     {  
654       AliInfo(Form("Branch RegionalTrigger is already in treeD."));
655       return;
656     }
657     branch = treeD->Branch(branchname, &fRegionalTrigger, kBufferSize);
658   
659
660     //
661     // one branch for local trigger
662     //  
663     sprintf(branchname,"%sLocalTrigger",GetName());
664     branch = 0x0;
665     branch = treeD->GetBranch(branchname);
666     if (branch) 
667     {  
668       AliInfo(Form("Branch LocalTrigger is already in treeD."));
669       return;
670     }
671     branch = treeD->Branch(branchname, &fLocalTrigger, kBufferSize);
672   }
673     
674   //Creating Branches for SDigits
675   if (TreeS() && cS ) {
676     // one branch for Sdigits per chamber
677     for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
678       sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
679       branch = 0x0;
680       branch = TreeS()->GetBranch(branchname);
681       if (branch) {  
682         AliInfo(Form("Branch %s is already in tree.",branchname));
683         return;
684       }
685       TClonesArray * sdigits = SDigits(iDetectionPlane); 
686       branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
687       //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
688     }
689   }
690   
691   if (TreeR() && cRC ) {
692     //  one branch for raw clusters per tracking detection plane
693     //        
694     Int_t i; 
695     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
696       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
697       branch = 0x0;
698       branch = TreeR()->GetBranch(branchname);
699       if (branch) {  
700         AliInfo(Form("Branch %s is already in tree.",branchname));
701         return;
702       }
703       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
704       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
705     }
706   }
707   
708   if (TreeR() && cTC ) {
709     //
710     // one branch for global trigger
711     //
712     sprintf(branchname,"%sGlobalTrigger",GetName());
713     branch = 0x0;
714     branch = TreeR()->GetBranch(branchname);
715     if (branch) {  
716       AliInfo(Form("Branch GlobalTrigger is already in treeR."));
717       return ;
718     }
719     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
720     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
721
722   //
723     // one branch for regional trigger
724     //  
725     sprintf(branchname,"%sRegionalTrigger",GetName());
726     branch = 0x0;
727     branch = TreeR()->GetBranch(branchname);
728     if (branch) {  
729       AliInfo(Form("Branch RegionalTrigger is already in treeR."));
730       return;
731     }
732     branch = TreeR()->Branch(branchname, &fRegionalTrigger, kBufferSize);
733      
734     //
735     // one branch for local trigger
736     //  
737     sprintf(branchname,"%sLocalTrigger",GetName());
738     branch = 0x0;
739     branch = TreeR()->GetBranch(branchname);
740     if (branch) {  
741       AliInfo(Form("Branch LocalTrigger is already in treeR."));
742       return;
743     }
744     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
745     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
746   }
747   
748   if (TreeT() && cRT ) {
749     sprintf(branchname,"%sTrack",GetName());  
750     branch = TreeT()->GetBranch(branchname);
751     if (branch) {  
752       AliInfo(Form("Branch %s is already in tree.",GetName()));
753       return ;
754     }
755     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
756     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
757   }  
758   // trigger tracks
759   if (TreeT() && cRL ) {
760     sprintf(branchname,"%sTriggerTrack",GetName());  
761     branch = TreeT()->GetBranch(branchname);
762     if (branch) {  
763       AliInfo(Form("Branch %s is already in tree.",GetName()));
764       return ;
765     }
766     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
767     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
768   }  
769 }
770 //____________________________________________________________________________
771 TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
772 {
773 /// Getting Raw Clusters
774
775   if (fRawClusters) 
776     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
777   else
778     return NULL;
779 }
780
781 //____________________________________________________________________________
782 TClonesArray*  
783 AliMUONData::LocalTrigger() const
784 {
785 /// Getting local trigger
786
787   return fLocalTrigger;
788 }
789
790 //____________________________________________________________________________
791 TClonesArray*  
792 AliMUONData::RegionalTrigger() const
793 {
794 /// Getting regional trigger
795
796   return fRegionalTrigger;
797 }
798
799 //____________________________________________________________________________
800 Int_t          
801 AliMUONData::GetNtracks() const      
802 {
803 /// Get number of entries in hits three
804
805   Int_t ntrk = 0;
806   if (fLoader && fLoader->TreeH())
807     ntrk = (Int_t) fLoader->TreeH()->GetEntries();
808   return ntrk;
809 }
810
811 //____________________________________________________________________________
812 void
813 AliMUONData::GetDigits() const 
814 {
815 /// Load the digits from TreeD for the current event.
816
817   Int_t event = fLoader->GetRunLoader()->GetEventNumber();
818   if ( fCurrentEvent != event )
819   {
820     if (fLoader->TreeD()) {
821       fLoader->TreeD()->GetEvent(0);
822       fCurrentEvent = event;
823     }
824   }
825 }
826
827 //____________________________________________________________________________
828 TClonesArray*  
829 AliMUONData::GlobalTrigger() const
830 {
831 /// Return the global trigger 
832
833   return fGlobalTrigger;
834 }
835
836 //____________________________________________________________________________
837 void AliMUONData::ResetDigits()
838 {
839 /// Reset number of digits and the digits array for this detector
840
841     if (fDigits == 0x0) return;
842     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
843       if ((*fDigits)[i])    ((TClonesArray*)fDigits->At(i))->Clear("C");
844       if (fNdigits)  fNdigits[i]=0;
845     }
846 }
847 //____________________________________________________________________________
848 void AliMUONData::ResetSDigits()
849 {
850 /// Reset number of Sdigits and the Sdigits array for this detector
851
852     if (fSDigits == 0x0) return;
853     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
854       if ((*fSDigits)[i])    ((TClonesArray*)fSDigits->At(i))->Clear();
855       if (fNSdigits)  fNSdigits[i]=0;
856     }
857 }
858 //______________________________________________________________________________
859 void AliMUONData::ResetHits()
860 {
861 /// Reset number of clusters and the cluster array for this detector
862
863   fNhits   = 0;
864   if (fHits) fHits->Clear();
865 }
866 //_______________________________________________________________________________
867 void AliMUONData::ResetRawClusters()
868 {
869 /// Reset number of raw clusters and the raw clust array for this detector
870
871   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
872     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
873     if (fNrawclusters)  fNrawclusters[i]=0;
874   }
875 }
876 //_______________________________________________________________________________
877 void AliMUONData::ResetTrigger()
878 {
879 /// Reset Local and Global Trigger 
880
881   fNglobaltrigger = 0;
882   if (fGlobalTrigger) fGlobalTrigger->Clear();
883   fNregionaltrigger = 0;
884   if (fRegionalTrigger) fRegionalTrigger->Clear();
885   fNlocaltrigger = 0;
886   if (fLocalTrigger) fLocalTrigger->Clear();
887
888 }
889 //____________________________________________________________________________
890 void AliMUONData::ResetRecTracks()
891 {
892 /// Reset tracks information
893
894   fNrectracks = 0;
895   if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
896 }
897 //____________________________________________________________________________
898 void AliMUONData::ResetRecTriggerTracks()
899 {
900 /// Reset tracks information
901
902   fNrectriggertracks = 0;
903   if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
904 }
905 //____________________________________________________________________________
906 void AliMUONData::SetDataContainer(Option_t* option)
907 {
908 /// Setting data containers of muon data
909   const char *cH   = strstr(option,"H");
910   const char *cD   = strstr(option,"D");   // Digits
911   const char *cS   = strstr(option,"S");   // SDigits
912   const char *cRC  = strstr(option,"RC");  // RawCluster
913   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger
914   const char *cTC = strstr(option,"TC");   // global and local Trigger 
915   const char *cRT  = strstr(option,"RT");  // Reconstructed Tracks
916   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Tracks
917                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particles  
918   AliDebug(1,Form("option=%s",option));
919   //
920   // Clones array for hits
921   if ( cH ) {
922     if (fHits == 0x0) {
923       fHits     = new TClonesArray("AliMUONHit",1000);
924     }
925     ResetHits();
926   }
927   
928   //
929   // ObjArray of ClonesArrays for Digits
930   if ( cD ) {      
931     if (fDigits == 0x0 ) {
932       fDigits = new TObjArray(AliMUONConstants::NCh());
933       fNdigits= new Int_t[AliMUONConstants::NCh()];
934       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
935         TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
936         tca->SetOwner();
937         fDigits->AddAt(tca,i); 
938         fNdigits[i]=0;
939       }
940     } 
941     else {
942       AliDebug(1,Form("fDigits already there = %p",fSDigits));
943     }
944     ResetDigits();
945   }
946
947   //
948   // ClonesArrays for Trigger
949   if ( cGLT ) { 
950     if (fLocalTrigger == 0x0) {
951       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
952     }
953     if (fRegionalTrigger == 0x0) {
954       fRegionalTrigger  = new TClonesArray("AliMUONRegionalTrigger",16);
955     }
956     if (fGlobalTrigger== 0x0) {
957       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
958     }
959     ResetTrigger();
960   }
961     
962   //
963   // Container for Sdigits
964   if (cS) {
965     if (fSDigits == 0x0) { 
966       AliDebug(1,"Creating fSDigits TObjArray");
967       fSDigits = new TObjArray(AliMUONConstants::NCh());
968       fNSdigits= new Int_t[AliMUONConstants::NCh()];
969       for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
970         TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
971         a->SetOwner();
972         fSDigits->AddAt(a,i);
973         AliDebug(1,Form("fSDigits[%d]=%p",i,a));
974         fNSdigits[i]=0;
975       }
976     }
977     else {
978       AliDebug(1,Form("fSDigits already there = %p",fSDigits));
979     }
980     ResetSDigits();
981   }
982   
983   //
984   // Containers for rawclusters, globaltrigger and local trigger tree
985   if (cRC ) {
986     if (fRawClusters == 0x0) {
987       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
988       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
989       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
990         TClonesArray* tca = new TClonesArray("AliMUONRawCluster",10000);
991         tca->SetOwner();
992         fRawClusters->AddAt(tca,i); 
993         fNrawclusters[i]=0;
994       }
995     }
996     // ResetRawClusters(); 
997     // It breaks the correct functioning of the combined reconstruction (AZ)
998     
999   }
1000   if (cTC ) {
1001     if (fLocalTrigger == 0x0) {
1002       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
1003     }
1004    if (fRegionalTrigger == 0x0) {
1005       fRegionalTrigger  = new TClonesArray("AliMUONRegionalTrigger",16);
1006     }
1007     if (fGlobalTrigger== 0x0) {
1008       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
1009     }
1010     // ResetTrigger(); 
1011     // This is not necessary here since trigger info ins copied from digits info on flight to RecPoint output
1012   }
1013
1014   //
1015   // Containers for rectracks and rectrigger tracks
1016   if ( cRT ) {
1017     if (fRecTracks == 0x0)  {
1018       fRecTracks  = new TClonesArray("AliMUONTrack",100);
1019     }
1020     ResetRecTracks();
1021   }
1022   if (cRL) {
1023     if (fRecTriggerTracks == 0x0 && cRL)  {
1024       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
1025     }
1026     ResetRecTriggerTracks();
1027   }  
1028 }
1029
1030 //____________________________________________________________________________
1031 void AliMUONData::SetTreeAddress(Option_t* option)
1032 {
1033   // Setting Data containers
1034   SetDataContainer(option);
1035
1036 /// Setting Addresses to the events trees
1037
1038   const char *cH   = strstr(option,"H");
1039   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
1040   const char *cS   = strstr(option,"S");   // SDigits branches in TreeS
1041   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
1042   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
1043   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
1044   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
1045   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
1046                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
1047   
1048   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
1049   char branchname[30];
1050   TBranch * branch = 0x0;
1051   
1052   AliDebug(1,Form("option=%s",option));
1053   //
1054   // Branch address for hit tree
1055   if (TreeH() && fHits && cH) {
1056     sprintf(branchname,"%sHits",GetName());  
1057     branch = TreeH()->GetBranch(branchname);
1058     if (branch) {
1059       //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
1060       branch->SetAddress(&fHits);
1061     }
1062     else { //can be invoked before branch creation
1063       //AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
1064     }
1065   }
1066   
1067   //
1068   // Branch address for digit tree
1069   if (TreeD() && fDigits && cD) {
1070     for (int i=0; i<AliMUONConstants::NCh(); i++) {
1071       sprintf(branchname,"%sDigits%d",GetName(),i+1);
1072       if (fDigits) {
1073         branch = TreeD()->GetBranch(branchname);
1074         TClonesArray * digits = Digits(i);
1075         if (branch) {
1076           branch->SetAddress( &digits );
1077         }
1078         else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
1079       }
1080     }
1081   }
1082   if ( TreeD()  && fLocalTrigger && cGLT) {
1083     sprintf(branchname,"%sLocalTrigger",GetName());
1084     branch = TreeD()->GetBranch(branchname);
1085     if (branch) branch->SetAddress(&fLocalTrigger);
1086     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
1087   }
1088  if ( TreeD()  && fRegionalTrigger && cGLT) {
1089     sprintf(branchname,"%sRegionalTrigger",GetName());
1090     branch = TreeD()->GetBranch(branchname);
1091     if (branch) branch->SetAddress(&fRegionalTrigger);
1092     else AliWarning(Form("(%s) Failed for RegionalTrigger. Can not find branch in treeD.",GetName()));
1093   }
1094   if ( TreeD() && fGlobalTrigger && cGLT) {
1095     sprintf(branchname,"%sGlobalTrigger",GetName());
1096     branch = TreeD()->GetBranch(branchname);
1097     if (branch) branch->SetAddress(&fGlobalTrigger);
1098     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
1099   }
1100   
1101   //
1102   // Branch address for Sdigit tree
1103   if (TreeS() && fSDigits && cS) {
1104     AliDebug(1,"Setting branch addresses");
1105     for (int i=0; i<AliMUONConstants::NCh(); i++) {
1106       sprintf(branchname,"%sSDigits%d",GetName(),i+1);
1107       if (fSDigits) {
1108         AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
1109                         TreeS(),i,branchname));
1110         branch = TreeS()->GetBranch(branchname);
1111         TClonesArray * sdigits = SDigits(i);
1112         if (branch) branch->SetAddress( &sdigits );
1113         else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
1114       }
1115     }
1116   }
1117   
1118   //
1119   // Branch address for rawclusters, globaltrigger and local trigger tree
1120   if ( TreeR()  && fRawClusters && cRC && !strstr(cRC,"RCC")) {
1121     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
1122       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
1123       if (fRawClusters) {
1124         branch = TreeR()->GetBranch(branchname);
1125         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
1126         else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
1127       }
1128     }
1129   }
1130   if ( TreeR()  && fLocalTrigger && cTC) {
1131     sprintf(branchname,"%sLocalTrigger",GetName());
1132     branch = TreeR()->GetBranch(branchname);
1133     if (branch) branch->SetAddress(&fLocalTrigger);
1134     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
1135   }
1136   if ( TreeR()  && fRegionalTrigger && cTC) {
1137     sprintf(branchname,"%sRegionalTrigger",GetName());
1138     branch = TreeR()->GetBranch(branchname);
1139     if (branch) branch->SetAddress(&fRegionalTrigger);
1140     else AliWarning(Form("(%s) Failed for RegionalTrigger. Can not find branch in treeR.",GetName()));
1141   }
1142   if ( TreeR() && fGlobalTrigger && cTC) {
1143     sprintf(branchname,"%sGlobalTrigger",GetName());
1144     branch = TreeR()->GetBranch(branchname);
1145     if (branch) branch->SetAddress(&fGlobalTrigger);
1146     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
1147   }
1148
1149   // Rec Trakcs
1150   if ( TreeT() && fRecTracks && cRT ) {
1151     sprintf(branchname,"%sTrack",GetName());  
1152     branch = TreeT()->GetBranch(branchname);
1153     if (branch) branch->SetAddress(&fRecTracks);
1154     else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
1155   }
1156   // Trigger tracks
1157   if ( TreeT() && fRecTriggerTracks && cRL ) {
1158     sprintf(branchname,"%sTriggerTrack",GetName());  
1159     branch = TreeT()->GetBranch(branchname);
1160     if (branch) branch->SetAddress(&fRecTriggerTracks);
1161     else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
1162   }
1163 }
1164
1165 //_____________________________________________________________________________
1166 void
1167 AliMUONData::Print(Option_t* opt) const
1168 {
1169 /// Dump object on screen
1170
1171   TString options(opt);
1172   options.ToUpper();
1173   
1174   if ( options.Contains("D") )
1175   {
1176     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1177     {
1178       TClonesArray* digits = Digits(ich);
1179       Int_t ndigits = digits->GetEntriesFast();
1180       for ( Int_t id = 0; id < ndigits; ++id )
1181       {
1182         AliMUONDigit* digit = 
1183           static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1184         digit->Print();
1185       }
1186     }
1187   }
1188   
1189   if ( options.Contains("S") )
1190   {
1191     for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
1192     {
1193       TClonesArray* digits = SDigits(ich);
1194       Int_t ndigits = digits->GetEntriesFast();
1195       for ( Int_t id = 0; id < ndigits; ++id )
1196       {
1197         AliMUONDigit* digit = 
1198         static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
1199         digit->Print();
1200       }
1201     }
1202   }
1203   
1204 }
1205
1206 //_____________________________________________________________________________
1207 void 
1208 AliMUONData::DumpKine(Int_t event2Check)
1209 {
1210   // Load kinematics
1211   fRunLoader->LoadKinematics("READ");
1212
1213   Int_t nevents = fRunLoader->GetNumberOfEvents();
1214   for (Int_t ievent=0; ievent<nevents; ievent++) {  // Event loop
1215     if ( event2Check != 0 ) ievent=event2Check;
1216
1217     // Getting event ievent
1218     fRunLoader->GetEvent(ievent); 
1219
1220     // Stack of particle for this event
1221     AliStack* stack = fRunLoader->Stack();
1222
1223     Int_t nparticles = (Int_t) fRunLoader->Stack()->GetNtrack();
1224     printf(">>> Event %d, Number of particles is %d \n", ievent, nparticles);
1225
1226     for (Int_t iparticle=0; iparticle<nparticles; iparticle++) {
1227       stack->Particle(iparticle)->Print("");  
1228     }
1229     if (event2Check!=0) ievent=nevents;
1230   }
1231   fRunLoader->UnloadKinematics();
1232 }
1233
1234
1235 //_____________________________________________________________________________
1236 void 
1237 AliMUONData::DumpHits(Int_t event2Check, Option_t* opt)
1238 {
1239   // Loading data
1240   fLoader->LoadHits("READ");
1241
1242   // Event loop
1243   Int_t nevents = fRunLoader->GetNumberOfEvents();
1244   for (Int_t ievent=0; ievent<nevents; ievent++) {
1245     if (event2Check!=0) ievent=event2Check;
1246     printf(">>> Event %d \n",ievent);
1247
1248     // Getting event ievent
1249     fRunLoader->GetEvent(ievent); 
1250     SetTreeAddress("H");
1251
1252     // Track loop
1253     Int_t ntracks = (Int_t) GetNtracks();
1254     for (Int_t itrack=0; itrack<ntracks; itrack++) {
1255       //Getting List of Hits of Track itrack
1256       GetTrack(itrack);
1257
1258       Int_t nhits = (Int_t) Hits()->GetEntriesFast();
1259       printf(">>> Track %d, Number of hits %d \n",itrack,nhits);
1260       for (Int_t ihit=0; ihit<nhits; ihit++) {
1261         AliMUONHit* mHit = static_cast<AliMUONHit*>(Hits()->At(ihit));
1262         mHit->Print(opt);
1263       }
1264       ResetHits();
1265     }
1266     if (event2Check!=0) ievent=nevents;
1267   }
1268   fLoader->UnloadHits();
1269 }
1270
1271 //_____________________________________________________________________________
1272 void 
1273 AliMUONData::DumpDigits(Int_t event2Check, Option_t* opt)
1274 {
1275   // Loading data
1276   fLoader->LoadDigits("READ");
1277   
1278   // Event loop
1279   Int_t firstEvent = 0;
1280   Int_t lastEvent = fRunLoader->GetNumberOfEvents()-1;
1281   if ( event2Check != 0 ) {
1282     firstEvent = event2Check;
1283     lastEvent = event2Check;
1284   }  
1285   
1286   for ( Int_t ievent = firstEvent; ievent <= lastEvent; ++ievent ) {
1287     printf(">>> Event %d \n",ievent);
1288     fRunLoader->GetEvent(ievent);
1289
1290     AliMUONDataIterator it(this, "digit", AliMUONDataIterator::kTrackingChambers);
1291     AliMUONDigit* digit;
1292  
1293      while ( ( digit = (AliMUONDigit*)it.Next() ) )
1294      {
1295        digit->Print(opt);
1296      }
1297   } 
1298   fLoader->UnloadDigits();
1299 }
1300
1301 //_____________________________________________________________________________
1302 void 
1303 AliMUONData::DumpSDigits(Int_t event2Check, Option_t* opt)
1304 {
1305   // Loading data
1306   fLoader->LoadSDigits("READ");
1307   
1308   // Event loop
1309   Int_t nevents = fRunLoader->GetNumberOfEvents();
1310   for (Int_t ievent=0; ievent<nevents; ievent++) {
1311     if (event2Check!=0) ievent=event2Check;
1312     printf(">>> Event %d \n",ievent);
1313
1314     // Getting event ievent
1315     fRunLoader->GetEvent(ievent);
1316     SetTreeAddress("S");
1317     GetSDigits();
1318
1319     // Loop on chambers
1320     Int_t nchambers = AliMUONConstants::NCh(); ;
1321     for (Int_t ichamber=0; ichamber<nchambers; ichamber++) {
1322       TClonesArray* digits = SDigits(ichamber);
1323
1324       // Loop on Sdigits
1325       Int_t ndigits = (Int_t)digits->GetEntriesFast();
1326       for (Int_t idigit=0; idigit<ndigits; idigit++) {
1327         AliMUONDigit* mDigit = static_cast<AliMUONDigit*>(digits->At(idigit));
1328         mDigit->Print(opt);
1329       }
1330     }
1331     ResetSDigits();
1332     if (event2Check!=0) ievent=nevents;
1333   }
1334   fLoader->UnloadSDigits();
1335 }
1336
1337 //_____________________________________________________________________________
1338 void 
1339 AliMUONData::DumpRecPoints(Int_t event2Check, Option_t* opt) 
1340 {
1341   // Loading data
1342   fLoader->LoadRecPoints("READ");
1343
1344   // Event loop
1345   Int_t nevents = fRunLoader->GetNumberOfEvents();
1346   for (Int_t ievent=0; ievent<nevents; ievent++) {
1347     if (event2Check!=0) ievent=event2Check;
1348     printf(">>> Event %d \n",ievent);
1349
1350     // Getting event ievent
1351     fRunLoader->GetEvent(ievent);
1352     Int_t nchambers = AliMUONConstants::NTrackingCh();
1353     SetTreeAddress("RC,TC"); 
1354     GetRawClusters();
1355
1356     // Loop on chambers
1357     for (Int_t ichamber=0; ichamber<nchambers; ichamber++) {
1358       char branchname[30];    
1359       sprintf(branchname,"MUONRawClusters%d",ichamber+1);
1360       //printf(">>>  branchname %s\n",branchname);
1361
1362       // Loop on rec points
1363       Int_t nrecpoints = (Int_t) RawClusters(ichamber)->GetEntriesFast();
1364       // printf(">>> Chamber %2d, Number of recpoints = %6d \n",ichamber+1, nrecpoints);
1365       for (Int_t irecpoint=0; irecpoint<nrecpoints; irecpoint++) {
1366         AliMUONRawCluster* mRecPoint = static_cast<AliMUONRawCluster*>(RawClusters(ichamber)->At(irecpoint));
1367         mRecPoint->Print(opt);
1368       }
1369     }
1370     ResetRawClusters();
1371     if (event2Check!=0) ievent=nevents;
1372   }
1373   fLoader->UnloadRecPoints();
1374 }
1375
1376
1377 //_____________________________________________________________________________
1378 void 
1379 AliMUONData::DumpRecTrigger(Int_t event2Check, 
1380                             Int_t write, Bool_t readFromRP)
1381 {
1382 /// Reads and dumps trigger objects from MUON.RecPoints.root
1383
1384   TClonesArray * globalTrigger;
1385   TClonesArray * localTrigger;
1386   
1387   // Do NOT print out all the info if the loop runs over all events 
1388   Int_t printout = (event2Check == 0 ) ? 0 : 1 ;  
1389
1390   // Book a ntuple for more detailled studies
1391   TNtuple *tupleGlo = new TNtuple("TgtupleGlo","Global Trigger Ntuple","ev:global:slpt:shpt:uplpt:uphpt:lplpt:lplpt");
1392   TNtuple *tupleLoc = new TNtuple("TgtupleLoc","Local Trigger Ntuple","ev:LoCircuit:LoStripX:LoDev:StripY:LoLpt:LoHpt:y11:y21:x11");
1393
1394   // counters
1395   Int_t sLowpt=0,sHighpt=0;
1396   Int_t uSLowpt=0,uSHighpt=0;
1397   Int_t lSLowpt=0,lSHighpt=0;
1398
1399   AliMUONTriggerCrateStore* crateManager = new AliMUONTriggerCrateStore();   
1400   crateManager->ReadFromFile();
1401
1402   AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(kFALSE);
1403   transformer->ReadGeometryData("volpath.dat", "geometry.root");
1404
1405   TClonesArray*  triggerCircuit = new TClonesArray("AliMUONTriggerCircuit", 234);
1406
1407   for (Int_t i = 0; i < AliMUONConstants::NTriggerCircuit(); i++)  {
1408       AliMUONTriggerCircuit* c = new AliMUONTriggerCircuit();
1409       c->SetTransformer(transformer);
1410       c->Init(i,*crateManager);
1411       TClonesArray& circuit = *triggerCircuit;
1412       new(circuit[circuit.GetEntriesFast()])AliMUONTriggerCircuit(*c);
1413       delete c;
1414   }
1415   
1416   Char_t fileName[30];
1417   if (!readFromRP) {
1418       AliInfoStream() << " reading from digits \n";
1419       fLoader->LoadDigits("READ");
1420       sprintf(fileName,"TriggerCheckFromDigits.root");
1421   } else {
1422       AliInfoStream() << " reading from RecPoints \n";
1423       fLoader->LoadRecPoints("READ");
1424       sprintf(fileName,"TriggerCheckFromRP.root");
1425   }
1426
1427   
1428   AliMUONGlobalTrigger *gloTrg(0x0);
1429   AliMUONLocalTrigger *locTrg(0x0);
1430
1431   Int_t nevents = fRunLoader->GetNumberOfEvents();
1432   for (Int_t ievent=0; ievent<nevents; ievent++) {
1433     if (event2Check!=0) ievent=event2Check;
1434     if (ievent%100==0 || event2Check) 
1435       AliInfoStream() << "Processing event " << ievent << endl;
1436     fRunLoader->GetEvent(ievent);
1437     
1438     if (!readFromRP) {
1439         SetTreeAddress("D,GLT"); 
1440         GetTriggerD();
1441     } else {    
1442         SetTreeAddress("RC,TC"); 
1443         GetTrigger();
1444     }
1445
1446     globalTrigger = GlobalTrigger();
1447     localTrigger = LocalTrigger();
1448     
1449     Int_t nglobals = (Int_t) globalTrigger->GetEntriesFast(); // should be 1
1450     Int_t nlocals  = (Int_t) localTrigger->GetEntriesFast(); // up to 234
1451     if (printout) printf("###################################################\n");
1452     if (printout) printf("event %d nglobal %d nlocal %d \n",ievent,nglobals,nlocals);
1453
1454     for (Int_t iglobal=0; iglobal<nglobals; iglobal++) { // Global Trigger
1455       gloTrg = static_cast<AliMUONGlobalTrigger*>(globalTrigger->At(iglobal));
1456       
1457       sLowpt+=gloTrg->SingleLpt() ;
1458       sHighpt+=gloTrg->SingleHpt() ;
1459       uSLowpt+=gloTrg->PairUnlikeLpt(); 
1460       uSHighpt+=gloTrg->PairUnlikeHpt();
1461       lSLowpt+=gloTrg->PairLikeLpt(); 
1462       lSHighpt+=gloTrg->PairLikeHpt();
1463       
1464       if (printout) gloTrg->Print("full");
1465
1466     } // end of loop on Global Trigger
1467
1468     for (Int_t ilocal=0; ilocal<nlocals; ilocal++) { // Local Trigger
1469       locTrg = static_cast<AliMUONLocalTrigger*>(localTrigger->At(ilocal));
1470
1471       if (locTrg->LoLpt()!=0) { // board is fired
1472
1473       if (printout) locTrg->Print("full");
1474       
1475       AliMUONTriggerCircuit* circuit = (AliMUONTriggerCircuit*)triggerCircuit->At(locTrg->LoCircuit()-1); 
1476       
1477       tupleLoc->Fill(ievent,locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoDev(),locTrg->LoStripY(),locTrg->LoLpt(),locTrg->LoHpt(),circuit->GetY11Pos(locTrg->LoStripX()),circuit->GetY21Pos(locTrg->LoStripX()+locTrg->LoDev()+1),circuit->GetX11Pos(locTrg->LoStripY()));
1478       }
1479       
1480     } // end of loop on Local Trigger
1481
1482     // fill ntuple
1483     tupleGlo->Fill(ievent,nglobals,gloTrg->SingleLpt(),gloTrg->SingleHpt(),gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
1484
1485     ResetTrigger();
1486     if (event2Check!=0) ievent=nevents;
1487   } // end loop on event  
1488   
1489   // Print out summary if loop ran over all event
1490   if (!event2Check){
1491
1492     printf("\n");
1493     printf("=============================================\n");
1494     printf("================  SUMMARY  ==================\n");
1495     printf("\n");
1496     printf("Total number of events processed %d \n", (event2Check==0) ? nevents : 1);
1497     printf("\n");
1498     printf(" Global Trigger output       Low pt  High pt\n");
1499     printf(" number of Single           :\t");
1500     printf("%i\t%i\t",sLowpt,sHighpt);
1501     printf("\n");
1502     printf(" number of UnlikeSign pair  :\t"); 
1503     printf("%i\t%i\t",uSLowpt,uSHighpt);
1504     printf("\n");
1505     printf(" number of LikeSign pair    :\t");  
1506     printf("%i\t%i\t",lSLowpt,lSHighpt);
1507     printf("\n");
1508     printf("=============================================\n");
1509     fflush(stdout);
1510   }
1511   
1512   if (write){
1513       TFile *myFile = new TFile(fileName, "RECREATE");
1514       tupleGlo->Write();
1515       tupleLoc->Write();
1516       myFile->Close();
1517   }
1518
1519   fLoader->UnloadRecPoints();
1520
1521   delete crateManager;
1522   delete transformer;
1523   delete triggerCircuit;
1524   
1525 }