28 #include <boost/foreach.hpp>
34 #include "TDirectory.h"
38 #include <Math/VectorUtil.h>
39 using namespace ROOT::Math::VectorUtil ;
54 dirname_=
"HLT/HLTEgammaValidation/"+pset.
getParameter<std::string>(
"@module_label");
55 dbe->setCurrentFolder(dirname_);
86 std::vector<edm::ParameterSet>
filters =
87 pset.
getParameter<std::vector<edm::ParameterSet> >(
"filters");
90 for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++)
93 theHLTCollectionLabels.push_back(filterconf->getParameter<
edm::InputTag>(
"HLTCollectionLabels"));
94 theHLTOutputTypes.push_back(filterconf->getParameter<
int>(
"theHLTOutputTypes"));
96 theHLTCollectionHumanNames.push_back(filterconf->getUntrackedParameter<std::string>(
"HLTCollectionHumanName",theHLTCollectionLabels[i].label()));
98 std::vector<double> bounds = filterconf->getParameter<std::vector<double> >(
"PlotBounds");
100 assert(bounds.size() == 2);
101 plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
102 isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >(
"IsoCollections"));
104 assert(isoNames.back().size()>0);
105 if (isoNames.back().at(0).label()==
"none") {
106 plotiso.push_back(
false);
108 if (!noIsolationPlots) plotiso.push_back(
true);
109 else plotiso.push_back(
false);
111 nCandCuts.push_back(filterconf->getParameter<
int>(
"ncandcut"));
116 numOfHLTCollectionLabels = theHLTCollectionLabels.size();
134 if (hltConf_.init(iRun, iSetup, triggerobjwithrefs.process(), changed)) {
139 dbe->setCurrentFolder(dirname_);
147 std::string histName=
"total_eff";
148 std::string histTitle =
"total events passing";
149 if (!mcMatchedOnly) {
152 total = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
153 total->setBinLabel(numOfHLTCollectionLabels+1,
"Total");
154 total->setBinLabel(numOfHLTCollectionLabels+2,
"Gen");
155 for (
unsigned int u=0; u<numOfHLTCollectionLabels; u++){
total->setBinLabel(u+1,theHLTCollectionLabels[u].
label().c_str());}
158 histName=
"total_eff_MC_matched";
159 histTitle=
"total events passing (mc matched)";
160 totalmatch = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
161 totalmatch->setBinLabel(numOfHLTCollectionLabels+1,
"Total");
162 totalmatch->setBinLabel(numOfHLTCollectionLabels+2,
"Gen");
163 for (
unsigned int u=0; u<numOfHLTCollectionLabels; u++){totalmatch->setBinLabel(u+1,theHLTCollectionLabels[u].
label().c_str());}
171 std::string pdgIdString;
174 pdgIdString=
"Electron";
break;
176 pdgIdString=
"Photon";
break;
178 pdgIdString=
"Particle";
182 histTitle=
"E_{T} of " + pdgIdString +
"s" ;
183 etgen = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
184 histName =
"gen_eta";
185 histTitle=
"#eta of "+ pdgIdString +
"s " ;
186 etagen = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
187 histName =
"gen_phi";
188 histTitle=
"#phi of "+ pdgIdString +
"s " ;
189 if (!noPhiPlots) phigen = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
198 std::vector<std::string> HltHistTitle;
199 if ( theHLTCollectionHumanNames.size() == numOfHLTCollectionLabels && useHumanReadableHistTitles ) {
200 HltHistTitle = theHLTCollectionHumanNames;
202 for (
unsigned int i =0;
i < numOfHLTCollectionLabels;
i++) {
203 HltHistTitle.push_back(theHLTCollectionLabels[
i].
label());
207 for(
unsigned int i = 0;
i< numOfHLTCollectionLabels ;
i++){
208 if (!mcMatchedOnly) {
210 histName = theHLTCollectionLabels[
i].label()+
"et_all";
211 histTitle = HltHistTitle[
i]+
" Et (ALL)";
212 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
213 ethist.push_back(tmphisto);
216 histName = theHLTCollectionLabels[
i].label()+
"eta_all";
217 histTitle = HltHistTitle[
i]+
" #eta (ALL)";
218 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
219 etahist.push_back(tmphisto);
223 histName = theHLTCollectionLabels[
i].label()+
"phi_all";
224 histTitle = HltHistTitle[
i]+
" #phi (ALL)";
225 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
226 phihist.push_back(tmphisto);
231 histName = theHLTCollectionLabels[
i].label()+
"et";
232 histTitle = HltHistTitle[
i]+
" Et";
233 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
234 histEtOfHltObjMatchToGen.push_back(tmphisto);
237 histName = theHLTCollectionLabels[
i].label()+
"eta";
238 histTitle = HltHistTitle[
i]+
" eta";
239 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
240 histEtaOfHltObjMatchToGen.push_back(tmphisto);
244 histName = theHLTCollectionLabels[
i].label()+
"phi";
245 histTitle = HltHistTitle[
i]+
" phi";
246 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
247 histPhiOfHltObjMatchToGen.push_back(tmphisto);
252 histName = theHLTCollectionLabels[
i].label()+
"et_MC_matched";
253 histTitle = HltHistTitle[
i]+
" Et (MC matched)";
254 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
255 ethistmatch.push_back(tmphisto);
258 histName = theHLTCollectionLabels[
i].label()+
"eta_MC_matched";
259 histTitle = HltHistTitle[
i]+
" #eta (MC matched)";
260 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
261 etahistmatch.push_back(tmphisto);
265 histName = theHLTCollectionLabels[
i].label()+
"phi_MC_matched";
266 histTitle = HltHistTitle[
i]+
" #phi (MC matched)";
267 tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
268 phihistmatch.push_back(tmphisto);
274 if (!mcMatchedOnly) {
275 etahistiso.push_back(tmpiso);
276 phihistiso.push_back(tmpiso);
277 ethistiso.push_back(tmpiso);
278 histEtaIsoOfHltObjMatchToGen.push_back(tmpiso);
279 histPhiIsoOfHltObjMatchToGen.push_back(tmpiso);
280 histEtIsoOfHltObjMatchToGen.push_back(tmpiso);
282 etahistisomatch.push_back(tmpiso);
283 phihistisomatch.push_back(tmpiso);
284 ethistisomatch.push_back(tmpiso);
286 if (!mcMatchedOnly) {
288 histName = theHLTCollectionLabels[
i].label()+
"eta_isolation_all";
289 histTitle = HltHistTitle[
i]+
" isolation vs #eta (all)";
290 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
291 etahistiso.push_back(tmpiso);
294 histName = theHLTCollectionLabels[
i].label()+
"phi_isolation_all";
295 histTitle = HltHistTitle[
i]+
" isolation vs #phi (all)";
296 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
297 phihistiso.push_back(tmpiso);
300 histName = theHLTCollectionLabels[
i].label()+
"et_isolation_all";
301 histTitle = HltHistTitle[
i]+
" isolation vs Et (all)";
302 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
303 ethistiso.push_back(tmpiso);
307 histName = theHLTCollectionLabels[
i].label()+
"eta_isolation";
308 histTitle = HltHistTitle[
i]+
" isolation vs #eta";
309 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
310 histEtaIsoOfHltObjMatchToGen.push_back(tmpiso);
314 histName = theHLTCollectionLabels[
i].label()+
"phi_isolation";
315 histTitle = HltHistTitle[
i]+
" isolation vs #phi";
316 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
317 histPhiIsoOfHltObjMatchToGen.push_back(tmpiso);
321 histName = theHLTCollectionLabels[
i].label()+
"et_isolation";
322 histTitle = HltHistTitle[
i]+
" isolation vs Et";
323 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
324 histEtIsoOfHltObjMatchToGen.push_back(tmpiso);
328 histName = theHLTCollectionLabels[
i].label()+
"eta_isolation_MC_matched";
329 histTitle = HltHistTitle[
i]+
" isolation vs #eta (mc matched)";
330 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
331 etahistisomatch.push_back(tmpiso);
334 histName = theHLTCollectionLabels[
i].label()+
"phi_isolation_MC_matched";
335 histTitle = HltHistTitle[
i]+
" isolation vs #phi (mc matched)";
336 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
337 phihistisomatch.push_back(tmpiso);
341 histName = theHLTCollectionLabels[
i].label()+
"et_isolation_MC_matched";
342 histTitle = HltHistTitle[
i]+
" isolation vs Et (mc matched)";
343 tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[
i].first,plotBounds[
i].second);
344 ethistisomatch.push_back(tmpiso);
358 edm::LogError(
"EmDQM") <<
" HLT config extraction failure with process name '" << triggerobjwithrefs.process() <<
"'.";
378 event.getByLabel(
"genParticles", genParticles);
385 std::vector<reco::LeafCandidate> allSortedGenParticles;
392 if ( !(
abs((*currentGenParticle).pdgId())==pdgGen && (*currentGenParticle).status()==1 && (*currentGenParticle).et() > 2.0) )
continue;
396 if (tmpcand.
et() < plotEtMin)
continue;
398 allSortedGenParticles.push_back(tmpcand);
401 std::sort(allSortedGenParticles.begin(), allSortedGenParticles.end(),pTGenComparator_);
404 if (allSortedGenParticles.size() < gencut_)
414 for (
unsigned int i = 0 ;
i < gencut_ ;
i++ ) {
415 bool inECALgap = fabs(allSortedGenParticles[
i].
eta()) > 1.4442 && fabs(allSortedGenParticles[
i].
eta()) < 1.556;
416 if ( (fabs(allSortedGenParticles[
i].
eta()) > genEtaAcc) || inECALgap ) {
433 event.getByLabel(gencutCollection_,referenceParticles);
434 if(!referenceParticles.
isValid()) {
440 std::vector<const reco::Candidate *> allSortedReferenceParticles;
443 currentReferenceParticle != referenceParticles->end();
444 currentReferenceParticle++)
446 if ( currentReferenceParticle->et() <= 2.0)
454 if (currentReferenceParticle->et() < plotEtMin)
458 allSortedReferenceParticles.push_back(&(*currentReferenceParticle));
464 return allSortedReferenceParticles.size() >= gencut_;
479 event.getByLabel(gencutCollection_,cutCounter);
480 if (cutCounter->size() < (
unsigned int)gencut_) {
489 event.getByLabel(triggerobjwithrefs,triggerObj);
492 edm::LogWarning(
"EmDQM") <<
"parameter triggerobject (" << triggerobjwithrefs <<
") does not corresond to a valid TriggerEventWithRefs product. Please check especially the process name (e.g. when running over reprocessed datasets)";
504 if (!checkRecoParticlesRequirement(event))
510 if (!checkGeneratedParticlesRequirement(event))
522 if (!mcMatchedOnly)
total->Fill(numOfHLTCollectionLabels+0.5);
523 totalmatch->Fill(numOfHLTCollectionLabels+0.5);
531 std::vector<reco::Particle> sortedGen;
533 reco::Particle tmpcand( genpart->charge(), genpart->p4(), genpart->vertex(),genpart->pdgId(),genpart->status() );
534 if (tmpcand.et() >= plotEtMin) {
535 sortedGen.push_back(tmpcand);
538 std::sort(sortedGen.begin(),sortedGen.end(),pTComparator_ );
543 if (sortedGen.size() < gencut_){
546 sortedGen.erase(sortedGen.begin()+gencut_,sortedGen.end());
548 for (
unsigned int i = 0 ;
i < gencut_ ;
i++ ) {
549 etgen ->Fill( sortedGen[
i].et() );
550 if (sortedGen[
i].et() > plotMinEtForEtaEffPlot) {
551 etagen->Fill( sortedGen[
i].
eta() );
552 if (!noPhiPlots) phigen->Fill( sortedGen[
i].
phi() );
555 if (gencut_ >= reqNum && !mcMatchedOnly)
total->Fill(numOfHLTCollectionLabels+1.5);
556 if (gencut_ >= reqNum) totalmatch->Fill(numOfHLTCollectionLabels+1.5);
558 bool accepted =
true;
560 event.getByLabel(
edm::InputTag(
"TriggerResults",
"", triggerobjwithrefs.process()), hltResults);
564 for(
unsigned int n=0;
n < numOfHLTCollectionLabels ;
n++) {
566 if (sortedGen.size() < nCandCuts.at(
n)) {
568 edm::LogError(
"EmDQM") <<
"There are less generated particles than the module '" << theHLTCollectionLabels[
n].label() <<
"' requires.";
571 std::vector<reco::Particle> sortedGenForFilter(sortedGen);
572 sortedGenForFilter.erase(sortedGenForFilter.begin() + nCandCuts.at(
n), sortedGenForFilter.end());
575 if (pathIndex != 0 && hltConf_.moduleIndex(pathIndex, theHLTCollectionLabels[
n].label()) > hltResults->index(pathIndex))
break;
578 switch(theHLTOutputTypes[
n])
581 fillHistos<l1extra::L1EmParticleCollection>(triggerObj,
event,
n,sortedGenForFilter,accepted);
break;
583 fillHistos<l1extra::L1EmParticleCollection>(triggerObj,
event,
n,sortedGenForFilter,accepted);
break;
585 fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,
event,
n,sortedGenForFilter,accepted);
break;
587 fillHistos<reco::ElectronCollection>(triggerObj,
event,
n,sortedGenForFilter,accepted);
break;
589 fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,
event,
n,sortedGenForFilter,accepted);
break;
591 throw(
cms::Exception(
"Release Validation Error") <<
"HLT output type not implemented: theHLTOutputTypes[n]" );
603 std::vector<edm::Ref<T> > recoecalcands;
604 if ( ( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){
605 hltCollectionLabelsMissed.insert(theHLTCollectionLabels[n].
encode());
610 hltCollectionLabelsFound.insert(theHLTCollectionLabels[n].
encode());
615 triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[
n],recoecalcands);
619 std::vector<edm::Ref<T> > isocands;
621 if (isocands.size()>0)
623 for (
unsigned int i=0;
i < isocands.size();
i++)
624 recoecalcands.push_back(isocands[
i]);
629 if (recoecalcands.size() < 1){
635 if (recoecalcands.size() >= nCandCuts.at(n) && !mcMatchedOnly)
642 for (
unsigned int j=0;
j<recoecalcands.size();
j++){
643 if(!( recoecalcands.at(
j).isAvailable())){
645 edm::LogError(
"EmDQMInvalidRefs") <<
"Event content inconsistent: TriggerEventWithRefs contains invalid Refs. Invalid refs for: " << theHLTCollectionLabels[
n].label() <<
". The collection that this module uses may has been dropped in the event.";
650 if (!mcMatchedOnly) {
656 for (
unsigned int i=0;
i < nCandCuts.at(n);
i++) {
659 float closestDeltaR = 0.5;
660 int closestEcalCandIndex = -1;
661 for (
unsigned int j=0;
j<recoecalcands.size();
j++) {
662 float deltaR =
DeltaR(recoecalcands[
j]->momentum(),currentGenParticleMomentum);
664 if (deltaR < closestDeltaR) {
666 closestEcalCandIndex =
j;
672 if ( closestEcalCandIndex >= 0 ) {
673 histEtOfHltObjMatchToGen[
n] ->Fill( recoecalcands[closestEcalCandIndex]->et() );
674 histEtaOfHltObjMatchToGen[
n]->Fill( recoecalcands[closestEcalCandIndex]->
eta() );
675 if (!noPhiPlots) histPhiOfHltObjMatchToGen[
n]->Fill( recoecalcands[closestEcalCandIndex]->
phi() );
678 if (n+1 < numOfHLTCollectionLabels){
680 for (
unsigned int j = 0 ;
j < isoNames[n+1].size() ;
j++ ){
685 if (mapi!=depMap->end()) {
686 histEtaIsoOfHltObjMatchToGen[n+1]->Fill( recoecalcands[closestEcalCandIndex]->
eta(),mapi->val);
687 histPhiIsoOfHltObjMatchToGen[n+1]->Fill( recoecalcands[closestEcalCandIndex]->
phi(),mapi->val);
688 histEtIsoOfHltObjMatchToGen[n+1] ->Fill( recoecalcands[closestEcalCandIndex]->et(), mapi->val);
703 for (
unsigned int i=0;
i<recoecalcands.size();
i++) {
721 ethist[
n] ->Fill(recoecalcands[
i]->et() );
722 etahist[
n]->Fill(recoecalcands[
i]->
eta() );
723 if (!noPhiPlots) phihist[
n]->Fill(recoecalcands[
i]->
phi() );
729 if ( n+1 < numOfHLTCollectionLabels ) {
731 for (
unsigned int j = 0 ;
j < isoNames[n+1].size() ;
j++ ){
736 if (mapi!=depMap->end()){
737 etahistiso[n+1]->Fill(recoecalcands[i]->
eta(),mapi->val);
738 phihistiso[n+1]->Fill(recoecalcands[i]->
phi(),mapi->val);
739 ethistiso[n+1]->Fill(recoecalcands[i]->et(),mapi->val);
752 unsigned int mtachedMcParts = 0;
754 if(n==0) mindist=0.5;
755 for(
unsigned int i =0;
i < nCandCuts.at(n); ++
i){
757 bool matchThis=
false;
759 unsigned int closest = 0;
760 double closestDr = 1000.;
761 for(
unsigned int trigOb = 0 ; trigOb < recoecalcands.size(); ++trigOb){
762 double dr =
DeltaR(recoecalcands[trigOb]->momentum(),candDir);
763 if (dr < closestDr) {
767 if (closestDr > mindist) {
779 ethistmatch[
n] ->Fill( sortedGen[
i].et() );
780 if (sortedGen[
i].et() > plotMinEtForEtaEffPlot) {
781 etahistmatch[
n]->Fill( sortedGen[
i].
eta() );
782 if (!noPhiPlots) phihistmatch[
n]->Fill( sortedGen[
i].
phi() );
788 if (n+1 < numOfHLTCollectionLabels){
790 for (
unsigned int j = 0 ;
j < isoNames[n+1].size() ;
j++ ){
795 if (mapi!=depMap->end()){
797 etahistisomatch[n+1]->Fill(sortedGen[
i].
eta(),mapi->val);
798 phihistisomatch[n+1]->Fill(sortedGen[
i].
phi(),mapi->val);
799 ethistisomatch[n+1]->Fill(sortedGen[
i].et(),mapi->val);
808 if (mtachedMcParts >= nCandCuts.at(n) && accepted ==
true)
809 totalmatch->Fill(n+0.5);
819 std::vector<std::string> labelsNeverFound;
825 if (hltCollectionLabelsFound.count(tag.
encode()) == 0)
827 labelsNeverFound.push_back(tag.
encode());
831 if (labelsNeverFound.empty())
834 std::sort(labelsNeverFound.begin(), labelsNeverFound.end());
840 edm::LogWarning(
"EmDQM") <<
"There were some HLTCollectionLabels which were never found:";
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
bool checkRecoParticlesRequirement(const edm::Event &event)
virtual double et() const
transverse energy
#define DEFINE_FWK_MODULE(type)
std::vector< TPRegexp > filters
void beginRun(edm::Run const &, edm::EventSetup const &)
void endRun(edm::Run const &, edm::EventSetup const &)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
EmDQM(const edm::ParameterSet &pset)
Constructor.
double deltaR(double eta1, double eta2, double phi1, double phi2)
bool checkGeneratedParticlesRequirement(const edm::Event &event)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void analyze(const edm::Event &event, const edm::EventSetup &)
void fillHistos(edm::Handle< trigger::TriggerEventWithRefs > &, const edm::Event &, unsigned int, std::vector< reco::Particle > &, bool &)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")