CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/HLTrigger/HLTanalyzers/src/HLTBitAnalyzer.cc

Go to the documentation of this file.
00001 // File: HLTBitAnalyzer.cc
00002 // Description:  Example of Analysis driver originally from Jeremy Mans, 
00003 // Date:  13-October-2006
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 // Boiler-plate constructor definition of an analyzer module:
00028 HLTBitAnalyzer::HLTBitAnalyzer(edm::ParameterSet const& conf) {
00029 
00030   // If your module takes parameters, here is where you would define
00031   // their names and types, and access them to initialize internal
00032   // variables. Example as follows:
00033   std::cout << " Beginning HLTBitAnalyzer Analysis " << std::endl;
00034 
00035   l1extramu_        = conf.getParameter<std::string>   ("l1extramu");
00036   m_l1extramu       = edm::InputTag(l1extramu_, "");
00037 
00038   // read the L1Extra collection name, and add the instance names as needed
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_l1extrataujet   = edm::InputTag(l1extramc_, "Tau");
00045   m_l1extramet      = edm::InputTag(l1extramc_, "MET");
00046   m_l1extramht      = edm::InputTag(l1extramc_, "MHT");
00047 
00048   hltresults_       = conf.getParameter<edm::InputTag> ("hltresults");
00049   gtReadoutRecord_  = conf.getParameter<edm::InputTag> ("l1GtReadoutRecord");
00050   gtObjectMap_      = conf.getParameter<edm::InputTag> ("l1GtObjectMapRecord");
00051 
00052   gctBitCounts_        = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFBitCounts").label(), "" );
00053   gctRingSums_         = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFRingSums").label(), "" );
00054 
00055         _UseTFileService = conf.getUntrackedParameter<bool>("UseTFileService",false);
00056         
00057   m_file = 0;   // set to null
00058   errCnt = 0;
00059 
00060   // read run parameters with a default value
00061   edm::ParameterSet runParameters = conf.getParameter<edm::ParameterSet>("RunParameters");
00062   _HistName = runParameters.getUntrackedParameter<std::string>("HistogramFile", "test.root");
00063 
00064   // open the tree file and initialize the tree
00065   if(_UseTFileService){
00066     edm::Service<TFileService> fs;
00067     HltTree = fs->make<TTree>("HltTree", "");
00068   }else{
00069     m_file = new TFile(_HistName.c_str(), "RECREATE");
00070     if (m_file)
00071       m_file->cd();
00072     HltTree = new TTree("HltTree", "");
00073   }
00074 
00075   // Setup the different analysis
00076   hlt_analysis_.setup(conf, HltTree);
00077   evt_header_.setup(HltTree);
00078 }
00079 
00080 // Boiler-plate "analyze" method declaration for an analyzer module.
00081 void HLTBitAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
00082 
00083   edm::Handle<edm::TriggerResults>                  hltresults;
00084   edm::Handle<l1extra::L1EmParticleCollection>      l1extemi, l1extemn;
00085   edm::Handle<l1extra::L1MuonParticleCollection>    l1extmu;
00086   edm::Handle<l1extra::L1JetParticleCollection>     l1extjetc, l1extjetf, l1exttaujet;
00087   edm::Handle<l1extra::L1EtMissParticleCollection>  l1extmet,l1extmht;
00088   edm::Handle<L1GlobalTriggerReadoutRecord>         l1GtRR;
00089   edm::Handle<L1GlobalTriggerObjectMapRecord>       l1GtOMRec;
00090   edm::Handle<L1GlobalTriggerObjectMap>             l1GtOM;
00091   edm::Handle< L1GctHFBitCountsCollection >         gctBitCounts ;
00092   edm::Handle< L1GctHFRingEtSumsCollection >        gctRingSums ;
00093 
00094   // extract the collections from the event, check their validity and log which are missing
00095   std::vector<MissingCollectionInfo> missing;
00096 
00097   getCollection( iEvent, missing, hltresults,      hltresults_,        kHltresults );
00098   getCollection( iEvent, missing, l1extemi,        m_l1extraemi,       kL1extemi );
00099   getCollection( iEvent, missing, l1extemn,        m_l1extraemn,       kL1extemn );
00100   getCollection( iEvent, missing, l1extmu,         m_l1extramu,        kL1extmu );
00101   getCollection( iEvent, missing, l1extjetc,       m_l1extrajetc,      kL1extjetc );
00102   getCollection( iEvent, missing, l1extjetf,       m_l1extrajetf,      kL1extjetf );
00103   getCollection( iEvent, missing, l1exttaujet,     m_l1extrataujet,    kL1exttaujet );
00104   getCollection( iEvent, missing, l1extmet,        m_l1extramet,       kL1extmet );
00105   getCollection( iEvent, missing, l1extmht,        m_l1extramht,       kL1extmht );
00106   getCollection( iEvent, missing, l1GtRR,          gtReadoutRecord_,   kL1GtRR );
00107   getCollection( iEvent, missing, l1GtOMRec,       gtObjectMap_,       kL1GtOMRec );
00108   getCollection( iEvent, missing, gctBitCounts,     gctBitCounts_,      kL1GctBitCounts );
00109   getCollection( iEvent, missing, gctRingSums,      gctRingSums_,       kL1GctRingSums );
00110 
00111 
00112   // print missing collections
00113   if (not missing.empty() and (errCnt < errMax())) {
00114     errCnt++;
00115     std::stringstream out;       
00116     out <<  "OpenHLT analyser - missing collections:";
00117     BOOST_FOREACH(const MissingCollectionInfo & entry, missing)
00118       out << "\n\t" << entry.first << ": " << entry.second->encode();
00119     edm::LogPrint("OpenHLT") << out.str() << std::endl; 
00120     if (errCnt == errMax())
00121       edm::LogWarning("OpenHLT") << "Maximum error count reached -- No more messages will be printed.";
00122   }
00123 
00124   // run the analysis, passing required event fragments
00125   hlt_analysis_.analyze(
00126     hltresults,
00127     l1extemi,
00128     l1extemn,
00129     l1extmu,
00130     l1extjetc,
00131     l1extjetf,
00132     l1exttaujet,
00133     l1extmet,
00134     l1extmht,
00135     l1GtRR,
00136     gctBitCounts,
00137     gctRingSums,
00138     iSetup,
00139     iEvent,
00140     HltTree);
00141 
00142   evt_header_.analyze(iEvent, HltTree);
00143 
00144   // std::cout << " Ending Event Analysis" << std::endl;
00145   // After analysis, fill the variables tree
00146   if (m_file)
00147     m_file->cd();
00148   HltTree->Fill();
00149 }
00150 
00151 // ------------ method called when starting to processes a run  ------------
00152 void 
00153 HLTBitAnalyzer::beginRun(edm::Run const& run, edm::EventSetup const& es)
00154 {
00155    hlt_analysis_.beginRun(run, es);
00156 }
00157 
00158 // "endJob" is an inherited method that you may implement to do post-EOF processing and produce final output.
00159 void HLTBitAnalyzer::endJob() {
00160         
00161         if(!_UseTFileService){
00162                 if (m_file)
00163                         m_file->cd();
00164                 
00165                 HltTree->Write();
00166                 delete HltTree;
00167                 HltTree = 0;
00168                 
00169                 if (m_file) {         // if there was a tree file...
00170                         m_file->Write();    // write out the branches
00171                         delete m_file;      // close and delete the file
00172                         m_file = 0;         // set to zero to clean up
00173                 }
00174         }
00175 }