CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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=0;
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); return massWBoson_;
91 }
92 
93 
94 double
95 CalculateHLT::massTopQuark(const std::vector<reco::Jet>& jets)
96 {
97  if(!failed_&& massTopQuark_<0) operator()(jets); return massTopQuark_;
98 }
99 
100 /*
101 double
102 Calculate::tmassWBoson(const T& mu, const reco::MET& met, const reco::Jet& b)
103 {
104  if(!failed_&& tmassWBoson_<0) operator()(b,mu,met); return tmassWBoson_;
105 }
106 
107 
108 double
109 Calculate::masslb(const T& mu, const reco::MET& met, const reco::Jet& b)
110 {
111  if(!failed_&& mlb_<0) operator()(b,mu,met); return mlb_;
112 }
113 
114 
115 double
116 Calculate::tmassTopQuark(const T& lepton, const reco::MET& met, const reco::Jet& b)
117 {
118  if(!failed_&& tmassTopQuark_<0) operator()(b,lepton,met); return tmassTopQuark_;
119 }
120 
121 
122 void Calculate::operator()( const reco::Jet& bJet, const T& lepton, const reco::MET& met){
123  reco::Particle::LorentzVector WT = lepton.p4() + met.p4();
124  tmassWBoson_ = sqrt((WT.px()*WT.px()) + (WT.py()*WT.py()));
125  reco::Particle::LorentzVector topT = WT + bJet.p4();
126  tmassTopQuark_ = sqrt((topT.px()*topT.px()) + (topT.py()*topT.py()));
127  reco::Particle::LorentzVector lb = bJet.p4() + lepton.p4();
128  mlb_ = lb.mass();
129 }*/
130 
131 
132 double
134 {
135  if(!failed_&& tmassWBoson_<0) operator()(b,mu,met); return tmassWBoson_;
136 }
137 
138 
139 double
141 {
142  if(!failed_&& mlb_<0) operator()(b,mu,met); return mlb_;
143 }
144 
145 
146 double
148 {
149  if(!failed_&& tmassTopQuark_<0) operator()(b,lepton,met); return tmassTopQuark_;
150 }
151 
152 
154  double metT = sqrt(pow(met.px(),2) + pow(met.py(),2));
155  double lepT = sqrt(pow(lepton->px(),2) + pow(lepton->py(),2));
156  double bT = sqrt(pow(bJet.px(),2) + pow(bJet.py(),2));
157  reco::Particle::LorentzVector WT = lepton->p4() + met.p4();
158  // cout<<"in calculate:\n\t"<<bJet.pt()<<"\t"<<lepton->pt()<<"\t"<<met.pt()<<endl;
159  tmassWBoson_ = sqrt(pow(metT+lepT,2) - (WT.px()*WT.px()) - (WT.py()*WT.py()));
160  reco::Particle::LorentzVector topT = WT + bJet.p4();
161  tmassTopQuark_ = sqrt(pow((metT+lepT+bT),2) - (topT.px()*topT.px()) - (topT.py()*topT.py()));
162  reco::Particle::LorentzVector lb = bJet.p4() + lepton->p4();
163  mlb_ = lb.mass();
164 }
165 
166 
167 void
168 CalculateHLT::operator()(const std::vector<reco::Jet>& jets)
169 {
170 
171  if(maxNJets_<0) maxNJets_=jets.size();
172  failed_= jets.size()<(unsigned int) maxNJets_;
173  if( failed_){ return; }
174 
175  // associate those jets with maximum pt of the vectorial
176  // sum to the hadronic decay chain
177  double maxPt=-1.;
178  std::vector<int> maxPtIndices;
179  maxPtIndices.push_back(-1);
180  maxPtIndices.push_back(-1);
181  maxPtIndices.push_back(-1);
182  for(int idx=0; idx<maxNJets_; ++idx){
183  for(int jdx=0; jdx<maxNJets_; ++jdx){ if(jdx<=idx) continue;
184  for(int kdx=0; kdx<maxNJets_; ++kdx){ if(kdx==idx || kdx==jdx) continue;
185  reco::Particle::LorentzVector sum = jets[idx].p4()+jets[jdx].p4()+jets[kdx].p4();
186  if( maxPt<0. || maxPt<sum.pt() ){
187  maxPt=sum.pt();
188  maxPtIndices.clear();
189  maxPtIndices.push_back(idx);
190  maxPtIndices.push_back(jdx);
191  maxPtIndices.push_back(kdx);
192  }
193  }
194  }
195  }
196  massTopQuark_= (jets[maxPtIndices[0]].p4()+
197  jets[maxPtIndices[1]].p4()+
198  jets[maxPtIndices[2]].p4()).mass();
199 
200  // associate those jets that get closest to the W mass
201  // with their invariant mass to the W boson
202  double wDist =-1.;
203  std::vector<int> wMassIndices;
204  wMassIndices.push_back(-1);
205  wMassIndices.push_back(-1);
206  for(unsigned idx=0; idx<maxPtIndices.size(); ++idx){
207  for(unsigned jdx=0; jdx<maxPtIndices.size(); ++jdx){
208  if( jdx==idx || maxPtIndices[idx]>maxPtIndices[jdx] ) continue;
209  reco::Particle::LorentzVector sum = jets[maxPtIndices[idx]].p4()+jets[maxPtIndices[jdx]].p4();
210  if( wDist<0. || wDist>fabs(sum.mass()-wMass_) ){
211  wDist=fabs(sum.mass()-wMass_);
212  wMassIndices.clear();
213  wMassIndices.push_back(maxPtIndices[idx]);
214  wMassIndices.push_back(maxPtIndices[jdx]);
215  }
216  }
217  }
218  massWBoson_= (jets[wMassIndices[0]].p4()+
219  jets[wMassIndices[1]].p4()).mass();
220 }
221 
222 
223 
bool failed_
indicate failed associations
virtual void scaleEnergy(double fScale)
scale energy of the jet
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:449
double wMass_
paramater of the w boson mass
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
Base class for all types of Jets.
Definition: Jet.h:20
double tmassTopQuark(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate top quark transverse mass estimate
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:25
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
double massWBoson_
cache of w boson mass estimate
double mlb_
cache of mlb estimate
tuple corrector
Definition: mvaPFMET_cff.py:89
Definition: MET.h:42
T sqrt(T t)
Definition: SSEVec.h:48
vector< PseudoJet > jets
double massTopQuark_
cache of top quark mass estimate
const int mu
Definition: Constants.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual bool select(const edm::Event &event)
apply selection
double tmassWBoson(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate W boson transverse mass estimate
virtual double px() const
x coordinate of momentum vector
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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
int maxNJets_
max. number of jets to be considered
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
volatile std::atomic< bool > shutdown_flag false
double tmassTopQuark_
cache of top quark transverse mass estimate
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual double py() const
y coordinate of momentum vector
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40