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"
33 ClassImp(AlidNdEtaCorrectionTask)
35 AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask() :
40 fAnalysisMode((AliPWG0Helper::AnalysisMode) (AliPWG0Helper::kTPC | AliPWG0Helper::kFieldOn)),
41 fTrigger(AliPWG0Helper::kMB1),
45 fOnlyPrimaries(kFALSE),
50 fdNdEtaAnalysisESD(0),
53 fVertexCorrelation(0),
54 fVertexCorrelationShift(0),
59 fEtaCorrelationShift(0),
62 fDeltaPhiCorrelation(0),
74 // Constructor. Initialization of pointers
77 for (Int_t i=0; i<4; i++)
78 fdNdEtaCorrectionSpecial[i] = 0;
80 for (Int_t i=0; i<8; i++)
84 AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask(const char* opt) :
85 AliAnalysisTask("AlidNdEtaCorrectionTask", ""),
89 fAnalysisMode((AliPWG0Helper::AnalysisMode) (AliPWG0Helper::kTPC | AliPWG0Helper::kFieldOn)),
90 fTrigger(AliPWG0Helper::kMB1),
94 fOnlyPrimaries(kFALSE),
99 fdNdEtaAnalysisESD(0),
102 fVertexCorrelation(0),
103 fVertexCorrelationShift(0),
108 fEtaCorrelationShift(0),
111 fDeltaPhiCorrelation(0),
113 fEsdTrackCutsPrim(0),
123 // Constructor. Initialization of pointers
126 // Define input and output slots here
127 DefineInput(0, TChain::Class());
128 DefineOutput(0, TList::Class());
130 for (Int_t i=0; i<4; i++)
131 fdNdEtaCorrectionSpecial[i] = 0;
133 for (Int_t i=0; i<8; i++)
137 AlidNdEtaCorrectionTask::~AlidNdEtaCorrectionTask()
143 // histograms are in the output list and deleted when the output
144 // list is deleted by the TSelector dtor
152 //________________________________________________________________________
153 void AlidNdEtaCorrectionTask::ConnectInputData(Option_t *)
158 Printf("AlidNdEtaCorrectionTask::ConnectInputData called");
160 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
163 Printf("ERROR: Could not get ESDInputHandler");
165 fESD = esdH->GetEvent();
167 // Enable only the needed branches
168 esdH->SetActiveBranches("AliESDHeader Vertex");
170 if (fAnalysisMode & AliPWG0Helper::kSPD)
171 esdH->SetActiveBranches("AliESDHeader Vertex AliMultiplicity");
173 if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS) {
174 esdH->SetActiveBranches("AliESDHeader Vertex Tracks");
178 // disable info messages of AliMCEvent (per event)
179 AliLog::SetClassDebugLevel("AliMCEvent", AliLog::kWarning - AliLog::kDebug + 1);
182 void AlidNdEtaCorrectionTask::CreateOutputObjects()
184 // create result objects and add to output list
186 if (fOption.Contains("only-positive"))
188 Printf("INFO: Processing only positive particles.");
191 else if (fOption.Contains("only-negative"))
193 Printf("INFO: Processing only negative particles.");
197 if (fOption.Contains("stat-error-1"))
199 Printf("INFO: Evaluation statistical errors. Mode: 1.");
202 else if (fOption.Contains("stat-error-2"))
204 Printf("INFO: Evaluation statistical errors. Mode: 2.");
211 fdNdEtaCorrection = new AlidNdEtaCorrection("dndeta_correction", "dndeta_correction", fAnalysisMode);
212 fOutput->Add(fdNdEtaCorrection);
214 fPIDParticles = new TH1F("fPIDParticles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
215 fOutput->Add(fPIDParticles);
217 fPIDTracks = new TH1F("fPIDTracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
218 fOutput->Add(fPIDTracks);
220 fdNdEtaAnalysisMC = new dNdEtaAnalysis("dndetaMC", "dndetaMC", fAnalysisMode);
221 fOutput->Add(fdNdEtaAnalysisMC);
223 fdNdEtaAnalysisESD = new dNdEtaAnalysis("dndetaESD", "dndetaESD", fAnalysisMode);
224 fOutput->Add(fdNdEtaAnalysisESD);
228 fEsdTrackCutsPrim = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCuts->Clone("fEsdTrackCutsPrim"));
229 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCuts->Clone("fEsdTrackCutsSec"));
230 fOutput->Add(fEsdTrackCutsPrim);
231 fOutput->Add(fEsdTrackCutsSec);
234 if (fOption.Contains("process-types")) {
235 fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_ND", "dndeta_correction_ND", fAnalysisMode);
236 fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_SD", "dndeta_correction_SD", fAnalysisMode);
237 fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_DD", "dndeta_correction_DD", fAnalysisMode);
239 fOutput->Add(fdNdEtaCorrectionSpecial[0]);
240 fOutput->Add(fdNdEtaCorrectionSpecial[1]);
241 fOutput->Add(fdNdEtaCorrectionSpecial[2]);
244 if (fOption.Contains("particle-species")) {
245 fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_pi", "dndeta_correction_pi", fAnalysisMode);
246 fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_K", "dndeta_correction_K", fAnalysisMode);
247 fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_p", "dndeta_correction_p", fAnalysisMode);
248 fdNdEtaCorrectionSpecial[3] = new AlidNdEtaCorrection("dndeta_correction_other", "dndeta_correction_other", fAnalysisMode);
250 for (Int_t i=0; i<4; i++)
251 fOutput->Add(fdNdEtaCorrectionSpecial[i]);
256 fTemp1 = new TH2F("fTemp1", "fTemp1", 200, -0.08, 0.08, 200, -0.08, 0.08);
257 fOutput->Add(fTemp1);
258 fTemp2 = new TH1F("fTemp2", "fTemp2", 2000, -5, 5);
259 fOutput->Add(fTemp2);
262 fVertexCorrelation = new TH2F("fVertexCorrelation", "fVertexCorrelation;MC z-vtx;ESD z-vtx", 120, -30, 30, 120, -30, 30);
263 fOutput->Add(fVertexCorrelation);
264 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);
265 fOutput->Add(fVertexCorrelationShift);
266 fVertexProfile = new TProfile("fVertexProfile", "fVertexProfile;MC z-vtx;MC z-vtx - ESD z-vtx", 40, -20, 20);
267 fOutput->Add(fVertexProfile);
268 fVertexShift = new TH1F("fVertexShift", "fVertexShift;(MC z-vtx - ESD z-vtx);Entries", 201, -2, 2);
269 fOutput->Add(fVertexShift);
270 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);
271 fOutput->Add(fVertexShiftNorm);
273 fEtaCorrelation = new TH2F("fEtaCorrelation", "fEtaCorrelation;MC #eta;ESD #eta", 120, -3, 3, 120, -3, 3);
274 fOutput->Add(fEtaCorrelation);
275 fEtaCorrelationShift = new TH2F("fEtaCorrelationShift", "fEtaCorrelationShift;MC #eta;MC #eta - ESD #eta", 120, -3, 3, 100, -0.1, 0.1);
276 fOutput->Add(fEtaCorrelationShift);
277 fEtaProfile = new TProfile("fEtaProfile", "fEtaProfile;MC #eta;MC #eta - ESD #eta", 120, -3, 3);
278 fOutput->Add(fEtaProfile);
279 fEtaResolution = new TH1F("fEtaResolution", "fEtaResolution;MC #eta - ESD #eta", 201, -0.2, 0.2);
280 fOutput->Add(fEtaResolution);
282 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);
283 fOutput->Add(fpTResolution);
285 fMultAll = new TH1F("fMultAll", "fMultAll", 500, -0.5, 499.5);
286 fOutput->Add(fMultAll);
287 fMultVtx = new TH1F("fMultVtx", "fMultVtx", 500, -0.5, 499.5);
288 fOutput->Add(fMultVtx);
289 fMultTr = new TH1F("fMultTr", "fMultTr", 500, -0.5, 499.5);
290 fOutput->Add(fMultTr);
292 for (Int_t i=0; i<8; i++)
294 fDeltaPhi[i] = new TH2F(Form("fDeltaPhi_%d", i), ";#Delta phi;#phi;Entries", 2000, -0.1, 0.1, 18 * 5, 0, TMath::TwoPi());
295 fOutput->Add(fDeltaPhi[i]);
298 fEventStats = new TH2F("fEventStats", "fEventStats;event type;status;count", 106, -5.5, 100.5, 4, -0.5, 3.5);
299 fOutput->Add(fEventStats);
300 fEventStats->GetXaxis()->SetBinLabel(1, "INEL"); // x = -5
301 fEventStats->GetXaxis()->SetBinLabel(2, "NSD"); // x = -4
302 fEventStats->GetXaxis()->SetBinLabel(3, "ND"); // x = -3
303 fEventStats->GetXaxis()->SetBinLabel(4, "SD"); // x = -2
304 fEventStats->GetXaxis()->SetBinLabel(5, "DD"); // x = -1
306 for (Int_t i=0; i<100; i++)
307 fEventStats->GetXaxis()->SetBinLabel(7+i, Form("%d", i));
309 fEventStats->GetYaxis()->SetBinLabel(1, "nothing");
310 fEventStats->GetYaxis()->SetBinLabel(2, "trg");
311 fEventStats->GetYaxis()->SetBinLabel(3, "vtx");
312 fEventStats->GetYaxis()->SetBinLabel(4, "trgvtx");
316 fEsdTrackCuts->SetName("fEsdTrackCuts");
317 fOutput->Add(fEsdTrackCuts);
321 void AlidNdEtaCorrectionTask::Exec(Option_t*)
325 // Check prerequisites
328 AliDebug(AliLog::kError, "ESD branch not available");
333 Printf("WARNING: Processing only primaries. For systematical studies only!");
336 Printf("WARNING: Statistical error evaluation active!");
338 // trigger definition
339 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, fTrigger);
340 //Printf("Trigger mask: %lld", fESD->GetTriggerMask());
343 Printf("No trigger");
345 // post the data already here
346 PostData(0, fOutput);
349 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
351 Printf("ERROR: Could not retrieve MC event handler");
355 AliMCEvent* mcEvent = eventHandler->MCEvent();
357 Printf("ERROR: Could not retrieve MC event");
361 AliStack* stack = mcEvent->Stack();
364 AliDebug(AliLog::kError, "Stack not available");
368 AliHeader* header = mcEvent->Header();
371 AliDebug(AliLog::kError, "Header not available");
376 Int_t processType = AliPWG0Helper::GetEventProcessType(header);
377 AliDebug(AliLog::kDebug+1, Form("Found process type %d", processType));
379 if (processType == AliPWG0Helper::kInvalidProcess)
380 AliDebug(AliLog::kError, "Unknown process type.");
383 AliGenEventHeader* genHeader = header->GenEventHeader();
385 genHeader->PrimaryVertex(vtxMC);
387 // get the ESD vertex
388 Bool_t eventVertex = kFALSE;
390 const AliESDVertex* vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
391 if (vtxESD && AliPWG0Helper::TestVertex(vtxESD, fAnalysisMode))
400 Int_t biny = (Int_t) eventTriggered + 2 * (Int_t) eventVertex;
402 fEventStats->Fill(-5, biny);
404 if (processType != AliPWG0Helper::kSD)
405 fEventStats->Fill(-4, biny);
407 if (processType == AliPWG0Helper::kND)
408 fEventStats->Fill(-3, biny);
409 if (processType == AliPWG0Helper::kSD)
410 fEventStats->Fill(-2, biny);
411 if (processType == AliPWG0Helper::kDD)
412 fEventStats->Fill(-1, biny);
414 // create list of (label, eta, pt) tuples
415 Int_t inputCount = 0;
417 Int_t* labelArr2 = 0; // only for case of SPD
419 Float_t* thirdDimArr = 0;
420 Float_t* deltaPhiArr = 0;
421 if (fAnalysisMode & AliPWG0Helper::kSPD)
424 const AliMultiplicity* mult = fESD->GetMultiplicity();
427 AliDebug(AliLog::kError, "AliMultiplicity not available");
431 labelArr = new Int_t[mult->GetNumberOfTracklets()];
432 labelArr2 = new Int_t[mult->GetNumberOfTracklets()];
433 etaArr = new Float_t[mult->GetNumberOfTracklets()];
434 thirdDimArr = new Float_t[mult->GetNumberOfTracklets()];
435 deltaPhiArr = new Float_t[mult->GetNumberOfTracklets()];
437 // get multiplicity from SPD tracklets
438 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
440 //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
442 Float_t phi = mult->GetPhi(i);
444 phi += TMath::Pi() * 2;
445 Float_t deltaPhi = mult->GetDeltaPhi(i);
447 if (TMath::Abs(deltaPhi) > 1)
448 printf("WARNING: Very high Delta Phi: %d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), deltaPhi);
451 if (mult->GetLabel(i, 0) < 0 || mult->GetLabel(i, 0) != mult->GetLabel(i, 1) || !stack->IsPhysicalPrimary(mult->GetLabel(i, 0)))
454 if (fDeltaPhiCut > 0 && TMath::Abs(deltaPhi) > fDeltaPhiCut)
457 etaArr[inputCount] = mult->GetEta(i);
458 labelArr[inputCount] = mult->GetLabel(i, 0);
459 labelArr2[inputCount] = mult->GetLabel(i, 1);
460 thirdDimArr[inputCount] = phi;
461 deltaPhiArr[inputCount] = deltaPhi;
465 else if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS)
469 AliDebug(AliLog::kError, "fESDTrackCuts not available");
475 // get multiplicity from ESD tracks
476 TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode & AliPWG0Helper::kTPC));
477 Int_t nGoodTracks = list->GetEntries();
479 Printf("Accepted %d tracks", nGoodTracks);
481 labelArr = new Int_t[nGoodTracks];
482 labelArr2 = new Int_t[nGoodTracks];
483 etaArr = new Float_t[nGoodTracks];
484 thirdDimArr = new Float_t[nGoodTracks];
485 deltaPhiArr = new Float_t[nGoodTracks];
487 // loop over esd tracks
488 for (Int_t i=0; i<nGoodTracks; i++)
490 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
493 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
497 //Printf("status is: %u", esdTrack->GetStatus());
501 Int_t label = TMath::Abs(esdTrack->GetLabel());
505 if (stack->IsPhysicalPrimary(label) == kFALSE)
509 etaArr[inputCount] = esdTrack->Eta();
510 labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
511 labelArr2[inputCount] = labelArr[inputCount]; // no second label for tracks
512 thirdDimArr[inputCount] = esdTrack->Pt();
513 deltaPhiArr[inputCount] = 0; // no delta phi for tracks
521 // collect values for primaries and secondaries
522 for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
524 AliESDtrack* track = 0;
526 if (fAnalysisMode & AliPWG0Helper::kTPC)
527 track = AliESDtrackCuts::GetTPCOnlyTrack(fESD, iTrack);
528 else if (fAnalysisMode & AliPWG0Helper::kTPCITS)
529 track = fESD->GetTrack(iTrack);
534 Int_t label = TMath::Abs(track->GetLabel());
535 if (!stack->Particle(label) || !stack->Particle(label)->GetPDG())
537 Printf("WARNING: No particle for %d", label);
538 if (stack->Particle(label))
539 stack->Particle(label)->Print();
543 if (stack->Particle(label)->GetPDG()->Charge() == 0)
546 if (TMath::Abs(track->Eta()) < 0.8 && track->Pt() > 0.15)
548 if (stack->IsPhysicalPrimary(label))
551 if (fEsdTrackCutsPrim->AcceptTrack(track))
553 // if (AliESDtrackCuts::GetSigmaToVertex(track) > 900)
555 // Printf("Track %d has nsigma of %f. Printing track and vertex...", iTrack, AliESDtrackCuts::GetSigmaToVertex(track));
558 // track->GetImpactParameters(b, r);
559 // Printf("Impact parameter %f %f and resolution: %f %f %f", b[0], b[1], r[0], r[1], r[2]);
569 fEsdTrackCutsSec->AcceptTrack(track);
573 // TODO mem leak in the continue statements above
574 if (fAnalysisMode & AliPWG0Helper::kTPC)
583 // loop over mc particles
584 Int_t nPrim = stack->GetNprimary();
587 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
589 //Printf("Getting particle %d", iMc);
590 TParticle* particle = stack->Particle(iMc);
595 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
597 //if (TMath::Abs(particle->GetPdgCode()) > 3000 && TMath::Abs(particle->Eta()) < 1.0)
598 // fPIDParticles->Fill(particle->GetPdgCode());
602 if (SignOK(particle->GetPDG()) == kFALSE)
605 if (fPIDParticles && TMath::Abs(particle->Eta()) < 1.0)
606 fPIDParticles->Fill(particle->GetPdgCode());
608 Float_t eta = particle->Eta();
610 Float_t thirdDim = -1;
611 if (fAnalysisMode & AliPWG0Helper::kSPD)
615 thirdDim = particle->Phi();
618 thirdDim = inputCount;
621 thirdDim = particle->Pt();
624 //Float_t y = 0.5 * TMath::Log((particle->Energy() + particle->Pz()) / (particle->Energy() - particle->Pz()));
628 fdNdEtaCorrection->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
630 if (fOption.Contains("process-types"))
633 if (processType==AliPWG0Helper::kND)
634 fdNdEtaCorrectionSpecial[0]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
636 // single diffractive
637 if (processType==AliPWG0Helper::kSD)
638 fdNdEtaCorrectionSpecial[1]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
640 // double diffractive
641 if (processType==AliPWG0Helper::kDD)
642 fdNdEtaCorrectionSpecial[2]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
645 if (fOption.Contains("particle-species"))
648 switch (TMath::Abs(particle->GetPdgCode()))
650 case 211: id = 0; break;
651 case 321: id = 1; break;
652 case 2212: id = 2; break;
653 default: id = 3; break;
655 fdNdEtaCorrectionSpecial[id]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
660 fdNdEtaAnalysisMC->FillTrack(vtxMC[2], eta, thirdDim);
662 // TODO this value might be needed lower for the SPD study (only used for control histograms anyway)
663 if (TMath::Abs(eta) < 1.5) // && pt > 0.2)
667 fEventStats->Fill(AliPWG0Helper::GetLastProcessType(), biny);
669 fMultAll->Fill(nAccepted);
670 if (eventTriggered) {
671 fMultTr->Fill(nAccepted);
673 fMultVtx->Fill(nAccepted);
678 Bool_t* primCount = 0;
681 primCount = new Bool_t[nPrim];
682 for (Int_t i=0; i<nPrim; ++i)
683 primCount[i] = kFALSE;
686 for (Int_t i=0; i<inputCount; ++i)
688 Int_t label = labelArr[i];
689 Int_t label2 = labelArr2[i];
693 Printf("WARNING: cannot find corresponding mc particle for track(let) %d with label %d.", i, label);
697 TParticle* particle = stack->Particle(label);
700 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label));
704 fPIDTracks->Fill(particle->GetPdgCode());
706 // find particle that is filled in the correction map
707 // this should be the particle that has been reconstructed
708 // for TPC this is clear and always identified by the track's label
709 // for SPD the labels might not be identical. In this case the particle closest to the beam line that is a primary is taken:
710 // L1 L2 (P = primary, S = secondary)
716 if (label != label2 && label2 >= 0)
718 if (stack->IsPhysicalPrimary(label) == kFALSE && stack->IsPhysicalPrimary(label2))
720 particle = stack->Particle(label2);
723 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label2));
729 if (eventTriggered && eventVertex)
731 if (SignOK(particle->GetPDG()) == kFALSE)
737 fEtaResolution->Fill(particle->Eta() - etaArr[i]);
739 if (fAnalysisMode & AliPWG0Helper::kTPC || fAnalysisMode & AliPWG0Helper::kTPCITS)
740 if (TMath::Abs(particle->Eta() < 0.9) && particle->Pt() > 0)
741 fpTResolution->Fill(particle->Pt(), (particle->Pt() - thirdDimArr[i]) / particle->Pt());
744 Float_t thirdDim = -1;
746 Bool_t firstIsPrim = stack->IsPhysicalPrimary(label);
747 // in case of same label the MC values are filled, otherwise (background) the reconstructed values
750 eta = particle->Eta();
752 if (fAnalysisMode & AliPWG0Helper::kSPD)
756 thirdDim = particle->Phi();
759 thirdDim = inputCount;
762 thirdDim = particle->Pt();
766 if (fAnalysisMode & AliPWG0Helper::kSPD && !fFillPhi)
768 thirdDim = inputCount;
771 thirdDim = thirdDimArr[i];
776 Bool_t fillTrack = kTRUE;
778 // statistical error evaluation active?
781 Bool_t statErrorDecision = kFALSE;
783 // primary and not yet counted
784 if (label == label2 && firstIsPrim && !primCount[label])
786 statErrorDecision = kTRUE;
787 primCount[label] = kTRUE;
790 // in case of 1 we count only unique primaries, in case of 2 all the rest
793 fillTrack = statErrorDecision;
795 else if (fStatError == 2)
796 fillTrack = !statErrorDecision;
800 fdNdEtaCorrection->FillTrackedParticle(vtxMC[2], eta, thirdDim);
802 // eta comparison for tracklets with the same label (others are background)
805 fEtaProfile->Fill(particle->Eta(), particle->Eta() - etaArr[i]);
806 fEtaCorrelation->Fill(etaArr[i], particle->Eta());
807 fEtaCorrelationShift->Fill(particle->Eta(), particle->Eta() - etaArr[i]);
810 fdNdEtaAnalysisESD->FillTrack(vtxMC[2], particle->Eta(), thirdDim);
812 if (fOption.Contains("process-types"))
815 if (processType == AliPWG0Helper::kND)
816 fdNdEtaCorrectionSpecial[0]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
818 // single diffractive
819 if (processType == AliPWG0Helper::kSD)
820 fdNdEtaCorrectionSpecial[1]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
822 // double diffractive
823 if (processType == AliPWG0Helper::kDD)
824 fdNdEtaCorrectionSpecial[2]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
827 if (fOption.Contains("particle-species"))
830 TParticle* mother = AliPWG0Helper::FindPrimaryMother(stack, label);
833 switch (TMath::Abs(mother->GetPdgCode()))
835 case 211: id = 0; break;
836 case 321: id = 1; break;
837 case 2212: id = 2; break;
838 default: id = 3; break;
840 fdNdEtaCorrectionSpecial[id]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
843 // control histograms
854 else if (label2 >= 0)
856 Bool_t secondIsPrim = stack->IsPhysicalPrimary(label2);
857 if (firstIsPrim && secondIsPrim)
861 else if (firstIsPrim && !secondIsPrim)
865 // check if secondary is caused by the primary or it is a fake combination
866 //Printf("PS case --> Label 1 is %d, label 2 is %d", label, label2);
867 Int_t mother = label2;
868 while (stack->Particle(mother) && stack->Particle(mother)->GetMother(0) >= 0)
870 //Printf(" %d created by %d, %d", mother, stack->Particle(mother)->GetMother(0), stack->Particle(mother)->GetMother(1));
871 if (stack->Particle(mother)->GetMother(0) == label)
873 /*Printf("The untraceable decay was:");
876 Printf(" to (status code %d):", stack->Particle(mother)->GetStatusCode());
877 stack->Particle(mother)->Print();*/
880 mother = stack->Particle(mother)->GetMother(0);
883 else if (!firstIsPrim && secondIsPrim)
887 else if (!firstIsPrim && !secondIsPrim)
896 fDeltaPhi[hist]->Fill(deltaPhiArr[i], thirdDimArr[i]);
906 if (processed < inputCount)
907 Printf("Only %d out of %d track(let)s were used", processed, inputCount);
909 if (eventTriggered && eventVertex)
911 Double_t diff = vtxMC[2] - vtx[2];
912 fVertexShift->Fill(diff);
913 if (vtxESD->GetZRes() > 0)
914 fVertexShiftNorm->Fill(diff / vtxESD->GetZRes(), inputCount);
916 fVertexCorrelation->Fill(vtxMC[2], vtx[2]);
917 fVertexCorrelationShift->Fill(vtxMC[2], vtxMC[2] - vtx[2], inputCount);
918 fVertexProfile->Fill(vtxMC[2], vtxMC[2] - vtx[2]);
921 if (eventTriggered && eventVertex)
923 fdNdEtaAnalysisMC->FillEvent(vtxMC[2], inputCount);
924 fdNdEtaAnalysisESD->FillEvent(vtxMC[2], inputCount);
927 // stuff regarding the vertex reco correction and trigger bias correction
928 fdNdEtaCorrection->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
930 if (fOption.Contains("process-types"))
933 if (processType == AliPWG0Helper::kND)
934 fdNdEtaCorrectionSpecial[0]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
936 // single diffractive
937 if (processType == AliPWG0Helper::kSD)
938 fdNdEtaCorrectionSpecial[1]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
940 // double diffractive
941 if (processType == AliPWG0Helper::kDD)
942 fdNdEtaCorrectionSpecial[2]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
945 if (fOption.Contains("particle-species"))
946 for (Int_t id=0; id<4; id++)
947 fdNdEtaCorrectionSpecial[id]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
956 delete[] thirdDimArr;
958 delete[] deltaPhiArr;
961 void AlidNdEtaCorrectionTask::Terminate(Option_t *)
963 // The Terminate() function is the last function to be called during
964 // a query. It always runs on the client, it can be used to present
965 // the results graphically or save the results to file.
967 fOutput = dynamic_cast<TList*> (GetOutputData(0));
969 Printf("ERROR: fOutput not available");
973 fdNdEtaCorrection = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction"));
974 fdNdEtaAnalysisMC = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaMC"));
975 fdNdEtaAnalysisESD = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaESD"));
976 if (!fdNdEtaCorrection || !fdNdEtaAnalysisMC || !fdNdEtaAnalysisESD)
978 AliDebug(AliLog::kError, "Could not read object from output list");
982 fdNdEtaCorrection->Finish();
985 fileName.Form("correction_map%s.root", fOption.Data());
986 TFile* fout = new TFile(fileName, "RECREATE");
988 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCuts"));
990 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
992 fEsdTrackCutsPrim = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPrim"));
993 if (fEsdTrackCutsPrim)
994 fEsdTrackCutsPrim->SaveHistograms("esd_track_cuts_primaries");
996 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsSec"));
997 if (fEsdTrackCutsSec)
998 fEsdTrackCutsSec->SaveHistograms("esd_track_cuts_secondaries");
1000 fdNdEtaCorrection->SaveHistograms();
1001 fdNdEtaAnalysisMC->SaveHistograms();
1002 fdNdEtaAnalysisESD->SaveHistograms();
1004 if (fOutput->FindObject("dndeta_correction_ND"))
1006 fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_ND"));
1007 fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_SD"));
1008 fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_DD"));
1012 fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_pi"));
1013 fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_K"));
1014 fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_p"));
1015 fdNdEtaCorrectionSpecial[3] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_other"));
1017 for (Int_t i=0; i<4; ++i)
1018 if (fdNdEtaCorrectionSpecial[i])
1019 fdNdEtaCorrectionSpecial[i]->SaveHistograms();
1021 fTemp1 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp1"));
1024 fTemp2 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp2"));
1028 fVertexCorrelation = dynamic_cast<TH2F*> (fOutput->FindObject("fVertexCorrelation"));
1029 if (fVertexCorrelation)
1030 fVertexCorrelation->Write();
1031 fVertexCorrelationShift = dynamic_cast<TH3F*> (fOutput->FindObject("fVertexCorrelationShift"));
1032 if (fVertexCorrelationShift)
1034 ((TH2*) fVertexCorrelationShift->Project3D("yx"))->FitSlicesY();
1035 fVertexCorrelationShift->Write();
1037 fVertexProfile = dynamic_cast<TProfile*> (fOutput->FindObject("fVertexProfile"));
1039 fVertexProfile->Write();
1040 fVertexShift = dynamic_cast<TH1F*> (fOutput->FindObject("fVertexShift"));
1042 fVertexShift->Write();
1043 fVertexShiftNorm = dynamic_cast<TH2F*> (fOutput->FindObject("fVertexShiftNorm"));
1044 if (fVertexShiftNorm)
1046 fVertexShiftNorm->ProjectionX();
1047 fVertexShiftNorm->Write();
1050 fEtaCorrelation = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaCorrelation"));
1051 if (fEtaCorrelation)
1052 fEtaCorrelation->Write();
1053 fEtaCorrelationShift = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaCorrelationShift"));
1054 if (fEtaCorrelationShift)
1056 fEtaCorrelationShift->FitSlicesY();
1057 fEtaCorrelationShift->Write();
1059 fEtaProfile = dynamic_cast<TProfile*> (fOutput->FindObject("fEtaProfile"));
1061 fEtaProfile->Write();
1062 fEtaResolution = dynamic_cast<TH1F*> (fOutput->FindObject("fEtaResolution"));
1064 fEtaResolution->Write();
1065 fpTResolution = dynamic_cast<TH2F*> (fOutput->FindObject("fpTResolution"));
1068 fpTResolution->FitSlicesY();
1069 fpTResolution->Write();
1072 fMultAll = dynamic_cast<TH1F*> (fOutput->FindObject("fMultAll"));
1076 fMultTr = dynamic_cast<TH1F*> (fOutput->FindObject("fMultTr"));
1080 fMultVtx = dynamic_cast<TH1F*> (fOutput->FindObject("fMultVtx"));
1084 for (Int_t i=0; i<8; ++i)
1086 fDeltaPhi[i] = dynamic_cast<TH2*> (fOutput->FindObject(Form("fDeltaPhi_%d", i)));
1088 fDeltaPhi[i]->Write();
1091 fEventStats = dynamic_cast<TH2F*> (fOutput->FindObject("fEventStats"));
1093 fEventStats->Write();
1095 fPIDParticles = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDParticles"));
1097 fPIDParticles->Write();
1099 fPIDTracks = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDTracks"));
1101 fPIDTracks->Write();
1103 //fdNdEtaCorrection->DrawHistograms();
1105 Printf("Writting result to %s", fileName.Data());
1107 if (fPIDParticles && fPIDTracks)
1109 TDatabasePDG* pdgDB = new TDatabasePDG;
1111 for (Int_t i=0; i <= fPIDParticles->GetNbinsX()+1; ++i)
1112 if (fPIDParticles->GetBinContent(i) > 0)
1114 TObject* pdgParticle = pdgDB->GetParticle((Int_t) fPIDParticles->GetBinCenter(i));
1115 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));
1126 Bool_t AlidNdEtaCorrectionTask::SignOK(TParticlePDG* particle)
1128 // returns if a particle with this sign should be counted
1129 // this is determined by the value of fSignMode, which should have the same sign
1131 // if fSignMode is 0 all particles are counted
1138 printf("WARNING: not counting a particle that does not have a pdg particle\n");
1142 Double_t charge = particle->Charge();