3 #include "AlidNdEtaCorrectionTask.h"
12 #include <TParticle.h>
13 #include <TParticlePDG.h>
14 #include <TDatabasePDG.h>
17 #include <AliESDVertex.h>
18 #include <AliESDEvent.h>
20 #include <AliHeader.h>
21 #include <AliGenEventHeader.h>
22 #include <AliMultiplicity.h>
23 #include <AliAnalysisManager.h>
24 #include <AliMCEventHandler.h>
25 #include <AliMCEvent.h>
26 #include <AliESDInputHandler.h>
28 #include "AliESDtrackCuts.h"
29 #include "AliPWG0Helper.h"
30 #include "dNdEta/dNdEtaAnalysis.h"
31 #include "dNdEta/AlidNdEtaCorrection.h"
32 #include "AliTriggerAnalysis.h"
34 ClassImp(AlidNdEtaCorrectionTask)
36 AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask() :
41 fAnalysisMode((AliPWG0Helper::AnalysisMode) (AliPWG0Helper::kTPC | AliPWG0Helper::kFieldOn)),
42 fTrigger(AliTriggerAnalysis::kMB1),
47 fOnlyPrimaries(kFALSE),
52 fdNdEtaAnalysisESD(0),
55 fVertexCorrelation(0),
56 fVertexCorrelationShift(0),
61 fEtaCorrelationShift(0),
64 fDeltaPhiCorrelation(0),
76 // Constructor. Initialization of pointers
79 for (Int_t i=0; i<4; i++)
80 fdNdEtaCorrectionSpecial[i] = 0;
82 for (Int_t i=0; i<8; i++)
86 AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask(const char* opt) :
87 AliAnalysisTask("AlidNdEtaCorrectionTask", ""),
91 fAnalysisMode((AliPWG0Helper::AnalysisMode) (AliPWG0Helper::kTPC | AliPWG0Helper::kFieldOn)),
92 fTrigger(AliTriggerAnalysis::kMB1),
97 fOnlyPrimaries(kFALSE),
100 fdNdEtaCorrection(0),
101 fdNdEtaAnalysisMC(0),
102 fdNdEtaAnalysisESD(0),
105 fVertexCorrelation(0),
106 fVertexCorrelationShift(0),
111 fEtaCorrelationShift(0),
114 fDeltaPhiCorrelation(0),
116 fEsdTrackCutsPrim(0),
126 // Constructor. Initialization of pointers
129 // Define input and output slots here
130 DefineInput(0, TChain::Class());
131 DefineOutput(0, TList::Class());
133 for (Int_t i=0; i<4; i++)
134 fdNdEtaCorrectionSpecial[i] = 0;
136 for (Int_t i=0; i<8; i++)
140 AlidNdEtaCorrectionTask::~AlidNdEtaCorrectionTask()
146 // histograms are in the output list and deleted when the output
147 // list is deleted by the TSelector dtor
155 //________________________________________________________________________
156 void AlidNdEtaCorrectionTask::ConnectInputData(Option_t *)
161 Printf("AlidNdEtaCorrectionTask::ConnectInputData called");
163 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
166 Printf("ERROR: Could not get ESDInputHandler");
168 fESD = esdH->GetEvent();
170 // Enable only the needed branches
171 esdH->SetActiveBranches("AliESDHeader Vertex");
173 if (fAnalysisMode & AliPWG0Helper::kSPD)
174 esdH->SetActiveBranches("AliESDHeader Vertex AliMultiplicity");
176 if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS) {
177 esdH->SetActiveBranches("AliESDHeader Vertex Tracks");
181 // disable info messages of AliMCEvent (per event)
182 AliLog::SetClassDebugLevel("AliMCEvent", AliLog::kWarning - AliLog::kDebug + 1);
185 void AlidNdEtaCorrectionTask::CreateOutputObjects()
187 // create result objects and add to output list
189 if (fOption.Contains("only-positive"))
191 Printf("INFO: Processing only positive particles.");
194 else if (fOption.Contains("only-negative"))
196 Printf("INFO: Processing only negative particles.");
200 if (fOption.Contains("stat-error-1"))
202 Printf("INFO: Evaluation statistical errors. Mode: 1.");
205 else if (fOption.Contains("stat-error-2"))
207 Printf("INFO: Evaluation statistical errors. Mode: 2.");
214 fdNdEtaCorrection = new AlidNdEtaCorrection("dndeta_correction", "dndeta_correction", fAnalysisMode);
215 fOutput->Add(fdNdEtaCorrection);
217 fPIDParticles = new TH1F("fPIDParticles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
218 fOutput->Add(fPIDParticles);
220 fPIDTracks = new TH1F("fPIDTracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
221 fOutput->Add(fPIDTracks);
223 fdNdEtaAnalysisMC = new dNdEtaAnalysis("dndetaMC", "dndetaMC", fAnalysisMode);
224 fOutput->Add(fdNdEtaAnalysisMC);
226 fdNdEtaAnalysisESD = new dNdEtaAnalysis("dndetaESD", "dndetaESD", fAnalysisMode);
227 fOutput->Add(fdNdEtaAnalysisESD);
231 fEsdTrackCutsPrim = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCuts->Clone("fEsdTrackCutsPrim"));
232 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCuts->Clone("fEsdTrackCutsSec"));
233 fOutput->Add(fEsdTrackCutsPrim);
234 fOutput->Add(fEsdTrackCutsSec);
237 if (fOption.Contains("process-types")) {
238 fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_ND", "dndeta_correction_ND", fAnalysisMode);
239 fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_SD", "dndeta_correction_SD", fAnalysisMode);
240 fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_DD", "dndeta_correction_DD", fAnalysisMode);
242 fOutput->Add(fdNdEtaCorrectionSpecial[0]);
243 fOutput->Add(fdNdEtaCorrectionSpecial[1]);
244 fOutput->Add(fdNdEtaCorrectionSpecial[2]);
247 if (fOption.Contains("particle-species")) {
248 fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_pi", "dndeta_correction_pi", fAnalysisMode);
249 fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_K", "dndeta_correction_K", fAnalysisMode);
250 fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_p", "dndeta_correction_p", fAnalysisMode);
251 fdNdEtaCorrectionSpecial[3] = new AlidNdEtaCorrection("dndeta_correction_other", "dndeta_correction_other", fAnalysisMode);
253 for (Int_t i=0; i<4; i++)
254 fOutput->Add(fdNdEtaCorrectionSpecial[i]);
258 fTemp1 = new TH2F("fTemp1", "fTemp1", 200, -20, 20, 200, -0.5, 199.5);
259 fOutput->Add(fTemp1);
261 fTemp2 = new TH1F("fTemp2", "fTemp2", 2000, -5, 5);
262 fOutput->Add(fTemp2);
265 fVertexCorrelation = new TH2F("fVertexCorrelation", "fVertexCorrelation;MC z-vtx;ESD z-vtx", 120, -30, 30, 120, -30, 30);
266 fOutput->Add(fVertexCorrelation);
267 fVertexCorrelationShift = new TH3F("fVertexCorrelationShift", "fVertexCorrelationShift;MC z-vtx;MC z-vtx - ESD z-vtx;rec. tracks", 120, -30, 30, 100, -1, 1, 100, -0.5, 99.5);
268 fOutput->Add(fVertexCorrelationShift);
269 fVertexProfile = new TProfile("fVertexProfile", "fVertexProfile;MC z-vtx;MC z-vtx - ESD z-vtx", 40, -20, 20);
270 fOutput->Add(fVertexProfile);
271 fVertexShift = new TH1F("fVertexShift", "fVertexShift;(MC z-vtx - ESD z-vtx);Entries", 201, -2, 2);
272 fOutput->Add(fVertexShift);
273 fVertexShiftNorm = new TH2F("fVertexShiftNorm", "fVertexShiftNorm;(MC z-vtx - ESD z-vtx) / #sigma_{ESD z-vtx};rec. tracks;Entries", 200, -100, 100, 100, -0.5, 99.5);
274 fOutput->Add(fVertexShiftNorm);
276 fEtaCorrelation = new TH2F("fEtaCorrelation", "fEtaCorrelation;MC #eta;ESD #eta", 120, -3, 3, 120, -3, 3);
277 fOutput->Add(fEtaCorrelation);
278 fEtaCorrelationShift = new TH2F("fEtaCorrelationShift", "fEtaCorrelationShift;MC #eta;MC #eta - ESD #eta", 120, -3, 3, 100, -0.1, 0.1);
279 fOutput->Add(fEtaCorrelationShift);
280 fEtaProfile = new TProfile("fEtaProfile", "fEtaProfile;MC #eta;MC #eta - ESD #eta", 120, -3, 3);
281 fOutput->Add(fEtaProfile);
282 fEtaResolution = new TH1F("fEtaResolution", "fEtaResolution;MC #eta - ESD #eta", 201, -0.2, 0.2);
283 fOutput->Add(fEtaResolution);
285 fpTResolution = new TH2F("fpTResolution", ";MC p_{T} (GeV/c);(MC p_{T} - ESD p_{T}) / MC p_{T}", 160, 0, 20, 201, -0.2, 0.2);
286 fOutput->Add(fpTResolution);
288 fMultAll = new TH1F("fMultAll", "fMultAll", 500, -0.5, 499.5);
289 fOutput->Add(fMultAll);
290 fMultVtx = new TH1F("fMultVtx", "fMultVtx", 500, -0.5, 499.5);
291 fOutput->Add(fMultVtx);
292 fMultTr = new TH1F("fMultTr", "fMultTr", 500, -0.5, 499.5);
293 fOutput->Add(fMultTr);
295 for (Int_t i=0; i<8; i++)
297 fDeltaPhi[i] = new TH2F(Form("fDeltaPhi_%d", i), ";#Delta phi;#phi;Entries", 2000, -0.1, 0.1, 18 * 5, 0, TMath::TwoPi());
298 fOutput->Add(fDeltaPhi[i]);
301 fEventStats = new TH2F("fEventStats", "fEventStats;event type;status;count", 106, -5.5, 100.5, 4, -0.5, 3.5);
302 fOutput->Add(fEventStats);
303 fEventStats->GetXaxis()->SetBinLabel(1, "INEL"); // x = -5
304 fEventStats->GetXaxis()->SetBinLabel(2, "NSD"); // x = -4
305 fEventStats->GetXaxis()->SetBinLabel(3, "ND"); // x = -3
306 fEventStats->GetXaxis()->SetBinLabel(4, "SD"); // x = -2
307 fEventStats->GetXaxis()->SetBinLabel(5, "DD"); // x = -1
309 for (Int_t i=0; i<100; i++)
310 fEventStats->GetXaxis()->SetBinLabel(7+i, Form("%d", i));
312 fEventStats->GetYaxis()->SetBinLabel(1, "nothing");
313 fEventStats->GetYaxis()->SetBinLabel(2, "trg");
314 fEventStats->GetYaxis()->SetBinLabel(3, "vtx");
315 fEventStats->GetYaxis()->SetBinLabel(4, "trgvtx");
319 fEsdTrackCuts->SetName("fEsdTrackCuts");
320 fOutput->Add(fEsdTrackCuts);
324 void AlidNdEtaCorrectionTask::Exec(Option_t*)
328 // Check prerequisites
331 AliDebug(AliLog::kError, "ESD branch not available");
336 Printf("WARNING: Processing only primaries. For systematical studies only!");
339 Printf("WARNING: Statistical error evaluation active!");
341 // trigger definition
342 static AliTriggerAnalysis* triggerAnalysis = new AliTriggerAnalysis;
343 Bool_t eventTriggered = triggerAnalysis->IsTriggerFired(fESD, fTrigger);
344 //Printf("Trigger mask: %lld", fESD->GetTriggerMask());
347 Printf("No trigger");
349 // post the data already here
350 PostData(0, fOutput);
353 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
355 Printf("ERROR: Could not retrieve MC event handler");
359 AliMCEvent* mcEvent = eventHandler->MCEvent();
361 Printf("ERROR: Could not retrieve MC event");
365 AliStack* stack = mcEvent->Stack();
368 AliDebug(AliLog::kError, "Stack not available");
372 AliHeader* header = mcEvent->Header();
375 AliDebug(AliLog::kError, "Header not available");
380 Int_t processType = AliPWG0Helper::GetEventProcessType(header);
381 AliDebug(AliLog::kDebug+1, Form("Found process type %d", processType));
383 if (processType == AliPWG0Helper::kInvalidProcess)
384 AliDebug(AliLog::kError, "Unknown process type.");
387 AliGenEventHeader* genHeader = header->GenEventHeader();
389 genHeader->PrimaryVertex(vtxMC);
391 // get the ESD vertex
392 Bool_t eventVertex = kFALSE;
394 const AliESDVertex* vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
395 if (vtxESD && AliPWG0Helper::TestVertex(vtxESD, fAnalysisMode))
404 Int_t biny = (Int_t) eventTriggered + 2 * (Int_t) eventVertex;
406 fEventStats->Fill(-5, biny);
408 if (processType != AliPWG0Helper::kSD)
409 fEventStats->Fill(-4, biny);
411 if (processType == AliPWG0Helper::kND)
412 fEventStats->Fill(-3, biny);
413 if (processType == AliPWG0Helper::kSD)
414 fEventStats->Fill(-2, biny);
415 if (processType == AliPWG0Helper::kDD)
416 fEventStats->Fill(-1, biny);
418 // create list of (label, eta, pt) tuples
419 Int_t inputCount = 0;
421 Int_t* labelArr2 = 0; // only for case of SPD
423 Float_t* thirdDimArr = 0;
424 Float_t* deltaPhiArr = 0;
425 if (fAnalysisMode & AliPWG0Helper::kSPD)
428 const AliMultiplicity* mult = fESD->GetMultiplicity();
431 AliDebug(AliLog::kError, "AliMultiplicity not available");
435 labelArr = new Int_t[mult->GetNumberOfTracklets()];
436 labelArr2 = new Int_t[mult->GetNumberOfTracklets()];
437 etaArr = new Float_t[mult->GetNumberOfTracklets()];
438 thirdDimArr = new Float_t[mult->GetNumberOfTracklets()];
439 deltaPhiArr = new Float_t[mult->GetNumberOfTracklets()];
441 // get multiplicity from SPD tracklets
442 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
444 //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
446 Float_t phi = mult->GetPhi(i);
448 phi += TMath::Pi() * 2;
449 Float_t deltaPhi = mult->GetDeltaPhi(i);
451 if (TMath::Abs(deltaPhi) > 1)
452 printf("WARNING: Very high Delta Phi: %d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), deltaPhi);
455 if (mult->GetLabel(i, 0) < 0 || mult->GetLabel(i, 0) != mult->GetLabel(i, 1) || !stack->IsPhysicalPrimary(mult->GetLabel(i, 0)))
458 if (fDeltaPhiCut > 0 && TMath::Abs(deltaPhi) > fDeltaPhiCut)
461 etaArr[inputCount] = mult->GetEta(i);
463 etaArr[inputCount] = TMath::Abs(etaArr[inputCount]);
464 labelArr[inputCount] = mult->GetLabel(i, 0);
465 labelArr2[inputCount] = mult->GetLabel(i, 1);
466 thirdDimArr[inputCount] = phi;
467 deltaPhiArr[inputCount] = deltaPhi;
471 else if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS)
475 AliDebug(AliLog::kError, "fESDTrackCuts not available");
481 // get multiplicity from ESD tracks
482 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode & AliPWG0Helper::kTPC));
483 Int_t nGoodTracks = list->GetEntries();
485 Printf("Accepted %d tracks", nGoodTracks);
487 labelArr = new Int_t[nGoodTracks];
488 labelArr2 = new Int_t[nGoodTracks];
489 etaArr = new Float_t[nGoodTracks];
490 thirdDimArr = new Float_t[nGoodTracks];
491 deltaPhiArr = new Float_t[nGoodTracks];
493 // loop over esd tracks
494 for (Int_t i=0; i<nGoodTracks; i++)
496 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
499 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
503 //Printf("status is: %u", esdTrack->GetStatus());
507 Int_t label = TMath::Abs(esdTrack->GetLabel());
511 if (stack->IsPhysicalPrimary(label) == kFALSE)
515 etaArr[inputCount] = esdTrack->Eta();
517 etaArr[inputCount] = TMath::Abs(etaArr[inputCount]);
518 labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
519 labelArr2[inputCount] = labelArr[inputCount]; // no second label for tracks
520 thirdDimArr[inputCount] = esdTrack->Pt();
521 deltaPhiArr[inputCount] = 0; // no delta phi for tracks
529 // collect values for primaries and secondaries
530 for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
532 AliESDtrack* track = 0;
534 if (fAnalysisMode & AliPWG0Helper::kTPC)
535 track = AliESDtrackCuts::GetTPCOnlyTrack(fESD, iTrack);
536 else if (fAnalysisMode & AliPWG0Helper::kTPCITS)
537 track = fESD->GetTrack(iTrack);
542 Int_t label = TMath::Abs(track->GetLabel());
543 if (!stack->Particle(label) || !stack->Particle(label)->GetPDG())
545 Printf("WARNING: No particle for %d", label);
546 if (stack->Particle(label))
547 stack->Particle(label)->Print();
551 if (stack->Particle(label)->GetPDG()->Charge() == 0)
554 if (TMath::Abs(track->Eta()) < 0.8 && track->Pt() > 0.15)
556 if (stack->IsPhysicalPrimary(label))
559 if (fEsdTrackCutsPrim->AcceptTrack(track))
561 // if (AliESDtrackCuts::GetSigmaToVertex(track) > 900)
563 // Printf("Track %d has nsigma of %f. Printing track and vertex...", iTrack, AliESDtrackCuts::GetSigmaToVertex(track));
566 // track->GetImpactParameters(b, r);
567 // Printf("Impact parameter %f %f and resolution: %f %f %f", b[0], b[1], r[0], r[1], r[2]);
577 fEsdTrackCutsSec->AcceptTrack(track);
581 // TODO mem leak in the continue statements above
582 if (fAnalysisMode & AliPWG0Helper::kTPC)
591 // loop over mc particles
592 Int_t nPrim = stack->GetNprimary();
595 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
597 //Printf("Getting particle %d", iMc);
598 TParticle* particle = stack->Particle(iMc);
603 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
605 //if (TMath::Abs(particle->GetPdgCode()) > 3000 && TMath::Abs(particle->Eta()) < 1.0)
606 // fPIDParticles->Fill(particle->GetPdgCode());
610 if (SignOK(particle->GetPDG()) == kFALSE)
613 if (fPIDParticles && TMath::Abs(particle->Eta()) < 1.0)
614 fPIDParticles->Fill(particle->GetPdgCode());
616 Float_t eta = particle->Eta();
618 eta = TMath::Abs(eta);
620 Float_t thirdDim = -1;
621 if (fAnalysisMode & AliPWG0Helper::kSPD)
625 thirdDim = particle->Phi();
628 thirdDim = inputCount;
631 thirdDim = particle->Pt();
634 //Float_t y = 0.5 * TMath::Log((particle->Energy() + particle->Pz()) / (particle->Energy() - particle->Pz()));
638 fdNdEtaCorrection->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
640 if (fOption.Contains("process-types"))
643 if (processType==AliPWG0Helper::kND)
644 fdNdEtaCorrectionSpecial[0]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
646 // single diffractive
647 if (processType==AliPWG0Helper::kSD)
648 fdNdEtaCorrectionSpecial[1]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
650 // double diffractive
651 if (processType==AliPWG0Helper::kDD)
652 fdNdEtaCorrectionSpecial[2]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
655 if (fOption.Contains("particle-species"))
658 switch (TMath::Abs(particle->GetPdgCode()))
660 case 211: id = 0; break;
661 case 321: id = 1; break;
662 case 2212: id = 2; break;
663 default: id = 3; break;
665 fdNdEtaCorrectionSpecial[id]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
670 fdNdEtaAnalysisMC->FillTrack(vtxMC[2], eta, thirdDim);
672 // TODO this value might be needed lower for the SPD study (only used for control histograms anyway)
673 if (TMath::Abs(eta) < 1.5) // && pt > 0.2)
677 fEventStats->Fill(AliPWG0Helper::GetLastProcessType(), biny);
679 fMultAll->Fill(nAccepted);
680 if (eventTriggered) {
681 fMultTr->Fill(nAccepted);
683 fMultVtx->Fill(nAccepted);
688 Bool_t* primCount = 0;
691 primCount = new Bool_t[nPrim];
692 for (Int_t i=0; i<nPrim; ++i)
693 primCount[i] = kFALSE;
697 for (Int_t i=0; i<inputCount; ++i)
699 if (TMath::Abs(etaArr[i]) < 0.5)
702 Int_t label = labelArr[i];
703 Int_t label2 = labelArr2[i];
707 Printf("WARNING: cannot find corresponding mc particle for track(let) %d with label %d.", i, label);
711 TParticle* particle = stack->Particle(label);
714 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
718 fPIDTracks->Fill(particle->GetPdgCode());
720 // find particle that is filled in the correction map
721 // this should be the particle that has been reconstructed
722 // for TPC this is clear and always identified by the track's label
723 // for SPD the labels might not be identical. In this case the particle closest to the beam line that is a primary is taken:
724 // L1 L2 (P = primary, S = secondary)
730 if (label != label2 && label2 >= 0)
732 if (stack->IsPhysicalPrimary(label) == kFALSE && stack->IsPhysicalPrimary(label2))
734 particle = stack->Particle(label2);
737 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label2));
743 if (eventTriggered && eventVertex)
745 if (SignOK(particle->GetPDG()) == kFALSE)
752 fEtaResolution->Fill(TMath::Abs(particle->Eta()) - etaArr[i]);
754 fEtaResolution->Fill(particle->Eta() - etaArr[i]);
756 if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS)
757 if (TMath::Abs(particle->Eta() < 0.9) && particle->Pt() > 0)
758 fpTResolution->Fill(particle->Pt(), (particle->Pt() - thirdDimArr[i]) / particle->Pt());
761 Float_t thirdDim = -1;
763 Bool_t firstIsPrim = stack->IsPhysicalPrimary(label);
764 // in case of same label the MC values are filled, otherwise (background) the reconstructed values
767 eta = particle->Eta();
769 eta = TMath::Abs(eta);
771 if (fAnalysisMode & AliPWG0Helper::kSPD)
775 thirdDim = particle->Phi();
778 thirdDim = inputCount;
781 thirdDim = particle->Pt();
785 if (fAnalysisMode & AliPWG0Helper::kSPD && !fFillPhi)
787 thirdDim = inputCount;
790 thirdDim = thirdDimArr[i];
795 Bool_t fillTrack = kTRUE;
797 // statistical error evaluation active?
800 Bool_t statErrorDecision = kFALSE;
802 // primary and not yet counted
803 if (label == label2 && firstIsPrim && !primCount[label])
805 statErrorDecision = kTRUE;
806 primCount[label] = kTRUE;
809 // in case of 1 we count only unique primaries, in case of 2 all the rest
812 fillTrack = statErrorDecision;
814 else if (fStatError == 2)
815 fillTrack = !statErrorDecision;
819 fdNdEtaCorrection->FillTrackedParticle(vtxMC[2], eta, thirdDim);
821 // eta comparison for tracklets with the same label (others are background)
824 Float_t eta2 = particle->Eta();
826 eta2 = TMath::Abs(eta2);
828 fEtaProfile->Fill(eta2, eta2 - etaArr[i]);
829 fEtaCorrelation->Fill(etaArr[i], eta2);
830 fEtaCorrelationShift->Fill(eta2, eta2 - etaArr[i]);
834 fdNdEtaAnalysisESD->FillTrack(vtxMC[2], TMath::Abs(particle->Eta()), thirdDim);
836 fdNdEtaAnalysisESD->FillTrack(vtxMC[2], particle->Eta(), thirdDim);
838 if (fOption.Contains("process-types"))
841 if (processType == AliPWG0Helper::kND)
842 fdNdEtaCorrectionSpecial[0]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
844 // single diffractive
845 if (processType == AliPWG0Helper::kSD)
846 fdNdEtaCorrectionSpecial[1]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
848 // double diffractive
849 if (processType == AliPWG0Helper::kDD)
850 fdNdEtaCorrectionSpecial[2]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
853 if (fOption.Contains("particle-species"))
856 TParticle* mother = AliPWG0Helper::FindPrimaryMother(stack, label);
859 switch (TMath::Abs(mother->GetPdgCode()))
861 case 211: id = 0; break;
862 case 321: id = 1; break;
863 case 2212: id = 2; break;
864 default: id = 3; break;
866 fdNdEtaCorrectionSpecial[id]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
869 // control histograms
880 else if (label2 >= 0)
882 Bool_t secondIsPrim = stack->IsPhysicalPrimary(label2);
883 if (firstIsPrim && secondIsPrim)
887 else if (firstIsPrim && !secondIsPrim)
891 // check if secondary is caused by the primary or it is a fake combination
892 //Printf("PS case --> Label 1 is %d, label 2 is %d", label, label2);
893 Int_t mother = label2;
894 while (stack->Particle(mother) && stack->Particle(mother)->GetMother(0) >= 0)
896 //Printf(" %d created by %d, %d", mother, stack->Particle(mother)->GetMother(0), stack->Particle(mother)->GetMother(1));
897 if (stack->Particle(mother)->GetMother(0) == label)
899 /*Printf("The untraceable decay was:");
902 Printf(" to (status code %d):", stack->Particle(mother)->GetStatusCode());
903 stack->Particle(mother)->Print();*/
906 mother = stack->Particle(mother)->GetMother(0);
909 else if (!firstIsPrim && secondIsPrim)
913 else if (!firstIsPrim && !secondIsPrim)
922 fDeltaPhi[hist]->Fill(deltaPhiArr[i], thirdDimArr[i]);
932 if (processed < inputCount)
933 Printf("Only %d out of %d track(let)s were used", processed, inputCount);
935 if (eventTriggered && eventVertex)
937 Double_t diff = vtxMC[2] - vtx[2];
938 fVertexShift->Fill(diff);
939 if (vtxESD->GetZRes() > 0)
940 fVertexShiftNorm->Fill(diff / vtxESD->GetZRes(), inputCount);
942 fVertexCorrelation->Fill(vtxMC[2], vtx[2]);
943 fVertexCorrelationShift->Fill(vtxMC[2], vtxMC[2] - vtx[2], inputCount);
944 fVertexProfile->Fill(vtxMC[2], vtxMC[2] - vtx[2]);
946 fTemp1->Fill(vtxMC[2], nEta05);
949 if (eventTriggered && eventVertex)
951 fdNdEtaAnalysisMC->FillEvent(vtxMC[2], inputCount);
952 fdNdEtaAnalysisESD->FillEvent(vtxMC[2], inputCount);
955 // stuff regarding the vertex reco correction and trigger bias correction
956 fdNdEtaCorrection->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
958 if (fOption.Contains("process-types"))
961 if (processType == AliPWG0Helper::kND)
962 fdNdEtaCorrectionSpecial[0]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
964 // single diffractive
965 if (processType == AliPWG0Helper::kSD)
966 fdNdEtaCorrectionSpecial[1]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
968 // double diffractive
969 if (processType == AliPWG0Helper::kDD)
970 fdNdEtaCorrectionSpecial[2]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
973 if (fOption.Contains("particle-species"))
974 for (Int_t id=0; id<4; id++)
975 fdNdEtaCorrectionSpecial[id]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
984 delete[] thirdDimArr;
986 delete[] deltaPhiArr;
989 void AlidNdEtaCorrectionTask::Terminate(Option_t *)
991 // The Terminate() function is the last function to be called during
992 // a query. It always runs on the client, it can be used to present
993 // the results graphically or save the results to file.
995 fOutput = dynamic_cast<TList*> (GetOutputData(0));
997 Printf("ERROR: fOutput not available");
1001 fdNdEtaCorrection = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction"));
1002 fdNdEtaAnalysisMC = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaMC"));
1003 fdNdEtaAnalysisESD = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaESD"));
1004 if (!fdNdEtaCorrection || !fdNdEtaAnalysisMC || !fdNdEtaAnalysisESD)
1006 AliDebug(AliLog::kError, "Could not read object from output list");
1010 fdNdEtaCorrection->Finish();
1013 fileName.Form("correction_map%s.root", fOption.Data());
1014 TFile* fout = new TFile(fileName, "RECREATE");
1016 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCuts"));
1018 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
1020 fEsdTrackCutsPrim = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPrim"));
1021 if (fEsdTrackCutsPrim)
1022 fEsdTrackCutsPrim->SaveHistograms("esd_track_cuts_primaries");
1024 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsSec"));
1025 if (fEsdTrackCutsSec)
1026 fEsdTrackCutsSec->SaveHistograms("esd_track_cuts_secondaries");
1028 fdNdEtaCorrection->SaveHistograms();
1029 fdNdEtaAnalysisMC->SaveHistograms();
1030 fdNdEtaAnalysisESD->SaveHistograms();
1032 if (fOutput->FindObject("dndeta_correction_ND"))
1034 fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_ND"));
1035 fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_SD"));
1036 fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_DD"));
1040 fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_pi"));
1041 fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_K"));
1042 fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_p"));
1043 fdNdEtaCorrectionSpecial[3] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_other"));
1045 for (Int_t i=0; i<4; ++i)
1046 if (fdNdEtaCorrectionSpecial[i])
1047 fdNdEtaCorrectionSpecial[i]->SaveHistograms();
1049 fTemp1 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp1"));
1052 fTemp2 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp2"));
1056 fVertexCorrelation = dynamic_cast<TH2F*> (fOutput->FindObject("fVertexCorrelation"));
1057 if (fVertexCorrelation)
1058 fVertexCorrelation->Write();
1059 fVertexCorrelationShift = dynamic_cast<TH3F*> (fOutput->FindObject("fVertexCorrelationShift"));
1060 if (fVertexCorrelationShift)
1062 ((TH2*) fVertexCorrelationShift->Project3D("yx"))->FitSlicesY();
1063 fVertexCorrelationShift->Write();
1065 fVertexProfile = dynamic_cast<TProfile*> (fOutput->FindObject("fVertexProfile"));
1067 fVertexProfile->Write();
1068 fVertexShift = dynamic_cast<TH1F*> (fOutput->FindObject("fVertexShift"));
1070 fVertexShift->Write();
1071 fVertexShiftNorm = dynamic_cast<TH2F*> (fOutput->FindObject("fVertexShiftNorm"));
1072 if (fVertexShiftNorm)
1074 fVertexShiftNorm->ProjectionX();
1075 fVertexShiftNorm->Write();
1078 fEtaCorrelation = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaCorrelation"));
1079 if (fEtaCorrelation)
1080 fEtaCorrelation->Write();
1081 fEtaCorrelationShift = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaCorrelationShift"));
1082 if (fEtaCorrelationShift)
1084 fEtaCorrelationShift->FitSlicesY();
1085 fEtaCorrelationShift->Write();
1087 fEtaProfile = dynamic_cast<TProfile*> (fOutput->FindObject("fEtaProfile"));
1089 fEtaProfile->Write();
1090 fEtaResolution = dynamic_cast<TH1F*> (fOutput->FindObject("fEtaResolution"));
1092 fEtaResolution->Write();
1093 fpTResolution = dynamic_cast<TH2F*> (fOutput->FindObject("fpTResolution"));
1096 fpTResolution->FitSlicesY();
1097 fpTResolution->Write();
1100 fMultAll = dynamic_cast<TH1F*> (fOutput->FindObject("fMultAll"));
1104 fMultTr = dynamic_cast<TH1F*> (fOutput->FindObject("fMultTr"));
1108 fMultVtx = dynamic_cast<TH1F*> (fOutput->FindObject("fMultVtx"));
1112 for (Int_t i=0; i<8; ++i)
1114 fDeltaPhi[i] = dynamic_cast<TH2*> (fOutput->FindObject(Form("fDeltaPhi_%d", i)));
1116 fDeltaPhi[i]->Write();
1119 fEventStats = dynamic_cast<TH2F*> (fOutput->FindObject("fEventStats"));
1121 fEventStats->Write();
1123 fPIDParticles = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDParticles"));
1125 fPIDParticles->Write();
1127 fPIDTracks = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDTracks"));
1129 fPIDTracks->Write();
1131 //fdNdEtaCorrection->DrawHistograms();
1133 Printf("Writting result to %s", fileName.Data());
1135 if (fPIDParticles && fPIDTracks)
1137 TDatabasePDG* pdgDB = new TDatabasePDG;
1139 for (Int_t i=0; i <= fPIDParticles->GetNbinsX()+1; ++i)
1140 if (fPIDParticles->GetBinContent(i) > 0)
1142 TObject* pdgParticle = pdgDB->GetParticle((Int_t) fPIDParticles->GetBinCenter(i));
1143 printf("PDG = %d (%s): generated: %d, reconstructed: %d, ratio: %f\n", (Int_t) fPIDParticles->GetBinCenter(i), (pdgParticle) ? pdgParticle->GetName() : "not found", (Int_t) fPIDParticles->GetBinContent(i), (Int_t) fPIDTracks->GetBinContent(i), ((fPIDTracks->GetBinContent(i) > 0) ? fPIDParticles->GetBinContent(i) / fPIDTracks->GetBinContent(i) : -1));
1154 Bool_t AlidNdEtaCorrectionTask::SignOK(TParticlePDG* particle)
1156 // returns if a particle with this sign should be counted
1157 // this is determined by the value of fSignMode, which should have the same sign
1159 // if fSignMode is 0 all particles are counted
1166 printf("WARNING: not counting a particle that does not have a pdg particle\n");
1170 Double_t charge = particle->Charge();