1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 **************************************************************************/
17 // Dielectron helper functions wrapped in a namespace
21 // Jens Wiechula <Jens.Wiechula@cern.ch>
22 // Frederick Kramer <Frederick.Kramer@cern.ch>
30 #include <TObjString.h>
31 #include <TObjArray.h>
37 #include <AliVEvent.h>
38 #include <AliVParticle.h>
39 #include <AliKFParticle.h>
40 #include <AliESDtrackCuts.h>
41 #include <AliESDEvent.h>
42 #include <AliMCEvent.h>
43 #include <AliAODEvent.h>
44 #include <AliAODTracklets.h>
45 #include <AliMultiplicity.h>
48 #include "AliDielectronVarManager.h"
49 #include "AliDielectronHelper.h"
51 //_____________________________________________________________________________
52 TVectorD* AliDielectronHelper::MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
55 // Make logarithmic binning
56 // the user has to delete the array afterwards!!!
60 if (xmin<1e-20 || xmax<1e-20){
61 Error("AliDielectronHelper::MakeLogBinning","For Log binning xmin and xmax must be > 1e-20. Using linear binning instead!");
62 return AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
69 TVectorD *binLim=new TVectorD(nbinsX+1);
72 Double_t expMax=TMath::Log(last/first);
73 for (Int_t i=0; i<nbinsX+1; ++i){
74 (*binLim)[i]=first*TMath::Exp(expMax/nbinsX*(Double_t)i);
79 //_____________________________________________________________________________
80 TVectorD* AliDielectronHelper::MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
83 // Make linear binning
84 // the user has to delete the array afterwards!!!
91 TVectorD *binLim=new TVectorD(nbinsX+1);
94 Double_t binWidth=(last-first)/nbinsX;
95 for (Int_t i=0; i<nbinsX+1; ++i){
96 (*binLim)[i]=first+binWidth*(Double_t)i;
101 //_____________________________________________________________________________
102 TVectorD* AliDielectronHelper::MakeArbitraryBinning(const char* bins)
105 // Make arbitrary binning, bins separated by a ','
107 TString limits(bins);
108 if (limits.IsNull()){
109 Error("AliDielectronHelper::MakeArbitraryBinning","Bin Limit string is empty, cannot add the variable");
113 TObjArray *arr=limits.Tokenize(",");
114 Int_t nLimits=arr->GetEntries();
116 Error("AliDielectronHelper::MakeArbitraryBinning","Need at leas 2 bin limits, cannot add the variable");
121 TVectorD *binLimits=new TVectorD(nLimits);
122 for (Int_t iLim=0; iLim<nLimits; ++iLim){
123 (*binLimits)[iLim]=(static_cast<TObjString*>(arr->At(iLim)))->GetString().Atof();
131 //_____________________________________________________________________________
132 Int_t AliDielectronHelper::GetNch(const AliMCEvent *ev, Double_t etaRange){
133 // determination of Nch
134 if (!ev || ev->IsA()!=AliMCEvent::Class()) return -1;
136 AliStack *stack = ((AliMCEvent*)ev)->Stack();
138 if (!stack) return -1;
140 Int_t nParticles = stack->GetNtrack();
144 for (Int_t iMc = 0; iMc < nParticles; ++iMc) {
145 if (!stack->IsPhysicalPrimary(iMc)) continue;
147 TParticle* particle = stack->Particle(iMc);
148 if (!particle) continue;
149 if (particle->GetPDG()->Charge() == 0) continue;
151 Float_t eta = particle->Eta();
152 if (TMath::Abs(eta) < TMath::Abs(etaRange)) nCh++;
159 //_____________________________________________________________________________
160 Int_t AliDielectronHelper::GetNaccTrcklts(const AliVEvent *ev, Double_t etaRange){
161 // Compute the collision multiplicity based on AOD or ESD tracklets
162 // Code taken from: AliAnalysisTaskMuonCollisionMultiplicity::ComputeMultiplicity()
166 Int_t nTracklets = 0;
169 if (ev->IsA() == AliAODEvent::Class()) {
170 AliAODTracklets *tracklets = ((AliAODEvent*)ev)->GetTracklets();
171 nTracklets = tracklets->GetNumberOfTracklets();
172 for (Int_t nn = 0; nn < nTracklets; nn++) {
173 Double_t theta = tracklets->GetTheta(nn);
174 Double_t eta = -TMath::Log(TMath::Tan(theta/2.0));
175 if (TMath::Abs(eta) < etaRange) nAcc++;
177 } else if (ev->IsA() == AliESDEvent::Class()) {
178 nTracklets = ((AliESDEvent*)ev)->GetMultiplicity()->GetNumberOfTracklets();
179 for (Int_t nn = 0; nn < nTracklets; nn++) {
180 Double_t eta = ((AliESDEvent*)ev)->GetMultiplicity()->GetEta(nn);
181 if (TMath::Abs(eta) < etaRange) nAcc++;
190 //________________________________________________________________
191 Double_t AliDielectronHelper::GetNaccTrckltsCorrected(const AliVEvent *event, Double_t uncorrectedNacc, Double_t vtxZ, Int_t type) {
193 // Correct the number of accepted tracklets based on the period and event vertex
196 Int_t runNo = event->GetRunNumber();
198 Int_t period = -1; // 0-LHC10b, 1-LHC10c, 2-LHC10d, 3-LHC10e
199 Double_t refMult = 0.0; // reference multiplicity
201 if(runNo>114930 && runNo<117223) period = 0;
202 if(runNo>119158 && runNo<120830) period = 1;
203 if(runNo>122373 && runNo<126438) period = 2;
204 if(runNo>127711 && runNo<130841) period = 3;
205 if(period<0 || period>3) return uncorrectedNacc;
207 if(type<0 || type>8) return uncorrectedNacc;
208 if(type == 0) refMult = 5.0; // SPD tracklets in |eta|<0.5
209 if(type == 1) refMult = 9.5; // SPD tracklets in |eta|<1.0
210 if(type == 2) refMult = 13.0; // SPD tracklets in |eta|<1.6
211 if(type == 3) refMult = 6.0; // ITSTPC+ in |eta|<0.5
212 if(type == 4) refMult = 12.0; // ITSTPC+ in |eta|<1.0
213 if(type == 5) refMult = 16.0; // ITSTPC+ in |eta|<1.6
214 if(type == 6) refMult = 6.0; // ITSSA+ in |eta|<0.5
215 if(type == 7) refMult = 12.0; // ITSSA+ in |eta|<1.0
216 if(type == 8) refMult = 15.0; // ITSSA+ in |eta|<1.6
218 if(TMath::Abs(vtxZ)>10.0) return uncorrectedNacc;
220 TProfile* estimatorAvg = AliDielectronVarManager::GetEstimatorHistogram(period, type);
221 if(!estimatorAvg) return uncorrectedNacc;
223 Double_t localAvg = estimatorAvg->GetBinContent(estimatorAvg->FindBin(vtxZ));
225 Double_t deltaM = uncorrectedNacc*(refMult/localAvg - 1);
227 Double_t correctedNacc = uncorrectedNacc + (deltaM>0 ? 1 : -1) * gRandom->Poisson(TMath::Abs(deltaM));
229 return correctedNacc;
232 //_____________________________________________________________________________
233 Int_t AliDielectronHelper::GetNacc(const AliVEvent */*ev*/){
234 // put a robust Nacc definition here
238 if (!ev || ev->IsA()!=AliESDEvent::Class()) return -1;
240 // basic track cuts for the N_acc definition
241 AliESDtrackCuts esdTC;
242 esdTC.SetMaxDCAToVertexZ(3.0);
243 esdTC.SetMaxDCAToVertexXY(1.0);
244 esdTC.SetEtaRange( -0.9 , 0.9 );
245 esdTC.SetAcceptKinkDaughters(kFALSE);
246 esdTC.SetRequireITSRefit(kTRUE);
247 esdTC.SetRequireTPCRefit(kTRUE);
248 esdTC.SetMinNClustersTPC(70);
249 esdTC.SetMaxChi2PerClusterTPC(4);
250 esdTC.SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
252 Int_t nRecoTracks = ev->GetNumberOfTracks();
255 for (Int_t iTrack = 0; iTrack < nRecoTracks; iTrack++) {
256 AliVParticle* candidate = ev->GetTrack(iTrack);
257 if (esdTC.IsSelected(candidate)) nAcc++;
265 //_____________________________________________________________________________
266 void AliDielectronHelper::RotateKFParticle(AliKFParticle * kfParticle,Double_t angle, const AliVEvent * const ev){
267 // Before rotate needs to be moved to position 0,0,0, ; move back after rotation
268 if (!kfParticle) return;
274 dx = ev->GetPrimaryVertex()->GetX()-0.;
275 dy = ev->GetPrimaryVertex()->GetY()-0.;
276 dz = ev->GetPrimaryVertex()->GetZ()-0.;
279 kfParticle->X() = kfParticle->GetX() - dx;
280 kfParticle->Y() = kfParticle->GetY() - dy;
281 kfParticle->Z() = kfParticle->GetZ() - dz;
284 // Rotate the kf particle
285 Double_t c = cos(angle);
286 Double_t s = sin(angle);
289 for( Int_t i=0; i<8; i++ ){
290 for( Int_t j=0; j<8; j++){
294 for( int i=0; i<8; i++ ){
297 mA[0][0] = c; mA[0][1] = s;
298 mA[1][0] = -s; mA[1][1] = c;
299 mA[3][3] = c; mA[3][4] = s;
300 mA[4][3] = -s; mA[4][4] = c;
305 for( Int_t i=0; i<8; i++ ){
307 for( Int_t k=0; k<8; k++){
308 mAp[i]+=mA[i][k] * kfParticle->GetParameter(k);
312 for( Int_t i=0; i<8; i++){
313 kfParticle->Parameter(i) = mAp[i];
316 for( Int_t i=0; i<8; i++ ){
317 for( Int_t j=0; j<8; j++ ){
319 for( Int_t k=0; k<8; k++ ){
320 mAC[i][j]+= mA[i][k] * kfParticle->GetCovariance(k,j);
325 for( Int_t i=0; i<8; i++ ){
326 for( Int_t j=0; j<=i; j++ ){
328 for( Int_t k=0; k<8; k++){
329 xx+= mAC[i][k]*mA[j][k];
331 kfParticle->Covariance(i,j) = xx;
335 kfParticle->X() = kfParticle->GetX() + dx;
336 kfParticle->Y() = kfParticle->GetY() + dy;
337 kfParticle->Z() = kfParticle->GetZ() + dz;
341 //_____________________________________________________________________________
342 Int_t AliDielectronHelper::GetNMothers(const AliMCEvent *ev, Double_t etaRange, Int_t pdgMother, Int_t pdgDaughter, Int_t prim){
343 // counting number of mother particles generated in given eta range and 2 particle decay
344 if (!ev || ev->IsA()!=AliMCEvent::Class()) return -1;
346 AliStack *stack = ((AliMCEvent*)ev)->Stack();
348 if (!stack) return -1;
350 Int_t nParticles = stack->GetNtrack();
354 for (Int_t iMc = 0; iMc < nParticles; ++iMc) {
356 TParticle* particle = stack->Particle(iMc);
357 if (!particle) continue;
358 if (particle->GetPdgCode() != pdgMother) continue;
359 if (TMath::Abs(particle->Eta()) > TMath::Abs(etaRange)) continue;
361 if (particle->GetNDaughters() != 2) continue;
363 if (particle->GetFirstDaughter()>=nParticles ||
364 particle->GetFirstDaughter()<0 ) continue;
366 TParticle* dau1 = stack->Particle(particle->GetFirstDaughter());
367 if (TMath::Abs(dau1->GetPdgCode()) != pdgDaughter) continue;
368 if (TMath::Abs(dau1->Eta()) > TMath::Abs(etaRange)) continue;
371 if (particle->GetLastDaughter()>=nParticles ||
372 particle->GetLastDaughter()<0 ) continue;
374 TParticle* dau2 = stack->Particle(particle->GetLastDaughter());
375 if (TMath::Abs(dau2->GetPdgCode()) != pdgDaughter) continue;
376 if (TMath::Abs(dau2->Eta()) > TMath::Abs(etaRange)) continue;
380 if(particle->IsPrimary() != prim) continue;