CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQMOffline/Trigger/src/BPAGTrigAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     TopTrigAnalyzer
00004 // Class:       BPAGTrigAnalyzer
00005 // 
00013 //
00014 // Original Author:  Muriel Vander Donckt
00015 //         Created:  Tue Jul 24 12:17:12 CEST 2007
00016 // $Id: BPAGTrigAnalyzer.cc,v 1.7 2010/07/21 04:23:22 wmtan Exp $
00017 //
00018 //
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDAnalyzer.h"
00026 #include "FWCore/Framework/interface/Event.h"
00027 
00028 
00029 #include "FWCore/Framework/interface/Run.h"
00030 #include "FWCore/Framework/interface/EventSetup.h"
00031 
00032 
00033 #include "FWCore/Framework/interface/MakerMacros.h"
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00036 
00037 #include "DQMOffline/Trigger/interface/HLTMuonMatchAndPlot.h"
00038 #include "DQMOffline/Trigger/interface/HLTMuonBPAG.h"
00039 //#include "DQMOffline/Trigger/interface/HLTMuonOverlap.h"
00040 
00041 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00042 #include "FWCore/ServiceRegistry/interface/Service.h"
00043 //#include "CommonTools/Utilities/interface/StringCutObjectSelector.h"
00044 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00045 
00046 #include "TFile.h"
00047 #include "TDirectory.h"
00048 
00049 using namespace std;
00050 using namespace edm;
00051 using reco::Muon;
00052 
00053 class BPAGTrigAnalyzer : public edm::EDAnalyzer {
00054 
00055 public:
00056   explicit BPAGTrigAnalyzer(const edm::ParameterSet&);
00057   ~BPAGTrigAnalyzer();
00058 
00059 private:
00060   virtual void beginJob() ;
00061   virtual void beginRun(edm::Run const& currentRun, edm::EventSetup const& currentEventSetup);
00062   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00063   virtual void endJob() ;
00064 
00065   int theNumberOfTriggers;
00066 
00067   std::vector<HLTMuonMatchAndPlot*> theTriggerAnalyzers;
00068   std::vector<HLTMuonBPAG*> theTopPlotters;
00069   
00070   //HLTMuonOverlap *theOverlapAnalyzer;
00071 
00072   bool weHaveProcessedTheFirstRun;
00073   bool useDQMStore;
00074 
00075   vector<string> triggerNames;
00076   string theHltProcessName;
00077   vector<edm::ParameterSet> customCollection;
00078 
00079   const ParameterSet& initialPset;
00080 
00081 
00082 };
00083 
00084 
00085 BPAGTrigAnalyzer::BPAGTrigAnalyzer(const ParameterSet& pset) :
00086   initialPset(pset)
00087 {
00088 
00089   LogTrace ("HLTMuonVal") << "\n\n Inside MuonTriggerRate Constructor\n\n";
00090   
00091   vector<string> triggerNames = initialPset.getParameter< vector<string> >
00092                                 ("TriggerNames");
00093   theHltProcessName = initialPset.getParameter<string>("HltProcessName");
00094 
00095   //string defRecoLabel = initialPset.getUntrackedParameter<string>("RecoLabel","");
00096   //string highPtTracksLabel =  initialPset.getParameter <string> ("highPtTrackCollection");
00097 
00098   //vector<string> recoCollectionNames = initialPset.getParameter < vector<string> > ("allCollectionNames");
00099 
00100   
00101   // make analyzers for each collection. Push the collections into a vector
00102   //vector <string> recoCollectionNames;
00103   //if (defRecoLabel != "") recoCollectionNames.push_back(defRecoLabel);
00104   //if (highPtTracksLabel != "") recoCollectionNames.push_back(highPtTracksLabel);
00105 
00106   vector<edm::ParameterSet> customCollection = initialPset.getParameter<vector<edm::ParameterSet> > ("customCollection");
00107 
00108 
00109 
00110   LogTrace ("HLTMuonVal") << "customCollection is a vector of size = " << customCollection.size() << std::endl
00111                           << "looping over entries... and storing descriptions in a root file" << std::endl;
00112 
00113   useDQMStore = initialPset.getUntrackedParameter<bool>("DQMStore", false);
00114 
00115 
00116   weHaveProcessedTheFirstRun = false;
00117   
00118 }
00119 
00120 void BPAGTrigAnalyzer::beginRun(edm::Run const& currentRun, edm::EventSetup const& currentEventSetup) {
00121 
00122   if(!weHaveProcessedTheFirstRun) {
00123     weHaveProcessedTheFirstRun = true;
00124 
00125     vector<edm::ParameterSet>::iterator iPSet;
00126       
00127     DQMStore * dbe_ = 0;
00128     if (useDQMStore  ) {
00129       dbe_ = Service<DQMStore>().operator->();
00130       dbe_->setVerbose(0);    
00131     }
00132 
00133 
00135     //
00136     // Parse the inputs
00137     //
00139   
00140     vector < MuonSelectionStruct > customSelectors;
00141     vector < MuonSelectionStruct > tagSelectors;
00142     vector < string > customNames;
00143     // Print out information about each initialPset
00144     for ( iPSet = customCollection.begin();
00145           iPSet != customCollection.end();
00146           iPSet++) {
00147       string customCuts  = iPSet->getUntrackedParameter<string> ("recoCuts");
00148       string customName = iPSet->getUntrackedParameter<string> ("collectionName");
00149       string hltCuts   = iPSet->getUntrackedParameter<string> ("hltCuts");
00150       string targetTrackCollection = iPSet->getUntrackedParameter<string> ("trackCollection");
00151       double  customD0Cut = iPSet->getUntrackedParameter<double> ("d0cut");
00152       double customZ0Cut = iPSet->getUntrackedParameter<double> ("z0cut");
00153 
00154       // the following two parameters are not currently used
00155       // but maybe in the future
00156       double customChi2Cut = iPSet->getUntrackedParameter<double> ("chi2cut", 30.0);
00157       int customNHitsCut = iPSet->getUntrackedParameter<int> ("nHits", 10);
00158 
00159       //
00160       vector<string> requiredTriggers = iPSet->getUntrackedParameter< vector<string> > ("requiredTriggers");
00161     
00162       LogTrace("HLTMuonVal") << "customTargetCollection = " << customName  << std::endl
00163                              << "customCuts = " << customCuts << std::endl
00164                              << "targetTrackCollection = " << targetTrackCollection << std::endl
00165                              << "d0 cut = " << customD0Cut << std::endl
00166                              << "z0 cut = " << customZ0Cut << std:: endl
00167                              << "nHits cut = " << customNHitsCut << std::endl
00168                              << "chi2 cut = " << customChi2Cut <<std::endl;
00169 
00170       // parse the tag selection cuts
00171 
00172       string tagCustomCuts  = iPSet->getUntrackedParameter<string> ("tagRecoCuts");
00173       string tagCustomName = iPSet->getUntrackedParameter<string> ("tagCollectionName");
00174       string tagHltCuts   = iPSet->getUntrackedParameter<string> ("tagHltCuts");
00175       string tagTargetTrackCollection = iPSet->getUntrackedParameter<string> ("tagTrackCollection");
00176       double  tagCustomD0Cut = iPSet->getUntrackedParameter<double> ("tagD0cut");
00177       double tagCustomZ0Cut = iPSet->getUntrackedParameter<double> ("tagZ0cut");
00178       // not used (VR)
00179       //double tagCustomChi2Cut = iPSet->getUntrackedParameter<double> ("tagChi2cut");
00180       // not used (VR)
00181       //int tagCustomNHitsCut = iPSet->getUntrackedParameter<int> ("tagNHits");  
00182       string tagObjectTrigger = iPSet->getUntrackedParameter< string > ("tagObjectTrigger");
00183 
00184       // re-use this variable
00185       // which would normally be called
00186       // "required trigger"
00187       // now it is the trigger to require
00188       // for the tag muon
00189       vector<string> tagObjTrigVec;
00190       tagObjTrigVec.push_back(tagObjectTrigger);
00191     
00192 
00193       if (dbe_) {
00194 
00195         string description = customName + ", reco cuts = " + customCuts
00196           + ", hlt cuts = " + hltCuts + ", trackCollection = " + targetTrackCollection
00197           + ", required triggers, ";
00198 
00199         // add the required triggers
00200         for (vector <string>::const_iterator trigit = requiredTriggers.begin();
00201              trigit != requiredTriggers.end();
00202              trigit++){
00203           description  += (*trigit) + ", ";
00204         }
00205 
00206         // Add the other cuts
00207         ostringstream ossd0, ossz0, osschi2, osshits;
00208 
00209       
00210         ossd0 << customD0Cut;
00211         ossz0 << customZ0Cut;
00212         osschi2 << customChi2Cut;
00213         osshits << customNHitsCut;
00214 
00215         description += "|d0| < "  + ossd0.str() + ", |z0| < " + ossz0.str()
00216           + ", chi2 < " + osschi2.str() + ", nHits > " + osshits.str();
00217 
00218         LogTrace ("HLTMuonVal") << "Storing description = " << description << endl;
00219 
00220         dbe_->setCurrentFolder("HLT/Muon/Distributions/");
00221 
00222         dbe_->bookString (customName, description);
00223       
00224       
00225 
00226       }
00227 
00228     
00229       StringCutObjectSelector<reco::Muon> tempRecoSelector(customCuts);
00230       StringCutObjectSelector<trigger::TriggerObject> tempHltSelector(hltCuts);
00231     
00232       // create a custom selector
00233       MuonSelectionStruct tempStruct(tempRecoSelector, tempHltSelector,
00234                                      customName, customD0Cut, customZ0Cut,
00235                                      //customChi2Cut, customNHitsCut,
00236                                      targetTrackCollection, requiredTriggers);
00237 
00238       StringCutObjectSelector<reco::Muon> tagTempRecoSelector(tagCustomCuts);
00239       StringCutObjectSelector<trigger::TriggerObject> tagTempHltSelector(tagHltCuts);
00240     
00241       MuonSelectionStruct tempTagSelStruct(tagTempRecoSelector, tagTempHltSelector,
00242                                            tagCustomName, tagCustomD0Cut, tagCustomZ0Cut, 
00243                                            tagTargetTrackCollection, tagObjTrigVec);
00244     
00245 
00246     
00247       customNames.push_back ( customName);
00248       customSelectors.push_back(tempStruct);
00249       tagSelectors.push_back (tempTagSelStruct);
00250     }
00251 
00252 
00253 
00254   
00255   
00256     HLTConfigProvider hltConfig;
00257     bool hltConfigChanged;
00258     bool hltConfigInitSuccess = hltConfig.init(currentRun, currentEventSetup, theHltProcessName, hltConfigChanged);
00259     vector<string> validTriggerNames;
00260 
00261     if (hltConfigInitSuccess)
00262       validTriggerNames = hltConfig.triggerNames();
00263 
00264     if (validTriggerNames.size() < 1) {
00265       LogTrace ("HLTMuonVal") << endl << endl << endl
00266                               << "---> WARNING: The HLT Config Provider gave you an empty list of valid trigger names" << endl
00267                               << "Could be a problem with the HLT Process Name (you provided  " << theHltProcessName <<")" << endl
00268                               << "W/o valid triggers we can't produce plots, exiting..."
00269                               << endl << endl << endl;
00270       return;
00271     }
00272 
00273     vector<string>::const_iterator iDumpName;
00274     unsigned int numTriggers = 0;
00275     for (iDumpName = validTriggerNames.begin();
00276          iDumpName != validTriggerNames.end();
00277          iDumpName++) {
00278 
00279       LogTrace ("HLTMuonVal") << "Trigger " << numTriggers
00280                               << " is called " << (*iDumpName)
00281                               << endl;
00282       numTriggers++;
00283     }
00284 
00285 
00287     //
00288     // Create the analyzers
00289     //
00291 
00292     vector<MuonSelectionStruct>::iterator iMuonSelector;
00293     vector<string>::iterator iName = customNames.begin();
00294     vector<MuonSelectionStruct>::iterator iTagSelector = tagSelectors.begin();
00295   
00296   
00297     for ( iMuonSelector = customSelectors.begin();
00298           iMuonSelector != customSelectors.end();
00299           iMuonSelector++) {
00300   
00301       for( size_t i = 0; i < triggerNames.size(); i++) {
00302         bool isValidTriggerName = false;
00303         for ( size_t j = 0; j < validTriggerNames.size(); j++ )
00304           if ( triggerNames[i] == validTriggerNames[j] ) isValidTriggerName = true;
00305         if ( !isValidTriggerName ) {}   
00306         else {
00307           vector<string> moduleNames = hltConfig.moduleLabels( triggerNames[i] );
00308           //HLTMuonMatchAndPlot *analyzer;
00309           //analyzer = new HLTMuonMatchAndPlot ( initialPset, triggerNames[i], moduleNames, (*iMuonSelector), (*iName), validTriggerNames );
00310           HLTMuonBPAG * tempTop;
00311           tempTop = new HLTMuonBPAG ( initialPset, triggerNames[i], moduleNames, (*iMuonSelector), (*iTagSelector), (*iName), validTriggerNames, currentRun, currentEventSetup);
00312           //theTriggerAnalyzers.push_back( analyzer );
00313           theTopPlotters.push_back (tempTop);
00314         }
00315       }
00316       iName++;
00317       iTagSelector++;
00318     }
00319     //theOverlapAnalyzer = new HLTMuonOverlap( initialPset );    
00320 
00321     //theNumberOfTriggers = theTriggerAnalyzers.size();
00322     theNumberOfTriggers = theTopPlotters.size();  
00323 
00324   }
00325 }
00326 
00327 
00328 
00329   
00330 
00331 
00332 
00333 
00334 BPAGTrigAnalyzer::~BPAGTrigAnalyzer()
00335 {
00336  //  vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
00337 //   for ( thisAnalyzer  = theTriggerAnalyzers.begin(); 
00338 //         thisAnalyzer != theTriggerAnalyzers.end(); 
00339 //      ++thisAnalyzer )
00340 //   {
00341 //     delete *thisAnalyzer;
00342 //   }
00343 
00344   vector<HLTMuonBPAG *>::iterator iTopAna;
00345   for ( iTopAna  = theTopPlotters.begin(); 
00346         iTopAna != theTopPlotters.end(); 
00347         ++iTopAna )
00348   {
00349     delete *iTopAna;
00350   }
00351 
00352   theTopPlotters.clear();
00353   //theTriggerAnalyzers.clear();
00354   //delete theOverlapAnalyzer;
00355 }
00356 
00357 
00358 //
00359 // member functions
00360 //
00361 
00362 void
00363 BPAGTrigAnalyzer::analyze(const Event& iEvent, const EventSetup& iSetup)
00364 {
00365   //vector<HLTMuonMatchAndPlot *>::iterator thisAnalyzer;
00366 
00367   //  unsigned iAna = 0;
00368 //   for ( thisAnalyzer  = theTriggerAnalyzers.begin(); 
00369 //      thisAnalyzer != theTriggerAnalyzers.end(); ++thisAnalyzer )
00370 //     {
00371 //       (*thisAnalyzer)->analyze(iEvent);
00372 //       theTopPlotters[iAna]->analyze(iEvent);
00373 //       iAna++;
00374 //     }
00375 
00376   vector<HLTMuonBPAG *>::iterator iTopAna;
00377   for ( iTopAna  = theTopPlotters.begin(); 
00378         iTopAna != theTopPlotters.end(); 
00379         ++iTopAna )
00380   {
00381     (*iTopAna)->analyze(iEvent);
00382   }
00383 
00384 
00385   
00386   //theOverlapAnalyzer ->analyze(iEvent);
00387 }
00388 
00389 
00390 
00391 void 
00392 BPAGTrigAnalyzer::beginJob()
00393 {
00394   
00395   vector<HLTMuonBPAG *>::iterator thisAnalyzer;
00396   //unsigned iAna = 0;
00397   LogTrace ("HLTMuonVal") << "Inside begin job " << endl
00398                           << "Looping over analyzers"
00399                           << endl;
00400   
00401   for ( thisAnalyzer  = theTopPlotters.begin(); 
00402         thisAnalyzer != theTopPlotters.end(); 
00403         ++thisAnalyzer )
00404     {
00405      (*thisAnalyzer)->begin();     
00406     } 
00407   //theOverlapAnalyzer ->begin();
00408 }
00409 
00410 
00411 
00412 void 
00413 BPAGTrigAnalyzer::endJob() {
00414   vector<HLTMuonBPAG *>::iterator thisAnalyzer;
00415   //unsigned iAna = 0;
00416 
00417   LogTrace ("HLTMuonVal") << "Inside end job, looping over analyzers"
00418                           << endl;
00419   for ( thisAnalyzer  = theTopPlotters.begin(); 
00420         thisAnalyzer != theTopPlotters.end(); 
00421         ++thisAnalyzer )
00422     {
00423       (*thisAnalyzer)->finish();      
00424     }
00425   //theOverlapAnalyzer ->finish();
00426 }
00427 
00428 //define this as a plug-in
00429 DEFINE_FWK_MODULE(BPAGTrigAnalyzer);