2 // Implementation file for implementation of data analysis aft 900 GeV
4 // Author: A. Pulvirenti
12 #include "TParticle.h"
14 #include "TLorentzVector.h"
17 #include "AliESDpid.h"
18 #include "AliESDEvent.h"
19 #include "AliESDVertex.h"
20 #include "AliESDtrack.h"
22 #include "AliMCEvent.h"
23 #include "AliTOFT0maker.h"
24 #include "AliTOFcalib.h"
25 #include "AliCDBManager.h"
26 #include "AliITSPIDResponse.h"
28 #include "AliRsnAnalysisPhi7TeV.h"
30 //__________________________________________________________________________________________________
31 AliRsnAnalysisPhi7TeV::AliRsnAnalysisPhi7TeV(const char *name) :
32 AliAnalysisTaskSE(name),
57 fTOFcalibrateESD(kFALSE),
58 fTOFcorrectTExp(kFALSE),
68 DefineOutput(1, TTree::Class());
69 DefineOutput(2, TTree::Class());
70 DefineOutput(3, TList::Class());
73 //__________________________________________________________________________________________________
74 AliRsnAnalysisPhi7TeV::AliRsnAnalysisPhi7TeV(const AliRsnAnalysisPhi7TeV& copy) :
75 AliAnalysisTaskSE(copy),
77 fCheckITS(copy.fCheckITS),
78 fCheckTPC(copy.fCheckTPC),
79 fCheckTOF(copy.fCheckTOF),
87 fMaxITSband(copy.fMaxITSband),
88 fTPCpLimit(copy.fTPCpLimit),
89 fMinTPCband(copy.fMinTPCband),
90 fMaxTPCband(copy.fMaxTPCband),
95 fESDtrackCutsTPC(copy.fESDtrackCutsTPC),
96 fESDtrackCutsITS(copy.fESDtrackCutsITS),
100 fTOFcalibrateESD(kFALSE),
101 fTOFcorrectTExp(kFALSE),
111 //__________________________________________________________________________________________________
112 AliRsnAnalysisPhi7TeV& AliRsnAnalysisPhi7TeV::operator=(const AliRsnAnalysisPhi7TeV& copy)
115 // Assignment operator
118 fUseMC = copy.fUseMC;
119 fCheckITS = copy.fCheckITS;
120 fCheckTPC = copy.fCheckTPC;
121 fCheckTOF = copy.fCheckTOF;
123 fMaxVz = copy.fMaxVz;
124 fMaxITSband = copy.fMaxITSband;
126 fTPCpLimit = copy.fTPCpLimit;
127 fMinTPCband = copy.fMinTPCband;
128 fMaxTPCband = copy.fMaxTPCband;
130 fESDtrackCutsTPC = copy.fESDtrackCutsTPC;
131 fESDtrackCutsITS = copy.fESDtrackCutsITS;
133 fTOFcalibrateESD = copy.fTOFcalibrateESD;
134 fTOFcorrectTExp = copy.fTOFcorrectTExp;
135 fTOFuseT0 = copy.fTOFuseT0;
136 fTOFtuneMC = copy.fTOFtuneMC;
137 fTOFresolution = copy.fTOFresolution;
142 //__________________________________________________________________________________________________
143 AliRsnAnalysisPhi7TeV::~AliRsnAnalysisPhi7TeV()
149 if (fRsnTreeComp) delete fRsnTreeComp;
150 if (fRsnTreeTrue) delete fRsnTreeTrue;
151 if (fHEvents) delete fHEvents;
152 if (fESDpid) delete fESDpid;
155 //__________________________________________________________________________________________________
156 void AliRsnAnalysisPhi7TeV::UserCreateOutputObjects()
159 // Create the output data container
162 // setup TPC response
163 fESDpid = new AliESDpid;
164 fESDpid->GetTPCResponse().SetBetheBlochParameters(fTPCpar[0],fTPCpar[1],fTPCpar[2],fTPCpar[3],fTPCpar[4]);
166 // setup TOF maker & calibration
167 fTOFcalib = new AliTOFcalib;
168 fTOFmaker = new AliTOFT0maker(fESDpid, fTOFcalib);
169 fTOFmaker->SetTimeResolution(fTOFresolution);
174 // create output trees
176 fRsnTreeComp = new TTree("rsnTree", "Pairs");
178 fRsnTreeComp->Branch("pdg", &fPDG, "pdg/S" );
179 fRsnTreeComp->Branch("ch" , &fCh , "ch/S" );
180 fRsnTreeComp->Branch("im" , &fIM , "im/F" );
181 fRsnTreeComp->Branch("y" , &fY , "y/F" );
182 fRsnTreeComp->Branch("pt" , &fPt , "pt/F" );
183 fRsnTreeComp->Branch("eta", &fEta, "eta/F" );
184 fRsnTreeComp->Branch("its", &fITS, "its[2]/S");
187 fRsnTreeTrue = new TTree("rsnTrue", "True pairs");
189 fRsnTreeTrue->Branch("im" , &fIM , "im/F" );
190 fRsnTreeTrue->Branch("y" , &fY , "y/F" );
191 fRsnTreeTrue->Branch("pt" , &fPt , "pt/F" );
192 fRsnTreeTrue->Branch("eta", &fEta, "eta/F");
195 fOutList = new TList;
196 fHEvents = new TH1I("hEvents", "Event details", 5, 0, 5);
197 fVertexX[0] = new TH1F("hVertexTracksX", "X position of primary vertex (tracks)", 200, -2, 2);
198 fVertexY[0] = new TH1F("hVertexTracksY", "Y position of primary vertex (tracks)", 200, -2, 2);
199 fVertexZ[0] = new TH1F("hVertexTracksZ", "Z position of primary vertex (tracks)", 400, -40, 40);
200 fVertexX[1] = new TH1F("hVertexSPDX", "X position of primary vertex (SPD)", 200, -2, 2);
201 fVertexY[1] = new TH1F("hVertexSPDY", "Y position of primary vertex (SPD)", 200, -2, 2);
202 fVertexZ[1] = new TH1F("hVertexSPDZ", "Z position of primary vertex (SPD)", 400, -40, 40);
204 fHEvents->GetXaxis()->SetBinLabel(1, "Good vertex with tracks");
205 fHEvents->GetXaxis()->SetBinLabel(2, "Good vertex with SPD");
206 fHEvents->GetXaxis()->SetBinLabel(3, "Far vertex with tracks");
207 fHEvents->GetXaxis()->SetBinLabel(4, "Far vertex with SPD");
208 fHEvents->GetXaxis()->SetBinLabel(5, "No good vertex");
210 fOutList->Add(fHEvents);
211 fOutList->Add(fVertexX[0]);
212 fOutList->Add(fVertexY[0]);
213 fOutList->Add(fVertexZ[0]);
214 fOutList->Add(fVertexX[1]);
215 fOutList->Add(fVertexY[1]);
216 fOutList->Add(fVertexZ[1]);
219 //__________________________________________________________________________________________________
220 void AliRsnAnalysisPhi7TeV::UserExec(Option_t *)
223 // Main execution function.
224 // Fills the fHEvents data member with the following legenda:
225 // 0 -- event OK, prim vertex with tracks
226 // 1 -- event OK, prim vertex with SPD
227 // 2 -- event OK but vz large
231 static Int_t evNum = 0;
234 // retrieve ESD event and related stack (if available)
235 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(fInputEvent);
236 AliStack *stack = (fMCEvent ? fMCEvent->Stack() : 0x0);
239 Int_t eval = EventEval(esd);
240 fHEvents->Fill(eval);
242 // if the event is good for analysis, process it
243 if (eval == kGoodTracksPrimaryVertex || eval == kGoodSPDPrimaryVertex)
245 ProcessESD(esd, stack);
249 // update histogram container
250 PostData(3, fOutList);
253 //__________________________________________________________________________________________________
254 void AliRsnAnalysisPhi7TeV::Terminate(Option_t *)
261 //__________________________________________________________________________________________________
262 Int_t AliRsnAnalysisPhi7TeV::EventEval(AliESDEvent *esd)
265 // Checks if the event is good for analysis.
266 // Returns one of the flag values defined in the header
269 static Int_t evNum = 0;
272 // get the best primary vertex:
273 // first try the one with tracks
274 const AliESDVertex *vTrk = esd->GetPrimaryVertexTracks();
275 const AliESDVertex *vSPD = esd->GetPrimaryVertexSPD();
276 Double_t vzTrk = 1000.0;
277 Double_t vzSPD = 1000.0;
280 if (vTrk) ncTrk = (Int_t)vTrk->GetNContributors();
281 if (vSPD) ncSPD = (Int_t)vSPD->GetNContributors();
282 if (vTrk) vzTrk = TMath::Abs(vTrk->GetZv());
283 if (vSPD) vzSPD = TMath::Abs(vSPD->GetZv());
284 if(vTrk && ncTrk > 0)
286 // fill the histograms
287 fVertexX[0]->Fill(vTrk->GetXv());
288 fVertexY[0]->Fill(vTrk->GetYv());
289 fVertexZ[0]->Fill(vTrk->GetZv());
293 return kGoodTracksPrimaryVertex;
295 return kFarTracksPrimaryVertex;
297 else if (vSPD && ncSPD > 0)
299 // fill the histograms
300 fVertexX[1]->Fill(vSPD->GetXv());
301 fVertexY[1]->Fill(vSPD->GetYv());
302 fVertexZ[1]->Fill(vSPD->GetZv());
306 return kGoodSPDPrimaryVertex;
308 return kFarSPDPrimaryVertex;
311 return kNoGoodPrimaryVertex;
314 //__________________________________________________________________________________________________
315 void AliRsnAnalysisPhi7TeV::ProcessESD
316 (AliESDEvent *esd, AliStack *stack)
319 // This function works with the ESD object
322 static Int_t lastRun = -1;
324 // ITS stuff #1 create the response function
325 Bool_t isMC = (stack != 0x0);
326 AliITSPIDResponse itsrsp(isMC);
328 // TOF stuff #1: init OCDB
329 Int_t run = esd->GetRunNumber();
332 cout << "Run = " << run << " -- LAST = " << lastRun << endl;
334 AliCDBManager *cdb = AliCDBManager::Instance();
335 cdb->SetDefaultStorage("raw://");
337 fTOFcalib->SetCorrectTExp(fTOFcorrectTExp);
340 //AliCDBManager *cdb = AliCDBManager::Instance();
341 //cdb->SetDefaultStorage("raw://");
343 // TOF stuff #2: init calibration
344 //fTOFcalib->SetCorrectTExp(fTOFcorrectTExp);
346 // TOF stuff #3: calibrate
347 if (fTOFcalibrateESD) fTOFcalib->CalibrateESD(esd);
348 if (fTOFtuneMC) fTOFmaker->TuneForMC(esd);
351 fTOFmaker->ComputeT0TOF(esd);
352 fTOFmaker->ApplyT0TOF(esd);
353 fESDpid->MakePID(esd, kFALSE, 0.);
355 // TOF stuff #4: define fixed function for compatibility range
356 Double_t a1 = 0.01, a2 = -0.03;
357 Double_t b1 = 0.25, b2 = 0.25;
358 Double_t c1 = 0.05, c2 = -0.03;
361 // prepare to look on all tracks to select the ones
362 // which pass all the cuts
363 Int_t ntracks = esd->GetNumberOfTracks();
364 TArrayI pos(ntracks);
365 TArrayI neg(ntracks);
366 TArrayI itspos(ntracks);
367 TArrayI itsneg(ntracks);
369 // loop on all tracks
371 Int_t i, k, charge, npos = 0, nneg = 0, nITS;
372 Double_t times[10], tpcNSigma, tpcMaxNSigma, itsSignal, itsNSigma, mom, tofTime, tofSigma, tofRef, tofDiff, tofRel;
373 Bool_t okQuality, okTOF, okTPC, okITS, okTrack, isTPC, isITSSA;
375 for (i = 0; i < ntracks; i++)
377 AliESDtrack *track = esd->GetTrack(i);
378 if (!track) continue;
380 // get commonly used variables
381 status = (ULong_t)track->GetStatus();
383 isTPC = ((status & AliESDtrack::kTPCin) != 0);
384 isITSSA = ((status & AliESDtrack::kTPCin) == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
385 //cout << isTPC << ' ' << isITSSA << endl;
387 // accept only tracks which are TPC+ITS or ITS standalone
388 if (!isTPC && !isITSSA) continue;
390 // define selection properties depending on track type
391 // it track is standard TPC+ITS+TOF track, check standard cuts and TOF
392 // if the track is an ITS standalone, check its specific cuts only
397 // check standard ESD cuts
398 okQuality = fESDtrackCutsTPC.IsSelected(track);
399 //cout << "GLOBAL -- quality = " << (okQuality ? "GOOD" : "BAD") << endl;
400 if (!okQuality) continue;
405 tpcNSigma = TMath::Abs(fESDpid->NumberOfSigmasTPC(track, AliPID::kKaon));
406 if (track->GetInnerParam()->P() > fTPCpLimit) tpcMaxNSigma = fMinTPCband; else tpcMaxNSigma = fMaxTPCband;
407 okTPC = (tpcNSigma <= tpcMaxNSigma);
408 //cout << "ALT -- TPC -- nsigma = " << tpcNSigma << ", max = " << tpcMaxNSigma << " --> " << (okTPC ? "OK" : "FAILED") << endl;
409 //cout << "ALTTPC -- " << fTPCpar[0] << ' ' << fTPCpar[1] << ' ' << fTPCpar[2] << ' ' << fTPCpar[3] << ' ' << fTPCpar[4] << endl;
416 // check TOF (only if momentum is large than function asymptote and flags are OK)
419 if (((status & AliESDtrack::kTOFout) != 0) && ((status & AliESDtrack::kTIME) != 0) && mom > TMath::Max(b1, b2))
421 track->GetIntegratedTimes(times);
422 tofTime = (Double_t)track->GetTOFsignal();
423 tofSigma = fTOFmaker->GetExpectedSigma(mom, times[AliPID::kKaon], AliPID::ParticleMass(AliPID::kKaon));
424 tofRef = times[AliPID::kKaon];
427 tofDiff = (tofTime - tofRef);
428 tofRel = (tofTime - tofRef) / tofRef;
429 ymax = a1 / (mom - b1) + c1;
430 ymin = a2 / (mom - b2) + c2;
431 okTOF = (tofRel >= ymin && tofRel <= ymax);
432 //cout << "TOF -- diff = " << tofDiff << ", rel diff = " << tofRel << ", range = " << ymin << " to " << ymax << ", sigma = " << tofSigma << " --> " << (okTOF ? "OK" : "FAILED") << endl;
437 //cout << "TOF -- not checked due to ZERO reference time" << endl;
443 //cout << "TOF -- not checked because TOF pid absent" << endl;
451 okTrack = okQuality && okTPC && okTOF;
452 //cout << "GLOBAL -- overall = " << (okTrack ? "ACCEPTED" : "REJECTED") << endl;
456 // check standard ESD cuts
457 okQuality = fESDtrackCutsITS.IsSelected(track);
458 //cout << "ITSSA -- quality = " << (okQuality ? "GOOD" : "BAD") << endl;
459 if (!okQuality) continue;
464 itsSignal = track->GetITSsignal();
465 itsCluMap = track->GetITSClusterMap();
467 for(k = 2; k < 6; k++) if(itsCluMap & (1 << k)) ++nITS;
471 //cout << "ITS -- not checked due to too few PID clusters" << endl;
475 itsNSigma = itsrsp.GetNumberOfSigmas(mom, itsSignal, AliPID::kKaon, nITS, kTRUE);
476 okITS = (TMath::Abs(itsNSigma) <= fMaxITSband);
477 //cout << "ITS -- nsigma = " << itsNSigma << ", max = " << fMaxITSband << " --> " << (okITS ? "OK" : "FAILED") << endl;
485 okTrack = okQuality && okITS;
486 //cout << "ITSSA -- overall = " << (okTrack ? "ACCEPTED" : "REJECTED") << endl;
489 // skip tracks not passing cuts
490 if (!okTrack) continue;
492 // if all checks are passed, add the track index in one of the
493 // charged tracks arrays
494 charge = (Int_t)track->Charge();
498 if (isITSSA) itspos[npos] = 1; else itspos[npos] = 0;
504 if (isITSSA) itsneg[nneg] = 1; else itsneg[nneg] = 0;
509 // resize arrays accordingly
518 for (i1 = 0; i1 < npos; i1++)
519 for (i2 = 0; i2 < nneg; i2++)
520 AddEntryFromESD(esd, i1, i2, itspos[i1], itsneg[i2], 0, stack);
523 for (i1 = 0; i1 < npos; i1++)
524 for (i2 = i1 + 1; i2 < npos; i2++)
525 AddEntryFromESD(esd, i1, i2, itspos[i1], itspos[i2], 1, 0x0);
528 for (i1 = 0; i1 < nneg; i1++)
529 for (i2 = i1 + 1; i2 < nneg; i2++)
530 AddEntryFromESD(esd, i1, i2, itsneg[i1], itsneg[i2], -1, 0x0);
533 // loop on unlike-sign pairs to compute invariant mass signal
534 Int_t ip, in, lp, ln;
536 Double_t kmass = pid.ParticleMass(AliPID::kKaon);
537 Double_t phimass = 1.019455;
538 TParticle *partp = 0x0, *partn = 0x0;
539 AliESDtrack *tp = 0x0, *tn = 0x0;
540 TLorentzVector vp, vn, vsum, vref;
541 for (ip = 0; ip < npos; ip++)
543 tp = esd->GetTrack(pos[ip]);
544 lp = TMath::Abs(tp->GetLabel());
545 if (stack) partp = stack->Particle(lp);
547 for (in = 0; in < nneg; in++)
549 if (pos[ip] == neg[in])
551 AliError("POS = NEG");
554 tn = esd->GetTrack(neg[in]);
555 ln = TMath::Abs(tn->GetLabel());
556 if (stack) partn = stack->Particle(ln);
561 if (partp->GetFirstMother() == partn->GetFirstMother())
563 if (partp->GetFirstMother() > 0)
565 TParticle *mum = stack->Particle(partp->GetFirstMother());
566 fPDG = mum->GetPdgCode();
570 fPDG = TMath::Abs(fPDG);
572 vp.SetXYZM(tp->Px(), tp->Py(), tp->Pz(), kmass);
573 vn.SetXYZM(tn->Px(), tn->Py(), tn->Pz(), kmass);
575 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
578 fIM = (Float_t)vsum.M();
579 fPt = (Float_t)vsum.Perp();
580 fEta = (Float_t)vsum.Eta();
581 fY = (Float_t)vref.Rapidity();
582 fITS[0] = itspos[ip];
583 fITS[1] = itsneg[in];
585 //if (fIM < 0.9 || fIM > 1.4) continue;
586 //if (fPt < 0.0 || fPt > 20.0) continue;
588 fRsnTreeComp->Fill();
592 // loop on like-sign pairs to compute invariant mass background
594 AliESDtrack *t1 = 0x0, *t2 = 0x0;
595 TLorentzVector v1, v2;
598 for (i1 = 0; i1 < npos; i1++)
600 t1 = esd->GetTrack(pos[i1]);
602 for (i2 = i1+1; i2 < npos; i2++)
604 t2 = esd->GetTrack(pos[i2]);
606 v1.SetXYZM(t1->Px(), t1->Py(), t1->Pz(), kmass);
607 v2.SetXYZM(t2->Px(), t2->Py(), t2->Pz(), kmass);
609 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
613 fIM = (Float_t)vsum.M();
614 fPt = (Float_t)vsum.Perp();
615 fEta = (Float_t)vsum.Eta();
616 fY = (Float_t)vref.Rapidity();
617 fITS[0] = itspos[i1];
618 fITS[1] = itspos[i2];
620 //if (fIM < 0.9 || fIM > 1.4) continue;
621 //if (fPt < 0.0 || fPt > 20.0) continue;
623 fRsnTreeComp->Fill();
627 for (i1 = 0; i1 < nneg; i1++)
629 t1 = esd->GetTrack(neg[i1]);
631 for (i2 = i1+1; i2 < nneg; i2++)
633 t2 = esd->GetTrack(neg[i2]);
635 v1.SetXYZM(t1->Px(), t1->Py(), t1->Pz(), kmass);
636 v2.SetXYZM(t2->Px(), t2->Py(), t2->Pz(), kmass);
638 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
642 fIM = (Float_t)vsum.M();
643 fPt = (Float_t)vsum.Perp();
644 fEta = (Float_t)vsum.Eta();
645 fY = (Float_t)vref.Rapidity();
646 fITS[0] = itsneg[i1];
647 fITS[1] = itsneg[i2];
649 //if (fIM < 0.9 || fIM > 1.4) continue;
650 //if (fPt < 0.0 || fPt > 20.0) continue;
652 fRsnTreeComp->Fill();
656 PostData(1, fRsnTreeComp);
659 //__________________________________________________________________________________________________
660 void AliRsnAnalysisPhi7TeV::AddEntryFromESD(AliESDEvent *esd, Int_t i1, Int_t i2, Int_t its1, Int_t its2, Short_t charge, AliStack *stack)
663 // Add an entry to the output TTree computed from two tracks in the ESD
666 // loop on unlike-sign pairs to compute invariant mass signal
668 Double_t kmass = pid.ParticleMass(AliPID::kKaon);
669 Double_t phimass = 1.019455;
670 TLorentzVector v1, v2, vsum, vref;
672 AliESDtrack *t1 = esd->GetTrack(i1);
673 AliESDtrack *t2 = esd->GetTrack(i2);
675 v1.SetXYZM(t1->Px(), t1->Py(), t1->Pz(), kmass);
676 v2.SetXYZM(t2->Px(), t2->Py(), t2->Pz(), kmass);
678 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
680 // if stack is present, search for true pair
682 Int_t l1 = TMath::Abs(t1->GetLabel());
683 Int_t l2 = TMath::Abs(t2->GetLabel());
686 TParticle *part1 = stack->Particle(l1);
687 TParticle *part2 = stack->Particle(l2);
690 if (part1->GetFirstMother() == part2->GetFirstMother())
692 if (part1->GetFirstMother() > 0)
694 TParticle *mum = stack->Particle(part1->GetFirstMother());
695 fPDG = mum->GetPdgCode();
701 fPDG = TMath::Abs(fPDG);
703 fIM = (Float_t)vsum.M();
704 fPt = (Float_t)vsum.Perp();
705 fEta = (Float_t)vsum.Eta();
706 fY = (Float_t)vref.Rapidity();
710 //if (fIM < 0.9 || fIM > 1.4) return;
711 //if (fPt < 0.0 || fPt > 20.0) return;
713 fRsnTreeComp->Fill();
716 //__________________________________________________________________________________________________
717 void AliRsnAnalysisPhi7TeV::ProcessMC(AliStack *stack)
720 // Function to process stack only
724 Int_t nPart = stack->GetNtrack();
726 // loop to compute invariant mass
729 Double_t kmass = pid.ParticleMass(AliPID::kKaon);
730 Double_t phimass = 1.019455;
731 TParticle *partp = 0x0, *partn = 0x0;
732 TLorentzVector vp, vn, vsum, vref;
734 for (ip = 0; ip < nPart; ip++)
736 partp = stack->Particle(ip);
737 if (partp->GetPdgCode() != 321) continue;
739 for (in = 0; in < nPart; in++)
741 partn = stack->Particle(in);
742 if (partn->GetPdgCode() != -321) continue;
745 if (partp->GetFirstMother() == partn->GetFirstMother())
747 if (partp->GetFirstMother() > 0)
749 TParticle *mum = stack->Particle(partp->GetFirstMother());
750 fPDG = mum->GetPdgCode();
753 fPDG = TMath::Abs(fPDG);
754 if (fPDG != 333) continue;
756 vp.SetXYZM(partp->Px(), partp->Py(), partp->Pz(), kmass);
757 vn.SetXYZM(partn->Px(), partn->Py(), partn->Pz(), kmass);
759 vref.SetXYZM(vsum.X(), vsum.Y(), vsum.Z(), phimass);
761 fIM = (Float_t)vsum.M();
762 fPt = (Float_t)vsum.Perp();
763 fEta = (Float_t)vsum.Eta();
764 fY = (Float_t)vref.Rapidity();
766 fRsnTreeTrue->Fill();
770 PostData(2, fRsnTreeTrue);