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():
45 fDeltaX = new TH1D("deltaX", ";delta X (cm)", 100, -1, 1);
46 fDeltaZ = new TH1D("deltaZ", ";delta Z (cm)", 100, -2, 2);
48 fDeltaYPos = new TH1D("deltaYpos", ";delta Y (mm)", 100, -1, 1);
49 fDeltaYNeg = new TH1D("deltaYneg", ";delta Y (mm)", 100, -1, 1);
51 fNPoints = new TH1D("nPoints", ";np", 40, -0.5, 39.5);
52 fNGood = new TH1D("nGood", ";np", 40, -0.5, 39.5);
54 fDeltaPt = new TH1D("deltaPt", ";delta Pt/Pt (%)", 100, -10, 10);
55 fRefSpace = new TH2D("refSpace", ";y;x", 120, -60, 60, 200, -4, 1);
57 fTrklY = new TH1D("trklY", ";delta Y (mm)", 100, -1, 1);
58 fTrklZ = new TH1D("trklZ", ";delta Z (cm)", 100, -10, 10);
62 fClY2 = new TH1D("clY2", ";delta Y (mm)", 100, -10, 10);
63 fClY3 = new TH1D("clY3", ";delta Y (mm)", 100, -10, 10);
65 for(int i=0; i<12; i++) // bewere hidden constants in the code
66 fClYTgPhi[i] = new TH1D(Form("clYtgPhi%d", i), ";delta Y (mm)", 100, -3, 3);
68 fTgPhi = new TH1D("tgPhi", ";Tg(#phi)", 100, -0.3, 0.3);
69 fGrResTgPhi = new TGraphErrors();
70 fGrMeanTgPhi = new TGraphErrors();
72 //fPullY2 = new TH1D("pullY2", ";pulls Y", 100, -5, 5);
73 //fPullY3 = new TH1D("pullY3", ";pulls Y", 100, -5, 5);
76 fClZ = new TH1D("clZ", ";delta Z (cm)", 200, -20, 20);
77 fClZZ = new TH2D("clZZ", ";z ref;z cl", 600, -300, 300, 600, -300, 300);
79 fClYY = new TH2D("clYY", ";dY;dY", 100, -3, 3, 100, -3, 3);
80 fClYX = new TH2D("clYX", ";Y;X", 250, -60, 60, 100, -4, 1);
82 fNLabels = new TH1D("clLabels", ";n labels", 10, -0.5, 9.5);
83 fBits = new TH1D("bits", ";bits", 10, -0.5, 9.5);
85 fRefDx = new TH1D("refDX", ";delta X", 100, 0, 20);
86 fClPos = new TH2D("clPos", ";z;y", 400, -400, 400, 120, -60, 60);
88 fClZXref = new TH2D("clZXref", ";z;x", 36, -54, 54, 300, 280, 380);
89 fClZXcl = new TH2D("clZXcl", ";z;x", 36, -54, 54, 300, 280, 380);
91 //fGeo = new AliTRDgeometry();
94 //////////////////////////////////////////////////////////////////////////////////////////
96 void AliTRDtrackingAnalysis::DrawResolutionPt(int startEvent, int stopEvent) {
100 // loop over ESD events
101 int nevents = fEsdTree->GetEntries();
103 for(int iEvent=startEvent; iEvent<nevents && iEvent < stopEvent; iEvent++) {
105 Info("Draw", "Event = %d", iEvent);
107 fEsdTree->GetEvent(iEvent);
108 fLoader->GetEvent(iEvent);
111 int nTracks = fESD->GetNumberOfTracks();
112 for(int iTrack=0; iTrack<nTracks; iTrack++) {
114 //Info("Track", "Track = %d", iTrack);
115 AliESDtrack *esdTrack = fESD->GetTrack(iTrack);
116 if (!esdTrack->GetInnerParam()) continue;
117 const AliExternalTrackParam *param = esdTrack->GetOuterParam();
118 int status = esdTrack->GetStatus();
120 if (!(status & AliESDtrack::kTRDout)) continue;
121 if (!(status & AliESDtrack::kTRDrefit)) continue;
122 if (TMath::Abs(esdTrack->GetOuterParam()->GetPt()) < 1.0) continue;
125 while(param->GetX() > fGeo->GetTime0(ch)+2) ch++;
126 fRefSpace->Fill(2.*ch+0.5, param->GetX() - fGeo->GetTime0(ch));
127 //if (ch < 5) continue;
130 int label = abs(esdTrack->GetTRDLabel());
134 for(int iPoint=GetReference(label); iPoint<fRefTRD->GetEntries(); iPoint++) {
136 AliTrackReference *aRef = (AliTrackReference*)(*fRefTRD)[iPoint];
137 if (aRef->GetTrack() != label) break;
140 lastX = (aRef->LocalX() < lastX)? lastX : aRef->LocalX();
141 double dx = aRef->LocalX() - param->GetX();
142 if (TMath::Abs(dx) > 1.) continue;
145 double bz=fESD->GetMagneticField();
146 AliExternalTrackParam out(*param);
147 out.PropagateTo(aRef->LocalX(),bz);
149 double dp = aRef->Pt() + out.GetPt();
150 double dy = 10. * (aRef->LocalY() - out.GetY()); // in mm
152 fDeltaPt->Fill(100. * dp / aRef->Pt());
153 //fDeltaPt->Fill(out.GetPt() / aRef->Pt());
156 if (esdTrack->GetSign() > 0) fDeltaYPos->Fill(dy);
157 else fDeltaYNeg->Fill(dy);
159 fDeltaZ->Fill(aRef->Z() - out.GetZ());
162 //if (ngood == 0) Info("X", "N = %d, X = %f, DX = %f", ntr, param->GetX(), param->GetX()-lastX);
197 //////////////////////////////////////////////////////////////////////////////////////////
199 // void AliTRDtrackingAnalysis::DrawTrackletResolution(int startEvent, int stopEvent) {
201 // LoadRecPointsFile();
203 // TFile *file = new TFile(Form("%s/TRD.Tracklets.root", fPath), "read");
204 // TTree *tree = (TTree*)file->Get("TRDtracklets");
206 // AliTRDtracklet *tracklet = new AliTRDtracklet();
207 // tree->SetBranchAddress("tracklets", &tracklet);
209 // for(int ev=startEvent; ev<stopEvent; ev++) {
211 // gAlice->GetEvent(ev);
214 // int N = tree->GetEntries();
215 // for(int i=0; i<N; i++) {
217 // tree->GetEntry(i);
219 // Double_t yref, zref, tgphi;
220 // int stat = GetMCPosition(tracklet->GetLabel(), tracklet->GetX(), yref, zref, tgphi);
221 // if (stat < 0) continue;
223 // int plane = tracklet->GetPlane();
224 // Double_t h01 = tracklet->GetTilt();
226 // //printf("Tile = %f\tcorrection = %f um \n", h01, 1e4 * h01 * (tracklet->GetZ()-zref));
227 // //double dz = zref - tracklet->GetZ() - cls->GetZ();
229 // fTrklY->Fill(10 * (tracklet->GetY() - yref));
230 // fTrklZ->Fill(tracklet->GetZ() - zref);
233 // while(tracklet->GetX() > fGeo->GetTime0(ch)+2) ch++;
234 // fRefSpace->Fill(tracklet->GetY(), tracklet->GetX() - fGeo->GetTime0(ch));
242 // fRefSpace->Draw();
244 // gStyle->SetOptFit(1);
247 // fTrklY->Fit("gaus");
253 //////////////////////////////////////////////////////////////////////////////////////////
255 void AliTRDtrackingAnalysis::DrawRecPointResolution(int startEvent, int stopEvent) {
258 TObjArray *module = new TObjArray();
260 int nEvents = gAlice->GetEventsPerRun();
262 for(int ev=startEvent; ev<nEvents && ev < stopEvent; ev++) {
264 gAlice->GetEvent(ev);
267 TTree *tree = fLoader->GetTreeR("TRD", 0);
268 tree->SetBranchAddress("TRDcluster", &module);
270 Info("Res", "Refs Loaded");
272 int N = tree->GetEntries();
273 for(int i=0; i<N; i++) {
276 int m = module->GetEntries();
278 for(int j=0; j<m; j++) {
280 AliTRDcluster *cls = (AliTRDcluster*)module->At(j);
281 if (cls->GetQ() < 10) continue;
282 fTracker->Transform(cls);
283 fClPos->Fill(cls->GetZ(), cls->GetY());
285 int plane = fGeo->GetPlane(cls->GetDetector());
288 for(int k=0; k<3; k++) if (cls->GetLabel(k) > -1) nl++;
291 Double_t yref, zref, tgphi;
292 int stat = GetMCPosition(cls->GetLabel(0), cls->GetX(), yref, zref, tgphi);
293 if (stat < 0) continue;
295 fClZXcl->Fill(cls->GetZ(), cls->GetX());
296 fClZXref->Fill(zref, cls->GetX());
298 AliTRDpadPlane *padPlane = AliTRDCommonParam::Instance()->GetPadPlane(plane,0);
299 Double_t h01 = TMath::Tan(-TMath::Pi() / 180.0 * padPlane->GetTiltingAngle());
301 //double dz = zref - padPlane->GetRow0();
302 double dz = zref - cls->GetZ();
303 double dy = dz * h01;
304 double yy = cls->GetY() - dy;
306 if (cls->From2pad()) fClY2->Fill(10 * (yy - yref));
307 if (cls->From3pad()) fClY3->Fill(10 * (yy - yref));
309 int idx = GetPhiBin(tgphi);
310 if (idx >= 0 && idx < 12) fClYTgPhi[idx]->Fill(10 * (yy - yref));
312 fClZZ->Fill(zref, cls->GetZ());
315 fClYX->Fill(cls->GetY(), cls->GetX() - fGeo->GetTime0(plane));
331 gStyle->SetOptFit(1);
336 fClY2->Fit("gaus", "", "", -2*fClY2->GetRMS(), 2*fClY2->GetRMS());
341 fClY3->Fit("gaus", "", "", -2*fClY3->GetRMS(), 2*fClY3->GetRMS());
353 TCanvas *c = new TCanvas();
356 for(int i=0; i<12; i++) {
359 fClYTgPhi[i]->Draw();
360 if (fClYTgPhi[i]->GetSum() < 100) continue;
362 double mean = fClYTgPhi[i]->GetMean();
363 double rms = fClYTgPhi[i]->GetRMS();
365 fClYTgPhi[i]->Fit("gaus", "", "", mean-2*rms, mean+2*rms);
366 TF1 *f = fClYTgPhi[i]->GetFunction("gaus");
368 int n = fGrResTgPhi->GetN();
369 fGrResTgPhi->SetPoint(n, GetPhi(i), f->GetParameter(2));
370 fGrResTgPhi->SetPointError(n, 0, f->GetParError(2));
372 fGrMeanTgPhi->SetPoint(n, GetPhi(i), f->GetParameter(1));
373 fGrMeanTgPhi->SetPointError(n, 0, f->GetParError(1));
376 //gSystem->Sleep(1000);
377 gStyle->SetOptStat(0);
380 TH1D *dummy = new TH1D("dummy", "", 100, -0.3, 0.3);
382 dummy->SetTitle(";tg(#phi);resolution (mm)");
383 dummy->SetMinimum(0);
384 dummy->SetMaximum(1);
387 (dummy->Clone("dummy1"))->Draw();
389 fGrResTgPhi->Draw("PL");
390 fGrResTgPhi->GetHistogram()->SetTitle(";tg(#phi);resolution (mm)");
391 fGrResTgPhi->SetMarkerStyle(20);
394 dummy->SetTitle(";tg(#phi);mean value (mm)");
395 dummy->SetMinimum(-0.3);
396 dummy->SetMaximum(0.3);
399 (dummy->Clone("dummy2"))->Draw();
401 fGrMeanTgPhi->Draw("PL");
402 fGrMeanTgPhi->GetHistogram()->SetTitle(";tg(#phi);mean value (mm)");
403 fGrMeanTgPhi->SetMarkerStyle(20);
408 //fClZZ->Draw("colz");
411 //fClPos->Draw("colz");
421 //////////////////////////////////////////////////////////////////////////////////////////
423 void AliTRDtrackingAnalysis::LoadRecPointsFile() {
426 sprintf(filename, "%s/galice.root", fPath);
428 fLoader = AliRunLoader::Open(filename);
430 Error("CheckFiles", "getting run loader from file %s/galice.root failed", filename);
434 fLoader->LoadgAlice();
435 gAlice = fLoader->GetAliRun();
438 Error("CheckFiles", "no galice object found");
442 fLoader->LoadKinematics();
443 fLoader->LoadHeader();
444 fLoader->LoadTrackRefs();
446 //TGeoManager::Import("/data/alice_u/radomski/condor/run_0/geometry.root");
447 TGeoManager::Import(Form("%s/geometry.root", fPath));
451 fGeo = (AliTRDgeometry*)gDirectory->Get("TRDgeometry");
452 fTracker = new AliTRDtracker(gFile);
454 fLoader->LoadRecPoints("TRD");
456 AliTracker::SetFieldMap(gAlice->Field(), 1);
459 //////////////////////////////////////////////////////////////////////////////////////////
461 void AliTRDtrackingAnalysis::CheckFiles() {
466 sprintf(filename, "%s/galice.root", fPath);
468 fLoader = AliRunLoader::Open(filename);
470 Error("CheckFiles", "getting run loader from file %s/galice.root failed", filename);
474 fLoader->LoadgAlice();
475 gAlice = fLoader->GetAliRun();
478 Error("CheckFiles", "no galice object found");
482 fLoader->LoadKinematics();
483 fLoader->LoadHeader();
484 fLoader->LoadTrackRefs();
487 fGeo = (AliTRDgeometry*)gDirectory->Get("TRDgeometry");
488 //fGeo->ReadGeoMatrices();
492 sprintf(filename,"%s/AliESDs.root", fPath);
493 TFile *esdFile = new TFile(filename, "READ");
495 if (esdFile->IsZombie()) {
496 Error("CheckFiles", "file not present: AliESDs.root");
500 fEsdTree = (TTree*)esdFile->Get("esdTree");
503 fEsdTree->SetBranchAddress("ESD", &fESD);
506 //////////////////////////////////////////////////////////////////////////////////////////
508 void AliTRDtrackingAnalysis::LoadRefs() {
510 if (fRefTPC) delete fRefTPC;
511 if (fRefTRD) delete fRefTRD;
513 fRefTPC = new TObjArray();
514 fRefTRD = new TObjArray();
516 //fLoader->GetEvent(event);
517 //AliStack* stack = gAlice->Stack();
518 TTree *refTree = fLoader->TreeTR();
520 const int nBranch = 2;
521 const char *brName[] = {"TPC", "TRD"};
522 TClonesArray *clRefs = new TClonesArray("AliTrackReference");
524 for(int b=0; b<nBranch; b++) {
526 TBranch *branch = refTree->GetBranch(brName[b]);
527 refTree->SetBranchAddress(brName[b],&clRefs);
529 int nEntries = branch->GetEntries();
530 for(int iTrack = 0; iTrack < nEntries; iTrack++) {
532 refTree->GetEvent(iTrack);
533 int nPoints = clRefs->GetEntries();
534 for(int iPoint=0; iPoint<nPoints; iPoint++) {
535 AliTrackReference *ref = (AliTrackReference*)clRefs->At(iPoint);
536 if (b == 0) fRefTPC->Add(new AliTrackReference(*ref));
537 if (b == 1) fRefTRD->Add(new AliTrackReference(*ref));
545 for(int i=0; i<fRefTRD->GetEntries(); i++) {
546 AliTrackReference *ref = (AliTrackReference*)(*fRefTRD)[i];
547 fLabels[i] = ref->GetTrack();
550 while(ref->LocalX() > fGeo->GetTime0(p)+2) p++;
551 fRefSpace->Fill(ref->LocalY(), ref->LocalX()-fGeo->GetTime0(p));
553 //for(int bit=0; bit<9; bit++) if (ref->TestBit(bit)) fBits->Fill(bit);
557 Info("LoadRefs", "TPC = %d\t TRD = %d", fRefTPC->GetEntries(), fRefTRD->GetEntries());
560 //////////////////////////////////////////////////////////////////////////////////////////
562 Int_t AliTRDtrackingAnalysis::GetReference(Int_t label) {
564 int start = TMath::BinarySearch(fRefTRD->GetEntries(), fLabels, label);
567 AliTrackReference *ref = (AliTrackReference*)(*fRefTRD)[start];
568 if (ref->GetTrack() != label) return start+1;
575 //////////////////////////////////////////////////////////////////////////////////////////
577 int AliTRDtrackingAnalysis::GetMCPosition(Int_t label, Double_t x, Double_t &Y, Double_t &Z, Double_t &tgphi) {
585 int idx = GetReference(label);
586 for(int i=idx; i<fRefTRD->GetEntries(); i++) {
588 AliTrackReference *ref = (AliTrackReference*)(*fRefTRD)[i];
589 if (ref->GetTrack() != label) break;
593 //while(ref->LocalX() > fGeo->GetTime0(p)+2) p++;
594 //if (p != layer) continue;
596 double dX = ref->LocalX()-x;
611 if (idLow == -1 || idHigh == -1) return -1;
613 AliTrackReference *refI = (AliTrackReference*)(*fRefTRD)[idLow];
614 AliTrackReference *refO = (AliTrackReference*)(*fRefTRD)[idHigh];
617 double dx = refO->LocalX() - refI->LocalX();
618 double dy = refO->LocalY() - refI->LocalY();
619 double dz = refO->Z() - refI->Z();
620 double ddx = (x - refI->LocalX())/dx;
624 Y = refI->LocalY() + ddx * dy;
625 Z = refI->Z() + ddx * dz;
632 //////////////////////////////////////////////////////////////////////////////////////////
633 Int_t AliTRDtrackingAnalysis::GetPhiBin(Double_t phi) {
634 return (int)((phi+0.3)/0.05);
637 //////////////////////////////////////////////////////////////////////////////////////////
639 Double_t AliTRDtrackingAnalysis::GetPhi(Int_t bin) {
640 return bin * 0.05 - 0.3 + 0.025;
642 //////////////////////////////////////////////////////////////////////////////////////////