AliPhysics  master (3d17d9d)
AliAnalysisTaskEmcalEmbeddingHelperData.cxx
Go to the documentation of this file.
1 #include <vector>
2 
5 #include "AliAODEvent.h"
6 #include "AliESDEvent.h"
7 #include "AliVAODHeader.h"
8 #include "AliEmcalList.h"
9 #include "AliAnalysisManager.h"
10 
11 #include "TClonesArray.h"
13 #include "AliTrackContainer.h"
14 #include "TObjArray.h"
15 
16 
20 
23  fPtSelection(),
24  fTrackContainer(0x0)
25 {
26 }
27 
28 
31  fPtSelection(),
32  fTrackContainer(0x0)
33 {
34 }
35 
37 {
38 }
39 
41 {
42 //
43 
44 }
45 
47 {
48 
49  // run function from embedding helper base class
51 
52  TString histName = "fHistPtSelection";
53  TString histTitle = "pT selection;Result;p_{T}^{lead}";
54  auto histPtSelection= fHistManager.CreateTH2(histName, histTitle, 2, 0, 2, 200, 0, 100);
55  histPtSelection->GetXaxis()->SetBinLabel(1,"Accepted");
56  histPtSelection->GetXaxis()->SetBinLabel(2,"Rejected");
57 
58  fOutput->Add(histPtSelection);
59 
60  PostData(1, fOutput);
61 
62  // set track container array
64  else {
65  AliFatal("must set track container to use this task");
66  }
67 
68 }
69 
76 {
78 
80 
81  Int_t nTracksInRange = 0;
82  Double_t ptMax = 0;
83  for(auto track : fTrackContainer->accepted()) {
84  Double_t pt = track->Pt();
85  if(pt>ptMax) ptMax = pt;
86  //now check set windows
87  Int_t npt = fPtSelection.size();
88  for(Int_t j=0;j<npt;j++) {
89  if(pt>fPtSelection[j].first && pt<fPtSelection[j].second) {
90  // found track within pt
91  nTracksInRange++;
92  }
93  }
94  }
95 
96  TString histName = "fHistPtSelection";
97  if(nTracksInRange==0) {
98  fHistManager.FillTH2(histName, 1.5, ptMax );
99  return kFALSE;
100  }
101  else {
102  fHistManager.FillTH2(histName, 0.5, ptMax );
103  }
104 
105 
106  return kTRUE;
107 }
108 
109 
111 
113 
114  // get pt selection from YAML file
115  // defined in 2 arrays, pt
116 
117  std::vector <double> ptSelectionMin;
118  std::vector <double> ptSelectionMax;
119  bool resMin = fYAMLConfig.GetProperty( "ptSelectionMin", ptSelectionMin, false);
120  bool resMax = fYAMLConfig.GetProperty( "ptSelectionMax", ptSelectionMax, false);
121  if (resMin && resMax) {
122  if (ptSelectionMin.size() != ptSelectionMax.size()) {
123  AliErrorStream() << "Passed pt selection min with size" << ptSelectionMin.size() << " entries and pt selection max with size " << ptSelectionMax.size() << " - need same size arrays\n";
124  }
125  else {
126  for(std::size_t i = 0; i < ptSelectionMin.size(); i++) {
127  AliDebugStream(1) << "Setting pt selection [" << ptSelectionMin.at(i) << ", " << ptSelectionMax.at(i) << "]\n";
128  fPtSelection.push_back(std::make_pair(ptSelectionMin.at(i), ptSelectionMax.at(i)));
129  }
130  }
131  }
132  else if( (resMin && !resMax) || (!resMin && resMax)) {
133  AliErrorStream() << "Only set one pt selection array - should set both\n";
134  }
135 }
136 
145 {
146 
147  // Get the pointer to the existing analysis manager via the static access method.
148  //==============================================================================
149  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
150  if (!mgr)
151  {
152  ::Error("AddTaskEmcalEmbeddingHelperData", "No analysis manager to connect to.");
153  return 0;
154  }
155 
156  // Check the analysis type using the event handlers connected to the analysis manager.
157  //==============================================================================
158  AliVEventHandler* handler = mgr->GetInputEventHandler();
159  if (!handler)
160  {
161  ::Error("AddTaskEmcalEmbeddingHelperData", "This task requires an input event handler");
162  return 0;
163  }
164 
165  TString name = "AliAnalysisTaskEmcalEmbeddingHelperData";
166 
167  AliAnalysisTaskEmcalEmbeddingHelperData * mgrTask = static_cast<AliAnalysisTaskEmcalEmbeddingHelperData *>(mgr->GetTask(name.Data()));
168  if (mgrTask) return mgrTask;
169 
170  // Create the task that manages
172 
173  // set embedded track container
174  AliTrackContainer *contEmb = new AliTrackContainer("tracks");
175  contEmb->SetTrackCutsPeriod("LHC17p");
176  embeddingHelper->SetEmbeddedTrackContainer(contEmb);
177 
178  //-------------------------------------------------------
179  // Final settings, pass to manager and set the containers
180  //-------------------------------------------------------
181 
182  mgr->AddTask(embeddingHelper);
183 
184  // Create containers for input/output
185  AliAnalysisDataContainer* cInput = mgr->GetCommonInputContainer();
186 
187  TString outputContainerName(name);
188  outputContainerName += "_histos";
189 
190  AliAnalysisDataContainer * cOutput = mgr->CreateContainer(outputContainerName.Data(),
191  TList::Class(),
192  AliAnalysisManager::kOutputContainer,
193  Form("%s", AliAnalysisManager::GetCommonFileName()));
194 
195  mgr->ConnectInput(embeddingHelper, 0, cInput);
196  mgr->ConnectOutput(embeddingHelper, 1, cOutput);
197 
198  return embeddingHelper;
199 }
double Double_t
Definition: External.C:58
const AliTrackIterableContainer accepted() const
Container with name, TClonesArray and cuts for particles.
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
void NextEvent(const AliVEvent *event)
AliTrackContainer * fTrackContainer
track container for pT selection
bool GetProperty(std::vector< std::string > propertyPath, const std::string &propertyName, T &property, const bool requiredProperty) const
Declaration of class AliAnalysisTaskEmcalEmbeddingHelperData.
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
int Int_t
Definition: External.C:63
Implementation of task to embed external events.
static AliAnalysisTaskEmcalEmbeddingHelperData * AddTaskEmcalEmbeddingHelperData()
PWG::Tools::AliYAMLConfiguration fYAMLConfig
Hanldes configuration from YAML.
THistManager fHistManager
Manages access to all histograms.
void SetArray(const AliVEvent *event)
AliEmcalList * fOutput
! List which owns the output histograms to be saved
bool Bool_t
Definition: External.C:53
Double_t ptMax
std::vector< std::pair< Double_t, Double_t > > fPtSelection
min and max pT stored as a vector of pairs
AliVEvent * InputEvent() const
SHOULD NOT BE USED! Use GetExternalEvent()! SHOULD NOT BE USED! Use GetExternalEvent()! Returns the e...