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>
34 #include <AliVEvent.h>
35 #include <AliVParticle.h>
36 #include <AliKFParticle.h>
37 #include <AliESDtrackCuts.h>
38 #include <AliESDEvent.h>
39 #include <AliMCEvent.h>
40 #include <AliAODEvent.h>
41 #include <AliAODTracklets.h>
42 #include <AliMultiplicity.h>
45 #include "AliDielectronHelper.h"
47 //_____________________________________________________________________________
48 TVectorD* AliDielectronHelper::MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
51 // Make logarithmic binning
52 // the user has to delete the array afterwards!!!
56 if (xmin<1e-20 || xmax<1e-20){
57 Error("AliDielectronHelper::MakeLogBinning","For Log binning xmin and xmax must be > 1e-20. Using linear binning instead!");
58 return AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
65 TVectorD *binLim=new TVectorD(nbinsX+1);
68 Double_t expMax=TMath::Log(last/first);
69 for (Int_t i=0; i<nbinsX+1; ++i){
70 (*binLim)[i]=first*TMath::Exp(expMax/nbinsX*(Double_t)i);
75 //_____________________________________________________________________________
76 TVectorD* AliDielectronHelper::MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
79 // Make linear binning
80 // the user has to delete the array afterwards!!!
87 TVectorD *binLim=new TVectorD(nbinsX+1);
90 Double_t binWidth=(last-first)/nbinsX;
91 for (Int_t i=0; i<nbinsX+1; ++i){
92 (*binLim)[i]=first+binWidth*(Double_t)i;
97 //_____________________________________________________________________________
98 TVectorD* AliDielectronHelper::MakeArbitraryBinning(const char* bins)
101 // Make arbitrary binning, bins separated by a ','
103 TString limits(bins);
104 if (limits.IsNull()){
105 Error("AliDielectronHelper::MakeArbitraryBinning","Bin Limit string is empty, cannot add the variable");
109 TObjArray *arr=limits.Tokenize(",");
110 Int_t nLimits=arr->GetEntries();
112 Error("AliDielectronHelper::MakeArbitraryBinning","Need at leas 2 bin limits, cannot add the variable");
117 TVectorD *binLimits=new TVectorD(nLimits);
118 for (Int_t iLim=0; iLim<nLimits; ++iLim){
119 (*binLimits)[iLim]=(static_cast<TObjString*>(arr->At(iLim)))->GetString().Atof();
127 //_____________________________________________________________________________
128 Int_t AliDielectronHelper::GetNch(const AliMCEvent *ev, Double_t etaRange){
129 // determination of Nch
130 if (!ev || ev->IsA()!=AliMCEvent::Class()) return -1;
132 AliStack *stack = ((AliMCEvent*)ev)->Stack();
134 if (!stack) return -1;
136 Int_t nParticles = stack->GetNtrack();
140 for (Int_t iMc = 0; iMc < nParticles; ++iMc) {
141 if (!stack->IsPhysicalPrimary(iMc)) continue;
143 TParticle* particle = stack->Particle(iMc);
144 if (!particle) continue;
145 if (particle->GetPDG()->Charge() == 0) continue;
147 Float_t eta = particle->Eta();
148 if (TMath::Abs(eta) < TMath::Abs(etaRange)) nCh++;
155 //_____________________________________________________________________________
156 Int_t AliDielectronHelper::GetNaccTrcklts(const AliVEvent *ev){
157 // Compute the collision multiplicity based on AOD or ESD tracklets
158 // Code taken from: AliAnalysisTaskMuonCollisionMultiplicity::ComputeMultiplicity()
162 Int_t nTracklets = 0;
164 Double_t etaRange = 1.6;
166 if (ev->IsA() == AliAODEvent::Class()) {
167 AliAODTracklets *tracklets = ((AliAODEvent*)ev)->GetTracklets();
168 nTracklets = tracklets->GetNumberOfTracklets();
169 for (Int_t nn = 0; nn < nTracklets; nn++) {
170 Double_t theta = tracklets->GetTheta(nn);
171 Double_t eta = -TMath::Log(TMath::Tan(theta/2.0));
172 if (TMath::Abs(eta) < etaRange) nAcc++;
174 } else if (ev->IsA() == AliESDEvent::Class()) {
175 nTracklets = ((AliESDEvent*)ev)->GetMultiplicity()->GetNumberOfTracklets();
176 for (Int_t nn = 0; nn < nTracklets; nn++) {
177 Double_t eta = ((AliESDEvent*)ev)->GetMultiplicity()->GetEta(nn);
178 if (TMath::Abs(eta) < etaRange) nAcc++;
186 //_____________________________________________________________________________
187 Int_t AliDielectronHelper::GetNacc(const AliVEvent */*ev*/){
188 // put a robust Nacc definition here
192 if (!ev || ev->IsA()!=AliESDEvent::Class()) return -1;
194 // basic track cuts for the N_acc definition
195 AliESDtrackCuts esdTC;
196 esdTC.SetMaxDCAToVertexZ(3.0);
197 esdTC.SetMaxDCAToVertexXY(1.0);
198 esdTC.SetEtaRange( -0.9 , 0.9 );
199 esdTC.SetAcceptKinkDaughters(kFALSE);
200 esdTC.SetRequireITSRefit(kTRUE);
201 esdTC.SetRequireTPCRefit(kTRUE);
202 esdTC.SetMinNClustersTPC(70);
203 esdTC.SetMaxChi2PerClusterTPC(4);
204 esdTC.SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
206 Int_t nRecoTracks = ev->GetNumberOfTracks();
209 for (Int_t iTrack = 0; iTrack < nRecoTracks; iTrack++) {
210 AliVParticle* candidate = ev->GetTrack(iTrack);
211 if (esdTC.IsSelected(candidate)) nAcc++;
219 //_____________________________________________________________________________
220 void AliDielectronHelper::RotateKFParticle(AliKFParticle * kfParticle,Double_t angle, const AliVEvent * const ev){
221 // Before rotate needs to be moved to position 0,0,0, ; move back after rotation
222 if (!kfParticle) return;
228 dx = ev->GetPrimaryVertex()->GetX()-0.;
229 dy = ev->GetPrimaryVertex()->GetY()-0.;
230 dz = ev->GetPrimaryVertex()->GetZ()-0.;
233 kfParticle->X() = kfParticle->GetX() - dx;
234 kfParticle->Y() = kfParticle->GetY() - dy;
235 kfParticle->Z() = kfParticle->GetZ() - dz;
238 // Rotate the kf particle
239 Double_t c = cos(angle);
240 Double_t s = sin(angle);
243 for( Int_t i=0; i<8; i++ ){
244 for( Int_t j=0; j<8; j++){
248 for( int i=0; i<8; i++ ){
251 mA[0][0] = c; mA[0][1] = s;
252 mA[1][0] = -s; mA[1][1] = c;
253 mA[3][3] = c; mA[3][4] = s;
254 mA[4][3] = -s; mA[4][4] = c;
259 for( Int_t i=0; i<8; i++ ){
261 for( Int_t k=0; k<8; k++){
262 mAp[i]+=mA[i][k] * kfParticle->GetParameter(k);
266 for( Int_t i=0; i<8; i++){
267 kfParticle->Parameter(i) = mAp[i];
270 for( Int_t i=0; i<8; i++ ){
271 for( Int_t j=0; j<8; j++ ){
273 for( Int_t k=0; k<8; k++ ){
274 mAC[i][j]+= mA[i][k] * kfParticle->GetCovariance(k,j);
279 for( Int_t i=0; i<8; i++ ){
280 for( Int_t j=0; j<=i; j++ ){
282 for( Int_t k=0; k<8; k++){
283 xx+= mAC[i][k]*mA[j][k];
285 kfParticle->Covariance(i,j) = xx;
289 kfParticle->X() = kfParticle->GetX() + dx;
290 kfParticle->Y() = kfParticle->GetY() + dy;
291 kfParticle->Z() = kfParticle->GetZ() + dz;