1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 * Analysis task of the pt analysis on EMCal-triggered events
19 * Author: Markus Fasel
30 #include <TDirectory.h>
32 #include <THashList.h>
36 #include <TObjArray.h>
39 #include "AliESDEvent.h"
40 #include "AliESDInputHandler.h"
41 #include "AliESDtrack.h"
42 #include "AliESDVertex.h"
44 #include "AliEMCalHistoContainer.h"
45 #include "AliAnalysisTaskPtEMCalTrigger.h"
47 ClassImp(EMCalTriggerPtAnalysis::AliAnalysisTaskPtEMCalTrigger)
49 namespace EMCalTriggerPtAnalysis {
51 //______________________________________________________________________________
52 AliAnalysisTaskPtEMCalTrigger::AliAnalysisTaskPtEMCalTrigger():
59 * Dummy constructor, initialising the values with default (NULL) values
63 //______________________________________________________________________________
64 AliAnalysisTaskPtEMCalTrigger::AliAnalysisTaskPtEMCalTrigger(const char *name):
65 AliAnalysisTaskSE(name),
71 * Main constructor, setting default values for eta and zvertex cut
73 DefineOutput(1, TList::Class());
75 fListTrackCuts = new TList;
76 fListTrackCuts->SetOwner(false);
79 fEtaRange.SetLimits(-0.8, 0.8);
83 //______________________________________________________________________________
84 AliAnalysisTaskPtEMCalTrigger::~AliAnalysisTaskPtEMCalTrigger(){
86 * Destructor, deleting output
88 //if(fTrackSelection) delete fTrackSelection;
89 if(fHistos) delete fHistos;
90 if(fListTrackCuts) delete fListTrackCuts;
93 //______________________________________________________________________________
94 void AliAnalysisTaskPtEMCalTrigger::UserCreateOutputObjects(){
96 * Create the list of output objects and define the histograms.
97 * Also adding the track cuts to the list of histograms.
100 fResults->SetOwner();
102 fHistos = new AliEMCalHistoContainer("PtEMCalTriggerHistograms");
103 fHistos->ReleaseOwner();
105 std::map<std::string, std::string> triggerCombinations;
106 const char *triggernames[6] = {"MinBias", "EMCJHigh", "EMCJLow", "EMCGHigh", "EMCGLow", "NoEMCal"};
107 // Define axes for the trigger correlation histogram
108 const TAxis *triggeraxis[5]; memset(triggeraxis, 0, sizeof(const TAxis *) * 5);
109 const char *binlabels[2] = {"OFF", "ON"};
111 for(int itrg = 0; itrg < 5; ++itrg){
112 DefineAxis(mytrgaxis[itrg], triggernames[itrg], triggernames[itrg], 2, -0.5, 1.5, binlabels);
113 triggeraxis[itrg] = mytrgaxis+itrg;
115 // Define names and titles for different triggers in the histogram container
116 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[0], "min. bias events"));
117 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[1], "jet-triggered events (high threshold)"));
118 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[2], "jet-triggered events (low threshold)"));
119 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[3], "jet-triggered events (high threshold)"));
120 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[4], "jet-triggered events (low threshold)"));
121 triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[5], "non-EMCal-triggered events (low threshold)"));
122 // Define axes for the pt histogram
128 // 5. pileup (0 = all events, 1 = after pileup rejection)
129 // 6. track cuts (0 = no cuts; 1 = after std cuts)
130 TArrayD ptbinning, zvertexBinning, etabinning, pileupaxis(3);
131 pileupaxis[0] = -0.5; pileupaxis[1] = 0.5; pileupaxis[2] = 1.5;
132 CreateDefaultPtBinning(ptbinning);
133 CreateDefaultZVertexBinning(zvertexBinning);
134 CreateDefaultEtaBinning(etabinning);
136 DefineAxis(htrackaxes[0], "pt", "p_{t} (GeV/c)", ptbinning);
137 DefineAxis(htrackaxes[1], "eta", "#eta", etabinning);
138 DefineAxis(htrackaxes[2], "phi", "#phi", 20, 0, 2 * TMath::Pi());
139 DefineAxis(htrackaxes[3], "zvertex", "z_{V} (cm)", zvertexBinning);
140 DefineAxis(htrackaxes[4], "pileup", "Pileup rejection", 2, -0.5, 1.5);
141 DefineAxis(htrackaxes[5], "trackcuts", "Track Cuts", (fListTrackCuts ? fListTrackCuts->GetEntries() : 0) + 1, -0.5, (fListTrackCuts ? fListTrackCuts->GetEntries() : 0) + 0.5);
142 const TAxis *trackaxes[6];
143 for(int iaxis = 0; iaxis < 6; ++iaxis) trackaxes[iaxis] = htrackaxes + iaxis;
145 for(std::map<std::string,std::string>::iterator it = triggerCombinations.begin(); it != triggerCombinations.end(); ++it){
146 const std::string name = it->first, &title = it->second;
147 // Create event-based histogram
148 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);
149 // Create track-based histogram
150 fHistos->CreateTHnSparse(Form("hTrackHist%s", name.c_str()), Form("Track-based data for %s events", title.c_str()), 6, trackaxes);
152 fHistos->CreateTHnSparse("hEventTriggers", "Trigger type per event", 5, triggeraxis);
153 } catch (HistoContainerContentException &e){
154 std::stringstream errormessage;
155 errormessage << "Creation of histogram failed: " << e.what();
156 AliError(errormessage.str().c_str());
158 fResults->Add(fHistos->GetListOfHistograms());
159 if(fListTrackCuts && fListTrackCuts->GetEntries()){
160 TIter cutIter(fListTrackCuts);
161 AliESDtrackCuts *cutObject(NULL);
162 while((cutObject = dynamic_cast<AliESDtrackCuts *>(cutIter()))){
163 cutObject->DefineHistograms();
164 fResults->Add(cutObject);
167 PostData(1, fResults);
170 //______________________________________________________________________________
171 void AliAnalysisTaskPtEMCalTrigger::UserExec(Option_t* /*option*/){
173 * Runs the event loop
175 * @param option: Additional options
178 // Common checks: Have SPD vertex and primary vertex from tracks, and both need to have at least one contributor
179 AliESDEvent *esd = static_cast<AliESDEvent *>(fInputEvent);
180 const AliESDVertex *vtxTracks = esd->GetPrimaryVertex(),
181 *vtxSPD = esd->GetPrimaryVertexSPD();
182 if(!(vtxTracks && vtxSPD)) return;
183 if(vtxTracks->GetNContributors() < 1 || vtxSPD->GetNContributors() < 1) return;
185 double triggers[5]; memset(triggers, 0, sizeof(double) *5);
186 if(fInputHandler->IsEventSelected() & AliVEvent::kINT7)
189 std::vector<std::string> triggerstrings;
190 if(fInputHandler->IsEventSelected() & AliVEvent::kEMC7){
191 // EMCal-triggered event, distinguish types
192 TString trgstr(fInputEvent->GetFiredTriggerClasses());
193 if(trgstr.Contains("EJ1")){
194 triggerstrings.push_back("EMCJHigh");
197 if(trgstr.Contains("EJ2")){
198 triggerstrings.push_back("EMCJLow");
201 if(trgstr.Contains("EG1")){
202 triggerstrings.push_back("EMCGHigh");
205 if(trgstr.Contains("EG2")){
206 triggerstrings.push_back("EMCGLow");
211 fHistos->FillTHnSparse("hEventTriggers", triggers);
212 } catch (HistoContainerContentException &e){
213 std::stringstream errormessage;
214 errormessage << "Filling of histogram failed: " << e.what();
215 AliError(errormessage.str().c_str());
218 // apply event selection: Combine the Pileup cut from SPD with the other pA Vertex selection cuts.
219 bool isPileupEvent = esd->IsPileupFromSPD();
220 isPileupEvent = isPileupEvent || (TMath::Abs(vtxTracks->GetZ() - vtxSPD->GetZ()) > 0.5);
221 double covSPD[6]; vtxSPD->GetCovarianceMatrix(covSPD);
222 isPileupEvent = isPileupEvent || (TString(vtxSPD->GetTitle()).Contains("vertexer:Z") && TMath::Sqrt(covSPD[5]) > 0.25);
224 // Fill event-based histogram
225 const double &zv = vtxTracks->GetZ();
226 if(triggers[0]) FillEventHist("MinBias", zv, isPileupEvent);
227 if(!triggerstrings.size()) // Non-EMCal-triggered
228 FillEventHist("NoEMCal", zv, isPileupEvent);
230 // EMCal-triggered events
231 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it)
232 FillEventHist(it->c_str(), zv, isPileupEvent);
235 AliESDtrack *track(NULL);
236 // Loop over all tracks (No cuts applied)
237 for(int itrk = 0; itrk < fInputEvent->GetNumberOfTracks(); ++itrk){
238 track = dynamic_cast<AliESDtrack *>(fInputEvent->GetTrack(itrk));
239 // first fill without pielup cut
240 if(fEtaRange.IsInRange(track->Eta())) continue;
241 if(triggers[0]) FillTrackHist("MinBias", track, zv, isPileupEvent, 0);
242 if(!triggerstrings.size()) // Non-EMCal-triggered
243 FillTrackHist("NoEMCal", track, zv, isPileupEvent, 0);
245 // EMCal-triggered events
246 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it)
247 FillTrackHist(it->c_str(), track, zv, isPileupEvent, 0);
251 // Now apply track selection cuts
252 // allow for several track selections to be tested at the same time
253 // each track selection gets a different cut ID starting from 1
254 // cut ID 0 is reserved for the case of no cuts
255 if(fListTrackCuts && fListTrackCuts->GetEntries()){
256 for(int icut = 0; icut < fListTrackCuts->GetEntries(); icut++){
257 AliESDtrackCuts *trackSelection = static_cast<AliESDtrackCuts *>(fListTrackCuts->At(icut));
258 std::auto_ptr<TObjArray> acceptedTracks(trackSelection->GetAcceptedTracks(esd));
259 TIter trackIter(acceptedTracks.get());
260 while((track = dynamic_cast<AliESDtrack *>(trackIter()))){
261 if(!fEtaRange.IsInRange(track->Eta())) continue;
262 if(triggers[0]) FillTrackHist("MinBias", track, zv, isPileupEvent, icut + 1);
263 if(!triggerstrings.size()) // Non-EMCal-triggered
264 FillTrackHist("NoEMCal", track, zv, isPileupEvent, icut + 1);
266 // EMCal-triggered events
267 for(std::vector<std::string>::iterator it = triggerstrings.begin(); it != triggerstrings.end(); ++it)
268 FillTrackHist(it->c_str(), track, zv, isPileupEvent, icut + 1);
273 PostData(1, fResults);
276 //______________________________________________________________________________
277 void AliAnalysisTaskPtEMCalTrigger::CreateDefaultPtBinning(TArrayD &binning) const{
279 * Creating the default pt binning.
281 * @param binning: Array where to store the results.
283 std::vector<double> mybinning;
284 std::map<double,double> definitions;
285 definitions.insert(std::pair<double,double>(2.5, 0.1));
286 definitions.insert(std::pair<double,double>(7., 0.25));
287 definitions.insert(std::pair<double,double>(15., 0.5));
288 definitions.insert(std::pair<double,double>(25., 1.));
289 definitions.insert(std::pair<double,double>(40., 2.5));
290 definitions.insert(std::pair<double,double>(60., 5.));
291 definitions.insert(std::pair<double,double>(100., 5.));
292 double currentval = 0;
293 for(std::map<double,double>::iterator id = definitions.begin(); id != definitions.end(); ++id){
294 double limit = id->first, binwidth = id->second;
295 while(currentval <= limit){
296 currentval += binwidth;
297 mybinning.push_back(currentval);
300 binning.Set(mybinning.size());
302 for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
306 //______________________________________________________________________________
307 void AliAnalysisTaskPtEMCalTrigger::CreateDefaultZVertexBinning(TArrayD &binning) const {
309 * Creating default z-Vertex binning.
311 * @param binning: Array where to store the results.
313 std::vector<double> mybinning;
314 double currentval = -40;
315 mybinning.push_back(currentval);
316 while(currentval <= 40.){
318 mybinning.push_back(currentval);
320 binning.Set(mybinning.size());
322 for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
326 //______________________________________________________________________________
327 void AliAnalysisTaskPtEMCalTrigger::CreateDefaultEtaBinning(TArrayD& binning) const {
329 * Creating default z-Vertex binning.
331 * @param binning: Array where to store the results.
333 std::vector<double> mybinning;
334 double currentval = -0.8;
335 mybinning.push_back(currentval);
336 while(currentval <= 0.8){
338 mybinning.push_back(currentval);
340 binning.Set(mybinning.size());
342 for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
346 //______________________________________________________________________________
347 void AliAnalysisTaskPtEMCalTrigger::DefineAxis(TAxis& axis, const char* name,
348 const char* title, const TArrayD& binning, const char** labels) {
350 * Define an axis with a given binning
352 * @param axis: Axis to be defined
353 * @param name: Name of the axis
354 * @param title: Title of the axis
355 * @param binning: axis binning
356 * @param labels (@optional): array of bin labels
358 axis.Set(binning.GetSize()-1, binning.GetArray());
360 axis.SetTitle(title);
362 for(int ib = 1; ib <= axis.GetNbins(); ++ib)
363 axis.SetBinLabel(ib, labels[ib]);
367 //______________________________________________________________________________
368 void AliAnalysisTaskPtEMCalTrigger::DefineAxis(TAxis& axis, const char* name,
369 const char* title, int nbins, double min, double max,
370 const char** labels) {
372 * Define an axis with number of bins from min to max
374 * @param axis: Axis to be defined
375 * @param name: Name of the axis
376 * @param title: Title of the axis
377 * @param nbins: Number of bins
378 * @param min: lower limit of the axis
379 * @param max: upper limit of the axis
380 * @param labels (@optional): array of bin labels
382 axis.Set(nbins, min, max);
384 axis.SetTitle(title);
386 for(int ib = 1; ib <= axis.GetNbins(); ++ib)
387 axis.SetBinLabel(ib, labels[ib]);
391 //______________________________________________________________________________
392 void AliAnalysisTaskPtEMCalTrigger::FillEventHist(const char* trigger,
393 double vz, bool isPileup) {
395 * Fill event-based histogram
397 * @param trigger: name of the trigger configuration to be processed
398 * @param vz: z-position of the vertex
399 * @param isPileup: signalises if the event is flagged as pileup event
402 sprintf(histname, "hEventHist%s", trigger);
404 fHistos->FillTH2(histname, vz, 0);
405 } catch (HistoContainerContentException &e){
406 std::stringstream errormessage;
407 errormessage << "Filling of histogram failed: " << e.what();
408 AliError(errormessage.str().c_str());
412 fHistos->FillTH2(histname, vz, 1);
413 } catch(HistoContainerContentException &e){
414 std::stringstream errormessage;
415 errormessage << "Filling of histogram failed: " << e.what();
416 AliError(errormessage.str().c_str());
421 //______________________________________________________________________________
422 void AliAnalysisTaskPtEMCalTrigger::FillTrackHist(const char* trigger,
423 const AliESDtrack* track, double vz, bool isPileup, int cut) {
425 * Fill track-based histogram with corresponding information
427 * @param trigger: name of the trigger
428 * @param track: ESD track selected
429 * @param vz: z-position of the vertex
430 * @param isPileup: flag event as pileup event
431 * @param cut: id of the cut (0 = no cut)
433 double data[6] = {track->Pt(), track->Eta(), track->Phi(), vz, 0, cut};
435 sprintf(histname, "hTrackHist%s", trigger);
437 fHistos->FillTHnSparse(histname, data);
438 } catch (HistoContainerContentException &e){
439 std::stringstream errormessage;
440 errormessage << "Filling of histogram failed: " << e.what();
441 AliError(errormessage.str().c_str());
446 fHistos->FillTHnSparse(histname, data);
447 } catch (HistoContainerContentException &e){
448 std::stringstream errormessage;
449 errormessage << "Filling of histogram failed: " << e.what();
450 AliError(errormessage.str().c_str());