1 #if !defined(__CINT__) || defined(__MAKECINT__)
5 #include "TClonesArray.h"
6 #include "TLorentzVector.h"
10 #include "TParticle.h"
12 #include <Riostream.h>
13 #include <TGeoManager.h>
19 #include "AliRunLoader.h"
20 #include "AliHeader.h"
21 #include "AliLoader.h"
23 #include "AliMagFMaps.h"
25 #include "AliTracker.h"
28 #include "AliMUONTrackParam.h"
29 #include "AliMUONTrackExtrap.h"
30 #include "AliESDMuonTrack.h"
33 // Macro MUONmassPlot.C for ESD
34 // Ch. Finck, Subatech, April. 2004
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.
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)
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.
64 // Add parameters and histograms for analysis
66 Bool_t MUONmassPlot(Int_t ExtrapToVertex = -1, char* geoFilename = "geometry.root", char* filename = "galice.root",
67 Int_t FirstEvent = 0, Int_t LastEvent = 10000, char* esdFileName = "AliESDs.root", Int_t ResType = 553,
68 Float_t Chi2Cut = 100., Float_t PtCutMin = 1., Float_t PtCutMax = 10000.,
69 Float_t massMin = 9.17,Float_t massMax = 9.77)
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;
82 //Reset ROOT and connect tree file
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.);
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.);
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.);
93 TH1F *hInvMassBg = new TH1F("hInvMassBg", "Mu+Mu- invariant mass BG(GeV/c2)", 480, 0., 12.);
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.);
97 TH1F *hPrimaryVertex = new TH1F("hPrimaryVertex","SPD reconstructed Z vertex",150,-15,15);
100 hInvMassRes = new TH1F("hInvMassRes", "Mu+Mu- invariant mass (GeV/c2) around Upsilon", 60, 8., 11.);
102 hInvMassRes = new TH1F("hInvMassRes", "Mu+Mu- invariant mass (GeV/c2) around J/Psi", 80, 0., 5.);
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.);
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.);
114 Int_t EventInMass = 0;
115 Int_t EventInMassMatch = 0;
118 Float_t muonMass = 0.105658389;
119 // Float_t UpsilonMass = 9.46037;
120 // Float_t JPsiMass = 3.097;
122 Int_t fCharge1, fCharge2;
123 Double_t fPxRec1, fPyRec1, fPzRec1, fE1;
124 Double_t fPxRec2, fPyRec2, fPzRec2, fE2;
126 Int_t ntrackhits, nevents;
132 TLorentzVector fV1, fV2, fVtot;
134 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
136 TGeoManager::Import(geoFilename);
138 Error("MUONmass_ESD", "getting geometry from file %s failed", filename);
144 // waiting for mag field in CDB
145 printf("Loading field map...\n");
146 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
147 AliTracker::SetFieldMap(field, kFALSE);
149 // open run loader and load gAlice, kinematics and header
150 AliRunLoader* runLoader = AliRunLoader::Open(filename);
152 Error("MUONmass_ESD", "getting run loader from file %s failed", filename);
157 Error("MUONmass_ESD", "no galice object found");
163 TFile* esdFile = TFile::Open(esdFileName);
164 if (!esdFile || !esdFile->IsOpen()) {
165 Error("MUONmass_ESD", "opening ESD file %s failed", esdFileName);
169 AliESD* esd = new AliESD();
170 TTree* tree = (TTree*) esdFile->Get("esdTree");
172 Error("CheckESD", "no ESD tree found");
175 tree->SetBranchAddress("ESD", &esd);
179 runLoader->LoadHeader();
180 nevents = runLoader->GetNumberOfEvents();
182 AliMUONTrackParam trackParam;
185 for (Int_t iEvent = FirstEvent; iEvent <= TMath::Min(LastEvent, nevents - 1); iEvent++) {
188 runLoader->GetEvent(iEvent);
190 // get the event summary data
191 tree->GetEvent(iEvent);
193 Error("CheckESD", "no ESD object found for event %d", iEvent);
197 // get the SPD reconstructed vertex (vertexer) and fill the histogram
198 AliESDVertex* Vertex = (AliESDVertex*) esd->GetVertex();
199 if (Vertex->GetNContributors()) {
200 fZVertex = Vertex->GetZv();
201 fYVertex = Vertex->GetYv();
202 fXVertex = Vertex->GetXv();
204 hPrimaryVertex->Fill(fZVertex);
206 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
208 // printf("\n Nb of events analysed: %d\r",iEvent);
209 // cout << " number of tracks: " << nTracks <<endl;
211 // set the magnetic field for track extrapolations
212 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
213 // loop over all reconstructed tracks (also first track of combination)
214 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
216 AliESDMuonTrack* muonTrack = new AliESDMuonTrack(*(esd->GetMuonTrack(iTrack)));
218 // extrapolate to vertex if required and available
219 if (ExtrapToVertex > 0 && Vertex->GetNContributors()) {
220 trackParam.GetParamFromUncorrected(*muonTrack);
221 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, fXVertex, fYVertex, fZVertex);
222 trackParam.SetParamFor(*muonTrack); // put the new parameters in this copy of AliESDMuonTrack
223 } else if ((ExtrapToVertex > 0 && !Vertex->GetNContributors()) || ExtrapToVertex == 0){
224 trackParam.GetParamFromUncorrected(*muonTrack);
225 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, 0., 0., 0.);
226 trackParam.SetParamFor(*muonTrack); // put the new parameters in this copy of AliESDMuonTrack
229 fCharge1 = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
231 muonTrack->LorentzP(fV1);
233 ntrackhits = muonTrack->GetNHit();
234 fitfmin = muonTrack->GetChi2();
236 // transverse momentum
237 Float_t pt1 = fV1.Pt();
240 Float_t p1 = fV1.P();
243 Float_t rapMuon1 = fV1.Rapidity();
246 Float_t ch1 = fitfmin / (2.0 * ntrackhits - 5);
247 // printf(" px %f py %f pz %f NHits %d Norm.chi2 %f charge %d\n",
248 // fPxRec1, fPyRec1, fPzRec1, ntrackhits, ch1, fCharge1);
250 // condition for good track (Chi2Cut and PtCut)
252 if ((ch1 < Chi2Cut) && (pt1 > PtCutMin) && (pt1 < PtCutMax)) {
254 // fill histos hPtMuon and hChi2PerDof
257 hChi2PerDof->Fill(ch1);
258 hRapMuon->Fill(rapMuon1);
260 hPtMuonPlus->Fill(pt1);
261 hThetaPhiPlus->Fill(fV1.Phi()*180./TMath::Pi(),fV1.Theta()*180./TMath::Pi());
263 hPtMuonMinus->Fill(pt1);
264 hThetaPhiMinus->Fill(fV1.Phi()*180./TMath::Pi(),fV1.Theta()*180./TMath::Pi());
266 // loop over second track of combination
267 for (Int_t iTrack2 = iTrack + 1; iTrack2 < nTracks; iTrack2++) {
269 AliESDMuonTrack* muonTrack2 = new AliESDMuonTrack(*(esd->GetMuonTrack(iTrack2)));
271 // extrapolate to vertex if required and available
272 if (ExtrapToVertex > 0 && Vertex->GetNContributors()) {
273 trackParam.GetParamFromUncorrected(*muonTrack2);
274 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, fXVertex, fYVertex, fZVertex);
275 trackParam.SetParamFor(*muonTrack2); // put the new parameters in this copy of AliESDMuonTrack
276 } else if ((ExtrapToVertex > 0 && !Vertex->GetNContributors()) || ExtrapToVertex == 0){
277 trackParam.GetParamFromUncorrected(*muonTrack2);
278 AliMUONTrackExtrap::ExtrapToVertex(&trackParam, 0., 0., 0.);
279 trackParam.SetParamFor(*muonTrack2); // put the new parameters in this copy of AliESDMuonTrack
282 fCharge2 = Int_t(TMath::Sign(1.,muonTrack2->GetInverseBendingMomentum()));
284 muonTrack2->LorentzP(fV2);
286 ntrackhits = muonTrack2->GetNHit();
287 fitfmin = muonTrack2->GetChi2();
289 // transverse momentum
290 Float_t pt2 = fV2.Pt();
293 Float_t ch2 = fitfmin / (2.0 * ntrackhits - 5);
295 // condition for good track (Chi2Cut and PtCut)
296 if ((ch2 < Chi2Cut) && (pt2 > PtCutMin) && (pt2 < PtCutMax)) {
298 // condition for opposite charges
299 if ((fCharge1 * fCharge2) == -1) {
303 Float_t invMass = fVtot.M();
305 // fill histos hInvMassAll and hInvMassRes
306 hInvMassAll->Fill(invMass);
307 hInvMassRes->Fill(invMass);
308 hInvMassAll_vs_Pt->Fill(invMass,fVtot.Pt());
311 ptTrig = 0x20;// mask for Hpt unlike sign pair
313 ptTrig = 0x10;// mask for Lpt unlike sign pair
315 if (esd->GetTriggerMask() & ptTrig) NbTrigger++;
316 if (invMass > massMin && invMass < massMax) {
318 if (muonTrack2->GetMatchTrigger() && (esd->GetTriggerMask() & ptTrig))// match with trigger
321 hRapResonance->Fill(fVtot.Rapidity());
322 hPtResonance->Fill(fVtot.Pt());
325 } // if (fCharge1 * fCharge2) == -1)
326 } // if ((ch2 < Chi2Cut) && (pt2 > PtCutMin) && (pt2 < PtCutMax))
328 } // for (Int_t iTrack2 = iTrack + 1; iTrack2 < iTrack; iTrack2++)
329 } // if (ch1 < Chi2Cut) && (pt1 > PtCutMin)&& (pt1 < PtCutMax) )
331 } // for (Int_t iTrack = 0; iTrack < nrectracks; iTrack++)
333 hNumberOfTrack->Fill(nTracks);
334 // esdFile->Delete();
335 } // for (Int_t iEvent = FirstEvent;
337 // Loop over events for bg event
339 Double_t thetaPlus, phiPlus;
340 Double_t thetaMinus, phiMinus;
341 Float_t PtMinus, PtPlus;
343 for (Int_t iEvent = 0; iEvent < hInvMassAll->Integral(); iEvent++) {
345 hThetaPhiPlus->GetRandom2(phiPlus, thetaPlus);
346 hThetaPhiMinus->GetRandom2(phiMinus,thetaMinus);
347 PtPlus = hPtMuonPlus->GetRandom();
348 PtMinus = hPtMuonMinus->GetRandom();
350 fPxRec1 = PtPlus * TMath::Cos(TMath::Pi()/180.*phiPlus);
351 fPyRec1 = PtPlus * TMath::Sin(TMath::Pi()/180.*phiPlus);
352 fPzRec1 = PtPlus / TMath::Tan(TMath::Pi()/180.*thetaPlus);
354 fE1 = TMath::Sqrt(muonMass * muonMass + fPxRec1 * fPxRec1 + fPyRec1 * fPyRec1 + fPzRec1 * fPzRec1);
355 fV1.SetPxPyPzE(fPxRec1, fPyRec1, fPzRec1, fE1);
357 fPxRec2 = PtMinus * TMath::Cos(TMath::Pi()/180.*phiMinus);
358 fPyRec2 = PtMinus * TMath::Sin(TMath::Pi()/180.*phiMinus);
359 fPzRec2 = PtMinus / TMath::Tan(TMath::Pi()/180.*thetaMinus);
361 fE2 = TMath::Sqrt(muonMass * muonMass + fPxRec2 * fPxRec2 + fPyRec2 * fPyRec2 + fPzRec2 * fPzRec2);
362 fV2.SetPxPyPzE(fPxRec2, fPyRec2, fPzRec2, fE2);
367 // fill histos hInvMassAll and hInvMassRes
368 hInvMassBg->Fill(fVtot.M());
369 hInvMassBgk_vs_Pt->Fill( fVtot.M(), fVtot.Pt() );
376 cout << "EventInMass " << EventInMass << endl;
377 cout << "NbTrigger " << NbTrigger << endl;
378 cout << "EventInMass match with trigger " << EventInMassMatch << endl;