1 #if !defined(__CINT__) || defined(__MAKECINT__)
9 #include <TClonesArray.h>
10 #include <TGeoGlobalMagField.h>
11 #include <TLorentzVector.h>
16 #include "AliESDEvent.h"
17 #include "AliESDMuonTrack.h"
18 #include "AliESDMuonCluster.h"
19 #include "AliCDBPath.h"
20 #include "AliCDBEntry.h"
21 #include "AliCDBManager.h"
24 #include "AliMUONTrack.h"
25 #include "AliMUONVTrackStore.h"
26 #include "AliMUONTrackParam.h"
27 #include "AliMUONTrackExtrap.h"
28 #include "AliMUONESDInterface.h"
29 #include "AliMUONRecoCheck.h"
30 #include "AliMUONVCluster.h"
31 #include "AliMUONRecoParam.h"
35 /// \file DIMUONFakes.C
37 /// \author Ph. Pillot, Subatech, March. 2009
39 /// Macro to study the effects of fake tracks on the dimuon spectra
40 /// Results are saved in the root file DiFakes.root
41 /// Results are relevent provided that you use the same recoParams as for the reconstruction
43 void Prepare(AliMUONRecoParam *&recoParam, Double_t &sigmaCut);
44 TTree* GetESDTree(TFile *esdFile);
45 Bool_t TrackMatched(AliMUONTrack &track, AliMUONTrack &trackRef, Float_t &fractionOfMatchCluster, Double_t sigmaCut);
46 AliMUONTrack* MatchWithTrackRef(AliESDMuonTrack &muonTrack, AliMUONVTrackStore &trackRefStore,
47 Float_t &fractionOfMatchCluster, Bool_t useLabel, Double_t sigmaCut);
49 //-----------------------------------------------------------------------
50 void DIMUONFakes(Bool_t useLabel = kFALSE, Int_t FirstEvent = 0, Int_t LastEvent = -1,
51 const TString esdFileName = "AliESDs.root", const TString SimDir = "./generated/")
54 //Reset ROOT and connect tree file
57 // File for histograms and histogram booking
58 TFile *histoFile = new TFile("DiFakes.root", "RECREATE");
60 TH1F *hMass = new TH1F("hMass", "Muon mass distribution (GeV/c^{2})", 100, 0., 12.);
61 TH1F *hMassM = new TH1F("hMassM", "matched track mass distribution (GeV/c^{2})", 100, 0., 12.);
62 TH1F *hMassF = new TH1F("hMassF", "fake track mass distribution (GeV/c^{2})", 100, 0., 12.);
63 TH1F *hP = new TH1F("hP", "Muon P distribution (GeV/c)", 100, 0., 200.);
64 TH1F *hPM = new TH1F("hPM", "matched track P distribution (GeV/c)", 100, 0., 200.);
65 TH1F *hPF = new TH1F("hPF", "fake track P distribution (GeV/c)", 100, 0., 200.);
66 TH1F *hPt = new TH1F("hPt", "Muon Pt distribution (GeV/c)", 100, 0., 20.);
67 TH1F *hPtM = new TH1F("hPtM", "matched track Pt distribution (GeV/c)", 100, 0., 20.);
68 TH1F *hPtF = new TH1F("hPtF", "fake track Pt distribution (GeV/c)", 100, 0., 20.);
69 TH1F *hY = new TH1F("hY"," Muon rapidity distribution",100,-10,0);
70 TH1F *hYM = new TH1F("hYM"," matched track rapidity distribution",100,-10,0);
71 TH1F *hYF = new TH1F("hYF"," fake track rapidity distribution",100,-10,0);
72 TH1F *hEta = new TH1F("hEta"," Muon pseudo-rapidity distribution",100,-10,0);
73 TH1F *hEtaM = new TH1F("hEtaM"," matched track pseudo-rapidity distribution",100,-10,0);
74 TH1F *hEtaF = new TH1F("hEtaF"," fake track pseudo-rapidity distribution",100,-10,0);
75 TH1F *hPhi = new TH1F("hPhi"," Muon phi distribution",100,-1.,9.);
76 TH1F *hPhiM = new TH1F("hPhiM"," matched track phi distribution",100,-1.,9.);
77 TH1F *hPhiF = new TH1F("hPhiF"," fake track phi distribution",100,-1.,9.);
79 // prepare for analysis
80 AliMUONRecoParam *recoParam = 0x0;
81 Double_t sigmaCut = -1;
82 Prepare(recoParam, sigmaCut);
84 // link to reconstructed tracks
85 TFile* esdFile = TFile::Open(esdFileName);
86 TTree* esdTree = GetESDTree(esdFile);
87 AliESDEvent* esd = new AliESDEvent();
88 esd->ReadFromTree(esdTree);
90 // link to simulated tracks
91 AliMUONRecoCheck rc(esdFileName, SimDir);
93 TLorentzVector vMu1, vMu2, vDiMu;
95 // Loop over ESD events
96 FirstEvent = TMath::Max(0, FirstEvent);
97 LastEvent = (LastEvent>=0) ? TMath::Min((Int_t)esdTree->GetEntries() - 1, LastEvent) : (Int_t)esdTree->GetEntries() - 1;
98 for (Int_t iEvent = FirstEvent; iEvent <= LastEvent; iEvent++) {
100 // get the ESD of current event
101 esdTree->GetEvent(iEvent);
103 Error("CheckESD", "no ESD object found for event %d", iEvent);
107 // convert TrackRef to MUON tracks
108 AliMUONVTrackStore* trackRefStore = rc.TrackRefs(iEvent);
110 // loop over ESD tracks and flag them
111 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
112 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
114 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
117 if (!muonTrack->ContainTrackerData()) continue;
119 // try to match the reconstructed track with a simulated one
120 Float_t fractionOfMatchCluster = 0.;
121 AliMUONTrack* matchedTrackRef = MatchWithTrackRef(*muonTrack, *trackRefStore, fractionOfMatchCluster, useLabel, sigmaCut);
123 // take actions according to matching result
124 if (matchedTrackRef) {
126 // flag matched tracks
127 muonTrack->SetLabel(matchedTrackRef->GetUniqueID());
129 // remove already matched trackRefs
130 trackRefStore->Remove(*matchedTrackRef);
135 muonTrack->SetLabel(-1);
141 // double loop over ESD tracks, build pairs and fill histograms according to their label
142 for (Int_t iTrack1 = 0; iTrack1 < nTracks; iTrack1++) {
143 AliESDMuonTrack* muonTrack1 = esd->GetMuonTrack(iTrack1);
146 if (!muonTrack1->ContainTrackerData()) continue;
149 Short_t charge1 = muonTrack1->Charge();
150 Int_t label1 = muonTrack1->GetLabel();
151 muonTrack1->LorentzP(vMu1);
153 for (Int_t iTrack2 = iTrack1+1; iTrack2 < nTracks; iTrack2++) {
154 AliESDMuonTrack* muonTrack2 = esd->GetMuonTrack(iTrack2);
157 if (!muonTrack2->ContainTrackerData()) continue;
159 // keep only opposite sign pairs
160 Short_t charge2 = muonTrack2->Charge();
161 if (charge1*charge2 > 0) continue;
164 Int_t label2 = muonTrack2->GetLabel();
165 muonTrack2->LorentzP(vMu2);
167 // compute kinematics of the pair
169 Float_t mass = vDiMu.M();
170 Float_t p = vDiMu.P();
171 Float_t pt = vDiMu.Pt();
172 Float_t y = vDiMu.Rapidity();
173 Float_t eta = vDiMu.Eta();
174 Float_t phi = vMu1.Phi();
175 if (phi < 0) phi += 2.*TMath::Pi();
177 // fill global histograms
185 // fill histograms according to labels
186 if (label1 >= 0 && label2 >= 0) {
210 } // end of loop over events
213 TCanvas cDiFakesSummary("cDiFakesSummary","cDiFakesSummary",900,600);
214 cDiFakesSummary.Divide(3,2);
215 cDiFakesSummary.cd(1);
216 cDiFakesSummary.GetPad(1)->SetLogy();
218 hMass->SetMinimum(0.5);
219 hMassM->Draw("same");
220 hMassM->SetLineColor(4);
221 hMassF->Draw("same");
222 hMassF->SetLineColor(2);
223 hMassF->SetFillColor(2);
224 hMassF->SetFillStyle(3017);
225 cDiFakesSummary.cd(2);
226 cDiFakesSummary.GetPad(3)->SetLogy();
230 hPM->SetLineColor(4);
232 hPF->SetLineColor(2);
233 hPF->SetFillColor(2);
234 hPF->SetFillStyle(3017);
235 cDiFakesSummary.cd(3);
236 cDiFakesSummary.GetPad(4)->SetLogy();
238 hPt->SetMinimum(0.5);
240 hPtM->SetLineColor(4);
242 hPtF->SetLineColor(2);
243 hPtF->SetFillColor(2);
244 hPtF->SetFillStyle(3017);
245 cDiFakesSummary.cd(4);
246 cDiFakesSummary.GetPad(2)->SetLogy();
250 hYM->SetLineColor(4);
252 hYF->SetLineColor(2);
253 hYF->SetFillColor(2);
254 hYF->SetFillStyle(3017);
255 cDiFakesSummary.cd(5);
256 cDiFakesSummary.GetPad(5)->SetLogy();
258 hEta->SetMinimum(0.5);
260 hEtaM->SetLineColor(4);
262 hEtaF->SetLineColor(2);
263 hEtaF->SetFillColor(2);
264 hEtaF->SetFillStyle(3017);
265 cDiFakesSummary.cd(6);
266 cDiFakesSummary.GetPad(6)->SetLogy();
268 hPhi->SetMinimum(0.5);
270 hPhiM->SetLineColor(4);
272 hPhiF->SetLineColor(2);
273 hPhiF->SetFillColor(2);
274 hPhiF->SetFillStyle(3017);
279 cDiFakesSummary.Write();
289 //-----------------------------------------------------------------------
290 void Prepare(AliMUONRecoParam *&recoParam, Double_t &sigmaCut)
292 /// Set the magnetic field and return recoParam and sigmaCut to associate cluster and trackRef
294 // prepare OCDB access
295 AliCDBManager* man = AliCDBManager::Instance();
296 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
300 // waiting for mag field in CDB
301 if (!TGeoGlobalMagField::Instance()->GetField()) {
302 printf("Loading field map...\n");
303 AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
304 TGeoGlobalMagField::Instance()->SetField(field);
306 // set the magnetic field for track extrapolations
307 AliMUONTrackExtrap::SetField();
309 // Load initial reconstruction parameters from OCDB
310 AliCDBPath path("MUON","Calib","RecoParam");
311 AliCDBEntry *entry=man->Get(path.GetPath());
313 recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject());
315 AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
318 printf("Couldn't find RecoParam object in OCDB: create default one");
319 recoParam = AliMUONRecoParam::GetLowFluxParam();
322 Info("MUONFakes", "\n recontruction parameters:");
323 recoParam->Print("FULL");
324 AliMUONESDInterface::ResetTracker(recoParam);
326 // sigma cut to associate clusters with TrackRefs in case the label are not used
327 sigmaCut = (recoParam->ImproveTracks()) ? recoParam->GetSigmaCutForImprovement() : recoParam->GetSigmaCutForTracking();
331 //-----------------------------------------------------------------------
332 TTree* GetESDTree(TFile *esdFile)
334 /// Check that the file is properly open
335 /// Return pointer to the ESD Tree
337 if (!esdFile || !esdFile->IsOpen()) {
338 Error("GetESDTree", "opening ESD file failed");
342 TTree* tree = (TTree*) esdFile->Get("esdTree");
344 Error("GetESDTree", "no ESD tree found");
352 //-----------------------------------------------------------------------
353 Bool_t TrackMatched(AliMUONTrack &track, AliMUONTrack &trackRef, Float_t &fractionOfMatchCluster, Double_t sigmaCut)
355 /// Try to match 2 tracks
357 Bool_t compTrack[10];
358 Int_t nMatchClusters = track.CompatibleTrack(&trackRef, sigmaCut, compTrack);
359 fractionOfMatchCluster = ((Float_t)nMatchClusters) / ((Float_t)track.GetNClusters());
361 if ((compTrack[0] || compTrack[1] || compTrack[2] || compTrack[3]) && // at least 1 cluster matched in st 1 & 2
362 (compTrack[6] || compTrack[7] || compTrack[8] || compTrack[9]) && // at least 1 cluster matched in st 4 & 5
363 fractionOfMatchCluster > 0.5) return kTRUE; // more than 50% of clusters matched
368 //-----------------------------------------------------------------------
369 AliMUONTrack* MatchWithTrackRef(AliESDMuonTrack &muonTrack, AliMUONVTrackStore &trackRefStore,
370 Float_t &fractionOfMatchCluster, Bool_t useLabel, Double_t sigmaCut)
372 /// Return if the trackRef matched with the reconstructed track and the fraction of matched clusters
374 AliMUONTrack *matchedTrackRef = 0x0;
375 fractionOfMatchCluster = 0.;
377 if (useLabel) { // by using the MC label
379 // get the corresponding simulated track if any
380 Int_t label = muonTrack.GetLabel();
381 matchedTrackRef = (AliMUONTrack*) trackRefStore.FindObject(label);
383 // get the fraction of matched clusters
384 if (matchedTrackRef) {
385 Int_t nMatchClusters = 0;
386 if (muonTrack.ClustersStored()) {
387 AliESDMuonCluster* cluster = (AliESDMuonCluster*) muonTrack.GetClusters().First();
389 if (cluster->GetLabel() == label) nMatchClusters++;
390 cluster = (AliESDMuonCluster*) muonTrack.GetClusters().After(cluster);
393 fractionOfMatchCluster = ((Float_t)nMatchClusters) / ((Float_t)muonTrack.GetNClusters());
396 } else { // by comparing cluster/TrackRef positions
398 // convert ESD track to MUON track
400 AliMUONESDInterface::ESDToMUON(muonTrack,track);
402 // look for the corresponding simulated track if any
403 TIter next(trackRefStore.CreateIterator());
404 AliMUONTrack* trackRef;
405 while ( ( trackRef = static_cast<AliMUONTrack*>(next()) ) ) {
407 // check compatibility
409 if (TrackMatched(track, *trackRef, f, sigmaCut)) {
410 matchedTrackRef = trackRef;
411 fractionOfMatchCluster = f;
419 return matchedTrackRef;