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