]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONTriggerEfficiency.C
Changes to speed up creating of status and status map (Laurent)
[u/mrichter/AliRoot.git] / MUON / MUONTriggerEfficiency.C
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*  */
17
18 //
19 // Macro for checking trigger integrated efficiency for dimuons.
20 // The efficiency is calculated with respect to the 3/4 coincidence.
21 // Author: Fabien Guerin, LPC Clermont-Ferrand, Jan. 2006
22 //
23
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25 // ROOT includes
26 #include "TBranch.h"
27 #include "TClonesArray.h"
28 #include "TObject.h"
29 #include "TFile.h"
30 #include "TH1.h"
31 #include "TH2.h"
32 #include "TTree.h"
33 #include "TParticle.h"
34
35 // STEER includes
36 #include "AliRun.h"
37 #include "AliRunLoader.h"
38 #include "AliHeader.h"
39 #include "AliLoader.h"
40 #include "AliStack.h"
41
42 // MUON includes
43 #include "AliMUON.h"
44 #include "AliMUONHit.h"
45 #include "AliMUONConstants.h"
46 #include "AliMUONDigit.h"
47 #include "AliMUONGlobalTrigger.h"
48 #include "AliMUONTrack.h"
49
50 #include "AliMUONDataInterface.h"
51 #include "AliMUONMCDataInterface.h"
52 #include "AliMUONVHitStore.h"
53 #include "AliMUONVTriggerStore.h"
54
55 #endif
56
57 // Upsilon(1S)
58
59
60 void MUONTriggerEfficiency(const char* filenameSim="galice_sim.root", 
61                            const char* filenameRec="galice.root",  
62                            Bool_t readFromRP = 0)
63 {
64   
65   // output file
66   
67   AliMUONMCDataInterface diSim(filenameSim);
68   AliMUONDataInterface diRec(filenameRec);
69   
70   if (!diSim.IsValid())
71   {
72     cerr << "Cannot access " << filenameSim << endl;
73     return;
74   }
75   
76   if (!diRec.IsValid())
77   {
78     cerr << "Cannot access " << filenameRec << endl;
79     return;
80   }
81   
82   FILE* fdat = fopen("MUONTriggerEfficiency.out","w");          
83   if (!fdat)
84   {
85     cerr << "Cannot create output file" << endl;
86     return;
87   }
88   
89   Int_t coincmuon,muonlpt,muonhpt;
90   Int_t CoincMuPlus,CoincMuMinus;
91   coincmuon=0;
92   muonlpt=0;  
93   muonhpt=0;
94   
95   Int_t nevents = diSim.NumberOfEvents();          
96   
97   for (Int_t ievent=0; ievent<nevents; ++ievent) 
98   {   
99     CoincMuPlus=0;
100     CoincMuMinus=0;
101     
102     if (ievent%1000==0) printf("\t Event = %d\n",ievent);    
103     
104     // Hits
105     
106     Int_t NbHits[2][4];
107     for (Int_t j=0; j<2; j++) 
108     {
109       for (Int_t jj=0; jj<4; jj++) 
110       {
111         NbHits[j][jj]=0;
112       }
113     } 
114     
115     Int_t ntracks = (Int_t) diSim.NumberOfTracks(ievent);
116     
117     for ( Int_t itrack=0; itrack<ntracks; ++itrack ) 
118     {
119       AliMUONVHitStore* hitStore = diSim.HitStore(ievent,itrack);      
120       AliMUONHit* mHit;
121       TIter next(hitStore->CreateIterator());
122       
123       while ( ( mHit = static_cast<AliMUONHit*>(next()) ) )
124       {
125         Int_t Nch = mHit->Chamber(); 
126         Int_t hittrack = mHit->Track();
127         Float_t IdPart = mHit->Particle();
128         
129         for (Int_t j=0;j<4;j++) 
130         {
131           Int_t kch=11+j;
132           if (hittrack==1 || hittrack==2) 
133           {
134             if (Nch==kch && IdPart==-13 && NbHits[0][j]==0) NbHits[0][j]++; 
135             if (Nch==kch && IdPart==13 && NbHits[1][j]==0) NbHits[1][j]++; 
136           }       
137         }
138       }
139     } // end track loop     
140     
141     // 3/4 coincidence
142     Int_t SumNbHits=NbHits[0][0]+NbHits[0][1]+NbHits[0][2]+NbHits[0][3];
143     if (SumNbHits==3 || SumNbHits==4) CoincMuPlus=1;
144     
145     SumNbHits=NbHits[1][0]+NbHits[1][1]+NbHits[1][2]+NbHits[1][3];
146     if (SumNbHits==3 || SumNbHits==4) CoincMuMinus=1;
147     
148     if (CoincMuPlus==1 && CoincMuMinus==1) coincmuon++;         
149           
150     TString tree("D");
151     if ( readFromRP ) tree = "R";
152     
153     AliMUONVTriggerStore* triggerStore = diRec.TriggerStore(ievent,tree.Data());
154
155     AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
156     
157     if (gloTrg->PairUnlikeLpt()>=1) muonlpt++;
158     if (gloTrg->PairUnlikeHpt()>=1) muonhpt++;
159
160   } // end loop on event  
161  
162   // calculate efficiency with as a ref. at least 3/4 planes fired
163   Float_t efficiencylpt,efficiencyhpt;
164   Double_t coincmu,lptmu,hptmu;  
165   Float_t error;  
166   coincmu=Double_t(coincmuon);
167   lptmu=Double_t(muonlpt); 
168   hptmu=Double_t(muonhpt); 
169
170   // output
171   fprintf(fdat,"\n"); 
172   fprintf(fdat," Number of events = %d \n",nevents);  
173   fprintf(fdat," Number of events with 3/4 coinc = %d \n",coincmuon);  
174   fprintf(fdat," Nomber of dimuons with 3/4 coinc Lpt cut = %d \n",muonlpt);  
175   fprintf(fdat," Number of dimuons with 3/4 coinc Hpt cut = %d \n",muonhpt);  
176   fprintf(fdat,"\n");
177   
178   efficiencylpt=lptmu/coincmu;  
179   error=efficiencylpt*TMath::Sqrt((lptmu+coincmu)/(lptmu*coincmu));  
180   fprintf(fdat," Efficiency Lpt cut = %4.4f +/- %4.4f\n",efficiencylpt,error); 
181  
182   efficiencyhpt=hptmu/coincmu; 
183   error=efficiencyhpt*TMath::Sqrt((hptmu+coincmu)/(hptmu*coincmu));          
184   fprintf(fdat," Efficiency Hpt cut = %4.4f +/- %4.4f\n",efficiencyhpt,error);
185       
186
187   fclose(fdat);  
188 }
189
190
191
192
193