2 #include "AliTRDtrackingAnalysis.h"
11 #include "TGeoMatrix.h"
13 #include "TGraphErrors.h"
17 #include "AliRunLoader.h"
18 #include "AliTRDgeometry.h"
21 #include "AliESDtrack.h"
22 #include "AliTrackReference.h"
24 #include "AliTRDcluster.h"
25 #include "AliTRDCommonParam.h"
26 #include "AliTRDpadPlane.h"
27 #include "AliTRDcalibDB.h"
28 #include "AliTracker.h"
29 #include "AliTRDtracker.h"
30 //#include "AliTRDtracklet.h"
32 #include "TGeoManager.h"
34 //////////////////////////////////////////////////////////////////////////////////////////
36 AliTRDtrackingAnalysis::AliTRDtrackingAnalysis():
73 fDeltaX = new TH1D("deltaX", ";delta X (cm)", 100, -1, 1);
74 fDeltaZ = new TH1D("deltaZ", ";delta Z (cm)", 100, -2, 2);
76 fDeltaYPos = new TH1D("deltaYpos", ";delta Y (mm)", 100, -1, 1);
77 fDeltaYNeg = new TH1D("deltaYneg", ";delta Y (mm)", 100, -1, 1);
79 fNPoints = new TH1D("nPoints", ";np", 40, -0.5, 39.5);
80 fNGood = new TH1D("nGood", ";np", 40, -0.5, 39.5);
82 fDeltaPt = new TH1D("deltaPt", ";delta Pt/Pt (%)", 100, -10, 10);
83 fRefSpace = new TH2D("refSpace", ";y;x", 120, -60, 60, 200, -4, 1);
85 fTrklY = new TH1D("trklY", ";delta Y (mm)", 100, -1, 1);
86 fTrklZ = new TH1D("trklZ", ";delta Z (cm)", 100, -10, 10);
90 fClY2 = new TH1D("clY2", ";delta Y (mm)", 100, -10, 10);
91 fClY3 = new TH1D("clY3", ";delta Y (mm)", 100, -10, 10);
93 for(int i=0; i<12; i++) // bewere hidden constants in the code
94 fClYTgPhi[i] = new TH1D(Form("clYtgPhi%d", i), ";delta Y (mm)", 100, -3, 3);
96 fTgPhi = new TH1D("tgPhi", ";Tg(#phi)", 100, -0.3, 0.3);
97 fGrResTgPhi = new TGraphErrors();
98 fGrMeanTgPhi = new TGraphErrors();
100 //fPullY2 = new TH1D("pullY2", ";pulls Y", 100, -5, 5);
101 //fPullY3 = new TH1D("pullY3", ";pulls Y", 100, -5, 5);
104 fClZ = new TH1D("clZ", ";delta Z (cm)", 200, -20, 20);
105 fClZZ = new TH2D("clZZ", ";z ref;z cl", 600, -300, 300, 600, -300, 300);
107 fClYY = new TH2D("clYY", ";dY;dY", 100, -3, 3, 100, -3, 3);
108 fClYX = new TH2D("clYX", ";Y;X", 250, -60, 60, 100, -4, 1);
110 fNLabels = new TH1D("clLabels", ";n labels", 10, -0.5, 9.5);
111 fBits = new TH1D("bits", ";bits", 10, -0.5, 9.5);
113 fRefDx = new TH1D("refDX", ";delta X", 100, 0, 20);
114 fClPos = new TH2D("clPos", ";z;y", 400, -400, 400, 120, -60, 60);
116 fClZXref = new TH2D("clZXref", ";z;x", 36, -54, 54, 300, 280, 380);
117 fClZXcl = new TH2D("clZXcl", ";z;x", 36, -54, 54, 300, 280, 380);
119 //fGeo = new AliTRDgeometry();
122 //////////////////////////////////////////////////////////////////////////////////////////
124 void AliTRDtrackingAnalysis::DrawResolutionPt(int startEvent, int stopEvent) {
128 // loop over ESD events
129 int nevents = fEsdTree->GetEntries();
131 for(int iEvent=startEvent; iEvent<nevents && iEvent < stopEvent; iEvent++) {
133 Info("Draw", "Event = %d", iEvent);
135 fEsdTree->GetEvent(iEvent);
136 fLoader->GetEvent(iEvent);
139 int nTracks = fESD->GetNumberOfTracks();
140 for(int iTrack=0; iTrack<nTracks; iTrack++) {
142 //Info("Track", "Track = %d", iTrack);
143 AliESDtrack *esdTrack = fESD->GetTrack(iTrack);
144 if (!esdTrack->GetInnerParam()) continue;
145 const AliExternalTrackParam *param = esdTrack->GetOuterParam();
146 int status = esdTrack->GetStatus();
148 if (!(status & AliESDtrack::kTRDout)) continue;
149 if (!(status & AliESDtrack::kTRDrefit)) continue;
150 if (TMath::Abs(esdTrack->GetOuterParam()->GetPt()) < 1.0) continue;
153 while(param->GetX() > fGeo->GetTime0(ch)+2) ch++;
154 fRefSpace->Fill(2.*ch+0.5, param->GetX() - fGeo->GetTime0(ch));
155 //if (ch < 5) continue;
158 int label = abs(esdTrack->GetTRDLabel());
162 for(int iPoint=GetReference(label); iPoint<fRefTRD->GetEntries(); iPoint++) {
164 AliTrackReference *aRef = (AliTrackReference*)(*fRefTRD)[iPoint];
165 if (aRef->GetTrack() != label) break;
168 lastX = (aRef->LocalX() < lastX)? lastX : aRef->LocalX();
169 double dx = aRef->LocalX() - param->GetX();
170 if (TMath::Abs(dx) > 1.) continue;
173 double bz=fESD->GetMagneticField();
174 AliExternalTrackParam out(*param);
175 out.PropagateTo(aRef->LocalX(),bz);
177 double dp = aRef->Pt() + out.GetPt();
178 double dy = 10. * (aRef->LocalY() - out.GetY()); // in mm
180 fDeltaPt->Fill(100. * dp / aRef->Pt());
181 //fDeltaPt->Fill(out.GetPt() / aRef->Pt());
184 if (esdTrack->GetSign() > 0) fDeltaYPos->Fill(dy);
185 else fDeltaYNeg->Fill(dy);
187 fDeltaZ->Fill(aRef->Z() - out.GetZ());
190 //if (ngood == 0) Info("X", "N = %d, X = %f, DX = %f", ntr, param->GetX(), param->GetX()-lastX);
225 //////////////////////////////////////////////////////////////////////////////////////////
227 // void AliTRDtrackingAnalysis::DrawTrackletResolution(int startEvent, int stopEvent) {
229 // LoadRecPointsFile();
231 // TFile *file = new TFile(Form("%s/TRD.Tracklets.root", fPath), "read");
232 // TTree *tree = (TTree*)file->Get("TRDtracklets");
234 // AliTRDtracklet *tracklet = new AliTRDtracklet();
235 // tree->SetBranchAddress("tracklets", &tracklet);
237 // for(int ev=startEvent; ev<stopEvent; ev++) {
239 // gAlice->GetEvent(ev);
242 // int N = tree->GetEntries();
243 // for(int i=0; i<N; i++) {
245 // tree->GetEntry(i);
247 // Double_t yref, zref, tgphi;
248 // int stat = GetMCPosition(tracklet->GetLabel(), tracklet->GetX(), yref, zref, tgphi);
249 // if (stat < 0) continue;
251 // int plane = tracklet->GetPlane();
252 // Double_t h01 = tracklet->GetTilt();
254 // //printf("Tile = %f\tcorrection = %f um \n", h01, 1e4 * h01 * (tracklet->GetZ()-zref));
255 // //double dz = zref - tracklet->GetZ() - cls->GetZ();
257 // fTrklY->Fill(10 * (tracklet->GetY() - yref));
258 // fTrklZ->Fill(tracklet->GetZ() - zref);
261 // while(tracklet->GetX() > fGeo->GetTime0(ch)+2) ch++;
262 // fRefSpace->Fill(tracklet->GetY(), tracklet->GetX() - fGeo->GetTime0(ch));
270 // fRefSpace->Draw();
272 // gStyle->SetOptFit(1);
275 // fTrklY->Fit("gaus");
281 //////////////////////////////////////////////////////////////////////////////////////////
283 void AliTRDtrackingAnalysis::DrawRecPointResolution(int startEvent, int stopEvent) {
286 TObjArray *module = new TObjArray();
288 int nEvents = gAlice->GetEventsPerRun();
290 for(int ev=startEvent; ev<nEvents && ev < stopEvent; ev++) {
292 gAlice->GetEvent(ev);
295 TTree *tree = fLoader->GetTreeR("TRD", 0);
296 tree->SetBranchAddress("TRDcluster", &module);
298 Info("Res", "Refs Loaded");
300 int N = tree->GetEntries();
301 for(int i=0; i<N; i++) {
304 int m = module->GetEntries();
306 for(int j=0; j<m; j++) {
308 AliTRDcluster *cls = (AliTRDcluster*)module->At(j);
309 if (cls->GetQ() < 10) continue;
310 fTracker->Transform(cls);
311 fClPos->Fill(cls->GetZ(), cls->GetY());
313 int plane = fGeo->GetPlane(cls->GetDetector());
316 for(int k=0; k<3; k++) if (cls->GetLabel(k) > -1) nl++;
319 Double_t yref, zref, tgphi;
320 int stat = GetMCPosition(cls->GetLabel(0), cls->GetX(), yref, zref, tgphi);
321 if (stat < 0) continue;
323 fClZXcl->Fill(cls->GetZ(), cls->GetX());
324 fClZXref->Fill(zref, cls->GetX());
326 AliTRDpadPlane *padPlane = AliTRDCommonParam::Instance()->GetPadPlane(plane,0);
327 Double_t h01 = TMath::Tan(-TMath::Pi() / 180.0 * padPlane->GetTiltingAngle());
329 //double dz = zref - padPlane->GetRow0();
330 double dz = zref - cls->GetZ();
331 double dy = dz * h01;
332 double yy = cls->GetY() - dy;
334 if (cls->From2pad()) fClY2->Fill(10 * (yy - yref));
335 if (cls->From3pad()) fClY3->Fill(10 * (yy - yref));
337 int idx = GetPhiBin(tgphi);
338 if (idx >= 0 && idx < 12) fClYTgPhi[idx]->Fill(10 * (yy - yref));
340 fClZZ->Fill(zref, cls->GetZ());
343 fClYX->Fill(cls->GetY(), cls->GetX() - fGeo->GetTime0(plane));
359 gStyle->SetOptFit(1);
364 fClY2->Fit("gaus", "", "", -2*fClY2->GetRMS(), 2*fClY2->GetRMS());
369 fClY3->Fit("gaus", "", "", -2*fClY3->GetRMS(), 2*fClY3->GetRMS());
381 TCanvas *c = new TCanvas();
384 for(int i=0; i<12; i++) {
387 fClYTgPhi[i]->Draw();
388 if (fClYTgPhi[i]->GetSum() < 100) continue;
390 double mean = fClYTgPhi[i]->GetMean();
391 double rms = fClYTgPhi[i]->GetRMS();
393 fClYTgPhi[i]->Fit("gaus", "", "", mean-2*rms, mean+2*rms);
394 TF1 *f = fClYTgPhi[i]->GetFunction("gaus");
396 int n = fGrResTgPhi->GetN();
397 fGrResTgPhi->SetPoint(n, GetPhi(i), f->GetParameter(2));
398 fGrResTgPhi->SetPointError(n, 0, f->GetParError(2));
400 fGrMeanTgPhi->SetPoint(n, GetPhi(i), f->GetParameter(1));
401 fGrMeanTgPhi->SetPointError(n, 0, f->GetParError(1));
404 //gSystem->Sleep(1000);
405 gStyle->SetOptStat(0);
408 TH1D *dummy = new TH1D("dummy", "", 100, -0.3, 0.3);
410 dummy->SetTitle(";tg(#phi);resolution (mm)");
411 dummy->SetMinimum(0);
412 dummy->SetMaximum(1);
415 (dummy->Clone("dummy1"))->Draw();
417 fGrResTgPhi->Draw("PL");
418 fGrResTgPhi->GetHistogram()->SetTitle(";tg(#phi);resolution (mm)");
419 fGrResTgPhi->SetMarkerStyle(20);
422 dummy->SetTitle(";tg(#phi);mean value (mm)");
423 dummy->SetMinimum(-0.3);
424 dummy->SetMaximum(0.3);
427 (dummy->Clone("dummy2"))->Draw();
429 fGrMeanTgPhi->Draw("PL");
430 fGrMeanTgPhi->GetHistogram()->SetTitle(";tg(#phi);mean value (mm)");
431 fGrMeanTgPhi->SetMarkerStyle(20);
436 //fClZZ->Draw("colz");
439 //fClPos->Draw("colz");
449 //////////////////////////////////////////////////////////////////////////////////////////
451 void AliTRDtrackingAnalysis::LoadRecPointsFile() {
454 sprintf(filename, "%s/galice.root", fPath);
456 fLoader = AliRunLoader::Open(filename);
458 Error("CheckFiles", "getting run loader from file %s/galice.root failed", filename);
462 fLoader->LoadgAlice();
463 gAlice = fLoader->GetAliRun();
466 Error("CheckFiles", "no galice object found");
470 fLoader->LoadKinematics();
471 fLoader->LoadHeader();
472 fLoader->LoadTrackRefs();
474 //TGeoManager::Import("/data/alice_u/radomski/condor/run_0/geometry.root");
475 TGeoManager::Import(Form("%s/geometry.root", fPath));
479 fGeo = (AliTRDgeometry*)gDirectory->Get("TRDgeometry");
480 fTracker = new AliTRDtracker(gFile);
482 fLoader->LoadRecPoints("TRD");
484 AliTracker::SetFieldMap(gAlice->Field(), 1);
487 //////////////////////////////////////////////////////////////////////////////////////////
489 void AliTRDtrackingAnalysis::CheckFiles() {
494 sprintf(filename, "%s/galice.root", fPath);
496 fLoader = AliRunLoader::Open(filename);
498 Error("CheckFiles", "getting run loader from file %s/galice.root failed", filename);
502 fLoader->LoadgAlice();
503 gAlice = fLoader->GetAliRun();
506 Error("CheckFiles", "no galice object found");
510 fLoader->LoadKinematics();
511 fLoader->LoadHeader();
512 fLoader->LoadTrackRefs();
515 fGeo = (AliTRDgeometry*)gDirectory->Get("TRDgeometry");
516 //fGeo->ReadGeoMatrices();
520 sprintf(filename,"%s/AliESDs.root", fPath);
521 TFile *esdFile = new TFile(filename, "READ");
523 if (esdFile->IsZombie()) {
524 Error("CheckFiles", "file not present: AliESDs.root");
528 fEsdTree = (TTree*)esdFile->Get("esdTree");
531 fEsdTree->SetBranchAddress("ESD", &fESD);
534 //////////////////////////////////////////////////////////////////////////////////////////
536 void AliTRDtrackingAnalysis::LoadRefs() {
538 if (fRefTPC) delete fRefTPC;
539 if (fRefTRD) delete fRefTRD;
541 fRefTPC = new TObjArray();
542 fRefTRD = new TObjArray();
544 //fLoader->GetEvent(event);
545 //AliStack* stack = gAlice->Stack();
546 TTree *refTree = fLoader->TreeTR();
548 const int nBranch = 2;
549 const char *brName[] = {"TPC", "TRD"};
550 TClonesArray *clRefs = new TClonesArray("AliTrackReference");
552 for(int b=0; b<nBranch; b++) {
554 TBranch *branch = refTree->GetBranch(brName[b]);
555 refTree->SetBranchAddress(brName[b],&clRefs);
557 int nEntries = branch->GetEntries();
558 for(int iTrack = 0; iTrack < nEntries; iTrack++) {
560 refTree->GetEvent(iTrack);
561 int nPoints = clRefs->GetEntries();
562 for(int iPoint=0; iPoint<nPoints; iPoint++) {
563 AliTrackReference *ref = (AliTrackReference*)clRefs->At(iPoint);
564 if (b == 0) fRefTPC->Add(new AliTrackReference(*ref));
565 if (b == 1) fRefTRD->Add(new AliTrackReference(*ref));
573 for(int i=0; i<fRefTRD->GetEntries(); i++) {
574 AliTrackReference *ref = (AliTrackReference*)(*fRefTRD)[i];
575 fLabels[i] = ref->GetTrack();
578 while(ref->LocalX() > fGeo->GetTime0(p)+2) p++;
579 fRefSpace->Fill(ref->LocalY(), ref->LocalX()-fGeo->GetTime0(p));
581 //for(int bit=0; bit<9; bit++) if (ref->TestBit(bit)) fBits->Fill(bit);
585 Info("LoadRefs", "TPC = %d\t TRD = %d", fRefTPC->GetEntries(), fRefTRD->GetEntries());
588 //////////////////////////////////////////////////////////////////////////////////////////
590 Int_t AliTRDtrackingAnalysis::GetReference(Int_t label) {
592 int start = TMath::BinarySearch(fRefTRD->GetEntries(), fLabels, label);
595 AliTrackReference *ref = (AliTrackReference*)(*fRefTRD)[start];
596 if (ref->GetTrack() != label) return start+1;
603 //////////////////////////////////////////////////////////////////////////////////////////
605 int AliTRDtrackingAnalysis::GetMCPosition(Int_t label, Double_t x, Double_t &Y, Double_t &Z, Double_t &tgphi) {
613 int idx = GetReference(label);
614 for(int i=idx; i<fRefTRD->GetEntries(); i++) {
616 AliTrackReference *ref = (AliTrackReference*)(*fRefTRD)[i];
617 if (ref->GetTrack() != label) break;
621 //while(ref->LocalX() > fGeo->GetTime0(p)+2) p++;
622 //if (p != layer) continue;
624 double dX = ref->LocalX()-x;
639 if (idLow == -1 || idHigh == -1) return -1;
641 AliTrackReference *refI = (AliTrackReference*)(*fRefTRD)[idLow];
642 AliTrackReference *refO = (AliTrackReference*)(*fRefTRD)[idHigh];
645 double dx = refO->LocalX() - refI->LocalX();
646 double dy = refO->LocalY() - refI->LocalY();
647 double dz = refO->Z() - refI->Z();
648 double ddx = (x - refI->LocalX())/dx;
652 Y = refI->LocalY() + ddx * dy;
653 Z = refI->Z() + ddx * dz;
660 //////////////////////////////////////////////////////////////////////////////////////////
661 Int_t AliTRDtrackingAnalysis::GetPhiBin(Double_t phi) {
662 return (int)((phi+0.3)/0.05);
665 //////////////////////////////////////////////////////////////////////////////////////////
667 Double_t AliTRDtrackingAnalysis::GetPhi(Int_t bin) {
668 return bin * 0.05 - 0.3 + 0.025;
670 //////////////////////////////////////////////////////////////////////////////////////////