CMS 3D CMS Logo

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