HiggsAnalysis-KITHiggsToTauTau
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SvfitTools.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "Artus/Utility/interface/ArtusLogging.h"
5 
6 #include <map>
7 
8 #include <TChain.h>
9 #include <TMemFile.h>
10 
11 #include "TauAnalysis/ClassicSVfit/interface/ClassicSVfit.h"
12 #include "TauAnalysis/ClassicSVfit/interface/MeasuredTauLepton.h"
13 #include "TauAnalysis/ClassicSVfit/interface/svFitHistogramAdapter.h"
14 
15 #include "Kappa/DataFormats/interface/Kappa.h"
16 
17 #include "HiggsAnalysis/KITHiggsToTauTau/interface/HttEnumTypes.h"
18 #include "HiggsAnalysis/KITHiggsToTauTau/interface/Utility/CPQuantities.h"
19 
20 
21 typedef ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<float>,ROOT::Math::DefaultCoordinateSystemTag> RMDataV;
22 typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > RMSM2x2;
23 
24 
25 class PhiCPSVfitQuantity : public classic_svFit::SVfitQuantity
26 {
27 public:
28  virtual TH1* createHistogram(const classic_svFit::LorentzVector& vis1P4, const classic_svFit::LorentzVector& vis2P4, const classic_svFit::Vector& met) const;
29  virtual double fitFunction(const classic_svFit::LorentzVector& tau1P4, const classic_svFit::LorentzVector& tau2P4, const classic_svFit::LorentzVector& vis1P4, const classic_svFit::LorentzVector& vis2P4, const classic_svFit::Vector& met) const;
30 
31 private:
32  mutable CPQuantities cpQuantities;
33 };
34 
35 class PhiStarCPSVfitQuantity : public classic_svFit::SVfitQuantity
36 {
37 public:
38  virtual TH1* createHistogram(const classic_svFit::LorentzVector& vis1P4, const classic_svFit::LorentzVector& vis2P4, const classic_svFit::Vector& met) const;
39  virtual double fitFunction(const classic_svFit::LorentzVector& tau1P4, const classic_svFit::LorentzVector& tau2P4, const classic_svFit::LorentzVector& vis1P4, const classic_svFit::LorentzVector& vis2P4, const classic_svFit::Vector& met) const;
40 
41 private:
42  mutable CPQuantities cpQuantities;
43 };
44 
45 class TauTauHistogramAdapter : public classic_svFit::TauTauHistogramAdapter
46 {
47 
48 public:
49  TauTauHistogramAdapter(std::vector<classic_svFit::SVfitQuantity*> const& quantities = std::vector<classic_svFit::SVfitQuantity*>());
50 
51  RMFLV GetFittedHiggsLV() const;
52 
53  float GetFittedTau1ERatio() const;
54  RMFLV GetFittedTau1LV() const;
55 
56  float GetFittedTau2ERatio() const;
57  RMFLV GetFittedTau2LV() const;
58 
59 private:
60  unsigned int indexTau1ERatio = 0;
61  unsigned int indexTau2ERatio = 0;
62 };
63 
67 
68 public:
69  ULong64_t runLumiEvent;
72  int decayMode1 = 0;
73  int decayMode2 = 0;
76  float diTauMassConstraint = -1.0;
77  float kappa = -1.0;
78 
80  SvfitEventKey(ULong64_t const& runLumiEvent,
81  classic_svFit::MeasuredTauLepton::kDecayType const& decayType1, classic_svFit::MeasuredTauLepton::kDecayType const& decayType2,
82  int const& decayMode1, int const& decayMode2,
84  float const& diTauMassConstraint, float const& kappa);
85 
86  void Set(ULong64_t const& runLumiEvent,
87  classic_svFit::MeasuredTauLepton::kDecayType const& decayType1, classic_svFit::MeasuredTauLepton::kDecayType const& decayType2,
88  int const& decayMode1, int const& decayMode2,
90  float const& diTauMassConstraint, float const& kappa);
91 
93 
94  void CreateBranches(TTree* tree);
95  void SetBranchAddresses(TTree* tree);
96  void ActivateBranches(TTree* tree, bool activate=true);
97 
98  bool operator<(SvfitEventKey const& rhs) const;
99  bool operator==(SvfitEventKey const& rhs) const;
100  bool operator!=(SvfitEventKey const& rhs) const;
101 };
102 
103 namespace std {
104  string to_string(SvfitEventKey const& svfitEventKey);
105 }
106 
107 std::ostream& operator<<(std::ostream& os, SvfitEventKey const& svfitEventKey);
108 
109 
112 class SvfitInputs {
113 
114 public:
115  RMFLV* leptonMomentum1 = 0;
116  RMFLV* leptonMomentum2 = 0;
119 
121  SvfitInputs(RMFLV const& leptonMomentum1, RMFLV const& leptonMomentum2,
122  RMDataV const& metMomentum, RMSM2x2 const& metCovariance);
123  ~SvfitInputs();
124 
125  void Set(RMFLV const& leptonMomentum1, RMFLV const& leptonMomentum2,
126  RMDataV const& metMomentum, RMSM2x2 const& metCovariance);
127 
128  void CreateBranches(TTree* tree);
129  void SetBranchAddresses(TTree* tree);
130  void ActivateBranches(TTree* tree, bool activate=true);
131 
132  bool operator==(SvfitInputs const& rhs) const;
133  bool operator!=(SvfitInputs const& rhs) const;
134 
135  void Integrate(SvfitEventKey const& svfitEventKey, ClassicSVfit& svfitAlgorithm) const;
136 
137 private:
138  std::vector<classic_svFit::MeasuredTauLepton> GetMeasuredTauLeptons(SvfitEventKey const& svfitEventKey) const;
139  TMatrixD GetMetCovarianceMatrix() const;
140 };
141 
142 
146 
147 public:
149  RMFLV* fittedHiggsLV = nullptr;
151  RMFLV* fittedTau1LV = nullptr;
153  RMFLV* fittedTau2LV = nullptr;
154 
156  SvfitResults(double fittedTransverseMass, RMFLV const& fittedHiggsLV, float fittedTau1ERatio, RMFLV const& fittedTau1LV, float fittedTau2ERatio, RMFLV const& fittedTau2LV);
157  SvfitResults(ClassicSVfit const& svfitAlgorithm);
158  ~SvfitResults();
159 
160  void Set(double fittedTransverseMass, RMFLV const& fittedHiggsLV, float fittedTau1ERatio, RMFLV const& fittedTau1LV, float fittedTau2ERatio, RMFLV const& fittedTau2LV);
161  void Set(ClassicSVfit const& svfitAlgorithm);
162  inline void FromRecalculation() { recalculated = true; }
163  inline void FromCache() { recalculated = false; }
164 
165  void CreateBranches(TTree* tree);
166  void SetBranchAddresses(TTree* tree);
167  void ActivateBranches(TTree* tree, bool activate=true);
168 
169  bool operator==(SvfitResults const& rhs) const;
170  bool operator!=(SvfitResults const& rhs) const;
171 
173 
174 private:
175  double GetFittedTransverseMass(ClassicSVfit const& svfitAlgorithm) const;
176  RMFLV GetFittedHiggsLV(ClassicSVfit const& svfitAlgorithm) const;
177  float GetFittedTau1ERatio(ClassicSVfit const& svfitAlgorithm) const;
178  RMFLV GetFittedTau1LV(ClassicSVfit const& svfitAlgorithm) const;
179  float GetFittedTau2ERatio(ClassicSVfit const& svfitAlgorithm) const;
180  RMFLV GetFittedTau2LV(ClassicSVfit const& svfitAlgorithm) const;
181 };
182 
183 
186 class SvfitTools {
187 
188 public:
189  SvfitTools();
190  ~SvfitTools();
191 
192  void Init(std::string const& cacheFileName, std::string const& cacheTreeName);
193  SvfitResults GetResults(SvfitEventKey const& svfitEventKey, SvfitInputs const& svfitInputs,
194  HttEnumTypes::SvfitCacheMissBehaviour svfitCacheMissBehaviour);
195 
196 private:
197  ClassicSVfit svfitAlgorithm;
198 
199  static std::map<std::string, TFile*> svfitCacheInputFiles;
200  static std::map<std::string, TTree*> svfitCacheInputTrees;
201  static std::map<std::string, std::map<SvfitEventKey, uint64_t> > svfitCacheInputTreeIndices;
202 
203  std::string cacheFileName;
204  std::string cacheFileTreeName;
205 
206  SvfitEventKey svfitEventKey;
207  SvfitInputs svfitInputs;
208  SvfitResults svfitResults;
209 };
void SetBranchAddresses(TTree *tree)
Definition: SvfitTools.cc:117
SvfitCacheMissBehaviour
Definition: HttEnumTypes.h:92
Place to collect functions calculating CP quantities -Phi* : this is a variable, with which one can s...
Definition: CPQuantities.h:19
void ActivateBranches(TTree *tree, bool activate=true)
Definition: SvfitTools.cc:131
float diTauMassConstraint
Definition: SvfitTools.h:76
~SvfitTools()
Definition: SvfitTools.cc:660
RMFLV GetFittedHiggsLV() const
Definition: SvfitTools.cc:45
Definition: SvfitTools.h:35
virtual double fitFunction(const classic_svFit::LorentzVector &tau1P4, const classic_svFit::LorentzVector &tau2P4, const classic_svFit::LorentzVector &vis1P4, const classic_svFit::LorentzVector &vis2P4, const classic_svFit::Vector &met) const
Definition: SvfitTools.cc:13
std::ostream & operator<<(std::ostream &os, SvfitEventKey const &svfitEventKey)
Definition: SvfitTools.cc:236
SvfitResults()
Definition: SvfitTools.h:155
float fittedTau2ERatio
Definition: SvfitTools.h:152
float systematicShiftSigma
Definition: SvfitTools.h:75
void SetBranchAddresses(TTree *tree)
Definition: SvfitTools.cc:304
Definition: SvfitTools.h:112
string to_string(TauSpinner::SimpleParticle &particle)
Definition: TauSpinnerProducer.cc:247
SvfitResults GetResults(SvfitEventKey const &svfitEventKey, SvfitInputs const &svfitInputs, HttEnumTypes::SvfitCacheMissBehaviour svfitCacheMissBehaviour)
Definition: SvfitTools.cc:615
bool operator!=(SvfitEventKey const &rhs) const
Definition: SvfitTools.cc:217
SvfitInputs()
Definition: SvfitTools.h:120
SystematicShift
Definition: HttEnumTypes.h:73
bool operator!=(SvfitInputs const &rhs) const
Definition: SvfitTools.cc:329
RMFLV * fittedTau1LV
Definition: SvfitTools.h:151
~SvfitInputs()
Definition: SvfitTools.cc:248
float GetFittedTau1ERatio() const
Definition: SvfitTools.cc:51
RMFLV GetFittedTau1LV() const
Definition: SvfitTools.cc:56
virtual TH1 * createHistogram(const classic_svFit::LorentzVector &vis1P4, const classic_svFit::LorentzVector &vis2P4, const classic_svFit::Vector &met) const
Definition: SvfitTools.cc:9
virtual double fitFunction(const classic_svFit::LorentzVector &tau1P4, const classic_svFit::LorentzVector &tau2P4, const classic_svFit::LorentzVector &vis1P4, const classic_svFit::LorentzVector &vis2P4, const classic_svFit::Vector &met) const
Definition: SvfitTools.cc:28
tuple tree
Definition: makePlots_datacardsCPStudies_projection.py:223
bool operator==(SvfitResults const &rhs) const
Definition: SvfitTools.cc:495
int decayType1
Definition: SvfitTools.h:70
RMDataV * metMomentum
Definition: SvfitTools.h:117
RMFLV * leptonMomentum1
Definition: SvfitTools.h:115
void Set(RMFLV const &leptonMomentum1, RMFLV const &leptonMomentum2, RMDataV const &metMomentum, RMSM2x2 const &metCovariance)
Definition: SvfitTools.cc:270
SvfitTools()
Definition: SvfitTools.cc:540
bool operator==(SvfitEventKey const &rhs) const
Definition: SvfitTools.cc:204
void CreateBranches(TTree *tree)
Definition: SvfitTools.cc:104
void Set(ULong64_t const &runLumiEvent, classic_svFit::MeasuredTauLepton::kDecayType const &decayType1, classic_svFit::MeasuredTauLepton::kDecayType const &decayType2, int const &decayMode1, int const &decayMode2, HttEnumTypes::SystematicShift const &systematicShift, float const &systematicShiftSigma, float const &diTauMassConstraint, float const &kappa)
Definition: SvfitTools.cc:82
void Set(double fittedTransverseMass, RMFLV const &fittedHiggsLV, float fittedTau1ERatio, RMFLV const &fittedTau1LV, float fittedTau2ERatio, RMFLV const &fittedTau2LV)
Definition: SvfitTools.cc:419
void SetBranchAddresses(TTree *tree)
Definition: SvfitTools.cc:474
float kappa
Definition: SvfitTools.h:77
Definition: SvfitTools.h:66
virtual TH1 * createHistogram(const classic_svFit::LorentzVector &vis1P4, const classic_svFit::LorentzVector &vis2P4, const classic_svFit::Vector &met) const
Definition: SvfitTools.cc:24
void Init(std::string const &cacheFileName, std::string const &cacheTreeName)
Definition: SvfitTools.cc:546
RMFLV * fittedTau2LV
Definition: SvfitTools.h:153
Definition: SvfitTools.h:186
bool operator==(SvfitInputs const &rhs) const
Definition: SvfitTools.cc:321
float fittedTau1ERatio
Definition: SvfitTools.h:150
int decayMode1
Definition: SvfitTools.h:72
RMFLV * fittedHiggsLV
Definition: SvfitTools.h:149
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::DefaultCoordinateSystemTag > RMDataV
Definition: SvfitTools.h:21
double fittedTransverseMass
Definition: SvfitTools.h:148
void CreateBranches(TTree *tree)
Definition: SvfitTools.cc:464
~SvfitResults()
Definition: SvfitTools.cc:401
bool operator!=(SvfitResults const &rhs) const
Definition: SvfitTools.cc:505
int decayMode2
Definition: SvfitTools.h:73
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::DefaultCoordinateSystemTag > RMDataV
Place to collect functions calculating generic physical quantities -Mt: transverse mass...
Definition: Quantities.h:14
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > RMSM2x2
Definition: SvfitTools.h:22
void ActivateBranches(TTree *tree, bool activate=true)
Definition: SvfitTools.cc:485
bool recalculated
Definition: SvfitTools.h:172
HttEnumTypes::SystematicShift GetSystematicShift() const
Definition: SvfitTools.cc:99
int decayType2
Definition: SvfitTools.h:71
RMSM2x2 * metCovariance
Definition: SvfitTools.h:118
Definition: SvfitTools.h:25
void CreateBranches(TTree *tree)
Definition: SvfitTools.cc:296
TauTauHistogramAdapter(std::vector< classic_svFit::SVfitQuantity * > const &quantities=std::vector< classic_svFit::SVfitQuantity * >())
Definition: SvfitTools.cc:38
void Integrate(SvfitEventKey const &svfitEventKey, ClassicSVfit &svfitAlgorithm) const
Definition: SvfitTools.cc:334
Definition: SvfitTools.h:145
int systematicShift
Definition: SvfitTools.h:74
RMFLV * leptonMomentum2
Definition: SvfitTools.h:116
ULong64_t runLumiEvent
Definition: SvfitTools.h:69
RMFLV GetFittedTau2LV() const
Definition: SvfitTools.cc:66
void ActivateBranches(TTree *tree, bool activate=true)
Definition: SvfitTools.cc:313
Definition: SvfitTools.h:45
void FromCache()
Definition: SvfitTools.h:163
bool operator<(SvfitEventKey const &rhs) const
Definition: SvfitTools.cc:144
float GetFittedTau2ERatio() const
Definition: SvfitTools.cc:61
void FromRecalculation()
Definition: SvfitTools.h:162
SvfitEventKey()
Definition: SvfitTools.h:79