6 #include "TClonesArray.h"
12 #include "TBenchmark.h"
14 #include "AliAnalysisTask.h"
15 #include "AliAnalysisManager.h"
18 #include "AliVEvent.h"
19 #include "AliESDEvent.h"
20 #include "AliMCEvent.h"
21 #include "AliESDtrack.h"
22 #include "AliTrackReference.h"
23 #include "AliMCComparisonTrack.h"
25 #include "AliTRDComparisonTask.h"
27 ClassImp(AliTRDComparisonTask)
29 AliTRDComparisonTask::AliTRDComparisonTask()
30 : AliAnalysisTaskSE("AliTRDComparisonTask"),
46 // Default constructor
47 AliInfo("Default constructor AliTRDComparisonTask");
48 // Define input and output slots here
49 // Input slot #0 works with a TChain
50 DefineInput(0, TChain::Class());
51 // Output slot #1 TList
52 DefineOutput(1, TList::Class());
55 AliTRDComparisonTask::AliTRDComparisonTask(const char* name)
56 : AliAnalysisTaskSE(name),
73 AliInfo("Constructor AliTRDComparisonTask");
74 // Define input and output slots here
75 // Input slot #0 works with a TChain
76 DefineInput(0, TChain::Class());
77 // Output slot #1 TList
78 DefineOutput(1, TList::Class());
83 void AliTRDComparisonTask::UserCreateOutputObjects()
87 AliInfo("AliTRDComparisonTask::UserCreateOutputObjects");
88 // Create output container
89 fListOfHistos = new TList();
91 hgood = new TH1F("hgood", "Pt for good tracks", 34, 0.2, 7.0);
92 hfound = new TH1F("hfound", "Pt for found tracks", 34, 0.2, 7.0);
93 hfake = new TH1F("hfake", "Pt for fake tracks", 34, 0.2, 7.0);
94 hp = new TH1F("hp", "PHI resolution", 50, -20., 20.);
95 hl = new TH1F("hl", "LAMBDA resolution", 50, -20., 20.);
96 hpt = new TH1F("hpt", "Relative Pt resolution", 30, -10., 10.);
97 hmpt = new TH1F("hmpt", "Y and Z resolution", 30, -30., 30.);
98 he = new TH1F("he", "dE/dX for pions with 0.4<p<0.5 GeV/c", 50, 0., 1000.);
99 hep = new TH2F("hep", "dE/dX vs momentum", 50, 0., 2., 50, 0., 2000.);
100 hgoodPhi = new TH1F("hgoodPhi", "Phi for Good tracks", 90, 0., 2.*TMath::Pi());
101 hfoundPhi = new TH1F("hfoundPhi", "Phi for Found tracks", 90, 0., 2.*TMath::Pi());
102 hz = new TH1F("hz", "Z resolution", 30, -30., 30.);
103 hc = new TH1F("hc", "Number of the assigned clusters", 25, 110., 135.);
105 fListOfHistos->Add(hgood);
106 fListOfHistos->Add(hfound);
107 fListOfHistos->Add(hfake);
108 fListOfHistos->Add(hp);
109 fListOfHistos->Add(hl);
110 fListOfHistos->Add(hpt);
111 fListOfHistos->Add(hmpt);
112 fListOfHistos->Add(he);
113 fListOfHistos->Add(hep);
114 fListOfHistos->Add(hgoodPhi);
115 fListOfHistos->Add(hfoundPhi);
116 fListOfHistos->Add(hz);
117 fListOfHistos->Add(hc);
121 void AliTRDComparisonTask::UserExec(Option_t *)
125 // Called for each event
128 AliMCEvent* mcEvent = MCEvent();
130 Printf("ERROR: Could not retrieve MC event");
136 TClonesArray dummy("AliMCComparisonTrack",1000), *refs=&dummy;
138 // Loop over all MC tracks and select "good" tracks
139 for (Int_t iTracks = 0; iTracks < mcEvent->GetNumberOfTracks(); iTracks++) {
140 AliMCParticle* track = mcEvent->GetTrack(iTracks);
142 Printf("ERROR: Could not receive track %d (mc loop)", iTracks);
147 if (track->Pt() < 0.2) continue;
148 if (track->Pt() > 7.0) continue;
149 if (TMath::Abs(track->Pz()/track->Pt()) > 0.999) continue;
151 Double_t vx = track->Xv(), vy = track->Yv(), vz = track->Zv();
152 if (TMath::Sqrt(vx*vx+vy*vy) > 3.5) continue;
153 if (TMath::Abs(vz) > 50.) continue;
155 // Check TRD information
156 Int_t nRefs = track->GetNumberOfTrackReferences();
157 if (nRefs <= 1) continue;
159 AliTrackReference* trackRef0 = 0;
160 for (Int_t iTrackRef = 0; iTrackRef < nRefs; iTrackRef++) {
161 trackRef0 = track->GetTrackReference(iTrackRef);
163 Int_t detectorId = trackRef0->DetectorId();
164 if (detectorId == AliTrackReference::kTRD) {
170 if (!trackRef0) continue;
172 if (trackRef0->LocalX() > 300.) continue;
174 AliTrackReference* trackRef = 0;
175 for (Int_t iTrackRef = nRefs - 1; iTrackRef >= 0; --iTrackRef) {
176 trackRef = track->GetTrackReference(iTrackRef);
177 if (!trackRef) continue;
178 if (trackRef->LocalX() > 363. &&
179 trackRef->DetectorId() == AliTrackReference::kTRD) break;
182 if (!trackRef) continue;
184 if (TMath::Abs(trackRef0->Alpha() - trackRef->Alpha()) > 1e-5) continue;
186 // Check TPC information
187 Bool_t LabelTPC = kFALSE;
188 for (Int_t iTrackRef = 0; iTrackRef < nRefs; iTrackRef++) {
189 trackRef = track->GetTrackReference(iTrackRef);
191 Int_t detectorId = trackRef->DetectorId();
192 if (detectorId == AliTrackReference::kTPC) {
197 } // track references loop
201 AliMCComparisonTrack* ref = new((*refs)[nt]) AliMCComparisonTrack();
202 ref->SetLabel(iTracks);
203 TParticle* particle = track->Particle();
204 Int_t pdg = particle->GetPdgCode();
206 ref->SetPz(trackRef->Pz());
207 Float_t Pt = trackRef->Pt();
210 Float_t phig = trackRef->Phi();
212 hgoodPhi->Fill(phig);
213 ref->SetLocalX(trackRef->LocalX());
214 ref->SetLocalY(trackRef->LocalY());
215 ref->SetZ(trackRef->Z());
222 AliVEvent* event = InputEvent();
224 Printf("ERROR: Could not retrieve event");
228 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event);
235 Int_t MCgoods = refs->GetEntriesFast();
237 // Loop over all "good" MC tracks
238 for (Int_t k = 0; k < MCgoods; k++) {
239 AliMCComparisonTrack* ref = (AliMCComparisonTrack*)refs->UncheckedAt(k);
241 Int_t MCLabel = ref->GetLabel();
242 Float_t ptg = ref->GetPt();
243 Float_t PhiG = ref->GetPhi();
245 for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) {
246 AliESDtrack* track = esd->GetTrack(iTrack);
248 Printf("ERROR: Could not receive track %d", iTrack);
252 if (! track->IsOn(AliESDtrack::kTRDout)) continue;
253 const AliExternalTrackParam * outorig = track->GetOuterParam();
254 if (!outorig) continue;
256 Int_t Label = track->GetTRDLabel();
258 if (MCLabel == TMath::Abs(Label)) {
259 if (MCLabel == Label) {
262 hfoundPhi->Fill(PhiG);
270 AliExternalTrackParam out(*outorig);
272 Double_t bz = esd->GetMagneticField();
273 Double_t xg = ref->GetLocalX();
274 out.PropagateTo(xg,bz);
276 Float_t phi = TMath::ASin(out.GetSnp()) + out.GetAlpha();
277 if (phi < 0) phi += 2*TMath::Pi();
278 if (phi >= 2*TMath::Pi()) phi -= 2*TMath::Pi();
279 Float_t phig = ref->GetPhi();
280 hp->Fill((phi - phig)*1000.);
282 Float_t lam = TMath::ATan(out.GetTgl());
283 Float_t lamg = TMath::ATan2(ref->GetPz(), ptg);
284 hl->Fill((lam - lamg)*1000.);
286 hc->Fill(track->GetTRDclusters(0));
288 Float_t pt_1 = out.OneOverPt();
289 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
291 Float_t y = out.GetY();
292 Float_t yg = ref->GetLocalY();
293 hmpt->Fill(10*(y - yg));
295 Float_t z = out.GetZ();
296 Float_t zg = ref->GetZ();
297 hz->Fill(10.*(z - zg));
299 Float_t mom = 1./(pt_1*TMath::Cos(lam));
300 Float_t dedx = track->GetTRDsignal();
301 Printf (" dedx = %f ", dedx);
302 hep->Fill(mom, dedx, 1.);
304 Int_t pdg = ref->GetPDG();
305 if (TMath::Abs(pdg)==211) //pions
306 if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
316 Printf(" Results: " );
317 Printf(" Good %d Found %d Fake %d Lost %d ", nt, nfound, nfake, nlost);
322 PostData(1, fListOfHistos);
326 void AliTRDComparisonTask::Terminate(Option_t *) {
327 // Draw result to the screen
328 // Called once at the end of the query
329 fListOfHistos = dynamic_cast<TList*>(GetOutputData(1));
330 if (!fListOfHistos) {
331 Printf("ERROR: fListOfHistos not available");
335 hgood = dynamic_cast<TH1F*>(fListOfHistos->At(0));
336 hfound = dynamic_cast<TH1F*>(fListOfHistos->At(1));
337 hfake = dynamic_cast<TH1F*>(fListOfHistos->At(2));
338 hp = dynamic_cast<TH1F*>(fListOfHistos->At(3));
339 hl = dynamic_cast<TH1F*>(fListOfHistos->At(4));
340 hpt = dynamic_cast<TH1F*>(fListOfHistos->At(5));
341 hmpt = dynamic_cast<TH1F*>(fListOfHistos->At(6));
342 he = dynamic_cast<TH1F*>(fListOfHistos->At(7));
343 hep = dynamic_cast<TH2F*>(fListOfHistos->At(8));
344 hgoodPhi = dynamic_cast<TH1F*>(fListOfHistos->At(9));
345 hfoundPhi = dynamic_cast<TH1F*>(fListOfHistos->At(10));
346 hz = dynamic_cast<TH1F*>(fListOfHistos->At(11));
347 hc = dynamic_cast<TH1F*>(fListOfHistos->At(12));
349 gStyle->SetOptStat(111110);
350 gStyle->SetOptFit(1);
352 TCanvas* c1 = new TCanvas("c1", "", 0, 0, 700, 850);
356 TPad* p1 = new TPad("p1", "", 0., 0.3, 0.5, 0.6); p1->Draw();
357 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
358 hp->SetFillColor(4); hp->SetXTitle("(mrad)");
359 if (hp->GetEntries() < minc) hp->Draw(); else hp->Fit("gaus"); c1->cd();
361 TPad* p2 = new TPad("p2", "", 0.5, 0.3, 1., 0.6); p2->Draw();
362 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
363 hl->SetFillColor(4); hl->SetXTitle("(mrad)");
364 if (hl->GetEntries() < minc) hl->Draw(); else hl->Fit("gaus"); c1->cd();
366 TPad* p3 = new TPad("p3", "", 0., 0., 0.5, 0.3); p3->Draw();
367 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
368 hpt->SetFillColor(2); hpt->SetXTitle("(%)");
369 if (hpt->GetEntries() < minc) hpt->Draw(); else hpt->Fit("gaus"); c1->cd();
371 TPad* p4 = new TPad("p4", "", 0.5, 0., 1., 0.3); p4->Draw();
372 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
373 hmpt->SetFillColor(6); hmpt->SetXTitle("(mm)");
374 if (hmpt->GetEntries() < minc) hmpt->Draw(); else hmpt->Fit("gaus");
375 hz->Draw("same"); c1->cd();
377 TPad* p5 = new TPad("p5", "", 0., 0.6, 1., 1.); p5->Draw(); p5->cd();
378 p5->SetFillColor(41); p5->SetFrameFillColor(10);
379 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
380 TH1F* hg = new TH1F("hg", "Efficiency for good tracks", 34, 0.2, 7.0);
381 TH1F* hf = new TH1F("hf", "Efficiency for fake tracks", 34, 0.2, 7.0);
382 hg->Divide(hfound,hgood,1.,1.,"B");
383 hf->Divide(hfake,hgood,1.,1.,"B");
385 hg->SetYTitle("Tracking efficiency");
386 hg->SetXTitle("Pt (GeV/c)");
389 TLine* line1 = new TLine(0.2, 1.0, 7.0, 1.0); line1->SetLineStyle(4);
391 TLine* line2 = new TLine(0.2, 0.9, 7.0, 0.9); line2->SetLineStyle(4);
395 hf->SetFillStyle(3013);
398 hf->Draw("histsame");
399 TText* text = new TText(0.461176, 0.248448, "Fake tracks");
400 text->SetTextSize(0.05);
402 text = new TText(0.453919, 1.11408, "Good tracks");
403 text->SetTextSize(0.05);
406 TCanvas* c2 = new TCanvas("c2", "", 320, 32, 530, 590);
408 TPad* p6 = new TPad("p6", "", 0., 0., 1., .5); p6->Draw();
409 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
410 he->SetFillColor(2); he->SetFillStyle(3005);
411 he->SetXTitle("Arbitrary Units");
412 if (he->GetEntries() < minc) he->Draw(); else he->Fit("gaus"); c2->cd();
414 TPad* p7 = new TPad("p7", "", 0., 0.5, 1., 1.); p7->Draw();
415 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
416 hep->SetMarkerStyle(8); hep->SetMarkerSize(0.4);
417 hep->SetFillColor(2); hep->SetFillStyle(3005);
418 hep->SetXTitle("p (GeV/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
419 hep->Draw(); c1->cd();
421 TCanvas* c3 = new TCanvas("c3", "", 10, 10, 510, 510);
422 c3->SetFillColor(42); c3->SetFrameFillColor(10);
423 hfoundPhi->Sumw2(); hgoodPhi->Sumw2();
424 TH1F* hgphi = new TH1F("hgphi", "Efficiency for good tracks (Phi)",
425 90, 0., 2.*TMath::Pi());
426 hgphi->Divide(hfoundPhi, hgoodPhi, 1., 1., "B");
427 hgphi->SetYTitle("Tracking efficiency");
428 hgphi->SetXTitle("Phi (rad)");
431 TFile fc("AliTRDComparison.root","RECREATE");