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
00020 inline bool
00021 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::string& triggerPath)
00022 {
00023 bool passed=false;
00024 const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
00025 for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
00026 if(triggerNames.triggerNames()[i] == triggerPath) {
00027 if(triggerTable.accept(i)){
00028 passed=true;
00029 break;
00030 }
00031 }
00032 }
00033 return passed;
00034 }
00035
00036 inline bool
00037 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::vector<std::string>& triggerPaths)
00038 {
00039 bool passed=false;
00040 for(unsigned int j=0; j<triggerPaths.size(); ++j){
00041 if(accept(event, triggerTable, triggerPaths[j])){
00042 passed=true;
00043 break;
00044 }
00045 }
00046 return passed;
00047 }
00048
00049
00050 #include "DataFormats/JetReco/interface/Jet.h"
00051 #include "FWCore/Framework/interface/EventSetup.h"
00052
00064 class Calculate {
00065 public:
00067 Calculate(int maxNJets, double wMass);
00069 ~Calculate(){};
00070
00072 double massWBoson(const std::vector<reco::Jet>& jets);
00074 double massTopQuark(const std::vector<reco::Jet>& jets);
00075
00076 private:
00080 void operator()(const std::vector<reco::Jet>& jets);
00081
00082 private:
00084 bool failed_;
00086 int maxNJets_;
00088 double wMass_;
00090 double massWBoson_;
00092 double massTopQuark_;
00093 };
00094
00095
00096 #include "DataFormats/JetReco/interface/JetID.h"
00097 #include "DataFormats/JetReco/interface/PFJet.h"
00098 #include "DataFormats/JetReco/interface/CaloJet.h"
00099 #include "DataFormats/BTauReco/interface/JetTag.h"
00100 #include "DataFormats/Common/interface/ValueMap.h"
00101 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00102 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00103 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00104 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00105 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
00106
00146 template <typename Object>
00147 class SelectionStep {
00148 public:
00150 SelectionStep(const edm::ParameterSet& cfg);
00152 ~SelectionStep(){};
00153
00155 bool select(const edm::Event& event);
00157 bool select(const edm::Event& event, const edm::EventSetup& setup);
00158
00159 private:
00161 edm::InputTag src_;
00163 int min_, max_;
00165 edm::InputTag electronId_;
00167 std::string jetCorrector_;
00169 edm::InputTag btagLabel_;
00171 double btagWorkingPoint_;
00173 edm::InputTag jetIDLabel_;
00174
00176 StringCutObjectSelector<Object> select_;
00178 StringCutObjectSelector<reco::JetID>* jetIDSelect_;
00179 };
00180
00182 template <typename Object>
00183 SelectionStep<Object>::SelectionStep(const edm::ParameterSet& cfg) :
00184 src_( cfg.getParameter<edm::InputTag>( "src" )),
00185 select_( cfg.getParameter<std::string>("select")),
00186 jetIDSelect_(0)
00187 {
00188
00189
00190 cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
00191 cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
00192
00193 if(cfg.exists("electronId" )){ electronId_= cfg.getParameter<edm::InputTag>("electronId" ); }
00194
00195 if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
00196
00197 if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
00198 edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
00199 btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
00200 btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
00201 }
00202
00203 if(cfg.existsAs<edm::ParameterSet>("jetID")){
00204 edm::ParameterSet jetID=cfg.getParameter<edm::ParameterSet>("jetID");
00205 jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
00206 jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
00207 }
00208 }
00209
00211 template <typename Object>
00212 bool SelectionStep<Object>::select(const edm::Event& event)
00213 {
00214
00215 edm::Handle<edm::View<Object> > src;
00216 if( !event.getByLabel(src_, src) ) return false;
00217
00218
00219 edm::Handle<edm::ValueMap<float> > electronId;
00220 if(!electronId_.label().empty()) {
00221 if( !event.getByLabel(electronId_, electronId) ) return false;
00222 }
00223
00224
00225 int n=0;
00226 for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00227
00228 if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
00229 unsigned int idx = obj-src->begin();
00230 if( electronId_.label().empty() ? true : (*electronId)[src->refAt(idx)]>0.99 ){
00231 if(select_(*obj))++n;
00232 }
00233 }
00234
00235 else{
00236 if(select_(*obj))++n;
00237 }
00238 }
00239 bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00240 return (min_<0 && max_<0) ? (n>0):accept;
00241 }
00242
00244 template <typename Object>
00245 bool SelectionStep<Object>::select(const edm::Event& event, const edm::EventSetup& setup)
00246 {
00247
00248 edm::Handle<edm::View<Object> > src;
00249 if( !event.getByLabel(src_, src) ) return false;
00250
00251
00252
00253
00254
00255 edm::Handle<edm::View<reco::Jet> > bjets;
00256 edm::Handle<reco::JetTagCollection> btagger;
00257 if(!btagLabel_.label().empty()){
00258 if( !event.getByLabel(src_, bjets) ) return false;
00259 if( !event.getByLabel(btagLabel_, btagger) ) return false;
00260 }
00261
00262
00263 edm::Handle<reco::JetIDValueMap> jetID;
00264 if(jetIDSelect_){
00265 if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
00266 }
00267
00268
00269 const JetCorrector* corrector=0;
00270 if(!jetCorrector_.empty()){
00271
00272 if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
00273 corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
00274 }
00275 else{
00276 edm::LogVerbatim( "TopDQMHelpers" )
00277 << "\n"
00278 << "------------------------------------------------------------------------------------- \n"
00279 << " No JetCorrectionsRecord available from EventSetup: \n"
00280 << " - Jets will not be corrected. \n"
00281 << " - If you want to change this add the following lines to your cfg file \n"
00282 << " \n"
00283 << " ## load jet corrections \n"
00284 << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
00285 << " process.prefer(\"ak5CaloL2L3\") \n"
00286 << " \n"
00287 << "------------------------------------------------------------------------------------- \n";
00288 }
00289 }
00290
00291 int n=0;
00292 for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00293
00294
00295 unsigned int idx = obj-src->begin();
00296 if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
00297 bool passedJetID=true;
00298
00299 if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
00300 passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
00301 }
00302 if(passedJetID){
00303
00304 Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
00305 if(select_(jet))++n;
00306 }
00307 }
00308 }
00309 bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00310 return (min_<0 && max_<0) ? (n>0):accept;
00311 }
00312
00313 #endif