Updated list of classes
[u/mrichter/AliRoot.git] / MUON / MUONefficiency.C
CommitLineData
d949b15e 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
53399039 18// Macro (upgraded version of MUONmassPlot_ESD.C, better handling of Jpsi) to make :
d949b15e 19// 1) Ntuple (Ktuple) containing Upsilon kinematics variables (from kinematics.root files)
20// 2) Ntuple (ESDtuple) containing Upsilon kinematics variables from reconstruction and
53399039 21// combinations of 2 muons with opposite charges (ESDtupleBck will be used later)
d949b15e 22// 3) Some QA histograms
23// Ntuple are stored in the file MUONefficiency.root and ESD tree and QA histograms in AliESDs.root
24
53399039 25// Christophe Suire, IPN Orsay
26
27
28
d949b15e 29// Arguments:
30// FirstEvent (default 0)
53399039 31// LastEvent (default 1.e6)
d949b15e 32// ResType (default 553)
53399039 33// 553 for Upsilon, 443 for J/Psi
d949b15e 34// Chi2Cut (default 100)
35// to keep only tracks with chi2 per d.o.f. < Chi2Cut
d949b15e 36
d949b15e 37
d949b15e 38
39#if !defined(__CINT__) || defined(__MAKECINT__)
40// ROOT includes
41#include "TTree.h"
53399039 42#include "TNtuple.h"
d949b15e 43#include "TBranch.h"
44#include "TClonesArray.h"
45#include "TLorentzVector.h"
46#include "TFile.h"
47#include "TH1.h"
48#include "TH2.h"
49#include "TParticle.h"
50#include "TTree.h"
51#include "TString.h"
52#include <Riostream.h>
8cde4af5 53#include <TGeoManager.h>
d949b15e 54
55// STEER includes
56#include "AliRun.h"
57#include "AliRunLoader.h"
58#include "AliHeader.h"
59#include "AliLoader.h"
60#include "AliStack.h"
3f6289e9 61#include "AliMagFMaps.h"
d949b15e 62#include "AliESD.h"
3f6289e9 63#include "AliTracker.h"
d949b15e 64
65// MUON includes
cfc3191e 66#include "AliMUONTrackParam.h"
37827b29 67#include "AliMUONTrackExtrap.h"
d949b15e 68#include "AliESDMuonTrack.h"
69#endif
70
8cde4af5 71// Arguments:
72// ExtrapToVertex (default -1)
73// <0: no extrapolation;
74// =0: extrapolation to (0,0,0);
75// >0: extrapolation to ESDVertex if available, else to (0,0,0)
76// ResType (default 553)
77// 553 for Upsilon, anything else for J/Psi
d949b15e 78
8cde4af5 79Bool_t MUONefficiency( Int_t ExtrapToVertex = -1, Int_t ResType = 553, Int_t FirstEvent = 0, Int_t LastEvent = 1000000,
80 char* geoFilename = "geometry.root", char* esdFileName = "AliESDs.root", char* filename = "galice.root")
d949b15e 81{ // MUONefficiency starts
d949b15e 82
53399039 83 Double_t MUON_MASS = 0.105658369;
84 Double_t UPSILON_MASS = 9.4603 ;
85 Double_t JPSI_MASS = 3.097;
86
87 // Upper and lower bound for counting entries in the mass peak
88 // +/- 300 MeV/c^2 in this case.
89 Float_t countingRange = 0.300 ;
90
91 Float_t massResonance = 5.;
92 Float_t invMassMinInPeak = 0. ;
93 Float_t invMassMaxInPeak = 0. ;
94
95 Float_t nBinsPerGev = 40 ;
96 Float_t invMassMin = 0; Float_t invMassMax = 20;
97 Float_t ptMinResonance = 0 ; Float_t ptMaxResonance = 20 ; Int_t ptBinsResonance = 100;
98
99 if (ResType==443) {
100 massResonance = JPSI_MASS ;
101 invMassMinInPeak = JPSI_MASS - countingRange ; invMassMaxInPeak = JPSI_MASS + countingRange ;
102 //limits for histograms
103 invMassMin = 0 ; invMassMax = 6.;
104 ptMinResonance = 0 ; ptMaxResonance = 20 ; ptBinsResonance = 100;
105 }
106 if (ResType==553) {
107 massResonance = UPSILON_MASS;
108 invMassMinInPeak = UPSILON_MASS - countingRange ; invMassMaxInPeak = UPSILON_MASS + countingRange;
109 //limits for histograms
110 invMassMin = 0 ; invMassMax = 12.;
111 ptMinResonance = 0 ; ptMaxResonance = 20 ; ptBinsResonance = 100;
112 }
113
114 // Single Tracks muon cuts
115 Float_t Chi2Cut = 100.;
116 Float_t PtCutMin = 0. ;
117 Float_t PtCutMax = 10000. ;
118
119
120 // Limits for histograms
121 Float_t ptMinMuon = 0. ; Float_t ptMaxMuon = 20.; Int_t ptBinsMuon = 100 ;
122 Float_t pMinMuon = 0. ; Float_t pMaxMuon = 200.; Int_t pBinsMuon = 100 ;
d949b15e 123
53399039 124
d949b15e 125 //Reset ROOT and connect tree file
126 gROOT->Reset();
127
128 // Printing Level
129 Int_t PRINTLEVEL = 0 ;
d949b15e 130
131 //for kinematic, i.e. reference tracks
132 TNtuple *Ktuple = new TNtuple("Ktuple","Kinematics NTuple","ev:npart:id:idmo:idgdmo:p:pt:y:theta:pseudorap:vx:vy:vz");
133
53399039 134 //for reconstruction
135 TH1F *hPtMuon = new TH1F("hPtMuon", "Muon Pt (GeV/c)", ptBinsMuon, ptMinMuon, ptMaxMuon);
136 TH1F *hPtMuonPlus = new TH1F("hPtMuonPlus", "Muon+ Pt (GeV/c)", ptBinsMuon, ptMinMuon, ptMaxMuon);
137 TH1F *hPtMuonMinus = new TH1F("hPtMuonMinus", "Muon- Pt (GeV/c)", ptBinsMuon, ptMinMuon, ptMaxMuon);
138 TH1F *hPMuon = new TH1F("hPMuon", "Muon P (GeV/c)", pBinsMuon, pMinMuon, pMaxMuon);
139
140 TH1F *hInvMassAll;
141 TH1F *hInvMassBg;
142 TH2F *hInvMassAll_vs_Pt;
143 TH2F *hInvMassBgk_vs_Pt;
d949b15e 144 TH1F *hInvMassRes;
d949b15e 145
53399039 146
147 hInvMassAll = new TH1F("hInvMassAll", "Mu+Mu- invariant mass (GeV/c2)", (Int_t) (nBinsPerGev*(invMassMax - invMassMin)), invMassMin, invMassMax);
148 hInvMassBg = new TH1F("hInvMassBg", "Mu+Mu- invariant mass BG(GeV/c2)", (Int_t) (nBinsPerGev*(invMassMax- invMassMin)), invMassMin, invMassMax);
149 hInvMassAll_vs_Pt = new TH2F("hInvMassAll_vs_Pt","hInvMassAll_vs_Pt",(Int_t) (nBinsPerGev*(invMassMax- invMassMin)), invMassMin, invMassMax,ptBinsResonance,ptMinResonance,ptMaxResonance);
150 hInvMassBgk_vs_Pt = new TH2F("hInvMassBgk_vs_Pt","hInvMassBgk_vs_Pt",(Int_t) (nBinsPerGev*(invMassMax- invMassMin)), invMassMin, invMassMax,ptBinsResonance,ptMinResonance,ptMaxResonance);
151
152 hInvMassRes = new TH1F("hInvMassRes", "Mu+Mu- invariant mass (GeV/c2) around Resonance",(Int_t) (nBinsPerGev*3*countingRange*2),massResonance-3*countingRange,massResonance+3*countingRange);
153
cfc3191e 154 TH1F *hPrimaryVertex = new TH1F("hPrimaryVertex","SPD reconstructed Z vertex",150,-15,15);
53399039 155 TH1F *hChi2PerDof = new TH1F("hChi2PerDof", "Muon track chi2/d.o.f.", 100, 0., 20.);
d949b15e 156 TH1F *hNumberOfTrack = new TH1F("hNumberOfTrack","nb of track /evt ",20,-0.5,19.5);
157 TH1F *hRapMuon = new TH1F("hRapMuon"," Muon Rapidity",50,-4.5,-2);
158 TH1F *hRapResonance = new TH1F("hRapResonance"," Resonance Rapidity",50,-4.5,-2);
159 TH1F *hPtResonance = new TH1F("hPtResonance", "Resonance Pt (GeV/c)", 100, 0., 20.);
160 TH2F *hThetaPhiPlus = new TH2F("hThetaPhiPlus", "Theta vs Phi +", 760, -190., 190., 400, 160., 180.);
161 TH2F *hThetaPhiMinus = new TH2F("hThetaPhiMinus", "Theta vs Phi -", 760, -190., 190., 400, 160., 180.);
53399039 162
d949b15e 163 TNtuple *ESDtuple = new TNtuple("ESDtuple","Reconstructed Mu+Mu- pairs and Upsilon","ev:tw:pt:y:theta:minv:pt1:y1:theta1:q1:trig1:pt2:y2:theta2:q2:trig2");
164 TNtuple *ESDtupleBck = new TNtuple("ESDtupleBck","Reconstructed Mu+Mu- pairs for Background","ev:pt:y:theta:minv:pt1:y1:theta1:pt2:y2:theta2");
165
166
53399039 167 // Variables
d949b15e 168 Int_t EventInMass = 0;
53399039 169 Int_t EventInMassMatch = 0;
170 Int_t NbTrigger = 0;
171 Int_t ptTrig = 0;
d949b15e 172
cfc3191e 173 Double_t fXVertex=0;
174 Double_t fYVertex=0;
175 Double_t fZVertex=0;
176
d949b15e 177 Double_t thetaX, thetaY, pYZ;
178 Double_t fPxRec1, fPyRec1, fPzRec1, fE1;
179 Double_t fPxRec2, fPyRec2, fPzRec2, fE2;
180 Int_t fCharge1, fCharge2;
181
53399039 182 Int_t ntrackhits, nevents;
183 Int_t nprocessedevents = 0 ;
d949b15e 184 Double_t fitfmin;
185
186 TLorentzVector fV1, fV2, fVtot;
187
8cde4af5 188 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
189 if (!gGeoManager) {
190 TGeoManager::Import(geoFilename);
191 if (!gGeoManager) {
192 Error("MUONmass_ESD", "getting geometry from file %s failed", filename);
193 return kFALSE;
194 }
195 }
196
3f6289e9 197 // set mag field
198 // waiting for mag field in CDB
199 printf("Loading field map...\n");
b97b210c 200 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
3f6289e9 201 AliTracker::SetFieldMap(field, kFALSE);
d949b15e 202
203 // open run loader and load gAlice, kinematics and header
204 AliRunLoader* runLoader = AliRunLoader::Open(filename);
205 if (!runLoader) {
206 Error("MUONefficiency", "getting run loader from file %s failed", filename);
207 return kFALSE;
208 }
209
210 runLoader->LoadgAlice();
211 gAlice = runLoader->GetAliRun();
212 if (!gAlice) {
213 Error("MUONefficiency", "no galice object found");
214 return kFALSE;
215 }
216
217 // open the ESD file
218 TFile* esdFile = TFile::Open(esdFileName);
219 if (!esdFile || !esdFile->IsOpen()) {
220 Error("MUONefficiency", "opening ESD file %s failed", esdFileName);
221 return kFALSE;
222 }
223
224 AliESD* esd = new AliESD();
225 TTree* tree = (TTree*) esdFile->Get("esdTree");
226 if (!tree) {
227 Error("CheckESD", "no ESD tree found");
228 return kFALSE;
229 }
230 tree->SetBranchAddress("ESD", &esd);
231
232 runLoader->LoadHeader();
233 nevents = runLoader->GetNumberOfEvents();
cfc3191e 234 AliMUONTrackParam trackParam;
235
d949b15e 236 // to access the particle Stack
237 runLoader->LoadKinematics("READ");
238
53399039 239 Int_t numberOfGeneratedResonances = 0 ;
240
d949b15e 241 TParticle *particle;
53399039 242
d949b15e 243 Int_t track1Trigger = 0 ;
244 Float_t track1TriggerChi2 = 0 ;
d949b15e 245 Int_t track2Trigger = 0 ;
246 Float_t track2TriggerChi2 = 0 ;
247
248
249 // Loop over events
250 for (Int_t iEvent = FirstEvent; iEvent <= TMath::Min(LastEvent, nevents - 1); iEvent++) { // Start event loop
251
252 if (iEvent%1000 == 0 )
253 printf("\n Nb of events analysed: %d \n",iEvent);
254
255 // get current event
256 runLoader->GetEvent(iEvent);
53399039 257 nprocessedevents++;
258
d949b15e 259 // get the stack and fill the kine tree
260 AliStack *theStack = runLoader->Stack();
261 if (PRINTLEVEL > 0) theStack->DumpPStack ();
262
263 Int_t nparticles = (Int_t)runLoader->TreeK()->GetEntries();
264 Int_t nprimarypart = theStack->GetNprimary();
265 Int_t ntracks = theStack->GetNtrack();
53399039 266
d949b15e 267 if (PRINTLEVEL || (iEvent%100==0)) printf("\n >>> Event %d \n",iEvent);
cfc3191e 268 if (PRINTLEVEL) cout << nprimarypart << " Particles generated (total is " << ntracks << ")"<< endl ;
d949b15e 269
270 for(Int_t iparticle=0; iparticle<nparticles; iparticle++) { // Start loop over particles
271 particle = theStack->Particle(iparticle);
272
273 Int_t muId = particle->GetPdgCode();
274 Int_t muM = particle->GetFirstMother();
275 Int_t muGM = 0;
276 Float_t muP = particle->P();
277 Float_t muPt = TMath::Sqrt(particle->Px()*particle->Px()+particle->Py()*particle->Py());
278 Float_t muY = 0.5*TMath::Log((particle->Energy()+particle->Pz()+1.e-13)/(particle->Energy()-particle->Pz()+1.e-13));
279 if (muM >= 0) {
d949b15e 280 TParticle *theMum = theStack->Particle(muM);
281 muM = theMum->GetPdgCode();
d949b15e 282 muGM = theMum->GetFirstMother() ;
283 if (muGM >= 0){
284 TParticle *grandMa = theStack->Particle(muGM);
285 muGM = grandMa->GetPdgCode();
286 }
287 else muGM=0;
288 }
289 else muM=0;
53399039 290
291 if (muId==ResType) numberOfGeneratedResonances++;
292
293
d949b15e 294 Float_t muT = particle->Theta()*180/TMath::Pi();
295 Float_t muE = particle->Eta();
296
297 Float_t muVx = particle->Vx();
298 Float_t muVy = particle->Vy();
299 Float_t muVz = particle->Vz();
300
301 // If a write error occurs, the number of bytes returned is -1.
302 // If no data are written, because e.g. the branch is disabled,
303 // the number of bytes returned is 0.
304 Int_t errCode = Ktuple->Fill(iEvent,nparticles,muId,muM,muGM,muP,muPt,muY,muT,muE,muVx,muVy,muVz);
305 if (PRINTLEVEL || errCode < 1) printf("iEvent %d,nparticles %d,muId %d,muM %d,muGM %d,muP %.2f,muPt %.2f,muY %.2f,muT %.2f,muE %.2f,muVx %.2f,muVy %.2f,muVz %.2f \n", iEvent,nparticles,muId,muM,muGM,muP,muPt,muY,muT,muE,muVx,muVy,muVz);
306
307 } // End loop over particles
308
309
310
311 // get the event summary data
312 tree->GetEvent(iEvent);
313 if (!esd) {
314 Error("CheckESD", "no ESD object found for event %d", iEvent);
315 return kFALSE;
316 }
cfc3191e 317
318 // get the SPD reconstructed vertex (vertexer) and fill the histogram
43939bd8 319 AliESDVertex* Vertex = (AliESDVertex*) esd->GetVertex();
320 if (Vertex->GetNContributors()) {
cfc3191e 321 fZVertex = Vertex->GetZv();
322 fYVertex = Vertex->GetYv();
323 fXVertex = Vertex->GetXv();
324 }
325 hPrimaryVertex->Fill(fZVertex);
326
f57d136a 327 Int_t triggerWord = esd->GetTriggerMask();
d949b15e 328 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
329
330 if (PRINTLEVEL > 0){
331 printf("\n Nb of events analysed: %d \n",iEvent);
332 cout << " number of tracks: " << nTracks <<endl;
333 }
334
37827b29 335 // set the magnetic field for track extrapolations
336 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
d949b15e 337 // loop over all reconstructed tracks (also first track of combination)
338 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
339
8cde4af5 340 AliESDMuonTrack* muonTrack = new AliESDMuonTrack(*(esd->GetMuonTrack(iTrack)));
d949b15e 341
8cde4af5 342 // extrapolate to vertex if required and available
343 if (ExtrapToVertex > 0 && Vertex->GetNContributors()) {
344 trackParam.GetParamFrom(*muonTrack);
37827b29 345 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, fXVertex, fYVertex, fZVertex);
8cde4af5 346 trackParam.SetParamFor(*muonTrack); // put the new parameters in this copy of AliESDMuonTrack
347 } else if ((ExtrapToVertex > 0 && !Vertex->GetNContributors()) || ExtrapToVertex == 0){
348 trackParam.GetParamFrom(*muonTrack);
349 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, 0., 0., 0.);
350 trackParam.SetParamFor(*muonTrack); // put the new parameters in this copy of AliESDMuonTrack
d949b15e 351 }
352
353 // Trigger
354 if (PRINTLEVEL > 5) cout << "MatchTrigger " << muonTrack->GetMatchTrigger() << " and Chi2 of matching tracks " << track1TriggerChi2 << endl ;
355 track1Trigger = muonTrack->GetMatchTrigger();
356 if (track1Trigger)
357 track1TriggerChi2 = muonTrack->GetChi2MatchTrigger();
358 else
359 track1TriggerChi2 = 0. ;
360
361 thetaX = muonTrack->GetThetaX();
362 thetaY = muonTrack->GetThetaY();
363
364 pYZ = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
365 fPzRec1 = - pYZ / TMath::Sqrt(1.0 + TMath::Tan(thetaY)*TMath::Tan(thetaY));
366 fPxRec1 = fPzRec1 * TMath::Tan(thetaX);
367 fPyRec1 = fPzRec1 * TMath::Tan(thetaY);
368 fCharge1 = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
369
53399039 370 fE1 = TMath::Sqrt(MUON_MASS * MUON_MASS + fPxRec1 * fPxRec1 + fPyRec1 * fPyRec1 + fPzRec1 * fPzRec1);
d949b15e 371 fV1.SetPxPyPzE(fPxRec1, fPyRec1, fPzRec1, fE1);
372
373 ntrackhits = muonTrack->GetNHit();
374 fitfmin = muonTrack->GetChi2();
375
376 // transverse momentum
377 Float_t pt1 = fV1.Pt();
378
379 // total momentum
380 Float_t p1 = fV1.P();
381
382 // Rapidity
383 Float_t rapMuon1 = fV1.Rapidity();
384
385 // chi2 per d.o.f.
386
387 Float_t ch1 = fitfmin / (2.0 * ntrackhits - 5);
388 if (PRINTLEVEL > 5 ) printf(" px %f py %f pz %f pt %f NHits %d Norm.chi2 %f charge %d\n",fPxRec1, fPyRec1, fPzRec1, pt1, ntrackhits, ch1, fCharge1);
389
390
391 if ((ch1 < Chi2Cut) && (pt1 > PtCutMin) && (pt1 < PtCutMax)) { // condition for good track (Chi2Cut and PtCut)
392 if (PRINTLEVEL > 8) cout << "inside pt and chi2 cuts " << endl ;
393
394 // fill histos hPtMuon and hChi2PerDof
395 hPtMuon->Fill(pt1);
396 hPMuon->Fill(p1);
397 hChi2PerDof->Fill(ch1);
398 hRapMuon->Fill(rapMuon1);
399
400 if (fCharge1 > 0) {
401 hPtMuonPlus->Fill(pt1);
402 hThetaPhiPlus->Fill(TMath::ATan2(fPyRec1,fPxRec1)*180./TMath::Pi(),TMath::ATan2(pt1,fPzRec1)*180./3.1415);
403 } else {
404 hPtMuonMinus->Fill(pt1);
405 hThetaPhiMinus->Fill(TMath::ATan2(fPyRec1,fPxRec1)*180./TMath::Pi(),TMath::ATan2(pt1,fPzRec1)*180./3.1415);
406 }
407
408 // loop over second track of combination
409 for (Int_t iTrack2 = iTrack + 1; iTrack2 < nTracks; iTrack2++) {
410
8cde4af5 411 AliESDMuonTrack* muonTrack2 = new AliESDMuonTrack(*(esd->GetMuonTrack(iTrack2)));
cfc3191e 412
8cde4af5 413 // extrapolate to vertex if required and available
414 if (ExtrapToVertex > 0 && Vertex->GetNContributors()) {
415 trackParam.GetParamFrom(*muonTrack2);
37827b29 416 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, fXVertex, fYVertex, fZVertex);
8cde4af5 417 trackParam.SetParamFor(*muonTrack2); // put the new parameters in this copy of AliESDMuonTrack
418 } else if ((ExtrapToVertex > 0 && !Vertex->GetNContributors()) || ExtrapToVertex == 0){
419 trackParam.GetParamFrom(*muonTrack2);
420 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, 0., 0., 0.);
421 trackParam.SetParamFor(*muonTrack2); // put the new parameters in this copy of AliESDMuonTrack
d949b15e 422 }
423
8cde4af5 424 track2Trigger = muonTrack2->GetMatchTrigger();
d949b15e 425 if (track2Trigger)
8cde4af5 426 track2TriggerChi2 = muonTrack2->GetChi2MatchTrigger();
d949b15e 427 else
428 track2TriggerChi2 = 0. ;
429
8cde4af5 430 thetaX = muonTrack2->GetThetaX();
431 thetaY = muonTrack2->GetThetaY();
d949b15e 432
8cde4af5 433 pYZ = 1./TMath::Abs(muonTrack2->GetInverseBendingMomentum());
d949b15e 434 fPzRec2 = - pYZ / TMath::Sqrt(1.0 + TMath::Tan(thetaY)*TMath::Tan(thetaY));
435 fPxRec2 = fPzRec2 * TMath::Tan(thetaX);
436 fPyRec2 = fPzRec2 * TMath::Tan(thetaY);
8cde4af5 437 fCharge2 = Int_t(TMath::Sign(1.,muonTrack2->GetInverseBendingMomentum()));
d949b15e 438
53399039 439 fE2 = TMath::Sqrt(MUON_MASS * MUON_MASS + fPxRec2 * fPxRec2 + fPyRec2 * fPyRec2 + fPzRec2 * fPzRec2);
d949b15e 440 fV2.SetPxPyPzE(fPxRec2, fPyRec2, fPzRec2, fE2);
441
8cde4af5 442 ntrackhits = muonTrack2->GetNHit();
443 fitfmin = muonTrack2->GetChi2();
d949b15e 444
445 // transverse momentum
446 Float_t pt2 = fV2.Pt();
447
448 // chi2 per d.o.f.
449 Float_t ch2 = fitfmin / (2.0 * ntrackhits - 5);
450
d949b15e 451
cfc3191e 452 // condition for good track (Chi2Cut and PtCut)
453 if ((ch2 < Chi2Cut) && (pt2 > PtCutMin) && (pt2 < PtCutMax)) {
d949b15e 454
cfc3191e 455 // condition for opposite charges
456 if ((fCharge1 * fCharge2) == -1) {
457
458 if (PRINTLEVEL > 8) cout << "---------> Now filling the Ntuple " << endl ;
459
460 // invariant mass
461 fVtot = fV1 + fV2;
462 Float_t invMass = fVtot.M();
463
464 if (fCharge1 < 0){ //mu_minus is index 1 in the ntuple
465 Float_t ESDFill[16] = {iEvent,triggerWord,fVtot.Pt(),fVtot.Rapidity(),fVtot.Theta()/TMath::Pi()*180,invMass,fV1.Pt(),fV1.Rapidity(),fV1.Theta()/TMath::Pi()*180,fCharge1,track1TriggerChi2,fV2.Pt(),fV2.Rapidity(),fV2.Theta()/TMath::Pi()*180,fCharge2,track2TriggerChi2};
466 ESDtuple->Fill(ESDFill);
467 }
468 else{
469 Float_t ESDFill[16] = {iEvent,triggerWord,fVtot.Pt(),fVtot.Rapidity(),fVtot.Theta()/TMath::Pi()*180,invMass,fV2.Pt(),fV2.Rapidity(),fV2.Theta()/TMath::Pi()*180,fCharge2,track2TriggerChi2,fV1.Pt(),fV1.Rapidity(),fV1.Theta()/TMath::Pi()*180,fCharge1,track1TriggerChi2};
470 ESDtuple->Fill(ESDFill);
471 }
472
473 // fill histos hInvMassAll and hInvMassRes
474 hInvMassAll->Fill(invMass);
475 hInvMassRes->Fill(invMass);
476 hInvMassAll_vs_Pt->Fill(invMass,fVtot.Pt());
477
478 //trigger info
479 if (ResType == 553)
8d4fefab 480 ptTrig = 0x20;// mask for Hpt unlike sign pair
cfc3191e 481 else if (ResType == 443)
8d4fefab 482 ptTrig = 0x10;// mask for Lpt unlike sign pair
cfc3191e 483
484
485 if (esd->GetTriggerMask() & ptTrig) NbTrigger++;
486
487 if (invMass > invMassMinInPeak && invMass < invMassMaxInPeak) {
488 EventInMass++;
489 hRapResonance->Fill(fVtot.Rapidity());
490 hPtResonance->Fill(fVtot.Pt());
53399039 491
cfc3191e 492 // match with trigger
8cde4af5 493 if (muonTrack2->GetMatchTrigger() && (esd->GetTriggerMask() & ptTrig)) EventInMassMatch++;
53399039 494
cfc3191e 495 }
496
497 } // if (fCharge1 * fCharge2) == -1)
498 } // if ((ch2 < Chi2Cut) && (pt2 > PtCutMin) && (pt2 < PtCutMax))
8cde4af5 499 delete muonTrack2;
d949b15e 500 } // for (Int_t iTrack2 = iTrack + 1; iTrack2 < iTrack; iTrack2++)
501 } // if (ch1 < Chi2Cut) && (pt1 > PtCutMin)&& (pt1 < PtCutMax) )
8cde4af5 502 delete muonTrack;
d949b15e 503 } // for (Int_t iTrack = 0; iTrack < nrectracks; iTrack++)
504
505 hNumberOfTrack->Fill(nTracks);
506 // esdFile->Delete();
507
508 } // End of event loop
509
510
511 // Loop over events for bg event
512
513 Double_t thetaPlus, phiPlus;
514 Double_t thetaMinus, phiMinus;
515 Float_t PtMinus, PtPlus;
516
517 for (Int_t iEvent = 0; iEvent < hInvMassAll->Integral(); iEvent++) { // Loop over events for bg event
53399039 518 // according to Christian a 3d phi-theta-pt random pick would take better care
d949b15e 519 // of all correlations
520
521 hThetaPhiPlus->GetRandom2(phiPlus, thetaPlus);
522 hThetaPhiMinus->GetRandom2(phiMinus,thetaMinus);
523 PtPlus = hPtMuonPlus->GetRandom();
524 PtMinus = hPtMuonMinus->GetRandom();
525
526 fPxRec1 = PtPlus * TMath::Cos(TMath::Pi()/180.*phiPlus);
527 fPyRec1 = PtPlus * TMath::Sin(TMath::Pi()/180.*phiPlus);
528 fPzRec1 = PtPlus / TMath::Tan(TMath::Pi()/180.*thetaPlus);
529
53399039 530 fE1 = TMath::Sqrt(MUON_MASS * MUON_MASS + fPxRec1 * fPxRec1 + fPyRec1 * fPyRec1 + fPzRec1 * fPzRec1);
d949b15e 531 fV1.SetPxPyPzE(fPxRec1, fPyRec1, fPzRec1, fE1);
532
533 fPxRec2 = PtMinus * TMath::Cos(TMath::Pi()/180.*phiMinus);
534 fPyRec2 = PtMinus * TMath::Sin(TMath::Pi()/180.*phiMinus);
535 fPzRec2 = PtMinus / TMath::Tan(TMath::Pi()/180.*thetaMinus);
536
53399039 537 fE2 = TMath::Sqrt(MUON_MASS * MUON_MASS + fPxRec2 * fPxRec2 + fPyRec2 * fPyRec2 + fPzRec2 * fPzRec2);
d949b15e 538 fV2.SetPxPyPzE(fPxRec2, fPyRec2, fPzRec2, fE2);
539
540 // invariant mass
541 fVtot = fV1 + fV2;
542
543 // fill histos hInvMassAll and hInvMassRes
544 hInvMassBg->Fill(fVtot.M());
545 hInvMassBgk_vs_Pt->Fill( fVtot.M(), fVtot.Pt() );
546
547 // Ntuple for background... more convenient
548 ESDtupleBck->Fill(iEvent,fVtot.Pt(),fVtot.Rapidity(),fVtot.Theta()/TMath::Pi()*180,fVtot.M(),fV2.Pt(),fV2.Rapidity(),fV2.Theta()/TMath::Pi()*180,fV1.Pt(),fV1.Rapidity(),fV1.Theta()/TMath::Pi()*180);
549
550 } // End loop over events for background
551
552
553 // File for histograms and histogram booking
554 TString outfilename = "MUONefficiency.root";
53399039 555 TFile *ntupleFile = new TFile(outfilename.Data(), "RECREATE");
d949b15e 556
557 Ktuple->Write();
558 ESDtuple->Write();
53399039 559 ESDtupleBck->Write();
560
561 ntupleFile->Close();
d949b15e 562
53399039 563 TFile *histoFile = new TFile("MUONhistos.root", "RECREATE");
cfc3191e 564 hPrimaryVertex->Write();
53399039 565 hPtMuon->Write();
566 hPtMuonPlus->Write();
567 hPtMuonMinus->Write();
568 hPMuon->Write();
569 hChi2PerDof->Write();
570 hInvMassAll->Write();
571 hInvMassBg->Write();
572 hInvMassAll_vs_Pt ->Write();
573 hInvMassBgk_vs_Pt->Write();
574 hInvMassRes->Write();
575 hNumberOfTrack->Write();
576 hRapMuon ->Write();
577 hRapResonance ->Write();
578 hPtResonance ->Write();
579 hThetaPhiPlus ->Write();
580 hThetaPhiMinus ->Write();
d949b15e 581 histoFile->Close();
53399039 582
583 cout << "" << endl ;
584 cout << "*************************************************" << endl;
585
586 cout << "MUONefficiency : " << nprocessedevents << " events processed" << endl;
587 if (ResType==443)
588 cout << "Number of generated J/Psi (443) : " << numberOfGeneratedResonances << endl ;
589 if (ResType==553)
590 cout << "Number of generated Upsilon (553) :" << numberOfGeneratedResonances << endl ;
591 cout << "Chi2Cut for muon tracks = " << Chi2Cut << endl;
592 cout << "PtCutMin for muon tracks = " << PtCutMin << endl;
593 cout << "PtCutMax for muon tracks = " << PtCutMax << endl;
594 cout << "Entries (unlike sign dimuons) in the mass range ["<<invMassMinInPeak<<";"<<invMassMaxInPeak<<"] : " << EventInMass <<endl;
595 if (ptTrig==0x800) cout << "Unlike Pair - All Pt" ;
596 if (ptTrig==0x400) cout << "Unlike Pair - High Pt" ;
597 if (ptTrig==0x200) cout << "Unlike Pair - Low Pt" ;
598 cout << " triggers : " << NbTrigger << endl;
d949b15e 599
53399039 600 cout << "Entries in the mass range with matching between reconstructed tracks and trigger tracks " << EventInMassMatch << endl;
601
d949b15e 602
603 return kTRUE;
604}