2 #include "AliESDEvent.h"
3 #include "AliAODEvent.h"
4 #include "AliVVertex.h"
6 #include "AliAODVertex.h"
9 #include <TMatrixDSym.h>
11 #include "AliVMultiplicity.h"
12 #include "AliPPVsMultUtils.h"
14 #include "AliAnalysisUtils.h"
16 ClassImp(AliAnalysisUtils)
18 //______________________________________________________________________
19 AliAnalysisUtils::AliAnalysisUtils():TObject(),
23 fCutOnZVertexSPD(kTRUE),
24 fUseMVPlpSelection(kFALSE),
25 fUseOutOfBunchPileUp(kFALSE),
29 fCheckPlpFromDifferentBCMV(kFALSE),
32 fnSigmaPlpZdistSPD(3.),
33 fnSigmaPlpDiamXYSPD(2.),
34 fnSigmaPlpDiamZSPD(5.),
35 fUseSPDCutInMultBins(kFALSE),
43 //______________________________________________________________________
44 Bool_t AliAnalysisUtils::IsVertexSelected2013pA(AliVEvent *event)
46 Bool_t accept = kFALSE;
48 // Check whether the event is of AOD or ESD type
49 AliAODEvent *aod = 0x0;
50 AliESDEvent *esd = 0x0;
51 aod = dynamic_cast<AliAODEvent*>(event);
52 esd = dynamic_cast<AliESDEvent*>(event);
59 AliFatal("Event is neither of AOD nor ESD type");
64 const AliVVertex *trkVtx = fisAOD ?
65 dynamic_cast<const AliVVertex*>(aod->GetPrimaryVertex()) :
66 dynamic_cast<const AliVVertex*>(esd->GetPrimaryVertex()) ;
67 if(!trkVtx || trkVtx->GetNContributors()<=fMinVtxContr){
72 TString vtxTtl = trkVtx->GetTitle();
73 if (!vtxTtl.Contains("VertexerTracks")) return accept;
75 Float_t zvtx = trkVtx->GetZ();
76 const AliVVertex* spdVtx = fisAOD ?
77 dynamic_cast<const AliVVertex*>(aod->GetPrimaryVertexSPD()) :
78 dynamic_cast<const AliVVertex*>(esd->GetPrimaryVertexSPD()) ;
79 if (spdVtx->GetNContributors()<=fMinVtxContr) return accept;
81 TString vtxTyp = spdVtx->GetTitle();
83 spdVtx->GetCovarianceMatrix(cov);
84 Double_t zRes = TMath::Sqrt(cov[5]);
85 if (vtxTyp.Contains("vertexer:Z") && (zRes>0.25)) return accept;
86 if (fCutOnZVertexSPD && TMath::Abs(spdVtx->GetZ() - trkVtx->GetZ())>0.5) return accept;
88 if (TMath::Abs(zvtx) > fMaxVtxZ) return accept;
93 //______________________________________________________________________
94 Bool_t AliAnalysisUtils::IsFirstEventInChunk(AliVEvent *event)
97 Bool_t accept = kFALSE;
99 // Check whether the event is of AOD or ESD type
100 AliAODEvent *aod = 0x0;
101 AliESDEvent *esd = 0x0;
102 aod = dynamic_cast<AliAODEvent*>(event);
103 esd = dynamic_cast<AliESDEvent*>(event);
110 AliFatal("Event is neither of AOD nor ESD type");
116 AliAODHeader *aodheader = 0x0;
117 aodheader = dynamic_cast<AliAODHeader*>(aod->GetHeader());
118 if(!aodheader) AliFatal("Not a standard AOD");
120 AliFatal("AOD header not there ?!");
123 if(aodheader->GetEventNumberESDFile()==0) accept = kTRUE;
125 if(esd->GetEventNumberInFile()==0) accept = kTRUE;
131 //______________________________________________________________________
132 Bool_t AliAnalysisUtils::IsPileUpEvent(AliVEvent *event)
134 Bool_t isPileUp=kFALSE;
135 //check for multiple vertices
136 if(fUseMVPlpSelection)isPileUp=IsPileUpMV(event);
137 else isPileUp=IsPileUpSPD(event);
138 //check for different BC
139 if(fUseOutOfBunchPileUp && IsOutOfBunchPileUp(event))isPileUp=kTRUE;
144 //______________________________________________________________________
145 Bool_t AliAnalysisUtils::IsPileUpMV(AliVEvent *event)
147 // check for multi-vertexer pile-up
148 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
149 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
152 AliFatal("Event is neither of AOD nor ESD type");
156 const AliVVertex* vtPrm = 0;
157 const AliVVertex* vtPlp = 0;
161 if ( !(nPlp=aod->GetNumberOfPileupVerticesTracks()) ) return kFALSE;
162 vtPrm = aod->GetPrimaryVertex();
163 if (vtPrm == aod->GetPrimaryVertexSPD()) return kTRUE; // there are pile-up vertices but no primary
166 if ( !(nPlp=esd->GetNumberOfPileupVerticesTracks())) return kFALSE;
167 vtPrm = esd->GetPrimaryVertexTracks();
168 if (((AliESDVertex*)vtPrm)->GetStatus()!=1) return kTRUE; // there are pile-up vertices but no primary
170 Int_t bcPrim = vtPrm->GetBC();
172 for (Int_t ipl=0;ipl<nPlp;ipl++) {
173 vtPlp = aod ? (const AliVVertex*)aod->GetPileupVertexTracks(ipl) : (const AliVVertex*)esd->GetPileupVertexTracks(ipl);
175 if (vtPlp->GetNContributors() < fMinPlpContribMV) continue;
176 if (vtPlp->GetChi2perNDF() > fMaxPlpChi2MV) continue;
177 if(fCheckPlpFromDifferentBCMV)
179 Int_t bcPlp = vtPlp->GetBC();
180 if (bcPlp!=AliVTrack::kTOFBCNA && TMath::Abs(bcPlp-bcPrim)>2) return kTRUE; // pile-up from other BC
183 Double_t wDst = GetWDist(vtPrm,vtPlp);
184 if (wDst<fMinWDistMV) continue;
186 return kTRUE; // pile-up: well separated vertices
193 //______________________________________________________________________
194 Bool_t AliAnalysisUtils::IsPileUpSPD(AliVEvent *event)
196 // check for SPD pile-up
197 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
198 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
201 AliFatal("Event is neither of AOD nor ESD type");
205 if (aod) return (fUseSPDCutInMultBins)?aod->IsPileupFromSPDInMultBins():aod->IsPileupFromSPD(fMinPlpContribSPD,fMinPlpZdistSPD,fnSigmaPlpZdistSPD,fnSigmaPlpDiamXYSPD,fnSigmaPlpDiamZSPD);
206 else return (fUseSPDCutInMultBins)?esd->IsPileupFromSPDInMultBins():esd->IsPileupFromSPD(fMinPlpContribSPD,fMinPlpZdistSPD,fnSigmaPlpZdistSPD,fnSigmaPlpDiamXYSPD,fnSigmaPlpDiamZSPD);
209 //______________________________________________________________________
210 Bool_t AliAnalysisUtils::IsOutOfBunchPileUp(AliVEvent *event)
212 // check for SPD pile-up
213 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
214 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
217 AliFatal("Event is neither of AOD nor ESD type");
220 Int_t bc2 = (aod)?((AliVAODHeader*)aod->GetHeader())->GetIRInt2ClosestInteractionMap():esd->GetHeader()->GetIRInt2ClosestInteractionMap();
224 Int_t bc1 = (aod)?((AliVAODHeader*)aod->GetHeader())->GetIRInt1ClosestInteractionMap():esd->GetHeader()->GetIRInt1ClosestInteractionMap();
232 //______________________________________________________________________
233 Bool_t AliAnalysisUtils::IsSPDClusterVsTrackletBG(AliVEvent *event){
234 Int_t nClustersLayer0 = event->GetNumberOfITSClusters(0);
235 Int_t nClustersLayer1 = event->GetNumberOfITSClusters(1);
236 Int_t nTracklets = event->GetMultiplicity()->GetNumberOfTracklets();
237 if (nClustersLayer0 + nClustersLayer1 > fASPDCvsTCut + nTracklets*fBSPDCvsTCut) return kTRUE;
242 //______________________________________________________________________
243 Double_t AliAnalysisUtils::GetWDist(const AliVVertex* v0, const AliVVertex* v1)
245 // calculate sqrt of weighted distance to other vertex
247 printf("One of vertices is not valid\n");
250 static TMatrixDSym vVb(3);
252 Double_t dx = v0->GetX()-v1->GetX();
253 Double_t dy = v0->GetY()-v1->GetY();
254 Double_t dz = v0->GetZ()-v1->GetZ();
255 Double_t cov0[6],cov1[6];
256 v0->GetCovarianceMatrix(cov0);
257 v1->GetCovarianceMatrix(cov1);
258 vVb(0,0) = cov0[0]+cov1[0];
259 vVb(1,1) = cov0[2]+cov1[2];
260 vVb(2,2) = cov0[5]+cov1[5];
261 vVb(1,0) = vVb(0,1) = cov0[1]+cov1[1];
262 vVb(0,2) = vVb(1,2) = vVb(2,0) = vVb(2,1) = 0.;
264 if (!vVb.IsValid()) {printf("Singular Matrix\n"); return dist;}
265 dist = vVb(0,0)*dx*dx + vVb(1,1)*dy*dy + vVb(2,2)*dz*dz
266 + 2*vVb(0,1)*dx*dy + 2*vVb(0,2)*dx*dz + 2*vVb(1,2)*dy*dz;
267 return dist>0 ? TMath::Sqrt(dist) : -1;
271 //______________________________________________________________________
272 Float_t AliAnalysisUtils::GetMultiplicityPercentile(AliVEvent *event, TString lMethod ){
274 fPPVsMultUtils=new AliPPVsMultUtils();
275 if( (event->InheritsFrom("AliAODEvent")) || (event->InheritsFrom("AliESDEvent")) ) return fPPVsMultUtils->GetMultiplicityPercentile(event,lMethod);
277 AliFatal("Event is neither of AOD nor ESD type");