]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCheck.cxx
Removing quick code hack and unnecessary methods. Now have a much cleaner implementat...
[u/mrichter/AliRoot.git] / MUON / AliMUONCheck.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 //-----------------------------------------------------------------------------
19 /// \class AliMUONCheck
20 ///
21 /// This class check the ESD tree, providing the matching with the trigger
22 /// response and designing useful plots (Pt, Y, ITS vertex, multiplicity).
23 ///  Note that there is a special flag to turn on for pdc06 production. 
24 /// It also checks the TR tree giving hit densities on the two first and 
25 /// last planes of the spectrometer as well as the time of flight on these planes.
26 /// MUONkine() provides event stack and check if the event are generated with 
27 /// at least one muon and two muons (for PDC06).
28 /// DumpDigit() as a replacement of the function from MUONCheck.C macro.
29 ///
30 /// \author Frederic Yermia, INFN Torino
31 //-----------------------------------------------------------------------------
32
33 #include "AliMUONCheck.h"
34 #include "AliMUONConstants.h"
35 #include "AliMUONTrack.h"
36 #include "AliMUONTrackParam.h"
37 #include "AliMUONTrackExtrap.h"
38 #include "AliMUONMCDataInterface.h"
39 #include "AliMUONDataInterface.h"
40 #include "AliMpSegmentation.h"
41 #include "AliMpVSegmentation.h"
42 #include "AliMpDEManager.h"
43 #include "AliMpCDB.h"
44 #include "AliMUONVDigitStore.h"
45
46 #include "AliRunLoader.h"
47 #include "AliLoader.h"
48 #include "AliStack.h"
49 #include "AliTrackReference.h"
50 #include "AliTracker.h"
51 #include "AliESDEvent.h"
52 #include "AliESDMuonTrack.h"
53 #include "AliESDVertex.h"
54 #include "AliMagFMaps.h"
55 #include "AliLog.h"
56
57 #include <TSystem.h>
58 #include <TCanvas.h>
59 #include <TLorentzVector.h>
60 #include <TFile.h>
61 #include <TH1.h>
62 #include <TParticle.h>
63
64 /// \cond CLASSIMP
65 ClassImp(AliMUONCheck)
66 /// \endcond
67
68 AliMUONCheck::AliMUONCheck(const char* galiceFile, const char* esdFile,Int_t firstEvent, Int_t lastEvent,const char* outDir) 
69 : TObject(),
70 fFileName(galiceFile),
71 fFileNameSim(),
72 fesdFileName(esdFile),
73 foutDir(outDir),
74 fFirstEvent(firstEvent),
75 fLastEvent(lastEvent)
76 {
77   /// ctor
78 }
79
80 //_____________________________________________________________________________
81 AliMUONCheck::AliMUONCheck(const char* galiceFile, const char* galiceFileSim,
82                            const char* esdFile,Int_t firstEvent, Int_t lastEvent,
83                            const char* outDir) 
84 : TObject(),
85 fFileName(galiceFile),
86 fFileNameSim(galiceFileSim),
87 fesdFileName(esdFile),
88 foutDir(outDir),
89 fFirstEvent(firstEvent),
90 fLastEvent(lastEvent)
91 {
92   /// ctor
93 }
94
95 //_____________________________________________________________________________
96 AliMUONCheck::~AliMUONCheck()
97 {
98   /// Destructor
99 }
100
101 //_____________________________________________________________________________
102 void
103 AliMUONCheck::CheckESD(Bool_t pdc06TriggerResponse) 
104 {
105   /// Check ESD files
106   
107   // Histograms
108   TH1F * fhMUONVertex ; //! 
109   TH1F * fhMUONMult   ; //!
110   
111   // create histograms 
112   fhMUONVertex = new TH1F("hMUONVertex","ITS Vertex"                ,100, -25., 25.);
113   fhMUONMult   = new TH1F("hMUONMult"  ,"Multiplicity of ESD tracks",10,  -0.5, 9.5);
114   
115   TH1F *hY = new TH1F("hY","Rapidity",100,-5.,-1.);
116   TH1F *hPt = new TH1F("hPt","Pt",100, 0.,20.);
117   
118   // ------------->open the ESD file
119   TFile* esdFile = TFile::Open(fesdFileName.Data());
120   
121   if (!esdFile || !esdFile->IsOpen()) 
122   {
123     AliError(Form("Error opening %s file \n",fesdFileName.Data()));
124     return;
125   }
126   
127   Int_t fSPLowpt=0     ; //!
128   Int_t fSPHighpt=0    ; //!
129   Int_t fSPAllpt=0     ; //!
130   Int_t fSMLowpt=0     ; //!
131   Int_t fSMHighpt =0   ; //!
132   Int_t fSMAllpt=0     ; //!
133   Int_t fSULowpt=0     ; //!
134   Int_t fSUHighpt=0    ; //!
135   Int_t fSUAllpt=0     ; //!
136   Int_t fUSLowpt=0     ; //!
137   Int_t fUSHighpt=0    ; //!
138   Int_t fUSAllpt=0     ; //! 
139   Int_t fLSLowpt=0     ; //!
140   Int_t fLSHighpt=0    ; //! 
141   Int_t fLSAllpt=0     ; //!
142   
143   Int_t fSLowpt=0      ; //!
144   Int_t fSHighpt=0     ; //!
145   
146   Int_t fnTrackTrig=0  ; //!
147   Int_t ftracktot=0    ; //!
148   Int_t effMatch=0     ; //!
149   
150   TLorentzVector fV1;
151   Float_t muonMass = 0.105658389;
152   Double_t thetaX, thetaY, pYZ;
153   Double_t fPxRec1, fPyRec1, fPzRec1, fE1;
154   Int_t fZ1;
155   
156   AliESDEvent* fESD = new AliESDEvent();
157   TTree* tree = (TTree*) esdFile->Get("esdTree");
158   if (!tree) 
159   {
160     Error("CheckESD", "no ESD tree found");
161     AliError(Form("CheckESD", "no ESD tree found"));
162     return ;
163   }
164   fESD->ReadFromTree(tree);
165   
166   Int_t fnevents = tree->GetEntries();
167   Int_t endOfLoop = fLastEvent+1;
168   
169   if ( fLastEvent == -1 ) endOfLoop = fnevents;
170   Int_t ievent=0;
171   Int_t nev=0;
172   
173   for (ievent = fFirstEvent; ievent < endOfLoop; ++ievent ) 
174   {
175     nev++;    
176     tree->GetEvent(ievent);
177     if (!fESD) 
178     {
179       Error("CheckESD", "no ESD object found for event %d", ievent);
180       return ;
181     }
182     AliESDVertex* vertex = (AliESDVertex*) fESD->GetVertex();
183     
184     Double_t zVertex = 0. ;
185     if (vertex) zVertex = vertex->GetZv();
186     
187     Int_t nTracks = (Int_t)fESD->GetNumberOfMuonTracks() ;
188     ULong64_t trigword=fESD->GetTriggerMask();
189     
190     if(pdc06TriggerResponse)
191     {
192       if (trigword & 0x01) {
193         fSPLowpt++;
194       }
195       
196       if (trigword & 0x02){
197         fSPHighpt++;
198       }
199       if (trigword & 0x04){
200         fSPAllpt++;
201       } 
202       if (trigword & 0x08){
203         fSMLowpt++;
204       }  
205       if (trigword & 0x010){
206         fSMHighpt++;
207       }
208       if (trigword & 0x020){
209         fSMAllpt++;
210       } 
211       if (trigword & 0x040){
212         fSULowpt++;
213       }  
214       if (trigword & 0x080){
215         fSUHighpt++;
216       }   
217       if (trigword & 0x100){
218         fSUAllpt++;
219       }  
220       if (trigword & 0x200){
221         fUSLowpt++;
222       }
223       
224       if (trigword & 0x400){
225         fUSHighpt++;
226       }
227       if (trigword & 0x800){
228         fUSAllpt++;
229       }
230       if (trigword & 0x1000){
231         fLSLowpt++;
232       }
233       
234       if (trigword & 0x2000){
235         fLSHighpt++;
236       }
237       
238       if (trigword & 0x4000){
239         fLSAllpt++;
240       }
241     }// if pdc06TriggerResponse
242     else {
243       if (trigword & 0x01) {
244         fSLowpt++;
245       }
246       
247       if (trigword & 0x02){
248         fSHighpt++;
249       }
250       if (trigword & 0x04){
251         fLSLowpt++;
252       } 
253       if (trigword & 0x08){
254         fLSHighpt++;
255       }  
256       if (trigword & 0x010){
257         fUSLowpt++;
258       }
259       if (trigword & 0x020){
260         fUSHighpt++;
261       }
262     }
263     
264     Int_t tracktrig=0;
265     
266     for ( Int_t iTrack1 = 0; iTrack1<nTracks; ++iTrack1 ) 
267     { //1st loop
268       AliESDMuonTrack* muonTrack = fESD->GetMuonTrack(iTrack1);
269       ftracktot++;
270       
271       thetaX = muonTrack->GetThetaX();
272       thetaY = muonTrack->GetThetaY();
273       pYZ     =  1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
274       
275       fPzRec1  = - pYZ / TMath::Sqrt(1.0 + TMath::Tan(thetaY)*TMath::Tan(thetaY));
276       fPxRec1  = fPzRec1 * TMath::Tan(thetaX);
277       fPyRec1  = fPzRec1 * TMath::Tan(thetaY);
278       fZ1 = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
279       fE1 = TMath::Sqrt(muonMass * muonMass + fPxRec1 * fPxRec1 + fPyRec1 * fPyRec1 + fPzRec1 * fPzRec1);
280       fV1.SetPxPyPzE(fPxRec1, fPyRec1, fPzRec1, fE1);
281       // -----------> transverse momentum
282       Float_t pt1 = fV1.Pt();
283       // ----------->Rapidity
284       Float_t y1 = fV1.Rapidity();
285       
286       if(muonTrack->GetMatchTrigger()) 
287       {
288         fnTrackTrig++;
289         tracktrig++;
290       }
291       hY->Fill(y1);
292       hPt->Fill(pt1);
293     } // loop on track
294     
295     fhMUONVertex->Fill(zVertex) ;
296     fhMUONMult->Fill(Float_t(nTracks)) ;
297     
298   } // loop over events
299   
300   AliInfo(Form("Terminate %s:", GetName())) ;
301   
302   effMatch=100*fnTrackTrig/ftracktot;
303   
304   if(pdc06TriggerResponse)
305   {
306     printf("=================================================================\n") ;
307     printf("================  %s ESD SUMMARY    ==============\n", GetName()) ;
308     printf("                                                   \n") ;
309     printf("         Total number of processed events  %d      \n", nev) ;
310     printf("\n")  ;
311     printf("\n")  ;
312     printf("Table 1:                                         \n") ;
313     printf(" Global Trigger output       Low pt  High pt   All\n") ;
314     printf(" number of Single Plus      :\t");
315     printf("%i\t%i\t%i\t", fSPLowpt, fSPHighpt, fSPAllpt) ;
316     printf("\n");
317     printf(" number of Single Minus     :\t");
318     printf("%i\t%i\t%i\t", fSMLowpt, fSMHighpt, fSMAllpt) ;
319     printf("\n");
320     printf(" number of Single Undefined :\t"); 
321     printf("%i\t%i\t%i\t", fSULowpt, fSUHighpt, fSUAllpt) ;
322     printf("\n");
323     printf(" number of UnlikeSign pair  :\t"); 
324     printf("%i\t%i\t%i\t", fUSLowpt, fUSHighpt, fUSAllpt) ;
325     printf("\n");
326     printf(" number of LikeSign pair    :\t");  
327     printf("%i\t%i\t%i\t", fLSLowpt, fLSHighpt, fLSAllpt) ;
328     printf("\n");
329     printf("===================================================\n") ;
330     printf("\n") ;
331     printf("matching efficiency with the trigger for single tracks = %2d %% \n", effMatch);
332     printf("================================================================\n") ;  printf("\n") ;
333     
334   }//if(pdc06TriggerResponse)
335   
336   gSystem->cd(foutDir);
337   
338   FILE *outtxt=fopen("output.txt","a");
339   freopen("output.txt","a",outtxt);
340   
341   if(pdc06TriggerResponse){
342     fprintf(outtxt,"                                                   \n");
343     fprintf(outtxt,"===================================================\n");
344     fprintf(outtxt,"================      ESD SUMMARY    ==============\n");
345     fprintf(outtxt,"                                                   \n");
346     fprintf(outtxt,"    Total number of processed events  %d      \n", nev); 
347     fprintf(outtxt,"\n");
348     fprintf(outtxt,"\n");
349     fprintf(outtxt,"Table 1:                                         \n");
350     fprintf(outtxt," Global Trigger output       Low pt  High pt   All\n");
351     fprintf(outtxt," number of Single Plus      :\t");
352     fprintf(outtxt,"%i\t%i\t%i\t",fSPLowpt,fSPHighpt,fSPAllpt);
353     fprintf(outtxt,"\n");
354     fprintf(outtxt," number of Single Minus     :\t");
355     fprintf(outtxt,"%i\t%i\t%i\t",fSMLowpt,fSMHighpt,fSMAllpt);
356     fprintf(outtxt,"\n");
357     fprintf(outtxt," number of Single Undefined :\t"); 
358     fprintf(outtxt,"%i\t%i\t%i\t",fSULowpt,fSUHighpt,fSUAllpt);
359     fprintf(outtxt,"\n");
360     fprintf(outtxt," number of UnlikeSign pair  :\t"); 
361     fprintf(outtxt,"%i\t%i\t%i\t",fUSLowpt,fUSHighpt,fUSAllpt);
362     fprintf(outtxt,"\n");
363     fprintf(outtxt," number of LikeSign pair    :\t");  
364     fprintf(outtxt,"%i\t%i\t%i\t",fLSLowpt,fLSHighpt, fLSAllpt);
365     fprintf(outtxt,"\n");
366     fprintf(outtxt,"===================================================\n");
367     fprintf(outtxt,"\n");
368     fprintf(outtxt,"matching efficiency with the trigger for single tracks = %2d %% \n", effMatch);
369   }//if(pdc06TriggerResponse)
370   
371   else {
372     
373     fprintf(outtxt,"                                                   \n");
374     fprintf(outtxt,"===================================================\n");
375     fprintf(outtxt,"================      ESD SUMMARY    ==============\n");
376     fprintf(outtxt,"                                                   \n");
377     fprintf(outtxt,"    Total number of processed events  %d      \n", nev); 
378     fprintf(outtxt,"\n");
379     fprintf(outtxt,"\n");
380     fprintf(outtxt,"Table 1:                                         \n");
381     fprintf(outtxt," Global Trigger output       Low pt  High pt     \n");
382     fprintf(outtxt," number of Single       :\t");
383     fprintf(outtxt,"%i\t%i\t",fSLowpt,fSHighpt);
384     fprintf(outtxt,"\n");
385     fprintf(outtxt," number of UnlikeSign pair :\t"); 
386     fprintf(outtxt,"%i\t%i\t",fUSLowpt,fUSHighpt);
387     fprintf(outtxt,"\n");
388     fprintf(outtxt," number of LikeSign pair    :\t");  
389     fprintf(outtxt,"%i\t%i\t",fLSLowpt,fLSHighpt);
390     fprintf(outtxt,"\n");
391     fprintf(outtxt,"===================================================\n");
392     fprintf(outtxt,"\n");
393     fprintf(outtxt,"matching efficiency with the trigger for single tracks = %2d %% \n", effMatch);
394   }//else
395   fclose(outtxt);
396   
397   TCanvas * c1 = new TCanvas("c1", "ESD", 400, 10, 600, 700) ;
398   c1->Divide(1,2) ;
399   c1->cd(1) ;
400   fhMUONVertex->Draw() ;
401   c1->cd(2) ;
402   fhMUONMult->Draw() ;  
403   c1->Print("VertexAndMul.eps") ; 
404   TCanvas *c2 = new TCanvas("c2","ESD",400,10,600,700);
405   c2->Divide(1,2);
406   c2->cd(1);
407   hY->Draw();
408   c2->cd(2);
409   hPt->Draw();
410   c2->Print("YandPt.eps") ; 
411 }
412
413 //_____________________________________________________________________________
414 void
415 AliMUONCheck::CheckKine() 
416 {
417   /// Check Stack 
418   
419   AliMUONMCDataInterface diSim(fFileNameSim.Data());
420   if (!diSim.IsValid()) return;
421   
422   Int_t fnevents = diSim.NumberOfEvents();
423   
424   Int_t endOfLoop = fLastEvent+1;
425   
426   if ( fLastEvent == -1 ) endOfLoop = fnevents;
427   
428   Int_t nev=0;
429   Int_t nmu=0;
430   Int_t nonemu=0;
431   Int_t ndimu=0;
432   
433   for ( Int_t ievent = fFirstEvent; ievent < endOfLoop; ++ievent ) 
434   {
435     Int_t nmu2=0;
436     ++nev;  
437     
438     AliStack* stack = diSim.Stack(ievent);
439     Int_t npa = stack->GetNprimary();
440     Int_t npb = stack->GetNtrack(); 
441     printf("Primary particles  %i   \n",npa); 
442     printf("Sec particles  %i   \n",npb); 
443     printf("=================================================================\n") ;
444     printf("Primary particles listing:  \n"); 
445     printf("=================================================================\n") ;
446     for (Int_t i=0; i<npa; ++i) 
447     {
448       TParticle *p  = stack->Particle(i);
449       p->Print("");
450       Int_t pdg=p->GetPdgCode(); 
451       
452       if (abs(pdg) == 13) 
453       {
454         ++nmu2;
455       }
456     }
457     printf("=================================================================\n") ;
458     printf("=================================================================\n") ;
459     
460     printf("Secondaries particles listing:  \n"); 
461     printf("=================================================================\n") ;
462     for (Int_t i=npa; i<npb; ++i) 
463     {
464       stack->Particle(i)->Print("");
465     }
466     
467     printf("=================================================================\n") ; 
468     printf(">>> Event %d, Number of primary particles is %d \n",ievent, npa); 
469     printf(">>> Event %d, Number of secondary articles is %d \n",ievent, npb-npa); 
470     printf("=================================================================\n");
471     if(nmu2>0)
472     {
473       printf(">>> Okay!!! Event %d with at least one muon on primary stack! \n",ievent); 
474       ++nonemu;
475     }
476     
477     if(nmu2==0)
478     {
479       printf(">>> Warning!!! Event %d without muon on primary stack! \n",ievent);     
480       ++nmu;
481     }
482     
483     if(nmu2>1)
484     {
485       printf(">>> Okay!!! Event %d with at least two muons on primary stack! \n",ievent); 
486       ++ndimu; 
487     }
488     printf("=================================================================\n");  
489     printf("                                                                  \n");
490     printf("                                                                  \n") ;
491   }//ievent
492   
493   printf("=================================================================\n") ;
494   printf("               Total number of processed events  %d               \n", nev) ;
495   printf("                                                                 \n") ;
496   
497   if(nmu>0)
498   {
499     printf("--->                       WARNING!!!                       <---\n"); 
500     printf(" %i events without muon on primary stack \n",nmu); 
501   }
502   
503   if(nmu==0)
504   {
505     printf("--->                          OKAY!!!                        <---\n"); 
506     printf("  %i events generated with at least one muon on primary stack \n",nonemu);
507   }
508   
509   if(ndimu>0)
510   {
511     printf("--->                          OKAY!!!                        <---\n"); 
512     printf("  %i events generated with at least two muons on primary stack \n",ndimu); 
513   }
514   
515   printf("                                                                 \n") ;
516   printf("***                       Leaving MuonKine()                 *** \n");
517   printf("**************************************************************** \n");
518   
519   gSystem->cd(foutDir);
520   FILE *outtxt=fopen("output.txt","a");
521   freopen("output.txt","a",outtxt);
522   fprintf(outtxt,"                                                   \n");
523   fprintf(outtxt,"=================================================================\n");
524   fprintf(outtxt,"================         MUONkine SUMMARY        ================\n");
525   fprintf(outtxt,"\n");
526   fprintf(outtxt,"=================================================================\n");
527   fprintf(outtxt,"               Total number of processed events  %d              \n", nev) ;
528   fprintf(outtxt,"                                                                 \n");
529   
530   if(nmu>0)
531   {
532     fprintf(outtxt,"                        ---> WARNING!!! <---                     \n"); 
533     fprintf(outtxt,"  %i events without muon on primary stack \n",nmu); 
534   }
535   
536   if(nmu==0)
537   {
538     fprintf(outtxt,"                         ---> OKAY!!! <---                       \n"); 
539     fprintf(outtxt,"  %i events generated with at least one muon on primary stack \n",nonemu); 
540   }
541   
542   if(ndimu>0)
543   {
544     fprintf(outtxt,"                         ---> OKAY!!! <---                       \n"); 
545     fprintf(outtxt,"  %i events generated with at least two muons on primary stack \n",ndimu); 
546   }
547   
548   fprintf(outtxt,"                                                                 \n") ;
549   fprintf(outtxt,"***                       Leaving MuonKine()                 *** \n");
550   fprintf(outtxt,"**************************************************************** \n");
551   fclose(outtxt);
552 }
553
554 //_____________________________________________________________________________
555 void
556 AliMUONCheck::CheckTrackRef() 
557 {
558   /// Check TrackRef files
559   
560   AliMUONMCDataInterface diSim(fFileNameSim.Data());
561   if ( !diSim.IsValid() ) return;
562   
563   Int_t flag11=0,flag12=0,flag13=0,flag14=0;
564   
565   TH1F *tof01= new TH1F("tof01","TOF for first tracking plane",100,0.,100);
566   tof01->SetXTitle("tof (ns)");
567   TH1F *tof14= new TH1F("tof14","TOF for MT22",100,0.,100);
568   tof14->SetXTitle("tof (ns)");
569   
570   TH1F   *hitDensity[4];
571   hitDensity[0] =  new TH1F("TR_dhits01","",30,0,300);
572   hitDensity[0]->SetFillColor(3);
573   hitDensity[0]->SetXTitle("R (cm)");
574   hitDensity[1] =  new TH1F("TR_dhits10","",30,0,300);
575   hitDensity[1]->SetFillColor(3);
576   hitDensity[1]->SetXTitle("R (cm)");
577   hitDensity[2] =  new TH1F("TR_dhits11","",30,0,300);
578   hitDensity[2]->SetFillColor(3);
579   hitDensity[2]->SetXTitle("R (cm)");
580   hitDensity[3] =  new TH1F("TR_dhits14","",30,0,300);
581   hitDensity[3]->SetFillColor(3);
582   hitDensity[3]->SetXTitle("R (cm)");
583   
584   Int_t fnevents = diSim.NumberOfEvents();
585   
586   Int_t endOfLoop = fLastEvent+1;
587   
588   if ( fLastEvent == -1 ) endOfLoop = fnevents;
589   
590   Int_t nev=0;
591   Int_t ntot=fLastEvent+1-fFirstEvent;
592   
593   for ( Int_t ievent = fFirstEvent; ievent < endOfLoop; ++ievent ) 
594   {
595     Int_t  save=-99;
596     ++nev;  
597     
598     Int_t nentries = diSim.NumberOfTrackRefs(ievent);
599     
600     for ( Int_t l=0; l<nentries; ++l )
601     {
602       TClonesArray* trackRefs = diSim.TrackRefs(ievent,l);
603       if (!trackRefs) continue;
604       
605       Int_t nnn = trackRefs->GetEntriesFast();
606       
607       for ( Int_t k=0; k<nnn; ++k ) 
608       {
609         AliTrackReference *tref = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(k));
610         Int_t label = tref->GetTrack();
611         Float_t x     =    tref->X();        // x-pos of hit
612         Float_t y     =    tref->Y();        // y-pos
613         Float_t z     = tref->Z();
614         
615         Float_t r=TMath::Sqrt(x*x+y*y);
616         Float_t time =    tref->GetTime();  
617         
618         Float_t wgt=1/(2*10*TMath::Pi()*r)/(ntot);
619         
620         if (save!=label){
621           save=label;
622           flag11=0;
623           flag12=0;
624           flag13=0;
625           flag14=0;
626         }
627         
628         if (save==label){
629           
630           //Ch 1, z=-526.16
631           if (z<=-521&& z>=-531&&flag11==0){
632             flag11=1;
633             hitDensity[0]->Fill(r,wgt);
634             tof01->Fill(1000000000*time,1);
635           };
636           
637           //Ch 10, z=-1437.6
638           if (z<=-1432&&z>=-1442&&flag12==0){
639             flag12=1;
640             hitDensity[1]->Fill(r,wgt);
641           }
642           
643           //Ch 11, z=-1603.5
644           if (z<=-1598&& z>=-1608&&flag13==0){
645             flag13=1;
646             hitDensity[2]->Fill(r,wgt);
647           };
648           
649           //ch 14 z=-1720.5    
650           if(z<=-1715&&z>=-1725&&flag14==0){
651             flag14=1;
652             hitDensity[3]->Fill(r,wgt);
653             tof14->Fill(1000000000*time,1);
654           }; 
655           
656         }//if save==label
657         
658       }//hits de tTR
659       
660     }//entree de tTR 
661     
662   }//evt loop
663   
664   gSystem->cd(foutDir);
665   TCanvas *c6 = new TCanvas("c6","TOF",400,10,600,700);
666   c6->Divide(1,2);
667   c6->cd(1);
668   
669   tof01->Draw();
670   c6->cd(2);
671   tof14->Draw();
672   c6->Print("tof_on_trigger.ps");
673   
674   TCanvas *c5 = new TCanvas("c5","TRef:Hits Density",400,10,600,700);
675   c5->Divide(2,2);
676   c5->cd(1);
677   hitDensity[0]->Draw();
678   c5->cd(2);
679   hitDensity[1]->Draw();
680   c5->cd(3);
681   hitDensity[2]->Draw();
682   c5->cd(4);
683   hitDensity[3]->Draw();
684   c5->Print("TR_Hit_densities.ps");
685   printf("=================================================================\n") ;
686   printf("================  %s Tref SUMMARY    ==============\n", GetName()) ;
687   printf("                                                   \n") ;
688   printf("         Total number of processed events  %d      \n", nev) ;
689   printf("***                Leaving TRef()               *** \n");
690   printf("*************************************************** \n");
691 }
692
693 //_____________________________________________________________________________
694 void 
695 AliMUONCheck::CheckOccupancy(Bool_t perDetEle) const
696 {
697   /// Check occupancy for the first event selected
698   
699   Int_t dEoccupancyBending[14][26];
700   Int_t dEoccupancyNonBending[14][26];
701   Int_t cHoccupancyBending[14];
702   Int_t cHoccupancyNonBending[14];
703   Int_t totaloccupancyBending =0;
704   Int_t totaloccupancyNonBending =0;
705   
706   Int_t dEchannelsBending[14][26];
707   Int_t dEchannelsNonBending[14][26];
708   Int_t cHchannelsBending[14];
709   Int_t cHchannelsNonBending[14];
710   Int_t totalchannelsBending =0;
711   Int_t totalchannelsNonBending =0;
712   
713   Int_t nchambers = AliMUONConstants::NCh();
714   
715   AliMUONDataInterface di(fFileNameSim);
716   
717   AliMUONVDigitStore* digitStore = di.DigitStore(fFirstEvent);
718   
719   if ( ! AliMpCDB::LoadMpSegmentation()  ) 
720     AliFatal("Could not access mapping from OCDB !");
721   
722   // Compute values
723   for (Int_t ichamber=0; ichamber<nchambers; ++ichamber) 
724   {
725     cHchannelsBending[ichamber]=0;
726     cHchannelsNonBending[ichamber]=0;
727     cHoccupancyBending[ichamber]=0;
728     cHoccupancyNonBending[ichamber]=0;
729     
730     for (Int_t idetele=0; idetele<26; idetele++) 
731     {
732       Int_t detele = 100*(ichamber +1)+idetele;
733       
734       if ( AliMpDEManager::IsValidDetElemId(detele) ) 
735       {
736         Int_t cathode(0);
737         
738         const AliMpVSegmentation* segbend = AliMpSegmentation::Instance()
739         ->GetMpSegmentation(detele, AliMp::kCath0);
740         const AliMpVSegmentation* segnonbend = AliMpSegmentation::Instance()
741           ->GetMpSegmentation(detele, AliMp::kCath1);
742         
743         if (AliMpDEManager::GetPlaneType(detele, AliMp::kCath0) != AliMp::kBendingPlane ) 
744         {
745           const AliMpVSegmentation* tmp = segbend;
746           segbend    =  segnonbend;
747           segnonbend =  tmp;
748           cathode = 1;
749         }  
750         
751         Int_t nchannels = segbend->NofPads();
752         Int_t ndigits = digitStore->GetSize(detele,cathode);
753               dEchannelsBending[ichamber][idetele] = nchannels;
754         dEoccupancyBending[ichamber][idetele] = ndigits;
755               cHchannelsBending[ichamber] += nchannels;
756         cHoccupancyBending[ichamber] += ndigits;
757               totalchannelsBending += nchannels;
758         totaloccupancyBending += ndigits;
759         
760         nchannels = segnonbend->NofPads();
761         ndigits = digitStore->GetSize(detele,1-cathode);
762         
763               dEchannelsNonBending[ichamber][idetele] = nchannels;
764         dEoccupancyBending[ichamber][idetele] = ndigits;
765               cHchannelsNonBending[ichamber] += nchannels;
766               cHoccupancyNonBending[ichamber] += ndigits;
767               totalchannelsNonBending += nchannels;
768               totaloccupancyNonBending += ndigits;
769             }
770       if (perDetEle) 
771       {
772         printf(">>> Detection element %4d has %5d channels in bending and %5d channels in nonbending \n",
773                detele, dEchannelsBending[ichamber][idetele], dEchannelsNonBending[ichamber][idetele] ); 
774       }
775     }
776     printf(">>> Chamber %2d has %6d channels in bending and %6d channels in nonbending \n",
777            ichamber+1,  cHchannelsBending[ichamber], cHchannelsNonBending[ichamber]);
778   }
779   printf(">>Spectrometer has  %7d channels in bending and %7d channels in nonbending \n",
780          totalchannelsBending, totalchannelsNonBending);
781   
782   // Output values
783   
784   for ( Int_t ichamber = 0; ichamber < 14; ++ichamber ) 
785   {
786     printf(">>> Chamber %2d  nChannels Bending %5d  nChannels NonBending %5d \n", 
787          ichamber+1, 
788          cHoccupancyBending[ichamber],
789          cHoccupancyNonBending[ichamber]);           
790     printf(">>> Chamber %2d  Occupancy Bending %5.2f %%  Occupancy NonBending %5.2f %% \n", 
791          ichamber+1, 
792          100.*((Float_t) cHoccupancyBending[ichamber])/((Float_t) cHchannelsBending[ichamber]),
793          100.*((Float_t) cHoccupancyNonBending[ichamber])/((Float_t) cHchannelsBending[ichamber])            );
794   
795     if ( perDetEle )
796     {
797       for(Int_t idetele=0; idetele<26; idetele++) 
798       {
799         Int_t detele = idetele + 100*(ichamber+1);
800         if ( AliMpDEManager::IsValidDetElemId(detele) ) 
801         {
802           printf(">>> DetEle %4d nChannels Bending %5d  nChannels NonBending %5d \n", 
803                idetele+100*(ichamber+1), 
804                dEoccupancyBending[ichamber][idetele],
805                dEoccupancyNonBending[ichamber][idetele]);  
806           printf(">>> DetEle %4d Occupancy Bending %5.2f %%  Occupancy NonBending %5.2f %% \n", 
807                idetele+100*(ichamber+1), 
808                100.*((Float_t) dEoccupancyBending[ichamber][idetele])/((Float_t) dEchannelsBending[ichamber][idetele]),
809                100.*((Float_t) dEoccupancyNonBending[ichamber][idetele])/((Float_t) dEchannelsBending[ichamber][idetele]));  
810         }
811       }
812     }
813   }
814
815   printf(">>> Muon Spectrometer  Occupancy Bending %5.2f %%  Occupancy NonBending %5.2f %% \n",  
816        100.*((Float_t) totaloccupancyBending)/((Float_t) totalchannelsBending),
817        100.*((Float_t) totaloccupancyNonBending)/((Float_t) totalchannelsNonBending)            );
818
819 }
820
821 //_____________________________________________________________________________
822 void 
823 AliMUONCheck::CheckRecTracks () const
824 {
825   /// Reads and dumps rec tracks objects
826   
827   AliWarning("Reimplement me ? or use AliMUONDumper simply ?");
828   
829   //  // waiting for mag field in CDB 
830   //  AliInfoStream() << "Loading field map...\n";
831   //  if (!AliTracker::GetFieldMap()) {
832   //    AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
833   //    AliTracker::SetFieldMap(field, kFALSE);
834   //  }
835   //  
836   //  // Loading data
837   //  fLoader->LoadTracks("READ");
838   //  
839   //  Int_t endOfLoop = fLastEvent+1;
840   //  if ( fLastEvent == -1 ) endOfLoop = fRunLoader->GetNumberOfEvents();
841   //
842   //  for (Int_t ievent=fFirstEvent; ievent<endOfLoop; ievent++) {
843   //    fRunLoader->GetEvent(ievent);
844   //    
845   //    fRecData->SetTreeAddress("RT");
846   //    fRecData->GetRecTracks();
847   //    TClonesArray* recTracks = fRecData->RecTracks();
848   //    
849   //    Int_t nrectracks = (Int_t) recTracks->GetEntriesFast(); //
850   //    printf(">>> Event %d, Number of Recconstructed tracks %d \n",ievent, nrectracks);
851   //
852   //    // Set the magnetic field for track extrapolations
853   //    AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
854   //
855   //    // Loop over tracks
856   //    for (Int_t iRecTracks = 0; iRecTracks <  nrectracks;  iRecTracks++) {
857   //      AliMUONTrack* recTrack = (AliMUONTrack*) recTracks->At(iRecTracks);
858   //      AliMUONTrackParam* trackParam = (AliMUONTrackParam*) (recTrack->GetTrackParamAtHit())->First();
859   //      AliMUONTrackExtrap::ExtrapToZ(trackParam,0.);
860   //      recTrack->Print("full");
861   //    }
862   //    fRecData->ResetRecTracks();
863   //  }   
864   //  fLoader->UnloadTracks();
865 }
866
867 //_____________________________________________________________________________
868 void AliMUONCheck::SetEventsToCheck(Int_t firstEvent, Int_t lastEvent)
869 {
870   /// Set first and last event number to check
871   
872   fFirstEvent = firstEvent;
873   fLastEvent = lastEvent;
874 }