]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskPtEMCalTrigger.cxx
Use aod track selection wrapper inside the task, when running on aods
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskPtEMCalTrigger.cxx
CommitLineData
46f589c2 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17 * Analysis task of the pt analysis on EMCal-triggered events
18 *
19 * Author: Markus Fasel
20 */
21
22#include <map>
23#include <cstring>
24#include <iostream>
25#include <memory>
26#include <vector>
27#include <string>
28#include <sstream>
29
bf1cb6ad 30#include <TClonesArray.h>
46f589c2 31#include <TDirectory.h>
32#include <TH1.h>
33#include <THashList.h>
eed93770 34#include <TList.h>
46f589c2 35#include <TKey.h>
36#include <TMath.h>
37#include <TObjArray.h>
38#include <TString.h>
39
cdc26d91 40#include "AliAODEvent.h"
46f589c2 41#include "AliESDEvent.h"
cdc26d91 42#include "AliInputEventHandler.h"
43#include "AliMCEvent.h"
44#include "AliParticleContainer.h"
45#include "AliVCluster.h"
46#include "AliVParticle.h"
47#include "AliVTrack.h"
48#include "AliVVertex.h"
46f589c2 49
50#include "AliEMCalHistoContainer.h"
cdc26d91 51#include "AliEMCalPtTaskVTrackSelection.h"
009a14cb 52#include "AliEMCalPtTaskTrackSelectionAOD.h"
cdc26d91 53#include "AliEMCalPtTaskTrackSelectionESD.h"
46f589c2 54#include "AliAnalysisTaskPtEMCalTrigger.h"
55
56ClassImp(EMCalTriggerPtAnalysis::AliAnalysisTaskPtEMCalTrigger)
57
58namespace EMCalTriggerPtAnalysis {
59
60 //______________________________________________________________________________
61 AliAnalysisTaskPtEMCalTrigger::AliAnalysisTaskPtEMCalTrigger():
cdc26d91 62 AliAnalysisTaskEmcal(),
46f589c2 63 fHistos(NULL),
4c61ea4f 64 fListTrackCuts(NULL),
65 fEtaRange(),
bd1a1d65 66 fPtRange(),
5bdebc68 67 fSwapEta(kFALSE),
cdc26d91 68 fUseTriggersFromTriggerMaker(kFALSE)
46f589c2 69 {
70 /*
71 * Dummy constructor, initialising the values with default (NULL) values
72 */
73 }
74
75 //______________________________________________________________________________
76 AliAnalysisTaskPtEMCalTrigger::AliAnalysisTaskPtEMCalTrigger(const char *name):
cdc26d91 77 AliAnalysisTaskEmcal(name, kTRUE),
46f589c2 78 fHistos(NULL),
4c61ea4f 79 fListTrackCuts(NULL),
80 fEtaRange(),
710e1b95 81 fPtRange(),
5bdebc68 82 fSwapEta(kFALSE),
cdc26d91 83 fUseTriggersFromTriggerMaker(kFALSE)
46f589c2 84 {
85 /*
86 * Main constructor, setting default values for eta and zvertex cut
87 */
46f589c2 88
89 fListTrackCuts = new TList;
90 fListTrackCuts->SetOwner(false);
91
92 // Set default cuts
93 fEtaRange.SetLimits(-0.8, 0.8);
bf9501c1 94 fPtRange.SetLimits(0.15, 100.);
cdc26d91 95 SetMakeGeneralHistograms(kTRUE);
46f589c2 96 }
97
98 //______________________________________________________________________________
99 AliAnalysisTaskPtEMCalTrigger::~AliAnalysisTaskPtEMCalTrigger(){
100 /*
101 * Destructor, deleting output
102 */
103 //if(fTrackSelection) delete fTrackSelection;
104 if(fHistos) delete fHistos;
105 if(fListTrackCuts) delete fListTrackCuts;
106 }
107
108 //______________________________________________________________________________
109 void AliAnalysisTaskPtEMCalTrigger::UserCreateOutputObjects(){
110 /*
111 * Create the list of output objects and define the histograms.
112 * Also adding the track cuts to the list of histograms.
113 */
cdc26d91 114 AliAnalysisTaskEmcal::UserCreateOutputObjects();
115 TString trackContainerName = "ESDFilterTracks", clusterContainerName = "EmcCaloClusters";
116 if(!fIsEsd){
117 trackContainerName = "AODFilterTracks";
118 clusterContainerName = "EmcCaloClusters";
119 }
120 AliParticleContainer *trackContainer = this->AddParticleContainer(trackContainerName.Data());
121 trackContainer->SetClassName("AliVTrack");
122 this->AddClusterContainer(clusterContainerName.Data());
46f589c2 123 fHistos = new AliEMCalHistoContainer("PtEMCalTriggerHistograms");
124 fHistos->ReleaseOwner();
125
126 std::map<std::string, std::string> triggerCombinations;
bf1cb6ad 127 const char *triggernames[12] = {"MinBias", "EMCJHigh", "EMCJLow", "EMCGHigh", "EMCGLow", "NoEMCal", "EMCHighBoth", "EMCHighGammaOnly", "EMCHighJetOnly", "EMCLowBoth", "EMCLowGammaOnly", "EMCLowJetOnly"},
f9e83256 128 *bitnames[4] = {"CINT7", "EMC7", "kEMCEGA", "kEMCEJE"};
46f589c2 129 // Define axes for the trigger correlation histogram
130 const TAxis *triggeraxis[5]; memset(triggeraxis, 0, sizeof(const TAxis *) * 5);
f9e83256 131 const TAxis *bitaxes[4]; memset(bitaxes, 0, sizeof(TAxis *) * 4);
46f589c2 132 const char *binlabels[2] = {"OFF", "ON"};
f9e83256 133 TAxis mytrgaxis[5], mybitaxis[4];
46f589c2 134 for(int itrg = 0; itrg < 5; ++itrg){
135 DefineAxis(mytrgaxis[itrg], triggernames[itrg], triggernames[itrg], 2, -0.5, 1.5, binlabels);
136 triggeraxis[itrg] = mytrgaxis+itrg;
f9e83256 137 if(itrg < 4){
138 DefineAxis(mybitaxis[itrg], bitnames[itrg], bitnames[itrg], 2, -0.5, 1.5, binlabels);
139 bitaxes[itrg] = mybitaxis+itrg;
140 }
46f589c2 141 }
142 // Define names and titles for different triggers in the histogram container
143 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[0], "min. bias events"));
144 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[1], "jet-triggered events (high threshold)"));
145 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[2], "jet-triggered events (low threshold)"));
f9e83256 146 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[3], "gamma-triggered events (high threshold)"));
147 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[4], "gamma-triggered events (low threshold)"));
bf1cb6ad 148 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[5], "non-EMCal-triggered events"));
149 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[6], "jet and gamma triggered events (high threshold)"));
150 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[7], "exclusively gamma-triggered events (high threshold)"));
151 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[8], "exclusively jet-triggered events (high threshold)"));
152 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[9], "jet and gamma triggered events (low threshold)"));
153 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[10], "exclusively gamma-triggered events (low threshold)"));
154 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[11], "exclusively-triggered events (low threshold)"));
46f589c2 155 // Define axes for the pt histogram
156 // Dimensions:
157 // 1. pt
158 // 2. eta
159 // 3. phi
160 // 4. vertex
161 // 5. pileup (0 = all events, 1 = after pileup rejection)
162 // 6. track cuts (0 = no cuts; 1 = after std cuts)
163 TArrayD ptbinning, zvertexBinning, etabinning, pileupaxis(3);
164 pileupaxis[0] = -0.5; pileupaxis[1] = 0.5; pileupaxis[2] = 1.5;
165 CreateDefaultPtBinning(ptbinning);
166 CreateDefaultZVertexBinning(zvertexBinning);
167 CreateDefaultEtaBinning(etabinning);
8738a2f4 168 TAxis htrackaxes[7];
46f589c2 169 DefineAxis(htrackaxes[0], "pt", "p_{t} (GeV/c)", ptbinning);
170 DefineAxis(htrackaxes[1], "eta", "#eta", etabinning);
eed93770 171 DefineAxis(htrackaxes[2], "phi", "#phi", 20, 0, 2 * TMath::Pi());
46f589c2 172 DefineAxis(htrackaxes[3], "zvertex", "z_{V} (cm)", zvertexBinning);
173 DefineAxis(htrackaxes[4], "pileup", "Pileup rejection", 2, -0.5, 1.5);
174 DefineAxis(htrackaxes[5], "trackcuts", "Track Cuts", (fListTrackCuts ? fListTrackCuts->GetEntries() : 0) + 1, -0.5, (fListTrackCuts ? fListTrackCuts->GetEntries() : 0) + 0.5);
8738a2f4 175 DefineAxis(htrackaxes[6], "mbtrigger", "Has MB trigger", 2, -0.5, 1.5);
176 const TAxis *trackaxes[7];
177 for(int iaxis = 0; iaxis < 7; ++iaxis) trackaxes[iaxis] = htrackaxes + iaxis;
178 TAxis hclusteraxes[4];
bf1cb6ad 179 DefineAxis(hclusteraxes[0], "energy", "E (GeV)", ptbinning);
180 DefineAxis(hclusteraxes[1], "zvertex", "z_{V} (cm)", zvertexBinning);
181 DefineAxis(hclusteraxes[2], "pileup", "Pileup rejection", 2, -0.5, 1.5);
8738a2f4 182 DefineAxis(hclusteraxes[3], "mbtrigger", "Has MB trigger", 2, -0.5, 1.5);
183 const TAxis *clusteraxes[4];
184 for(int iaxis = 0; iaxis < 4; ++iaxis) clusteraxes[iaxis] = hclusteraxes + iaxis;
46f589c2 185 try{
cdc26d91 186 // Create histogram for MC-truth
187 fHistos->CreateTHnSparse("hMCtrueParticles", "Particle-based histogram for MC-true particles", 3, trackaxes);
46f589c2 188 for(std::map<std::string,std::string>::iterator it = triggerCombinations.begin(); it != triggerCombinations.end(); ++it){
189 const std::string name = it->first, &title = it->second;
190 // Create event-based histogram
191 fHistos->CreateTH2(Form("hEventHist%s", name.c_str()), Form("Event-based data for %s events; pileup rejection; z_{V} (cm)", title.c_str()), pileupaxis, zvertexBinning);
192 // Create track-based histogram
8738a2f4 193 fHistos->CreateTHnSparse(Form("hTrackHist%s", name.c_str()), Form("Track-based data for %s events", title.c_str()), 7, trackaxes);
194 fHistos->CreateTHnSparse(Form("hTrackInAcceptanceHist%s", name.c_str()), Form("Track-based data for %s events", title.c_str()), 7, trackaxes);
195 fHistos->CreateTHnSparse(Form("hMCTrackHist%s", name.c_str()), Form("Track-based data for %s events with MC kinematics", title.c_str()), 7, trackaxes);
196 fHistos->CreateTHnSparse(Form("hMCTrackInAcceptanceHist%s", name.c_str()), Form("Track-based data for %s events with MC kinematics", title.c_str()), 7, trackaxes);
bf1cb6ad 197 // Create cluster-based histogram (Uncalibrated and calibrated clusters)
8738a2f4 198 fHistos->CreateTHnSparse(Form("hClusterCalibHist%s", name.c_str()), Form("Calib. cluster-based histogram for %s events", title.c_str()), 4, clusteraxes);
199 fHistos->CreateTHnSparse(Form("hClusterUncalibHist%s", name.c_str()), Form("Uncalib. cluster-based histogram for %s events", title.c_str()), 4, clusteraxes);
46f589c2 200 }
201 fHistos->CreateTHnSparse("hEventTriggers", "Trigger type per event", 5, triggeraxis);
f9e83256 202 fHistos->CreateTHnSparse("hEventsTriggerbit", "Trigger bits for the different events", 4, bitaxes);
46f589c2 203 } catch (HistoContainerContentException &e){
204 std::stringstream errormessage;
205 errormessage << "Creation of histogram failed: " << e.what();
206 AliError(errormessage.str().c_str());
207 }
cdc26d91 208 fOutput->Add(fHistos->GetListOfHistograms());
46f589c2 209 if(fListTrackCuts && fListTrackCuts->GetEntries()){
210 TIter cutIter(fListTrackCuts);
cdc26d91 211 AliEMCalPtTaskVTrackSelection *cutObject(NULL);
212 while((cutObject = dynamic_cast<AliEMCalPtTaskVTrackSelection *>(cutIter()))){
213 AliESDtrackCuts *cuts = dynamic_cast<AliESDtrackCuts *>(cutObject->GetTrackCuts());
214 if(cuts){
215 cuts->DefineHistograms();
216 fOutput->Add(cuts);
217 }
46f589c2 218 }
219 }
cdc26d91 220 PostData(1, fOutput);
46f589c2 221 }
222
223 //______________________________________________________________________________
cdc26d91 224 Bool_t AliAnalysisTaskPtEMCalTrigger::Run(){
46f589c2 225 /*
226 * Runs the event loop
227 *
228 * @param option: Additional options
229 */
46f589c2 230 // Common checks: Have SPD vertex and primary vertex from tracks, and both need to have at least one contributor
cdc26d91 231 AliDebug(1,Form("Number of calibrated clusters: %d", fCaloClusters->GetEntries()));
232 AliDebug(1,Form("Number of matched tracks: %d", fTracks->GetEntries()));
233
cdc26d91 234 if(fMCEvent){
235 for(int ipart = 0; ipart < fMCEvent->GetNumberOfTracks(); ipart++){
236 // Select only physical primary particles
61e747d3 237 AliVParticle *part = fMCEvent->GetTrack(ipart);
238 if(!fEtaRange.IsInRange(part->Eta())) continue;
239 if(!fPtRange.IsInRange(part->Pt())) continue;
cdc26d91 240 if(!fMCEvent->IsPhysicalPrimary(ipart)) continue;
61e747d3 241 FillMCParticleHist(part);
cdc26d91 242 }
243 // Build always trigger strig from the trigger maker in case of MC
244 fUseTriggersFromTriggerMaker = kTRUE;
245 }
5bdebc68 246
cdc26d91 247 const AliVVertex *vtxTracks = fInputEvent->GetPrimaryVertex(),
248 *vtxSPD = GetSPDVertex();
249 if(!(vtxTracks && vtxSPD)) return false;
250 if(vtxTracks->GetNContributors() < 1 || vtxSPD->GetNContributors() < 1) return false;
46f589c2 251
f9e83256 252 double triggers[5]; memset(triggers, 0, sizeof(double) * 5);
253 double triggerbits[4]; memset(triggerbits, 0, sizeof(double) * 4);
254 if(fInputHandler->IsEventSelected() & AliVEvent::kINT7){
46f589c2 255 triggers[0] = 1.;
f9e83256 256 triggerbits[0] = 1.;
257 }
46f589c2 258
f9e83256 259 // check triggerbits
46f589c2 260 if(fInputHandler->IsEventSelected() & AliVEvent::kEMC7){
f9e83256 261 triggerbits[1] = 1.;
262 }
263 if(fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA){
264 triggerbits[2] = 1.;
265 }
266 if(fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE){
267 triggerbits[3] = 1.;
46f589c2 268 }
f9e83256 269 try{
270 fHistos->FillTHnSparse("hEventsTriggerbit", triggerbits);
271 } catch(HistoContainerContentException &e) {
272 std::stringstream errormessage;
273 errormessage << "Filling of histogram failed: " << e.what();
274 AliError(errormessage.str().c_str());
275 }
276
277 std::vector<std::string> triggerstrings;
278 // EMCal-triggered event, distinguish types
cdc26d91 279 TString trgstr(fUseTriggersFromTriggerMaker ? BuildTriggerString() : fInputEvent->GetFiredTriggerClasses());
280 AliDebug(1, Form("Triggerstring: %s\n", trgstr.Data()));
f9e83256 281 if(trgstr.Contains("EJ1")){
282 triggerstrings.push_back("EMCJHigh");
283 triggers[1] = 1;
bf1cb6ad 284 if(trgstr.Contains("EG1"))
285 triggerstrings.push_back("EMCHighBoth");
286 else
287 triggerstrings.push_back("EMCHighJetOnly");
f9e83256 288 }
289 if(trgstr.Contains("EJ2")){
290 triggerstrings.push_back("EMCJLow");
291 triggers[2] = 1;
bf1cb6ad 292 if(trgstr.Contains("EG2"))
293 triggerstrings.push_back("EMCLowBoth");
294 else
295 triggerstrings.push_back("EMCLowJetOnly");
f9e83256 296 }
297 if(trgstr.Contains("EG1")){
298 triggerstrings.push_back("EMCGHigh");
299 triggers[3] = 1;
bf1cb6ad 300 if(!trgstr.Contains("EJ1"))
301 triggerstrings.push_back("EMCHighGammaOnly");
f9e83256 302 }
303 if(trgstr.Contains("EG2")){
304 triggerstrings.push_back("EMCGLow");
305 triggers[4] = 1;
bf1cb6ad 306 if(!trgstr.Contains("EJ2"))
307 triggerstrings.push_back("EMCLowGammaOnly");
f9e83256 308 }
309
46f589c2 310 try{
311 fHistos->FillTHnSparse("hEventTriggers", triggers);
312 } catch (HistoContainerContentException &e){
313 std::stringstream errormessage;
314 errormessage << "Filling of histogram failed: " << e.what();
315 AliError(errormessage.str().c_str());
316 }
317
318 // apply event selection: Combine the Pileup cut from SPD with the other pA Vertex selection cuts.
cdc26d91 319 bool isPileupEvent = fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.);
46f589c2 320 isPileupEvent = isPileupEvent || (TMath::Abs(vtxTracks->GetZ() - vtxSPD->GetZ()) > 0.5);
321 double covSPD[6]; vtxSPD->GetCovarianceMatrix(covSPD);
322 isPileupEvent = isPileupEvent || (TString(vtxSPD->GetTitle()).Contains("vertexer:Z") && TMath::Sqrt(covSPD[5]) > 0.25);
323
324 // Fill event-based histogram
325 const double &zv = vtxTracks->GetZ();
326 if(triggers[0]) FillEventHist("MinBias", zv, isPileupEvent);
327 if(!triggerstrings.size()) // Non-EMCal-triggered
328 FillEventHist("NoEMCal", zv, isPileupEvent);
329 else{
330 // EMCal-triggered events
331 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it)
332 FillEventHist(it->c_str(), zv, isPileupEvent);
333 }
334
cdc26d91 335 AliVTrack *track(NULL);
46f589c2 336 // Loop over all tracks (No cuts applied)
cdc26d91 337 TIter allTrackIter(fTracks);
338 while((track = dynamic_cast<AliVTrack *>(allTrackIter()))){
339 if(!IsTrueTrack(track)) continue;
bf9501c1 340 if(!fEtaRange.IsInRange(track->Eta())) continue;
341 if(!fPtRange.IsInRange(track->Pt())) continue;
8738a2f4 342 if(triggers[0]) FillTrackHist("MinBias", track, zv, isPileupEvent, 0, triggers[0]);
46f589c2 343 if(!triggerstrings.size()) // Non-EMCal-triggered
8738a2f4 344 FillTrackHist("NoEMCal", track, zv, isPileupEvent, 0, triggers[0]);
46f589c2 345 else {
346 // EMCal-triggered events
347 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it)
8738a2f4 348 FillTrackHist(it->c_str(), track, zv, isPileupEvent, 0, triggers[0]);
46f589c2 349 }
350 }
351
352 // Now apply track selection cuts
353 // allow for several track selections to be tested at the same time
354 // each track selection gets a different cut ID starting from 1
355 // cut ID 0 is reserved for the case of no cuts
356 if(fListTrackCuts && fListTrackCuts->GetEntries()){
357 for(int icut = 0; icut < fListTrackCuts->GetEntries(); icut++){
cdc26d91 358 AliEMCalPtTaskVTrackSelection *trackSelection = static_cast<AliEMCalPtTaskVTrackSelection *>(fListTrackCuts->At(icut));
359 TIter trackIter(trackSelection->GetAcceptedTracks(fTracks));
360 while((track = dynamic_cast<AliVTrack *>(trackIter()))){
361 //if(!IsTrueTrack(track)) continue;
46f589c2 362 if(!fEtaRange.IsInRange(track->Eta())) continue;
bf9501c1 363 if(!fPtRange.IsInRange(track->Pt())) continue;
8738a2f4 364 if(triggers[0]) FillTrackHist("MinBias", track, zv, isPileupEvent, icut + 1, triggers[0]);
46f589c2 365 if(!triggerstrings.size()) // Non-EMCal-triggered
8738a2f4 366 FillTrackHist("NoEMCal", track, zv, isPileupEvent, icut + 1, triggers[0]);
46f589c2 367 else {
368 // EMCal-triggered events
369 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it)
8738a2f4 370 FillTrackHist(it->c_str(), track, zv, isPileupEvent, icut + 1, triggers[0]);
46f589c2 371 }
372 }
373 }
374 }
bf1cb6ad 375
376 // Next step we loop over the (uncalibrated) emcal clusters and fill histograms with the cluster energy
cdc26d91 377 const AliVCluster *clust(NULL);
bf1cb6ad 378 for(int icl = 0; icl < fInputEvent->GetNumberOfCaloClusters(); icl++){
cdc26d91 379 clust = fInputEvent->GetCaloCluster(icl);
bf1cb6ad 380 if(!clust->IsEMCAL()) continue;
8738a2f4 381 if(triggers[0]) FillClusterHist("MinBias", clust, false, zv, isPileupEvent, triggers[0]);
bf1cb6ad 382 if(!triggerstrings.size()) // Non-EMCal-triggered
8738a2f4 383 FillClusterHist("NoEMCal", clust, false, zv, isPileupEvent, triggers[0]);
bf1cb6ad 384 else{
385 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it){
8738a2f4 386 FillClusterHist(it->c_str(), clust, false, zv, isPileupEvent, triggers[0]);
bf1cb6ad 387 }
388 }
389 }
390
cdc26d91 391 if(fCaloClusters){
392 TIter clustIter(fCaloClusters);
393 while((clust = dynamic_cast<const AliVCluster *>(clustIter()))){
bf1cb6ad 394 if(!clust->IsEMCAL()) continue;
8738a2f4 395 if(triggers[0]) FillClusterHist("MinBias", clust, true, zv, isPileupEvent, triggers[0]);
bf1cb6ad 396 if(!triggerstrings.size()) // Non-EMCal-triggered
8738a2f4 397 FillClusterHist("NoEMCal", clust, true, zv, isPileupEvent, triggers[0]);
bf1cb6ad 398 else{
399 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it){
8738a2f4 400 FillClusterHist(it->c_str(), clust, true, zv, isPileupEvent, triggers[0]);
bf1cb6ad 401 }
402 }
403 }
404 }
405
cdc26d91 406 PostData(1, fOutput);
407 return true;
46f589c2 408 }
409
410 //______________________________________________________________________________
411 void AliAnalysisTaskPtEMCalTrigger::CreateDefaultPtBinning(TArrayD &binning) const{
412 /*
413 * Creating the default pt binning.
414 *
415 * @param binning: Array where to store the results.
416 */
417 std::vector<double> mybinning;
418 std::map<double,double> definitions;
419 definitions.insert(std::pair<double,double>(2.5, 0.1));
420 definitions.insert(std::pair<double,double>(7., 0.25));
421 definitions.insert(std::pair<double,double>(15., 0.5));
422 definitions.insert(std::pair<double,double>(25., 1.));
423 definitions.insert(std::pair<double,double>(40., 2.5));
424 definitions.insert(std::pair<double,double>(60., 5.));
425 definitions.insert(std::pair<double,double>(100., 5.));
426 double currentval = 0;
427 for(std::map<double,double>::iterator id = definitions.begin(); id != definitions.end(); ++id){
428 double limit = id->first, binwidth = id->second;
429 while(currentval <= limit){
430 currentval += binwidth;
431 mybinning.push_back(currentval);
432 }
433 }
434 binning.Set(mybinning.size());
435 int ib = 0;
436 for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
437 binning[ib++] = *it;
438 }
439
440 //______________________________________________________________________________
441 void AliAnalysisTaskPtEMCalTrigger::CreateDefaultZVertexBinning(TArrayD &binning) const {
442 /*
443 * Creating default z-Vertex binning.
444 *
445 * @param binning: Array where to store the results.
446 */
447 std::vector<double> mybinning;
448 double currentval = -40;
449 mybinning.push_back(currentval);
450 while(currentval <= 40.){
eed93770 451 currentval += 1.;
46f589c2 452 mybinning.push_back(currentval);
453 }
454 binning.Set(mybinning.size());
455 int ib = 0;
456 for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
457 binning[ib++] = *it;
458 }
459
460 //______________________________________________________________________________
461 void AliAnalysisTaskPtEMCalTrigger::CreateDefaultEtaBinning(TArrayD& binning) const {
462 /*
463 * Creating default z-Vertex binning.
464 *
465 * @param binning: Array where to store the results.
466 */
467 std::vector<double> mybinning;
468 double currentval = -0.8;
469 mybinning.push_back(currentval);
470 while(currentval <= 0.8){
eed93770 471 currentval += 0.1;
46f589c2 472 mybinning.push_back(currentval);
473 }
474 binning.Set(mybinning.size());
475 int ib = 0;
476 for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
477 binning[ib++] = *it;
478 }
479
480 //______________________________________________________________________________
481 void AliAnalysisTaskPtEMCalTrigger::DefineAxis(TAxis& axis, const char* name,
482 const char* title, const TArrayD& binning, const char** labels) {
483 /*
484 * Define an axis with a given binning
485 *
486 * @param axis: Axis to be defined
487 * @param name: Name of the axis
488 * @param title: Title of the axis
489 * @param binning: axis binning
490 * @param labels (@optional): array of bin labels
491 */
492 axis.Set(binning.GetSize()-1, binning.GetArray());
493 axis.SetName(name);
494 axis.SetTitle(title);
495 if(labels){
496 for(int ib = 1; ib <= axis.GetNbins(); ++ib)
5da6b0c2 497 axis.SetBinLabel(ib, labels[ib-1]);
46f589c2 498 }
499 }
500
501 //______________________________________________________________________________
502 void AliAnalysisTaskPtEMCalTrigger::DefineAxis(TAxis& axis, const char* name,
503 const char* title, int nbins, double min, double max,
504 const char** labels) {
505 /*
506 * Define an axis with number of bins from min to max
507 *
508 * @param axis: Axis to be defined
509 * @param name: Name of the axis
510 * @param title: Title of the axis
511 * @param nbins: Number of bins
512 * @param min: lower limit of the axis
513 * @param max: upper limit of the axis
514 * @param labels (@optional): array of bin labels
515 */
516 axis.Set(nbins, min, max);
517 axis.SetName(name);
518 axis.SetTitle(title);
519 if(labels){
520 for(int ib = 1; ib <= axis.GetNbins(); ++ib)
5da6b0c2 521 axis.SetBinLabel(ib, labels[ib-1]);
46f589c2 522 }
523 }
524
cdc26d91 525
46f589c2 526 //______________________________________________________________________________
527 void AliAnalysisTaskPtEMCalTrigger::FillEventHist(const char* trigger,
528 double vz, bool isPileup) {
529 /*
530 * Fill event-based histogram
531 *
532 * @param trigger: name of the trigger configuration to be processed
533 * @param vz: z-position of the vertex
534 * @param isPileup: signalises if the event is flagged as pileup event
535 */
536 char histname[1024];
537 sprintf(histname, "hEventHist%s", trigger);
538 try{
60284bec 539 fHistos->FillTH2(histname, 0., vz);
46f589c2 540 } catch (HistoContainerContentException &e){
541 std::stringstream errormessage;
542 errormessage << "Filling of histogram failed: " << e.what();
543 AliError(errormessage.str().c_str());
544 }
545 if(!isPileup){
546 try{
60284bec 547 fHistos->FillTH2(histname, 1., vz);
46f589c2 548 } catch(HistoContainerContentException &e){
549 std::stringstream errormessage;
550 errormessage << "Filling of histogram failed: " << e.what();
551 AliError(errormessage.str().c_str());
552 }
553 }
554 }
555
556 //______________________________________________________________________________
557 void AliAnalysisTaskPtEMCalTrigger::FillTrackHist(const char* trigger,
8738a2f4 558 const AliVTrack* track, double vz, bool isPileup, int cut, bool isMinBias) {
46f589c2 559 /*
560 * Fill track-based histogram with corresponding information
561 *
562 * @param trigger: name of the trigger
563 * @param track: ESD track selected
564 * @param vz: z-position of the vertex
565 * @param isPileup: flag event as pileup event
566 * @param cut: id of the cut (0 = no cut)
567 */
710e1b95 568 double etasign = fSwapEta ? -1. : 1.;
8738a2f4 569 double data[7] = {TMath::Abs(track->Pt()), etasign * track->Eta(), track->Phi(), vz, 0, static_cast<double>(cut), isMinBias ? 1. : 0.};
570 double dataMC[7] = {0., 0., 0., vz, 0, static_cast<double>(cut), isMinBias ? 1. : 0.};
571 AliVParticle *assocMC(NULL);
572 if(fMCEvent && (assocMC = fMCEvent->GetTrack(TMath::Abs(track->GetLabel())))){
573 dataMC[0] = TMath::Abs(assocMC->Pt());
574 dataMC[1] = etasign * assocMC->Eta();
575 dataMC[2] = assocMC->Phi();
576 }
577 char histname[1024], histnameAcc[1024], histnameMC[1024], histnameMCAcc[1024];
46f589c2 578 sprintf(histname, "hTrackHist%s", trigger);
bd1a1d65 579 sprintf(histnameAcc, "hTrackInAcceptanceHist%s", trigger);
8738a2f4 580 sprintf(histnameMC, "hMCTrackHist%s", trigger);
581 sprintf(histnameMCAcc, "hMCTrackInAcceptanceHist%s", trigger);
6f635d65 582 Bool_t isEMCAL = kFALSE;
583 if(track->IsEMCAL()){
584 // Check if the cluster is matched to only one track
5bdebc68 585 AliVCluster *emcclust(NULL);
586 AliDebug(2, Form("cluster id: %d\n", track->GetEMCALcluster()));
cdc26d91 587 if(fCaloClusters) {
5bdebc68 588 AliDebug(2, "Using calibrated clusters");
cdc26d91 589 emcclust = dynamic_cast<AliVCluster *>(fCaloClusters->At(track->GetEMCALcluster()));
5bdebc68 590 } else {
591 AliDebug(2, "Using uncalibrated clusters");
592 emcclust = fInputEvent->GetCaloCluster(track->GetEMCALcluster());
593 }
594 if(!emcclust) AliError("Null pointer to EMCal cluster");
595 if(emcclust && emcclust->GetNTracksMatched() <= 1){
6f635d65 596 isEMCAL = kTRUE;
597 }
598 }
46f589c2 599 try{
600 fHistos->FillTHnSparse(histname, data);
8738a2f4 601 if(fMCEvent) fHistos->FillTHnSparse(histnameMC, dataMC);
6f635d65 602 if(isEMCAL){
bd1a1d65 603 fHistos->FillTHnSparse(histnameAcc, data);
8738a2f4 604 if(fMCEvent) fHistos->FillTHnSparse(histnameMCAcc, dataMC);
bd1a1d65 605 }
46f589c2 606 } catch (HistoContainerContentException &e){
607 std::stringstream errormessage;
608 errormessage << "Filling of histogram failed: " << e.what();
609 AliError(errormessage.str().c_str());
610 }
611 if(!isPileup){
612 data[4] = 1;
8738a2f4 613 dataMC[4] = 1;
46f589c2 614 try{
615 fHistos->FillTHnSparse(histname, data);
8738a2f4 616 if(fMCEvent) fHistos->FillTHnSparse(histnameMC, dataMC);
6f635d65 617 if(isEMCAL){
bd1a1d65 618 fHistos->FillTHnSparse(histnameAcc, data);
8738a2f4 619 if(fMCEvent) fHistos->FillTHnSparse(histnameMCAcc, dataMC);
bd1a1d65 620 }
46f589c2 621 } catch (HistoContainerContentException &e){
622 std::stringstream errormessage;
623 errormessage << "Filling of histogram failed: " << e.what();
624 AliError(errormessage.str().c_str());
625 }
626 }
627 }
628
bf1cb6ad 629 //______________________________________________________________________________
630 void AliAnalysisTaskPtEMCalTrigger::FillClusterHist(const char* trigger,
8738a2f4 631 const AliVCluster* clust, bool isCalibrated, double vz, bool isPileup, bool isMinBias) {
bf1cb6ad 632 /*
633 * Fill cluster-based histogram with corresponding information
634 *
635 * @param trigger: name of the trigger
636 * @param cluster: the EMCal cluster information
637 * @param vz: z-position of the vertex
638 * @param isPileup: flag event as pileup event
639 */
8738a2f4 640 double data[4] = {clust->E(), vz, 0, isMinBias ? 1. : 0.};
bf1cb6ad 641 char histname[1024];
642 sprintf(histname, "hCluster%sHist%s", isCalibrated ? "Calib" : "Uncalib", trigger);
643 try{
644 fHistos->FillTHnSparse(histname, data);
645 } catch (HistoContainerContentException &e){
646 std::stringstream errormessage;
647 errormessage << "Filling of histogram failed: " << e.what();
648 AliError(errormessage.str().c_str());
649 }
650 if(!isPileup){
651 data[2] = 1.;
652 try{
653 fHistos->FillTHnSparse(histname, data);
654 } catch (HistoContainerContentException &e){
655 std::stringstream errormessage;
656 errormessage << "Filling of histogram failed: " << e.what();
657 AliError(errormessage.str().c_str());
658 }
659 }
660 }
46f589c2 661
cdc26d91 662 //______________________________________________________________________________
663 void AliAnalysisTaskPtEMCalTrigger::FillMCParticleHist(const AliVParticle * const track){
664 /*
665 * Fill histogram for MC-true particles with the information pt, eta and phi
666 *
667 * @param track: the Monte-Carlo track
668 */
669 double data[3] = {TMath::Abs(track->Pt()), track->Eta(), track->Phi()};
670 fHistos->FillTHnSparse("hMCtrueParticles", data);
671 }
672
673 //______________________________________________________________________________
674 bool AliAnalysisTaskPtEMCalTrigger::IsTrueTrack(const AliVTrack *const track) const{
675 /*
676 * Check if the track has an associated MC particle, and that the particle is a physical primary
677 * In case of data we do not do the selection at that step (always return true)
678 *
679 * @param track: Track to check
680 * @result: true primary track (true or false)
681 */
682 if(!fMCEvent) return true;
683 AliVParticle *mcassociate = fMCEvent->GetTrack(TMath::Abs(track->GetLabel()));
684 if(!mcassociate) return false;
685 return fMCEvent->IsPhysicalPrimary(TMath::Abs(track->GetLabel()));
686 }
687
688 //______________________________________________________________________________
689 void AliAnalysisTaskPtEMCalTrigger::AddESDTrackCuts(AliESDtrackCuts* trackCuts) {
690 /*
691 * Add new track cuts to the task
692 *
693 * @param trackCuts: Object of type AliESDtrackCuts
694 */
695 fListTrackCuts->AddLast(new AliEMCalPtTaskTrackSelectionESD(trackCuts));
696 }
697
009a14cb 698 //______________________________________________________________________________
699 void AliAnalysisTaskPtEMCalTrigger::AddCutsForAOD(AliESDtrackCuts* trackCuts, UInt_t filterbits) {
700 /*
701 * Add new track cuts to the task
702 *
703 * @param trackCuts: Object of type AliESDtrackCuts
704 */
705 fListTrackCuts->AddLast(new AliEMCalPtTaskTrackSelectionAOD(trackCuts, filterbits));
706 }
707
708
cdc26d91 709 //______________________________________________________________________________
710 TString AliAnalysisTaskPtEMCalTrigger::BuildTriggerString() {
711 /*
712 * Build trigger string from the trigger maker
713 *
714 * @return: blank-separated string of fired trigger classes
715 */
716 AliDebug(1, "trigger checking");
717 TString result = "";
718 if(HasTriggerType(kJ1)) result += "EJ1 ";
719 if(HasTriggerType(kJ2)) result += "EJ2 ";
720 if(HasTriggerType(kG1)) result += "EG1 ";
721 if(HasTriggerType(kG2)) result += "EG2 ";
722 return result;
723 }
724
725 //______________________________________________________________________________
726 const AliVVertex* AliAnalysisTaskPtEMCalTrigger::GetSPDVertex() const {
727 /*
728 * Accessor for the SPD vertex, creating transparency for ESDs and AODs
729 *
730 * @return: the spd vertex
731 */
732 AliESDEvent *esd = dynamic_cast<AliESDEvent *>(fInputEvent);
733 if(esd){
734 return esd->GetPrimaryVertexSPD();
735 } else {
736 AliAODEvent *aod = dynamic_cast<AliAODEvent *>(fInputEvent);
737 if(aod){
738 return aod->GetPrimaryVertexSPD();
739 }
5bdebc68 740 }
cdc26d91 741 return NULL;
5bdebc68 742 }
cdc26d91 743
bf1cb6ad 744}
5bdebc68 745