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