8 #include "TParticlePDG.h"
10 #include "AliESDtrackCuts.h"
11 #include "AliPWG0Helper.h"
12 #include "AliTriggerAnalysis.h"
14 #include "AliAnalysisTask.h"
15 #include "AliAnalysisManager.h"
16 #include "AliESDEvent.h"
17 #include "AliESDInputHandler.h"
18 #include "AliESDVertex.h"
20 #include "AliMCEventHandler.h"
21 #include "AliMCEvent.h"
25 #include "AliCutTask.h"
27 // simple task that runs the esd track cuts to evaluate the basic plots created during the cuts
31 //________________________________________________________________________
32 AliCutTask::AliCutTask(const char *name) :
33 AliAnalysisTask(name, ""), fESD(0), fTrackCuts(0),
34 fAnalysisMode(AliPWG0Helper::kTPCITS),
35 fTrackCutsPrimaries(0),
36 fTrackCutsSecondaries(0), fVertex(0), fTriggerStats(0), fOutput(0),
41 // Define input and output slots here
42 DefineInput(0, TChain::Class());
43 DefineOutput(0, TList::Class());
46 //________________________________________________________________________
47 void AliCutTask::ConnectInputData(Option_t *)
49 // Connect ESD or AOD here
52 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
54 Printf("ERROR: Could not read chain from input slot 0");
56 // Disable all branches and enable only the needed ones
57 //tree->SetBranchStatus("*", kFALSE);
60 tree->SetBranchStatus("fTriggerMask", kTRUE);
61 tree->SetBranchStatus("fTracks.*", kTRUE);
62 tree->SetBranchStatus("fSPDVertex*", kTRUE);
65 tree->SetBranchStatus("TriggerMask", kTRUE);
66 tree->SetBranchStatus("AliESDHeader", kTRUE);
67 //AliPWG0Helper::SetBranchStatusRecursive(tree, "Tracks", kTRUE);
68 //AliPWG0Helper::SetBranchStatusRecursive(tree, "SPDVertex", kTRUE);
70 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
73 Printf("ERROR: Could not get ESDInputHandler");
75 fESD = esdH->GetEvent();
79 //________________________________________________________________________
80 void AliCutTask::CreateOutputObjects()
88 fOutput->Add(fTrackCuts);
89 if (fTrackCutsPrimaries)
90 fOutput->Add(fTrackCutsPrimaries);
91 if (fTrackCutsSecondaries)
92 fOutput->Add(fTrackCutsSecondaries);
94 fVertex = new TH1F("fVertex", "fVertex;z vtx (cm);Count", 201, -20, 20);
95 fOutput->Add(fVertex);
97 fTriggerStats = new TH1F("fTriggerStats", "fTriggerStats;trigger;Count", 5, -0.5, 4.5);
98 fTriggerStats->GetXaxis()->SetBinLabel(1, "!MB1 & !MB2");
99 fTriggerStats->GetXaxis()->SetBinLabel(2, "MB1");
100 fTriggerStats->GetXaxis()->SetBinLabel(3, "MB2");
101 fTriggerStats->GetXaxis()->SetBinLabel(4, "ITS_SPD_GFO_L0");
102 fTriggerStats->GetXaxis()->SetBinLabel(5, "VZERO_OR_LEFT | VZERO_OR_RIGHT");
103 fOutput->Add(fTriggerStats);
105 fPrimStats = new TH1F("fPrimStats", "fPrimStats", 8, 0.5, 8.5);
106 fPrimStats->GetXaxis()->SetBinLabel(1, "Primary accepted once");
107 fPrimStats->GetXaxis()->SetBinLabel(2, "Primary accepted more than once");
108 fPrimStats->GetXaxis()->SetBinLabel(3, "Primary accepted more than once (count)");
109 fPrimStats->GetXaxis()->SetBinLabel(4, "Primary track rejected");
110 fPrimStats->GetXaxis()->SetBinLabel(5, "Primary track rejected (count)");
111 fPrimStats->GetXaxis()->SetBinLabel(6, "Primary track rejected, but other track accepted");
112 fPrimStats->GetXaxis()->SetBinLabel(7, "Primary track rejected, but other track accepted (count)");
113 fOutput->Add(fPrimStats);
115 // disable info messages of AliMCEvent (per event)
116 AliLog::SetClassDebugLevel("AliMCEvent", AliLog::kWarning - AliLog::kDebug + 1);
119 //________________________________________________________________________
120 void AliCutTask::Exec(Option_t *)
123 // Called for each event
126 Printf("ERROR: fESD not available");
131 PostData(0, fOutput);
133 //fESD->GetVertex()->Print();
135 static AliTriggerAnalysis* triggerAnalysis = new AliTriggerAnalysis;
137 if (!triggerAnalysis->IsTriggerFired(fESD, AliTriggerAnalysis::kMB1) && !triggerAnalysis->IsTriggerFired(fESD, AliTriggerAnalysis::kMB2))
138 fTriggerStats->Fill(0);
140 if (triggerAnalysis->IsTriggerFired(fESD, AliTriggerAnalysis::kMB1))
141 fTriggerStats->Fill(1);
143 if (triggerAnalysis->IsTriggerFired(fESD, AliTriggerAnalysis::kMB2))
144 fTriggerStats->Fill(2);
146 if (fESD->GetTriggerMask() & (0x1 << 14))
147 fTriggerStats->Fill(3);
149 if (fESD->GetTriggerMask() & 1 || fESD->GetTriggerMask() & 2)
150 fTriggerStats->Fill(4);
152 //if (fESD->GetTriggerMask() & (0x1 << 14) == 0)
153 if (!triggerAnalysis->IsTriggerFired(fESD, AliTriggerAnalysis::kMB2))
156 // get the ESD vertex
157 const AliESDVertex* vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
161 Printf("No vertex. Skipping event");
165 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
166 Int_t acceptedTracks = fTrackCuts->CountAcceptedTracks(fESD);
167 Printf("Accepted %d tracks", acceptedTracks);
169 if (fTrackCutsPrimaries && fTrackCutsSecondaries)
171 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
173 Printf("ERROR: Could not retrieve MC event handler");
177 AliMCEvent* mcEvent = eventHandler->MCEvent();
179 Printf("ERROR: Could not retrieve MC event");
183 AliStack* stack = mcEvent->Stack();
186 Printf("ERROR: Stack not available");
190 // count if primaries are counted several times
191 Int_t max = stack->GetNprimary();
192 Int_t* primAcc = new Int_t[max];
193 Int_t* primRej = new Int_t[max];
194 for (Int_t i=0; i<max; i++)
200 for (Int_t trackId = 0; trackId < fESD->GetNumberOfTracks(); trackId++)
202 AliESDtrack* track = fESD->GetTrack(trackId);
205 Printf("UNEXPECTED: Could not get track with id %d", trackId);
209 if (track->GetLabel() == 0)
211 Printf("Track %d has no label. Skipping", trackId);
215 Int_t label = TMath::Abs(track->GetLabel());
216 if (stack->IsPhysicalPrimary(label) == kTRUE)
220 Printf("Warning label %d is higher than number of primaries %d", label, max);
224 if (fTrackCutsPrimaries->AcceptTrack(track))
234 if (!stack->Particle(label)) {
235 Printf("ERROR: Could not get particle with label %d", label);
239 // Deuteron is ok, but missing in Pdg particles in root
240 if (stack->Particle(label)->GetPdgCode() != 10010020) {
241 if (!stack->Particle(label)->GetPDG()) {
242 Printf("ERROR: Could not get PDG particle of particle with label %d (pdg code is %d)", label, stack->Particle(label)->GetPdgCode());
243 stack->Particle(label)->Print();
247 if (stack->Particle(label)->GetPDG()->Charge() == 0) {
248 Printf("Particle %d has 0 charge. Skipping.", label);
253 fTrackCutsSecondaries->AcceptTrack(track);
257 for (Int_t i=0; i<max; i++) {
258 if (primAcc[i] == 1) {
260 } else if (primAcc[i] > 1) {
262 fPrimStats->Fill(3, primAcc[i]);
265 if (primRej[i] > 0) {
266 if (primAcc[i] == 0) {
268 fPrimStats->Fill(5, primRej[i]);
269 } else if (primAcc[i] > 0) {
271 fPrimStats->Fill(7, primRej[i]);
280 // get the ESD vertex
281 fVertex->Fill(vtxESD->GetZv());
284 //________________________________________________________________________
285 void AliCutTask::Terminate(Option_t *)
287 // Draw result to the screen
288 // Called once at the end of the query
290 fOutput = dynamic_cast<TList*> (GetOutputData(0));
292 Printf("ERROR: fOutput not available");
296 fTrackCuts = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("AliESDtrackCuts"));
298 Printf("ERROR: fTrackCuts not available");
302 fVertex = dynamic_cast<TH1F*> (fOutput->FindObject("fVertex"));
304 Printf("ERROR: fVertex not available");
308 fTriggerStats = dynamic_cast<TH1F*> (fOutput->FindObject("fTriggerStats"));
309 if (!fTriggerStats) {
310 Printf("ERROR: fTriggerStats not available");
314 fTrackCutsPrimaries = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fTrackCutsPrimaries"));
315 fTrackCutsSecondaries = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fTrackCutsSecondaries"));
317 TFile* file = TFile::Open("trackCuts.root", "RECREATE");
319 fTrackCuts->SaveHistograms();
321 fTriggerStats->Write();
323 if (fTrackCutsPrimaries)
324 fTrackCutsPrimaries->SaveHistograms();
326 if (fTrackCutsSecondaries)
327 fTrackCutsSecondaries->SaveHistograms();
334 Printf("Writting results to trackCuts.root.");
336 fTrackCuts->DrawHistograms();
342 fTriggerStats->Draw();
345 void AliCutTask::EnableSecondaryStudy()
348 // clones the fTrackCuts
352 Printf("ERROR: fTrackCuts 0. Do not call this function before SetTrackCuts");
356 fTrackCutsPrimaries = dynamic_cast<AliESDtrackCuts*> (fTrackCuts->Clone("fTrackCutsPrimaries"));
357 fTrackCutsSecondaries = dynamic_cast<AliESDtrackCuts*> (fTrackCuts->Clone("fTrackCutsSecondaries"));