]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONmassPlot_ESD.C
Updated for new VStores (Laurent)
[u/mrichter/AliRoot.git] / MUON / MUONmassPlot_ESD.C
CommitLineData
5473f16a 1#if !defined(__CINT__) || defined(__MAKECINT__)
2// ROOT includes
48d6b312 3#include "TTree.h"
5473f16a 4#include "TBranch.h"
5#include "TClonesArray.h"
6#include "TLorentzVector.h"
7#include "TFile.h"
8#include "TH1.h"
ac3c5325 9#include "TH2.h"
5473f16a 10#include "TParticle.h"
11#include "TTree.h"
12#include <Riostream.h>
8cde4af5 13#include <TGeoManager.h>
21939432 14#include <TROOT.h>
5473f16a 15
16// STEER includes
17#include "AliRun.h"
0ff94351 18#include "AliLog.h"
5473f16a 19#include "AliRunLoader.h"
20#include "AliHeader.h"
21#include "AliLoader.h"
22#include "AliStack.h"
0ff94351 23#include "AliMagFMaps.h"
5473f16a 24#include "AliESD.h"
0ff94351 25#include "AliTracker.h"
5473f16a 26
27// MUON includes
211c52eb 28#include "AliMUONTrackParam.h"
37827b29 29#include "AliMUONTrackExtrap.h"
5473f16a 30#include "AliESDMuonTrack.h"
31#endif
32//
33// Macro MUONmassPlot.C for ESD
34// Ch. Finck, Subatech, April. 2004
35//
36
37// macro to make invariant mass plots
38// for combinations of 2 muons with opposite charges,
39// from root file "MUON.tracks.root" containing the result of track reconstruction.
40// Histograms are stored on the "MUONmassPlot.root" file.
41// introducing TLorentzVector for parameter calculations (Pt, P,rap,etc...)
42// using Invariant Mass for rapidity.
43
44// Arguments:
8cde4af5 45// ExtrapToVertex (default -1)
46// <0: no extrapolation;
47// =0: extrapolation to (0,0,0);
48// >0: extrapolation to ESDVertex if available, else to (0,0,0)
5473f16a 49// FirstEvent (default 0)
50// LastEvent (default 0)
51// ResType (default 553)
52// 553 for Upsilon, anything else for J/Psi
53// Chi2Cut (default 100)
54// to keep only tracks with chi2 per d.o.f. < Chi2Cut
55// PtCutMin (default 1)
56// to keep only tracks with transverse momentum > PtCutMin
57// PtCutMax (default 10000)
58// to keep only tracks with transverse momentum < PtCutMax
59// massMin (default 9.17 for Upsilon)
60// & massMax (default 9.77 for Upsilon)
61// to calculate the reconstruction efficiency for resonances with invariant mass
62// massMin < mass < massMax.
63
64// Add parameters and histograms for analysis
65
6b092dfc 66Bool_t MUONmassPlot(char* filename = "galice_sim.root", Int_t ExtrapToVertex = -1, char* geoFilename = "geometry.root",
8cde4af5 67 Int_t FirstEvent = 0, Int_t LastEvent = 10000, char* esdFileName = "AliESDs.root", Int_t ResType = 553,
5473f16a 68 Float_t Chi2Cut = 100., Float_t PtCutMin = 1., Float_t PtCutMax = 10000.,
69 Float_t massMin = 9.17,Float_t massMax = 9.77)
70{
71 cout << "MUONmassPlot " << endl;
72 cout << "FirstEvent " << FirstEvent << endl;
73 cout << "LastEvent " << LastEvent << endl;
74 cout << "ResType " << ResType << endl;
75 cout << "Chi2Cut " << Chi2Cut << endl;
76 cout << "PtCutMin " << PtCutMin << endl;
77 cout << "PtCutMax " << PtCutMax << endl;
78 cout << "massMin " << massMin << endl;
79 cout << "massMax " << massMax << endl;
80
81
82 //Reset ROOT and connect tree file
83 gROOT->Reset();
84
5473f16a 85 // File for histograms and histogram booking
86 TFile *histoFile = new TFile("MUONmassPlot.root", "RECREATE");
87 TH1F *hPtMuon = new TH1F("hPtMuon", "Muon Pt (GeV/c)", 100, 0., 20.);
ac3c5325 88 TH1F *hPtMuonPlus = new TH1F("hPtMuonPlus", "Muon+ Pt (GeV/c)", 100, 0., 20.);
89 TH1F *hPtMuonMinus = new TH1F("hPtMuonMinus", "Muon- Pt (GeV/c)", 100, 0., 20.);
5473f16a 90 TH1F *hPMuon = new TH1F("hPMuon", "Muon P (GeV/c)", 100, 0., 200.);
91 TH1F *hChi2PerDof = new TH1F("hChi2PerDof", "Muon track chi2/d.o.f.", 100, 0., 20.);
92 TH1F *hInvMassAll = new TH1F("hInvMassAll", "Mu+Mu- invariant mass (GeV/c2)", 480, 0., 12.);
ac3c5325 93 TH1F *hInvMassBg = new TH1F("hInvMassBg", "Mu+Mu- invariant mass BG(GeV/c2)", 480, 0., 12.);
f57d136a 94 TH2F *hInvMassAll_vs_Pt = new TH2F("hInvMassAll_vs_Pt","hInvMassAll_vs_Pt",480,0.,12.,80,0.,20.);
95 TH2F *hInvMassBgk_vs_Pt = new TH2F("hInvMassBgk_vs_Pt","hInvMassBgk_vs_Pt",480,0.,12.,80,0.,20.);
96 TH1F *hInvMassRes;
6ab68e5f 97 TH1F *hPrimaryVertex = new TH1F("hPrimaryVertex","SPD reconstructed Z vertex",150,-15,15);
5473f16a 98
99 if (ResType == 553) {
100 hInvMassRes = new TH1F("hInvMassRes", "Mu+Mu- invariant mass (GeV/c2) around Upsilon", 60, 8., 11.);
101 } else {
102 hInvMassRes = new TH1F("hInvMassRes", "Mu+Mu- invariant mass (GeV/c2) around J/Psi", 80, 0., 5.);
103 }
104
105 TH1F *hNumberOfTrack = new TH1F("hNumberOfTrack","nb of track /evt ",20,-0.5,19.5);
106 TH1F *hRapMuon = new TH1F("hRapMuon"," Muon Rapidity",50,-4.5,-2);
107 TH1F *hRapResonance = new TH1F("hRapResonance"," Resonance Rapidity",50,-4.5,-2);
108 TH1F *hPtResonance = new TH1F("hPtResonance", "Resonance Pt (GeV/c)", 100, 0., 20.);
ac3c5325 109 TH2F *hThetaPhiPlus = new TH2F("hThetaPhiPlus", "Theta vs Phi +", 760, -190., 190., 400, 160., 180.);
110 TH2F *hThetaPhiMinus = new TH2F("hThetaPhiMinus", "Theta vs Phi -", 760, -190., 190., 400, 160., 180.);
5473f16a 111
112
113 // settings
114 Int_t EventInMass = 0;
6678cd54 115 Int_t EventInMassMatch = 0;
116 Int_t NbTrigger = 0;
117
5473f16a 118 Float_t muonMass = 0.105658389;
119// Float_t UpsilonMass = 9.46037;
120// Float_t JPsiMass = 3.097;
121
22ccc301 122 Int_t fCharge1, fCharge2;
5473f16a 123 Double_t fPxRec1, fPyRec1, fPzRec1, fE1;
124 Double_t fPxRec2, fPyRec2, fPzRec2, fE2;
5473f16a 125
126 Int_t ntrackhits, nevents;
127 Double_t fitfmin;
e3c6ae4c 128 Double_t fZVertex=0;
211c52eb 129 Double_t fYVertex=0;
130 Double_t fXVertex=0;
5473f16a 131
132 TLorentzVector fV1, fV2, fVtot;
cb75342e 133
8cde4af5 134 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
135 if (!gGeoManager) {
136 TGeoManager::Import(geoFilename);
137 if (!gGeoManager) {
138 Error("MUONmass_ESD", "getting geometry from file %s failed", filename);
139 return kFALSE;
140 }
141 }
142
0ff94351 143 // set mag field
144 // waiting for mag field in CDB
145 printf("Loading field map...\n");
b97b210c 146 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
0ff94351 147 AliTracker::SetFieldMap(field, kFALSE);
cb75342e 148
5473f16a 149 // open run loader and load gAlice, kinematics and header
150 AliRunLoader* runLoader = AliRunLoader::Open(filename);
151 if (!runLoader) {
8cde4af5 152 Error("MUONmass_ESD", "getting run loader from file %s failed", filename);
5473f16a 153 return kFALSE;
154 }
6b092dfc 155/*
156 runLoader->LoadgAlice();
5473f16a 157 if (!gAlice) {
158 Error("MUONmass_ESD", "no galice object found");
159 return kFALSE;
160 }
6b092dfc 161*/
5473f16a 162
163 // open the ESD file
164 TFile* esdFile = TFile::Open(esdFileName);
165 if (!esdFile || !esdFile->IsOpen()) {
166 Error("MUONmass_ESD", "opening ESD file %s failed", esdFileName);
167 return kFALSE;
168 }
169
48d6b312 170 AliESD* esd = new AliESD();
171 TTree* tree = (TTree*) esdFile->Get("esdTree");
172 if (!tree) {
173 Error("CheckESD", "no ESD tree found");
174 return kFALSE;
175 }
176 tree->SetBranchAddress("ESD", &esd);
f9ebb3bd 177
178
48d6b312 179
5473f16a 180 runLoader->LoadHeader();
181 nevents = runLoader->GetNumberOfEvents();
211c52eb 182
183 AliMUONTrackParam trackParam;
0ff94351 184
5473f16a 185 // Loop over events
186 for (Int_t iEvent = FirstEvent; iEvent <= TMath::Min(LastEvent, nevents - 1); iEvent++) {
187
188 // get current event
189 runLoader->GetEvent(iEvent);
48d6b312 190
5473f16a 191 // get the event summary data
48d6b312 192 tree->GetEvent(iEvent);
5473f16a 193 if (!esd) {
48d6b312 194 Error("CheckESD", "no ESD object found for event %d", iEvent);
5473f16a 195 return kFALSE;
196 }
197
f9ebb3bd 198 // get the SPD reconstructed vertex (vertexer) and fill the histogram
43939bd8 199 AliESDVertex* Vertex = (AliESDVertex*) esd->GetVertex();
43939bd8 200 if (Vertex->GetNContributors()) {
211c52eb 201 fZVertex = Vertex->GetZv();
202 fYVertex = Vertex->GetYv();
203 fXVertex = Vertex->GetXv();
211c52eb 204 }
f9ebb3bd 205 hPrimaryVertex->Fill(fZVertex);
206
48d6b312 207 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
5473f16a 208
209 // printf("\n Nb of events analysed: %d\r",iEvent);
48d6b312 210 // cout << " number of tracks: " << nTracks <<endl;
5473f16a 211
37827b29 212 // set the magnetic field for track extrapolations
213 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
5473f16a 214 // loop over all reconstructed tracks (also first track of combination)
215 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
216
8cde4af5 217 AliESDMuonTrack* muonTrack = new AliESDMuonTrack(*(esd->GetMuonTrack(iTrack)));
5473f16a 218
8cde4af5 219 // extrapolate to vertex if required and available
220 if (ExtrapToVertex > 0 && Vertex->GetNContributors()) {
22ccc301 221 trackParam.GetParamFromUncorrected(*muonTrack);
37827b29 222 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, fXVertex, fYVertex, fZVertex);
8cde4af5 223 trackParam.SetParamFor(*muonTrack); // put the new parameters in this copy of AliESDMuonTrack
224 } else if ((ExtrapToVertex > 0 && !Vertex->GetNContributors()) || ExtrapToVertex == 0){
22ccc301 225 trackParam.GetParamFromUncorrected(*muonTrack);
8cde4af5 226 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, 0., 0., 0.);
227 trackParam.SetParamFor(*muonTrack); // put the new parameters in this copy of AliESDMuonTrack
211c52eb 228 }
8cde4af5 229
22ccc301 230 fCharge1 = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
231
232 muonTrack->LorentzP(fV1);
8cde4af5 233
5473f16a 234 ntrackhits = muonTrack->GetNHit();
235 fitfmin = muonTrack->GetChi2();
236
237 // transverse momentum
238 Float_t pt1 = fV1.Pt();
239
240 // total momentum
241 Float_t p1 = fV1.P();
242
243 // Rapidity
244 Float_t rapMuon1 = fV1.Rapidity();
245
246 // chi2 per d.o.f.
247 Float_t ch1 = fitfmin / (2.0 * ntrackhits - 5);
248// printf(" px %f py %f pz %f NHits %d Norm.chi2 %f charge %d\n",
22ccc301 249// fPxRec1, fPyRec1, fPzRec1, ntrackhits, ch1, fCharge1);
5473f16a 250
251 // condition for good track (Chi2Cut and PtCut)
252
253 if ((ch1 < Chi2Cut) && (pt1 > PtCutMin) && (pt1 < PtCutMax)) {
254
255 // fill histos hPtMuon and hChi2PerDof
256 hPtMuon->Fill(pt1);
257 hPMuon->Fill(p1);
258 hChi2PerDof->Fill(ch1);
259 hRapMuon->Fill(rapMuon1);
22ccc301 260 if (fCharge1 > 0) {
ac3c5325 261 hPtMuonPlus->Fill(pt1);
22ccc301 262 hThetaPhiPlus->Fill(fV1.Phi()*180./TMath::Pi(),fV1.Theta()*180./TMath::Pi());
ac3c5325 263 } else {
264 hPtMuonMinus->Fill(pt1);
22ccc301 265 hThetaPhiMinus->Fill(fV1.Phi()*180./TMath::Pi(),fV1.Theta()*180./TMath::Pi());
ac3c5325 266 }
5473f16a 267 // loop over second track of combination
268 for (Int_t iTrack2 = iTrack + 1; iTrack2 < nTracks; iTrack2++) {
269
8cde4af5 270 AliESDMuonTrack* muonTrack2 = new AliESDMuonTrack(*(esd->GetMuonTrack(iTrack2)));
271
272 // extrapolate to vertex if required and available
273 if (ExtrapToVertex > 0 && Vertex->GetNContributors()) {
22ccc301 274 trackParam.GetParamFromUncorrected(*muonTrack2);
37827b29 275 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, fXVertex, fYVertex, fZVertex);
8cde4af5 276 trackParam.SetParamFor(*muonTrack2); // put the new parameters in this copy of AliESDMuonTrack
277 } else if ((ExtrapToVertex > 0 && !Vertex->GetNContributors()) || ExtrapToVertex == 0){
22ccc301 278 trackParam.GetParamFromUncorrected(*muonTrack2);
8cde4af5 279 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, 0., 0., 0.);
280 trackParam.SetParamFor(*muonTrack2); // put the new parameters in this copy of AliESDMuonTrack
211c52eb 281 }
8cde4af5 282
8cde4af5 283 fCharge2 = Int_t(TMath::Sign(1.,muonTrack2->GetInverseBendingMomentum()));
5473f16a 284
22ccc301 285 muonTrack2->LorentzP(fV2);
5473f16a 286
8cde4af5 287 ntrackhits = muonTrack2->GetNHit();
288 fitfmin = muonTrack2->GetChi2();
5473f16a 289
290 // transverse momentum
291 Float_t pt2 = fV2.Pt();
292
293 // chi2 per d.o.f.
294 Float_t ch2 = fitfmin / (2.0 * ntrackhits - 5);
295
296 // condition for good track (Chi2Cut and PtCut)
297 if ((ch2 < Chi2Cut) && (pt2 > PtCutMin) && (pt2 < PtCutMax)) {
298
299 // condition for opposite charges
22ccc301 300 if ((fCharge1 * fCharge2) == -1) {
5473f16a 301
302 // invariant mass
303 fVtot = fV1 + fV2;
304 Float_t invMass = fVtot.M();
305
306 // fill histos hInvMassAll and hInvMassRes
307 hInvMassAll->Fill(invMass);
308 hInvMassRes->Fill(invMass);
ac3c5325 309 hInvMassAll_vs_Pt->Fill(invMass,fVtot.Pt());
6678cd54 310 Int_t ptTrig;
311 if (ResType == 553)
8d4fefab 312 ptTrig = 0x20;// mask for Hpt unlike sign pair
6678cd54 313 else
8d4fefab 314 ptTrig = 0x10;// mask for Lpt unlike sign pair
6678cd54 315
f57d136a 316 if (esd->GetTriggerMask() & ptTrig) NbTrigger++;
5473f16a 317 if (invMass > massMin && invMass < massMax) {
318 EventInMass++;
8cde4af5 319 if (muonTrack2->GetMatchTrigger() && (esd->GetTriggerMask() & ptTrig))// match with trigger
6678cd54 320 EventInMassMatch++;
321
5473f16a 322 hRapResonance->Fill(fVtot.Rapidity());
323 hPtResonance->Fill(fVtot.Pt());
324 }
325
22ccc301 326 } // if (fCharge1 * fCharge2) == -1)
5473f16a 327 } // if ((ch2 < Chi2Cut) && (pt2 > PtCutMin) && (pt2 < PtCutMax))
8cde4af5 328 delete muonTrack2;
5473f16a 329 } // for (Int_t iTrack2 = iTrack + 1; iTrack2 < iTrack; iTrack2++)
330 } // if (ch1 < Chi2Cut) && (pt1 > PtCutMin)&& (pt1 < PtCutMax) )
8cde4af5 331 delete muonTrack;
5473f16a 332 } // for (Int_t iTrack = 0; iTrack < nrectracks; iTrack++)
333
334 hNumberOfTrack->Fill(nTracks);
48d6b312 335 // esdFile->Delete();
5473f16a 336 } // for (Int_t iEvent = FirstEvent;
337
ac3c5325 338// Loop over events for bg event
339
340 Double_t thetaPlus, phiPlus;
341 Double_t thetaMinus, phiMinus;
342 Float_t PtMinus, PtPlus;
343
344 for (Int_t iEvent = 0; iEvent < hInvMassAll->Integral(); iEvent++) {
345
346 hThetaPhiPlus->GetRandom2(phiPlus, thetaPlus);
347 hThetaPhiMinus->GetRandom2(phiMinus,thetaMinus);
348 PtPlus = hPtMuonPlus->GetRandom();
349 PtMinus = hPtMuonMinus->GetRandom();
350
351 fPxRec1 = PtPlus * TMath::Cos(TMath::Pi()/180.*phiPlus);
352 fPyRec1 = PtPlus * TMath::Sin(TMath::Pi()/180.*phiPlus);
353 fPzRec1 = PtPlus / TMath::Tan(TMath::Pi()/180.*thetaPlus);
354
355 fE1 = TMath::Sqrt(muonMass * muonMass + fPxRec1 * fPxRec1 + fPyRec1 * fPyRec1 + fPzRec1 * fPzRec1);
356 fV1.SetPxPyPzE(fPxRec1, fPyRec1, fPzRec1, fE1);
357
358 fPxRec2 = PtMinus * TMath::Cos(TMath::Pi()/180.*phiMinus);
359 fPyRec2 = PtMinus * TMath::Sin(TMath::Pi()/180.*phiMinus);
360 fPzRec2 = PtMinus / TMath::Tan(TMath::Pi()/180.*thetaMinus);
361
362 fE2 = TMath::Sqrt(muonMass * muonMass + fPxRec2 * fPxRec2 + fPyRec2 * fPyRec2 + fPzRec2 * fPzRec2);
363 fV2.SetPxPyPzE(fPxRec2, fPyRec2, fPzRec2, fE2);
364
365 // invariant mass
366 fVtot = fV1 + fV2;
367
368 // fill histos hInvMassAll and hInvMassRes
369 hInvMassBg->Fill(fVtot.M());
370 hInvMassBgk_vs_Pt->Fill( fVtot.M(), fVtot.Pt() );
371 }
372
5473f16a 373 histoFile->Write();
374 histoFile->Close();
375
6678cd54 376 cout << endl;
5473f16a 377 cout << "EventInMass " << EventInMass << endl;
6678cd54 378 cout << "NbTrigger " << NbTrigger << endl;
379 cout << "EventInMass match with trigger " << EventInMassMatch << endl;
5473f16a 380
381 return kTRUE;
382}
383