AliPhysics  c6e65cb (c6e65cb)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEmcalJetSubstructureTree.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 <iostream>
28 #include <string>
29 #include <set>
30 #include <sstream>
31 #include <vector>
32 
33 #include <fastjet/ClusterSequence.hh>
34 #include <fastjet/contrib/Nsubjettiness.hh>
35 #include <fastjet/contrib/SoftDrop.hh>
36 
37 #include <THistManager.h>
38 #include <TLinearBinning.h>
39 #include <TLorentzVector.h>
40 #include <TMath.h>
41 #include <TString.h>
42 #include <TVector3.h>
43 
44 #include "AliAODEvent.h"
45 #include "AliAODInputHandler.h"
46 #include "AliAnalysisManager.h"
48 #include "AliClusterContainer.h"
49 #include "AliJetContainer.h"
52 #include "AliEmcalJet.h"
53 #include "AliEmcalList.h"
55 #include "AliLog.h"
56 #include "AliParticleContainer.h"
57 #include "AliTrackContainer.h"
58 #include "AliRhoParameter.h"
59 #include "AliVCluster.h"
60 #include "AliVParticle.h"
61 
62 #ifdef EXPERIMENTAL_JETCONSTITUENTS
65 #endif
66 
67 
71 
72 namespace EmcalTriggerJets {
73 
76  fJetSubstructureTree(nullptr),
77  fQAHistos(nullptr),
78  fSDZCut(0.1),
79  fSDBetaCut(0),
80  fReclusterizer(kCAAlgo),
81  fTriggerSelectionBits(AliVEvent::kAny),
82  fTriggerSelectionString(""),
83  fUseDownscaleWeight(false)
84 {
85  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
86 }
87 
89  AliAnalysisTaskEmcalJet(name, kTRUE),
90  fJetSubstructureTree(nullptr),
91  fQAHistos(nullptr),
92  fSDZCut(0.1),
93  fSDBetaCut(0),
94  fReclusterizer(kCAAlgo),
95  fTriggerSelectionBits(AliVEvent::kAny),
96  fTriggerSelectionString(""),
97  fUseDownscaleWeight(false)
98 {
99  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
100  DefineOutput(2, TTree::Class());
101 }
102 
104 
105 }
106 
109 
110  // Make QA for constituent clusters
111  TLinearBinning jetptbinning(9, 20, 200),
112  clusterenergybinning(200, 0., 200),
113  timebinning(1000, -500., 500.),
114  m02binning(100, 0., 1.),
115  ncellbinning(101, -0.5, 100.5);
116  fQAHistos = new THistManager("QAhistos");
117  fQAHistos->CreateTH2("hClusterConstE", "EMCAL cluster energy vs jet pt; p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
118  fQAHistos->CreateTH2("hClusterConstTime", "EMCAL cluster time vs. jet pt; p_{t, jet} (GeV/c); t_{cl} (ns)", jetptbinning, timebinning);
119  fQAHistos->CreateTH2("hClusterConstM02", "EMCAL cluster M02 vs. jet pt; p{t, jet} (GeV/c); M02", jetptbinning, m02binning);
120  fQAHistos->CreateTH2("hClusterConstNcell", "EMCAL cluster ncell vs. jet pt; p{t, jet} (GeV/c); Number of cells", jetptbinning, ncellbinning);
121 
122  // Test of constituent QA
123 #ifdef EXPERIMENTAL_JETCONSTITUENTS
124  fQAHistos->CreateTH2("hChargedConstituentPt", "charged constituent pt vs jet pt (via constituent map); p_{t,jet} (GeV/c); p_{t,ch} (GeV/c)", jetptbinning, clusterenergybinning);
125  fQAHistos->CreateTH2("hChargedIndexPt", "charged constituent pt vs jet pt (via index map); p_{t, jet} (GeV/c); p_{t, ch} (GeV/c)", jetptbinning, clusterenergybinning);
126 
127  fQAHistos->CreateTH2("hClusterConstituentEDefault", "cluster constituent default energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
128  fQAHistos->CreateTH2("hClusterConstituentENLC", "cluster constituent non-linearity-corrected energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
129  fQAHistos->CreateTH2("hClusterConstituentEHC", "cluster constituent hadronic-corrected energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
130  fQAHistos->CreateTH2("hClusterIndexENLC", "cluster constituent non-linearity-corrected energy vs. jet pt (via index map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
131  fQAHistos->CreateTH2("hClusterIndexEHC", "cluster constituent hadronic-corrected energy vs. jet pt (via index map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
132 #endif
133  for(auto h : *(fQAHistos->GetListOfHistograms())) fOutput->Add(h);
134 
135  OpenFile(2);
136  fJetSubstructureTree = new TTree("jetSubstructure", "Tree with jet substructure information");
137  TString varnames[kTNVar];
138  varnames[0] = "Radius";
139  varnames[1] = "EventWeight";
140  varnames[2] = "PtJetRec";
141  varnames[3] = "PtJetSim";
142  varnames[4] = "EJetRec";
143  varnames[5] = "EJetSim";
144  varnames[6] = "RhoPtRec";
145  varnames[7] = "RhoPtSim";
146  varnames[8] = "RhoMassRec";
147  varnames[9] = "RhoMassSim";
148  varnames[10] = "AreaRec";
149  varnames[11] = "AreaSim";
150  varnames[12] = "NEFRec";
151  varnames[13] = "NEFSim";
152  varnames[14] = "MassRec";
153  varnames[15] = "MassSim";
154  varnames[16] = "ZgMeasured";
155  varnames[17] = "ZgTrue";
156  varnames[18] = "RgMeasured";
157  varnames[19] = "RgTrue";
158  varnames[20] = "MgMeasured";
159  varnames[21] = "MgTrue";
160  varnames[22] = "PtgMeasured";
161  varnames[23] = "PtgTrue";
162  varnames[24] = "MugMeasured";
163  varnames[25] = "MugTrue";
164  varnames[26] = "OneSubjettinessMeasured";
165  varnames[27] = "OneSubjettinessTrue";
166  varnames[28] = "TwoSubjettinessMeasured";
167  varnames[29] = "TwoSubjettinessTrue";
168  varnames[30] = "AngularityMeasured";
169  varnames[31] = "AngularityTrue";
170  varnames[32] = "PtDMeasured";
171  varnames[33] = "PtDTrue";
172  varnames[34] = "NCharged";
173  varnames[35] = "NNeutral";
174  varnames[36] = "NConstTrue";
175  varnames[37] = "NDroppedMeasured";
176  varnames[38] = "NDroppedTrue";
177 
178  for(int ib = 0; ib < kTNVar; ib++){
179  fJetSubstructureTree->Branch(varnames[ib], fJetTreeData + ib, Form("%s/D", varnames[ib].Data()));
180  }
181  PostData(1, fOutput);
182  PostData(2, fJetSubstructureTree);
183 }
184 
188  }
189 }
190 
194  AliParticleContainer *particles = GetParticleContainer("mcparticles");
195 
196  AliJetContainer *mcjets = GetJetContainer("mcjets");
197  AliJetContainer *datajets = GetJetContainer("datajets");
198 
199  // for(auto e : *(fInputEvent->GetList())) std::cout << e->GetName() << std::endl;
200 
201  TString rhoTagData = datajets ? TString::Format("R%02d", static_cast<Int_t>(datajets->GetJetRadius() * 10.)) : "",
202  rhoTagMC = mcjets ? TString::Format("R%02d", static_cast<Int_t>(mcjets->GetJetRadius() * 10.)) : "";
203 
204  AliRhoParameter *rhoPtRec = GetRhoFromEvent("RhoSparse_Full_" + rhoTagData),
205  *rhoMassRec = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagData),
206  *rhoPtSim = GetRhoFromEvent("RhoSparse_Full_" + rhoTagMC),
207  *rhoMassSim = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagMC);
208  AliDebugStream(2) << "Found rho parameter for reconstructed pt: " << (rhoPtRec ? "yes" : "no") << ", value: " << (rhoPtRec ? rhoPtRec->GetVal() : 0.) << std::endl;
209  AliDebugStream(2) << "Found rho parameter for sim pt: " << (rhoPtSim ? "yes" : "no") << ", value: " << (rhoPtSim ? rhoPtSim->GetVal() : 0.) << std::endl;
210  AliDebugStream(2) << "Found rho parameter for reconstructed Mass: " << (rhoMassRec ? "yes" : "no") << ", value: " << (rhoMassRec ? rhoMassRec->GetVal() : 0.) << std::endl;
211  AliDebugStream(2) << "Found rho parameter for sim Mass: " << (rhoMassSim ? "yes" : "no") << ", value: " << (rhoMassSim ? rhoMassSim->GetVal() : 0.) << std::endl;
212 
213  AliDebugStream(1) << "Inspecting jet radius " << (datajets ? datajets->GetJetRadius() : mcjets->GetJetRadius()) << std::endl;
214 
215  double weight = 1.;
218  }
219 
220  // Run trigger selection (not on pure MCgen train)
221  if(datajets){
222  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
223  if(!mcjets){
224  // Pure data - do EMCAL trigger selection from selection string
225  if(fTriggerSelectionString.Length()) {
226  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
227  }
228  } else {
229  // Simulation - do EMCAL trigger selection from trigger selection object
230  PWG::EMCAL::AliEmcalTriggerDecisionContainer *mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject("EmcalTriggerDecision"));
231  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
232  if(fTriggerSelectionString.Length()){
233  if(!mctrigger){
234  AliErrorStream() << "Trigger decision container not found in event - not possible to select EMCAL triggers" << std::endl;
235  return false;
236  }
237  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
238  }
239  }
240  }
241 
242  Double_t rhoparameters[4]; memset(rhoparameters, 0, sizeof(Double_t) * 4);
243  if(rhoPtRec) rhoparameters[0] = rhoPtRec->GetVal();
244  if(rhoPtSim) rhoparameters[1] = rhoPtSim->GetVal();
245  if(rhoMassRec) rhoparameters[2] = rhoMassRec->GetVal();
246  if(rhoMassSim) rhoparameters[3] = rhoMassSim->GetVal();
247 
248  AliSoftdropDefinition softdropSettings;
249  softdropSettings.fBeta = fSDBetaCut;
250  softdropSettings.fZ = fSDZCut;
251  switch(fReclusterizer) {
252  case kCAAlgo: softdropSettings.fRecluserAlgo = fastjet::cambridge_aachen_algorithm; break;
253  case kKTAlgo: softdropSettings.fRecluserAlgo = fastjet::kt_algorithm; break;
254  case kAKTAlgo: softdropSettings.fRecluserAlgo = fastjet::antikt_algorithm; break;
255  };
256 
257  AliNSubjettinessDefinition nsubjettinessSettings;
258  nsubjettinessSettings.fBeta = 1.;
259  nsubjettinessSettings.fRadius = 0.4;
260 
261  std::set<AliEmcalJet *> taglist;
262  if(datajets) {
263  AliDebugStream(1) << "In data jets branch: found" << datajets->GetNJets() << " jets, " << datajets->GetNAcceptedJets() << " were accepted\n";
264  AliDebugStream(1) << "Having MC information: " << (mcjets ? TString::Format("yes, with %d jets", mcjets->GetNJets()) : "no") << std::endl;
265  for(auto jet : datajets->accepted()) {
266  double pt = jet->Pt(), pz = jet->Pz(), E = jet->E(), M = TMath::Sqrt(E*E - pt*pt - pz*pz);
267  AliDebugStream(2) << "Next jet: pt:" << jet->Pt() << ", E: " << E << ", pz: " << pz << ", M(self): " << M << "M(fj)" << jet->M() << std::endl;
268  AliEmcalJet *associatedJet = jet->ClosestJet();
269 
270  if(mcjets) {
271  if(!associatedJet) continue;
272  taglist.insert(associatedJet);
273  try {
274  DoConstituentQA(jet, tracks, clusters);
275  AliJetSubstructureData structureData = MakeJetSubstructure(*jet, datajets->GetJetRadius() * 2., tracks, clusters, {softdropSettings, nsubjettinessSettings}),
276  structureMC = MakeJetSubstructure(*associatedJet, mcjets->GetJetRadius() * 2, particles, nullptr, {softdropSettings, nsubjettinessSettings});
277  Double_t angularity[2] = {MakeAngularity(*jet, tracks, clusters), MakeAngularity(*associatedJet, particles, nullptr)},
278  ptd[2] = {MakePtD(*jet, tracks, clusters), MakePtD(*associatedJet, particles, nullptr)};
279  FillTree(datajets->GetJetRadius(), weight, jet, associatedJet, &(structureData.fSoftDrop), &(structureMC.fSoftDrop), &(structureData.fNsubjettiness), &(structureMC.fNsubjettiness), angularity, ptd, rhoparameters);
280  } catch(ReclusterizerException &e) {
281  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
282  } catch(SubstructureException &e) {
283  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
284  }
285  } else {
286  try {
287  DoConstituentQA(jet, tracks, clusters);
288  AliJetSubstructureData structure = MakeJetSubstructure(*jet, 0.4, tracks, clusters, {softdropSettings, nsubjettinessSettings});
289  Double_t angularity[2] = {MakeAngularity(*jet, tracks, clusters), 0.},
290  ptd[2] = {MakePtD(*jet, tracks, clusters), 0.};
291  FillTree(datajets->GetJetRadius(), weight, jet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), nullptr, angularity, ptd, rhoparameters);
292  } catch(ReclusterizerException &e) {
293  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
294  } catch(SubstructureException &e) {
295  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
296  }
297  }
298  }
299  }
300 
301  if(mcjets) {
302  // process non-matched true jets
303  // - for efficiency studies
304  // - for MCgen train (taglist will be empty in this case)
305  AliDebugStream(1) << "In MC pure jet branch: found " << mcjets->GetNJets() << " jets, " << mcjets->GetNAcceptedJets() << " were accepted\n";
306  for(auto j : mcjets->accepted()){
307  AliEmcalJet *mcjet = static_cast<AliEmcalJet *>(j);
308  if(taglist.find(mcjet) != taglist.end()) continue;
309  try {
310  AliJetSubstructureData structure = MakeJetSubstructure(*mcjet, mcjets->GetJetRadius() * 2., particles, nullptr,{softdropSettings, nsubjettinessSettings});
311  Double_t angularity[2] = {0., MakeAngularity(*mcjet, particles, nullptr)},
312  ptd[2] = {0., MakePtD(*mcjet, particles, nullptr)};
313  FillTree(mcjets->GetJetRadius(), weight, nullptr, mcjet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), angularity, ptd, rhoparameters);
314  } catch (ReclusterizerException &e) {
315  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
316  } catch (SubstructureException &e) {
317  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
318  }
319  }
320  }
321 
322  return true;
323 }
324 
326  const AliEmcalJet *datajet, const AliEmcalJet *mcjet,
327  AliSoftDropParameters *dataSoftdrop, AliSoftDropParameters *mcSoftdrop,
328  AliNSubjettinessParameters *dataSubjettiness, AliNSubjettinessParameters *mcSubjettiness,
329  Double_t *angularity, Double_t *ptd, Double_t *rhoparameters){
330  fJetTreeData[kTRadius] = r;
331  fJetTreeData[kTWeight] = weight;
332  fJetTreeData[kTRhoPtRec] = rhoparameters[0];
333  fJetTreeData[kTRhoPtSim] = rhoparameters[1];
334  fJetTreeData[kTRhoMassRec] = rhoparameters[2];
335  fJetTreeData[kTRhoMassSim] = rhoparameters[3];
336  if(datajet) {
337  fJetTreeData[kTPtJetRec] = TMath::Abs(datajet->Pt());
339  fJetTreeData[kTNNeutral] = datajet->GetNumberOfClusters();
340  fJetTreeData[kTAreaRec] = datajet->Area();
341  fJetTreeData[kTNEFRec] = datajet->NEF();
342  fJetTreeData[kTMassRec] = datajet->M();
343  fJetTreeData[kTEJetRec] = datajet->E();
344  } else {
345  fJetTreeData[kTPtJetRec] = 0.;
348  fJetTreeData[kTAreaRec] = 0.;
349  fJetTreeData[kTNEFRec] = 0.;
350  fJetTreeData[kTMassRec] = 0.;
351  fJetTreeData[kTEJetRec] = 0.;
352  }
353 
354  if(mcjet) {
355  fJetTreeData[kTPtJetSim] = TMath::Abs(mcjet->Pt());
357  fJetTreeData[kTAreaSim] = mcjet->Area();
358  fJetTreeData[kTNEFSim] = mcjet->NEF();
359  fJetTreeData[kTMassSim] = mcjet->M();
360  fJetTreeData[kTEJetSim] = mcjet->E();
361  } else {
362  fJetTreeData[kTPtJetSim] = 0.;
364  fJetTreeData[kTAreaSim] = 0.;
365  fJetTreeData[kTNEFSim] = 0.;
366  fJetTreeData[kTMassSim] = 0.;
367  fJetTreeData[kTEJetSim] = 0.;
368  }
369 
370  if(dataSoftdrop) {
371  fJetTreeData[kTZgMeasured] = dataSoftdrop->fZg;
372  fJetTreeData[kTRgMeasured] = dataSoftdrop->fRg;
373  fJetTreeData[kTMgMeasured] = dataSoftdrop->fMg;
374  fJetTreeData[kTPtgMeasured] = dataSoftdrop->fPtg;
375  fJetTreeData[kTMugMeasured] = dataSoftdrop->fMug;
376  fJetTreeData[kTNDroppedMeasured] = dataSoftdrop->fNDropped;
377  } else {
384  }
385 
386  if(mcSoftdrop) {
387  fJetTreeData[kTZgTrue] = mcSoftdrop->fZg;
388  fJetTreeData[kTRgTrue] = mcSoftdrop->fRg;
389  fJetTreeData[kTMgTrue] = mcSoftdrop->fMg;
390  fJetTreeData[kTPtgTrue] = mcSoftdrop->fPtg;
391  fJetTreeData[kTMugTrue] = mcSoftdrop->fMug;
392  fJetTreeData[kTNDroppedTrue] = mcSoftdrop->fNDropped;
393  } else {
394  fJetTreeData[kTZgTrue] = 0.;
395  fJetTreeData[kTRgTrue] = 0.;
396  fJetTreeData[kTMgTrue] = 0.;
397  fJetTreeData[kTPtgTrue] = 0.;
398  fJetTreeData[kTMugTrue] = 0.;
400  }
401 
402  if(dataSubjettiness) {
405  } else {
408  }
409 
410  if(mcSubjettiness) {
413  } else {
416  }
417 
418  fJetTreeData[kTAngularityMeasured] = angularity[0];
419  fJetTreeData[kTAngularityTrue] = angularity[1];
420  fJetTreeData[kTPtDMeasured] = ptd[0];
421  fJetTreeData[kTPtDTrue] = ptd[1];
422 
423  fJetSubstructureTree->Fill();
424 }
425 
426 
428  const int kClusterOffset = 30000; // In order to handle tracks and clusters in the same index space the cluster index needs and offset, large enough so that there is no overlap with track indices
429  std::vector<fastjet::PseudoJet> constituents;
430  bool isMC = dynamic_cast<const AliTrackContainer *>(tracks);
431  AliDebugStream(2) << "Make new jet substrucutre for " << (isMC ? "MC" : "data") << " jet: Number of tracks " << jet.GetNumberOfTracks() << ", clusters " << jet.GetNumberOfClusters() << std::endl;
432  for(int itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++){
433  AliVTrack *track = static_cast<AliVTrack *>(jet.TrackAt(itrk, tracks->GetArray()));
434  fastjet::PseudoJet constituentTrack(track->Px(), track->Py(), track->Pz(), track->E());
435  constituentTrack.set_user_index(jet.TrackAt(itrk));
436  constituents.push_back(constituentTrack);
437  }
438 
439  if(clusters){
440  for(int icl = 0; icl < jet.GetNumberOfClusters(); icl++) {
441  AliVCluster *cluster = jet.ClusterAt(icl, clusters->GetArray());
442  TLorentzVector clustervec;
443  cluster->GetMomentum(clustervec, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
444  fastjet::PseudoJet constituentCluster(clustervec.Px(), clustervec.Py(), clustervec.Pz(), cluster->GetHadCorrEnergy());
445  constituentCluster.set_user_index(jet.ClusterAt(icl) + kClusterOffset);
446  constituents.push_back(constituentCluster);
447  }
448  }
449 
450  AliDebugStream(3) << "Found " << constituents.size() << " constituents for jet with pt=" << jet.Pt() << " GeV/c" << std::endl;
451  if(!constituents.size())
452  throw ReclusterizerException();
453  // Redo jet finding on constituents with a
454  fastjet::JetDefinition jetdef(fastjet::antikt_algorithm, jetradius*2, static_cast<fastjet::RecombinationScheme>(0), fastjet::BestFJ30 );
455  std::vector<fastjet::PseudoJet> outputjets;
456  try {
457  fastjet::ClusterSequence jetfinder(constituents, jetdef);
458  outputjets = jetfinder.inclusive_jets(0);
459  AliJetSubstructureData result({MakeSoftDropParameters(outputjets[0], settings.fSoftdropSettings), MakeNsubjettinessParameters(outputjets[0], settings.fSubjettinessSettings)});
460  return result;
461  } catch (fastjet::Error &e) {
462  AliErrorStream() << " FJ Exception caught: " << e.message() << std::endl;
463  throw ReclusterizerException();
464  }
465 }
466 
468  fastjet::contrib::SoftDrop softdropAlgorithm(cutparameters.fBeta, cutparameters.fZ);
469  softdropAlgorithm.set_verbose_structure(kTRUE);
470  std::unique_ptr<fastjet::contrib::Recluster> reclusterizer(new fastjet::contrib::Recluster(cutparameters.fRecluserAlgo, 1, true));
471  softdropAlgorithm.set_reclustering(kTRUE, reclusterizer.get());
472  AliDebugStream(4) << "Jet has " << jet.constituents().size() << " constituents" << std::endl;
473  fastjet::PseudoJet groomed = softdropAlgorithm(jet);
474 
475  AliSoftDropParameters result({groomed.structure_of<fastjet::contrib::SoftDrop>().symmetry(),
476  groomed.m(),
477  groomed.structure_of<fastjet::contrib::SoftDrop>().delta_R(),
478  groomed.perp(),
479  groomed.structure_of<fastjet::contrib::SoftDrop>().mu(),
480  groomed.structure_of<fastjet::contrib::SoftDrop>().dropped_count()});
481  return result;
482 }
483 
486  fastjet::contrib::Nsubjettiness (1,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet),
487  fastjet::contrib::Nsubjettiness (2,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet)
488  });
489  return result;
490 }
491 
493  if(!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
494  throw SubstructureException();
495  TVector3 jetvec(jet.Px(), jet.Py(), jet.Pz());
496  Double_t den(0.), num(0.);
497  if(tracks){
498  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
499  AliVParticle *track = jet.TrackAt(itrk, tracks->GetArray());
500  if(!track){
501  AliErrorStream() << "Associated constituent particle / track not found\n";
502  continue;
503  }
504  TVector3 trackvec(track->Px(), track->Py(), track->Pz());
505 
506  num += track->Pt() * trackvec.DrEtaPhi(jetvec);
507  den += +track->Pt();
508  }
509  }
510  if(clusters) {
511  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
512  AliVCluster *clust = jet.ClusterAt(icl, clusters->GetArray());
513  if(!clust) {
514  AliErrorStream() << "Associated constituent cluster not found\n";
515  continue;
516  }
517  TLorentzVector clusterp;
518  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
519 
520  num += clusterp.Pt() * clusterp.Vect().DrEtaPhi(jetvec);
521  den += clusterp.Pt();
522  }
523  }
524  return num/den;
525 }
526 
528  if (!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
529  throw SubstructureException();
530  Double_t den(0.), num(0.);
531  if(particles){
532  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
533  AliVParticle *trk = jet.TrackAt(itrk, particles->GetArray());
534  if(!trk){
535  AliErrorStream() << "Associated constituent particle / track not found\n";
536  continue;
537  }
538  num += trk->Pt() * trk->Pt();
539  den += trk->Pt();
540  }
541  }
542  if(clusters){
543  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
544  AliVCluster *clust = jet.ClusterAt(icl, clusters->GetArray());
545  if(!clust) {
546  AliErrorStream() << "Associated constituent cluster not found\n";
547  continue;
548  }
549  TLorentzVector clusterp;
550  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
551  num += clusterp.Pt() * clusterp.Pt();
552  den += clusterp.Pt();
553  }
554  }
555  return TMath::Sqrt(num)/den;
556 }
557 
559  for(int icl = 0; icl < jet->GetNumberOfClusters(); icl++){
560  AliVCluster *clust = jet->ClusterAt(icl, clusters->GetArray());
561  AliDebugStream(3) << "cluster time " << clust->GetTOF() << std::endl;
562  fQAHistos->FillTH2("hClusterConstE", jet->Pt(),clust->GetUserDefEnergy(clusters->GetDefaultClusterEnergy()));
563  fQAHistos->FillTH2("hClusterConstTime", jet->Pt(), clust->GetTOF());
564  fQAHistos->FillTH2("hClusterConstM02", jet->Pt(), clust->GetM02());
565  fQAHistos->FillTH2("hClusterConstNcell", jet->Pt(), clust->GetNCells());
566 
567 #ifdef EXPERIMENTAL_JETCONSTITUENTS
568  fQAHistos->FillTH2("hClusterIndexENLC", jet->Pt(), clust->GetNonLinCorrEnergy());
569  fQAHistos->FillTH2("hClusterIndexEHC", jet->Pt(), clust->GetHadCorrEnergy());
570 #endif
571  }
572 
573 #ifdef EXPERIMENTAL_JETCONSTITUENTS
574  // Loop over charged particles - fill test histogram
575  for(int itrk = 0; itrk < jet->GetNumberOfTracks(); itrk++){
576  AliVParticle *part = jet->TrackAt(itrk, cont->GetArray());
577  fQAHistos->FillTH2("hChargedIndexPt", jet->Pt(), part->Pt());
578  }
579 
580  // Look over charged constituents
581  AliDebugStream(2) << "Jet: Number of particle constituents: " << jet->GetParticleConstituents().GetEntriesFast() << std::endl;
582  for(auto pconst : jet->GetParticleConstituents()) {
584  AliDebugStream(3) << "Found particle constituent with pt " << part->Pt() << ", from VParticle " << part->GetParticle()->Pt() << std::endl;
585  fQAHistos->FillTH2("hChargedConstituentPt", jet->Pt(), part->Pt());
586  }
587 
588  // Loop over neutral constituents
589  AliDebugStream(2) << "Jet: Number of cluster constituents: " << jet->GetClusterConstituents().GetEntriesFast() << std::endl;
590  for(auto cconst : jet->GetClusterConstituents()){
592  AliDebugStream(3) << "Found cluster constituent with energy " << clust->E() << " using energy definition " << static_cast<int>(clust->GetDefaultEnergyType()) << std::endl;
593  fQAHistos->FillTH2("hClusterConstituentEDefault", jet->Pt(), clust->E());
594  fQAHistos->FillTH2("hClusterConstituentENLC", jet->Pt(), clust->GetCluster()->GetNonLinCorrEnergy());
595  fQAHistos->FillTH2("hClusterConstituentEHC", jet->Pt(), clust->GetCluster()->GetHadCorrEnergy());
596  }
597 #endif
598 }
599 
601  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
602 
603  Bool_t isAOD(kFALSE);
604  AliInputEventHandler *inputhandler = static_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
605  if(inputhandler) {
606  if(inputhandler->IsA() == AliAODInputHandler::Class()){
607  std::cout << "Analysing AOD events\n";
608  isAOD = kTRUE;
609  } else {
610  std::cout << "Analysing ESD events\n";
611  }
612  }
613 
614  AliAnalysisTaskEmcalJetSubstructureTree *treemaker = new AliAnalysisTaskEmcalJetSubstructureTree("JetSubstructureTreemaker_" + TString::Format("R%02d_", int(jetradius * 10.)) + trigger);
615  mgr->AddTask(treemaker);
616  treemaker->SetMakeGeneralHistograms(kTRUE);
617 
618  // Adding containers
619  if(isMC) {
620  AliParticleContainer *particles = treemaker->AddMCParticleContainer("mcparticles");
621  particles->SetMinPt(0.);
622 
623  AliJetContainer *mcjets = treemaker->AddJetContainer(
626  recombinationScheme,
627  jetradius,
628  (isData && jettype == kFull) ? AliEmcalJet::kEMCALfid : AliEmcalJet::kTPC,
629  particles, nullptr);
630  mcjets->SetName("mcjets");
631  mcjets->SetJetPtCut(20.);
632  }
633 
634  if(isData) {
636  std::cout << "Track container name: " << tracks->GetName() << std::endl;
637  tracks->SetMinPt(0.15);
638  AliClusterContainer *clusters(nullptr);
639  if(jettype == kFull){
640  std::cout << "Using full jets ..." << std::endl;
642  std::cout << "Cluster container name: " << clusters->GetName() << std::endl;
643  clusters->SetClusHadCorrEnergyCut(0.3); // 300 MeV E-cut
644  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
645  } else {
646  std::cout << "Using charged jets ... " << std::endl;
647  }
648 
649  AliJetContainer *datajets = treemaker->AddJetContainer(
652  recombinationScheme,
653  jetradius,
655  tracks, clusters);
656  datajets->SetName("datajets");
657  datajets->SetJetPtCut(20.);
658 
659  treemaker->SetUseAliAnaUtils(true, true);
660  treemaker->SetVzRange(-10., 10);
661 
662  // configure trigger selection
663  TString triggerstring(trigger);
664  if(triggerstring.Contains("INT7")) {
665  treemaker->SetTriggerBits(AliVEvent::kINT7);
666  } else if(triggerstring.Contains("EJ1")) {
667  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
668  treemaker->SetTriggerString("EJ1");
669  } else if(triggerstring.Contains("EJ2")) {
670  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
671  treemaker->SetTriggerString("EJ2");
672  }
673  }
674 
675  // Connecting containers
676  TString outputfile = mgr->GetCommonFileName();
677  outputfile += TString::Format(":JetSubstructure_R%02d_%s", int(jetradius * 10.), trigger);
678  mgr->ConnectInput(treemaker, 0, mgr->GetCommonInputContainer());
679  mgr->ConnectOutput(treemaker, 1, mgr->CreateContainer("JetSubstructureHistos_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, AliEmcalList::Class(), AliAnalysisManager::kOutputContainer, outputfile));
680  mgr->ConnectOutput(treemaker, 2, mgr->CreateContainer("JetSubstuctureTree_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, TTree::Class(), AliAnalysisManager::kOutputContainer, Form("JetSubstructureTree_R%02d_%s.root", static_cast<int>(jetradius*10.), trigger)));
681 
682  return treemaker;
683 }
684 
685 } /* namespace EmcalTriggerJets */
Double_t Area() const
Definition: AliEmcalJet.h:130
bool IsEventSelected(const char *name) const
Checks whether the events is selected for a given trigger type.
double Double_t
Definition: External.C:58
Class creating a linear binning, used in the histogram manager.
Double_t MakePtD(const AliEmcalJet &jet, const AliParticleContainer *const particles, const AliClusterContainer *const clusters) const
AliEmcalJet * ClosestJet() const
Definition: AliEmcalJet.h:327
AliJetContainer * GetJetContainer(Int_t i=0) const
virtual double E() const
Access to constituent energy.
static AliEmcalDownscaleFactorsOCDB * Instance()
Double_t Py() const
Definition: AliEmcalJet.h:107
Container with name, TClonesArray and cuts for particles.
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
AliJetSubstructureData MakeJetSubstructure(const AliEmcalJet &jet, double jetradius, const AliParticleContainer *tracks, const AliClusterContainer *clusters, const AliJetSubstructureSettings &settings) const
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
Int_t ClusterAt(Int_t idx) const
Definition: AliEmcalJet.h:137
AliJetContainer * AddJetContainer(const char *n, TString defaultCutType, Float_t jetRadius=0.4)
const std::vector< PWG::JETFW::AliEmcalParticleJetConstituent > & GetParticleConstituents() const
Get container with particle (track / MC particle) constituents.
Definition: AliEmcalJet.h:184
Structure for results from the soft drop algorithm.
Double_t E() const
Definition: AliEmcalJet.h:119
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_t GetDownscaleFactorForTriggerClass(const TString &trigger) const
void SetVzRange(Double_t min, Double_t max)
AliVCluster::VCluUserDefEnergy_t GetDefaultEnergyType() const
Get the energy definition used to calculate the cluster energy in the jetfinder.
AliClusterContainer * AddClusterContainer(const char *n)
Create new cluster container and attach it to the task.
fastjet::JetAlgorithm fRecluserAlgo
Reclusterization algorithm.
UShort_t GetNumberOfConstituents() const
Definition: AliEmcalJet.h:140
Container for particles within the EMCAL framework.
Int_t GetDefaultClusterEnergy() const
Int_t TrackAt(Int_t idx) const
Definition: AliEmcalJet.h:160
UShort_t GetNumberOfTracks() const
Definition: AliEmcalJet.h:139
Double_t Px() const
Definition: AliEmcalJet.h:106
AliParticleContainer * GetParticleContainer(Int_t i=0) const
Get particle container attached to this task.
static AliAnalysisTaskEmcalJetSubstructureTree * AddEmcalJetSubstructureTreeMaker(Bool_t isMC, Bool_t isData, Double_t jetradius, JetType_t jettype, AliJetContainer::ERecoScheme_t recombinationScheme, const char *name)
TPC fiducial acceptance (each eta edge narrowed by jet R)
Definition: AliEmcalJet.h:68
AliRhoParameter * GetRhoFromEvent(const char *name)
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
UShort_t GetNumberOfClusters() const
Definition: AliEmcalJet.h:138
void SetJetPtCut(Float_t cut)
TPC acceptance.
Definition: AliEmcalJet.h:67
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Int_t GetNJets() const
AliNSubjettinessParameters MakeNsubjettinessParameters(const fastjet::PseudoJet &jet, const AliNSubjettinessDefinition &cut) const
Definition for the algorithm obtaining the softdrop parameters.
AliClusterContainer * GetClusterContainer(Int_t i=0) const
Get cluster container attached to this task.
const AliVCluster * GetCluster() const
Get the underlying cluster.
virtual void RunChanged(Int_t newrun)
Process tasks relevant when a file with a different run number is processed.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
Create new container for MC particles and attach it to the task.
Double_t MakeAngularity(const AliEmcalJet &jet, const AliParticleContainer *tracks, const AliClusterContainer *clusters) const
Implementation of a jet constituent for constituent clusters.
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Double_t Pt() const
Definition: AliEmcalJet.h:109
Bool_t isMC
void DoConstituentQA(const AliEmcalJet *jet, const AliParticleContainer *tracks, const AliClusterContainer *clusters)
Float_t GetJetRadius() const
const std::vector< PWG::JETFW::AliEmcalClusterJetConstituent > & GetClusterConstituents() const
Get container with cluster constituents.
Definition: AliEmcalJet.h:190
virtual double Pt() const
Access to transverse momentum.
AliEmcalList * fOutput
!output list
Double_t fVertex[3]
!event vertex
AliTrackContainer * AddTrackContainer(const char *n)
Create new track container and attach it to the task.
AliTrackContainer * GetTrackContainer(Int_t i=0) const
void SetMakeGeneralHistograms(Bool_t g)
Base task in the EMCAL jet framework.
void FillTree(double r, double weight, const AliEmcalJet *datajet, const AliEmcalJet *mcjet, AliSoftDropParameters *dataSoftdrop, AliSoftDropParameters *mcsoftdrop, AliNSubjettinessParameters *dataSubjettiness, AliNSubjettinessParameters *mcSubjettiness, Double_t *angularity, Double_t *ptd, Double_t *rhoparameters)
Represent a jet reconstructed using the EMCal jet framework.
Definition: AliEmcalJet.h:51
Container class for histograms.
Definition: THistManager.h:99
Double_t Pz() const
Definition: AliEmcalJet.h:108
AliSoftDropParameters MakeSoftDropParameters(const fastjet::PseudoJet &jet, const AliSoftdropDefinition &cut) const
void UserCreateOutputObjects()
Main initialization function on the worker.
const AliJetIterableContainer accepted() const
bool Bool_t
Definition: External.C:53
Double_t NEF() const
Definition: AliEmcalJet.h:148
void SetDefaultClusterEnergy(Int_t d)
Container structure for EMCAL clusters.
Double_t M() const
Definition: AliEmcalJet.h:120
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
Definition: AliEmcalJet.h:70
Container for jet within the EMCAL jet framework.
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
void SetClusHadCorrEnergyCut(Double_t cut)
static TString TrackContainerNameFactory(Bool_t isAOD)
Get name of the default track container.
static TString ClusterContainerNameFactory(Bool_t isAOD)
Get name of the default cluster container.