AliPhysics  5364b50 (5364b50)
AliAnalysisTaskEmcalJetConstituentQA.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <array>
28 #include <cmath>
29 #include <iomanip>
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33 #include <THistManager.h>
34 #include <TLinearBinning.h>
35 #include <TLorentzVector.h>
36 
37 #include "AliAnalysisManager.h"
39 #include "AliAODInputHandler.h"
40 #include "AliClusterContainer.h"
43 #include "AliEmcalJet.h"
44 #include "AliInputEventHandler.h"
45 #include "AliJetContainer.h"
46 #include "AliLog.h"
47 #include "AliTrackContainer.h"
48 #include "AliVCluster.h"
49 #include "AliVEvent.h"
50 #include "AliVTrack.h"
51 
55 
56 using namespace EmcalTriggerJets;
57 
60  fHistos(nullptr),
61  fNameTrackContainer(""),
62  fNameClusterContainer(""),
63  fTriggerSelectionString(""),
64  fUseTriggerSelection(kFALSE),
65  fNameTriggerDecisionContainer("EmcalTriggerDecision")
66 {
67  this->SetUseAliAnaUtils(true);
68 }
69 
71  AliAnalysisTaskEmcalJet(name, true),
76  fUseTriggerSelection(kFALSE),
77  fNameTriggerDecisionContainer("EmcalTriggerDecision")
78 {
79  this->SetUseAliAnaUtils(true);
80 }
81 
83  if(fHistos) delete fHistos;
84 }
85 
88 
89  TLinearBinning binningz(50, 0., 1), multbinning(51, -0.5, 50.5), binningnef(50, 0., 1.), binningptconst(200, 0., 200.), binningptjet(20, 0., 200.);
90 
91  const TBinning *jetbinning[4] = {&binningptjet, &binningnef, &multbinning, &multbinning},
92  *chargedbinning[6] = {&binningptjet, &binningnef, &multbinning, &multbinning, &binningptconst, &binningz},
93  *neutralbinning[7] = {&binningptjet, &binningnef, &multbinning, &multbinning, &binningptconst, &binningptconst, &binningz};
94 
95  fHistos = new THistManager(Form("histos_%s", GetName()));
96  for(auto c : fNamesJetContainers){
97  auto contname = dynamic_cast<TObjString *>(c);
98  if(!contname) continue;
99  fHistos->CreateTHnSparse(Form("hJetCounter%s", contname->String().Data()), Form("jet counter for jets %s", contname->String().Data()), 4, jetbinning);
100  fHistos->CreateTHnSparse(Form("hChargedConstituents%s", contname->String().Data()), Form("charged constituents in jets %s", contname->String().Data()), 6, chargedbinning);
101  fHistos->CreateTHnSparse(Form("hNeutralConstituents%s", contname->String().Data()), Form("neutral constituents in jets %s", contname->String().Data()), 7, neutralbinning);
102  }
103 
104  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
105  PostData(1, fOutput);
106 }
107 
109  auto tracks = GetTrackContainer(fNameTrackContainer);
110  const auto clusters = GetClusterContainer(fNameClusterContainer);
111  if(!(tracks && clusters)){
112  AliErrorStream() << "Either track or cluster container missing, aborting ..." << std::endl;
113  }
114 
115  // Event selection
116  AliDebugStream(1) << "Trigger selection string: " << fTriggerSelectionString << ", fired trigger classes: " << fInputEvent->GetFiredTriggerClasses() << std::endl;
117  if(fTriggerSelectionString.Contains("INT7")){
118  // INT7 trigger
119  if(!(fInputHandler->IsEventSelected() & AliVEvent::kINT7)) return false;
120  } else if(fTriggerSelectionString.Contains("EJ")){
121  auto triggerclass = fTriggerSelectionString(fTriggerSelectionString.Index("EJ"),3); // cleanup trigger string from possible tags
122  AliDebugStream(1) << "Inspecting trigger class " << triggerclass << std::endl;
123  // EMCAL JET trigger
124  if(!fMCEvent){ // Running on Data
125  if(!(fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)) return false;
126  if(!fInputEvent->GetFiredTriggerClasses().Contains(triggerclass)) return false;
127  }
128 
130  auto triggerdecisions = dynamic_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer.Data()));
131  if(!triggerdecisions) {
132  AliErrorStream() << "No offline trigger selection available" << std::endl;
133  return false;
134  }
135  else if(!triggerdecisions->IsEventSelected(triggerclass.Data())) return false;
136  }
137  } else return false;
138 
139  AliDebugStream(1) << "Event is selected" << std::endl;
140 
141  for(auto jc : fNamesJetContainers){
142  auto contname = dynamic_cast<TObjString *>(jc);
143  if(!contname) {
144  AliErrorStream() << "Non-string object in the list of jet container names" << std::endl;
145  continue;
146  }
147  const auto jetcont = GetJetContainer(contname->String().Data());
148  if(!jetcont){
149  AliErrorStream() << "Jet container with name " << contname->String() << " not found in the list of jet containers" << std::endl;
150  continue;
151  }
152 
153  for(auto jet : jetcont->accepted()){
154  AliDebugStream(3) << "Next accepted jet, found " << jet->GetNumberOfTracks() << " tracks and " << jet->GetNumberOfClusters() << " clusters." << std::endl;
155  Double_t pointjet[4] = {std::abs(jet->Pt()), jet->NEF(), static_cast<double>(jet->GetNumberOfTracks()), static_cast<double>(jet->GetNumberOfClusters())},
156  pointcharged[6] = {std::abs(jet->Pt()), jet->NEF(), static_cast<double>(jet->GetNumberOfTracks()), static_cast<double>(jet->GetNumberOfClusters()), -1., 1.},
157  pointneutral[7] = {std::abs(jet->Pt()), jet->NEF(), static_cast<double>(jet->GetNumberOfTracks()), static_cast<double>(jet->GetNumberOfClusters()), -1., 1., -1.};
158  fHistos->FillTHnSparse(Form("hJetCounter%s", contname->String().Data()), pointjet);
159  for(decltype(jet->GetNumberOfTracks()) itrk = 0; itrk < jet->GetNumberOfTracks(); itrk++){
160  const auto trk = jet->TrackAt(itrk, tracks->GetArray());
161  if(!trk) continue;
162  pointcharged[4] = std::abs(trk->Pt());
163  pointcharged[5] = std::abs(jet->GetZ(trk));
164  fHistos->FillTHnSparse(Form("hChargedConstituents%s", contname->String().Data()), pointcharged);
165  }
166  for(decltype(jet->GetNumberOfClusters()) icl = 0; icl < jet->GetNumberOfClusters(); icl++){
167  const auto clust = jet->ClusterAt(icl, clusters->GetArray());
168  if(!clust) continue;
169  TLorentzVector ptvec;
170  clust->GetMomentum(ptvec, this->fVertex, AliVCluster::kHadCorr);
171  pointneutral[4] = std::abs(clust->GetHadCorrEnergy());
172  pointneutral[5] = std::abs(clust->GetNonLinCorrEnergy());
173  pointneutral[6] = jet->GetZ(ptvec.Px(), ptvec.Py(), ptvec.Pz());
174  fHistos->FillTHnSparse(Form("hNeutralConstituents%s", contname->String().Data()), pointneutral);
175  }
176  }
177  }
178 
179  return kTRUE;
180 }
181 
183  using AnalysisHelpers = EMCalTriggerPtAnalysis::AliEmcalAnalysisFactory;
184  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
185  if(!mgr) {
186  std::cerr << "[AliAnalysisTaskJetConstituentQA::AddTaskEmcalJetConstituentQA(EE)] No analysis manager provided ..." << std::endl;
187  return nullptr;
188  }
189 
190  std::stringstream taskname;
191  taskname << "constituentQA_" << trigger;
192  auto task = new AliAnalysisTaskEmcalJetConstituentQA(taskname.str().data());
193  task->SetTriggerSelection(trigger);
194  mgr->AddTask(task);
195 
196  auto inputhandler = mgr->GetInputEventHandler();
197  auto isAOD = false;
198  if(inputhandler->IsA() == AliAODInputHandler::Class()) isAOD = true;
199 
200  auto tracksname = AnalysisHelpers::TrackContainerNameFactory(isAOD);
201  auto tracks = task->AddTrackContainer(tracksname);
202  task->SetNameTrackContainer(tracksname);
203  tracks->SetMinPt(0.15);
204 
205  auto clustername = AnalysisHelpers::ClusterContainerNameFactory(isAOD);
206  auto clusters = task->AddClusterContainer(clustername);
207  task->SetNameClusterContainer(clustername);
208  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
209  clusters->SetClusHadCorrEnergyCut(0.3);
210 
211  // create jet containers for R02 and R04 jets
212  std::array<double, 2> jetradii = {{0.2, 0.4}};
213  for(auto r : jetradii) {
214  std::stringstream contname;
215  contname << "fulljets_R" << std::setw(2) << std::setfill('0') << int(r*10.);
216  auto jcont = task->AddJetContainer(AliJetContainer::kFullJet, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, r, AliJetContainer::kEMCALfid, tracks, clusters, "Jet");
217  jcont->SetName(contname.str().data());
218  task->AddNameJetContainer(contname.str().data());
219  jcont->SetMinPt(20.);
220  }
221 
222  std::stringstream contname, outfilename;
223  contname << "JetConstituentQA_" << trigger;
224  outfilename << mgr->GetCommonFileName() << ":JetConstituentQA_" << trigger;
225  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
226  mgr->ConnectOutput(task, 1, mgr->CreateContainer(contname.str().data(), AliEmcalList::Class(), AliAnalysisManager::kOutputContainer, outfilename.str().data()));
227 
228  return task;
229 }
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
virtual bool Run()
Run function. This is the core function of the analysis and contains the user code. Therefore users have to implement this function.
double Double_t
Definition: External.C:58
Class creating a linear binning, used in the histogram manager.
AliJetContainer * GetJetContainer(Int_t i=0) const
TObjArray fNamesJetContainers
Names of the connected jet container.
static AliAnalysisTaskEmcalJetConstituentQA * AddTaskEmcalJetConstituentQA(const char *trigger)
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
TCanvas * c
Definition: TestFitELoss.C:172
Interface for binnings used by the histogram handler.
Definition: TBinning.h:21
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Collection of helper functions used to configure the analysis.
AliClusterContainer * GetClusterContainer(Int_t i=0) const
Get cluster container attached to this task.
AliEmcalList * fOutput
!output list
Double_t fVertex[3]
!event vertex
AliTrackContainer * GetTrackContainer(Int_t i=0) const
TString fNameTriggerDecisionContainer
Name of the trigger decision container.
Base task in the EMCAL jet framework.
Container class for histograms.
Definition: THistManager.h:99
void UserCreateOutputObjects()
Main initialization function on the worker.
Bool_t fUseTriggerSelection
Use trigger selection in addition to trigger string.
THnSparse * CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Create a new THnSparse within the container.