CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/HLTriggerOffline/Egamma/src/EmDQMReco.cc

Go to the documentation of this file.
00001 
00002 //                    Header file for this                                    //
00004 #include "HLTriggerOffline/Egamma/interface/EmDQMReco.h"
00005 
00007 //                    Collaborating Class Header                              //
00009 #include "FWCore/Framework/interface/Frameworkfwd.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Framework/interface/MakerMacros.h"
00012 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00013 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00014 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00015 //#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00016 //#include "DataFormats/EgammaCandidates/interface/Photon.h"
00017 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00018 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00019 //#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00020 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "DataFormats/Common/interface/AssociationMap.h"
00023 
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "DataFormats/Common/interface/RefToBase.h"
00026 #include "FWCore/ServiceRegistry/interface/Service.h"
00027 //#include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00028 #include "FWCore/Utilities/interface/Exception.h"
00029 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00030 #include "DataFormats/Common/interface/TriggerResults.h"
00031 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00032 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00033 #include <boost/format.hpp>
00035 //                           Root include files                               //
00037 #include "TFile.h"
00038 #include "TDirectory.h"
00039 #include "TH1F.h"
00040 #include <iostream>
00041 #include <string>
00042 #include <Math/VectorUtil.h>
00043 using namespace ROOT::Math::VectorUtil ;
00044 
00045 //----------------------------------------------------------------------
00046 // class EmDQMReco::FourVectorMonitorElements
00047 //----------------------------------------------------------------------
00048 EmDQMReco::FourVectorMonitorElements::FourVectorMonitorElements(EmDQMReco *_parent,
00049     const std::string &histogramNameTemplate,
00050     const std::string &histogramTitleTemplate
00051   ) :
00052   parent(_parent)
00053 {
00054   // introducing variables for better code readability later on
00055   std::string histName;
00056   std::string histTitle;
00057 
00058   // et
00059   histName = boost::str(boost::format(histogramNameTemplate) % "et");
00060   histTitle = boost::str(boost::format(histogramTitleTemplate) % "E_{T}");
00061   etMonitorElement =  parent->dbe->book1D(histName.c_str(),
00062                                    histTitle.c_str(),
00063                                    parent->plotBins,
00064                                    parent->plotPtMin,
00065                                    parent->plotPtMax);
00066 
00067   // eta
00068   histName = boost::str(boost::format(histogramNameTemplate) % "eta");
00069   histTitle= boost::str(boost::format(histogramTitleTemplate) % "#eta");
00070   etaMonitorElement = parent->dbe->book1D(histName.c_str(),
00071                                   histTitle.c_str(),
00072                                   parent->plotBins,
00073                                   - parent->plotEtaMax,
00074                                     parent->plotEtaMax);
00075 
00076   // phi
00077   histName = boost::str(boost::format(histogramNameTemplate) % "phi");
00078   histTitle= boost::str(boost::format(histogramTitleTemplate) % "#phi");
00079   phiMonitorElement = parent->dbe->book1D(histName.c_str(),
00080                                   histTitle.c_str(),
00081                                   parent->plotBins,
00082                                   - parent->plotPhiMax,
00083                                     parent->plotPhiMax);
00084 }
00085 
00086 //----------------------------------------------------------------------
00087 
00088 void
00089 EmDQMReco::FourVectorMonitorElements::fill(const math::XYZTLorentzVector &momentum)
00090 {
00091   etMonitorElement->Fill(momentum.Et());
00092   etaMonitorElement->Fill(momentum.eta() );
00093   phiMonitorElement->Fill(momentum.phi() );
00094 }
00095 
00096 //----------------------------------------------------------------------
00097 
00099 //                             Constructor                                    //
00101 EmDQMReco::EmDQMReco(const edm::ParameterSet& pset)
00102 {
00103 
00104   dbe = edm::Service < DQMStore > ().operator->();
00105   dbe->setVerbose(0);
00106 
00107 
00109   //          Read from configuration file                  //
00111   dirname_="HLT/HLTEgammaValidation/"+pset.getParameter<std::string>("@module_label");
00112   dbe->setCurrentFolder(dirname_);
00113 
00114   // parameters for generator study
00115   reqNum    = pset.getParameter<unsigned int>("reqNum");
00116   pdgGen    = pset.getParameter<int>("pdgGen");
00117   recoEtaAcc = pset.getParameter<double>("genEtaAcc");
00118   recoEtAcc  = pset.getParameter<double>("genEtAcc");
00119   // plotting parameters (untracked because they don't affect the physics)
00120   plotPtMin  = pset.getUntrackedParameter<double>("PtMin",0.);
00121   plotPtMax  = pset.getUntrackedParameter<double>("PtMax",1000.);
00122   plotEtaMax = pset.getUntrackedParameter<double>("EtaMax", 2.7);
00123   plotPhiMax = pset.getUntrackedParameter<double>("PhiMax", 3.15);
00124   plotBins   = pset.getUntrackedParameter<unsigned int>("Nbins",50);
00125   useHumanReadableHistTitles = pset.getUntrackedParameter<bool>("useHumanReadableHistTitles", false);
00126 
00127   triggerNameRecoMonPath = pset.getUntrackedParameter<std::string>("triggerNameRecoMonPath","HLT_MinBias");
00128   processNameRecoMonPath = pset.getUntrackedParameter<std::string>("processNameRecoMonPath","HLT");
00129 
00130   recoElectronsInputTag  = pset.getUntrackedParameter<edm::InputTag>("recoElectrons",edm::InputTag("gsfElectrons"));
00131 
00132   // preselction cuts
00133   // recocutCollection_= pset.getParameter<edm::InputTag>("cutcollection");
00134   recocut_          = pset.getParameter<int>("cutnum");
00135 
00136   // prescale = 10;
00137   eventnum = 0;
00138 
00139   // just init
00140   isHltConfigInitialized_ = false;
00141 
00143   //         Read in the Vector of Parameter Sets.          //
00144   //           Information for each filter-step             //
00146   std::vector<edm::ParameterSet> filters =
00147        pset.getParameter<std::vector<edm::ParameterSet> >("filters");
00148 
00149   int i = 0;
00150   for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++)
00151   {
00152 
00153     theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
00154     theHLTOutputTypes.push_back(filterconf->getParameter<int>("theHLTOutputTypes"));
00155     // Grab the human-readable name, if it is not specified, use the Collection Label
00156     theHLTCollectionHumanNames.push_back(filterconf->getUntrackedParameter<std::string>("HLTCollectionHumanName",theHLTCollectionLabels[i].label()));
00157 
00158     std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
00159     // If the size of plot "bounds" vector != 2, abort
00160     assert(bounds.size() == 2);
00161     plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
00162     isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
00163     // If the size of the isoNames vector is not greater than zero, abort
00164     assert(isoNames.back().size()>0);
00165     if (isoNames.back().at(0).label()=="none") {
00166       plotiso.push_back(false);
00167     } else {
00168       plotiso.push_back(true);
00169     }
00170     i++;
00171   } // END of loop over parameter sets
00172 
00173   // Record number of HLTCollectionLabels
00174   numOfHLTCollectionLabels = theHLTCollectionLabels.size();
00175 
00176 }
00177 
00178 
00179 
00183 void EmDQMReco::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup ) {
00184 
00185   bool isHltConfigChanged = false; // change of cfg at run boundaries?
00186   isHltConfigInitialized_ = hltConfig_.init( iRun, iSetup, "HLT", isHltConfigChanged );
00187 
00188 }
00189 
00190 
00191 
00192 
00193 
00195 //       method called once each job just before starting event loop          //
00197 void
00198 EmDQMReco::beginJob()
00199 {
00200   //edm::Service<TFileService> fs;
00201   dbe->setCurrentFolder(dirname_);
00202 
00204   //  Set up Histogram of Effiency vs Step.                 //
00205   //   theHLTCollectionLabels is a vector of InputTags      //
00206   //    from the configuration file.                        //
00208 
00209   std::string histName="total_eff";
00210   std::string histTitle = "total events passing";
00211   // This plot will have bins equal to 2+(number of
00212   //        HLTCollectionLabels in the config file)
00213   totalreco = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
00214   totalreco->setBinLabel(numOfHLTCollectionLabels+1,"Total");
00215   totalreco->setBinLabel(numOfHLTCollectionLabels+2,"Reco");
00216   for (unsigned int u=0; u<numOfHLTCollectionLabels; u++){totalreco->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
00217 
00218   histName="total_eff_RECO_matched";
00219   histTitle="total events passing (Reco matched)";
00220   totalmatchreco = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
00221   totalmatchreco->setBinLabel(numOfHLTCollectionLabels+1,"Total");
00222   totalmatchreco->setBinLabel(numOfHLTCollectionLabels+2,"Reco");
00223   for (unsigned int u=0; u<numOfHLTCollectionLabels; u++){totalmatchreco->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
00224 
00225   // MonitorElement* tmphisto;
00226   MonitorElement* tmpiso;
00227 
00229   // Set up generator-level histograms                      //
00231   std::string pdgIdString;
00232   switch(pdgGen) {
00233   case 11:
00234     pdgIdString="Electron";break;
00235   case 22:
00236     pdgIdString="Photon";break;
00237   default:
00238     pdgIdString="Particle";
00239   }
00240 
00241   //--------------------
00242 
00243   // reco
00244   // (note that reset(..) must be used to set the value of the scoped_ptr...)
00245   histReco.reset(
00246       new FourVectorMonitorElements(this,
00247           "reco_%s",             // pattern for histogram name
00248           "%s of " + pdgIdString + "s"
00249       ));
00250 
00251   //--------------------
00252 
00253   // monpath
00254   histRecoMonpath.reset(
00255        new FourVectorMonitorElements(this,
00256            "reco_%s_monpath",   // pattern for histogram name
00257            "%s of " + pdgIdString + "s monpath"
00258        )
00259   );
00260 
00261   //--------------------
00262 
00263   // TODO: WHAT ARE THESE HISTOGRAMS FOR ? THEY SEEM NEVER REFERENCED ANYWHERE IN THIS FILE...
00264   // final X monpath
00265   histMonpath.reset(
00266        new FourVectorMonitorElements(this,
00267            "final_%s_monpath",   // pattern for histogram name
00268            "Final %s Monpath"
00269        )
00270   );
00271 
00272   //--------------------
00273 
00275   //  Set up histograms of HLT objects                      //
00277 
00278   // Determine what strings to use for histogram titles
00279   std::vector<std::string> HltHistTitle;
00280   if ( theHLTCollectionHumanNames.size() == numOfHLTCollectionLabels && useHumanReadableHistTitles ) {
00281     HltHistTitle = theHLTCollectionHumanNames;
00282   } else {
00283     for (unsigned int i =0; i < numOfHLTCollectionLabels; i++) {
00284       HltHistTitle.push_back(theHLTCollectionLabels[i].label());
00285     }
00286   }
00287 
00288   for(unsigned int i = 0; i< numOfHLTCollectionLabels ; i++){
00289     //--------------------
00290     // distributions of HLT objects passing filter i
00291     //--------------------
00292 
00293 //    // Et
00294 //    histName = theHLTCollectionLabels[i].label()+"et_all";
00295 //    histTitle = HltHistTitle[i]+" Et (ALL)";
00296 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
00297 //    ethist.push_back(tmphisto);
00298 //
00299 //    // Eta
00300 //    histName = theHLTCollectionLabels[i].label()+"eta_all";
00301 //    histTitle = HltHistTitle[i]+" #eta (ALL)";
00302 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
00303 //    etahist.push_back(tmphisto);
00304 //
00305 //    // phi
00306 //    histName = theHLTCollectionLabels[i].label()+"phi_all";
00307 //    histTitle = HltHistTitle[i]+" #phi (ALL)";
00308 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
00309 //    phiHist.push_back(tmphisto);
00310 
00311     standardHist.push_back(new FourVectorMonitorElements(this,
00312         theHLTCollectionLabels[i].label()+"%s_all", // histogram name
00313         HltHistTitle[i]+" %s (ALL)"                 // histogram title
00314         ));
00315 
00316     //--------------------
00317     // distributions of reco object matching HLT object passing filter i
00318     //--------------------
00319 
00320     // Et
00321 //    histName = theHLTCollectionLabels[i].label()+"et_RECO_matched";
00322 //    histTitle = HltHistTitle[i]+" Et (RECO matched)";
00323 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
00324 //    ethistmatchreco.push_back(tmphisto);
00325 
00326 //    // Eta
00327 //    histName = theHLTCollectionLabels[i].label()+"eta_RECO_matched";
00328 //    histTitle = HltHistTitle[i]+" #eta (RECO matched)";
00329 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
00330 //    etahistmatchreco.push_back(tmphisto);
00331 //
00332 //    // phi
00333 //    histName = theHLTCollectionLabels[i].label()+"phi_RECO_matched";
00334 //    histTitle = HltHistTitle[i]+" #phi (RECO matched)";
00335 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
00336 //    phiHistMatchReco.push_back(tmphisto);
00337     histMatchReco.push_back(new FourVectorMonitorElements(this,
00338         theHLTCollectionLabels[i].label()+"%s_RECO_matched", // histogram name
00339         HltHistTitle[i]+" %s (RECO matched)"                 // histogram title
00340         ));
00341 
00342     //--------------------
00343     // distributions of reco object matching HLT object passing filter i
00344     //--------------------
00345 
00346 //    // Et
00347 //    histName = theHLTCollectionLabels[i].label()+"et_RECO_matched_monpath";
00348 //    histTitle = HltHistTitle[i]+" Et (RECO matched, monpath)";
00349 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
00350 //    ethistmatchrecomonpath.push_back(tmphisto);
00351 //
00352 //    // Eta
00353 //    histName = theHLTCollectionLabels[i].label()+"eta_RECO_matched_monpath";
00354 //    histTitle = HltHistTitle[i]+" #eta (RECO matched, monpath)";
00355 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
00356 //    etahistmatchrecomonpath.push_back(tmphisto);
00357 //
00358 //    // phi
00359 //    histName = theHLTCollectionLabels[i].label()+"phi_RECO_matched_monpath";
00360 //    histTitle = HltHistTitle[i]+" #phi (RECO matched, monpath)";
00361 //    tmphisto =  dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
00362 //    phiHistMatchRecoMonPath.push_back(tmphisto);
00363 
00364     histMatchRecoMonPath.push_back(new FourVectorMonitorElements(this,
00365         theHLTCollectionLabels[i].label()+"%s_RECO_matched_monpath", // histogram name
00366         HltHistTitle[i]+" %s (RECO matched, monpath)"                // histogram title
00367         ));
00368     //--------------------
00369     // distributions of HLT object that is closest delta-R match to sorted reco particle(s)
00370     //--------------------
00371 
00372     // Et
00373 //    histName  = theHLTCollectionLabels[i].label()+"et_reco";
00374 //    histTitle = HltHistTitle[i]+" Et (reco)";
00375 //    tmphisto  = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
00376 //    histEtOfHltObjMatchToReco.push_back(tmphisto);
00377 //
00378 //    // eta
00379 //    histName  = theHLTCollectionLabels[i].label()+"eta_reco";
00380 //    histTitle = HltHistTitle[i]+" eta (reco)";
00381 //    tmphisto  = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
00382 //    histEtaOfHltObjMatchToReco.push_back(tmphisto);
00383 //
00384 //    // phi
00385 //    histName  = theHLTCollectionLabels[i].label()+"phi_reco";
00386 //    histTitle = HltHistTitle[i]+" phi (reco)";
00387 //    tmphisto  = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
00388 //    histPhiOfHltObjMatchToReco.push_back(tmphisto);
00389 
00390     histHltObjMatchToReco.push_back(new FourVectorMonitorElements(this,
00391         theHLTCollectionLabels[i].label()+"%s_reco",   // histogram name
00392         HltHistTitle[i]+" %s (reco)"                  // histogram title
00393         ));
00394 
00395     //--------------------
00396 
00397     if (!plotiso[i]) {
00398       tmpiso = NULL;
00399       etahistiso.push_back(tmpiso);
00400       ethistiso.push_back(tmpiso);
00401       phiHistIso.push_back(tmpiso);
00402 
00403       etahistisomatchreco.push_back(tmpiso);
00404       ethistisomatchreco.push_back(tmpiso);
00405       phiHistIsoMatchReco.push_back(tmpiso);
00406 
00407       histEtaIsoOfHltObjMatchToReco.push_back(tmpiso);
00408       histEtIsoOfHltObjMatchToReco.push_back(tmpiso);
00409       histPhiIsoOfHltObjMatchToReco.push_back(tmpiso);
00410 
00411     } else {
00412 
00413       //--------------------
00414       // 2D plot: Isolation values vs X for all objects
00415       //--------------------
00416 
00417       // X = eta
00418       histName  = theHLTCollectionLabels[i].label()+"eta_isolation_all";
00419       histTitle = HltHistTitle[i]+" isolation vs #eta (all)";
00420       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00421       etahistiso.push_back(tmpiso);
00422 
00423       // X = et
00424       histName  = theHLTCollectionLabels[i].label()+"et_isolation_all";
00425       histTitle = HltHistTitle[i]+" isolation vs Et (all)";
00426       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00427       ethistiso.push_back(tmpiso);
00428 
00429       // X = phi
00430       histName  = theHLTCollectionLabels[i].label()+"phi_isolation_all";
00431       histTitle = HltHistTitle[i]+" isolation vs #phi (all)";
00432       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00433       phiHistIso.push_back(tmpiso);
00434 
00435       //--------------------
00436       // 2D plot: Isolation values vs X for reco matched objects
00437       //--------------------
00438 
00439       // X = eta
00440       histName  = theHLTCollectionLabels[i].label()+"eta_isolation_RECO_matched";
00441       histTitle = HltHistTitle[i]+" isolation vs #eta (reco matched)";
00442       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00443       etahistisomatchreco.push_back(tmpiso);
00444 
00445       // X = et
00446       histName  = theHLTCollectionLabels[i].label()+"et_isolation_RECO_matched";
00447       histTitle = HltHistTitle[i]+" isolation vs Et (reco matched)";
00448       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00449       ethistisomatchreco.push_back(tmpiso);
00450 
00451       // X = eta
00452       histName  = theHLTCollectionLabels[i].label()+"phi_isolation_RECO_matched";
00453       histTitle = HltHistTitle[i]+" isolation vs #phi (reco matched)";
00454       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00455       phiHistIsoMatchReco.push_back(tmpiso);
00456 
00457       //--------------------
00458       // 2D plot: Isolation values vs X for HLT object that
00459       // is closest delta-R match to sorted reco particle(s)
00460       //--------------------
00461 
00462       // X = eta
00463       histName  = theHLTCollectionLabels[i].label()+"eta_isolation_reco";
00464       histTitle = HltHistTitle[i]+" isolation vs #eta (reco)";
00465       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00466       histEtaIsoOfHltObjMatchToReco.push_back(tmpiso);
00467 
00468       // X = et
00469       histName  = theHLTCollectionLabels[i].label()+"et_isolation_reco";
00470       histTitle = HltHistTitle[i]+" isolation vs Et (reco)";
00471       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00472       histEtIsoOfHltObjMatchToReco.push_back(tmpiso);
00473 
00474       // X = phi
00475       histName  = theHLTCollectionLabels[i].label()+"phi_isolation_reco";
00476       histTitle = HltHistTitle[i]+" isolation vs #phi (reco)";
00477       tmpiso    = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
00478       histPhiIsoOfHltObjMatchToReco.push_back(tmpiso);
00479       //--------------------
00480 
00481     } // END of HLT histograms
00482 
00483   }
00484 }
00485 
00486 
00488 //                                Destructor                                  //
00490 EmDQMReco::~EmDQMReco(){
00491 }
00492 
00493 
00495 //                     method called to for each event                        //
00497 void
00498 EmDQMReco::analyze(const edm::Event & event , const edm::EventSetup& setup)
00499 {
00500 
00501   // protect from hlt config failure
00502   if( !isHltConfigInitialized_ ) return;
00503 
00504   eventnum++;
00505   bool plotMonpath = false;
00506   bool plotReco = true;
00507 
00508   edm::Handle<edm::View<reco::Candidate> > recoObjects;
00509   edm::Handle<std::vector<reco::SuperCluster> > recoObjectsEB;
00510   edm::Handle<std::vector<reco::SuperCluster> > recoObjectsEE;
00511 
00512   if (pdgGen == 11) {
00513 
00514     event.getByLabel(recoElectronsInputTag, recoObjects);
00515 
00516     if (recoObjects->size() < (unsigned int)recocut_) {
00517       // edm::LogWarning("EmDQMReco") << "Less than "<< recocut_ <<" Reco particles with pdgId=" << pdgGen << ".  Only " << cutRecoCounter->size() << " particles.";
00518       return;
00519     }
00520   } else if (pdgGen == 22) {
00521 
00522     event.getByLabel("correctedHybridSuperClusters", recoObjectsEB);
00523     event.getByLabel("correctedMulti5x5SuperClustersWithPreshower", recoObjectsEE);
00524 
00525     if (recoObjectsEB->size() + recoObjectsEE->size() < (unsigned int)recocut_) {
00526       // edm::LogWarning("EmDQMReco") << "Less than "<< recocut_ <<" Reco particles with pdgId=" << pdgGen << ".  Only " << cutRecoCounter.size() << " particles.";
00527       return;
00528     }
00529   }
00530 
00531   edm::Handle<edm::TriggerResults> HLTR;
00532   event.getByLabel(edm::InputTag("TriggerResults","",processNameRecoMonPath), HLTR);
00533 
00538 
00539   /* if (theHLTCollectionHumanNames[0] == "hltL1sRelaxedSingleEgammaEt8"){
00540     triggerIndex = hltConfig.triggerIndex("HLT_L1SingleEG8");
00541   } else if (theHLTCollectionHumanNames[0] == "hltL1sRelaxedSingleEgammaEt5") {
00542     triggerIndex = hltConfig.triggerIndex("HLT_L1SingleEG5");
00543   } else if (theHLTCollectionHumanNames[0] == "hltL1sRelaxedDoubleEgammaEt5") {
00544     triggerIndex = hltConfig.triggerIndex("HLT_L1DoubleEG5");
00545   } else {
00546     triggerIndex = hltConfig.triggerIndex("");
00547     } */
00548 
00549   unsigned int triggerIndex;
00550   triggerIndex = hltConfig_.triggerIndex(triggerNameRecoMonPath);
00551 
00552   //triggerIndex must be less than the size of HLTR or you get a CMSException
00553   bool isFired = false;
00554   if (triggerIndex < HLTR->size()){
00555     isFired = HLTR->accept(triggerIndex);
00556   }
00557 
00558   // fill L1 and HLT info
00559   // get objects possed by each filter
00560   edm::Handle<trigger::TriggerEventWithRefs> triggerObj;
00561   event.getByLabel("hltTriggerSummaryRAW",triggerObj);
00562   if(!triggerObj.isValid()) {
00563     edm::LogWarning("EmDQMReco") << "RAW-type HLT results not found, skipping event";
00564     return;
00565   }
00566 
00568   //  Fill the bin labeled "Total"                          //
00569   //   This will be the number of events looked at.         //
00571   totalreco->Fill(numOfHLTCollectionLabels+0.5);
00572   totalmatchreco->Fill(numOfHLTCollectionLabels+.5);
00573 
00574   /* edm::Handle< edm::View<reco::GsfElectron> > recoParticles;
00575   event.getByLabel("gsfElectrons", recoParticles);
00576 
00577   std::vector<reco::GsfElectron> allSortedRecoParticles;
00578 
00579   for(edm::View<reco::GsfElectron>::const_iterator currentRecoParticle = recoParticles->begin(); currentRecoParticle != recoParticles->end(); currentRecoParticle++){
00580   if (  !((*currentRecoParticle).et() > 2.0)  )  continue;
00581     reco::GsfElectron tmpcand( *(currentRecoParticle) );
00582     allSortedRecoParticles.push_back(tmpcand);
00583   }
00584 
00585   std::sort(allSortedRecoParticles.begin(), allSortedRecoParticles.end(),pTRecoComparator_);*/
00586 
00587   // Were enough high energy gen particles found?
00588   // It was an event worth keeping. Continue.
00589 
00591   //  Fill the bin labeled "Total"                          //
00592   //   This will be the number of events looked at.         //
00594   //total->Fill(numOfHLTCollectionLabels+0.5);
00595   //totalmatch->Fill(numOfHLTCollectionLabels+0.5);
00596 
00597 
00599   //               Fill reconstruction info                      //
00601   // the recocut_ highest Et generator objects of the preselected type are our matches
00602 
00603   std::vector<reco::Particle> sortedReco;
00604   if (plotReco == true) {
00605     if (pdgGen == 11) {
00606       for(edm::View<reco::Candidate>::const_iterator recopart = recoObjects->begin(); recopart != recoObjects->end();recopart++){
00607         reco::Particle tmpcand(  recopart->charge(), recopart->p4(), recopart->vertex(),recopart->pdgId(),recopart->status() );
00608         sortedReco.push_back(tmpcand);
00609       }
00610     }
00611     else if (pdgGen == 22) {
00612       for(std::vector<reco::SuperCluster>::const_iterator recopart2 = recoObjectsEB->begin(); recopart2 != recoObjectsEB->end();recopart2++){
00613         float en = recopart2->energy();
00614         float er = sqrt(pow(recopart2->x(),2) + pow(recopart2->y(),2) + pow(recopart2->z(),2) );
00615         float px = recopart2->energy()*recopart2->x()/er;
00616         float py = recopart2->energy()*recopart2->y()/er;
00617         float pz = recopart2->energy()*recopart2->z()/er;
00618         reco::Candidate::LorentzVector thisLV(px,py,pz,en);
00619         reco::Particle tmpcand(  0, thisLV, math::XYZPoint(0.,0.,0.), 22, 1 );
00620         sortedReco.push_back(tmpcand);
00621       }
00622       for(std::vector<reco::SuperCluster>::const_iterator recopart2 = recoObjectsEE->begin(); recopart2 != recoObjectsEE->end();recopart2++){
00623         float en = recopart2->energy();
00624         float er = sqrt(pow(recopart2->x(),2) + pow(recopart2->y(),2) + pow(recopart2->z(),2) );
00625         float px = recopart2->energy()*recopart2->x()/er;
00626         float py = recopart2->energy()*recopart2->y()/er;
00627         float pz = recopart2->energy()*recopart2->z()/er;
00628         reco::Candidate::LorentzVector thisLV(px,py,pz,en);
00629         reco::Particle tmpcand(  0, thisLV, math::XYZPoint(0.,0.,0.), 22, 1 );
00630         sortedReco.push_back(tmpcand);
00631       }
00632     }
00633 
00634     std::sort(sortedReco.begin(),sortedReco.end(),pTComparator_ );
00635 
00636     // Now the collection of gen particles is sorted by pt.
00637     // So, remove all particles from the collection so that we
00638     // only have the top "1 thru recocut_" particles in it
00639 
00640     sortedReco.erase(sortedReco.begin()+recocut_,sortedReco.end());
00641 
00642     for (unsigned int i = 0 ; i < recocut_ ; i++ ) {
00643         //validity has been implicitily checked by the cut on recocut_ above
00644         histReco->fill(sortedReco[i].p4());
00645 
00646 //      etreco ->Fill( sortedReco[i].et()  );
00647 //      etareco->Fill( sortedReco[i].eta() );
00648 //      phiReco->Fill( sortedReco[i].phi() );
00649 
00650       if (isFired) {
00651         histRecoMonpath->fill(sortedReco[i].p4());
00652         plotMonpath = true;
00653       }
00654 
00655     } // END of loop over Reconstructed particles
00656 
00657     if (recocut_ >= reqNum) totalreco->Fill(numOfHLTCollectionLabels+1.5); // this isn't really needed anymore keep for backward comp.
00658     if (recocut_ >= reqNum) totalmatchreco->Fill(numOfHLTCollectionLabels+1.5); // this isn't really needed anymore keep for backward comp.
00659 
00660   }
00661 
00662 
00663 
00664 
00666   //            Loop over filter modules                    //
00668   for(unsigned int n=0; n < numOfHLTCollectionLabels ; n++) {
00669     // These numbers are from the Parameter Set, such as:
00670     //   theHLTOutputTypes = cms.uint32(100)
00671     switch(theHLTOutputTypes[n])
00672     {
00673       case trigger::TriggerL1NoIsoEG: // Non-isolated Level 1
00674         fillHistos<l1extra::L1EmParticleCollection>(triggerObj,event,n, sortedReco, plotReco, plotMonpath);break;
00675       case trigger::TriggerL1IsoEG: // Isolated Level 1
00676         fillHistos<l1extra::L1EmParticleCollection>(triggerObj,event,n, sortedReco, plotReco, plotMonpath);break;
00677       case trigger::TriggerPhoton: // Photon
00678         fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,event,n, sortedReco, plotReco, plotMonpath);break;
00679       case trigger::TriggerElectron: // Electron
00680         fillHistos<reco::ElectronCollection>(triggerObj,event,n, sortedReco, plotReco, plotMonpath);break;
00681       case trigger::TriggerCluster: // TriggerCluster
00682         fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,event,n, sortedReco, plotReco, plotMonpath);break;
00683       default:
00684         throw(cms::Exception("Release Validation Error") << "HLT output type not implemented: theHLTOutputTypes[n]" );
00685     }
00686     } // END of loop over filter modules
00687 }
00688 
00689 
00691 // fillHistos                                                                 //
00692 //   Called by analyze method.                                                //
00694 template <class T> void EmDQMReco::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent ,unsigned int n, std::vector<reco::Particle>& sortedReco, bool plotReco, bool plotMonpath)
00695 {
00696   std::vector<edm::Ref<T> > recoecalcands;
00697   if ( ( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if available
00698     return;
00699   }
00700 
00702   //      Retrieve saved filter objects                     //
00704   triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],recoecalcands);
00705   //Danger: special case, L1 non-isolated
00706   // needs to be merged with L1 iso
00707   if (theHLTOutputTypes[n] == trigger::TriggerL1NoIsoEG){
00708     std::vector<edm::Ref<T> > isocands;
00709     triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),trigger::TriggerL1IsoEG,isocands);
00710     if (isocands.size()>0)
00711       {
00712         for (unsigned int i=0; i < isocands.size(); i++)
00713           recoecalcands.push_back(isocands[i]);
00714       }
00715   } // END of if theHLTOutputTypes == 82
00716 
00717 
00718   if (recoecalcands.size() < 1){ // stop if no object passed the previous filter
00719     return;
00720   }
00721 
00722 
00723   if (recoecalcands.size() >= reqNum )
00724     totalreco->Fill(n+0.5);
00725 
00726 
00728   // check for validity                            //
00729   // prevents crash in CMSSW_3_1_0_pre6            //
00731   for (unsigned int j=0; j<recoecalcands.size(); j++){
00732     if(!( recoecalcands.at(j).isAvailable())){
00733       edm::LogError("EmDQMReco") << "Event content inconsistent: TriggerEventWithRefs contains invalid Refs" << std::endl << "invalid refs for: " << theHLTCollectionLabels[n].label();
00734       return;
00735     }
00736   }
00737 
00739   //  Loop over all HLT objects in this filter step, and    //
00740   //  fill histograms.                                      //
00742   //  bool foundAllMatches = false;
00743   //  unsigned int numOfHLTobjectsMatched = 0;
00744   for (unsigned int i=0; i<recoecalcands.size(); i++) {
00745 
00746     standardHist[n].fill(recoecalcands[i]->p4());
00747 
00749     //  Plot isolation variables (show the not-yet-cut        //
00750     //  isolation, i.e. associated to next filter)            //
00752     if ( n+1 < numOfHLTCollectionLabels ) { // can't plot beyond last
00753       if (plotiso[n+1]) {
00754         for (unsigned int j =  0 ; j < isoNames[n+1].size() ;j++  ){
00755           edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMap;
00756           iEvent.getByLabel(isoNames[n+1].at(j),depMap);
00757           if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
00758             typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
00759             if (mapi!=depMap->end()){  // found candidate in isolation map!
00760               etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
00761               ethistiso[n+1]->Fill(recoecalcands[i]->et()  ,mapi->val);
00762               phiHistIso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
00763       }
00764     }
00765   }
00766       }
00767     } // END of if n+1 < then the number of hlt collections
00768   }
00769 
00771   // Loop over the Reconstructed Particles, and find the        //
00772   // closest HLT object match.                              //
00774   if (plotReco == true) {
00775     for (unsigned int i=0; i < recocut_; i++) {
00776       math::XYZVector currentRecoParticleMomentum = sortedReco[i].momentum();
00777 
00778       // float closestRecoDeltaR = 0.5;
00779       float closestRecoDeltaR = 1000.;
00780       int closestRecoEcalCandIndex = -1;
00781       for (unsigned int j=0; j<recoecalcands.size(); j++) {
00782         float deltaR = DeltaR(recoecalcands[j]->momentum(),currentRecoParticleMomentum);
00783 
00784         if (deltaR < closestRecoDeltaR) {
00785           closestRecoDeltaR = deltaR;
00786           closestRecoEcalCandIndex = j;
00787         }
00788     }
00789 
00790       // If an HLT object was found within some delta-R
00791       // of this reco particle, store it in a histogram
00792       if ( closestRecoEcalCandIndex >= 0 ) {
00793 //        histEtOfHltObjMatchToReco[n] ->Fill( recoecalcands[closestRecoEcalCandIndex]->et()  );
00794 //        histEtaOfHltObjMatchToReco[n]->Fill( recoecalcands[closestRecoEcalCandIndex]->eta() );
00795 //        histPhiOfHltObjMatchToReco[n]->Fill( recoecalcands[closestRecoEcalCandIndex]->phi() );
00796 
00797           histHltObjMatchToReco[n].fill(recoecalcands[closestRecoEcalCandIndex]->p4());
00798 
00799         // Also store isolation info
00800         if (n+1 < numOfHLTCollectionLabels){ // can't plot beyond last
00801           if (plotiso[n+1] ){  // only plot if requested in config
00802             for (unsigned int j =  0 ; j < isoNames[n+1].size() ;j++  ){
00803               edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMap;
00804               iEvent.getByLabel(isoNames[n+1].at(j),depMap);
00805               if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
00806                 typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[closestRecoEcalCandIndex]);
00807                 if (mapi!=depMap->end()) {  // found candidate in isolation map!
00808                   histEtaIsoOfHltObjMatchToReco[n+1]->Fill( recoecalcands[closestRecoEcalCandIndex]->eta(),mapi->val);
00809                   histEtIsoOfHltObjMatchToReco[n+1] ->Fill( recoecalcands[closestRecoEcalCandIndex]->et(), mapi->val);
00810                   histPhiIsoOfHltObjMatchToReco[n+1] ->Fill( recoecalcands[closestRecoEcalCandIndex]->phi(), mapi->val);
00811                 }
00812               }
00813             }
00814           }
00815         }
00816       } // END of if closestEcalCandIndex >= 0
00817     }
00818 
00820     //        Fill reco matched objects into histograms         //
00822     unsigned int mtachedRecoParts = 0;
00823     float minrecodist=0.3;
00824     if(n==0) minrecodist=0.5; //low L1-resolution => allow wider matching
00825     for(unsigned int i =0; i < recocut_; i++){
00826       //match generator candidate
00827       bool matchThis= false;
00828       math::XYZVector candDir=sortedReco[i].momentum();
00829       unsigned int closest = 0;
00830       double closestDr = 1000.;
00831       for(unsigned int trigOb = 0 ; trigOb < recoecalcands.size(); trigOb++){
00832         double dr = DeltaR(recoecalcands[trigOb]->momentum(),candDir);
00833         if (dr < closestDr) {
00834           closestDr = dr;
00835           closest = trigOb;
00836         }
00837         if (closestDr > minrecodist) { // it's not really a "match" if it's that far away
00838           closest = -1;
00839         } else {
00840           mtachedRecoParts++;
00841           matchThis = true;
00842         }
00843       }
00844       if ( !matchThis ) continue; // only plot matched candidates
00845       // fill coordinates of mc particle matching trigger object
00846 //      ethistmatchreco[n] ->Fill( sortedReco[i].et()  );
00847 //      etahistmatchreco[n]->Fill( sortedReco[i].eta() );
00848 //      phiHistMatchReco[n]->Fill( sortedReco[i].phi() );
00849       histMatchReco[n].fill(sortedReco[i].p4());
00850 
00851       if (plotMonpath) {
00852 //        ethistmatchrecomonpath[n]->Fill( sortedReco[i].et() );
00853 //        etahistmatchrecomonpath[n]->Fill( sortedReco[i].eta() );
00854 //        phiHistMatchRecoMonPath[n]->Fill( sortedReco[i].phi() );
00855           histMatchRecoMonPath[n].fill(sortedReco[i].p4());
00856 
00857       }
00859       //  Plot isolation variables (show the not-yet-cut        //
00860       //  isolation, i.e. associated to next filter)            //
00862       if (n+1 < numOfHLTCollectionLabels){ // can't plot beyond last
00863         if (plotiso[n+1] ){  // only plot if requested in config
00864           for (unsigned int j =  0 ; j < isoNames[n+1].size() ;j++  ){
00865             edm::Handle<edm::AssociationMap<edm::OneToValue< T , float > > > depMapReco;
00866             iEvent.getByLabel(isoNames[n+1].at(j),depMapReco);
00867             if (depMapReco.isValid()){ //Map may not exist if only one candidate passes a double filter
00868               typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMapReco->find(recoecalcands[closest]);
00869               if (mapi!=depMapReco->end()){  // found candidate in isolation map!
00870                 etahistisomatchreco[n+1]->Fill(sortedReco[i].eta(),mapi->val);
00871                 ethistisomatchreco[n+1]->Fill(sortedReco[i].et(),mapi->val);
00872                 phiHistIsoMatchReco[n+1]->Fill(sortedReco[i].eta(),mapi->val);
00873               }
00874             }
00875           }
00876         }
00877       } // END of if n+1 < then the number of hlt collections
00878     }
00879     // fill total reco matched efficiency
00880     if (mtachedRecoParts >= reqNum )
00881       totalmatchreco->Fill(n+0.5);
00882   }
00883 
00884 }
00885 
00886 
00888 //      method called once each job just after ending the event loop          //
00890 void EmDQMReco::endJob(){
00891 
00892 }
00893 
00894 DEFINE_FWK_MODULE(EmDQMReco);