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 = aod->GetHeader();
119 AliFatal("AOD header not there ?!");
122 if(aodheader->GetEventNumberESDFile()==0) accept = kTRUE;
124 if(esd->GetEventNumberInFile()==0) accept = kTRUE;
130 //______________________________________________________________________
131 Bool_t AliAnalysisUtils::IsPileUpEvent(AliVEvent *event)
133 Bool_t isPileUp=kFALSE;
134 //check for multiple vertices
135 if(fUseMVPlpSelection)isPileUp=IsPileUpMV(event);
136 else isPileUp=IsPileUpSPD(event);
137 //check for different BC
138 if(fUseOutOfBunchPileUp && IsOutOfBunchPileUp(event))isPileUp=kTRUE;
143 //______________________________________________________________________
144 Bool_t AliAnalysisUtils::IsPileUpMV(AliVEvent *event)
146 // check for multi-vertexer pile-up
147 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
148 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
151 AliFatal("Event is neither of AOD nor ESD type");
155 const AliVVertex* vtPrm = 0;
156 const AliVVertex* vtPlp = 0;
160 if ( !(nPlp=aod->GetNumberOfPileupVerticesTracks()) ) return kFALSE;
161 vtPrm = aod->GetPrimaryVertex();
162 if (vtPrm == aod->GetPrimaryVertexSPD()) return kTRUE; // there are pile-up vertices but no primary
165 if ( !(nPlp=esd->GetNumberOfPileupVerticesTracks())) return kFALSE;
166 vtPrm = esd->GetPrimaryVertexTracks();
167 if (((AliESDVertex*)vtPrm)->GetStatus()!=1) return kTRUE; // there are pile-up vertices but no primary
169 Int_t bcPrim = vtPrm->GetBC();
171 for (Int_t ipl=0;ipl<nPlp;ipl++) {
172 vtPlp = aod ? (const AliVVertex*)aod->GetPileupVertexTracks(ipl) : (const AliVVertex*)esd->GetPileupVertexTracks(ipl);
174 if (vtPlp->GetNContributors() < fMinPlpContribMV) continue;
175 if (vtPlp->GetChi2perNDF() > fMaxPlpChi2MV) continue;
176 if(fCheckPlpFromDifferentBCMV)
178 Int_t bcPlp = vtPlp->GetBC();
179 if (bcPlp!=AliVTrack::kTOFBCNA && TMath::Abs(bcPlp-bcPrim)>2) return kTRUE; // pile-up from other BC
182 Double_t wDst = GetWDist(vtPrm,vtPlp);
183 if (wDst<fMinWDistMV) continue;
185 return kTRUE; // pile-up: well separated vertices
192 //______________________________________________________________________
193 Bool_t AliAnalysisUtils::IsPileUpSPD(AliVEvent *event)
195 // check for SPD pile-up
196 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
197 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
200 AliFatal("Event is neither of AOD nor ESD type");
204 if (aod) return (fUseSPDCutInMultBins)?aod->IsPileupFromSPDInMultBins():aod->IsPileupFromSPD(fMinPlpContribSPD,fMinPlpZdistSPD,fnSigmaPlpZdistSPD,fnSigmaPlpDiamXYSPD,fnSigmaPlpDiamZSPD);
205 else return (fUseSPDCutInMultBins)?esd->IsPileupFromSPDInMultBins():esd->IsPileupFromSPD(fMinPlpContribSPD,fMinPlpZdistSPD,fnSigmaPlpZdistSPD,fnSigmaPlpDiamXYSPD,fnSigmaPlpDiamZSPD);
208 //______________________________________________________________________
209 Bool_t AliAnalysisUtils::IsOutOfBunchPileUp(AliVEvent *event)
211 // check for SPD pile-up
212 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
213 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
216 AliFatal("Event is neither of AOD nor ESD type");
219 Int_t bc2 = (aod)?aod->GetHeader()->GetIRInt2ClosestInteractionMap():esd->GetHeader()->GetIRInt2ClosestInteractionMap();
223 Int_t bc1 = (aod)?aod->GetHeader()->GetIRInt1ClosestInteractionMap():esd->GetHeader()->GetIRInt1ClosestInteractionMap();
231 //______________________________________________________________________
232 Bool_t AliAnalysisUtils::IsSPDClusterVsTrackletBG(AliVEvent *event){
233 Int_t nClustersLayer0 = event->GetNumberOfITSClusters(0);
234 Int_t nClustersLayer1 = event->GetNumberOfITSClusters(1);
235 Int_t nTracklets = event->GetMultiplicity()->GetNumberOfTracklets();
236 if (nClustersLayer0 + nClustersLayer1 > fASPDCvsTCut + nTracklets*fBSPDCvsTCut) return kTRUE;
241 //______________________________________________________________________
242 Double_t AliAnalysisUtils::GetWDist(const AliVVertex* v0, const AliVVertex* v1)
244 // calculate sqrt of weighted distance to other vertex
246 printf("One of vertices is not valid\n");
249 static TMatrixDSym vVb(3);
251 Double_t dx = v0->GetX()-v1->GetX();
252 Double_t dy = v0->GetY()-v1->GetY();
253 Double_t dz = v0->GetZ()-v1->GetZ();
254 Double_t cov0[6],cov1[6];
255 v0->GetCovarianceMatrix(cov0);
256 v1->GetCovarianceMatrix(cov1);
257 vVb(0,0) = cov0[0]+cov1[0];
258 vVb(1,1) = cov0[2]+cov1[2];
259 vVb(2,2) = cov0[5]+cov1[5];
260 vVb(1,0) = vVb(0,1) = cov0[1]+cov1[1];
261 vVb(0,2) = vVb(1,2) = vVb(2,0) = vVb(2,1) = 0.;
263 if (!vVb.IsValid()) {printf("Singular Matrix\n"); return dist;}
264 dist = vVb(0,0)*dx*dx + vVb(1,1)*dy*dy + vVb(2,2)*dz*dz
265 + 2*vVb(0,1)*dx*dy + 2*vVb(0,2)*dx*dz + 2*vVb(1,2)*dy*dz;
266 return dist>0 ? TMath::Sqrt(dist) : -1;
270 //______________________________________________________________________
271 Float_t AliAnalysisUtils::GetMultiplicityPercentile(AliVEvent *event, TString lMethod ){
273 fPPVsMultUtils=new AliPPVsMultUtils();
274 if( (event->InheritsFrom("AliAODEvent")) || (event->InheritsFrom("AliESDEvent")) ) return fPPVsMultUtils->GetMultiplicityPercentile(event,lMethod);
276 AliFatal("Event is neither of AOD nor ESD type");