00001
00002
00003
00004
00005 #include <boost/foreach.hpp>
00006
00007 #include "HLTrigger/HLTanalyzers/interface/HLTBitAnalyzer.h"
00008 #include "HLTMessages.h"
00009 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011
00012 typedef std::pair<const char *, const edm::InputTag *> MissingCollectionInfo;
00013
00014 template <class T>
00015 static inline
00016 bool getCollection(const edm::Event & event, std::vector<MissingCollectionInfo> & missing, edm::Handle<T> & handle, const edm::InputTag & name, const char * description)
00017 {
00018 event.getByLabel(name, handle);
00019 bool valid = handle.isValid();
00020 if (not valid) {
00021 missing.push_back( std::make_pair(description, & name) );
00022 handle.clear();
00023 }
00024 return valid;
00025 }
00026
00027
00028 HLTBitAnalyzer::HLTBitAnalyzer(edm::ParameterSet const& conf) {
00029
00030
00031
00032
00033 std::cout << " Beginning HLTBitAnalyzer Analysis " << std::endl;
00034
00035 l1extramu_ = conf.getParameter<std::string> ("l1extramu");
00036 m_l1extramu = edm::InputTag(l1extramu_, "");
00037
00038
00039 l1extramc_ = conf.getParameter<std::string> ("l1extramc");
00040 m_l1extraemi = edm::InputTag(l1extramc_, "Isolated");
00041 m_l1extraemn = edm::InputTag(l1extramc_, "NonIsolated");
00042 m_l1extrajetc = edm::InputTag(l1extramc_, "Central");
00043 m_l1extrajetf = edm::InputTag(l1extramc_, "Forward");
00044 m_l1extrajet = edm::InputTag("gctInternJetProducer","Internal","ANALYSIS");
00045 m_l1extrataujet = edm::InputTag(l1extramc_, "Tau");
00046 m_l1extramet = edm::InputTag(l1extramc_, "MET");
00047 m_l1extramht = edm::InputTag(l1extramc_, "MHT");
00048
00049 mctruth_ = conf.getParameter<edm::InputTag> ("mctruth");
00050 genEventInfo_ = conf.getParameter<edm::InputTag> ("genEventInfo");
00051 VertexTagOffline0_ = conf.getParameter<edm::InputTag> ("OfflinePrimaryVertices0");
00052 simhits_ = conf.getParameter<edm::InputTag> ("simhits");
00053
00054 hltresults_ = conf.getParameter<edm::InputTag> ("hltresults");
00055 gtReadoutRecord_ = conf.getParameter<edm::InputTag> ("l1GtReadoutRecord");
00056 gtObjectMap_ = conf.getParameter<edm::InputTag> ("l1GtObjectMapRecord");
00057
00058 gctBitCounts_ = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFBitCounts").label(), "" );
00059 gctRingSums_ = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFRingSums").label(), "" );
00060
00061 pileupInfo_ = edm::InputTag("addPileupInfo");
00062
00063 _UseTFileService = conf.getUntrackedParameter<bool>("UseTFileService",false);
00064
00065 m_file = 0;
00066 errCnt = 0;
00067
00068
00069 edm::ParameterSet runParameters = conf.getParameter<edm::ParameterSet>("RunParameters");
00070 _HistName = runParameters.getUntrackedParameter<std::string>("HistogramFile", "test.root");
00071
00072
00073 if(_UseTFileService){
00074 edm::Service<TFileService> fs;
00075 HltTree = fs->make<TTree>("HltTree", "");
00076 }else{
00077 m_file = new TFile(_HistName.c_str(), "RECREATE");
00078 if (m_file)
00079 m_file->cd();
00080 HltTree = new TTree("HltTree", "");
00081 }
00082
00083
00084 hlt_analysis_.setup(conf, HltTree);
00085 mct_analysis_.setup(conf, HltTree);
00086 vrt_analysisOffline0_.setup(conf, HltTree, "Offline0");
00087 evt_header_.setup(HltTree);
00088 }
00089
00090
00091 void HLTBitAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
00092
00093 edm::Handle<edm::TriggerResults> hltresults;
00094 edm::Handle<l1extra::L1EmParticleCollection> l1extemi, l1extemn;
00095 edm::Handle<l1extra::L1MuonParticleCollection> l1extmu;
00096 edm::Handle<l1extra::L1JetParticleCollection> l1extjetc, l1extjetf, l1extjet, l1exttaujet;
00097 edm::Handle<l1extra::L1EtMissParticleCollection> l1extmet,l1extmht;
00098 edm::Handle<L1GlobalTriggerReadoutRecord> l1GtRR;
00099 edm::Handle<L1GlobalTriggerObjectMapRecord> l1GtOMRec;
00100 edm::Handle<L1GlobalTriggerObjectMap> l1GtOM;
00101 edm::Handle< L1GctHFBitCountsCollection > gctBitCounts ;
00102 edm::Handle< L1GctHFRingEtSumsCollection > gctRingSums ;
00103
00104 edm::Handle<reco::CandidateView> mctruth;
00105 edm::Handle<GenEventInfoProduct> genEventInfo;
00106 edm::Handle<std::vector<SimTrack> > simTracks;
00107 edm::Handle<std::vector<SimVertex> > simVertices;
00108 edm::Handle<reco::VertexCollection> recoVertexsOffline0;
00109 edm::Handle<std::vector< PileupSummaryInfo > > pupInfo;
00110
00111
00112 std::vector<MissingCollectionInfo> missing;
00113
00114 getCollection( iEvent, missing, hltresults, hltresults_, kHltresults );
00115 getCollection( iEvent, missing, l1extemi, m_l1extraemi, kL1extemi );
00116 getCollection( iEvent, missing, l1extemn, m_l1extraemn, kL1extemn );
00117 getCollection( iEvent, missing, l1extmu, m_l1extramu, kL1extmu );
00118 getCollection( iEvent, missing, l1extjetc, m_l1extrajetc, kL1extjetc );
00119 getCollection( iEvent, missing, l1extjetf, m_l1extrajetf, kL1extjetf );
00120 getCollection( iEvent, missing, l1extjet, m_l1extrajet, kL1extjet );
00121 getCollection( iEvent, missing, l1exttaujet, m_l1extrataujet, kL1exttaujet );
00122 getCollection( iEvent, missing, l1extmet, m_l1extramet, kL1extmet );
00123 getCollection( iEvent, missing, l1extmht, m_l1extramht, kL1extmht );
00124 getCollection( iEvent, missing, l1GtRR, gtReadoutRecord_, kL1GtRR );
00125 getCollection( iEvent, missing, l1GtOMRec, gtObjectMap_, kL1GtOMRec );
00126 getCollection( iEvent, missing, gctBitCounts, gctBitCounts_, kL1GctBitCounts );
00127 getCollection( iEvent, missing, gctRingSums, gctRingSums_, kL1GctRingSums );
00128
00129 getCollection( iEvent, missing, mctruth, mctruth_, kMctruth );
00130 getCollection( iEvent, missing, simTracks, simhits_, kSimhit );
00131 getCollection( iEvent, missing, simVertices, simhits_, kSimhit );
00132 getCollection( iEvent, missing, genEventInfo, genEventInfo_, kGenEventInfo );
00133 getCollection( iEvent, missing, pupInfo, pileupInfo_, kPileupInfo );
00134
00135 getCollection( iEvent, missing, recoVertexsOffline0, VertexTagOffline0_, kRecoVerticesOffline0 );
00136 double ptHat=-1.;
00137 if (genEventInfo.isValid()) {ptHat=genEventInfo->qScale();}
00138
00139 edm::ESHandle<LumiCorrectionParam> lumicorrdatahandle;
00140 iSetup.getData(lumicorrdatahandle);
00141
00142
00143 if (not missing.empty() and (errCnt < errMax())) {
00144 errCnt++;
00145 std::stringstream out;
00146 out << "OpenHLT analyser - missing collections:";
00147 BOOST_FOREACH(const MissingCollectionInfo & entry, missing)
00148 out << "\n\t" << entry.first << ": " << entry.second->encode();
00149 edm::LogPrint("OpenHLT") << out.str() << std::endl;
00150 if (errCnt == errMax())
00151 edm::LogWarning("OpenHLT") << "Maximum error count reached -- No more messages will be printed.";
00152 }
00153
00154
00155 hlt_analysis_.analyze(
00156 hltresults,
00157 l1extemi,
00158 l1extemn,
00159 l1extmu,
00160 l1extjetc,
00161 l1extjetf,
00162 l1extjet,
00163 l1exttaujet,
00164 l1extmet,
00165 l1extmht,
00166 l1GtRR,
00167 gctBitCounts,
00168 gctRingSums,
00169 iSetup,
00170 iEvent,
00171 HltTree);
00172
00173 evt_header_.analyze(iEvent, lumicorrdatahandle, HltTree);
00174
00175
00176 mct_analysis_.analyze(
00177 mctruth,
00178 ptHat,
00179 simTracks,
00180 simVertices,
00181 pupInfo,
00182 HltTree);
00183
00184 vrt_analysisOffline0_.analyze(
00185 recoVertexsOffline0,
00186 HltTree);
00187
00188
00189
00190
00191 if (m_file)
00192 m_file->cd();
00193 HltTree->Fill();
00194 }
00195
00196
00197 void
00198 HLTBitAnalyzer::beginRun(edm::Run const& run, edm::EventSetup const& es)
00199 {
00200 hlt_analysis_.beginRun(run, es);
00201 }
00202
00203
00204 void HLTBitAnalyzer::endJob() {
00205
00206 if(!_UseTFileService){
00207 if (m_file)
00208 m_file->cd();
00209
00210 HltTree->Write();
00211 delete HltTree;
00212 HltTree = 0;
00213
00214 if (m_file) {
00215 m_file->Write();
00216 delete m_file;
00217 m_file = 0;
00218 }
00219 }
00220 }