]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONCheck.C
Standard aliroot I/O for MUON tracks
[u/mrichter/AliRoot.git] / MUON / MUONCheck.C
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 //
19 // Macro for checking aliroot output and associated files contents
20 // Gines Martinez, Subatech June 2003
21 //
22
23 // ROOT includes
24 #include "TBranch.h"
25 #include "TClonesArray.h"
26 #include "TFile.h"
27 #include "TH1.h"
28 #include "TParticle.h"
29 #include "TTree.h"
30
31 // STEER includes
32 #include "AliRun.h"
33 #include "AliRunLoader.h"
34 #include "AliHeader.h"
35 #include "AliLoader.h"
36 #include "AliStack.h"
37
38 // MUON includes
39 #include "AliMUON.h"
40 #include "AliMUONData.h"
41 #include "AliMUONHit.h"
42 #include "AliMUONConstants.h"
43 #include "AliMUONDigit.h"
44 #include "AliMUONRawCluster.h"
45 #include "AliMUONGlobalTrigger.h"
46 #include "AliMUONLocalTrigger.h"
47 #include "AliMUONTrack.h"
48
49 void MUONkine(char * filename="galice.root")
50 {
51   TClonesArray * ListOfParticles = new TClonesArray("TParticle",1000);
52   TParticle * particle = new TParticle();
53   // Creating Run Loader and openning file containing Hits
54   AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONFolder","READ");
55   if (RunLoader ==0x0) {
56     printf(">>> Error : Error Opening %s file \n",filename);
57     return;
58   }
59   RunLoader->LoadKinematics("READ");
60   Int_t ievent, nevents;
61   nevents = RunLoader->GetNumberOfEvents();
62
63   for(ievent=0; ievent<nevents; ievent++) {  // Event loop
64     Int_t iparticle, nparticles;
65     // Getting event ievent
66     RunLoader->GetEvent(ievent); 
67     RunLoader->TreeK()->GetBranch("Particles")->SetAddress(&particle);
68     nparticles = RunLoader->TreeK()->GetEntries();
69     printf(">>> Event %d, Number of particles is %d \n",ievent, nparticles);
70     for(iparticle=0; iparticle<nparticles; iparticle++) {
71       RunLoader->TreeK()->GetEvent(iparticle);
72       particle->Print("");
73     }
74   }
75   RunLoader->UnloadKinematics();
76 }
77
78
79 void MUONhits(char * filename="galice.root")
80 {
81   // Creating Run Loader and openning file containing Hits
82   AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONFolder","READ");
83   if (RunLoader ==0x0) {
84     printf(">>> Error : Error Opening %s file \n",filename);
85     return;
86   }
87   // Loading MUON subsystem
88   AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
89   MUONLoader->LoadHits("READ");  // Loading Tree of hits for MUON
90   AliMUONData muondata(MUONLoader,"MUON","MUON");  // Creating MUON data container
91   Int_t ievent, nevents;
92   nevents = RunLoader->GetNumberOfEvents();
93
94   for(ievent=0; ievent<nevents; ievent++) {  // Event loop
95     printf(">>> Event %d \n",ievent);
96     // Getting event ievent
97     RunLoader->GetEvent(ievent); 
98     muondata.SetTreeAddress("H");
99     Int_t itrack, ntracks;
100     ntracks = (Int_t) muondata.GetNtracks();
101     for (itrack=0; itrack<ntracks; itrack++) { // Track loop
102       printf(">>> Track %d \n",itrack);
103
104       //Getting List of Hits of Track itrack
105       muondata.GetTrack(itrack); 
106
107       Int_t ihit, nhits;
108       nhits = (Int_t) muondata.Hits()->GetEntriesFast();
109       printf(">>> Number of hits  %d \n",nhits);
110       AliMUONHit* mHit;
111       for(ihit=0; ihit<nhits; ihit++) {
112         mHit = static_cast<AliMUONHit*>(muondata.Hits()->At(ihit));
113         Int_t Nch      = mHit->Chamber();  // chamber number
114         Int_t hittrack = mHit->Track();
115         Float_t x      = mHit->X();
116         Float_t y      = mHit->Y();
117         Float_t z      = mHit->Z();
118         Float_t elos   = mHit->Eloss();
119         Float_t theta  = mHit->Theta();
120         Float_t phi    = mHit->Phi();
121         Float_t momentum = mHit->Momentum();
122         printf(">>> Hit %2d Chamber %2d Track %4d x %6.3f y %6.3f z %7.3f elos %g theta %6.3f phi %5.3f momentum %5.3f\n",
123                ihit, Nch,hittrack,x,y,z,elos,theta,phi, momentum);
124       }
125       muondata.ResetHits();
126     } // end track loop
127   }  // end event loop
128   MUONLoader->UnloadHits();
129 }
130
131
132 void MUONdigits(char * filename="galice.root")
133 {
134   // Creating Run Loader and openning file containing Hits
135   AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONFolder","READ");
136   if (RunLoader ==0x0) {
137     printf(">>> Error : Error Opening %s file \n",filename);
138     return;
139   }
140   // Loading MUON subsystem
141   AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
142   MUONLoader->LoadDigits("READ");
143   // Creating MUON data container
144   AliMUONData muondata(MUONLoader,"MUON","MUON");
145
146   Int_t ievent, nevents;
147   nevents = RunLoader->GetNumberOfEvents();
148   AliMUONDigit * mDigit;
149   
150   for(ievent=0; ievent<nevents; ievent++) {
151     printf(">>> Event %d \n",ievent);
152     RunLoader->GetEvent(ievent);
153   
154     // Addressing
155     Int_t ichamber, nchambers;
156     nchambers = AliMUONConstants::NCh(); ;
157     muondata.SetTreeAddress("D"); 
158     char branchname[30];    
159  
160     Int_t icathode, ncathodes;
161     ncathodes=2;
162     //Loop on cathodes 
163     for(icathode=0; icathode<ncathodes; icathode++) {
164       printf(">>> Cathode %d\n",icathode);
165       muondata.GetCathode(icathode);
166       // Loop on chambers
167       for( ichamber=0; ichamber<nchambers; ichamber++) {
168         printf(">>> Chamber %d\n",ichamber);
169         
170         Int_t idigit, ndigits;
171         ndigits = (Int_t) muondata.Digits(ichamber)->GetEntriesFast();
172         
173         for(idigit=0; idigit<ndigits; idigit++) {
174           mDigit = static_cast<AliMUONDigit*>(muondata.Digits(ichamber)->At(idigit));
175           Int_t PadX   = mDigit->PadX();     // Pad X number
176           Int_t PadY   = mDigit->PadY();     // Pad Y number
177           Int_t Signal = mDigit->Signal();   // Physics Signal
178           Int_t Physics= mDigit->Physics();  // Physics contribution to signal
179           Int_t Hit    = mDigit->Hit();      // iHit
180           Int_t Cathode= mDigit->Cathode();  // Cathode
181           Int_t Track0 = mDigit->Track(0);
182           Int_t Track1 = mDigit->Track(1); 
183           Int_t Track2 = mDigit->Track(2);
184           Int_t TCharges0 = mDigit->TrackCharge(0);  //charge per track making this digit (up to 10)
185           Int_t TCharges1 = mDigit->TrackCharge(1);
186           Int_t TCharges2 = mDigit->TrackCharge(2);
187           
188           printf(">>> Digit %4d cathode %1d hit %4d PadX %3d PadY %3d Signal %4d Physics %4d Track0 %4d TrackCharge0 %4d Track1 %'d 
189           TrackCharge1 %4d Track2 %4d TrackCharge2 %4d \n",idigit, Cathode,Hit, PadX, PadY, Signal, Physics, 
190           Track0, TCharges0, Track1, TCharges1, Track2, TCharges2);
191         } // end digit loop
192       } // end chamber loop
193       muondata.ResetDigits();
194     } // end cathode loop
195   }  // end event loop
196   MUONLoader->UnloadDigits();
197 }
198
199 void MUONrecpoints(char * filename="galice.root") {
200
201   // Creating Run Loader and openning file containing Hits
202   AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONFolder","READ");
203   if (RunLoader ==0x0) {
204     printf(">>> Error : Error Opening %s file \n",filename);
205     return;
206   }
207   // Getting MUONloader
208   AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
209   MUONLoader->LoadRecPoints("READ");
210   // Creating MUON data container
211   AliMUONData muondata(MUONLoader,"MUON","MUON");
212
213   Int_t ievent, nevents;
214   nevents = RunLoader->GetNumberOfEvents();
215   AliMUONRawCluster * mRecPoint;
216   
217   for(ievent=0; ievent<nevents; ievent++) {
218     printf(">>> Event %d \n",ievent);
219     RunLoader->GetEvent(ievent);
220     // Addressing
221     Int_t ichamber, nchambers;
222     nchambers = AliMUONConstants::NTrackingCh();
223     muondata.SetTreeAddress("RC"); 
224     char branchname[30];    
225     muondata.GetRawClusters();
226     // Loop on chambers
227     for( ichamber=0; ichamber<nchambers; ichamber++) {
228       printf(">>> Chamber %d\n",ichamber);
229       sprintf(branchname,"MUONRawClusters%d",ichamber+1);
230       //printf(">>>  branchname %s\n",branchname);
231   
232       Int_t irecpoint, nrecpoints;
233       nrecpoints = (Int_t) muondata.RawClusters(ichamber)->GetEntriesFast();
234       
235       for(irecpoint=0; irecpoint<nrecpoints; irecpoint++) {
236         mRecPoint = static_cast<AliMUONRawCluster*>(muondata.RawClusters(ichamber)->At(irecpoint));
237 //     Int_t       fTracks[3];        //labels of overlapped tracks
238 //     Int_t       fQ[2]  ;           // Q of cluster (in ADC counts)     
239 //     Float_t     fX[2]  ;           // X of cluster
240 //     Float_t     fY[2]  ;           // Y of cluster
241 //     Float_t     fZ[2]  ;           // Z of cluster
242 //     Int_t       fPeakSignal[2];    // Peak signal 
243 //     Int_t       fIndexMap[50][2];  // indeces of digits
244 //     Int_t       fOffsetMap[50][2]; // Emmanuel special
245 //     Float_t     fContMap[50][2];   // Contribution from digit
246 //     Int_t       fPhysicsMap[50];   // Distinguish signal and background contr.
247 //     Int_t       fMultiplicity[2];  // Cluster multiplicity
248 //     Int_t       fNcluster[2];      // Number of clusters
249 //     Int_t       fClusterType;      // Cluster type
250 //     Float_t     fChi2[2];          // Chi**2 of fit
251 //     Int_t       fGhost;            // 0 if not a ghost or ghost problem solved
252 //                                    // >0 if ghost problem remains because
253 //                                    // 1 both (true and ghost) satify 
254 //                                    //   charge chi2 compatibility
255 //                                    // 2 none give satisfactory chi2
256
257         Int_t Track0 = mRecPoint->fTracks[0];
258         Int_t Track1 = mRecPoint->fTracks[1]; 
259         Int_t Track2 = mRecPoint->fTracks[2];
260         Int_t Q0 = mRecPoint->fQ[0];
261         Int_t Q1 = mRecPoint->fQ[1];
262         Float_t x0 = mRecPoint->fX[0];
263         Float_t x1 = mRecPoint->fX[1];
264         Float_t y0 = mRecPoint->fY[0];
265         Float_t y1 = mRecPoint->fY[1];
266         Float_t z0 = mRecPoint->fZ[0];
267         Float_t z1 = mRecPoint->fZ[1];
268         Float_t chi2_0 =  mRecPoint->fChi2[0];
269         Float_t chi2_1 =  mRecPoint->fChi2[1];
270
271         printf(">>> RecPoint %4d x %6.3f %6.3f y %6.3f %6.3f z %6.3f %6.3f Q0 %4d  Q1 %4d Hit %4d Track1 %4d Track2 %4d Chi2 %6.3f %6.3f \n",
272 irecpoint, x0, x1, y0, y1, z0, z1, Q0, Q1, Track0, Track1, Track2, chi2_0, chi2_1);
273       } // end recpoint loop
274     } // end chamber loop
275     muondata.ResetRawClusters();
276   }  // end event loop
277   MUONLoader->UnloadRecPoints();
278 }
279
280 void MUONTestTrigger (char * filename="galice.root"){
281 // reads and dumps trigger objects from MUON.RecPoints.root
282   TClonesArray * globalTrigger;
283   TClonesArray * localTrigger;
284   
285   // Creating Run Loader and openning file containing Hits
286   AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONFolder","READ");
287   if (RunLoader ==0x0) {
288     printf(">>> Error : Error Opening %s file \n",filename);
289     return;
290   }
291   
292   AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
293   MUONLoader->LoadRecPoints("READ");
294   // Creating MUON data container
295   AliMUONData muondata(MUONLoader,"MUON","MUON");
296   
297   
298   Int_t ievent, nevents;
299   nevents = RunLoader->GetNumberOfEvents();
300   
301   AliMUONGlobalTrigger *gloTrg;
302   AliMUONLocalTrigger *locTrg;
303   
304   for (ievent=0; ievent<nevents; ievent++) {
305     RunLoader->GetEvent(ievent);
306     
307     muondata.SetTreeAddress("GLT"); 
308     muondata.GetTrigger();
309     
310     globalTrigger = muondata.GlobalTrigger();
311     localTrigger = muondata.LocalTrigger();
312     
313     Int_t nglobals = (Int_t) globalTrigger->GetEntriesFast(); // should be 1
314     Int_t nlocals  = (Int_t) localTrigger->GetEntriesFast(); // up to 234
315     printf("###################################################\n");
316     cout << " event " << ievent 
317          << " nglobals nlocals: " << nglobals << " " << nlocals << "\n"; 
318     
319     for (Int_t iglobal=0; iglobal<nglobals; iglobal++) { // Global Trigger
320       gloTrg = static_cast<AliMUONGlobalTrigger*>(globalTrigger->At(iglobal));
321       
322       printf("===================================================\n");
323       printf(" Global Trigger output       Low pt  High pt   All\n");
324       printf(" number of Single Plus      :\t");
325       printf("%i\t%i\t%i\t",gloTrg->SinglePlusLpt(),
326              gloTrg->SinglePlusHpt(),gloTrg->SinglePlusApt());
327       printf("\n");
328       printf(" number of Single Minus     :\t");
329       printf("%i\t%i\t%i\t",gloTrg->SingleMinusLpt(),
330              gloTrg->SingleMinusHpt(),gloTrg->SingleMinusApt());
331       printf("\n");
332       printf(" number of Single Undefined :\t"); 
333       printf("%i\t%i\t%i\t",gloTrg->SingleUndefLpt(),
334              gloTrg->SingleUndefHpt(),gloTrg->SingleUndefApt());
335       printf("\n");
336       printf(" number of UnlikeSign pair  :\t"); 
337       printf("%i\t%i\t%i\t",gloTrg->PairUnlikeLpt(),
338              gloTrg->PairUnlikeHpt(),gloTrg->PairUnlikeApt());
339       printf("\n");
340       printf(" number of LikeSign pair    :\t");  
341       printf("%i\t%i\t%i\t",gloTrg->PairLikeLpt(),
342              gloTrg->PairLikeHpt(),gloTrg->PairLikeApt());
343       printf("\n");
344       printf("===================================================\n");
345       
346     } // end of loop on Global Trigger
347     
348     for (Int_t ilocal=0; ilocal<nlocals; ilocal++) { // Local Trigger
349       cout << " >>> Output for Local Trigger " << ilocal << "\n";
350       
351       locTrg = static_cast<AliMUONLocalTrigger*>(localTrigger->At(ilocal));
352       
353       cout << "Circuit StripX Dev StripY: " 
354            << locTrg->LoCircuit() << " " 
355            << locTrg->LoStripX() << " " 
356            << locTrg->LoDev() << " " 
357            << locTrg->LoStripY() 
358            << "\n";
359       cout << "Lpt Hpt Apt: "     
360            << locTrg->LoLpt() << " "   
361            << locTrg->LoHpt() << " "  
362            << locTrg->LoApt() << "\n";
363       
364     } // end of loop on Local Trigger
365     muondata.ResetTrigger();
366   } // end loop on event  
367   MUONLoader->UnloadRecPoints();
368 }
369
370
371
372 void MUONRecTracks (char * filename="galice.root"){
373 // reads and dumps trigger objects from MUON.RecPoints.root
374   TClonesArray * RecTracks;
375   
376   // Creating Run Loader and openning file containing Hits
377   AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONFolder","READ");
378   if (RunLoader ==0x0) {
379     printf(">>> Error : Error Opening %s file \n",filename);
380     return;
381   }
382   
383   AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
384   MUONLoader->LoadTracks("READ");
385   // Creating MUON data container
386   AliMUONData muondata(MUONLoader,"MUON","MUON");
387   
388     Int_t ievent, nevents;
389   nevents = RunLoader->GetNumberOfEvents();
390   
391   AliMUONTrack * rectrack;
392   
393   for (ievent=0; ievent<nevents; ievent++) {
394     RunLoader->GetEvent(ievent);
395     
396     muondata.SetTreeAddress("RT");
397     muondata.GetRecTracks();
398     RecTracks = muondata.RecTracks();
399     
400     
401     Int_t nrectracks = (Int_t) RecTracks->GetEntriesFast(); //
402
403     printf(">>> Event %d Number of Recconstructed tracks %d \n",ievent, nrectracks);
404    
405     muondata.ResetRecTracks();
406   } // end loop on event  
407   MUONLoader->UnloadTracks();
408 }
409
410
411
412
413
414
415
416
417
418