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