CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/HLTcore/plugins/HLTEventAnalyzerAOD.cc

Go to the documentation of this file.
00001 
00012 #include "FWCore/Common/interface/TriggerNames.h"
00013 #include "FWCore/Common/interface/TriggerResultsByName.h"
00014 #include "HLTrigger/HLTcore/interface/HLTEventAnalyzerAOD.h"
00015 #include <cassert>
00016 
00017 //
00018 // constructors and destructor
00019 //
00020 HLTEventAnalyzerAOD::HLTEventAnalyzerAOD(const edm::ParameterSet& ps) : 
00021   processName_(ps.getParameter<std::string>("processName")),
00022   triggerName_(ps.getParameter<std::string>("triggerName")),
00023   triggerResultsTag_(ps.getParameter<edm::InputTag>("triggerResults")),
00024   triggerEventTag_(ps.getParameter<edm::InputTag>("triggerEvent"))
00025 {
00026   using namespace std;
00027   using namespace edm;
00028 
00029   cout << "HLTEventAnalyzerAOD configuration: " << endl
00030        << "   ProcessName = " << processName_ << endl
00031        << "   TriggerName = " << triggerName_ << endl
00032        << "   TriggerResultsTag = " << triggerResultsTag_.encode() << endl
00033        << "   TriggerEventTag = " << triggerEventTag_.encode() << endl;
00034 
00035 }
00036 
00037 HLTEventAnalyzerAOD::~HLTEventAnalyzerAOD()
00038 {
00039 }
00040 
00041 //
00042 // member functions
00043 //
00044 void
00045 HLTEventAnalyzerAOD::beginRun(edm::Run const & iRun, edm::EventSetup const& iSetup)
00046 {
00047   using namespace std;
00048   using namespace edm;
00049 
00050   bool changed(true);
00051   if (hltConfig_.init(iRun,iSetup,processName_,changed)) {
00052     if (changed) {
00053       // check if trigger name in (new) config
00054       if (triggerName_!="@") { // "@" means: analyze all triggers in config
00055         const unsigned int n(hltConfig_.size());
00056         const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName_));
00057         if (triggerIndex>=n) {
00058           cout << "HLTEventAnalyzerAOD::analyze:"
00059                << " TriggerName " << triggerName_ 
00060                << " not available in (new) config!" << endl;
00061           cout << "Available TriggerNames are: " << endl;
00062           hltConfig_.dump("Triggers");
00063         }
00064       }
00065       hltConfig_.dump("Streams");
00066       hltConfig_.dump("Datasets");
00067       hltConfig_.dump("PrescaleTable");
00068       hltConfig_.dump("ProcessPSet");
00069     }
00070   } else {
00071     cout << "HLTEventAnalyzerAOD::analyze:"
00072          << " config extraction failure with process name "
00073          << processName_ << endl;
00074   }
00075 }
00076 
00077 // ------------ method called to produce the data  ------------
00078 void
00079 HLTEventAnalyzerAOD::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00080 {
00081   using namespace std;
00082   using namespace edm;
00083   
00084   cout << endl;
00085 
00086   // get event products
00087   iEvent.getByLabel(triggerResultsTag_,triggerResultsHandle_);
00088   if (!triggerResultsHandle_.isValid()) {
00089     cout << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerResults product from Event!" << endl;
00090     return;
00091   }
00092   iEvent.getByLabel(triggerEventTag_,triggerEventHandle_);
00093   if (!triggerEventHandle_.isValid()) {
00094     cout << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerEvent product from Event!" << endl;
00095     return;
00096   }
00097   // sanity check
00098   assert(triggerResultsHandle_->size()==hltConfig_.size());
00099   
00100   // analyze this event for the triggers requested
00101   if (triggerName_=="@") {
00102     const unsigned int n(hltConfig_.size());
00103     for (unsigned int i=0; i!=n; ++i) {
00104       analyzeTrigger(iEvent,iSetup,hltConfig_.triggerName(i));
00105     }
00106   } else {
00107     analyzeTrigger(iEvent,iSetup,triggerName_);
00108   }
00109 
00110   return;
00111 
00112 }
00113 
00114 void HLTEventAnalyzerAOD::analyzeTrigger(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& triggerName) {
00115   
00116   using namespace std;
00117   using namespace edm;
00118   using namespace reco;
00119   using namespace trigger;
00120 
00121   cout << endl;
00122 
00123   const unsigned int n(hltConfig_.size());
00124   const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName));
00125   assert(triggerIndex==iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(triggerName));
00126 
00127   // abort on invalid trigger name
00128   if (triggerIndex>=n) {
00129     cout << "HLTEventAnalyzerAOD::analyzeTrigger: path "
00130          << triggerName << " - not found!" << endl;
00131     return;
00132   }
00133   
00134   const std::pair<int,int> prescales(hltConfig_.prescaleValues(iEvent,iSetup,triggerName));
00135   cout << "HLTEventAnalyzerAOD::analyzeTrigger: path "
00136        << triggerName << " [" << triggerIndex << "] "
00137        << "prescales L1T,HLT: " << prescales.first << "," << prescales.second
00138        << endl;
00139 
00140   // modules on this trigger path
00141   const unsigned int m(hltConfig_.size(triggerIndex));
00142   const vector<string>& moduleLabels(hltConfig_.moduleLabels(triggerIndex));
00143 
00144   // Results from TriggerResults product
00145   cout << " Trigger path status:"
00146        << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
00147        << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
00148        << " Error =" << triggerResultsHandle_->error(triggerIndex)
00149        << endl;
00150   const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
00151   cout << " Last active module - label/type: "
00152        << moduleLabels[moduleIndex] << "/" << hltConfig_.moduleType(moduleLabels[moduleIndex])
00153        << " [" << moduleIndex << " out of 0-" << (m-1) << " on this path]"
00154        << endl;
00155   assert (moduleIndex<m);
00156 
00157   // Results from TriggerEvent product - Attention: must look only for
00158   // modules actually run in this path for this event!
00159   for (unsigned int j=0; j<=moduleIndex; ++j) {
00160     const string& moduleLabel(moduleLabels[j]);
00161     const string  moduleType(hltConfig_.moduleType(moduleLabel));
00162     // check whether the module is packed up in TriggerEvent product
00163     const unsigned int filterIndex(triggerEventHandle_->filterIndex(InputTag(moduleLabel,"",processName_)));
00164     if (filterIndex<triggerEventHandle_->sizeFilters()) {
00165       cout << " 'L3' filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType << endl;
00166       const Vids& VIDS (triggerEventHandle_->filterIds(filterIndex));
00167       const Keys& KEYS(triggerEventHandle_->filterKeys(filterIndex));
00168       const size_type nI(VIDS.size());
00169       const size_type nK(KEYS.size());
00170       assert(nI==nK);
00171       const size_type n(max(nI,nK));
00172       cout << "   " << n  << " accepted 'L3' objects found: " << endl;
00173       const TriggerObjectCollection& TOC(triggerEventHandle_->getObjects());
00174       for (size_type i=0; i!=n; ++i) {
00175         const TriggerObject& TO(TOC[KEYS[i]]);
00176         cout << "   " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "
00177              << TO.id() << " " << TO.pt() << " " << TO.eta() << " " << TO.phi() << " " << TO.mass()
00178              << endl;
00179       }
00180     }
00181   }
00182 
00183    return;
00184 }