CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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 
00010 typedef std::pair<const char *, const edm::InputTag *> MissingCollectionInfo;
00011   
00012 template <class T>
00013 static inline
00014 bool getCollection(const edm::Event & event, std::vector<MissingCollectionInfo> & missing, edm::Handle<T> & handle, const edm::InputTag & name, const char * description) 
00015 {
00016   event.getByLabel(name, handle);
00017   bool valid = handle.isValid();
00018   if (not valid) {
00019     missing.push_back( std::make_pair(description, & name) );
00020     handle.clear();
00021   }
00022   return valid;
00023 }
00024 
00025 // Boiler-plate constructor definition of an analyzer module:
00026 HLTBitAnalyzer::HLTBitAnalyzer(edm::ParameterSet const& conf) {
00027 
00028   // If your module takes parameters, here is where you would define
00029   // their names and types, and access them to initialize internal
00030   // variables. Example as follows:
00031   std::cout << " Beginning HLTBitAnalyzer Analysis " << std::endl;
00032 
00033   l1extramu_        = conf.getParameter<std::string>   ("l1extramu");
00034   m_l1extramu       = edm::InputTag(l1extramu_, "");
00035 
00036   // read the L1Extra collection name, and add the instance names as needed
00037   l1extramc_        = conf.getParameter<std::string>   ("l1extramc");
00038   m_l1extraemi      = edm::InputTag(l1extramc_, "Isolated");
00039   m_l1extraemn      = edm::InputTag(l1extramc_, "NonIsolated");
00040   m_l1extrajetc     = edm::InputTag(l1extramc_, "Central");
00041   m_l1extrajetf     = edm::InputTag(l1extramc_, "Forward");
00042   m_l1extrataujet   = edm::InputTag(l1extramc_, "Tau");
00043   m_l1extramet      = edm::InputTag(l1extramc_, "MET");
00044   m_l1extramht      = edm::InputTag(l1extramc_, "MHT");
00045 
00046   hltresults_       = conf.getParameter<edm::InputTag> ("hltresults");
00047   gtReadoutRecord_  = conf.getParameter<edm::InputTag> ("l1GtReadoutRecord");
00048   gtObjectMap_      = conf.getParameter<edm::InputTag> ("l1GtObjectMapRecord");
00049 
00050   gctBitCounts_        = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFBitCounts").label(), "" );
00051   gctRingSums_         = edm::InputTag( conf.getParameter<edm::InputTag>("l1GctHFRingSums").label(), "" );
00052   
00053   m_file = 0;   // set to null
00054   errCnt = 0;
00055 
00056   // read run parameters with a default value
00057   edm::ParameterSet runParameters = conf.getParameter<edm::ParameterSet>("RunParameters");
00058   _HistName = runParameters.getUntrackedParameter<std::string>("HistogramFile", "test.root");
00059 
00060   // open the tree file
00061   m_file = new TFile(_HistName.c_str(), "RECREATE");
00062   if (m_file)
00063     m_file->cd();
00064 
00065   // Initialize the tree
00066   HltTree = new TTree("HltTree", "");
00067 
00068   // Setup the different analysis
00069   hlt_analysis_.setup(conf, HltTree);
00070   evt_header_.setup(HltTree);
00071 }
00072 
00073 // Boiler-plate "analyze" method declaration for an analyzer module.
00074 void HLTBitAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
00075 
00076   edm::Handle<edm::TriggerResults>                  hltresults;
00077   edm::Handle<l1extra::L1EmParticleCollection>      l1extemi, l1extemn;
00078   edm::Handle<l1extra::L1MuonParticleCollection>    l1extmu;
00079   edm::Handle<l1extra::L1JetParticleCollection>     l1extjetc, l1extjetf, l1exttaujet;
00080   edm::Handle<l1extra::L1EtMissParticleCollection>  l1extmet,l1extmht;
00081   edm::Handle<L1GlobalTriggerReadoutRecord>         l1GtRR;
00082   edm::Handle<L1GlobalTriggerObjectMapRecord>       l1GtOMRec;
00083   edm::Handle<L1GlobalTriggerObjectMap>             l1GtOM;
00084   edm::Handle< L1GctHFBitCountsCollection >         gctBitCounts ;
00085   edm::Handle< L1GctHFRingEtSumsCollection >        gctRingSums ;
00086 
00087   // extract the collections from the event, check their validity and log which are missing
00088   std::vector<MissingCollectionInfo> missing;
00089 
00090   getCollection( iEvent, missing, hltresults,      hltresults_,        kHltresults );
00091   getCollection( iEvent, missing, l1extemi,        m_l1extraemi,       kL1extemi );
00092   getCollection( iEvent, missing, l1extemn,        m_l1extraemn,       kL1extemn );
00093   getCollection( iEvent, missing, l1extmu,         m_l1extramu,        kL1extmu );
00094   getCollection( iEvent, missing, l1extjetc,       m_l1extrajetc,      kL1extjetc );
00095   getCollection( iEvent, missing, l1extjetf,       m_l1extrajetf,      kL1extjetf );
00096   getCollection( iEvent, missing, l1exttaujet,     m_l1extrataujet,    kL1exttaujet );
00097   getCollection( iEvent, missing, l1extmet,        m_l1extramet,       kL1extmet );
00098   getCollection( iEvent, missing, l1extmht,        m_l1extramht,       kL1extmht );
00099   getCollection( iEvent, missing, l1GtRR,          gtReadoutRecord_,   kL1GtRR );
00100   getCollection( iEvent, missing, l1GtOMRec,       gtObjectMap_,       kL1GtOMRec );
00101   getCollection( iEvent, missing, gctBitCounts,     gctBitCounts_,      kL1GctBitCounts );
00102   getCollection( iEvent, missing, gctRingSums,      gctRingSums_,       kL1GctRingSums );
00103 
00104 
00105   // print missing collections
00106   if (not missing.empty() and (errCnt < errMax())) {
00107     errCnt++;
00108     std::stringstream out;       
00109     out <<  "OpenHLT analyser - missing collections:";
00110     BOOST_FOREACH(const MissingCollectionInfo & entry, missing)
00111       out << "\n\t" << entry.first << ": " << entry.second->encode();
00112     edm::LogPrint("OpenHLT") << out.str() << std::endl; 
00113     if (errCnt == errMax())
00114       edm::LogWarning("OpenHLT") << "Maximum error count reached -- No more messages will be printed.";
00115   }
00116 
00117   // run the analysis, passing required event fragments
00118   hlt_analysis_.analyze(
00119     hltresults,
00120     l1extemi,
00121     l1extemn,
00122     l1extmu,
00123     l1extjetc,
00124     l1extjetf,
00125     l1exttaujet,
00126     l1extmet,
00127     l1extmht,
00128     l1GtRR,
00129     gctBitCounts,
00130     gctRingSums,
00131     iSetup,
00132     iEvent,
00133     HltTree);
00134 
00135   evt_header_.analyze(iEvent, HltTree);
00136 
00137   // std::cout << " Ending Event Analysis" << std::endl;
00138   // After analysis, fill the variables tree
00139   if (m_file)
00140     m_file->cd();
00141   HltTree->Fill();
00142 }
00143 
00144 // "endJob" is an inherited method that you may implement to do post-EOF processing and produce final output.
00145 void HLTBitAnalyzer::endJob() {
00146 
00147   if (m_file)
00148     m_file->cd();
00149   
00150   HltTree->Write();
00151   delete HltTree;
00152   HltTree = 0;
00153 
00154   if (m_file) {         // if there was a tree file...
00155     m_file->Write();    // write out the branches
00156     delete m_file;      // close and delete the file
00157     m_file = 0;         // set to zero to clean up
00158   }
00159 
00160 }