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