]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONTriggerEfficiency.C
Updated for separation of simulation and reconstruction classes
[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 "AliMUONSimData.h"
45 #include "AliMUONRecData.h"
46 #include "AliMUONHit.h"
47 #include "AliMUONConstants.h"
48 #include "AliMUONDigit.h"
49 #include "AliMUONRawCluster.h"
50 #include "AliMUONGlobalTrigger.h"
51 #include "AliMUONLocalTrigger.h"
52 #include "AliMUONTrack.h"
53 #endif
54
55 // Upsilon(1S)
56
57
58 void MUONTriggerEfficiency (char filenameSim[10]="galice_sim.root", 
59                             char filenameRec[10]="galice.root",  
60                             Bool_t readFromRP = 0){
61  
62 // output file
63   char digitdat[100];
64   char currentfile[100]; 
65   sprintf(digitdat,"MUONTriggerEfficiency.out"); 
66   
67   FILE *fdat=fopen(digitdat,"w");          
68   
69   Int_t nevents,coincmuon,muonlpt,muonhpt;
70   Int_t CoincMuPlus,CoincMuMinus;
71   coincmuon=0;
72   muonlpt=0;  
73   muonhpt=0;
74  
75 // Initialise AliRoot
76    // Creating Run Loader and openning file containing Hits
77    AliRunLoader * RunLoaderSim = AliRunLoader::Open(filenameSim,"MUONFolderSim","READ");
78     
79    if (RunLoaderSim ==0x0) {
80        printf(">>> Error : Error Opening %s file \n",currentfile);
81        return;
82    }
83              
84    AliRunLoader * RunLoaderRec = AliRunLoader::Open(filenameRec,"MUONFolder","READ");
85     
86    if (RunLoaderRec ==0x0) {
87        printf(">>> Error : Error Opening %s file \n",currentfile);
88        return;
89    }
90              
91    nevents = RunLoaderSim->GetNumberOfEvents();          
92      
93  
94    AliLoader * MUONLoaderSim = RunLoaderSim->GetLoader("MUONLoader");
95    AliLoader * MUONLoaderRec = RunLoaderRec->GetLoader("MUONLoader");
96    
97    if (!readFromRP) {
98        cout << " reading from digits \n";
99        MUONLoaderSim->LoadDigits("READ");
100    } else {
101        cout << " reading from RecPoints \n";
102        MUONLoaderRec->LoadRecPoints("READ");
103    }
104    MUONLoaderSim->LoadHits("READ");
105    
106    // Creating MUON data containers
107    AliMUONSimData muondataSim(MUONLoaderSim,"MUON","MUON");
108    AliMUONRecData muondataRec(MUONLoaderRec,"MUON","MUON");
109
110    TClonesArray * globalTrigger;
111    AliMUONGlobalTrigger * gloTrg; 
112  
113  
114    for (Int_t ievent=0; ievent<nevents; ievent++) {    // event loop
115        CoincMuPlus=0;
116        CoincMuMinus=0;
117        RunLoaderSim->GetEvent(ievent);
118        RunLoaderRec->GetEvent(ievent);
119          
120      if (ievent%1000==0) printf("\t Event = %d\n",ievent);    
121
122 // Hits
123      muondataSim.SetTreeAddress("H");    
124         
125     Int_t itrack, ntracks, NbHits[2][4];
126     Int_t SumNbHits;
127     for (Int_t j=0; j<2; j++) {
128      for (Int_t jj=0; jj<4; jj++) {
129       NbHits[j][jj]=0;
130      }
131     } 
132     ntracks = (Int_t) muondataSim.GetNtracks();      
133     for (itrack=0; itrack<ntracks; itrack++) { // Track loop
134     
135       muondataSim.GetTrack(itrack); 
136
137       Int_t ihit, nhits;
138       nhits = (Int_t) muondataSim.Hits()->GetEntriesFast();   
139       AliMUONHit* mHit;
140       for(ihit=0; ihit<nhits; ihit++) {
141         mHit = static_cast<AliMUONHit*>(muondataSim.Hits()->At(ihit));
142         Int_t Nch        = mHit->Chamber(); 
143         Int_t hittrack   = mHit->Track();
144         Float_t IdPart     = mHit->Particle();
145
146         for (Int_t j=0;j<4;j++) {
147          Int_t kch=11+j;
148          if (hittrack==1 || hittrack==2) {
149           if (Nch==kch && IdPart==-13 && NbHits[0][j]==0) NbHits[0][j]++; 
150           if (Nch==kch && IdPart==13 && NbHits[1][j]==0) NbHits[1][j]++; 
151           }       
152         }
153        }
154        
155       muondataSim.ResetHits();
156       
157     } // end track loop     
158     
159 // 3/4 coincidence
160     SumNbHits=NbHits[0][0]+NbHits[0][1]+NbHits[0][2]+NbHits[0][3];
161     if (SumNbHits==3 || SumNbHits==4) CoincMuPlus=1;
162        
163     SumNbHits=NbHits[1][0]+NbHits[1][1]+NbHits[1][2]+NbHits[1][3];
164     if (SumNbHits==3 || SumNbHits==4) CoincMuMinus=1;
165     
166     if (CoincMuPlus==1 && CoincMuMinus==1) coincmuon++;         
167            
168 // Trigger
169     if (!readFromRP) {
170         muondataSim.SetTreeAddress("D,GLT"); 
171         muondataSim.GetTriggerD();
172         globalTrigger = muondataSim.GlobalTrigger();
173     } else {    
174         muondataRec.SetTreeAddress("RC,TC"); 
175         muondataRec.GetTrigger();
176         globalTrigger = muondataRec.GlobalTrigger();
177     }
178    
179     Int_t nglobals = (Int_t) globalTrigger->GetEntriesFast(); // should be 1
180
181     for (Int_t iglobal=0; iglobal<nglobals; iglobal++) { // Global Trigger
182     
183       gloTrg = static_cast<AliMUONGlobalTrigger*>(globalTrigger->At(iglobal));
184             
185        if (gloTrg->PairUnlikeLpt()>=1) muonlpt++;
186        if (gloTrg->PairUnlikeHpt()>=1) muonhpt++;
187                                
188     } // end of loop on Global Trigger         
189     
190     //if (!readFromRP) 
191       muondataSim.ResetTrigger();  
192     //else    
193       muondataRec.ResetTrigger();  
194
195   } // end loop on event  
196
197    MUONLoaderSim->UnloadHits();
198
199   if (!readFromRP) {
200       MUONLoaderSim->UnloadDigits();  
201   } else {    
202       MUONLoaderRec->UnloadRecPoints();
203   }  
204  
205   // calculate efficiency with as a ref. at least 3/4 planes fired
206   Float_t efficiencylpt,efficiencyhpt;
207   Double_t coincmu,lptmu,hptmu;  
208   Float_t error;  
209   coincmu=Double_t(coincmuon);
210   lptmu=Double_t(muonlpt); 
211   hptmu=Double_t(muonhpt); 
212
213
214   // output
215   fprintf(fdat,"\n"); 
216   fprintf(fdat," Number of events = %d \n",nevents);  
217   fprintf(fdat," Number of events with 3/4 coinc = %d \n",coincmuon);  
218   fprintf(fdat," Nomber of dimuons with 3/4 coinc Lpt cut = %d \n",muonlpt);  
219   fprintf(fdat," Number of dimuons with 3/4 coinc Hpt cut = %d \n",muonhpt);  
220   fprintf(fdat,"\n");
221   
222   efficiencylpt=lptmu/coincmu;  
223   error=efficiencylpt*TMath::Sqrt((lptmu+coincmu)/(lptmu*coincmu));  
224   fprintf(fdat," Efficiency Lpt cut = %4.4f +/- %4.4f\n",efficiencylpt,error); 
225  
226   efficiencyhpt=hptmu/coincmu; 
227   error=efficiencyhpt*TMath::Sqrt((hptmu+coincmu)/(hptmu*coincmu));          
228   fprintf(fdat," Efficiency Hpt cut = %4.4f +/- %4.4f\n",efficiencyhpt,error);
229       
230
231   fclose(fdat);  
232 }
233
234
235
236
237