00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DQMOffline/JetMET/src/JetMETAnalyzer.h"
00010
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013
00014 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00015 #include "DataFormats/METReco/interface/CaloMET.h"
00016 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00017 #include "DataFormats/JetReco/interface/CaloJet.h"
00018 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00019 #include "DataFormats/JetReco/interface/PFJet.h"
00020
00021 #include "DataFormats/Common/interface/Handle.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023
00024 #include <string>
00025 using namespace std;
00026 using namespace edm;
00027
00028 #define DEBUG 0
00029
00030 JetMETAnalyzer::JetMETAnalyzer(const edm::ParameterSet& pSet) {
00031
00032 parameters = pSet;
00033
00034
00035 theSCJetCollectionLabel = parameters.getParameter<edm::InputTag>("SCJetsCollectionLabel");
00036 theICJetCollectionLabel = parameters.getParameter<edm::InputTag>("ICJetsCollectionLabel");
00037
00038
00039 thePFJetCollectionLabel = parameters.getParameter<edm::InputTag>("PFJetsCollectionLabel");
00040
00041 theCaloMETCollectionLabel = parameters.getParameter<edm::InputTag>("CaloMETCollectionLabel");
00042 theCaloMETNoHFCollectionLabel = parameters.getParameter<edm::InputTag>("CaloMETNoHFCollectionLabel");
00043
00044 theTriggerResultsLabel = parameters.getParameter<edm::InputTag>("TriggerResultsLabel");
00045
00046
00047
00048 theJetAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoJetAnalysis",true);
00049
00050 thePFJetAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoPFJetAnalysis",true);
00051 theCaloMETAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoCaloMETAnalysis",true);
00052
00053
00054 if(theJetAnalyzerFlag) {
00055
00056
00057 theSCJetAnalyzer = new JetAnalyzer(parameters.getParameter<ParameterSet>("jetAnalysis"));
00058 theSCJetAnalyzer->setSource("SISConeJets");
00059 theICJetAnalyzer = new JetAnalyzer(parameters.getParameter<ParameterSet>("jetAnalysis"));
00060 theICJetAnalyzer->setSource("IterativeConeJets");
00061 }
00062
00063
00064 if(thePFJetAnalyzerFlag)
00065 thePFJetAnalyzer = new PFJetAnalyzer(parameters.getParameter<ParameterSet>("pfJetAnalysis"));
00066
00067
00068 if(theCaloMETAnalyzerFlag)
00069 theCaloMETAnalyzer = new CaloMETAnalyzer(parameters.getParameter<ParameterSet>("caloMETAnalysis"));
00070
00071 LoJetTrigger = parameters.getParameter<std::string>("JetLo");
00072 HiJetTrigger = parameters.getParameter<std::string>("JetHi");
00073
00074 }
00075
00076
00077 JetMETAnalyzer::~JetMETAnalyzer() {
00078 if(theJetAnalyzerFlag) {
00079
00080 delete theSCJetAnalyzer;
00081 delete theICJetAnalyzer;
00082 }
00083 if(thePFJetAnalyzerFlag) delete thePFJetAnalyzer;
00084 if(theCaloMETAnalyzerFlag) delete theCaloMETAnalyzer;
00085 }
00086
00087
00088
00089 void JetMETAnalyzer::beginJob(edm::EventSetup const& iSetup) {
00090
00091 metname = "JetMETAnalyzer";
00092
00093 LogTrace(metname)<<"[JetMETAnalyzer] Parameters initialization";
00094 dbe = edm::Service<DQMStore>().operator->();
00095
00096 if(theJetAnalyzerFlag) {
00097
00098 theSCJetAnalyzer->beginJob(iSetup, dbe);
00099 theICJetAnalyzer->beginJob(iSetup, dbe);
00100 }
00101
00102 if(thePFJetAnalyzerFlag) thePFJetAnalyzer->beginJob(iSetup, dbe);
00103 if(theCaloMETAnalyzerFlag) theCaloMETAnalyzer->beginJob(iSetup, dbe);
00104
00105 }
00106
00107
00108
00109 void JetMETAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00110
00111 LogTrace(metname)<<"[JetMETAnalyzer] Analysis of event # ";
00112
00113
00114 edm::Handle<TriggerResults> triggerResults;
00115 iEvent.getByLabel(theTriggerResultsLabel, triggerResults);
00116
00117 if (DEBUG) std::cout << "trigger label " << theTriggerResultsLabel << std::endl;
00118
00119 Int_t JetLoPass = 0;
00120 Int_t JetHiPass = 0;
00121
00122 if (triggerResults.isValid()) {
00123 if (DEBUG) std::cout << "trigger valid " << std::endl;
00124 edm::TriggerNames triggerNames;
00125 triggerNames.init(*triggerResults);
00126 unsigned int n = triggerResults->size();
00127 for (unsigned int i=0; i!=n; i++) {
00128
00129
00130
00131
00132
00133
00134 if ( triggerNames.triggerName(i) == LoJetTrigger ) {
00135 JetLoPass = triggerResults->accept(i);
00136 if (DEBUG) std::cout << "Found HLT_Jet30" << std::endl;
00137 }
00138
00139
00140
00141 if ( triggerNames.triggerName(i) == HiJetTrigger ) {
00142 JetHiPass = triggerResults->accept(i);
00143 }
00144 }
00145
00146
00147
00148
00149
00150 } else {
00151
00152 edm::Handle<TriggerResults> *tr = new edm::Handle<TriggerResults>;
00153 triggerResults = (*tr);
00154
00155
00156
00157
00158 if (DEBUG) std::cout << "trigger not valid " << std::endl;
00159 edm::LogInfo("JetAnalyzer") << "TriggerResults::HLT not found, "
00160 "automatically select events";
00161
00162 }
00163
00164 if (DEBUG) {
00165 std::cout << ">>> Trigger Lo = " << JetLoPass
00166 << " Hi = " << JetHiPass
00167 << std::endl;
00168 }
00169
00170
00171 edm::Handle<reco::CaloJetCollection> caloJets;
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 iEvent.getByLabel(theSCJetCollectionLabel, caloJets);
00187
00188
00189 if(caloJets.isValid()){
00190 theSCJetAnalyzer->setJetHiPass(JetHiPass);
00191 theSCJetAnalyzer->setJetLoPass(JetLoPass);
00192 for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); cal!=caloJets->end(); ++cal){
00193 if(theJetAnalyzerFlag){
00194 LogTrace(metname)<<"[JetMETAnalyzer] Call to the SC Jet analyzer";
00195 if (cal == caloJets->begin()) {
00196 theSCJetAnalyzer->setNJets(caloJets->size());
00197 theSCJetAnalyzer->setLeadJetFlag(1);
00198 } else {
00199 theSCJetAnalyzer->setLeadJetFlag(0);
00200 }
00201
00202 theSCJetAnalyzer->analyze(iEvent, iSetup, *cal);
00203 }
00204 }
00205 }
00206
00207
00208 iEvent.getByLabel(theICJetCollectionLabel, caloJets);
00209
00210 if(caloJets.isValid()){
00211 theICJetAnalyzer->setJetHiPass(JetHiPass);
00212 theICJetAnalyzer->setJetLoPass(JetLoPass);
00213 for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); cal!=caloJets->end(); ++cal){
00214 if(theJetAnalyzerFlag){
00215 LogTrace(metname)<<"[JetMETAnalyzer] Call to the IC Jet analyzer";
00216 if (cal == caloJets->begin()) {
00217 theICJetAnalyzer->setNJets(caloJets->size());
00218 theICJetAnalyzer->setLeadJetFlag(1);
00219 } else {
00220 theICJetAnalyzer->setLeadJetFlag(0);
00221 }
00222
00223 theICJetAnalyzer->analyze(iEvent, iSetup, *cal);
00224 }
00225 }
00226 }
00227
00228
00229
00230 edm::Handle<reco::PFJetCollection> pfJets;
00231 iEvent.getByLabel(thePFJetCollectionLabel, pfJets);
00232
00233 if(pfJets.isValid()){
00234 for (reco::PFJetCollection::const_iterator cal = pfJets->begin(); cal!=pfJets->end(); ++cal){
00235 if(thePFJetAnalyzerFlag){
00236 LogTrace(metname)<<"[JetMETAnalyzer] Call to the PFJet analyzer";
00237 thePFJetAnalyzer->analyze(iEvent, iSetup, *cal);
00238 }
00239 }
00240 }
00241
00242
00243
00244 edm::Handle<reco::CaloMETCollection> calometcoll;
00245 iEvent.getByLabel(theCaloMETCollectionLabel, calometcoll);
00246 edm::Handle<reco::CaloMETCollection> calometNoHFcoll;
00247 iEvent.getByLabel(theCaloMETNoHFCollectionLabel, calometNoHFcoll);
00248
00249 if(calometcoll.isValid() && calometNoHFcoll.isValid()){
00250 const CaloMETCollection *calometcol = calometcoll.product();
00251 const CaloMET *calomet;
00252 calomet = &(calometcol->front());
00253 const CaloMETCollection *calometNoHFcol = calometNoHFcoll.product();
00254 const CaloMET *calometNoHF;
00255 calometNoHF = &(calometNoHFcol->front());
00256
00257 if(theCaloMETAnalyzerFlag){
00258 LogTrace(metname)<<"[JetMETAnalyzer] Call to the CaloMET analyzer";
00259 theCaloMETAnalyzer->analyze(iEvent, iSetup,
00260 *triggerResults,
00261 *calomet, *calometNoHF);
00262 }
00263 }
00264
00265 }
00266
00267
00268
00269 void JetMETAnalyzer::endJob(void) {
00270 LogTrace(metname)<<"[JetMETAnalyzer] Saving the histos";
00271 bool outputMEsInRootFile = parameters.getParameter<bool>("OutputMEsInRootFile");
00272 std::string outputFileName = parameters.getParameter<std::string>("OutputFileName");
00273
00274 if(outputMEsInRootFile){
00275 dbe->showDirStructure();
00276 dbe->save(outputFileName);
00277 }
00278 }
00279