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