]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRecData.cxx
Updated list of MUON libraries
[u/mrichter/AliRoot.git] / MUON / AliMUONRecData.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 AliMUONRecData
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 "AliMUONRecData.h"
27 #include "AliMUONDataIterator.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONDigit.h"
30 #include "AliMUONGlobalTrigger.h"
31 #include "AliMUONLocalTrigger.h"
32 #include "AliMUONRegionalTrigger.h"
33 #include "AliMUONTriggerCrateStore.h"
34 #include "AliMUONTriggerCircuit.h"
35 #include "AliMUONGeometryTransformer.h"
36 #include "AliMUONRawCluster.h"
37 #include "AliMUONTrack.h"
38 #include "AliMUONTriggerTrack.h"
39
40 #include "AliRunLoader.h"
41 #include "AliStack.h"
42 #include "AliLog.h"
43
44 #include <TString.h>
45 #include <TParticle.h>
46 #include <TNtuple.h>
47 #include <Riostream.h>
48 #include <TFile.h>
49
50 /// \cond CLASSIMP
51 ClassImp(AliMUONRecData)
52 /// \endcond
53  
54 //_____________________________________________________________________________
55 AliMUONRecData::AliMUONRecData()
56   : AliMUONData(),
57     fRawClusters(0x0),
58     fRecTracks(0x0),
59     fRecTriggerTracks(0x0),
60     fNrawclusters(0x0),
61     fNrectracks(0),
62     fNrectriggertracks(0)
63 {
64 /// Default constructor
65 }
66 //_____________________________________________________________________________
67 AliMUONRecData::AliMUONRecData(AliLoader * loader, const char* name, const char* title)
68   : AliMUONData(loader, name, title),
69     fRawClusters(0x0),
70     fRecTracks(0x0),
71     fRecTriggerTracks(0x0),
72     fNrawclusters(0x0),
73     fNrectracks(0),
74     fNrectriggertracks(0)
75 {
76 /// Standard constructor
77 }
78
79 //_____________________________________________________________________________
80 AliMUONRecData::AliMUONRecData(const char* galiceFile)
81   : AliMUONData(galiceFile, "MUONFolder"),
82     fRawClusters(0x0),
83     fRecTracks(0x0),
84     fRecTriggerTracks(0x0),
85     fNrawclusters(0x0),
86     fNrectracks(0),
87     fNrectriggertracks(0)
88 {
89 /// Constructor for loading data from gAlice file
90 }
91
92 //_____________________________________________________________________________
93 AliMUONRecData::~AliMUONRecData()
94 {
95 /// Destructor for AliMUONRecData
96
97   if (fRawClusters) {
98     fRawClusters->Delete();
99     delete fRawClusters;
100   }
101   if (fRecTracks){
102     fRecTracks->Delete();
103     delete fRecTracks;
104   }
105   if (fRecTriggerTracks){
106     fRecTriggerTracks->Delete();
107     delete fRecTriggerTracks;
108   }
109 }
110 //_____________________________________________________________________________
111 void AliMUONRecData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
112 {
113 /// Add a MUON rawcluster to the list in the detection plane id
114
115   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
116   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
117 }
118 //_____________________________________________________________________________
119 void AliMUONRecData::AddRecTrack(const AliMUONTrack& track)
120 {
121 /// Add a MUON rectrack
122
123   TClonesArray &lrectracks = *fRecTracks;
124   new(lrectracks[fNrectracks++]) AliMUONTrack(track);
125 }
126 //_____________________________________________________________________________
127 void AliMUONRecData::AddRecTriggerTrack(const AliMUONTriggerTrack& triggertrack)
128 {
129 /// Add a MUON triggerrectrack
130
131   TClonesArray &lrectriggertracks = *fRecTriggerTracks;  
132   new(lrectriggertracks[fNrectriggertracks++]) AliMUONTriggerTrack(triggertrack);
133 }
134 //____________________________________________________________________________
135 Bool_t   AliMUONRecData::IsRawClusterBranchesInTree()
136 {
137 /// Checking if there are RawCluster Branches In TreeR
138
139   if (TreeR()==0x0) {
140     AliError("No treeR in memory");
141     return kFALSE;
142   }
143   else {
144      char branchname[30];
145      sprintf(branchname,"%sRawClusters1",GetName());
146      TBranch * branch = 0x0;
147      branch = TreeR()->GetBranch(branchname);
148      if (branch)  return kTRUE;
149      else return kFALSE;    
150   }
151 }
152 //____________________________________________________________________________
153 Bool_t   AliMUONRecData::IsTrackBranchesInTree()
154 {
155 /// Checking if there are Track Branches In TreeT
156   if (TreeT()==0x0) {
157     AliError("No treeT in memory");
158     return kFALSE;
159   }
160   else {
161      char branchname[30];
162      sprintf(branchname,"%sTrack",GetName());
163      TBranch * branch = 0x0;
164      branch = TreeT()->GetBranch(branchname);
165      if (branch)  return kTRUE;
166      else return kFALSE;    
167   }
168 }
169 //____________________________________________________________________________
170 Bool_t   AliMUONRecData::IsTriggerBranchesInTree()
171 {
172 /// Checking if there are Trigger Branches In TreeR
173  if (TreeR()==0x0) {
174     AliError("No treeR in memory");
175     return kFALSE;
176   }
177   else {
178      char branchname[30];
179      sprintf(branchname,"%sLocalTrigger",GetName());
180      TBranch * branch = 0x0;
181      branch = TreeR()->GetBranch(branchname);
182      if (branch)  return kTRUE;
183      else return kFALSE;    
184   }
185 }
186 //____________________________________________________________________________
187 Bool_t   AliMUONRecData::IsTriggerTrackBranchesInTree()
188 {
189 /// Checking if there are TriggerTrack Branches In TreeT
190   if (TreeT()==0x0) {
191     AliError("No treeT in memory");
192     return kFALSE;
193   }
194   else {
195      char branchname[30];
196      sprintf(branchname,"%sTriggerTrack",GetName());
197      TBranch * branch = 0x0;
198      branch = TreeT()->GetBranch(branchname);
199      if (branch)  return kTRUE;
200      else return kFALSE;    
201   }
202 }
203 //____________________________________________________________________________
204 void AliMUONRecData::FillOwn(Option_t* option)
205 {
206 /// Method to fill the trees
207
208   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
209   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
210   const char *cRL = strstr(option,"RL");   // Reconstructed Trigger Track in TreeT
211   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
212   
213   char branchname[30];
214   TBranch * branch = 0x0;
215
216   // Filling TreeR
217   
218   if ( TreeR() && cRC && cTC )
219   {
220     TreeR()->Fill();
221   }
222   else
223   {  
224     if ( TreeR()  && cRC ) 
225     {
226       if ( IsTriggerBranchesInTree() ) 
227       {
228       // Branch per branch filling
229         for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) 
230         {
231           sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
232           branch = TreeR()->GetBranch(branchname);
233           branch->Fill();
234         }
235       }
236       else  
237       {
238         TreeR()->Fill();
239       }
240     }
241     
242     if ( TreeR()  && cTC) 
243     {
244       if (IsRawClusterBranchesInTree()) 
245       {
246         // Branch per branch filling
247         sprintf(branchname,"%sLocalTrigger",GetName());
248         branch = TreeR()->GetBranch(branchname); 
249         branch->Fill();
250         sprintf(branchname,"%sRegionalTrigger",GetName());
251         branch = TreeR()->GetBranch(branchname); 
252         branch->Fill();
253         sprintf(branchname,"%sGlobalTrigger",GetName());
254         branch = TreeR()->GetBranch(branchname);
255         branch->Fill();
256       }
257       else
258       {
259         TreeR()->Fill();
260       }
261     }
262   }
263
264   // Filling TreeT
265   
266   if ( TreeT() && cRT && cRL )
267   {
268     TreeT()->Fill();
269   }
270   else
271   {
272     if ( TreeT() && cRT ) 
273     {
274       if (IsTriggerTrackBranchesInTree()) 
275       {
276         sprintf(branchname,"%sTrack",GetName());  
277         branch = TreeT()->GetBranch(branchname);
278         branch->Fill();
279       }
280       else 
281       {
282         TreeT()->Fill();
283       }
284     }
285
286     if ( TreeT() && cRL ) 
287     {
288       if (IsTrackBranchesInTree()) 
289       {
290         sprintf(branchname,"%sTriggerTrack",GetName());  
291         branch = TreeT()->GetBranch(branchname);
292         branch->Fill();
293       }    
294       else 
295       {
296         TreeT()->Fill();
297       }
298     }
299   }
300 }
301
302 //_____________________________________________________________________________
303 void AliMUONRecData::MakeOwnBranch(Option_t* option)
304 {
305 /// Create Tree branches for the MUON.
306
307   const Int_t kBufferSize = 4000;
308   char branchname[30];
309   
310   //Setting Data Container
311   SetDataContainer(option);  
312
313   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
314   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
315   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
316                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
317   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
318   
319   TBranch * branch = 0x0;
320   
321   if (TreeR() && cRC ) {
322     //  one branch for raw clusters per tracking detection plane
323     //        
324     Int_t i; 
325     for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
326       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
327       branch = 0x0;
328       branch = TreeR()->GetBranch(branchname);
329       if (branch) {  
330         AliInfo(Form("Branch %s is already in tree.",branchname));
331         return;
332       }
333       branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
334       //Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
335     }
336   }
337   
338   if (TreeR() && cTC ) {
339     //
340     // one branch for global trigger
341     //
342     sprintf(branchname,"%sGlobalTrigger",GetName());
343     branch = 0x0;
344     branch = TreeR()->GetBranch(branchname);
345     if (branch) {  
346       AliInfo(Form("Branch GlobalTrigger is already in treeR."));
347       return ;
348     }
349     branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
350     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
351
352   //
353     // one branch for regional trigger
354     //  
355     sprintf(branchname,"%sRegionalTrigger",GetName());
356     branch = 0x0;
357     branch = TreeR()->GetBranch(branchname);
358     if (branch) {  
359       AliInfo(Form("Branch RegionalTrigger is already in treeR."));
360       return;
361     }
362     branch = TreeR()->Branch(branchname, &fRegionalTrigger, kBufferSize);
363      
364     //
365     // one branch for local trigger
366     //  
367     sprintf(branchname,"%sLocalTrigger",GetName());
368     branch = 0x0;
369     branch = TreeR()->GetBranch(branchname);
370     if (branch) {  
371       AliInfo(Form("Branch LocalTrigger is already in treeR."));
372       return;
373     }
374     branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
375     //Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
376   }
377   
378   if (TreeT() && cRT ) {
379     sprintf(branchname,"%sTrack",GetName());  
380     branch = TreeT()->GetBranch(branchname);
381     if (branch) {  
382       AliInfo(Form("Branch %s is already in tree.",GetName()));
383       return ;
384     }
385     branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
386     //Info("MakeBranch","Making Branch %s for tracks \n",branchname);
387   }  
388   // trigger tracks
389   if (TreeT() && cRL ) {
390     sprintf(branchname,"%sTriggerTrack",GetName());  
391     branch = TreeT()->GetBranch(branchname);
392     if (branch) {  
393       AliInfo(Form("Branch %s is already in tree.",GetName()));
394       return ;
395     }
396     branch = TreeT()->Branch(branchname,&fRecTriggerTracks,kBufferSize);
397     //Info("MakeBranch","Making Branch %s for trigger tracks \n",branchname);
398   }  
399 }
400 //____________________________________________________________________________
401 void AliMUONRecData::SetOwnDataContainer(Option_t* option)
402 {
403 /// Setting data containers of muon data
404
405   const char *cRC  = strstr(option,"RC");  // RawCluster
406   const char *cRT  = strstr(option,"RT");  // Reconstructed Tracks
407   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Tracks
408                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particles  
409   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
410
411   AliDebug(1,Form("option=%s",option));
412
413   //
414   // Containers for rawclusters, globaltrigger and local trigger tree
415   if (cRC ) {
416     if (fRawClusters == 0x0) {
417       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
418       fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
419       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
420         TClonesArray* tca = new TClonesArray("AliMUONRawCluster",10000);
421         tca->SetOwner();
422         fRawClusters->AddAt(tca,i); 
423         fNrawclusters[i]=0;
424       }
425     }
426     // ResetRawClusters(); 
427     // It breaks the correct functioning of the combined reconstruction (AZ)
428     
429   }
430   if (cTC ) {
431     if (fLocalTrigger == 0x0) {
432       fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);
433     }
434    if (fRegionalTrigger == 0x0) {
435       fRegionalTrigger  = new TClonesArray("AliMUONRegionalTrigger",16);
436     }
437     if (fGlobalTrigger== 0x0) {
438       fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
439     }
440     // ResetTrigger(); 
441     // This is not necessary here since trigger info ins copied from digits info on flight to RecPoint output
442   }
443
444   //
445   // Containers for rectracks and rectrigger tracks
446   if ( cRT ) {
447     if (fRecTracks == 0x0)  {
448       fRecTracks  = new TClonesArray("AliMUONTrack",100);
449     }
450     ResetRecTracks();
451   }
452   if (cRL) {
453     if (fRecTriggerTracks == 0x0 && cRL)  {
454       fRecTriggerTracks  = new TClonesArray("AliMUONTriggerTrack",100);
455     }
456     ResetRecTriggerTracks();
457   }  
458 }
459
460 //____________________________________________________________________________
461 void AliMUONRecData::SetOwnTreeAddress(Option_t* option)
462 {
463   // Setting Data containers
464   SetOwnDataContainer(option);
465
466 /// Setting Addresses to the events trees
467
468   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
469   const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
470   const char *cRL  = strstr(option,"RL");  // Reconstructed Trigger Track in TreeT
471                                            //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
472   const char *cTC = strstr(option,"TC");   // global and local Trigger branches Copy in TreeR
473   
474   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
475   char branchname[30];
476   TBranch * branch = 0x0;
477   
478   AliDebug(1,Form("option=%s",option));
479
480   //
481   // Branch address for rawclusters, globaltrigger and local trigger tree
482   if ( TreeR()  && fRawClusters && cRC && !strstr(cRC,"RCC")) {
483     for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
484       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
485       if (fRawClusters) {
486         branch = TreeR()->GetBranch(branchname);
487         if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
488         else AliWarning(Form("(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i));
489       }
490     }
491   }
492   if ( TreeR()  && fLocalTrigger && cTC) {
493     sprintf(branchname,"%sLocalTrigger",GetName());
494     branch = TreeR()->GetBranch(branchname);
495     if (branch) branch->SetAddress(&fLocalTrigger);
496     else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeR.",GetName()));
497   }
498   if ( TreeR()  && fRegionalTrigger && cTC) {
499     sprintf(branchname,"%sRegionalTrigger",GetName());
500     branch = TreeR()->GetBranch(branchname);
501     if (branch) branch->SetAddress(&fRegionalTrigger);
502     else AliWarning(Form("(%s) Failed for RegionalTrigger. Can not find branch in treeR.",GetName()));
503   }
504   if ( TreeR() && fGlobalTrigger && cTC) {
505     sprintf(branchname,"%sGlobalTrigger",GetName());
506     branch = TreeR()->GetBranch(branchname);
507     if (branch) branch->SetAddress(&fGlobalTrigger);
508     else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeR.",GetName()));
509   }
510
511   // Rec Trakcs
512   if ( TreeT() && fRecTracks && cRT ) {
513     sprintf(branchname,"%sTrack",GetName());  
514     branch = TreeT()->GetBranch(branchname);
515     if (branch) branch->SetAddress(&fRecTracks);
516     else AliWarning(Form("(%s) Failed for Tracks. Can not find branch in tree.",GetName()));
517   }
518   // Trigger tracks
519   if ( TreeT() && fRecTriggerTracks && cRL ) {
520     sprintf(branchname,"%sTriggerTrack",GetName());  
521     branch = TreeT()->GetBranch(branchname);
522     if (branch) branch->SetAddress(&fRecTriggerTracks);
523     else AliWarning(Form("(%s) Failed for Trigger Tracks. Can not find branch in tree.",GetName()));
524   }
525 }
526
527 //____________________________________________________________________________
528 void AliMUONRecData::Fill(Option_t* option)
529 {
530 /// Method to fill the trees
531
532   AliMUONData::Fill(option);
533   FillOwn(option);
534 }  
535
536 //_____________________________________________________________________________
537 void AliMUONRecData::MakeBranch(Option_t* option)
538 {
539 /// Create Tree branches for the MUON.
540
541   AliMUONData::MakeBranch(option);
542   MakeOwnBranch(option);
543 }  
544
545 //____________________________________________________________________________
546 void AliMUONRecData::SetDataContainer(Option_t* option)
547 {
548 /// Setting data containers of muon data
549   AliMUONData::SetDataContainer(option);
550   SetOwnDataContainer(option);
551 }
552
553 //____________________________________________________________________________
554 void AliMUONRecData::SetTreeAddress(Option_t* option)
555 {
556   AliMUONData::SetTreeAddress(option);
557   SetOwnTreeAddress(option);
558 }  
559
560 //____________________________________________________________________________
561 TClonesArray*  AliMUONRecData::RawClusters(Int_t DetectionPlane)
562 {
563 /// Getting Raw Clusters
564
565   if (fRawClusters) 
566     return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
567   else
568     return NULL;
569 }
570
571 //_______________________________________________________________________________
572 void AliMUONRecData::ResetRawClusters()
573 {
574 /// Reset number of raw clusters and the raw clust array for this detector
575
576   for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
577     if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
578     if (fNrawclusters)  fNrawclusters[i]=0;
579   }
580 }
581
582 //____________________________________________________________________________
583 void AliMUONRecData::ResetRecTracks()
584 {
585 /// Reset tracks information
586
587   fNrectracks = 0;
588   if (fRecTracks) fRecTracks->Delete(); // necessary to delete in case of memory allocation
589 }
590
591 //____________________________________________________________________________
592 void AliMUONRecData::ResetRecTriggerTracks()
593 {
594 /// Reset tracks information
595
596   fNrectriggertracks = 0;
597   if (fRecTriggerTracks) fRecTriggerTracks->Delete(); // necessary to delete in case of memory allocation
598 }
599
600 //_____________________________________________________________________________
601 void 
602 AliMUONRecData::DumpRecPoints(Int_t event2Check, Option_t* opt) 
603 {
604 /// Dump rec points
605
606   fLoader->LoadRecPoints("READ");
607
608   // Event loop
609   Int_t nevents = fRunLoader->GetNumberOfEvents();
610   for (Int_t ievent=0; ievent<nevents; ievent++) {
611     if (event2Check!=0) ievent=event2Check;
612     printf(">>> Event %d \n",ievent);
613
614     // Getting event ievent
615     fRunLoader->GetEvent(ievent);
616     Int_t nchambers = AliMUONConstants::NTrackingCh();
617     SetTreeAddress("RC,TC"); 
618     GetRawClusters();
619
620     // Loop on chambers
621     for (Int_t ichamber=0; ichamber<nchambers; ichamber++) {
622       char branchname[30];    
623       sprintf(branchname,"MUONRawClusters%d",ichamber+1);
624       //printf(">>>  branchname %s\n",branchname);
625
626       // Loop on rec points
627       Int_t nrecpoints = (Int_t) RawClusters(ichamber)->GetEntriesFast();
628       // printf(">>> Chamber %2d, Number of recpoints = %6d \n",ichamber+1, nrecpoints);
629       for (Int_t irecpoint=0; irecpoint<nrecpoints; irecpoint++) {
630         AliMUONRawCluster* mRecPoint = static_cast<AliMUONRawCluster*>(RawClusters(ichamber)->At(irecpoint));
631         mRecPoint->Print(opt);
632       }
633     }
634     ResetRawClusters();
635     if (event2Check!=0) ievent=nevents;
636   }
637   fLoader->UnloadRecPoints();
638 }
639
640 //_____________________________________________________________________________
641 void 
642 AliMUONRecData::DumpTracks(Int_t event2Check, Option_t* opt) 
643 {
644   /// Dump tracks
645   
646   fLoader->LoadTracks("READ");
647   
648   // Event loop
649   Int_t nevents = fRunLoader->GetNumberOfEvents();
650   
651   for (Int_t ievent=0; ievent<nevents; ievent++) 
652   {
653     if (event2Check!=0) ievent=event2Check;
654   
655     printf(">>> Event %d \n",ievent);
656     
657     // Getting event ievent
658     fRunLoader->GetEvent(ievent);
659     
660     Int_t nchambers = AliMUONConstants::NTrackingCh();
661     SetTreeAddress("RT"); 
662     GetRecTracks();
663     
664     // Loop on chambers
665     for (Int_t ichamber=0; ichamber<nchambers; ++ichamber) 
666     {
667       // Loop on tracks
668       TClonesArray* tracks = RecTracks();
669       Int_t ntracks = (Int_t) tracks->GetEntriesFast();
670
671       for (Int_t i=0; i<ntracks; ++i) 
672       {
673         AliMUONTrack* mTrack = static_cast<AliMUONTrack*>(tracks->At(i));
674         mTrack->Print(opt);
675       }
676     }
677     ResetRecTracks();
678     if (event2Check!=0) ievent=nevents;
679   }
680   fLoader->UnloadTracks();
681 }
682
683 //_____________________________________________________________________________
684 void 
685 AliMUONRecData::DumpRecTrigger(Int_t event2Check, 
686                             Int_t write, Bool_t readFromRP)
687 {
688 /// Reads and dumps trigger objects from MUON.RecPoints.root
689
690   TClonesArray * globalTrigger;
691   TClonesArray * localTrigger;
692   
693   // Do NOT print out all the info if the loop runs over all events 
694   Int_t printout = (event2Check == 0 ) ? 0 : 1 ;  
695
696   // Book a ntuple for more detailled studies
697   TNtuple *tupleGlo = new TNtuple("TgtupleGlo","Global Trigger Ntuple","ev:global:slpt:shpt:uplpt:uphpt:lplpt:lplpt");
698   TNtuple *tupleLoc = new TNtuple("TgtupleLoc","Local Trigger Ntuple","ev:LoCircuit:LoStripX:LoDev:StripY:LoLpt:LoHpt:y11:y21:x11");
699
700   // counters
701   Int_t sLowpt=0,sHighpt=0;
702   Int_t uSLowpt=0,uSHighpt=0;
703   Int_t lSLowpt=0,lSHighpt=0;
704
705   AliMUONTriggerCrateStore* crateManager = new AliMUONTriggerCrateStore();   
706   crateManager->ReadFromFile();
707
708   AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(kFALSE);
709   transformer->ReadGeometryData("volpath.dat", "geometry.root");
710
711   TClonesArray*  triggerCircuit = new TClonesArray("AliMUONTriggerCircuit", 234);
712
713   for (Int_t i = 0; i < AliMUONConstants::NTriggerCircuit(); i++)  {
714       AliMUONTriggerCircuit* c = new AliMUONTriggerCircuit();
715       c->SetTransformer(transformer);
716       c->Init(i,*crateManager);
717       TClonesArray& circuit = *triggerCircuit;
718       new(circuit[circuit.GetEntriesFast()])AliMUONTriggerCircuit(*c);
719       delete c;
720   }
721   
722   Char_t fileName[30];
723   if (!readFromRP) {
724       AliInfoStream() << " reading from digits \n";
725       fLoader->LoadDigits("READ");
726       sprintf(fileName,"TriggerCheckFromDigits.root");
727   } else {
728       AliInfoStream() << " reading from RecPoints \n";
729       fLoader->LoadRecPoints("READ");
730       sprintf(fileName,"TriggerCheckFromRP.root");
731   }
732
733   
734   AliMUONGlobalTrigger *gloTrg(0x0);
735   AliMUONLocalTrigger *locTrg(0x0);
736
737   Int_t nevents = fRunLoader->GetNumberOfEvents();
738   for (Int_t ievent=0; ievent<nevents; ievent++) {
739     if (event2Check!=0) ievent=event2Check;
740     if (ievent%100==0 || event2Check) 
741       AliInfoStream() << "Processing event " << ievent << endl;
742     fRunLoader->GetEvent(ievent);
743     
744     if (!readFromRP) {
745         SetTreeAddress("D,GLT"); 
746         GetTriggerD();
747     } else {    
748         SetTreeAddress("RC,TC"); 
749         GetTrigger();
750     }
751
752     globalTrigger = GlobalTrigger();
753     localTrigger = LocalTrigger();
754     
755     Int_t nglobals = (Int_t) globalTrigger->GetEntriesFast(); // should be 1
756     Int_t nlocals  = (Int_t) localTrigger->GetEntriesFast(); // up to 234
757     if (printout) printf("###################################################\n");
758     if (printout) printf("event %d nglobal %d nlocal %d \n",ievent,nglobals,nlocals);
759
760     for (Int_t iglobal=0; iglobal<nglobals; iglobal++) { // Global Trigger
761       gloTrg = static_cast<AliMUONGlobalTrigger*>(globalTrigger->At(iglobal));
762       
763       sLowpt+=gloTrg->SingleLpt() ;
764       sHighpt+=gloTrg->SingleHpt() ;
765       uSLowpt+=gloTrg->PairUnlikeLpt(); 
766       uSHighpt+=gloTrg->PairUnlikeHpt();
767       lSLowpt+=gloTrg->PairLikeLpt(); 
768       lSHighpt+=gloTrg->PairLikeHpt();
769       
770       if (printout) gloTrg->Print("full");
771
772     } // end of loop on Global Trigger
773
774     for (Int_t ilocal=0; ilocal<nlocals; ilocal++) { // Local Trigger
775       locTrg = static_cast<AliMUONLocalTrigger*>(localTrigger->At(ilocal));
776
777       Bool_t xTrig=kFALSE;
778       Bool_t yTrig=kFALSE;
779
780       if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 && 
781            locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
782       else xTrig=kTRUE;                         // trigger in X
783       if (locTrg->LoTrigY()==1 && 
784           locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
785       else yTrig = kTRUE;                          // trigger in Y
786
787       if (xTrig && yTrig) { // make Trigger Track if trigger in X and Y
788           
789           if (printout) locTrg->Print("full");
790           
791           AliMUONTriggerCircuit* circuit = (AliMUONTriggerCircuit*)triggerCircuit->At(locTrg->LoCircuit()-1); 
792           
793           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()));
794       }
795       
796     } // end of loop on Local Trigger
797     
798     // fill ntuple
799     tupleGlo->Fill(ievent,nglobals,gloTrg->SingleLpt(),gloTrg->SingleHpt(),gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
800     
801     ResetTrigger();
802     if (event2Check!=0) ievent=nevents;
803   } // end loop on event  
804   
805   // Print out summary if loop ran over all event
806   if (!event2Check){
807
808     printf("\n");
809     printf("=============================================\n");
810     printf("================  SUMMARY  ==================\n");
811     printf("\n");
812     printf("Total number of events processed %d \n", (event2Check==0) ? nevents : 1);
813     printf("\n");
814     printf(" Global Trigger output       Low pt  High pt\n");
815     printf(" number of Single           :\t");
816     printf("%i\t%i\t",sLowpt,sHighpt);
817     printf("\n");
818     printf(" number of UnlikeSign pair  :\t"); 
819     printf("%i\t%i\t",uSLowpt,uSHighpt);
820     printf("\n");
821     printf(" number of LikeSign pair    :\t");  
822     printf("%i\t%i\t",lSLowpt,lSHighpt);
823     printf("\n");
824     printf("=============================================\n");
825     fflush(stdout);
826   }
827   
828   if (write){
829       TFile *myFile = new TFile(fileName, "RECREATE");
830       tupleGlo->Write();
831       tupleLoc->Write();
832       myFile->Close();
833   }
834
835   fLoader->UnloadRecPoints();
836
837   delete crateManager;
838   delete transformer;
839   delete triggerCircuit;
840   
841 }