AliPhysics  1cd79fa (1cd79fa)
 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"
47 #include "AliAnalysisDataSlot.h"
48 #include "AliAnalysisDataContainer.h"
50 #include "AliClusterContainer.h"
51 #include "AliJetContainer.h"
54 #include "AliEmcalJet.h"
55 #include "AliEmcalList.h"
57 #include "AliLog.h"
58 #include "AliParticleContainer.h"
59 #include "AliTrackContainer.h"
60 #include "AliRhoParameter.h"
61 #include "AliVCluster.h"
62 #include "AliVParticle.h"
63 
64 #ifdef EXPERIMENTAL_JETCONSTITUENTS
67 #endif
68 
69 
73 
74 namespace EmcalTriggerJets {
75 
78  fJetSubstructureTree(nullptr),
79  fQAHistos(nullptr),
80  fSDZCut(0.1),
81  fSDBetaCut(0),
82  fReclusterizer(kCAAlgo),
83  fTriggerSelectionBits(AliVEvent::kAny),
84  fTriggerSelectionString(""),
85  fUseDownscaleWeight(false),
86  fFillPart(true),
87  fFillRho(true),
88  fFillMass(true),
89  fFillSoftDrop(true),
90  fFillNSub(true),
91  fFillStructGlob(true)
92 {
93  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
94 }
95 
97  AliAnalysisTaskEmcalJet(name, kTRUE),
98  fJetSubstructureTree(nullptr),
99  fQAHistos(nullptr),
100  fSDZCut(0.1),
101  fSDBetaCut(0),
102  fReclusterizer(kCAAlgo),
103  fTriggerSelectionBits(AliVEvent::kAny),
104  fTriggerSelectionString(""),
105  fUseDownscaleWeight(false),
106  fFillPart(true),
107  fFillRho(true),
108  fFillMass(true),
109  fFillSoftDrop(true),
110  fFillNSub(true),
111  fFillStructGlob(true)
112 {
113  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
114  DefineOutput(2, TTree::Class());
115 }
116 
118 
119 }
120 
123 
124  // Make QA for constituent clusters
125  TLinearBinning jetptbinning(9, 20, 200),
126  clusterenergybinning(200, 0., 200),
127  timebinning(1000, -500., 500.),
128  m02binning(100, 0., 1.),
129  ncellbinning(101, -0.5, 100.5);
130  fQAHistos = new THistManager("QAhistos");
131  fQAHistos->CreateTH2("hClusterConstE", "EMCAL cluster energy vs jet pt; p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
132  fQAHistos->CreateTH2("hClusterConstTime", "EMCAL cluster time vs. jet pt; p_{t, jet} (GeV/c); t_{cl} (ns)", jetptbinning, timebinning);
133  fQAHistos->CreateTH2("hClusterConstM02", "EMCAL cluster M02 vs. jet pt; p{t, jet} (GeV/c); M02", jetptbinning, m02binning);
134  fQAHistos->CreateTH2("hClusterConstNcell", "EMCAL cluster ncell vs. jet pt; p{t, jet} (GeV/c); Number of cells", jetptbinning, ncellbinning);
135 
136  // Test of constituent QA
137 #ifdef EXPERIMENTAL_JETCONSTITUENTS
138  fQAHistos->CreateTH2("hChargedConstituentPt", "charged constituent pt vs jet pt (via constituent map); p_{t,jet} (GeV/c); p_{t,ch} (GeV/c)", jetptbinning, clusterenergybinning);
139  fQAHistos->CreateTH2("hChargedIndexPt", "charged constituent pt vs jet pt (via index map); p_{t, jet} (GeV/c); p_{t, ch} (GeV/c)", jetptbinning, clusterenergybinning);
140 
141  fQAHistos->CreateTH2("hClusterConstituentEDefault", "cluster constituent default energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
142  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);
143  fQAHistos->CreateTH2("hClusterConstituentEHC", "cluster constituent hadronic-corrected energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
144  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);
145  fQAHistos->CreateTH2("hClusterIndexEHC", "cluster constituent hadronic-corrected energy vs. jet pt (via index map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
146 #endif
147  for(auto h : *(fQAHistos->GetListOfHistograms())) fOutput->Add(h);
148 
149  OpenFile(2);
150  TString treename = this->GetOutputSlot(2)->GetContainer()->GetName();
151  fJetSubstructureTree = new TTree(treename, "Tree with jet substructure information");
152  TString varnames[kTNVar];
153  varnames[0] = "Radius";
154  varnames[1] = "EventWeight";
155  varnames[2] = "PtJetRec";
156  varnames[3] = "PtJetSim";
157  varnames[4] = "EJetRec";
158  varnames[5] = "EJetSim";
159  varnames[6] = "RhoPtRec";
160  varnames[7] = "RhoPtSim";
161  varnames[8] = "RhoMassRec";
162  varnames[9] = "RhoMassSim";
163  varnames[10] = "AreaRec";
164  varnames[11] = "AreaSim";
165  varnames[12] = "NEFRec";
166  varnames[13] = "NEFSim";
167  varnames[14] = "MassRec";
168  varnames[15] = "MassSim";
169  varnames[16] = "ZgMeasured";
170  varnames[17] = "ZgTrue";
171  varnames[18] = "RgMeasured";
172  varnames[19] = "RgTrue";
173  varnames[20] = "MgMeasured";
174  varnames[21] = "MgTrue";
175  varnames[22] = "PtgMeasured";
176  varnames[23] = "PtgTrue";
177  varnames[24] = "MugMeasured";
178  varnames[25] = "MugTrue";
179  varnames[26] = "OneSubjettinessMeasured";
180  varnames[27] = "OneSubjettinessTrue";
181  varnames[28] = "TwoSubjettinessMeasured";
182  varnames[29] = "TwoSubjettinessTrue";
183  varnames[30] = "AngularityMeasured";
184  varnames[31] = "AngularityTrue";
185  varnames[32] = "PtDMeasured";
186  varnames[33] = "PtDTrue";
187  varnames[34] = "NCharged";
188  varnames[35] = "NNeutral";
189  varnames[36] = "NConstTrue";
190  varnames[37] = "NDroppedMeasured";
191  varnames[38] = "NDroppedTrue";
192 
193  for(int ib = 0; ib < kTNVar; ib++){
194  LinkOutputBranch(varnames[ib], fJetTreeData + ib);
195  }
196  PostData(1, fOutput);
197  PostData(2, fJetSubstructureTree);
198 }
199 
201  // Check whether branch is rejected
202  if(!fFillPart && IsPartBranch(branchname)) return;
203  if(!fFillRho && IsRhoBranch(branchname)) return;
204  if(!fFillMass && IsMassBranch(branchname)) return;
205  if(!fFillSoftDrop && IsSoftdropBranch(branchname)) return;
206  if(!fFillNSub && IsNSubjettinessBranch(branchname)) return;
207  if(!fFillStructGlob && IsStructbranch(branchname)) return;
208 
209  std::cout << "Adding branch " << branchname << std::endl;
210  fJetSubstructureTree->Branch(branchname, datalocation, Form("%s/D", branchname.Data()));
211 }
212 
216  }
217 }
218 
222  AliParticleContainer *particles = GetParticleContainer("mcparticles");
223 
224  AliJetContainer *mcjets = GetJetContainer("mcjets");
225  AliJetContainer *datajets = GetJetContainer("datajets");
226 
227  // for(auto e : *(fInputEvent->GetList())) std::cout << e->GetName() << std::endl;
228 
229  TString rhoTagData = datajets ? TString::Format("R%02d", static_cast<Int_t>(datajets->GetJetRadius() * 10.)) : "",
230  rhoTagMC = mcjets ? TString::Format("R%02d", static_cast<Int_t>(mcjets->GetJetRadius() * 10.)) : "";
231 
232  AliRhoParameter *rhoPtRec = GetRhoFromEvent("RhoSparse_Full_" + rhoTagData),
233  *rhoMassRec = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagData),
234  *rhoPtSim = GetRhoFromEvent("RhoSparse_Full_" + rhoTagMC),
235  *rhoMassSim = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagMC);
236  AliDebugStream(2) << "Found rho parameter for reconstructed pt: " << (rhoPtRec ? "yes" : "no") << ", value: " << (rhoPtRec ? rhoPtRec->GetVal() : 0.) << std::endl;
237  AliDebugStream(2) << "Found rho parameter for sim pt: " << (rhoPtSim ? "yes" : "no") << ", value: " << (rhoPtSim ? rhoPtSim->GetVal() : 0.) << std::endl;
238  AliDebugStream(2) << "Found rho parameter for reconstructed Mass: " << (rhoMassRec ? "yes" : "no") << ", value: " << (rhoMassRec ? rhoMassRec->GetVal() : 0.) << std::endl;
239  AliDebugStream(2) << "Found rho parameter for sim Mass: " << (rhoMassSim ? "yes" : "no") << ", value: " << (rhoMassSim ? rhoMassSim->GetVal() : 0.) << std::endl;
240 
241  AliDebugStream(1) << "Inspecting jet radius " << (datajets ? datajets->GetJetRadius() : mcjets->GetJetRadius()) << std::endl;
242 
243  double weight = 1.;
246  }
247 
248  // Run trigger selection (not on pure MCgen train)
249  if(datajets){
250  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
251  if(!mcjets){
252  // Pure data - do EMCAL trigger selection from selection string
253  if(fTriggerSelectionString.Length()) {
254  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
255  }
256  } else {
257  // Simulation - do EMCAL trigger selection from trigger selection object
258  PWG::EMCAL::AliEmcalTriggerDecisionContainer *mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject("EmcalTriggerDecision"));
259  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
260  if(fTriggerSelectionString.Length()){
261  if(!mctrigger){
262  AliErrorStream() << "Trigger decision container not found in event - not possible to select EMCAL triggers" << std::endl;
263  return false;
264  }
265  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
266  }
267  }
268  }
269 
270  Double_t rhoparameters[4]; memset(rhoparameters, 0, sizeof(Double_t) * 4);
271  if(rhoPtRec) rhoparameters[0] = rhoPtRec->GetVal();
272  if(rhoPtSim) rhoparameters[1] = rhoPtSim->GetVal();
273  if(rhoMassRec) rhoparameters[2] = rhoMassRec->GetVal();
274  if(rhoMassSim) rhoparameters[3] = rhoMassSim->GetVal();
275 
276  AliSoftdropDefinition softdropSettings;
277  softdropSettings.fBeta = fSDBetaCut;
278  softdropSettings.fZ = fSDZCut;
279  switch(fReclusterizer) {
280  case kCAAlgo: softdropSettings.fRecluserAlgo = fastjet::cambridge_aachen_algorithm; break;
281  case kKTAlgo: softdropSettings.fRecluserAlgo = fastjet::kt_algorithm; break;
282  case kAKTAlgo: softdropSettings.fRecluserAlgo = fastjet::antikt_algorithm; break;
283  };
284 
285  AliNSubjettinessDefinition nsubjettinessSettings;
286  nsubjettinessSettings.fBeta = 1.;
287  nsubjettinessSettings.fRadius = 0.4;
288 
289  if(datajets) {
290  AliDebugStream(1) << "In data jets branch: found " << datajets->GetNJets() << " jets, " << datajets->GetNAcceptedJets() << " were accepted\n";
291  AliDebugStream(1) << "Having MC information: " << (mcjets ? TString::Format("yes, with %d jets", mcjets->GetNJets()) : "no") << std::endl;
292  if(mcjets) {
293  AliDebugStream(1) << "In MC jets branch: found " << mcjets->GetNJets() << " jets, " << mcjets->GetNAcceptedJets() << " were accepted\n";
294  }
295  for(auto jet : datajets->accepted()) {
296  double pt = jet->Pt(), pz = jet->Pz(), E = jet->E(), M = TMath::Sqrt(E*E - pt*pt - pz*pz);
297  AliDebugStream(2) << "Next jet: pt:" << jet->Pt() << ", E: " << E << ", pz: " << pz << ", M(self): " << M << "M(fj)" << jet->M() << std::endl;
298  AliEmcalJet *associatedJet = jet->ClosestJet();
299 
300  if(mcjets) {
301  if(!associatedJet) {
302  AliDebugStream(2) << "Not found associated jet" << std::endl;
303  continue;
304  }
305  try {
306  DoConstituentQA(jet, tracks, clusters);
307  AliJetSubstructureData structureData = MakeJetSubstructure(*jet, datajets->GetJetRadius() * 2., tracks, clusters, {softdropSettings, nsubjettinessSettings}),
308  structureMC = fFillPart ? MakeJetSubstructure(*associatedJet, mcjets->GetJetRadius() * 2, particles, nullptr, {softdropSettings, nsubjettinessSettings}) : AliJetSubstructureData();
309  Double_t angularity[2] = {fFillStructGlob ? MakeAngularity(*jet, tracks, clusters) : 0., (fFillStructGlob && fFillPart) ? MakeAngularity(*associatedJet, particles, nullptr) : 0.},
310  ptd[2] = {fFillStructGlob ? MakePtD(*jet, tracks, clusters) : 0., (fFillStructGlob && fFillPart) ? MakePtD(*associatedJet, particles, nullptr) : 0};
311  FillTree(datajets->GetJetRadius(), weight, jet, associatedJet, &(structureData.fSoftDrop), &(structureMC.fSoftDrop), &(structureData.fNsubjettiness), &(structureMC.fNsubjettiness), angularity, ptd, rhoparameters);
312  } catch(ReclusterizerException &e) {
313  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
314  } catch(SubstructureException &e) {
315  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
316  }
317  } else {
318  try {
319  DoConstituentQA(jet, tracks, clusters);
320  AliJetSubstructureData structure = MakeJetSubstructure(*jet, 0.4, tracks, clusters, {softdropSettings, nsubjettinessSettings});
321  Double_t angularity[2] = {fFillStructGlob ? MakeAngularity(*jet, tracks, clusters): 0., 0.},
322  ptd[2] = {fFillStructGlob ? MakePtD(*jet, tracks, clusters) : 0., 0.};
323  FillTree(datajets->GetJetRadius(), weight, jet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), nullptr, angularity, ptd, rhoparameters);
324  } catch(ReclusterizerException &e) {
325  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
326  } catch(SubstructureException &e) {
327  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
328  }
329  }
330  }
331  } else {
332  if(mcjets) {
333  // for MCgen train
334  AliDebugStream(1) << "In MC pure jet branch: found " << mcjets->GetNJets() << " jets, " << mcjets->GetNAcceptedJets() << " were accepted\n";
335  for(auto j : mcjets->accepted()){
336  AliEmcalJet *mcjet = static_cast<AliEmcalJet *>(j);
337  try {
338  AliJetSubstructureData structure = MakeJetSubstructure(*mcjet, mcjets->GetJetRadius() * 2., particles, nullptr,{softdropSettings, nsubjettinessSettings});
339  Double_t angularity[2] = {0., MakeAngularity(*mcjet, particles, nullptr)},
340  ptd[2] = {0., MakePtD(*mcjet, particles, nullptr)};
341  FillTree(mcjets->GetJetRadius(), weight, nullptr, mcjet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), angularity, ptd, rhoparameters);
342  } catch (ReclusterizerException &e) {
343  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
344  } catch (SubstructureException &e) {
345  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
346  }
347  }
348  }
349  }
350 
351  return true;
352 }
353 
355  const AliEmcalJet *datajet, const AliEmcalJet *mcjet,
356  AliSoftDropParameters *dataSoftdrop, AliSoftDropParameters *mcSoftdrop,
357  AliNSubjettinessParameters *dataSubjettiness, AliNSubjettinessParameters *mcSubjettiness,
358  Double_t *angularity, Double_t *ptd, Double_t *rhoparameters){
359 
360  memset(fJetTreeData,0, sizeof(Double_t) * kTNVar);
361  fJetTreeData[kTRadius] = r;
362  fJetTreeData[kTWeight] = weight;
363  if(fFillRho){
364  fJetTreeData[kTRhoPtRec] = rhoparameters[0];
365  if(fFillMass) fJetTreeData[kTRhoMassRec] = rhoparameters[2];
366  if(fFillPart){
367  fJetTreeData[kTRhoPtSim] = rhoparameters[1];
368  if(fFillMass) fJetTreeData[kTRhoMassSim] = rhoparameters[3];
369  }
370  }
371  if(datajet) {
372  fJetTreeData[kTPtJetRec] = TMath::Abs(datajet->Pt());
374  fJetTreeData[kTNNeutral] = datajet->GetNumberOfClusters();
375  fJetTreeData[kTAreaRec] = datajet->Area();
376  fJetTreeData[kTNEFRec] = datajet->NEF();
377  if(fFillMass) fJetTreeData[kTMassRec] = datajet->M();
378  fJetTreeData[kTEJetRec] = datajet->E();
379  }
380 
381  if(fFillPart && mcjet){
382  fJetTreeData[kTPtJetSim] = TMath::Abs(mcjet->Pt());
384  fJetTreeData[kTAreaSim] = mcjet->Area();
385  fJetTreeData[kTNEFSim] = mcjet->NEF();
386  if(fFillMass) fJetTreeData[kTMassSim] = mcjet->M();
387  fJetTreeData[kTEJetSim] = mcjet->E();
388  }
389 
390  if(fFillSoftDrop){
391  if(dataSoftdrop) {
392  fJetTreeData[kTZgMeasured] = dataSoftdrop->fZg;
393  fJetTreeData[kTRgMeasured] = dataSoftdrop->fRg;
394  fJetTreeData[kTMgMeasured] = dataSoftdrop->fMg;
395  fJetTreeData[kTPtgMeasured] = dataSoftdrop->fPtg;
396  fJetTreeData[kTMugMeasured] = dataSoftdrop->fMug;
397  fJetTreeData[kTNDroppedMeasured] = dataSoftdrop->fNDropped;
398  }
399 
400  if(fFillPart && mcSoftdrop) {
401  fJetTreeData[kTZgTrue] = mcSoftdrop->fZg;
402  fJetTreeData[kTRgTrue] = mcSoftdrop->fRg;
403  fJetTreeData[kTMgTrue] = mcSoftdrop->fMg;
404  fJetTreeData[kTPtgTrue] = mcSoftdrop->fPtg;
405  fJetTreeData[kTMugTrue] = mcSoftdrop->fMug;
406  fJetTreeData[kTNDroppedTrue] = mcSoftdrop->fNDropped;
407  }
408  }
409 
410  if(fFillNSub){
411  if(dataSubjettiness) {
414  }
415 
416  if(fFillPart && mcSubjettiness) {
419  }
420  }
421 
422  if(fFillStructGlob){
423  fJetTreeData[kTAngularityMeasured] = angularity[0];
424  fJetTreeData[kTPtDMeasured] = ptd[0];
425 
426  if(fFillPart){
427  fJetTreeData[kTAngularityTrue] = angularity[1];
428  fJetTreeData[kTPtDTrue] = ptd[1];
429  }
430  }
431 
432  fJetSubstructureTree->Fill();
433 }
434 
435 
437  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
438  std::vector<fastjet::PseudoJet> constituents;
439  bool isMC = dynamic_cast<const AliTrackContainer *>(tracks);
440  AliDebugStream(2) << "Make new jet substrucutre for " << (isMC ? "MC" : "data") << " jet: Number of tracks " << jet.GetNumberOfTracks() << ", clusters " << jet.GetNumberOfClusters() << std::endl;
441  for(int itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++){
442  auto track = jet.TrackAt(itrk, tracks->GetArray());
443  fastjet::PseudoJet constituentTrack(track->Px(), track->Py(), track->Pz(), track->E());
444  constituentTrack.set_user_index(jet.TrackAt(itrk));
445  constituents.push_back(constituentTrack);
446  }
447 
448  if(clusters){
449  for(int icl = 0; icl < jet.GetNumberOfClusters(); icl++) {
450  auto cluster = jet.ClusterAt(icl, clusters->GetArray());
451  TLorentzVector clustervec;
452  cluster->GetMomentum(clustervec, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
453  fastjet::PseudoJet constituentCluster(clustervec.Px(), clustervec.Py(), clustervec.Pz(), cluster->GetHadCorrEnergy());
454  constituentCluster.set_user_index(jet.ClusterAt(icl) + kClusterOffset);
455  constituents.push_back(constituentCluster);
456  }
457  }
458 
459  AliDebugStream(3) << "Found " << constituents.size() << " constituents for jet with pt=" << jet.Pt() << " GeV/c" << std::endl;
460  if(!constituents.size())
461  throw ReclusterizerException();
462  // Redo jet finding on constituents with a
463  fastjet::JetDefinition jetdef(fastjet::antikt_algorithm, jetradius*2, static_cast<fastjet::RecombinationScheme>(0), fastjet::BestFJ30 );
464  std::vector<fastjet::PseudoJet> outputjets;
465  try {
466  fastjet::ClusterSequence jetfinder(constituents, jetdef);
467  outputjets = jetfinder.inclusive_jets(0);
469  return result;
470  } catch (fastjet::Error &e) {
471  AliErrorStream() << " FJ Exception caught: " << e.message() << std::endl;
472  throw ReclusterizerException();
473  } catch (SoftDropException &e) {
474  AliErrorStream() << "Softdrop exception caught: " << e.what() << std::endl;
475  throw ReclusterizerException();
476  }
477 }
478 
480  fastjet::contrib::SoftDrop softdropAlgorithm(cutparameters.fBeta, cutparameters.fZ);
481  softdropAlgorithm.set_verbose_structure(kTRUE);
482  std::unique_ptr<fastjet::contrib::Recluster> reclusterizer(new fastjet::contrib::Recluster(cutparameters.fRecluserAlgo, 1, true));
483  softdropAlgorithm.set_reclustering(kTRUE, reclusterizer.get());
484  AliDebugStream(4) << "Jet has " << jet.constituents().size() << " constituents" << std::endl;
485  auto groomed = softdropAlgorithm(jet);
486  try {
487  auto softdropstruct = groomed.structure_of<fastjet::contrib::SoftDrop>();
488 
489  AliSoftDropParameters result({softdropstruct.symmetry(),
490  groomed.m(),
491  softdropstruct.delta_R(),
492  groomed.perp(),
493  softdropstruct.mu(),
494  softdropstruct.dropped_count()});
495  return result;
496  } catch(std::bad_cast &e) {
497  throw SoftDropException();
498  }
499 }
500 
503  fastjet::contrib::Nsubjettiness (1,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet),
504  fastjet::contrib::Nsubjettiness (2,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet)
505  });
506  return result;
507 }
508 
510  if(!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
511  throw SubstructureException();
512  TVector3 jetvec(jet.Px(), jet.Py(), jet.Pz());
513  Double_t den(0.), num(0.);
514  if(tracks){
515  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
516  auto track = jet.TrackAt(itrk, tracks->GetArray());
517  if(!track){
518  AliErrorStream() << "Associated constituent particle / track not found\n";
519  continue;
520  }
521  TVector3 trackvec(track->Px(), track->Py(), track->Pz());
522 
523  num += track->Pt() * trackvec.DrEtaPhi(jetvec);
524  den += +track->Pt();
525  }
526  }
527  if(clusters) {
528  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
529  auto clust = jet.ClusterAt(icl, clusters->GetArray());
530  if(!clust) {
531  AliErrorStream() << "Associated constituent cluster not found\n";
532  continue;
533  }
534  TLorentzVector clusterp;
535  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
536 
537  num += clusterp.Pt() * clusterp.Vect().DrEtaPhi(jetvec);
538  den += clusterp.Pt();
539  }
540  }
541  return num/den;
542 }
543 
545  if (!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
546  throw SubstructureException();
547  Double_t den(0.), num(0.);
548  if(particles){
549  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
550  auto trk = jet.TrackAt(itrk, particles->GetArray());
551  if(!trk){
552  AliErrorStream() << "Associated constituent particle / track not found\n";
553  continue;
554  }
555  num += trk->Pt() * trk->Pt();
556  den += trk->Pt();
557  }
558  }
559  if(clusters){
560  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
561  auto clust = jet.ClusterAt(icl, clusters->GetArray());
562  if(!clust) {
563  AliErrorStream() << "Associated constituent cluster not found\n";
564  continue;
565  }
566  TLorentzVector clusterp;
567  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
568  num += clusterp.Pt() * clusterp.Pt();
569  den += clusterp.Pt();
570  }
571  }
572  return TMath::Sqrt(num)/den;
573 }
574 
576  for(int icl = 0; icl < jet->GetNumberOfClusters(); icl++){
577  auto clust = jet->ClusterAt(icl, clusters->GetArray());
578  AliDebugStream(3) << "cluster time " << clust->GetTOF() << std::endl;
579  fQAHistos->FillTH2("hClusterConstE", jet->Pt(),clust->GetUserDefEnergy(clusters->GetDefaultClusterEnergy()));
580  fQAHistos->FillTH2("hClusterConstTime", jet->Pt(), clust->GetTOF());
581  fQAHistos->FillTH2("hClusterConstM02", jet->Pt(), clust->GetM02());
582  fQAHistos->FillTH2("hClusterConstNcell", jet->Pt(), clust->GetNCells());
583 
584 #ifdef EXPERIMENTAL_JETCONSTITUENTS
585  fQAHistos->FillTH2("hClusterIndexENLC", jet->Pt(), clust->GetNonLinCorrEnergy());
586  fQAHistos->FillTH2("hClusterIndexEHC", jet->Pt(), clust->GetHadCorrEnergy());
587 #endif
588  }
589 
590 #ifdef EXPERIMENTAL_JETCONSTITUENTS
591  // Loop over charged particles - fill test histogram
592  for(int itrk = 0; itrk < jet->GetNumberOfTracks(); itrk++){
593  auto part = jet->TrackAt(itrk, cont->GetArray());
594  fQAHistos->FillTH2("hChargedIndexPt", jet->Pt(), part->Pt());
595  }
596 
597  // Look over charged constituents
598  AliDebugStream(2) << "Jet: Number of particle constituents: " << jet->GetParticleConstituents().GetEntriesFast() << std::endl;
599  for(auto pconst : jet->GetParticleConstituents()) {
600  auto part = static_cast<PWG::JETFW::AliEmcalParticleJetConstituent *>(pconst);
601  AliDebugStream(3) << "Found particle constituent with pt " << part->Pt() << ", from VParticle " << part->GetParticle()->Pt() << std::endl;
602  fQAHistos->FillTH2("hChargedConstituentPt", jet->Pt(), part->Pt());
603  }
604 
605  // Loop over neutral constituents
606  AliDebugStream(2) << "Jet: Number of cluster constituents: " << jet->GetClusterConstituents().GetEntriesFast() << std::endl;
607  for(auto cconst : jet->GetClusterConstituents()){
608  auto clust = static_cast<PWG::JETFW::AliEmcalClusterJetConstituent *>(cconst);
609  AliDebugStream(3) << "Found cluster constituent with energy " << clust->E() << " using energy definition " << static_cast<int>(clust->GetDefaultEnergyType()) << std::endl;
610  fQAHistos->FillTH2("hClusterConstituentEDefault", jet->Pt(), clust->E());
611  fQAHistos->FillTH2("hClusterConstituentENLC", jet->Pt(), clust->GetCluster()->GetNonLinCorrEnergy());
612  fQAHistos->FillTH2("hClusterConstituentEHC", jet->Pt(), clust->GetCluster()->GetHadCorrEnergy());
613  }
614 #endif
615 }
616 
618  return branchname.Contains("Sim") || branchname.Contains("True");
619 }
620 
622  return branchname.Contains("Rho");
623 }
624 
626  return branchname.Contains("Mass"); // also disable rho mass branch
627 }
628 
630  return branchname.Contains("gMeasured") || branchname.Contains("gTrue") || branchname.Contains("NDropped");
631 }
632 
634  return branchname.Contains("Subjettiness");
635 }
636 
638  return branchname.Contains("Angularity") || branchname.Contains("PtD");
639 }
640 
642  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
643 
644  Bool_t isAOD(kFALSE);
645  AliInputEventHandler *inputhandler = static_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
646  if(inputhandler) {
647  if(inputhandler->IsA() == AliAODInputHandler::Class()){
648  std::cout << "Analysing AOD events\n";
649  isAOD = kTRUE;
650  } else {
651  std::cout << "Analysing ESD events\n";
652  }
653  }
654 
655  AliAnalysisTaskEmcalJetSubstructureTree *treemaker = new AliAnalysisTaskEmcalJetSubstructureTree("JetSubstructureTreemaker_" + TString::Format("R%02d_", int(jetradius * 10.)) + trigger);
656  mgr->AddTask(treemaker);
657  treemaker->SetMakeGeneralHistograms(kTRUE);
658 
659  // Adding containers
660  if(isMC) {
661  AliParticleContainer *particles = treemaker->AddMCParticleContainer("mcparticles");
662  particles->SetMinPt(0.);
663 
664  AliJetContainer *mcjets = treemaker->AddJetContainer(
665  jettype,
667  recombinationScheme,
668  jetradius,
670  particles, nullptr);
671  mcjets->SetName("mcjets");
672  mcjets->SetJetPtCut(20.);
673  }
674 
675  if(isData) {
676  AliTrackContainer *tracks(nullptr);
677  if((jettype == AliJetContainer::kChargedJet) || (jettype == AliJetContainer::kFullJet)){
679  std::cout << "Track container name: " << tracks->GetName() << std::endl;
680  tracks->SetMinPt(0.15);
681  }
682  AliClusterContainer *clusters(nullptr);
684  std::cout << "Using full or neutral jets ..." << std::endl;
686  std::cout << "Cluster container name: " << clusters->GetName() << std::endl;
687  clusters->SetClusHadCorrEnergyCut(0.3); // 300 MeV E-cut
688  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
689  } else {
690  std::cout << "Using charged jets ... " << std::endl;
691  }
692 
693  AliJetContainer *datajets = treemaker->AddJetContainer(
694  jettype,
696  recombinationScheme,
697  jetradius,
699  tracks, clusters);
700  datajets->SetName("datajets");
701  datajets->SetJetPtCut(20.);
702 
703  treemaker->SetUseAliAnaUtils(true, true);
704  treemaker->SetVzRange(-10., 10);
705 
706  // configure trigger selection
707  TString triggerstring(trigger);
708  if(triggerstring.Contains("INT7")) {
709  treemaker->SetTriggerBits(AliVEvent::kINT7);
710  } else if(triggerstring.Contains("EJ1")) {
711  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
712  treemaker->SetTriggerString("EJ1");
713  } else if(triggerstring.Contains("EJ2")) {
714  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
715  treemaker->SetTriggerString("EJ2");
716  }
717  }
718 
719  // Connecting containers
720  TString outputfile = mgr->GetCommonFileName();
721  outputfile += TString::Format(":JetSubstructure_R%02d_%s", int(jetradius * 10.), trigger);
722  mgr->ConnectInput(treemaker, 0, mgr->GetCommonInputContainer());
723  mgr->ConnectOutput(treemaker, 1, mgr->CreateContainer("JetSubstructureHistos_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, AliEmcalList::Class(), AliAnalysisManager::kOutputContainer, outputfile));
724  mgr->ConnectOutput(treemaker, 2, mgr->CreateContainer("JetSubstuctureTree_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, TTree::Class(), AliAnalysisManager::kOutputContainer, mgr->GetCommonFileName()));
725 
726  return treemaker;
727 }
728 
729 } /* 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
static AliAnalysisTaskEmcalJetSubstructureTree * AddEmcalJetSubstructureTreeMaker(Bool_t isMC, Bool_t isData, Double_t jetradius, AliJetContainer::EJetType_t jettype, AliJetContainer::ERecoScheme_t recombinationScheme, const char *name)
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)
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.
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.
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.
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
void LinkOutputBranch(const TString &branchname, Double_t *datalocation)
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.