CMS 3D CMS Logo

TopHLTOfflineDQMHelper.cc
Go to the documentation of this file.
2 #include <iostream>
3 /*Originally from DQM/Physics package, written by Roger Wolf and Jeremy Andrea*/
4 
5 using namespace std;
6 
8 template <>
10 {
11  // fetch input collection
13  if( !event.getByToken(src_, src) ) return false;
14 
15  // load btag collection if configured such
16  // NOTE that the JetTagCollection needs an
17  // edm::View to reco::Jets; we have to add
18  // another Handle bjets for this purpose
22  if(!btagLabel_.isUninitialized()){
23  if( !event.getByToken(src_, bjets) ) return false;
24  if( !event.getByToken(btagLabel_, btagger) ) return false;
25  if( !event.getByToken(pvs_, pvertex) ) return false;
26  }
27 
28  // load jetID value map if configured such
30  if(jetIDSelect_){
31  if( !event.getByToken(jetIDLabel_, jetID) ) return false;
32 
33  }
34 
35  // load jet corrector if configured such
36  const JetCorrector* corrector=nullptr;
37  if(!jetCorrector_.empty()){
38  // check whether a jet correcto is in the event setup or not
39  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
40  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
41  }
42  else{
43  edm::LogVerbatim( "TopHLTOfflineDQMHelper" )
44  << "\n"
45  << "------------------------------------------------------------------------------------- \n"
46  << " No JetCorrectionsRecord available from EventSetup: \n"
47  << " - Jets will not be corrected. \n"
48  << " - If you want to change this add the following lines to your cfg file \n"
49  << " \n"
50  << " ## load jet corrections \n"
51  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
52  << " process.prefer(\"ak5CaloL2L3\") \n"
53  << " \n"
54  << "------------------------------------------------------------------------------------- \n";
55  }
56  }
57  // determine multiplicity of selected objects
58  int n=0;
59  for(typename edm::View<reco::Jet>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
60  // check for chosen btag discriminator to be above the
61  // corresponding working point if configured such
62  unsigned int idx = obj-src->begin();
63  if( btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
64  bool passedJetID=true;
65  // check jetID for calo jets
66  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
67  passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
68  }
69  if(passedJetID){
70  // scale jet energy if configured such
71  reco::Jet jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
72  if(select_(jet))++n;
73  }
74  }
75  }
76  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
77  return (min_<0 && max_<0) ? (n>0):accept;
78 }
79 
80 
82  failed_(false), maxNJets_(maxNJets), wMass_(wMass), massWBoson_(-1.), massTopQuark_(-1.),tmassWBoson_(-1),tmassTopQuark_(-1),mlb_(-1)
83 {
84 }
85 
86 
87 double
88 CalculateHLT::massWBoson(const std::vector<reco::Jet>& jets)
89 {
90  if(!failed_&& massWBoson_<0) operator()(jets);
91  return massWBoson_;
92 }
93 
94 
95 double
96 CalculateHLT::massTopQuark(const std::vector<reco::Jet>& jets)
97 {
98  if(!failed_&& massTopQuark_<0) operator()(jets);
99  return massTopQuark_;
100 }
101 
102 /*
103 double
104 Calculate::tmassWBoson(const T& mu, const reco::MET& met, const reco::Jet& b)
105 {
106  if(!failed_&& tmassWBoson_<0) operator()(b,mu,met); return tmassWBoson_;
107 }
108 
109 
110 double
111 Calculate::masslb(const T& mu, const reco::MET& met, const reco::Jet& b)
112 {
113  if(!failed_&& mlb_<0) operator()(b,mu,met); return mlb_;
114 }
115 
116 
117 double
118 Calculate::tmassTopQuark(const T& lepton, const reco::MET& met, const reco::Jet& b)
119 {
120  if(!failed_&& tmassTopQuark_<0) operator()(b,lepton,met); return tmassTopQuark_;
121 }
122 
123 
124 void Calculate::operator()( const reco::Jet& bJet, const T& lepton, const reco::MET& met){
125  reco::Particle::LorentzVector WT = lepton.p4() + met.p4();
126  tmassWBoson_ = sqrt((WT.px()*WT.px()) + (WT.py()*WT.py()));
127  reco::Particle::LorentzVector topT = WT + bJet.p4();
128  tmassTopQuark_ = sqrt((topT.px()*topT.px()) + (topT.py()*topT.py()));
129  reco::Particle::LorentzVector lb = bJet.p4() + lepton.p4();
130  mlb_ = lb.mass();
131 }*/
132 
133 
134 double
136 {
137  if(!failed_&& tmassWBoson_<0) operator()(b,mu,met);
138  return tmassWBoson_;
139 }
140 
141 
142 double
144 {
145  if(!failed_&& mlb_<0) operator()(b,mu,met);
146  return mlb_;
147 }
148 
149 
150 double
152 {
153  if(!failed_&& tmassTopQuark_<0) operator()(b,lepton,met);
154  return tmassTopQuark_;
155 }
156 
157 
159  double metT = sqrt(pow(met.px(),2) + pow(met.py(),2));
160  double lepT = sqrt(pow(lepton->px(),2) + pow(lepton->py(),2));
161  double bT = sqrt(pow(bJet.px(),2) + pow(bJet.py(),2));
162  reco::Particle::LorentzVector WT = lepton->p4() + met.p4();
163  // cout<<"in calculate:\n\t"<<bJet.pt()<<"\t"<<lepton->pt()<<"\t"<<met.pt()<<endl;
164  tmassWBoson_ = sqrt(pow(metT+lepT,2) - (WT.px()*WT.px()) - (WT.py()*WT.py()));
165  reco::Particle::LorentzVector topT = WT + bJet.p4();
166  tmassTopQuark_ = sqrt(pow((metT+lepT+bT),2) - (topT.px()*topT.px()) - (topT.py()*topT.py()));
167  reco::Particle::LorentzVector lb = bJet.p4() + lepton->p4();
168  mlb_ = lb.mass();
169 }
170 
171 
172 void
173 CalculateHLT::operator()(const std::vector<reco::Jet>& jets)
174 {
175 
176  if(maxNJets_<0) maxNJets_=jets.size();
177  failed_= jets.size()<(unsigned int) maxNJets_;
178  if( failed_){ return; }
179 
180  // associate those jets with maximum pt of the vectorial
181  // sum to the hadronic decay chain
182  double maxPt=-1.;
183  std::vector<int> maxPtIndices;
184  maxPtIndices.push_back(-1);
185  maxPtIndices.push_back(-1);
186  maxPtIndices.push_back(-1);
187  for(int idx=0; idx<maxNJets_; ++idx){
188  for(int jdx=0; jdx<maxNJets_; ++jdx){ if(jdx<=idx) continue;
189  for(int kdx=0; kdx<maxNJets_; ++kdx){ if(kdx==idx || kdx==jdx) continue;
190  reco::Particle::LorentzVector sum = jets[idx].p4()+jets[jdx].p4()+jets[kdx].p4();
191  if( maxPt<0. || maxPt<sum.pt() ){
192  maxPt=sum.pt();
193  maxPtIndices.clear();
194  maxPtIndices.push_back(idx);
195  maxPtIndices.push_back(jdx);
196  maxPtIndices.push_back(kdx);
197  }
198  }
199  }
200  }
201  massTopQuark_= (jets[maxPtIndices[0]].p4()+
202  jets[maxPtIndices[1]].p4()+
203  jets[maxPtIndices[2]].p4()).mass();
204 
205  // associate those jets that get closest to the W mass
206  // with their invariant mass to the W boson
207  double wDist =-1.;
208  std::vector<int> wMassIndices;
209  wMassIndices.push_back(-1);
210  wMassIndices.push_back(-1);
211  for(unsigned idx=0; idx<maxPtIndices.size(); ++idx){
212  for(unsigned jdx=0; jdx<maxPtIndices.size(); ++jdx){
213  if( jdx==idx || maxPtIndices[idx]>maxPtIndices[jdx] ) continue;
214  reco::Particle::LorentzVector sum = jets[maxPtIndices[idx]].p4()+jets[maxPtIndices[jdx]].p4();
215  if( wDist<0. || wDist>fabs(sum.mass()-wMass_) ){
216  wDist=fabs(sum.mass()-wMass_);
217  wMassIndices.clear();
218  wMassIndices.push_back(maxPtIndices[idx]);
219  wMassIndices.push_back(maxPtIndices[jdx]);
220  }
221  }
222  }
223  massWBoson_= (jets[wMassIndices[0]].p4()+
224  jets[wMassIndices[1]].p4()).mass();
225 }
226 
227 
228 
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &iKey) const
Definition: EventSetup.h:160
bool failed_
indicate failed associations
virtual void scaleEnergy(double fScale)
scale energy of the jet
bool select(const edm::Event &event) override
apply selection
double masslb(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate mlb estimate
double massTopQuark(const std::vector< reco::Jet > &jets)
calculate top quark mass estimate
void operator()(const std::vector< reco::Jet > &jets)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
double wMass_
paramater of the w boson mass
Base class for all types of Jets.
Definition: Jet.h:20
double px() const final
x coordinate of momentum vector
double tmassTopQuark(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate top quark transverse mass estimate
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
double massWBoson(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
CalculateHLT(int maxNJets, double wMass)
default constructor
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
double massWBoson_
cache of w boson mass estimate
double mlb_
cache of mlb estimate
Definition: MET.h:42
T sqrt(T t)
Definition: SSEVec.h:18
vector< PseudoJet > jets
double massTopQuark_
cache of top quark mass estimate
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
const int mu
Definition: Constants.h:22
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
maxNJets
maximum number of jets taken into account per event for each hypothesis (this parameter is used in th...
double tmassWBoson(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate W boson transverse mass estimate
met
===> hadronic RAZOR
double tmassWBoson_
cache of W boson transverse mass estimate
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:50
double b
Definition: hdecay.h:120
double py() const final
y coordinate of momentum vector
int maxNJets_
max. number of jets to be considered
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
double tmassTopQuark_
cache of top quark transverse mass estimate
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Definition: event.py:1