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),
46 fOnlyPrimaries(kFALSE),
51 fdNdEtaAnalysisESD(0),
54 fVertexCorrelation(0),
55 fVertexCorrelationShift(0),
60 fEtaCorrelationShift(0),
63 fDeltaPhiCorrelation(0),
75 // Constructor. Initialization of pointers
78 for (Int_t i=0; i<4; i++)
79 fdNdEtaCorrectionSpecial[i] = 0;
81 for (Int_t i=0; i<8; i++)
85 AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask(const char* opt) :
86 AliAnalysisTask("AlidNdEtaCorrectionTask", ""),
90 fAnalysisMode((AliPWG0Helper::AnalysisMode) (AliPWG0Helper::kTPC | AliPWG0Helper::kFieldOn)),
91 fTrigger(AliTriggerAnalysis::kMB1),
95 fOnlyPrimaries(kFALSE),
100 fdNdEtaAnalysisESD(0),
103 fVertexCorrelation(0),
104 fVertexCorrelationShift(0),
109 fEtaCorrelationShift(0),
112 fDeltaPhiCorrelation(0),
114 fEsdTrackCutsPrim(0),
124 // Constructor. Initialization of pointers
127 // Define input and output slots here
128 DefineInput(0, TChain::Class());
129 DefineOutput(0, TList::Class());
131 for (Int_t i=0; i<4; i++)
132 fdNdEtaCorrectionSpecial[i] = 0;
134 for (Int_t i=0; i<8; i++)
138 AlidNdEtaCorrectionTask::~AlidNdEtaCorrectionTask()
144 // histograms are in the output list and deleted when the output
145 // list is deleted by the TSelector dtor
153 //________________________________________________________________________
154 void AlidNdEtaCorrectionTask::ConnectInputData(Option_t *)
159 Printf("AlidNdEtaCorrectionTask::ConnectInputData called");
161 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
164 Printf("ERROR: Could not get ESDInputHandler");
166 fESD = esdH->GetEvent();
168 // Enable only the needed branches
169 esdH->SetActiveBranches("AliESDHeader Vertex");
171 if (fAnalysisMode & AliPWG0Helper::kSPD)
172 esdH->SetActiveBranches("AliESDHeader Vertex AliMultiplicity");
174 if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS) {
175 esdH->SetActiveBranches("AliESDHeader Vertex Tracks");
179 // disable info messages of AliMCEvent (per event)
180 AliLog::SetClassDebugLevel("AliMCEvent", AliLog::kWarning - AliLog::kDebug + 1);
183 void AlidNdEtaCorrectionTask::CreateOutputObjects()
185 // create result objects and add to output list
187 if (fOption.Contains("only-positive"))
189 Printf("INFO: Processing only positive particles.");
192 else if (fOption.Contains("only-negative"))
194 Printf("INFO: Processing only negative particles.");
198 if (fOption.Contains("stat-error-1"))
200 Printf("INFO: Evaluation statistical errors. Mode: 1.");
203 else if (fOption.Contains("stat-error-2"))
205 Printf("INFO: Evaluation statistical errors. Mode: 2.");
212 fdNdEtaCorrection = new AlidNdEtaCorrection("dndeta_correction", "dndeta_correction", fAnalysisMode);
213 fOutput->Add(fdNdEtaCorrection);
215 fPIDParticles = new TH1F("fPIDParticles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
216 fOutput->Add(fPIDParticles);
218 fPIDTracks = new TH1F("fPIDTracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
219 fOutput->Add(fPIDTracks);
221 fdNdEtaAnalysisMC = new dNdEtaAnalysis("dndetaMC", "dndetaMC", fAnalysisMode);
222 fOutput->Add(fdNdEtaAnalysisMC);
224 fdNdEtaAnalysisESD = new dNdEtaAnalysis("dndetaESD", "dndetaESD", fAnalysisMode);
225 fOutput->Add(fdNdEtaAnalysisESD);
229 fEsdTrackCutsPrim = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCuts->Clone("fEsdTrackCutsPrim"));
230 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCuts->Clone("fEsdTrackCutsSec"));
231 fOutput->Add(fEsdTrackCutsPrim);
232 fOutput->Add(fEsdTrackCutsSec);
235 if (fOption.Contains("process-types")) {
236 fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_ND", "dndeta_correction_ND", fAnalysisMode);
237 fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_SD", "dndeta_correction_SD", fAnalysisMode);
238 fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_DD", "dndeta_correction_DD", fAnalysisMode);
240 fOutput->Add(fdNdEtaCorrectionSpecial[0]);
241 fOutput->Add(fdNdEtaCorrectionSpecial[1]);
242 fOutput->Add(fdNdEtaCorrectionSpecial[2]);
245 if (fOption.Contains("particle-species")) {
246 fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_pi", "dndeta_correction_pi", fAnalysisMode);
247 fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_K", "dndeta_correction_K", fAnalysisMode);
248 fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_p", "dndeta_correction_p", fAnalysisMode);
249 fdNdEtaCorrectionSpecial[3] = new AlidNdEtaCorrection("dndeta_correction_other", "dndeta_correction_other", fAnalysisMode);
251 for (Int_t i=0; i<4; i++)
252 fOutput->Add(fdNdEtaCorrectionSpecial[i]);
256 fTemp1 = new TH2F("fTemp1", "fTemp1", 200, -20, 20, 200, -0.5, 199.5);
257 fOutput->Add(fTemp1);
259 fTemp2 = new TH1F("fTemp2", "fTemp2", 2000, -5, 5);
260 fOutput->Add(fTemp2);
263 fVertexCorrelation = new TH2F("fVertexCorrelation", "fVertexCorrelation;MC z-vtx;ESD z-vtx", 120, -30, 30, 120, -30, 30);
264 fOutput->Add(fVertexCorrelation);
265 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);
266 fOutput->Add(fVertexCorrelationShift);
267 fVertexProfile = new TProfile("fVertexProfile", "fVertexProfile;MC z-vtx;MC z-vtx - ESD z-vtx", 40, -20, 20);
268 fOutput->Add(fVertexProfile);
269 fVertexShift = new TH1F("fVertexShift", "fVertexShift;(MC z-vtx - ESD z-vtx);Entries", 201, -2, 2);
270 fOutput->Add(fVertexShift);
271 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);
272 fOutput->Add(fVertexShiftNorm);
274 fEtaCorrelation = new TH2F("fEtaCorrelation", "fEtaCorrelation;MC #eta;ESD #eta", 120, -3, 3, 120, -3, 3);
275 fOutput->Add(fEtaCorrelation);
276 fEtaCorrelationShift = new TH2F("fEtaCorrelationShift", "fEtaCorrelationShift;MC #eta;MC #eta - ESD #eta", 120, -3, 3, 100, -0.1, 0.1);
277 fOutput->Add(fEtaCorrelationShift);
278 fEtaProfile = new TProfile("fEtaProfile", "fEtaProfile;MC #eta;MC #eta - ESD #eta", 120, -3, 3);
279 fOutput->Add(fEtaProfile);
280 fEtaResolution = new TH1F("fEtaResolution", "fEtaResolution;MC #eta - ESD #eta", 201, -0.2, 0.2);
281 fOutput->Add(fEtaResolution);
283 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);
284 fOutput->Add(fpTResolution);
286 fMultAll = new TH1F("fMultAll", "fMultAll", 500, -0.5, 499.5);
287 fOutput->Add(fMultAll);
288 fMultVtx = new TH1F("fMultVtx", "fMultVtx", 500, -0.5, 499.5);
289 fOutput->Add(fMultVtx);
290 fMultTr = new TH1F("fMultTr", "fMultTr", 500, -0.5, 499.5);
291 fOutput->Add(fMultTr);
293 for (Int_t i=0; i<8; i++)
295 fDeltaPhi[i] = new TH2F(Form("fDeltaPhi_%d", i), ";#Delta phi;#phi;Entries", 2000, -0.1, 0.1, 18 * 5, 0, TMath::TwoPi());
296 fOutput->Add(fDeltaPhi[i]);
299 fEventStats = new TH2F("fEventStats", "fEventStats;event type;status;count", 106, -5.5, 100.5, 4, -0.5, 3.5);
300 fOutput->Add(fEventStats);
301 fEventStats->GetXaxis()->SetBinLabel(1, "INEL"); // x = -5
302 fEventStats->GetXaxis()->SetBinLabel(2, "NSD"); // x = -4
303 fEventStats->GetXaxis()->SetBinLabel(3, "ND"); // x = -3
304 fEventStats->GetXaxis()->SetBinLabel(4, "SD"); // x = -2
305 fEventStats->GetXaxis()->SetBinLabel(5, "DD"); // x = -1
307 for (Int_t i=0; i<100; i++)
308 fEventStats->GetXaxis()->SetBinLabel(7+i, Form("%d", i));
310 fEventStats->GetYaxis()->SetBinLabel(1, "nothing");
311 fEventStats->GetYaxis()->SetBinLabel(2, "trg");
312 fEventStats->GetYaxis()->SetBinLabel(3, "vtx");
313 fEventStats->GetYaxis()->SetBinLabel(4, "trgvtx");
317 fEsdTrackCuts->SetName("fEsdTrackCuts");
318 fOutput->Add(fEsdTrackCuts);
322 void AlidNdEtaCorrectionTask::Exec(Option_t*)
326 // Check prerequisites
329 AliDebug(AliLog::kError, "ESD branch not available");
334 Printf("WARNING: Processing only primaries. For systematical studies only!");
337 Printf("WARNING: Statistical error evaluation active!");
339 // trigger definition
340 static AliTriggerAnalysis* triggerAnalysis = new AliTriggerAnalysis;
341 Bool_t eventTriggered = triggerAnalysis->IsTriggerFired(fESD, fTrigger);
342 //Printf("Trigger mask: %lld", fESD->GetTriggerMask());
345 Printf("No trigger");
347 // post the data already here
348 PostData(0, fOutput);
351 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
353 Printf("ERROR: Could not retrieve MC event handler");
357 AliMCEvent* mcEvent = eventHandler->MCEvent();
359 Printf("ERROR: Could not retrieve MC event");
363 AliStack* stack = mcEvent->Stack();
366 AliDebug(AliLog::kError, "Stack not available");
370 AliHeader* header = mcEvent->Header();
373 AliDebug(AliLog::kError, "Header not available");
378 Int_t processType = AliPWG0Helper::GetEventProcessType(header);
379 AliDebug(AliLog::kDebug+1, Form("Found process type %d", processType));
381 if (processType == AliPWG0Helper::kInvalidProcess)
382 AliDebug(AliLog::kError, "Unknown process type.");
385 AliGenEventHeader* genHeader = header->GenEventHeader();
387 genHeader->PrimaryVertex(vtxMC);
389 // get the ESD vertex
390 Bool_t eventVertex = kFALSE;
392 const AliESDVertex* vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
393 if (vtxESD && AliPWG0Helper::TestVertex(vtxESD, fAnalysisMode))
402 Int_t biny = (Int_t) eventTriggered + 2 * (Int_t) eventVertex;
404 fEventStats->Fill(-5, biny);
406 if (processType != AliPWG0Helper::kSD)
407 fEventStats->Fill(-4, biny);
409 if (processType == AliPWG0Helper::kND)
410 fEventStats->Fill(-3, biny);
411 if (processType == AliPWG0Helper::kSD)
412 fEventStats->Fill(-2, biny);
413 if (processType == AliPWG0Helper::kDD)
414 fEventStats->Fill(-1, biny);
416 // create list of (label, eta, pt) tuples
417 Int_t inputCount = 0;
419 Int_t* labelArr2 = 0; // only for case of SPD
421 Float_t* thirdDimArr = 0;
422 Float_t* deltaPhiArr = 0;
423 if (fAnalysisMode & AliPWG0Helper::kSPD)
426 const AliMultiplicity* mult = fESD->GetMultiplicity();
429 AliDebug(AliLog::kError, "AliMultiplicity not available");
433 labelArr = new Int_t[mult->GetNumberOfTracklets()];
434 labelArr2 = new Int_t[mult->GetNumberOfTracklets()];
435 etaArr = new Float_t[mult->GetNumberOfTracklets()];
436 thirdDimArr = new Float_t[mult->GetNumberOfTracklets()];
437 deltaPhiArr = new Float_t[mult->GetNumberOfTracklets()];
439 // get multiplicity from SPD tracklets
440 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
442 //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
444 Float_t phi = mult->GetPhi(i);
446 phi += TMath::Pi() * 2;
447 Float_t deltaPhi = mult->GetDeltaPhi(i);
449 if (TMath::Abs(deltaPhi) > 1)
450 printf("WARNING: Very high Delta Phi: %d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), deltaPhi);
453 if (mult->GetLabel(i, 0) < 0 || mult->GetLabel(i, 0) != mult->GetLabel(i, 1) || !stack->IsPhysicalPrimary(mult->GetLabel(i, 0)))
456 if (fDeltaPhiCut > 0 && TMath::Abs(deltaPhi) > fDeltaPhiCut)
459 etaArr[inputCount] = mult->GetEta(i);
460 labelArr[inputCount] = mult->GetLabel(i, 0);
461 labelArr2[inputCount] = mult->GetLabel(i, 1);
462 thirdDimArr[inputCount] = phi;
463 deltaPhiArr[inputCount] = deltaPhi;
467 else if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS)
471 AliDebug(AliLog::kError, "fESDTrackCuts not available");
477 // get multiplicity from ESD tracks
478 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode & AliPWG0Helper::kTPC));
479 Int_t nGoodTracks = list->GetEntries();
481 Printf("Accepted %d tracks", nGoodTracks);
483 labelArr = new Int_t[nGoodTracks];
484 labelArr2 = new Int_t[nGoodTracks];
485 etaArr = new Float_t[nGoodTracks];
486 thirdDimArr = new Float_t[nGoodTracks];
487 deltaPhiArr = new Float_t[nGoodTracks];
489 // loop over esd tracks
490 for (Int_t i=0; i<nGoodTracks; i++)
492 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
495 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
499 //Printf("status is: %u", esdTrack->GetStatus());
503 Int_t label = TMath::Abs(esdTrack->GetLabel());
507 if (stack->IsPhysicalPrimary(label) == kFALSE)
511 etaArr[inputCount] = esdTrack->Eta();
512 labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
513 labelArr2[inputCount] = labelArr[inputCount]; // no second label for tracks
514 thirdDimArr[inputCount] = esdTrack->Pt();
515 deltaPhiArr[inputCount] = 0; // no delta phi for tracks
523 // collect values for primaries and secondaries
524 for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
526 AliESDtrack* track = 0;
528 if (fAnalysisMode & AliPWG0Helper::kTPC)
529 track = AliESDtrackCuts::GetTPCOnlyTrack(fESD, iTrack);
530 else if (fAnalysisMode & AliPWG0Helper::kTPCITS)
531 track = fESD->GetTrack(iTrack);
536 Int_t label = TMath::Abs(track->GetLabel());
537 if (!stack->Particle(label) || !stack->Particle(label)->GetPDG())
539 Printf("WARNING: No particle for %d", label);
540 if (stack->Particle(label))
541 stack->Particle(label)->Print();
545 if (stack->Particle(label)->GetPDG()->Charge() == 0)
548 if (TMath::Abs(track->Eta()) < 0.8 && track->Pt() > 0.15)
550 if (stack->IsPhysicalPrimary(label))
553 if (fEsdTrackCutsPrim->AcceptTrack(track))
555 // if (AliESDtrackCuts::GetSigmaToVertex(track) > 900)
557 // Printf("Track %d has nsigma of %f. Printing track and vertex...", iTrack, AliESDtrackCuts::GetSigmaToVertex(track));
560 // track->GetImpactParameters(b, r);
561 // Printf("Impact parameter %f %f and resolution: %f %f %f", b[0], b[1], r[0], r[1], r[2]);
571 fEsdTrackCutsSec->AcceptTrack(track);
575 // TODO mem leak in the continue statements above
576 if (fAnalysisMode & AliPWG0Helper::kTPC)
585 // loop over mc particles
586 Int_t nPrim = stack->GetNprimary();
589 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
591 //Printf("Getting particle %d", iMc);
592 TParticle* particle = stack->Particle(iMc);
597 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
599 //if (TMath::Abs(particle->GetPdgCode()) > 3000 && TMath::Abs(particle->Eta()) < 1.0)
600 // fPIDParticles->Fill(particle->GetPdgCode());
604 if (SignOK(particle->GetPDG()) == kFALSE)
607 if (fPIDParticles && TMath::Abs(particle->Eta()) < 1.0)
608 fPIDParticles->Fill(particle->GetPdgCode());
610 Float_t eta = particle->Eta();
612 Float_t thirdDim = -1;
613 if (fAnalysisMode & AliPWG0Helper::kSPD)
617 thirdDim = particle->Phi();
620 thirdDim = inputCount;
623 thirdDim = particle->Pt();
626 //Float_t y = 0.5 * TMath::Log((particle->Energy() + particle->Pz()) / (particle->Energy() - particle->Pz()));
630 fdNdEtaCorrection->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
632 if (fOption.Contains("process-types"))
635 if (processType==AliPWG0Helper::kND)
636 fdNdEtaCorrectionSpecial[0]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
638 // single diffractive
639 if (processType==AliPWG0Helper::kSD)
640 fdNdEtaCorrectionSpecial[1]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
642 // double diffractive
643 if (processType==AliPWG0Helper::kDD)
644 fdNdEtaCorrectionSpecial[2]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
647 if (fOption.Contains("particle-species"))
650 switch (TMath::Abs(particle->GetPdgCode()))
652 case 211: id = 0; break;
653 case 321: id = 1; break;
654 case 2212: id = 2; break;
655 default: id = 3; break;
657 fdNdEtaCorrectionSpecial[id]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
662 fdNdEtaAnalysisMC->FillTrack(vtxMC[2], eta, thirdDim);
664 // TODO this value might be needed lower for the SPD study (only used for control histograms anyway)
665 if (TMath::Abs(eta) < 1.5) // && pt > 0.2)
669 fEventStats->Fill(AliPWG0Helper::GetLastProcessType(), biny);
671 fMultAll->Fill(nAccepted);
672 if (eventTriggered) {
673 fMultTr->Fill(nAccepted);
675 fMultVtx->Fill(nAccepted);
680 Bool_t* primCount = 0;
683 primCount = new Bool_t[nPrim];
684 for (Int_t i=0; i<nPrim; ++i)
685 primCount[i] = kFALSE;
689 for (Int_t i=0; i<inputCount; ++i)
691 if (TMath::Abs(etaArr[i]) < 0.5)
694 Int_t label = labelArr[i];
695 Int_t label2 = labelArr2[i];
699 Printf("WARNING: cannot find corresponding mc particle for track(let) %d with label %d.", i, label);
703 TParticle* particle = stack->Particle(label);
706 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
710 fPIDTracks->Fill(particle->GetPdgCode());
712 // find particle that is filled in the correction map
713 // this should be the particle that has been reconstructed
714 // for TPC this is clear and always identified by the track's label
715 // for SPD the labels might not be identical. In this case the particle closest to the beam line that is a primary is taken:
716 // L1 L2 (P = primary, S = secondary)
722 if (label != label2 && label2 >= 0)
724 if (stack->IsPhysicalPrimary(label) == kFALSE && stack->IsPhysicalPrimary(label2))
726 particle = stack->Particle(label2);
729 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label2));
735 if (eventTriggered && eventVertex)
737 if (SignOK(particle->GetPDG()) == kFALSE)
743 fEtaResolution->Fill(particle->Eta() - etaArr[i]);
745 if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS)
746 if (TMath::Abs(particle->Eta() < 0.9) && particle->Pt() > 0)
747 fpTResolution->Fill(particle->Pt(), (particle->Pt() - thirdDimArr[i]) / particle->Pt());
750 Float_t thirdDim = -1;
752 Bool_t firstIsPrim = stack->IsPhysicalPrimary(label);
753 // in case of same label the MC values are filled, otherwise (background) the reconstructed values
756 eta = particle->Eta();
758 if (fAnalysisMode & AliPWG0Helper::kSPD)
762 thirdDim = particle->Phi();
765 thirdDim = inputCount;
768 thirdDim = particle->Pt();
772 if (fAnalysisMode & AliPWG0Helper::kSPD && !fFillPhi)
774 thirdDim = inputCount;
777 thirdDim = thirdDimArr[i];
782 Bool_t fillTrack = kTRUE;
784 // statistical error evaluation active?
787 Bool_t statErrorDecision = kFALSE;
789 // primary and not yet counted
790 if (label == label2 && firstIsPrim && !primCount[label])
792 statErrorDecision = kTRUE;
793 primCount[label] = kTRUE;
796 // in case of 1 we count only unique primaries, in case of 2 all the rest
799 fillTrack = statErrorDecision;
801 else if (fStatError == 2)
802 fillTrack = !statErrorDecision;
806 fdNdEtaCorrection->FillTrackedParticle(vtxMC[2], eta, thirdDim);
808 // eta comparison for tracklets with the same label (others are background)
811 fEtaProfile->Fill(particle->Eta(), particle->Eta() - etaArr[i]);
812 fEtaCorrelation->Fill(etaArr[i], particle->Eta());
813 fEtaCorrelationShift->Fill(particle->Eta(), particle->Eta() - etaArr[i]);
816 fdNdEtaAnalysisESD->FillTrack(vtxMC[2], particle->Eta(), thirdDim);
818 if (fOption.Contains("process-types"))
821 if (processType == AliPWG0Helper::kND)
822 fdNdEtaCorrectionSpecial[0]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
824 // single diffractive
825 if (processType == AliPWG0Helper::kSD)
826 fdNdEtaCorrectionSpecial[1]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
828 // double diffractive
829 if (processType == AliPWG0Helper::kDD)
830 fdNdEtaCorrectionSpecial[2]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
833 if (fOption.Contains("particle-species"))
836 TParticle* mother = AliPWG0Helper::FindPrimaryMother(stack, label);
839 switch (TMath::Abs(mother->GetPdgCode()))
841 case 211: id = 0; break;
842 case 321: id = 1; break;
843 case 2212: id = 2; break;
844 default: id = 3; break;
846 fdNdEtaCorrectionSpecial[id]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
849 // control histograms
860 else if (label2 >= 0)
862 Bool_t secondIsPrim = stack->IsPhysicalPrimary(label2);
863 if (firstIsPrim && secondIsPrim)
867 else if (firstIsPrim && !secondIsPrim)
871 // check if secondary is caused by the primary or it is a fake combination
872 //Printf("PS case --> Label 1 is %d, label 2 is %d", label, label2);
873 Int_t mother = label2;
874 while (stack->Particle(mother) && stack->Particle(mother)->GetMother(0) >= 0)
876 //Printf(" %d created by %d, %d", mother, stack->Particle(mother)->GetMother(0), stack->Particle(mother)->GetMother(1));
877 if (stack->Particle(mother)->GetMother(0) == label)
879 /*Printf("The untraceable decay was:");
882 Printf(" to (status code %d):", stack->Particle(mother)->GetStatusCode());
883 stack->Particle(mother)->Print();*/
886 mother = stack->Particle(mother)->GetMother(0);
889 else if (!firstIsPrim && secondIsPrim)
893 else if (!firstIsPrim && !secondIsPrim)
902 fDeltaPhi[hist]->Fill(deltaPhiArr[i], thirdDimArr[i]);
912 if (processed < inputCount)
913 Printf("Only %d out of %d track(let)s were used", processed, inputCount);
915 if (eventTriggered && eventVertex)
917 Double_t diff = vtxMC[2] - vtx[2];
918 fVertexShift->Fill(diff);
919 if (vtxESD->GetZRes() > 0)
920 fVertexShiftNorm->Fill(diff / vtxESD->GetZRes(), inputCount);
922 fVertexCorrelation->Fill(vtxMC[2], vtx[2]);
923 fVertexCorrelationShift->Fill(vtxMC[2], vtxMC[2] - vtx[2], inputCount);
924 fVertexProfile->Fill(vtxMC[2], vtxMC[2] - vtx[2]);
926 fTemp1->Fill(vtxMC[2], nEta05);
929 if (eventTriggered && eventVertex)
931 fdNdEtaAnalysisMC->FillEvent(vtxMC[2], inputCount);
932 fdNdEtaAnalysisESD->FillEvent(vtxMC[2], inputCount);
935 // stuff regarding the vertex reco correction and trigger bias correction
936 fdNdEtaCorrection->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
938 if (fOption.Contains("process-types"))
941 if (processType == AliPWG0Helper::kND)
942 fdNdEtaCorrectionSpecial[0]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
944 // single diffractive
945 if (processType == AliPWG0Helper::kSD)
946 fdNdEtaCorrectionSpecial[1]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
948 // double diffractive
949 if (processType == AliPWG0Helper::kDD)
950 fdNdEtaCorrectionSpecial[2]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
953 if (fOption.Contains("particle-species"))
954 for (Int_t id=0; id<4; id++)
955 fdNdEtaCorrectionSpecial[id]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
964 delete[] thirdDimArr;
966 delete[] deltaPhiArr;
969 void AlidNdEtaCorrectionTask::Terminate(Option_t *)
971 // The Terminate() function is the last function to be called during
972 // a query. It always runs on the client, it can be used to present
973 // the results graphically or save the results to file.
975 fOutput = dynamic_cast<TList*> (GetOutputData(0));
977 Printf("ERROR: fOutput not available");
981 fdNdEtaCorrection = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction"));
982 fdNdEtaAnalysisMC = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaMC"));
983 fdNdEtaAnalysisESD = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaESD"));
984 if (!fdNdEtaCorrection || !fdNdEtaAnalysisMC || !fdNdEtaAnalysisESD)
986 AliDebug(AliLog::kError, "Could not read object from output list");
990 fdNdEtaCorrection->Finish();
993 fileName.Form("correction_map%s.root", fOption.Data());
994 TFile* fout = new TFile(fileName, "RECREATE");
996 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCuts"));
998 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
1000 fEsdTrackCutsPrim = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPrim"));
1001 if (fEsdTrackCutsPrim)
1002 fEsdTrackCutsPrim->SaveHistograms("esd_track_cuts_primaries");
1004 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsSec"));
1005 if (fEsdTrackCutsSec)
1006 fEsdTrackCutsSec->SaveHistograms("esd_track_cuts_secondaries");
1008 fdNdEtaCorrection->SaveHistograms();
1009 fdNdEtaAnalysisMC->SaveHistograms();
1010 fdNdEtaAnalysisESD->SaveHistograms();
1012 if (fOutput->FindObject("dndeta_correction_ND"))
1014 fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_ND"));
1015 fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_SD"));
1016 fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_DD"));
1020 fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_pi"));
1021 fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_K"));
1022 fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_p"));
1023 fdNdEtaCorrectionSpecial[3] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_other"));
1025 for (Int_t i=0; i<4; ++i)
1026 if (fdNdEtaCorrectionSpecial[i])
1027 fdNdEtaCorrectionSpecial[i]->SaveHistograms();
1029 fTemp1 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp1"));
1032 fTemp2 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp2"));
1036 fVertexCorrelation = dynamic_cast<TH2F*> (fOutput->FindObject("fVertexCorrelation"));
1037 if (fVertexCorrelation)
1038 fVertexCorrelation->Write();
1039 fVertexCorrelationShift = dynamic_cast<TH3F*> (fOutput->FindObject("fVertexCorrelationShift"));
1040 if (fVertexCorrelationShift)
1042 ((TH2*) fVertexCorrelationShift->Project3D("yx"))->FitSlicesY();
1043 fVertexCorrelationShift->Write();
1045 fVertexProfile = dynamic_cast<TProfile*> (fOutput->FindObject("fVertexProfile"));
1047 fVertexProfile->Write();
1048 fVertexShift = dynamic_cast<TH1F*> (fOutput->FindObject("fVertexShift"));
1050 fVertexShift->Write();
1051 fVertexShiftNorm = dynamic_cast<TH2F*> (fOutput->FindObject("fVertexShiftNorm"));
1052 if (fVertexShiftNorm)
1054 fVertexShiftNorm->ProjectionX();
1055 fVertexShiftNorm->Write();
1058 fEtaCorrelation = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaCorrelation"));
1059 if (fEtaCorrelation)
1060 fEtaCorrelation->Write();
1061 fEtaCorrelationShift = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaCorrelationShift"));
1062 if (fEtaCorrelationShift)
1064 fEtaCorrelationShift->FitSlicesY();
1065 fEtaCorrelationShift->Write();
1067 fEtaProfile = dynamic_cast<TProfile*> (fOutput->FindObject("fEtaProfile"));
1069 fEtaProfile->Write();
1070 fEtaResolution = dynamic_cast<TH1F*> (fOutput->FindObject("fEtaResolution"));
1072 fEtaResolution->Write();
1073 fpTResolution = dynamic_cast<TH2F*> (fOutput->FindObject("fpTResolution"));
1076 fpTResolution->FitSlicesY();
1077 fpTResolution->Write();
1080 fMultAll = dynamic_cast<TH1F*> (fOutput->FindObject("fMultAll"));
1084 fMultTr = dynamic_cast<TH1F*> (fOutput->FindObject("fMultTr"));
1088 fMultVtx = dynamic_cast<TH1F*> (fOutput->FindObject("fMultVtx"));
1092 for (Int_t i=0; i<8; ++i)
1094 fDeltaPhi[i] = dynamic_cast<TH2*> (fOutput->FindObject(Form("fDeltaPhi_%d", i)));
1096 fDeltaPhi[i]->Write();
1099 fEventStats = dynamic_cast<TH2F*> (fOutput->FindObject("fEventStats"));
1101 fEventStats->Write();
1103 fPIDParticles = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDParticles"));
1105 fPIDParticles->Write();
1107 fPIDTracks = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDTracks"));
1109 fPIDTracks->Write();
1111 //fdNdEtaCorrection->DrawHistograms();
1113 Printf("Writting result to %s", fileName.Data());
1115 if (fPIDParticles && fPIDTracks)
1117 TDatabasePDG* pdgDB = new TDatabasePDG;
1119 for (Int_t i=0; i <= fPIDParticles->GetNbinsX()+1; ++i)
1120 if (fPIDParticles->GetBinContent(i) > 0)
1122 TObject* pdgParticle = pdgDB->GetParticle((Int_t) fPIDParticles->GetBinCenter(i));
1123 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));
1134 Bool_t AlidNdEtaCorrectionTask::SignOK(TParticlePDG* particle)
1136 // returns if a particle with this sign should be counted
1137 // this is determined by the value of fSignMode, which should have the same sign
1139 // if fSignMode is 0 all particles are counted
1146 printf("WARNING: not counting a particle that does not have a pdg particle\n");
1150 Double_t charge = particle->Charge();