AliPhysics  master (3d17d9d)
AliAnalysisTaskJetDynamicalGrooming.h
Go to the documentation of this file.
1 #ifndef ALIANALYSISTASKJETDYNAMICALGROOMING_H
2 #define ALIANALYSISTASKJETDYNAMICALGROOMING_H
3 
15 #include <map>
16 #include <string>
17 
18 class TH1;
19 class TH2;
20 class TH3;
21 class TH3F;
22 class TTree;
23 class THnSparse;
24 class TClonesArray;
25 class TArrayI;
26 class AliAnalysisManager;
27 class AliJetContainer;
28 class AliEmcalJetFinder;
29 
31 #include "AliFJWrapper.h"
33 #include "AliYAMLConfiguration.h"
34 
35 // operator<< has to be forward declared carefully to stay in the global namespace so that it works with CINT.
36 // For generally how to keep the operator in the global namespace, See: https://stackoverflow.com/a/38801633
37 namespace PWGJE {
38 namespace EMCALJetTasks {
39 namespace SubstructureTree {
40  class Subjets;
41  class JetSplittings;
42  class JetConstituents;
43  class JetSubstructureSplittings;
44 }
46 } // namespace EMCALJetTasks
47 } // namespace PWGJE
48 std::ostream& operator<<(std::ostream& in, const PWGJE::EMCALJetTasks::SubstructureTree::Subjets& myTask);
49 std::ostream& operator<<(std::ostream& in, const PWGJE::EMCALJetTasks::SubstructureTree::JetSplittings& myTask);
50 std::ostream& operator<<(std::ostream& in, const PWGJE::EMCALJetTasks::SubstructureTree::JetConstituents& myTask);
51 std::ostream& operator<<(std::ostream& in, const PWGJE::EMCALJetTasks::SubstructureTree::JetSubstructureSplittings& myTask);
52 std::ostream& operator<<(std::ostream& in, const PWGJE::EMCALJetTasks::AliAnalysisTaskJetDynamicalGrooming& myTask);
63 
64 namespace PWGJE {
65 namespace EMCALJetTasks {
66 namespace SubstructureTree {
67 
68 class Subjets {
69  public:
70  // TODO: Fully update and document!
71  Subjets();
72  // Additional constructors
73  Subjets(const Subjets & other);
74  Subjets& operator=(Subjets other);
75  friend void ::swap(Subjets & first, Subjets & second);
76  // Avoid implementing move since c++11 is not allowed in the header
77  virtual ~Subjets() {}
78 
80  bool Clear();
81 
82  // Getters and setters
83  void AddSubjet(const unsigned short splittingNodeIndex, const bool partOfIterativeSplitting,
84  const std::vector<unsigned short>& constituentIndices);
85  #if !(defined(__CINT__) || defined(__MAKECINT__))
86  std::tuple<unsigned short, bool, const std::vector<unsigned short>> GetSubjet(int i) const;
87  #endif
88 
89  // Printing
90  std::string toString() const;
91  friend std::ostream & ::operator<<(std::ostream &in, const Subjets &myTask);
92  void Print(Option_t* opt = "") const;
93  std::ostream & Print(std::ostream &in) const;
94 
95  protected:
96  std::vector<unsigned short> fSplittingNodeIndex;
97  std::vector<bool> fPartOfIterativeSplitting;
98  std::vector<std::vector<unsigned short>> fConstituentIndices;
99 
101  ClassDef(Subjets, 2) // Subjets from splittings.
103 };
104 
106  public:
107  JetSplittings();
108  // Additional constructors
109  JetSplittings(const JetSplittings & other);
110  JetSplittings& operator=(JetSplittings other);
111  friend void ::swap(JetSplittings & first, JetSplittings & second);
112  // Avoid implementing move since c++11 is not allowed in the header
113  virtual ~JetSplittings() {}
114 
116  bool Clear();
117 
118  // Getters and setters
119  void AddSplitting(float kt, float deltaR, float z, short parentIndex);
120  #if !(defined(__CINT__) || defined(__MAKECINT__))
121  std::tuple<float, float, float, short> GetSplitting(int i) const;
122  #endif
123  unsigned int GetNumberOfSplittings() const { return fKt.size(); }
124 
125  // Printing
126  std::string toString() const;
127  friend std::ostream & ::operator<<(std::ostream &in, const JetSplittings &myTask);
128  void Print(Option_t* opt = "") const;
129  std::ostream & Print(std::ostream &in) const;
130 
131  protected:
132  std::vector<float> fKt;
133  std::vector<float> fDeltaR;
134  std::vector<float> fZ;
135  std::vector<short> fParentIndex;
136 
138  ClassDef(JetSplittings, 1) // Jet splittings.
140 };
141 
143 {
144  public:
145  // TODO: Fully update and document!
146  JetConstituents();
147  // Additional constructors
148  JetConstituents(const JetConstituents & other);
149  JetConstituents& operator=(JetConstituents other);
150  friend void ::swap(JetConstituents & first, JetConstituents & second);
151  // Avoid implementing move since c++11 is not allowed in the header
152  virtual ~JetConstituents() {}
153 
155  bool Clear();
156 
157  // Getters and setters
158  void AddJetConstituent(const PWG::JETFW::AliEmcalParticleJetConstituent& part);
159  #if !(defined(__CINT__) || defined(__MAKECINT__))
160  std::tuple<float, float, float, int> GetJetConstituent(int i) const;
161  #endif
162 
163  // Printing
164  std::string toString() const;
165  friend std::ostream & ::operator<<(std::ostream &in, const JetConstituents &myTask);
166  void Print(Option_t* opt = "") const;
167  std::ostream & Print(std::ostream &in) const;
168 
169  protected:
170  std::vector<float> fPt;
171  std::vector<float> fEta;
172  std::vector<float> fPhi;
173  std::vector<unsigned int> fGlobalIndex;
174 
176  ClassDef(JetConstituents, 1) // Jet constituents.
178 };
179 
191  public:
193  // Additional constructors
197  // Avoid implementing move since c++11 is not allowed in the header
199 
201  bool Clear();
202 
203  // Setters
204  void SetJetPt(float pt) { fJetPt = pt; }
205  void AddJetConstituent(const PWG::JETFW::AliEmcalParticleJetConstituent& part);
206  void AddSplitting(float kt, float deltaR, float z, short parentIndex);
207  void AddSubjet(const unsigned short splittingNodeIndex, const bool partOfIterativeSplitting,
208  const std::vector<unsigned short>& constituentIndices);
209  // Getters
210  float GetJetPt() { return fJetPt; }
211  #if !(defined(__CINT__) || defined(__MAKECINT__))
212  std::tuple<float, float, float, int> GetJetConstituent(int i) const;
213  std::tuple<float, float, float, short> GetSplitting(int i) const;
214  std::tuple<unsigned short, bool, const std::vector<unsigned short>> GetSubjet(int i) const;
215  #endif
216  unsigned int GetNumberOfSplittings() { return fJetSplittings.GetNumberOfSplittings(); }
217 
218  // Printing
219  std::string toString() const;
220  friend std::ostream & ::operator<<(std::ostream &in, const JetSubstructureSplittings &myTask);
221  void Print(Option_t* opt = "") const;
222  std::ostream & Print(std::ostream &in) const;
223 
224  private:
225  // Jet properties
226  float fJetPt;
230 
232  ClassDef(JetSubstructureSplittings, 2) // Jet splitting properties.
234 };
235 
236 } /* namespace SubstructureTree */
237 
239 {
240  public:
242  kMCTrue = 0,
243  kTrueDet = 1,
244  kData = 2,
245  kDetEmb = 3,
246  kDetEmbPart = 4,
247  kPythiaDef = 5,
248  kDetEmbPartPythia = 6,
249  kGenOnTheFly = 7
250  };
251  enum JetShapeSub_t { kNoSub = 0, kConstSub = 1, kDerivSub = 2, kEventSub = 3 };
252  enum JetSelectionType_t { kInclusive = 0, kRecoil = 1 };
253  enum DerivSubtrOrder_t { kSecondOrder = 0, kFirstOrder = 1 };
254  static const std::map<std::string, JetShapeType_t> fgkJetShapeTypeMap;
255  static const std::map<std::string, JetShapeSub_t> fgkJetShapeSubMap;
256  static const std::map<std::string, JetSelectionType_t> fgkJetSelectionMap;
257  static const std::map<std::string, DerivSubtrOrder_t> fgkDerivSubtrOrderMap;
258 
260  AliAnalysisTaskJetDynamicalGrooming(const char* name);
261  // Additional constructors
265  // Avoid implementing move since c++11 is not allowed in the header
267 
268  void UserCreateOutputObjects();
269 
270  // Setters
271  void SetMinFractionShared(Double_t f) { fMinFractionShared = f; }
272  void SetJetShapeType(JetShapeType_t t) { fJetShapeType = t; }
273  void SetJetShapeSub(JetShapeSub_t t) { fJetShapeSub = t; }
274  void SetJetSelection(JetSelectionType_t t) { fJetSelection = t; }
275  void SetJetPtThreshold(Float_t f) { fPtThreshold = f; }
276  void SetRMatching(Float_t f) { fRMatching = f; }
277 
278  void SetCentralitySelectionOn(Bool_t t) { fCentSelectOn = t; }
279  void SetCheckResolution(Bool_t t) { fCheckResolution = t; }
280  void SetSubjetCutoff(Float_t t) { fSubjetCutoff = t; }
281  void SetMinPtConst(Float_t t) { fMinPtConst = t; }
282  void SetHardCutoff(Float_t t) { fHardCutoff = t; }
283  void SetDoTwoTrack(Bool_t t) { fDoTwoTrack = t; }
284  void SetCutDoubleCounts(Bool_t t) { fCutDoubleCounts = t; }
285  void SetMagFieldPol(Float_t t) { fMagFieldPolarity = t; }
286  void SetMinCentrality(Float_t t) { fCentMin = t; }
287  void SetMaxCentrality(Float_t t) { fCentMax = t; }
288  void SetDerivativeSubtractionOrder(Int_t c) { fDerivSubtrOrder = c; }
289  void SetDetLevelJetsOn(Bool_t t) { fStoreDetLevelJets = t; }
290  void SetStoreRecursiveJetSplittings(bool t = true) { fStoreRecursiveSplittings = t; }
291 
292  // Initialize the task
293  // Configuration is handled via the YAML configuration file
294  bool Initialize();
295  void AddConfigurationFile(const std::string & configurationPath, const std::string & configName = "") { fYAMLConfig.AddConfiguration(configurationPath, configName); }
296 
297  //static AliAnalysisTaskJetDynamicalGrooming * AddTaskJetDynamicalGrooming(const std::string & suffix = "");
298 
299  static AliAnalysisTaskJetDynamicalGrooming* AddTaskJetDynamicalGrooming(
300  const char* njetsBase, const char* njetsUS, const char* njetsTrue, const char* njetsPartLevel, const Double_t R,
301  const char* nrhoBase, const char* ntracks, const char* ntracksUS, const char* ntracksPartLevel,
302  const char* nclusters, const char* ntracksTrue, const char* type, const char* CentEst, Int_t pSel,
307  Float_t minpTHTrigger = 0., Float_t maxpTHTrigger = 0., Float_t acut = 0.6,
310  const std::string& suffix = "");
311 
312  // Printing
313  std::string toString() const;
314  friend std::ostream & ::operator<<(std::ostream &in, const AliAnalysisTaskJetDynamicalGrooming &myTask);
315  void Print(Option_t* opt = "") const;
316  std::ostream & Print(std::ostream &in) const;
317 
318  // Helpers
319  std::string DetermineOutputContainerName(std::string containerName) const;
320 
321  protected:
322  Bool_t RetrieveEventObjects();
323  Bool_t Run();
324  Bool_t FillHistograms();
325 
326  void RetrieveAndSetTaskPropertiesFromYAMLConfig();
327  void SetupTree();
328 
329  template<typename T>
330  std::string GetKeyFromMapValue(const T & value, const std::map<std::string, T> & valuesMap) const;
331 
342  double DynamicalGrooming(const fastjet::PseudoJet & subjet1, const fastjet::PseudoJet & subjet2, const fastjet::PseudoJet & parent, const double R, const double a) const;
344  double CalculateZDrop(const fastjet::PseudoJet & subjet1, const fastjet::PseudoJet & subjet2, const fastjet::PseudoJet & parent, const double R) const;
346  double CalculateKtDrop(const fastjet::PseudoJet & subjet1, const fastjet::PseudoJet & subjet2, const fastjet::PseudoJet & parent, const double R) const;
348  double CalculateTimeDrop(const fastjet::PseudoJet & subjet1, const fastjet::PseudoJet & subjet2, const fastjet::PseudoJet & parent, const double R) const;
349 
350  void IterativeParents(AliEmcalJet* jet, SubstructureTree::JetSubstructureSplittings& jetSplittings, bool isData);
351  void ExtractJetSplittings(SubstructureTree::JetSubstructureSplittings & jetSplittings, fastjet::PseudoJet & inputJet, int splittingNodeIndex, bool followingIterativeSplitting);
352  void CheckSubjetResolution(AliEmcalJet* fJet, AliEmcalJet* fJetM);
353  bool CheckClosePartner(AliEmcalJet* jet, PWG::JETFW::AliEmcalParticleJetConstituent & part1);
354 
355  // Basic configuration
358 
365 
381 
382  // Tree variables
386 
387  TH1F* fPtJet;
388 
390 
392 
393  private:
395  ClassDef(AliAnalysisTaskJetDynamicalGrooming, 2) // Jet dynamical grooming
397 };
398 
399 template<typename T>
400 std::string AliAnalysisTaskJetDynamicalGrooming::GetKeyFromMapValue(const T & value, const std::map<std::string, T> & valuesMap) const
401 {
402  auto findResult = std::find_if(std::begin(valuesMap), std::end(valuesMap), [&](const std::pair<std::string, T> &pair)
403  {
404  return pair.second == value;
405  });
406  std::string returnValue = "Invalid value: " + std::to_string(static_cast<int>(value));
407  if (findResult != std::end(valuesMap))
408  {
409  returnValue = findResult->first;
410  }
411  return returnValue;
412 }
413 
414 } /* namespace EMCALJetTasks */
415 } /* namespace PWGJE */
416 
417 #endif /* ALIANALYSISTASKJETDYNAMICALGROOMING_H */
void Print(std::ostream &o, const char *name, Double_t dT, Double_t dVM, Double_t alldT, Double_t alldVM)
Definition: PlotSysInfo.C:121
std::vector< short > fParentIndex
Index of the parent splitting.
double Double_t
Definition: External.C:58
Definition: External.C:260
std::vector< unsigned short > fSplittingNodeIndex
Index of the parent splitting node.
Jet substructure with dynamical grooming.
Definition: External.C:244
std::ostream & operator<<(std::ostream &in, const PWGJE::EMCALJetTasks::SubstructureTree::Subjets &myTask)
bool fStoreRecursiveSplittings
If true, recursive splittings will be stored.
std::string GetKeyFromMapValue(const T &value, const std::map< std::string, T > &valuesMap) const
TTree * fTreeSubstructure
! Tree with tagging variables subtracted MC or true MC or raw
TCanvas * c
Definition: TestFitELoss.C:172
SubstructureTree::JetSubstructureSplittings fDataJetSplittings
Data jet splittings.
std::vector< float > fDeltaR
Delta R between the subjets.
PWG::Tools::AliYAMLConfiguration fYAMLConfig
YAML configuration file.
UShort_t T(UShort_t m, UShort_t t)
Definition: RingBits.C:60
TString kData
Declare data MC or deltaAOD.
SubstructureTree::JetSubstructureSplittings fMatchedJetSplittings
Matched jet splittings.
std::vector< bool > fPartOfIterativeSplitting
True if the splitting is follow an iterative splitting.
Float_t fMinFractionShared
Only fill histos for jets if shared fraction larger than X.
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
std::vector< float > fZ
Momentum sharing of the splitting.
static const std::map< std::string, JetShapeType_t > fgkJetShapeTypeMap
! Map from name to jet shape type used with the YAML config
std::vector< unsigned int > fGlobalIndex
Jet constituent global index.
JetSelectionType_t fJetSelection
Jet selection: inclusive/recoil jet.
SubstructureTree::JetSubstructureSplittings fDetLevelJetSplittings
Det level (intermediate match) jet splittings.
void AddConfigurationFile(const std::string &configurationPath, const std::string &configName="")
Definition: External.C:220
static const std::map< std::string, JetShapeSub_t > fgkJetShapeSubMap
! Map from name to jet shape sub used with the YAML config
static const std::map< std::string, JetSelectionType_t > fgkJetSelectionMap
! Map from name to jet selection used with the YAML config
YAML configuration class for AliPhysics.
Bool_t fCutDoubleCounts
turn off to avoid true-hybrid cuts to suppress double counting
Base task in the EMCAL jet framework.
Represent a jet reconstructed using the EMCal jet framework.
Definition: AliEmcalJet.h:51
std::vector< std::vector< unsigned short > > fConstituentIndices
Constituent jet indices (ie. index by the stored jet constituents, not the global index)...
const char Option_t
Definition: External.C:48
Bool_t fStoreDetLevelJets
If True, store the detector level jet quantities.
bool Bool_t
Definition: External.C:53
void swap(PWGJE::EMCALJetTasks::SubstructureTree::Subjets &first, PWGJE::EMCALJetTasks::SubstructureTree::Subjets &second)
static const std::map< std::string, DerivSubtrOrder_t > fgkDerivSubtrOrderMap
! Map from name to derivative subtracter order used with the YAML config
Float_t fSubjetCutoff
angular cutoff for subjets at det/gen level
Container for jet within the EMCAL jet framework.
Definition: External.C:196
THnSparse * fHCheckResolutionSubjets
! To evaluate energy resolution of subjets as function of aperture angle
bool fConfigurationInitialized
True if the task configuration has been successfully initialized.