Go to the documentation of this file.00001 #ifndef TOPDQMHELPERS
00002 #define TOPDQMHELPERS
00003
00004 #include <string>
00005 #include <vector>
00006
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Common/interface/TriggerNames.h"
00009 #include "DataFormats/Common/interface/TriggerResults.h"
00010 #include "DataFormats/VertexReco/interface/Vertex.h"
00011
00021 inline bool
00022 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::string& triggerPath)
00023 {
00024 bool passed=false;
00025 const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
00026 for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
00027 if(triggerNames.triggerNames()[i] == triggerPath) {
00028 if(triggerTable.accept(i)){
00029 passed=true;
00030 break;
00031 }
00032 }
00033 }
00034 return passed;
00035 }
00036
00037 inline bool
00038 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::vector<std::string>& triggerPaths)
00039 {
00040 bool passed=false;
00041 for(unsigned int j=0; j<triggerPaths.size(); ++j){
00042 if(accept(event, triggerTable, triggerPaths[j])){
00043 passed=true;
00044 break;
00045 }
00046 }
00047 return passed;
00048 }
00049
00050
00051 #include "DataFormats/JetReco/interface/Jet.h"
00052 #include "FWCore/Framework/interface/EventSetup.h"
00053
00065 class Calculate {
00066 public:
00068 Calculate(int maxNJets, double wMass);
00070 ~Calculate(){};
00071
00073 double massWBoson(const std::vector<reco::Jet>& jets);
00075 double massTopQuark(const std::vector<reco::Jet>& jets);
00076
00077 private:
00081 void operator()(const std::vector<reco::Jet>& jets);
00082
00083 private:
00085 bool failed_;
00087 int maxNJets_;
00089 double wMass_;
00091 double massWBoson_;
00093 double massTopQuark_;
00094 };
00095
00096
00097 #include "DataFormats/JetReco/interface/JetID.h"
00098 #include "DataFormats/JetReco/interface/PFJet.h"
00099 #include "DataFormats/JetReco/interface/CaloJet.h"
00100 #include "DataFormats/BTauReco/interface/JetTag.h"
00101 #include "DataFormats/Common/interface/ValueMap.h"
00102 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00103 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00104 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00105 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00106 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
00107
00148 template <typename Object>
00149 class SelectionStep {
00150 public:
00152 SelectionStep(const edm::ParameterSet& cfg);
00154 ~SelectionStep(){};
00155
00157 bool select(const edm::Event& event);
00159 bool select(const edm::Event& event, const edm::EventSetup& setup);
00160 bool selectVertex(const edm::Event& event);
00161 private:
00163 edm::InputTag src_;
00165 int min_, max_;
00167 edm::InputTag electronId_;
00178 int eidPattern_;
00180 std::string jetCorrector_;
00182 edm::InputTag btagLabel_;
00184 double btagWorkingPoint_;
00186 edm::InputTag jetIDLabel_;
00187
00188 edm::InputTag pvs_;
00189
00191 StringCutObjectSelector<Object> select_;
00193 StringCutObjectSelector<reco::JetID>* jetIDSelect_;
00194 };
00195
00197 template <typename Object>
00198 SelectionStep<Object>::SelectionStep(const edm::ParameterSet& cfg) :
00199 src_( cfg.getParameter<edm::InputTag>( "src" )),
00200 select_( cfg.getParameter<std::string>("select")),
00201 jetIDSelect_(0)
00202 {
00203
00204
00205 cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
00206 cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
00207
00208 if(cfg.existsAs<edm::ParameterSet>("electronId")){
00209 edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
00210 electronId_= elecId.getParameter<edm::InputTag>("src");
00211 eidPattern_= elecId.getParameter<int>("pattern");
00212 }
00213
00214 if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
00215
00216 if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
00217 edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
00218 btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
00219 btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
00220 }
00221
00222 if(cfg.existsAs<edm::ParameterSet>("jetID")){
00223 edm::ParameterSet jetID=cfg.getParameter<edm::ParameterSet>("jetID");
00224 jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
00225 jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
00226 }
00227 }
00228
00230 template <typename Object>
00231 bool SelectionStep<Object>::select(const edm::Event& event)
00232 {
00233
00234 edm::Handle<edm::View<Object> > src;
00235 if( !event.getByLabel(src_, src) ) return false;
00236
00237
00238 edm::Handle<edm::ValueMap<float> > electronId;
00239 if(!electronId_.label().empty()) {
00240 if( !event.getByLabel(electronId_, electronId) ) return false;
00241 }
00242
00243
00244 int n=0;
00245 for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00246
00247 if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
00248 unsigned int idx = obj-src->begin();
00249 if( electronId_.label().empty() ? true : ((int)(*electronId)[src->refAt(idx)] & eidPattern_) ){
00250 if(select_(*obj))++n;
00251 }
00252 }
00253
00254 else{
00255 if(select_(*obj))++n;
00256 }
00257 }
00258 bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00259 return (min_<0 && max_<0) ? (n>0):accept;
00260 }
00261 template <typename Object>
00262 bool SelectionStep<Object>::selectVertex(const edm::Event& event)
00263 {
00264
00265 edm::Handle<edm::View<Object> > src;
00266 if( !event.getByLabel(src_, src) ) return false;
00267
00268
00269 edm::Handle<edm::ValueMap<float> > electronId;
00270 if(!electronId_.label().empty()) {
00271 if( !event.getByLabel(electronId_, electronId) ) return false;
00272 }
00273
00274
00275 int n=0;
00276 for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00277
00278 if(select_(*obj))++n;
00279 }
00280 bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00281 return (min_<0 && max_<0) ? (n>0):accept;
00282 }
00283
00285 template <typename Object>
00286 bool SelectionStep<Object>::select(const edm::Event& event, const edm::EventSetup& setup)
00287 {
00288
00289 edm::Handle<edm::View<Object> > src;
00290 if( !event.getByLabel(src_, src) ) return false;
00291
00292
00293
00294
00295
00296 edm::Handle<edm::View<reco::Jet> > bjets;
00297 edm::Handle<reco::JetTagCollection> btagger;
00298 edm::Handle<edm::View<reco::Vertex> > pvertex;
00299 if(!btagLabel_.label().empty()){
00300 if( !event.getByLabel(src_, bjets) ) return false;
00301 if( !event.getByLabel(btagLabel_, btagger) ) return false;
00302 if( !event.getByLabel(pvs_, pvertex) ) return false;
00303 }
00304
00305
00306 edm::Handle<reco::JetIDValueMap> jetID;
00307 if(jetIDSelect_){
00308 if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
00309
00310 }
00311
00312
00313 const JetCorrector* corrector=0;
00314 if(!jetCorrector_.empty()){
00315
00316 if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
00317 corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
00318 }
00319 else{
00320 edm::LogVerbatim( "TopDQMHelpers" )
00321 << "\n"
00322 << "------------------------------------------------------------------------------------- \n"
00323 << " No JetCorrectionsRecord available from EventSetup: \n"
00324 << " - Jets will not be corrected. \n"
00325 << " - If you want to change this add the following lines to your cfg file \n"
00326 << " \n"
00327 << " ## load jet corrections \n"
00328 << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
00329 << " process.prefer(\"ak5CaloL2L3\") \n"
00330 << " \n"
00331 << "------------------------------------------------------------------------------------- \n";
00332 }
00333 }
00334
00335 int n=0;
00336 for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00337
00338
00339 unsigned int idx = obj-src->begin();
00340 if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
00341 bool passedJetID=true;
00342
00343 if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
00344 passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
00345 }
00346 if(passedJetID){
00347
00348 Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
00349 if(select_(jet))++n;
00350 }
00351 }
00352 }
00353 bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00354 return (min_<0 && max_<0) ? (n>0):accept;
00355 }
00356
00357 #endif