CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQMOffline/Trigger/src/HLTTauDQMOfflineSource.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/HLTTauDQMOfflineSource.h"
00002 
00003 using namespace std;
00004 using namespace edm;
00005 using namespace reco;
00006 using namespace l1extra;
00007 using namespace trigger;
00008 
00009 //
00010 // constructors and destructor
00011 //
00012 HLTTauDQMOfflineSource::HLTTauDQMOfflineSource( const edm::ParameterSet& ps ) {
00013     //Get Initialization
00014     moduleName_     = ps.getUntrackedParameter<std::string>("ModuleName");
00015     dqmBaseFolder_  = ps.getUntrackedParameter<std::string>("DQMBaseFolder");
00016     hltProcessName_ = ps.getUntrackedParameter<std::string>("HLTProcessName","HLT");
00017     L1MatchDr_      = ps.getUntrackedParameter<double>("L1MatchDeltaR",0.5);
00018     HLTMatchDr_     = ps.getUntrackedParameter<double>("HLTMatchDeltaR",0.2);
00019     verbose_        = ps.getUntrackedParameter<bool>("Verbose",false);
00020     counterEvt_     = 0;
00021     hltMenuChanged_ = true;
00022     automation_     = HLTTauDQMAutomation(hltProcessName_, L1MatchDr_, HLTMatchDr_);        
00023     ps_             = ps;
00024 }
00025 
00026 HLTTauDQMOfflineSource::~HLTTauDQMOfflineSource() {
00027     //Clear the plotter collections
00028     while (!l1Plotters.empty()) delete l1Plotters.back(), l1Plotters.pop_back();
00029     while (!caloPlotters.empty()) delete caloPlotters.back(), caloPlotters.pop_back();
00030     while (!trackPlotters.empty()) delete trackPlotters.back(), trackPlotters.pop_back();
00031     while (!pathPlotters.empty()) delete pathPlotters.back(), pathPlotters.pop_back();
00032     while (!litePathPlotters.empty()) delete litePathPlotters.back(), litePathPlotters.pop_back();
00033 }
00034 
00035 //--------------------------------------------------------
00036 void HLTTauDQMOfflineSource::beginJob() {    
00037 }
00038 
00039 //--------------------------------------------------------
00040 void HLTTauDQMOfflineSource::beginRun( const edm::Run& iRun, const EventSetup& iSetup ) {
00041     //Evaluate configuration for every new trigger menu
00042     if ( HLTCP_.init(iRun, iSetup, hltProcessName_, hltMenuChanged_) ) {
00043         if ( hltMenuChanged_ ) {
00044             processPSet(ps_);
00045             if (verbose_) {
00046                 std::cout << "Trigger menu '" << HLTCP_.tableName() << "'" << std::endl;
00047                 HLTCP_.dump("Triggers");
00048                 
00049                 std::cout << std::endl << "Configuration of '" << moduleName_ << "' for trigger menu '" << HLTCP_.tableName() << "'" << std::endl;
00050                 for ( unsigned int i = 0; i < config_.size(); ++i ) {
00051                     std::cout << config_[i].dump() << std::endl;
00052                 }
00053                 std::cout << matching_.dump() << std::endl << std::endl;
00054                 
00055                 unsigned int npars = 14;
00056                 npars += countParameters(matching_);
00057                 for ( unsigned int i = 0; i < config_.size(); ++i ) {
00058                     npars += countParameters(config_[i]);
00059                 }
00060                 
00061                 std::cout << "--> Number of parameters: " << npars << std::endl;
00062                 std::cout << std::endl << "Event content need by this module: " << std::endl;
00063                 
00064                 std::vector<edm::InputTag> evtcontent;
00065                 for ( unsigned int i = 0; i < config_.size(); ++i ) {
00066                     searchEventContent(evtcontent, config_[i]);
00067                 }
00068                 searchEventContent(evtcontent, matching_);
00069                 
00070                 for (std::vector<edm::InputTag>::const_iterator iter = evtcontent.begin(); iter != evtcontent.end(); ++iter) {
00071                     std::cout << " " << iter->encode() << std::endl;
00072                 }
00073             }
00074         }
00075     } else {
00076         edm::LogWarning("HLTTauDQMOfflineSource") << "HLT config extraction failure with process name '" << hltProcessName_ << "'";
00077     }
00078 }
00079 
00080 //--------------------------------------------------------
00081 void HLTTauDQMOfflineSource::beginLuminosityBlock( const LuminosityBlock& lumiSeg, const EventSetup& context ) {
00082 }
00083 
00084 // ----------------------------------------------------------
00085 void HLTTauDQMOfflineSource::analyze(const Event& iEvent, const EventSetup& iSetup ) {
00086     //Apply the prescaler
00087     if (counterEvt_ > prescaleEvt_) {
00088         //Do Analysis here
00089         counterEvt_ = 0;
00090 
00091         //Create match collections
00092         std::map<int,LVColl> refC;
00093         
00094         if (doRefAnalysis_) {
00095             for ( std::vector<edm::ParameterSet>::const_iterator iter = refObjects_.begin(); iter != refObjects_.end(); ++iter ) {
00096                 int objID = iter->getUntrackedParameter<int>("matchObjectID");
00097                 
00098                 Handle<LVColl> collHandle;
00099                 if ( iEvent.getByLabel(iter->getUntrackedParameter<edm::InputTag>("FilterName"),collHandle) ) {
00100                     std::map<int,LVColl>::iterator it;
00101                     
00102                     if ( std::abs(objID) == 15 ) {
00103                         it = refC.find(15);
00104                         if ( it == refC.end() ) {
00105                             refC.insert(std::pair<int,LVColl>(15,*collHandle));
00106                         } else {
00107                             it->second.insert(it->second.end(),collHandle->begin(),collHandle->end());
00108                         }
00109                     } else if ( std::abs(objID) == 11 ) {
00110                         it = refC.find(11);
00111                         if ( it == refC.end() ) {
00112                             refC.insert(std::pair<int,LVColl>(11,*collHandle));
00113                         } else {
00114                             it->second.insert(it->second.end(),collHandle->begin(),collHandle->end());
00115                         }
00116                     } else if ( std::abs(objID) == 13 ) {
00117                         it = refC.find(13);
00118                         if ( it == refC.end() ) {
00119                             refC.insert(std::pair<int,LVColl>(13,*collHandle));
00120                         } else {
00121                             it->second.insert(it->second.end(),collHandle->begin(),collHandle->end());
00122                         }
00123                     } else {
00124                         it = refC.find(objID);
00125                         if ( it == refC.end() ) {
00126                             refC.insert(std::pair<int,LVColl>(objID,*collHandle));
00127                         } else {
00128                             it->second.insert(it->second.end(),collHandle->begin(),collHandle->end());
00129                         }
00130                     }
00131                 }
00132             }
00133         }
00134         
00135         //Path Plotters
00136         for ( unsigned int i = 0; i < pathPlotters.size(); ++i ) {
00137             if (pathPlotters[i]->isValid()) pathPlotters[i]->analyze(iEvent,iSetup,refC);
00138         }
00139         
00140         //Lite Path Plotters
00141         for ( unsigned int i = 0; i < litePathPlotters.size(); ++i ) {
00142             if (litePathPlotters[i]->isValid()) litePathPlotters[i]->analyze(iEvent,iSetup,refC);
00143         }
00144         
00145         //L1 Plotters
00146         for ( unsigned int i = 0; i < l1Plotters.size(); ++i ) {
00147             if (l1Plotters[i]->isValid()) l1Plotters[i]->analyze(iEvent,iSetup,refC);
00148         }
00149         
00150         //Calo Plotters
00151         for ( unsigned int i = 0; i < caloPlotters.size(); ++i ) {
00152             if (caloPlotters[i]->isValid()) caloPlotters[i]->analyze(iEvent,iSetup,refC);            
00153         }
00154         
00155         //Track Plotters
00156         for ( unsigned int i = 0; i < trackPlotters.size(); ++i ) {
00157             if (trackPlotters[i]->isValid()) trackPlotters[i]->analyze(iEvent,iSetup,refC);
00158         }
00159     } else {
00160         counterEvt_++;
00161     }
00162 }
00163 
00164 //--------------------------------------------------------
00165 void HLTTauDQMOfflineSource::endLuminosityBlock( const LuminosityBlock& lumiSeg, const EventSetup& context ) {
00166 }
00167 
00168 //--------------------------------------------------------
00169 void HLTTauDQMOfflineSource::endRun( const Run& r, const EventSetup& context ) {
00170 }
00171 
00172 //--------------------------------------------------------
00173 void HLTTauDQMOfflineSource::endJob() {
00174     return;
00175 }
00176 
00177 void HLTTauDQMOfflineSource::processPSet( const edm::ParameterSet& pset ) {
00178     //Get General Monitoring Parameters
00179     config_        = pset.getParameter<std::vector<edm::ParameterSet> >("MonitorSetup");
00180     matching_      = pset.getParameter<edm::ParameterSet>("Matching");
00181     NPtBins_       = pset.getUntrackedParameter<int>("PtHistoBins",20);
00182     NEtaBins_      = pset.getUntrackedParameter<int>("EtaHistoBins",25);
00183     NPhiBins_      = pset.getUntrackedParameter<int>("PhiHistoBins",32);
00184     EtMax_         = pset.getUntrackedParameter<double>("EtHistoMax",100);
00185     prescaleEvt_   = pset.getUntrackedParameter<int>("prescaleEvt", -1);
00186     doRefAnalysis_ = matching_.getUntrackedParameter<bool>("doMatching");
00187     refObjects_    = matching_.getUntrackedParameter<std::vector<edm::ParameterSet> >("matchFilters");
00188     
00189     //Clear the plotter collections first
00190     while (!l1Plotters.empty()) delete l1Plotters.back(), l1Plotters.pop_back();
00191     while (!caloPlotters.empty()) delete caloPlotters.back(), caloPlotters.pop_back();
00192     while (!trackPlotters.empty()) delete trackPlotters.back(), trackPlotters.pop_back();
00193     while (!pathPlotters.empty()) delete pathPlotters.back(), pathPlotters.pop_back();
00194     while (!litePathPlotters.empty()) delete litePathPlotters.back(), litePathPlotters.pop_back();
00195     
00196     //Automatic Configuration
00197     automation_.AutoCompleteConfig( config_, HLTCP_ );
00198 
00199     //Read The Configuration
00200     for ( unsigned int i = 0; i < config_.size(); ++i ) {
00201         std::string configtype;
00202         try {
00203             configtype = config_[i].getUntrackedParameter<std::string>("ConfigType");
00204         } catch ( cms::Exception &e ) {
00205             edm::LogWarning("HLTTauDQMOfflineSource")
00206             << e.what() << std::endl;
00207             continue;
00208         }
00209         if (configtype == "L1") {
00210             try {
00211                 l1Plotters.push_back(new HLTTauDQML1Plotter(config_[i],NPtBins_,NEtaBins_,NPhiBins_,EtMax_,doRefAnalysis_,L1MatchDr_,dqmBaseFolder_));
00212             } catch ( cms::Exception &e ) {
00213                 edm::LogWarning("HLTTauDQMSource") << e.what() << std::endl;
00214                 continue;
00215             }
00216         } else if (configtype == "Calo") {
00217             try {
00218                 caloPlotters.push_back(new HLTTauDQMCaloPlotter(config_[i],NPtBins_,NEtaBins_,NPhiBins_,EtMax_,doRefAnalysis_,HLTMatchDr_,dqmBaseFolder_));
00219             } catch ( cms::Exception &e ) {
00220                 edm::LogWarning("HLTTauDQMSource") << e.what() << std::endl;
00221                 continue;
00222             }
00223         } else if (configtype == "Track") {
00224             try {
00225                 trackPlotters.push_back(new HLTTauDQMTrkPlotter(config_[i],NPtBins_,NEtaBins_,NPhiBins_,EtMax_,doRefAnalysis_,HLTMatchDr_,dqmBaseFolder_));    
00226             } catch ( cms::Exception &e ) {
00227                 edm::LogWarning("HLTTauDQMSource") << e.what() << std::endl;
00228                 continue;
00229             }
00230         } else if (configtype == "Path") {
00231             try {
00232                 pathPlotters.push_back(new HLTTauDQMPathPlotter(config_[i],doRefAnalysis_,dqmBaseFolder_));
00233             } catch ( cms::Exception &e ) {
00234                 edm::LogWarning("HLTTauDQMSource") << e.what() << std::endl;
00235                 continue;
00236             }
00237         } else if (configtype == "LitePath") {
00238             try {
00239                 litePathPlotters.push_back(new HLTTauDQMLitePathPlotter(config_[i],NPtBins_,NEtaBins_,NPhiBins_,EtMax_,doRefAnalysis_,HLTMatchDr_,dqmBaseFolder_));   
00240             } catch ( cms::Exception &e ) {
00241                 edm::LogWarning("HLTTauDQMSource") << e.what() << std::endl;
00242                 continue;
00243             }
00244         }
00245     }
00246 }
00247 
00248 unsigned int HLTTauDQMOfflineSource::countParameters( const edm::ParameterSet& pset ) {
00249     unsigned int num = 0;
00250     const std::map<std::string,edm::ParameterSetEntry>& tmppset = pset.psetTable();
00251     for ( std::map<std::string,edm::ParameterSetEntry>::const_iterator iter = tmppset.begin(); iter != tmppset.end(); ++iter ) {
00252         num += countParameters(iter->second.pset());
00253     }
00254     const std::map<std::string,edm::VParameterSetEntry>& tmpvpset = pset.vpsetTable();
00255     for ( std::map<std::string,edm::VParameterSetEntry>::const_iterator iter = tmpvpset.begin(); iter != tmpvpset.end(); ++iter ) {
00256         const std::vector<edm::ParameterSet>& tmpvec = iter->second.vpset();
00257         for ( std::vector<edm::ParameterSet>::const_iterator iter2 = tmpvec.begin(); iter2 != tmpvec.end(); ++iter2 ) {
00258             num += countParameters(*iter2);
00259         }
00260     }
00261     num += pset.tbl().size();
00262     return num;
00263 }
00264 
00265 void HLTTauDQMOfflineSource::searchEventContent(std::vector<edm::InputTag>& eventContent, const edm::ParameterSet& pset) {
00266     for (std::map< std::string, edm::Entry >::const_iterator i = pset.tbl().begin(), e = pset.tbl().end(); i != e; ++i) {
00267         if (std::string(1,i->second.typeCode()) == "t") {
00268             std::vector<edm::InputTag>::iterator iter = std::find(eventContent.begin(), eventContent.end(), i->second.getInputTag());
00269             if (iter == eventContent.end()) {
00270                 eventContent.push_back(i->second.getInputTag());
00271             }
00272         }
00273     }
00274     for (std::map< std::string, edm::ParameterSetEntry >::const_iterator i = pset.psetTable().begin(), e = pset.psetTable().end(); i != e; ++i) {
00275         searchEventContent(eventContent, i->second.pset());
00276     }
00277     for (std::map< std::string, edm::VParameterSetEntry >::const_iterator i = pset.vpsetTable().begin(), e = pset.vpsetTable().end(); i != e; ++i) {
00278         std::vector<edm::ParameterSet> vpset = i->second.vpset();
00279         for (std::vector<edm::ParameterSet>::const_iterator iter = vpset.begin(); iter != vpset.end(); ++iter) {
00280             searchEventContent(eventContent, *iter);
00281         }
00282     }
00283 }