2 #include "AliESDEvent.h"
3 #include "AliAODEvent.h"
4 #include "AliVVertex.h"
6 #include "AliAODVertex.h"
9 #include <TMatrixDSym.h>
11 #include "AliVMultiplicity.h"
13 #include "AliAnalysisUtils.h"
15 ClassImp(AliAnalysisUtils)
17 //______________________________________________________________________
18 AliAnalysisUtils::AliAnalysisUtils():TObject(),
22 fCutOnZVertexSPD(kTRUE),
23 fUseMVPlpSelection(kFALSE),
24 fUseOutOfBunchPileUp(kFALSE),
28 fCheckPlpFromDifferentBCMV(kFALSE),
31 fnSigmaPlpZdistSPD(3.),
32 fnSigmaPlpDiamXYSPD(2.),
33 fnSigmaPlpDiamZSPD(5.),
34 fUseSPDCutInMultBins(kFALSE),
41 //______________________________________________________________________
42 Bool_t AliAnalysisUtils::IsVertexSelected2013pA(AliVEvent *event)
44 Bool_t accept = kFALSE;
46 // Check whether the event is of AOD or ESD type
47 AliAODEvent *aod = 0x0;
48 AliESDEvent *esd = 0x0;
49 aod = dynamic_cast<AliAODEvent*>(event);
50 esd = dynamic_cast<AliESDEvent*>(event);
57 AliFatal("Event is neither of AOD nor ESD type");
62 const AliVVertex *trkVtx = fisAOD ?
63 dynamic_cast<const AliVVertex*>(aod->GetPrimaryVertex()) :
64 dynamic_cast<const AliVVertex*>(esd->GetPrimaryVertex()) ;
65 if(!trkVtx || trkVtx->GetNContributors()<=fMinVtxContr){
70 TString vtxTtl = trkVtx->GetTitle();
71 if (!vtxTtl.Contains("VertexerTracks")) return accept;
73 Float_t zvtx = trkVtx->GetZ();
74 const AliVVertex* spdVtx = fisAOD ?
75 dynamic_cast<const AliVVertex*>(aod->GetPrimaryVertexSPD()) :
76 dynamic_cast<const AliVVertex*>(esd->GetPrimaryVertexSPD()) ;
77 if (spdVtx->GetNContributors()<=fMinVtxContr) return accept;
79 TString vtxTyp = spdVtx->GetTitle();
81 spdVtx->GetCovarianceMatrix(cov);
82 Double_t zRes = TMath::Sqrt(cov[5]);
83 if (vtxTyp.Contains("vertexer:Z") && (zRes>0.25)) return accept;
84 if (fCutOnZVertexSPD && TMath::Abs(spdVtx->GetZ() - trkVtx->GetZ())>0.5) return accept;
86 if (TMath::Abs(zvtx) > fMaxVtxZ) return accept;
91 //______________________________________________________________________
92 Bool_t AliAnalysisUtils::IsFirstEventInChunk(AliVEvent *event)
95 Bool_t accept = kFALSE;
97 // Check whether the event is of AOD or ESD type
98 AliAODEvent *aod = 0x0;
99 AliESDEvent *esd = 0x0;
100 aod = dynamic_cast<AliAODEvent*>(event);
101 esd = dynamic_cast<AliESDEvent*>(event);
108 AliFatal("Event is neither of AOD nor ESD type");
114 AliAODHeader *aodheader = 0x0;
115 aodheader = aod->GetHeader();
117 AliFatal("AOD header not there ?!");
120 if(aodheader->GetEventNumberESDFile()==0) accept = kTRUE;
122 if(esd->GetEventNumberInFile()==0) accept = kTRUE;
128 //______________________________________________________________________
129 Bool_t AliAnalysisUtils::IsPileUpEvent(AliVEvent *event)
131 Bool_t isPileUp=kFALSE;
132 //check for multiple vertices
133 if(fUseMVPlpSelection)isPileUp=IsPileUpMV(event);
134 else isPileUp=IsPileUpSPD(event);
135 //check for different BC
136 if(fUseOutOfBunchPileUp && IsOutOfBunchPileUp(event))isPileUp=kTRUE;
141 //______________________________________________________________________
142 Bool_t AliAnalysisUtils::IsPileUpMV(AliVEvent *event)
144 // check for multi-vertexer pile-up
145 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
146 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
149 AliFatal("Event is neither of AOD nor ESD type");
153 const AliVVertex* vtPrm = 0;
154 const AliVVertex* vtPlp = 0;
158 if ( !(nPlp=aod->GetNumberOfPileupVerticesTracks()) ) return kFALSE;
159 vtPrm = aod->GetPrimaryVertex();
160 if (vtPrm == aod->GetPrimaryVertexSPD()) return kTRUE; // there are pile-up vertices but no primary
163 if ( !(nPlp=esd->GetNumberOfPileupVerticesTracks())) return kFALSE;
164 vtPrm = esd->GetPrimaryVertexTracks();
165 if (((AliESDVertex*)vtPrm)->GetStatus()!=1) return kTRUE; // there are pile-up vertices but no primary
167 Int_t bcPrim = vtPrm->GetBC();
169 for (Int_t ipl=0;ipl<nPlp;ipl++) {
170 vtPlp = aod ? (const AliVVertex*)aod->GetPileupVertexTracks(ipl) : (const AliVVertex*)esd->GetPileupVertexTracks(ipl);
172 if (vtPlp->GetNContributors() < fMinPlpContribMV) continue;
173 if (vtPlp->GetChi2perNDF() > fMaxPlpChi2MV) continue;
174 if(fCheckPlpFromDifferentBCMV)
176 Int_t bcPlp = vtPlp->GetBC();
177 if (bcPlp!=AliVTrack::kTOFBCNA && TMath::Abs(bcPlp-bcPrim)>2) return kTRUE; // pile-up from other BC
180 Double_t wDst = GetWDist(vtPrm,vtPlp);
181 if (wDst<fMinWDistMV) continue;
183 return kTRUE; // pile-up: well separated vertices
190 //______________________________________________________________________
191 Bool_t AliAnalysisUtils::IsPileUpSPD(AliVEvent *event)
193 // check for SPD pile-up
194 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
195 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
198 AliFatal("Event is neither of AOD nor ESD type");
202 if (aod) return (fUseSPDCutInMultBins)?aod->IsPileupFromSPDInMultBins():aod->IsPileupFromSPD(fMinPlpContribSPD,fMinPlpZdistSPD,fnSigmaPlpZdistSPD,fnSigmaPlpDiamXYSPD,fnSigmaPlpDiamZSPD);
203 else return (fUseSPDCutInMultBins)?esd->IsPileupFromSPDInMultBins():esd->IsPileupFromSPD(fMinPlpContribSPD,fMinPlpZdistSPD,fnSigmaPlpZdistSPD,fnSigmaPlpDiamXYSPD,fnSigmaPlpDiamZSPD);
206 //______________________________________________________________________
207 Bool_t AliAnalysisUtils::IsOutOfBunchPileUp(AliVEvent *event)
209 // check for SPD pile-up
210 const AliAODEvent *aod = dynamic_cast<const AliAODEvent*>(event);
211 const AliESDEvent *esd = dynamic_cast<const AliESDEvent*>(event);
214 AliFatal("Event is neither of AOD nor ESD type");
217 Int_t bc2 = (aod)?aod->GetHeader()->GetIRInt2ClosestInteractionMap():esd->GetHeader()->GetIRInt2ClosestInteractionMap();
221 Int_t bc1 = (aod)?aod->GetHeader()->GetIRInt1ClosestInteractionMap():esd->GetHeader()->GetIRInt1ClosestInteractionMap();
229 //______________________________________________________________________
230 Bool_t AliAnalysisUtils::IsSPDClusterVsTrackletBG(AliVEvent *event){
231 Int_t nClustersLayer0 = event->GetNumberOfITSClusters(0);
232 Int_t nClustersLayer1 = event->GetNumberOfITSClusters(1);
233 Int_t nTracklets = event->GetMultiplicity()->GetNumberOfTracklets();
234 if (nClustersLayer0 + nClustersLayer1 > fASPDCvsTCut + nTracklets*fBSPDCvsTCut) return kTRUE;
239 //______________________________________________________________________
240 Double_t AliAnalysisUtils::GetWDist(const AliVVertex* v0, const AliVVertex* v1)
242 // calculate sqrt of weighted distance to other vertex
244 printf("One of vertices is not valid\n");
247 static TMatrixDSym vVb(3);
249 Double_t dx = v0->GetX()-v1->GetX();
250 Double_t dy = v0->GetY()-v1->GetY();
251 Double_t dz = v0->GetZ()-v1->GetZ();
252 Double_t cov0[6],cov1[6];
253 v0->GetCovarianceMatrix(cov0);
254 v1->GetCovarianceMatrix(cov1);
255 vVb(0,0) = cov0[0]+cov1[0];
256 vVb(1,1) = cov0[2]+cov1[2];
257 vVb(2,2) = cov0[5]+cov1[5];
258 vVb(1,0) = vVb(0,1) = cov0[1]+cov1[1];
259 vVb(0,2) = vVb(1,2) = vVb(2,0) = vVb(2,1) = 0.;
261 if (!vVb.IsValid()) {printf("Singular Matrix\n"); return dist;}
262 dist = vVb(0,0)*dx*dx + vVb(1,1)*dy*dy + vVb(2,2)*dz*dz
263 + 2*vVb(0,1)*dx*dy + 2*vVb(0,2)*dx*dz + 2*vVb(1,2)*dy*dz;
264 return dist>0 ? TMath::Sqrt(dist) : -1;