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 "AliDielectronVarCuts.h"
49 #include "AliDielectronTrackCuts.h"
50 #include "AliDielectronVarManager.h"
51 #include "AliDielectronHelper.h"
53 //_____________________________________________________________________________
54 TVectorD* AliDielectronHelper::MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
57 // Make logarithmic binning
58 // the user has to delete the array afterwards!!!
62 if (xmin<1e-20 || xmax<1e-20){
63 Error("AliDielectronHelper::MakeLogBinning","For Log binning xmin and xmax must be > 1e-20. Using linear binning instead!");
64 return AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
71 TVectorD *binLim=new TVectorD(nbinsX+1);
74 Double_t expMax=TMath::Log(last/first);
75 for (Int_t i=0; i<nbinsX+1; ++i){
76 (*binLim)[i]=first*TMath::Exp(expMax/nbinsX*(Double_t)i);
81 //_____________________________________________________________________________
82 TVectorD* AliDielectronHelper::MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
85 // Make linear binning
86 // the user has to delete the array afterwards!!!
93 TVectorD *binLim=new TVectorD(nbinsX+1);
96 Double_t binWidth=(last-first)/nbinsX;
97 for (Int_t i=0; i<nbinsX+1; ++i){
98 (*binLim)[i]=first+binWidth*(Double_t)i;
103 //_____________________________________________________________________________
104 TVectorD* AliDielectronHelper::MakeArbitraryBinning(const char* bins)
107 // Make arbitrary binning, bins separated by a ','
109 TString limits(bins);
110 if (limits.IsNull()){
111 Error("AliDielectronHelper::MakeArbitraryBinning","Bin Limit string is empty, cannot add the variable");
115 TObjArray *arr=limits.Tokenize(",");
116 Int_t nLimits=arr->GetEntries();
118 Error("AliDielectronHelper::MakeArbitraryBinning","Need at leas 2 bin limits, cannot add the variable");
123 TVectorD *binLimits=new TVectorD(nLimits);
124 for (Int_t iLim=0; iLim<nLimits; ++iLim){
125 (*binLimits)[iLim]=(static_cast<TObjString*>(arr->At(iLim)))->GetString().Atof();
133 //_____________________________________________________________________________
134 Int_t AliDielectronHelper::GetNch(const AliMCEvent *ev, Double_t etaRange){
135 // determination of Nch
136 if (!ev || ev->IsA()!=AliMCEvent::Class()) return -1;
138 AliStack *stack = ((AliMCEvent*)ev)->Stack();
140 if (!stack) return -1;
142 Int_t nParticles = stack->GetNtrack();
146 for (Int_t iMc = 0; iMc < nParticles; ++iMc) {
147 if (!stack->IsPhysicalPrimary(iMc)) continue;
149 TParticle* particle = stack->Particle(iMc);
150 if (!particle) continue;
151 if (particle->GetPDG()->Charge() == 0) continue;
153 Float_t eta = particle->Eta();
154 if (TMath::Abs(eta) < TMath::Abs(etaRange)) nCh++;
161 //_____________________________________________________________________________
162 Int_t AliDielectronHelper::GetNaccTrcklts(const AliVEvent *ev, Double_t etaRange){
163 // Compute the collision multiplicity based on AOD or ESD tracklets
164 // Code taken from: AliAnalysisTaskMuonCollisionMultiplicity::ComputeMultiplicity()
168 Int_t nTracklets = 0;
171 if (ev->IsA() == AliAODEvent::Class()) {
172 AliAODTracklets *tracklets = ((AliAODEvent*)ev)->GetTracklets();
173 if (!tracklets) return -1;
174 nTracklets = tracklets->GetNumberOfTracklets();
175 for (Int_t nn = 0; nn < nTracklets; nn++) {
176 Double_t theta = tracklets->GetTheta(nn);
177 Double_t eta = -TMath::Log(TMath::Tan(theta/2.0));
178 if (TMath::Abs(eta) < etaRange) nAcc++;
180 } else if (ev->IsA() == AliESDEvent::Class()) {
181 nTracklets = ((AliESDEvent*)ev)->GetMultiplicity()->GetNumberOfTracklets();
182 for (Int_t nn = 0; nn < nTracklets; nn++) {
183 Double_t eta = ((AliESDEvent*)ev)->GetMultiplicity()->GetEta(nn);
184 if (TMath::Abs(eta) < etaRange) nAcc++;
193 //________________________________________________________________
194 Double_t AliDielectronHelper::GetNaccTrckltsCorrected(const AliVEvent *event, Double_t uncorrectedNacc, Double_t vtxZ, Int_t type) {
196 // Correct the number of accepted tracklets based on the period and event vertex
199 Int_t runNo = event->GetRunNumber();
201 Int_t period = -1; // 0-LHC10b, 1-LHC10c, 2-LHC10d, 3-LHC10e
202 Double_t refMult = 0.0; // reference multiplicity
204 if(runNo>114930 && runNo<117223) period = 0;
205 if(runNo>119158 && runNo<120830) period = 1;
206 if(runNo>122373 && runNo<126438) period = 2;
207 if(runNo>127711 && runNo<130841) period = 3;
208 if(period<0 || period>3) return uncorrectedNacc;
210 if(type<0 || type>8) return uncorrectedNacc;
211 if(type == 0) refMult = 5.0; // SPD tracklets in |eta|<0.5
212 if(type == 1) refMult = 9.5; // SPD tracklets in |eta|<1.0
213 if(type == 2) refMult = 13.0; // SPD tracklets in |eta|<1.6
214 if(type == 3) refMult = 6.0; // ITSTPC+ in |eta|<0.5
215 if(type == 4) refMult = 12.0; // ITSTPC+ in |eta|<1.0
216 if(type == 5) refMult = 16.0; // ITSTPC+ in |eta|<1.6
217 if(type == 6) refMult = 6.0; // ITSSA+ in |eta|<0.5
218 if(type == 7) refMult = 12.0; // ITSSA+ in |eta|<1.0
219 if(type == 8) refMult = 15.0; // ITSSA+ in |eta|<1.6
221 if(TMath::Abs(vtxZ)>10.0) return uncorrectedNacc;
223 TProfile* estimatorAvg = AliDielectronVarManager::GetEstimatorHistogram(period, type);
224 if(!estimatorAvg) return uncorrectedNacc;
226 Double_t localAvg = estimatorAvg->GetBinContent(estimatorAvg->FindBin(vtxZ));
228 Double_t deltaM = uncorrectedNacc*(refMult/localAvg - 1);
230 Double_t correctedNacc = uncorrectedNacc + (deltaM>0 ? 1 : -1) * gRandom->Poisson(TMath::Abs(deltaM));
232 return correctedNacc;
235 //_____________________________________________________________________________
236 Int_t AliDielectronHelper::GetNacc(const AliVEvent *ev){
237 // put a robust Nacc definition here
241 AliDielectronVarCuts *varCuts = new AliDielectronVarCuts("VarCuts","VarCuts");
242 varCuts->AddCut(AliDielectronVarManager::kImpactParXY, -1.0, 1.0);
243 varCuts->AddCut(AliDielectronVarManager::kImpactParZ, -3.0, 3.0);
244 varCuts->AddCut(AliDielectronVarManager::kEta, -0.9, 0.9);
245 varCuts->AddCut(AliDielectronVarManager::kTPCchi2Cl, 0.0, 4.0);
246 varCuts->AddCut(AliDielectronVarManager::kNclsTPC, 70.0, 160.0);
247 varCuts->AddCut(AliDielectronVarManager::kKinkIndex0, -0.5, 0.5); //noKinks
249 AliDielectronTrackCuts *trkCuts = new AliDielectronTrackCuts("TrkCuts","TrkCuts");
250 trkCuts->SetClusterRequirementITS(AliDielectronTrackCuts::kSPD, AliDielectronTrackCuts::kAny);
251 trkCuts->SetRequireITSRefit(kTRUE);
252 trkCuts->SetRequireTPCRefit(kTRUE);
254 Int_t nRecoTracks = ev->GetNumberOfTracks();
257 for (Int_t iTrack = 0; iTrack < nRecoTracks; iTrack++) {
258 AliVTrack *track = static_cast<AliVTrack*>(ev->GetTrack(iTrack));
259 if (!track) continue;
260 if (varCuts->IsSelected(track) && trkCuts->IsSelected(track))
270 //_____________________________________________________________________________
271 void AliDielectronHelper::RotateKFParticle(AliKFParticle * kfParticle,Double_t angle, const AliVEvent * const ev){
272 // Before rotate needs to be moved to position 0,0,0, ; move back after rotation
273 if (!kfParticle) return;
279 dx = ev->GetPrimaryVertex()->GetX()-0.;
280 dy = ev->GetPrimaryVertex()->GetY()-0.;
281 dz = ev->GetPrimaryVertex()->GetZ()-0.;
284 kfParticle->X() = kfParticle->GetX() - dx;
285 kfParticle->Y() = kfParticle->GetY() - dy;
286 kfParticle->Z() = kfParticle->GetZ() - dz;
289 // Rotate the kf particle
290 Double_t c = cos(angle);
291 Double_t s = sin(angle);
294 for( Int_t i=0; i<8; i++ ){
295 for( Int_t j=0; j<8; j++){
299 for( int i=0; i<8; i++ ){
302 mA[0][0] = c; mA[0][1] = s;
303 mA[1][0] = -s; mA[1][1] = c;
304 mA[3][3] = c; mA[3][4] = s;
305 mA[4][3] = -s; mA[4][4] = c;
310 for( Int_t i=0; i<8; i++ ){
312 for( Int_t k=0; k<8; k++){
313 mAp[i]+=mA[i][k] * kfParticle->GetParameter(k);
317 for( Int_t i=0; i<8; i++){
318 kfParticle->Parameter(i) = mAp[i];
321 for( Int_t i=0; i<8; i++ ){
322 for( Int_t j=0; j<8; j++ ){
324 for( Int_t k=0; k<8; k++ ){
325 mAC[i][j]+= mA[i][k] * kfParticle->GetCovariance(k,j);
330 for( Int_t i=0; i<8; i++ ){
331 for( Int_t j=0; j<=i; j++ ){
333 for( Int_t k=0; k<8; k++){
334 xx+= mAC[i][k]*mA[j][k];
336 kfParticle->Covariance(i,j) = xx;
340 kfParticle->X() = kfParticle->GetX() + dx;
341 kfParticle->Y() = kfParticle->GetY() + dy;
342 kfParticle->Z() = kfParticle->GetZ() + dz;
346 //_____________________________________________________________________________
347 Int_t AliDielectronHelper::GetNMothers(const AliMCEvent *ev, Double_t etaRange, Int_t pdgMother, Int_t pdgDaughter, Int_t prim){
349 // counting number of mother particles generated in given eta range and 2 particle decay
350 if (!ev || ev->IsA()!=AliMCEvent::Class()) return -1;
352 AliStack *stack = ((AliMCEvent*)ev)->Stack();
354 if (!stack) return -1;
356 Int_t nParticles = stack->GetNtrack();
360 for (Int_t iMc = 0; iMc < nParticles; ++iMc) {
362 TParticle* particle = stack->Particle(iMc);
363 if (!particle) continue;
364 if (particle->GetPdgCode() != pdgMother) continue;
365 if (TMath::Abs(particle->Eta()) > TMath::Abs(etaRange)) continue;
367 if (particle->GetNDaughters() != 2) continue;
369 if (particle->GetFirstDaughter()>=nParticles ||
370 particle->GetFirstDaughter()<0 ) continue;
372 TParticle* dau1 = stack->Particle(particle->GetFirstDaughter());
373 if (TMath::Abs(dau1->GetPdgCode()) != pdgDaughter) continue;
374 if (TMath::Abs(dau1->Eta()) > TMath::Abs(etaRange)) continue;
377 if (particle->GetLastDaughter()>=nParticles ||
378 particle->GetLastDaughter()<0 ) continue;
380 TParticle* dau2 = stack->Particle(particle->GetLastDaughter());
381 if (TMath::Abs(dau2->GetPdgCode()) != pdgDaughter) continue;
382 if (TMath::Abs(dau2->Eta()) > TMath::Abs(etaRange)) continue;
386 if(particle->IsPrimary() != prim) continue;