1 /*************************************************************************
2 * Copyright(c) 1998-2008, 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 ///////////////////////////////////////////////////////////////////////////
17 // Class AliTaskITSUPerf //
18 // Analysis task to produce data and MC histos needed for tracklets //
19 // dNdEta extraction in multiple bins in one go //
20 // Author: ruben.shahoyan@cern.ch //
21 ///////////////////////////////////////////////////////////////////////////
30 #include "TObjArray.h"
31 #include "TGeoGlobalMagField.h"
33 #include "AliAnalysisManager.h"
35 #include "AliESDEvent.h"
36 #include "AliESDInputHandler.h"
37 #include "AliESDInputHandlerRP.h"
38 #include "AliCDBPath.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBEntry.h"
41 #include "AliCDBStorage.h"
42 #include "AliGeomManager.h"
44 #include "AliMCEventHandler.h"
45 #include "AliMCEvent.h"
46 #include "AliMCParticle.h"
48 #include "AliGenEventHeader.h"
49 #include "AliCentrality.h"
51 #include "AliPhysicsSelection.h"
52 #include "AliGenEventHeader.h"
53 #include "AliGenHijingEventHeader.h"
54 #include "AliGenDPMjetEventHeader.h"
55 #include "AliGenCocktailEventHeader.h"
56 #include "AliESDtrackCuts.h"
58 #include "AliTaskITSUPerf.h"
59 #include "../ITS/UPGRADE/AliITSURecoDet.h"
60 #include "../ITS/UPGRADE/AliITSUGeomTGeo.h"
61 #include "../ITS/UPGRADE/AliITSUClusterPix.h"
62 #include "../ITS/UPGRADE/AliITSUTrackCond.h"
63 #include <TGeoManager.h>
66 ClassImp(AliTaskITSUPerf)
69 const char* AliTaskITSUPerf::fgkLabelTypes[AliTaskITSUPerf::kNLabelTypes] = {
78 //________________________________________________________________________
79 /*//Default constructor
80 AliTaskITSUPerf::AliTaskITSUPerf(const char *name)
81 : AliAnalysisTaskSE(name),
83 //________________________________________________________________________
84 AliTaskITSUPerf::AliTaskITSUPerf(const char *name)
85 : AliAnalysisTaskSE(name)
96 ,fUseSpecialOutput(kTRUE)
115 ,fUseCentralityVar(0)
119 DefineOutput(1, TList::Class());
123 //________________________________________________________________________
124 AliTaskITSUPerf::~AliTaskITSUPerf()
127 // histograms are in the output list and deleted when the output
128 // list is deleted by the TSelector dtor
129 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { //RRR
130 printf("Deleteing output\n");
135 fHistosCentMCLb.Clear();
143 //________________________________________________________________________
144 void AliTaskITSUPerf::UserCreateOutputObjects()
147 if (fUseSpecialOutput) OpenFile(1);
148 fOutput = new TList();
153 TString geom = "geometry.root";
154 AliGeomManager::LoadGeometry(geom.Data());
155 if (!gGeoManager) AliFatal("Failed to load geometry");
158 // create ITS interface
159 fGeom = new AliITSUGeomTGeo(kTRUE,kTRUE);
160 AliITSUClusterPix::SetGeom(fGeom);
161 fITS = new AliITSURecoDet(fGeom,"ITSURecoInterface");
162 fITS->CreateClusterArrays();
165 for (int ib=0;ib<fNCentBins;ib++) {
169 int nhist = fOutput->GetEntries();
170 for (int i=0;i<nhist;i++) {
171 TObject* hst = fOutput->At(i);
172 if (!hst || !(hst->InheritsFrom(TH1::Class()))) continue;
173 ((TH1*)hst)->Sumw2();
176 PostData(1, fOutput);
180 //________________________________________________________________________
181 void AliTaskITSUPerf::UserExec(Option_t *)
185 AliInfo(Form("Event: %d",evID++));
187 AliAnalysisManager* anMan = AliAnalysisManager::GetAnalysisManager();
189 AliESDInputHandlerRP *handRP = (AliESDInputHandlerRP*)anMan->GetInputEventHandler();
190 if (!handRP) { AliFatal("No RP handler"); return; }
192 fESDEvent = handRP->GetEvent();
193 if (!fESDEvent) { AliFatal("No AliESDEvent"); return; }
195 fRPTree = handRP->GetTreeR("ITS");
196 if (!fRPTree) { AliFatal("Invalid ITS cluster tree"); return; }
198 AliMCEventHandler* eventHandler = (AliMCEventHandler*)anMan->GetMCtruthEventHandler();
199 if (!eventHandler) { AliFatal("Could not retrieve MC event handler"); return; }
200 fMCEvent = eventHandler->MCEvent();
201 if (!fMCEvent) { AliFatal("Could not retrieve MC event"); return; }
202 fStack = fMCEvent->Stack();
203 if (!fStack) { AliFatal("Stack is not available"); return; }
206 AliGenEventHeader* mcGenH = 0;
207 mcGenH = fMCEvent->GenEventHeader();
209 mcGenH->PrimaryVertex(vtmc);
210 for (int i=3;i--;) fVtxMC[i] = vtmc[i];
212 printf("MagField: %f\n",fESDEvent->GetMagneticField());
213 printf("VtxMC : %+e %+e %+e\n",fVtxMC[0],fVtxMC[1],fVtxMC[2]);
215 fVtxSPD = fESDEvent->GetPrimaryVertexSPD();
217 if (fVtxSPD->GetStatus()) printf("VtxSPD: %+e %+e %+e | Nc=%d\n",fVtxSPD->GetX(),fVtxSPD->GetY(),fVtxSPD->GetZ(),fVtxSPD->GetNContributors());
218 else printf("VtxSPD: N/A\n");
220 fVtxTrc = fESDEvent->GetPrimaryVertexTracks();
221 if (fVtxTrc->GetStatus()) printf("VtxTRC: %+e %+e %+e | Nc=%d\n",fVtxTrc->GetX(),fVtxTrc->GetY(),fVtxTrc->GetZ(),fVtxTrc->GetNContributors());
222 else printf("VtxTRC: N/A\n");
230 //________________________________________________________________________
231 void AliTaskITSUPerf::Terminate(Option_t *)
233 Printf("Terminating...");
236 //_________________________________________________________________________
237 void AliTaskITSUPerf::BookStandardHistosCentMCLb(Int_t bin, Int_t mcLb)
239 // book standard set of histos for specific centrality bin and MC status type,
240 // adding them to output list and management array
242 const double kMaxDPt = 0.3;
243 const double kMaxDCA = 0.3;
247 h2 = new TH2F(Form("B%d_%s_%s",bin,fgkLabelTypes[mcLb],"dPT2PTvsPT"),
248 Form("B%d %s %s",bin,fgkLabelTypes[mcLb],"#Deltap_{T}/p_{T} vs p_{T}"),
249 fNPtBins,fPtMin,fPtMax,fNResBins,-kMaxDPt,kMaxDPt);
250 AddHisto(&fHistosCentMCLb,h2, GetHistoID(kHResPTvsPTMC,mcLb,bin) );
252 // transverse DCA resolution
253 h2 = new TH2F(Form("B%d_%s_%s",bin,fgkLabelTypes[mcLb],"DCARvsPT"),
254 Form("B%d %s %s",bin,fgkLabelTypes[mcLb],"DCA R vs p_{T}"),
255 fNPtBins,fPtMin,fPtMax,fNResBins,-kMaxDCA,kMaxDCA);
256 AddHisto(&fHistosCentMCLb,h2, GetHistoID(kHResDCARvsPTMC,mcLb,bin) );
259 h2 = new TH2F(Form("B%d_%s_%s",bin,fgkLabelTypes[mcLb],"DCAZvsPT"),
260 Form("B%d %s %s",bin,fgkLabelTypes[mcLb],"DCA Z vs p_{T}"),
261 fNPtBins,fPtMin,fPtMax,fNResBins,-kMaxDCA,kMaxDCA);
262 AddHisto(&fHistosCentMCLb,h2, GetHistoID(kHResDCAZvsPTMC,mcLb,bin) );
266 //_________________________________________________________________________
267 void AliTaskITSUPerf::BookStandardHistosCent(Int_t bin)
269 // book standard set of histos for specific centrality bin
273 // MC labels combination vs pt
274 h2 = new TH2F(Form("B%d_%s",bin,"MCLabvsPT"),
275 Form("B%d %s",bin,"MCLabComb vs p_{T}"),
276 fNPtBins,fPtMin,fPtMax,kNLabelTypes,-0.5,kNLabelTypes-0.5);
277 AddHisto(&fHistosCent,h2, GetHistoID(kHMatchStatus,-1,bin) );
278 for (int i=0;i<kNLabelTypes;i++) h2->GetYaxis()->SetBinLabel(i+1,fgkLabelTypes[i]);
283 //_________________________________________________________________________
284 void AliTaskITSUPerf::BookHistos(Int_t bin)
286 // book standard set of histos, adding them to output list and management array
289 for (int ilb=0;ilb<kNLabelTypes;ilb++) { // create similar set of histos for all kind of MC labels
290 BookStandardHistosCentMCLb(bin,ilb);
292 BookStandardHistosCent(bin); // st.histos regardless of MClabels comb.
295 //_________________________________________________________________________
296 void AliTaskITSUPerf::AddHisto(TObjArray* array,TObject* h, Int_t at)
298 // add single histo to the set
299 if (at>=0) array->AddAtAndExpand(h,at);
304 //_________________________________________________________________________
305 Int_t AliTaskITSUPerf::GetHistoID(Int_t htype, Int_t mcStat, Int_t centBin) const
307 // generate ID for the histo. htype must be <100, mcStat<kNLabelTypes
309 if (mcStat>=kNLabelTypes) AliFatal(Form("MCStatus ID=%d > max.allowed %d",mcStat,kNLabelTypes));
310 if (centBin>=fNCentBins) AliFatal(Form("CentBin ID=%d > max.allowed %d",centBin,fNCentBins));
313 if (mcStat>=0) { // MCtruthness dependent histos
314 if (htype>=kHNStdHistosCentMC) AliFatal(Form("StdCentMC histo ID=%d > max.allowed %d",htype,kHNStdHistosCentMC));
315 return htype + kHNStdHistosCentMC*(mcStat + kNLabelTypes*centBin);
318 if (htype>=kHNStdHistosCent) AliFatal(Form("StdCent histo ID=%d > max.allowed %d",htype,kHNStdHistosCent));
319 return htype + kHNStdHistosCent*centBin;
327 //_________________________________________________________________________
328 void AliTaskITSUPerf::CheckTracks()
330 // build mc truth info for tracks
332 int ntr = fESDEvent->GetNumberOfTracks();
333 int ntrMC = fStack->GetNtrack();
335 double fldBz = fESDEvent->GetMagneticField();
338 for (int itr=0;itr<ntr;itr++) {
339 AliESDtrack* trc = fESDEvent->GetTrack(itr);
341 // at the moment we consider only TPC/ITS tracks
342 if (!trc->IsOn(AliESDtrack::kTPCin)) continue;
343 Int_t labMC = trc->GetLabel();
344 Int_t labMCabs = TMath::Abs(labMC);
345 Int_t labMCTPC = trc->GetTPCLabel();
346 Int_t labMCITS = trc->GetITSLabel();
347 Int_t nClTPC = trc->GetNcls(1);
348 Int_t nClITS = trc->GetNcls(0);
350 UInt_t& mcStatus = (UInt_t &)fMCStatus[labMCabs];
351 Bool_t reject = mcStatus & BIT(kTrCondFail);
352 if (reject) continue;
354 int mcLabType = GetMCLabType(labMCTPC,labMCITS,nClTPC,nClITS);
356 double pt = trc->Pt();
357 double eta = trc->Eta();
359 // printf("#%3d pt:%5.2f eta:%+5.2f | Lb:%+6d LbTPC:%+6d LbITS:%+6d MCTp:%d | Ntpc:%3d Nits:%3d\n",itr,pt,eta,labMC,labMCTPC,labMCITS,mcLabType, nClTPC,nClITS);
361 GetHisto(&fHistosCent,kHMatchStatus)->Fill(pt,mcLabType); // matching status
363 AliMCParticle *part = 0;
365 if (labMCabs<ntrMC) part = (AliMCParticle*)fMCEvent->GetTrack(labMCabs);
369 double ptMC = part->Pt();
370 double etaMC = part->Eta();
372 if ( (mcStatus&BIT(kMCPrimBit)) ) {
373 // compare MC vs reco track params
374 if (ptMC>0) GetHisto(&fHistosCentMCLb,kHResPTvsPTMC, mcLabType)->Fill(ptMC, (ptMC-pt)/ptMC);
377 trc->GetDZ(fVtxMC[0],fVtxMC[1],fVtxMC[2], fldBz, dcaRZ);
378 GetHisto(&fHistosCentMCLb,kHResDCARvsPTMC, mcLabType)->Fill(ptMC, dcaRZ[0]);
379 GetHisto(&fHistosCentMCLb,kHResDCAZvsPTMC, mcLabType)->Fill(ptMC, dcaRZ[1]);
392 //_________________________________________________________________________
393 void AliTaskITSUPerf::BuildMCInfo()
395 // build mc truth info for tracks
397 int ntrMC = fStack->GetNtrack();
399 if (fMCStatus.GetSize()<ntrMC) fMCStatus.Set(ntrMC);
402 for (int itr=0;itr<ntrMC;itr++) {
404 AliMCParticle *part = (AliMCParticle*)fMCEvent->GetTrack(itr);
405 if (!part->Charge()) continue;
407 UInt_t& mcStatus = (UInt_t &)fMCStatus[itr];
410 if (fStack->IsPhysicalPrimary(itr)) mcStatus |= BIT(kMCPrimBit);
413 TParticle* tp = part->Particle();
414 printf("mc%4d IsPri=%d",itr,fStack->IsPhysicalPrimary(itr)); tp->Print();
419 int nTrCond = fTrackingCond ? fTrackingCond->GetEntriesFast() : 0;
420 // fill MC clusters info (if available)
423 fITS->LoadClusters(fRPTree);
425 for (int ilr=fITS->GetNLayersActive();ilr--;) {
426 AliITSURecoLayer* lr = fITS->GetLayerActive(ilr);
427 for (int icl=lr->GetNClusters();icl--;) {
428 AliCluster* cl = lr->GetCluster(icl);
430 for (int ilb=0;ilb<3;ilb++) {
431 Int_t lab = cl->GetLabel(ilb);
432 if (lab<0||lab>=ntrMC) continue;
433 UInt_t& mcStatus = (UInt_t &)fMCStatus[lab];
434 mcStatus |= 0x1<<(ilr+kITSHitBits);
440 for (int itr=0;itr<ntrMC;itr++) {
442 UInt_t& mcStatus = (UInt_t &)fMCStatus[itr];
444 UShort_t patt = (mcStatus&0xffff);
445 for (int ic=0;ic<nTrCond;ic++) {
446 AliITSUTrackCond* cnd = (AliITSUTrackCond*) fTrackingCond->At(ic);
447 if (cnd->CheckPattern(patt)) {fail=kFALSE; break;}
449 if (fail) mcStatus |= BIT(kTrCondFail);
458 //_________________________________________________________________________
459 Int_t AliTaskITSUPerf::GetMCLabType(Int_t labMCTPC,Int_t labMCITS, Int_t nClTPC, Int_t nClITS)
461 // build type of track (0: both ITS and TPC correct, 1: ITS corr. TPC fake, 2: ITS fake TPC corr., 3: ITS fake TPC fake, 4: mismatch
464 if (nClTPC>0 && nClITS<1) return kITSTPCNoMatch;
465 if (TMath::Abs(labMCTPC)!=TMath::Abs(labMCITS)) tp = kITSTPCMismatch;
467 if (labMCITS<0) tp = labMCTPC<0 ? kITS0TPC0 : kITS0TPC1;
468 else tp = labMCTPC<0 ? kITS1TPC0 : kITS1TPC1;
474 //_________________________________________________________________________
475 Int_t AliTaskITSUPerf::GetCentralityBin() const
477 // calculate centrality bin