00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "DataFormats/Common/interface/Handle.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "DQM/HLTEvF/interface/HLTMonPhotonSource.h"
00008 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00009 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00010 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00011 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00013 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00014 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00015 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00016
00017
00018 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00019 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00020 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00021 #include "DataFormats/EgammaCandidates/interface/ElectronIsolationAssociation.h"
00022 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00023 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00024 #include "DataFormats/Common/interface/RefToBase.h"
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027
00028 using namespace edm;
00029
00030
00031 HLTMonPhotonSource::HLTMonPhotonSource(const edm::ParameterSet& iConfig)
00032 {
00033
00034 LogDebug("HLTMonPhotonSource") << "constructor...." ;
00035
00036 logFile_.open("HLTMonPhotonSource.log");
00037
00038 dbe = NULL;
00039 if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00040 dbe = Service < DQMStore > ().operator->();
00041 dbe->setVerbose(0);
00042 }
00043
00044
00045
00046 outputFile_ =
00047 iConfig.getUntrackedParameter < std::string > ("outputFile", "");
00048 if (outputFile_.size() != 0) {
00049 edm::LogInfo("HLTMonPhotonSource") << "Photon Trigger Monitoring histograms will be saved to " <<
00050 outputFile_ ;
00051
00052 }
00053 else {
00054
00055
00056 outputFile_ = "PhotonDQM.root";
00057 }
00058
00059 bool disable =
00060 iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
00061 if (disable) {
00062 std::cout<<"output disabled?\n\n\n";
00063 outputFile_ = "";
00064 }
00065
00066 dirname_="HLT/HLTMonPhoton/"+iConfig.getParameter<std::string>("@module_label");
00067
00068 if (dbe != NULL) {
00069 dbe->setCurrentFolder(dirname_);
00070 }
00071
00072
00073
00074
00075 thePtMin = iConfig.getUntrackedParameter<double>("PtMin",0.);
00076 thePtMax = iConfig.getUntrackedParameter<double>("PtMax",1000.);
00077 theNbins = iConfig.getUntrackedParameter<unsigned int>("Nbins",40);
00078
00079
00080 reqNum = iConfig.getParameter<unsigned int>("reqNum");
00081 std::vector<edm::ParameterSet> filters = iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
00082
00083 for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++){
00084 theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
00085 theHLTOutputTypes.push_back(filterconf->getParameter<unsigned int>("theHLTOutputTypes"));
00086 std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
00087 assert(bounds.size() == 2);
00088 plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
00089 isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
00090 assert(isoNames.back().size()>0);
00091 if (isoNames.back().at(0).label()=="none")
00092 plotiso.push_back(false);
00093 else{
00094 plotiso.push_back(true);
00095 }
00096 }
00097
00098
00099
00100 }
00101
00102
00103 HLTMonPhotonSource::~HLTMonPhotonSource()
00104 {
00105
00106
00107
00108
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 void
00118 HLTMonPhotonSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00119 {
00120 using namespace edm;
00121 using namespace trigger;
00122 nev_++;
00123
00124 edm::LogInfo("HLTMonPhotonSource")<< "HLTMonPhotonSource: analyze...." ;
00125
00126
00127 edm::Handle<trigger::TriggerEventWithRefs> triggerObj;
00128 iEvent.getByLabel("hltTriggerSummaryRAW",triggerObj);
00129 if(!triggerObj.isValid()) {
00130 edm::LogWarning("HLTMonPhotonSource") << "RAW-type HLT results not found, skipping event";
00131 return;
00132 }
00133
00134 maxEt = 0.;
00135 eta = 999.;
00136 phi = 999.;
00137
00138
00139 sigmaetaeta=0.;
00140
00141 for(unsigned int n=0; n < theHLTCollectionLabels.size() ; n++) {
00142
00143
00144
00145 switch(theHLTOutputTypes[n]){
00146 case 82:
00147 fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00148 case 83:
00149 fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
00150 case 91:
00151 fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00152 case 92:
00153 fillHistos<reco::ElectronCollection>(triggerObj,iEvent,n);break;
00154 case 100:
00155 fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
00156 default: throw(cms::Exception("Release Validation Error")<< "HLT output type not implemented: theHLTOutputTypes[n]" );
00157 }
00158 }
00159 }
00160
00161 template <class T> void HLTMonPhotonSource::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent ,unsigned int n){
00162
00163 std::vector<edm::Ref<T> > recoecalcands;
00164
00165
00166
00167
00168
00169 if (!( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){
00170
00171
00172
00173
00174
00175
00176 triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],recoecalcands);
00177
00178
00179 if(theHLTOutputTypes[n]==82){
00180 std::vector<edm::Ref<T> > isocands;
00181 triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),83,isocands);
00182 if(isocands.size()>0)
00183 for(unsigned int i=0; i < isocands.size(); i++)
00184 recoecalcands.push_back(isocands[i]);
00185 }
00186
00187
00188
00189
00190 if(n == 0 && recoecalcands.size()!=0){
00191 for (unsigned int i=0; i<recoecalcands.size(); i++) {
00192 if(recoecalcands[i]->et() > maxEt){
00193 maxEt = recoecalcands[i]->et();
00194 eta = recoecalcands[i]->eta();
00195 phi = recoecalcands[i]->phi();
00196
00197 if ( theHLTOutputTypes[n]==100){
00198
00199 }
00200 }
00201 }
00202 }
00203
00204
00205
00206 if (recoecalcands.size()!=0){
00207 if(recoecalcands.size() >= reqNum){
00208 eventCounter->Fill(n+0.5);
00209 ethist[n]->Fill(maxEt);
00210 phihist[n]->Fill(phi);
00211 etahist[n]->Fill(eta);
00212
00213
00214
00215 for (unsigned int i=0; i<recoecalcands.size(); i++) {
00216
00217 if(n+1 < theHLTCollectionLabels.size()){
00218 if(plotiso[n+1]){
00219 for(unsigned int j = 0 ; j < isoNames[n+1].size() ;j++ ){
00220 edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMap;
00221 iEvent.getByLabel(isoNames[n+1].at(j).label(),depMap);
00222 typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
00223 if(mapi!=depMap->end()){
00224 histiso[n+1]->Fill(mapi->val);
00225 etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
00226 phihistiso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
00227 ethistiso[n+1]->Fill(recoecalcands[i]->et(),mapi->val);
00228 break;
00229 }
00230 }
00231 }
00232 }
00233 }
00234 }
00235 }
00236 }
00237 }
00238
00239 void
00240 HLTMonPhotonSource::beginJob()
00241 {
00242 nev_ = 0;
00243 DQMStore *dbe = 0;
00244 dbe = Service < DQMStore > ().operator->();
00245
00246 if (dbe) {
00247 dbe->setCurrentFolder(dirname_);
00248 dbe->rmdir(dirname_);
00249 }
00250
00251
00252 if (dbe) {
00253 dbe->setCurrentFolder(dirname_);
00254
00255 std::string histoname;
00256 MonitorElement* tmphisto;
00257
00258 eventCounter = dbe->book1D("Evts Passing Filters","Evts Passing Filters",5,0,5);
00259 eventCounter->setBinLabel(1,"SinglePhotonEtFilter");
00260 eventCounter->setBinLabel(2,"SinglePhotonEcalIsolFilter");
00261 eventCounter->setBinLabel(3,"SinglePhotonHcalIsolFilter");
00262 eventCounter->setBinLabel(4,"SinglePhotonTrackIsolFilter");
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 for(unsigned int i = 0; i< theHLTCollectionLabels.size() ; i++){
00296 histoname = theHLTCollectionLabels[i].label()+" Et Dist";
00297 tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax);
00298 ethist.push_back(tmphisto);
00299
00300 histoname = theHLTCollectionLabels[i].label()+" Eta Dist";
00301 tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7);
00302 etahist.push_back(tmphisto);
00303
00304 histoname = theHLTCollectionLabels[i].label()+" Phi Dist";
00305 tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2);
00306 phihist.push_back(tmphisto);
00307
00308 if(plotiso[i]){
00309 histoname = theHLTCollectionLabels[i].label()+" Isolation Variable";
00310 tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,plotBounds[i].first,plotBounds[i].second);
00311 }
00312 else{
00313 tmphisto = NULL;
00314 }
00315 histiso.push_back(tmphisto);
00316
00317 if(plotiso[i]){
00318 histoname = theHLTCollectionLabels[i].label()+" Isolation vs Eta";
00319 tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7,theNbins,plotBounds[i].first,plotBounds[i].second);
00320 }
00321 else{
00322 tmphisto = NULL;
00323 }
00324 etahistiso.push_back(tmphisto);
00325
00326 if(plotiso[i]){
00327 histoname = theHLTCollectionLabels[i].label()+" Isolation vs Phi";
00328 tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2,theNbins,plotBounds[i].first,plotBounds[i].second);
00329 }
00330 else{
00331 tmphisto = NULL;
00332 }
00333 phihistiso.push_back(tmphisto);
00334
00335 if(plotiso[i]){
00336 histoname = theHLTCollectionLabels[i].label()+" Isolation vs Et";
00337 tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax,theNbins,plotBounds[i].first,plotBounds[i].second);
00338 }
00339 else{
00340 tmphisto = NULL;
00341 }
00342 ethistiso.push_back(tmphisto);
00343 }
00344 }
00345 }
00346
00347
00348 void
00349 HLTMonPhotonSource::endJob() {
00350
00351
00352
00353 LogInfo("HLTMonPhotonSource") << "analyzed " << nev_ << " events";
00354
00355 if (outputFile_.size() != 0 && dbe)
00356 dbe->save(outputFile_);
00357
00358
00359
00360
00361
00362
00363
00364
00365 return;
00366 }
00367
00368 DEFINE_FWK_MODULE(HLTMonPhotonSource);