1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /* $Id: AliTRDefficiencyMC.cxx 27496 2008-07-22 08:35:45Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // Reconstruction QA //
23 // Markus Fasel <M.Fasel@gsi.de> //
25 ////////////////////////////////////////////////////////////////////////////
27 #include <TObjArray.h>
28 #include <TClonesArray.h>
31 #include "TTreeStream.h"
35 #include "AliMathBase.h"
36 #include "AliTrackReference.h"
37 #include "AliAnalysisManager.h"
39 #include "AliTRDcluster.h"
40 #include "AliTRDseedV1.h"
41 #include "AliTRDtrackV1.h"
42 #include "Cal/AliTRDCalPID.h"
43 #include "info/AliTRDtrackInfo.h"
44 #include "AliTRDinfoGen.h"
45 #include "AliTRDefficiencyMC.h"
47 ClassImp(AliTRDefficiencyMC)
49 //_____________________________________________________________________________
50 AliTRDefficiencyMC::AliTRDefficiencyMC()
51 :AliTRDrecoTask("EfficiencyMC", "Combined Tracking Efficiency")
54 // Default constructor
59 //_____________________________________________________________________________
60 void AliTRDefficiencyMC::CreateOutputObjects(){
62 // Create output objects
65 OpenFile(0, "RECREATE");
66 fContainer = Histos();
70 //_____________________________________________________________________________
71 void AliTRDefficiencyMC::Exec(Option_t *){
75 // Loop over TrackInfos
76 // 1st: check if there is a trackTRD
77 // 2nd: put conditions on the track:
78 // - check if we did not register it before
79 // - check if we have Track References for the track
80 // 3rd: Register track:
81 // - accepted if both conditions are fulfilled
82 // - contamination if at least one condition is not fulfilled
83 // 4th: check Monte-Carlo Track wheter findable or not if there is no TRD track in this track info
84 // 5th: register MC track as rejected if findable and not jet registered
85 // Match the registers accepted and rejected and clean register rejected
86 // Fill the histograms
88 const Int_t kArraySize = 10000; // Store indices of track references in an array
89 Int_t indexAccepted[kArraySize], indexRejected[kArraySize], indexContamination[kArraySize];
90 memset(indexAccepted, 0, sizeof(Int_t) * kArraySize);
91 memset(indexRejected, 0, sizeof(Int_t) * kArraySize);
92 memset(indexContamination, 0, sizeof(Int_t) * kArraySize);
93 Int_t naccepted = 0, nrejected = 0, ncontamination = 0;
94 Bool_t isContamination = kFALSE;
96 Int_t nTrackInfos = fTracks->GetEntriesFast();
97 AliTRDtrackV1 *trackTRD = 0x0;
98 AliTRDtrackInfo *trkInf = 0x0;
99 for(Int_t itinf = 0; itinf < nTrackInfos; itinf++){
100 trkInf = dynamic_cast<AliTRDtrackInfo *>(fTracks->UncheckedAt(itinf));
101 if(!trkInf) continue;
102 if(trkInf->GetTrack() || trkInf->GetNumberOfClustersRefit()){
103 isContamination = IsRegistered(trkInf,indexAccepted,naccepted);
104 if(!trkInf->GetNTrackRefs()){
105 // We reject the track since the Monte Carlo Information is missing
106 AliDebug(1, Form("Error: Track Reference missing for Track %d", trkInf->GetLabel()));
107 isContamination = kTRUE;
109 if(trackTRD && DebugLevel() > 5) FillStreamTrackWOMC(trkInf);
112 // reject kink (we count these only once)
113 if(trkInf->GetKinkIndex()) continue;
114 // Register track as contamination
115 indexContamination[ncontamination++]=itinf;
119 AliDebug(4, "Accept track");
120 // Register track as accepted
121 indexAccepted[naccepted++] = itinf;
123 if(IsFindable(trkInf)){
124 // register track as rejected if not already registered there
126 // These track infos are not!!! registered as contamination
127 if(!IsRegistered(trkInf, indexRejected, nrejected)) indexRejected[nrejected++] = itinf;
131 // we have to check if the rejected tracks are registered as found
132 // a possible source for this:
133 // first the track is not found by the barrel tracking but it is later found
134 // by the stand alone tracking, then two track info objects with the same
135 // label would be created
137 // these tracks are not! registered as contamination
138 Int_t tmprejected[kArraySize]; Int_t nrej = nrejected;
139 memcpy(tmprejected, indexRejected, sizeof(Int_t) * nrejected);
141 for(Int_t irej = 0; irej < nrej; irej++){
142 trkInf = dynamic_cast<AliTRDtrackInfo *>(fTracks->At(tmprejected[irej]));
143 if(!IsRegistered(trkInf,indexAccepted,naccepted)) indexRejected[nrejected++] = tmprejected[irej];
146 FillHistograms(naccepted, &indexAccepted[0], kAccepted);
147 FillHistograms(nrejected, &indexRejected[0], kRejected);
148 FillHistograms(ncontamination, &indexContamination[0], kContamination);
149 Int_t nall = naccepted + nrejected;
150 //if(DebugLevel()>=1)
151 AliInfo(Form("%3d Tracks: MC[%3d] TRD[%3d | %5.2f%%] \n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nall, naccepted, nall ? 1.E2*Float_t(naccepted)/Float_t(nall) : 0.));
152 AliInfo(Form("%3d Tracks: ALL[%3d] Contamination[%3d | %5.2f%%] \n", (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nall + ncontamination, ncontamination, nall ? 1.E2*Float_t(ncontamination)/Float_t(nall + ncontamination) : 0.));
154 PostData(0, fContainer);
158 //_____________________________________________________________________________
159 Bool_t AliTRDefficiencyMC::PostProcess()
164 // Change the histogram style
165 // For species histograms apply the colors connected with the given particle species
167 TH1 *histo = dynamic_cast<TH1 *>(fContainer->At(kEfficiencyHistogram));
168 histo->SetMarkerStyle(22);
169 histo->SetMarkerColor(kBlue);
170 histo->GetXaxis()->SetTitle("p [GeV/c]");
171 histo->GetXaxis()->SetMoreLogLabels();
172 histo->GetYaxis()->SetTitle("Efficiency [%]");
173 histo->GetYaxis()->SetRangeUser(0.99, 1.005);
175 histo = dynamic_cast<TH1 *>(fContainer->At(kContaminationHistogram));
176 histo->SetMarkerStyle(22);
177 histo->SetMarkerColor(kBlue);
178 histo->GetXaxis()->SetTitle("p [GeV/c]");
179 histo->GetXaxis()->SetMoreLogLabels();
180 histo->GetYaxis()->SetTitle("Contamination [%]");
182 // Species Efficiency Histograms
183 for(Int_t ispec = 0; ispec < AliPID::kSPECIES; ispec++){
184 histo = dynamic_cast<TH1 *>(fContainer->At(kEfficiencySpeciesHistogram + ispec));
185 histo->SetMarkerStyle(22);
186 histo->SetLineColor(AliTRDCalPID::GetPartColor(ispec));
187 histo->SetMarkerColor(AliTRDCalPID::GetPartColor(ispec));
188 histo->GetXaxis()->SetTitle("p [GeV/c]");
189 histo->GetXaxis()->SetMoreLogLabels();
190 histo->GetYaxis()->SetTitle("Efficiency [%]");
191 histo->GetYaxis()->SetRangeUser(0.99, 1.005);
194 // Species Contamination Histograms
195 for(Int_t ispec = 0; ispec < AliPID::kSPECIES; ispec++){
196 histo = dynamic_cast<TH1 *>(fContainer->At(kContaminationSpeciesHistogram + ispec));
197 histo->SetMarkerStyle(22);
198 histo->SetLineColor(AliTRDCalPID::GetPartColor(ispec));
199 histo->SetMarkerColor(AliTRDCalPID::GetPartColor(ispec));
200 histo->GetXaxis()->SetTitle("p [GeV/c]");
201 histo->GetXaxis()->SetMoreLogLabels();
202 histo->GetYaxis()->SetTitle("Contamination [%]");
209 //_____________________________________________________________________________
210 Bool_t AliTRDefficiencyMC::GetRefFigure(Int_t ifig){
212 // Plot the histograms
214 if(ifig >= fNRefFigures) return kFALSE;
216 (dynamic_cast<TH1 *>(fContainer->At(ifig)))->Draw("e1");
221 (dynamic_cast<TH1 *>(fContainer->At(kEfficiencySpeciesHistogram)))->Draw("e1");
222 for(Int_t ispec = 1; ispec < AliPID::kSPECIES; ispec++)
223 (dynamic_cast<TH1 *>(fContainer->At(kEfficiencySpeciesHistogram + ispec)))->Draw("e1same");
226 (dynamic_cast<TH1 *>(fContainer->At(kContaminationSpeciesHistogram)))->Draw("e1");
227 for(Int_t ispec = 1; ispec < AliPID::kSPECIES; ispec++)
228 (dynamic_cast<TH1 *>(fContainer->At(kContaminationSpeciesHistogram + ispec)))->Draw("e1same");
231 (dynamic_cast<TH1 *>(fContainer->At(kEfficiencyNoPID)))->Draw("e1");
234 (dynamic_cast<TH1 *>(fContainer->At(kContaminationNoPID)))->Draw("e1");
240 //_____________________________________________________________________________
241 TObjArray *AliTRDefficiencyMC::Histos(){
243 // Create the histograms
245 const Int_t nbins = 11;
247 if(fContainer) return fContainer;
248 Float_t xbins[nbins+1] = {.5, .7, .9, 1.3, 1.7, 2.4, 3.5, 4.5, 5.5, 7., 9., 11.};
250 TString species[AliPID::kSPECIES] = {"Pions", "Muons", "Electrons", "Kaons", "Protons"};
251 TString species_short[AliPID::kSPECIES] = {"Pi", "Mu", "El", "Ka", "Pr"};
253 fContainer = new TObjArray();
254 fContainer->AddAt(new TProfile("trEffComb", "Combined Tracking Efficiency", nbins, xbins), kEfficiencyHistogram);
255 fContainer->AddAt(new TProfile("trContComb", "Combined Tracking Contamination", nbins, xbins), kContaminationHistogram);
256 for(Int_t ispec = 0; ispec < AliPID::kSPECIES; ispec++)
257 fContainer->AddAt(new TProfile(Form("trEffComb%s", species_short[ispec].Data()), Form("Combined Tracking Efficiency %s", species[ispec].Data()), nbins, xbins), kEfficiencySpeciesHistogram + ispec);
258 for(Int_t ispec = 0; ispec < AliPID::kSPECIES; ispec++)
259 fContainer->AddAt(new TProfile(Form("trContComb%s", species_short[ispec].Data()), Form("Combined Tracking Contamination %s", species[ispec].Data()), nbins, xbins), kContaminationSpeciesHistogram + ispec);
260 fContainer->AddAt(new TProfile("trEffCombNoPID", "Combined Tracking Efficiency", nbins, xbins), kEfficiencyNoPID);
261 fContainer->AddAt(new TProfile("trContCombNoPID", "Combined Tracking Contamination", nbins, xbins), kContaminationNoPID);
265 //_____________________________________________________________________________
266 Bool_t AliTRDefficiencyMC::IsFindable(AliTRDtrackInfo * const trkInf){
268 // Apply Cuts on the Monte Carlo track references
269 // return whether track is findable or not
271 const Float_t kAlpha = 0.349065850;
273 AliDebug(10, "Analysing Track References\n");
274 // Check if track is findable
276 Float_t xmin = 10000.0, xmax = 0.0;
277 Float_t ymin = 0.0, ymax = 0.0;
278 Float_t zmin = 0.0, zmax = 0.0;
279 Float_t lastx = 0.0, x = 0.0;
282 AliTrackReference *trackRef = 0x0;
283 for(Int_t itr = 0; itr < trkInf->GetNTrackRefs(); itr++){
284 trackRef = trkInf->GetTrackRef(itr);
285 AliDebug(10, Form("%d. x[%f], y[%f], z[%f]\n", itr, trackRef->LocalX(), trackRef->LocalY(), trackRef->Z()));
286 x = trackRef->LocalX();
288 // Be Sure that we are inside TRD
289 if(x < AliTRDinfoGen::GetTPCx() || x > AliTRDinfoGen::GetTOFx()) continue;
290 sector[itr] = Int_t(trackRef->Alpha()/kAlpha);
292 xmin = trackRef->LocalX();
293 ymin = trackRef->LocalY();
294 zmin = trackRef->Z();
297 xmax = trackRef->LocalX();
298 ymax = trackRef->LocalY();
299 zmax = trackRef->Z();
302 Float_t dist = TMath::Abs(x - lastx);
303 AliDebug(10, Form("x = %f, lastx = %f, dist = %f\n", x, lastx, dist));
304 if(TMath::Abs(dist - 3.7) < 0.1) nLayers++; // ref(i+1) has to be larger than ref(i)
310 Bool_t findable = kTRUE;
311 if(trkInf->GetNTrackRefs() > 2 && xmax > xmin){
312 if(mom < 0.55) findable = kFALSE; // momentum cut at 0.6
313 Double_t yangle = (ymax -ymin)/(xmax - xmin);
314 Double_t zangle = (zmax -zmin)/(xmax - xmin);
315 AliDebug(10, Form("\ntrack: y-Angle = %f, z-Angle = %f\nnLayers = %d", yangle, zangle, nLayers));
316 if(TMath::ATan(TMath::Abs(yangle)) > 45.) findable = kFALSE;
317 if(TMath::ATan(TMath::Abs(zangle)) > 45.) findable = kFALSE;
318 if(nLayers < 4) findable = kFALSE;
319 if(!trkInf->IsPrimary()) findable = kFALSE;
320 Bool_t samesec = kTRUE;
321 for(Int_t iref = 1; iref < trkInf->GetNTrackRefs(); iref++)
322 if(sector[iref] != sector[0]) samesec = kFALSE;
323 if(!samesec) findable = kFALSE; // Discard all tracks which are passing more than one sector
325 Double_t trackAngle = TMath::ATan(yangle);
326 Bool_t primary = trkInf->IsPrimary();
327 (*DebugStream()) << "NotFoundTrack"
328 << "Momentum=" << mom
329 << "trackAngle="<< trackAngle
330 << "NLayers=" << nLayers
331 << "Primary=" << primary
340 //_____________________________________________________________________________
341 void AliTRDefficiencyMC::FillHistograms(Int_t nTracks, Int_t *indices, FillingMode_t mode){
343 // Fill Histograms in three different modes:
344 // 1st tracks which are found and accepted
345 // 2nd tracks which are not found and not already counted
346 // 3rd contaminating tracks: either double counts (kinks!) or tracks with no MC hit inside TRD
348 const Int_t pid[AliPID::kSPECIES] = {211,13,11,321,2212};
349 Double_t trkmom = 0.; // the track momentum
350 Int_t trkpid = -1; // particle species
351 AliTRDtrackInfo *trkInf = 0x0;
352 for(Int_t itk = 0; itk < nTracks; itk++){
353 trkInf = dynamic_cast<AliTRDtrackInfo *>(fTracks->At(indices[itk]));
354 AliDebug(3, Form("Accepted MC track: %d\n", trkInf->GetLabel()));
355 if(trkInf->GetNTrackRefs()){
356 // use Monte-Carlo Information for Momentum and PID
357 trkmom = trkInf->GetTrackRef(0)->P();
358 trkpid = trkInf->GetPDG();
361 trkmom = trkInf->GetTrack()->P();
365 (dynamic_cast<TProfile *>(fContainer->At(kEfficiencyHistogram)))->Fill(trkmom, 1);
366 (dynamic_cast<TProfile *>(fContainer->At(kContaminationHistogram)))->Fill(trkmom, 0);
369 (dynamic_cast<TProfile *>(fContainer->At(kEfficiencyHistogram)))->Fill(trkmom, 0);
370 (dynamic_cast<TProfile *>(fContainer->At(kContaminationHistogram)))->Fill(trkmom, 0);
373 (dynamic_cast<TProfile *>(fContainer->At(kContaminationHistogram)))->Fill(trkmom, 1);
376 // Fill species histogram
378 for(Int_t ispec = 0; ispec < AliPID::kSPECIES; ispec++){
379 if(trkpid == pid[ispec]) partSpec = ispec;
384 (dynamic_cast<TProfile *>(fContainer->At(kEfficiencySpeciesHistogram + partSpec)))->Fill(trkmom, 1);
385 (dynamic_cast<TProfile *>(fContainer->At(kContaminationSpeciesHistogram + partSpec)))->Fill(trkmom, 0);
388 (dynamic_cast<TProfile *>(fContainer->At(kEfficiencySpeciesHistogram + partSpec)))->Fill(trkmom, 0); (dynamic_cast<TProfile *>(fContainer->At(kContaminationSpeciesHistogram + partSpec)))->Fill(trkmom, 0);
391 (dynamic_cast<TProfile *>(fContainer->At(kContaminationSpeciesHistogram + partSpec)))->Fill(trkmom, 1);
395 // The particle Type is not registered
396 (dynamic_cast<TProfile *>(fContainer->At(kEfficiencyNoPID)))->Fill(trkmom, 1);
397 (dynamic_cast<TProfile *>(fContainer->At(kContaminationNoPID)))->Fill(trkmom, 1);
402 //_____________________________________________________________________________
403 void AliTRDefficiencyMC::FillStreamTrackWOMC(AliTRDtrackInfo * const trkInf){
406 // 1. The event number
407 // 2. The track label
408 // 3. The TRD track label
409 // 4. The frequency of the TRD Label
410 // 5. Momentum from TPC (NO STAND ALONE TRACK)
413 // 8. Monte Carlo PID
414 // 9. We check the Labels of the TRD track according to them we search the maching Monte-Carlo track.
415 // From the matching Monte-Carlo track we store trackRefs, phi and momentum
416 // 10. We may also want to keep the kink index
417 Double_t mom = trkInf->GetESDinfo()->GetOuterParam()->P();
418 Int_t event = (Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry();
419 Int_t label = trkInf->GetLabel();
420 Int_t kinkIndex = trkInf->GetKinkIndex();
421 Int_t pdg = trkInf->GetPDG();
422 Double_t phiTPC = trkInf->GetESDinfo()->GetOuterParam()->Phi();
423 Int_t labelsTRD[180]; // Container for the cluster labels
424 Int_t sortlabels[360]; // Cluster Labels sorted according their occurancy
425 AliTRDseedV1 *tracklet = 0x0;
426 AliTRDcluster *c = 0x0;
427 Int_t nclusters = 0x0;
428 AliTRDtrackV1 *trackTRD = trkInf->GetTrack();
429 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
430 tracklet = trackTRD->GetTracklet(il);
431 if(!tracklet) continue;
432 tracklet->ResetClusterIter();
434 while((c = tracklet->NextCluster())) labelsTRD[nclusters++] = c->GetLabel(0);
436 // Determine Label and Frequency
437 AliMathBase::Freq(nclusters, const_cast<const Int_t *>(&labelsTRD[0]), &sortlabels[0], kTRUE);
438 Int_t labelTRD = sortlabels[0];
439 Int_t freqTRD = sortlabels[1];
440 // find the track info object matching to the TRD track
441 AliTRDtrackInfo *realtrack = 0;
442 TObjArrayIter rtiter(fTracks);
443 while((realtrack = (AliTRDtrackInfo *)rtiter())){
444 if(realtrack->GetLabel() != labelTRD) continue;
447 TClonesArray trackRefs("AliTrackReference");
450 Double_t realPhi = 0.;
452 // pack the track references into the trackRefsContainer
453 for(Int_t iref = 0; iref < realtrack->GetNTrackRefs(); iref++){
454 new(trackRefs[iref])AliTrackReference(*(realtrack->GetTrackRef(iref)));
456 realPdg = realtrack->GetPDG();
457 if(realtrack->GetNTrackRefs()){
458 realP = realtrack->GetTrackRef(0)->P();
459 realPhi = realtrack->GetTrackRef(0)->Phi();
462 (*DebugStream()) << "TrackingEffMCfake"
465 << "labelTRD=" << labelTRD
466 << "FreqTRDlabel=" << freqTRD
468 << "phiTPC=" << phiTPC
469 << "trackTRD=" << trackTRD
471 << "TrackRefs=" << &trackRefs
472 << "RealPDG=" << realPdg
474 << "RealPhi" << realPhi
475 << "KinkIndex=" << kinkIndex
479 //_____________________________________________________________________________
480 Bool_t AliTRDefficiencyMC::IsRegistered(AliTRDtrackInfo * const trkInf, Int_t *indices, Int_t nTracks){
482 // Checks if track is registered in a given mode
484 Bool_t isRegistered = kFALSE;
485 for(Int_t il = 0; il < nTracks; il++){
486 if((dynamic_cast<AliTRDtrackInfo *>(fTracks->At(indices[il])))->GetLabel() == trkInf->GetLabel()){
487 isRegistered = kTRUE;