4 #include "TLorentzVector.h"
7 #include "AliESDEvent.h"
8 #include "AliESDVertex.h"
9 #include "AliESDtrack.h"
11 #include "AliMCEvent.h"
13 #include "AliRsnAnalysisPhi900GeV.h"
16 AliRsnAnalysisPhi900GeV::AliRsnAnalysisPhi900GeV(const char *name) :
17 AliAnalysisTaskSE(name),
34 fTOFSettings(AliRsnTOFT0maker::kNone)
40 DefineOutput(1, TTree::Class());
44 AliRsnAnalysisPhi900GeV::AliRsnAnalysisPhi900GeV(const AliRsnAnalysisPhi900GeV& copy) :
45 AliAnalysisTaskSE(copy),
56 fMinTPC(copy.fMinTPC),
57 fMaxTPC(copy.fMaxTPC),
59 fTOFESD(copy.fTOFESD),
60 fTOFSigma(copy.fTOFSigma),
62 fTOFSettings(copy.fTOFSettings)
70 AliRsnAnalysisPhi900GeV& AliRsnAnalysisPhi900GeV::operator=(const AliRsnAnalysisPhi900GeV& copy)
73 // Assignment operator
83 fMinTPC = copy.fMinTPC;
84 fMaxTPC = copy.fMaxTPC;
86 fTOFESD = copy.fTOFESD;
87 fTOFSigma = copy.fTOFSigma;
88 fTOFSettings = copy.fTOFSettings;
94 AliRsnAnalysisPhi900GeV::~AliRsnAnalysisPhi900GeV()
100 if (fOutTree) delete fOutTree;
104 void AliRsnAnalysisPhi900GeV::UserCreateOutputObjects()
107 // Create the output data container
111 fTOFmaker = new AliRsnTOFT0maker;
112 fTOFmaker->SetTimeResolution(fTOFSigma * 1E-12);
113 fTOFmaker->SetESDdata(fTOFESD);
114 fTOFmaker->fSettings = fTOFSettings;
115 AliInfo(Form("TOF sigma = %f", fTOFSigma));
116 AliInfo(Form("TOF ESD = %s", (fTOFESD ? "YES" : "NO")));
117 AliInfo(Form("TOF settings = %s", fTOFmaker->Settings().Data()));
119 // load dead channel map
120 fTOFmaker->LoadChannelMap("tofmap.root");
121 fTOFmaker->SetMaskOffChannel();
126 // create output trees
128 fOutTree = new TTree("rsnTree", "Pairs");
130 fOutTree->Branch("pdg", &fPDG, "pdg/S");
131 fOutTree->Branch("im" , &fIM , "im/F" );
132 fOutTree->Branch("y" , &fY , "y/F" );
133 fOutTree->Branch("pt" , &fPt , "pt/F" );
134 fOutTree->Branch("eta", &fEta, "eta/F");
138 void AliRsnAnalysisPhi900GeV::UserExec(Option_t *)
141 // Main execution function
144 // retrieve ESD event and related stack (if available)
145 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(fInputEvent);
146 AliStack *stack = (fMCEvent ? fMCEvent->Stack() : 0x0);
148 // get the best primary vertex:
149 // first try the one with tracks
151 const AliESDVertex *v = esd->GetPrimaryVertexTracks();
152 if(v->GetNContributors() < 1)
154 // if not good, try SPD vertex
156 v = esd->GetPrimaryVertexSPD();
158 // if this is not good skip this event
159 if (v->GetNContributors() < 1) return;
162 // if the Z position is larger than 10, skip this event
163 if (TMath::Abs(v->GetZv()) > 10.0) return;
165 // smear TOF times in case of MC
166 if (stack) RemakeTOFtimeMC(esd);
168 // get time zero for TOF
169 Double_t *tof = fTOFmaker->RemakePID(esd);
171 if (!fUseMC) ProcessESD(esd, v, tof[0], stack);
172 else ProcessMC(stack);
176 void AliRsnAnalysisPhi900GeV::Terminate(Option_t *)
184 void AliRsnAnalysisPhi900GeV::ProcessESD
185 (AliESDEvent *esd, const AliESDVertex *v, Double_t time0, AliStack *stack)
188 // This function works with the ESD object
191 // prepare to look on all tracks to select the ones
192 // which pass all the cuts
193 Int_t ntracks = esd->GetNumberOfTracks();
194 TArrayI pos(ntracks);
195 TArrayI neg(ntracks);
197 // define fixed functions for TOF compatibility range
198 Double_t a1 = 0.01, a2 = -0.03;
199 Double_t b1 = 0.25, b2 = 0.25;
200 Double_t c1 = 0.05, c2 = -0.03;
203 // loop on all tracks
204 Int_t i, charge, nSPD, npos = 0, nneg = 0;
205 Float_t chi2, b[2], bCov[3];
206 Double_t tpc, bb, mom, tofTime, tofRef, tofRel, times[10];
208 for (i = 0; i < ntracks; i++)
210 AliESDtrack *track = esd->GetTrack(i);
211 if (!track) continue;
213 // skip if it has not the required flags
214 if (!track->IsOn(AliESDtrack::kTPCin)) continue;
215 if (!track->IsOn(AliESDtrack::kTPCrefit)) continue;
216 if (!track->IsOn(AliESDtrack::kITSrefit)) continue;
218 // skip if it has not the TPC inner wall projection
219 if (!track->GetInnerParam()) continue;
221 // skip kink daughters
222 if ((Int_t)track->GetKinkIndex(0) > 0) continue;
224 // check clusters in TPC
225 if (track->GetTPCclusters(0) < fNTPC) continue;
228 chi2 = (Float_t)track->GetTPCchi2();
229 chi2 /= (Float_t)track->GetTPCclusters(0);
230 if (chi2 > fChi2) continue;
232 // check that has at least 1 SPD cluster
234 if (track->HasPointOnITSLayer(0)) nSPD++;
235 if (track->HasPointOnITSLayer(1)) nSPD++;
236 if (nSPD < 1) continue;
238 // check primary by reverting to vertex
240 if (!track->RelateToVertex(v, esd->GetMagneticField(), kVeryBig)) continue;
241 track->GetImpactParameters(b, bCov);
242 if (b[0] > fDCAr) continue;
243 if (b[1] > fDCAz) continue;
246 AliExternalTrackParam trackIn(*track->GetInnerParam());
248 tpc = (Double_t)track->GetTPCsignal();
250 tpc = (tpc - bb) / bb;
251 if (tpc < fMinTPC || tpc > fMaxTPC) continue;
253 // if possible, check TOF
255 if (track->IsOn(AliESDtrack::kTOFpid))
262 track->GetIntegratedTimes(times);
263 tofTime = (Double_t)track->GetTOFsignal() - time0;
264 tofRef = times[AliPID::kKaon];
265 tofRel = (tofTime - tofRef) / tofRef;
266 ymax = a1 / (mom - b1) + c1;
267 ymin = a2 / (mom - b2) + c2;
268 okTOF = (tofRel >= ymin && tofRel <= ymax);
271 if (!okTOF) continue;
273 // if we arrive here, all cuts were passed
274 // and we add the track to one array depending on charge
275 charge = (Int_t)track->Charge();
282 // resize arrays accordingly
286 // loop to compute invariant mass
287 Int_t ip, in, lp, ln;
289 Double_t kmass = pid.ParticleMass(AliPID::kKaon);
290 Double_t phimass = 1.019455;
291 TParticle *partp = 0x0, *partn = 0x0;
292 AliESDtrack *tp = 0x0, *tn = 0x0;
293 TLorentzVector vp, vn, vsum, vref;
294 for (ip = 0; ip < npos; ip++)
296 tp = esd->GetTrack(pos[ip]);
297 lp = TMath::Abs(tp->GetLabel());
298 if (stack) partp = stack->Particle(lp);
300 for (in = 0; in < nneg; in++)
302 if (pos[ip] == neg[in]) continue;
303 tn = esd->GetTrack(neg[in]);
304 ln = TMath::Abs(tn->GetLabel());
305 if (stack) partn = stack->Particle(ln);
310 if (partp->GetFirstMother() == partn->GetFirstMother())
312 if (partp->GetFirstMother() > 0)
314 TParticle *mum = stack->Particle(partp->GetFirstMother());
315 fPDG = mum->GetPdgCode();
319 fPDG = TMath::Abs(fPDG);
321 vp.SetXYZM(tp->Px(), tp->Py(), tp->Pz(), kmass);
322 vn.SetXYZM(tn->Px(), tn->Py(), tn->Pz(), kmass);
324 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
326 fIM = (Float_t)vsum.M();
327 fPt = (Float_t)vsum.Perp();
328 fEta = (Float_t)vsum.Eta();
329 fY = (Float_t)vref.Rapidity();
337 void AliRsnAnalysisPhi900GeV::ProcessMC(AliStack *stack)
340 // Function to process stack only
344 Int_t nPart = stack->GetNtrack();
346 // loop to compute invariant mass
349 Double_t kmass = pid.ParticleMass(AliPID::kKaon);
350 Double_t phimass = 1.019455;
351 TParticle *partp = 0x0, *partn = 0x0;
352 TLorentzVector vp, vn, vsum, vref;
354 for (ip = 0; ip < nPart; ip++)
356 partp = stack->Particle(ip);
357 if (partp->GetPdgCode() != 321) continue;
359 for (in = 0; in < nPart; in++)
361 partn = stack->Particle(in);
362 if (partn->GetPdgCode() != -321) continue;
365 if (partp->GetFirstMother() == partn->GetFirstMother())
367 if (partp->GetFirstMother() > 0)
369 TParticle *mum = stack->Particle(partp->GetFirstMother());
370 fPDG = mum->GetPdgCode();
373 fPDG = TMath::Abs(fPDG);
374 if (fPDG != 333) continue;
376 vp.SetXYZM(partp->Px(), partp->Py(), partp->Pz(), kmass);
377 vn.SetXYZM(partn->Px(), partn->Py(), partn->Pz(), kmass);
379 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
381 fIM = (Float_t)vsum.M();
382 fPt = (Float_t)vsum.Perp();
383 fEta = (Float_t)vsum.Eta();
384 fY = (Float_t)vref.Rapidity();
392 Double_t AliRsnAnalysisPhi900GeV::AlephBB(Double_t p, Double_t mass)
395 // Compute expected Bethe-Bloch for that momentum and mass
398 if (mass < 1E-6) return 0.0;
400 Double_t aa, bb, out, beta, bg;
403 beta = bg / TMath::Sqrt(1.0 + bg * bg);
404 aa = TMath::Power(beta, fTPCpar[3]);
405 bb = TMath::Power(1./bg, fTPCpar[4]);
406 bb = TMath::Log(fTPCpar[2] + bb);
407 out = (fTPCpar[1] - aa - bb) * fTPCpar[0]/aa;
413 Double_t AliRsnAnalysisPhi900GeV::RemakeTOFtimeMC(AliESDEvent *& esd)
416 // Smear initial time for TOF in order to reproduce data resolution
419 Double_t t0 = gRandom->Gaus(0,135.); //spread in ps
420 Int_t ntracks = esd->GetNumberOfTracks();
421 Double_t sigmaStandard = 80.; // 80 ps from TOF
425 AliESDtrack *t = esd->GetTrack(ntracks);
426 if ((t->GetStatus()&AliESDtrack::kTOFout) == 0 || (t->GetStatus()&AliESDtrack::kTIME)==0) continue;
427 Double_t time = t->GetTOFsignal();
428 if(fTOFSigma > sigmaStandard)
430 Double_t sigmaAdded = TMath::Sqrt(fTOFSigma*fTOFSigma - sigmaStandard*sigmaStandard);
431 Double_t timerandomtrack = gRandom->Gaus(0, sigmaAdded); //spread in ps
432 time += timerandomtrack;
435 t->SetTOFsignal(time);