Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:38

0001 #include "GeneratorInterface/Core/interface/HepMCFilterDriver.h"
0002 #include "GeneratorInterface/Core/interface/GenericDauHepMCFilter.h"
0003 #include "GeneratorInterface/Core/interface/PartonShowerBsHepMCFilter.h"
0004 #include "GeneratorInterface/Core/interface/PartonShowerCsHepMCFilter.h"
0005 #include "GeneratorInterface/Core/interface/EmbeddingHepMCFilter.h"
0006 #include "GeneratorInterface/Core/interface/PythiaHepMCFilterGammaGamma.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 HepMCFilterDriver::HepMCFilterDriver(const edm::ParameterSet& pset)
0011     : filter_(nullptr),
0012       numEventsPassPos_(0),
0013       numEventsPassNeg_(0),
0014       numEventsTotalPos_(0),
0015       numEventsTotalNeg_(0),
0016       sumpass_w_(0.),
0017       sumpass_w2_(0.),
0018       sumtotal_w_(0.),
0019       sumtotal_w2_(0.) {
0020   std::string filterName = pset.getParameter<std::string>("filterName");
0021   edm::ParameterSet filterParameters = pset.getParameter<edm::ParameterSet>("filterParameters");
0022 
0023   if (filterName == "GenericDauHepMCFilter") {
0024     filter_ = new GenericDauHepMCFilter(filterParameters);
0025   } else if (filterName == "PartonShowerBsHepMCFilter") {
0026     filter_ = new PartonShowerBsHepMCFilter(filterParameters);
0027   } else if (filterName == "PartonShowerCsHepMCFilter") {
0028     filter_ = new PartonShowerCsHepMCFilter(filterParameters);
0029   }
0030 
0031   else if (filterName == "EmbeddingHepMCFilter") {
0032     filter_ = new EmbeddingHepMCFilter(filterParameters);
0033   } else if (filterName == "PythiaHepMCFilterGammaGamma") {
0034     filter_ = new PythiaHepMCFilterGammaGamma(filterParameters);
0035   } else {
0036     throw edm::Exception(edm::errors::Configuration, "HepMCFilterDriver") << "Invalid HepMCFilter name:" << filterName;
0037   }
0038 }
0039 
0040 HepMCFilterDriver::~HepMCFilterDriver() {
0041   if (filter_)
0042     delete filter_;
0043 }
0044 
0045 bool HepMCFilterDriver::filter(const HepMC::GenEvent* evt, double weight) {
0046   if (weight > 0)
0047     numEventsTotalPos_++;
0048   else
0049     numEventsTotalNeg_++;
0050 
0051   sumtotal_w_ += weight;
0052   sumtotal_w2_ += weight * weight;
0053 
0054   bool accepted = filter_->filter(evt);
0055 
0056   if (accepted) {
0057     if (weight > 0)
0058       numEventsPassPos_++;
0059     else
0060       numEventsPassNeg_++;
0061     sumpass_w_ += weight;
0062     sumpass_w2_ += weight * weight;
0063   }
0064 
0065   return accepted;
0066 }
0067 
0068 void HepMCFilterDriver::statistics() const {
0069   unsigned int ntried_ = numEventsTotalPos_ + numEventsTotalNeg_;
0070   unsigned int naccepted_ = numEventsPassPos_ + numEventsPassNeg_;
0071   printf("ntried = %i, naccepted = %i, efficiency = %5f\n", ntried_, naccepted_, (double)naccepted_ / (double)ntried_);
0072   printf(
0073       "weighttried = %5f, weightaccepted = %5f, efficiency = %5f\n", sumtotal_w_, sumpass_w_, sumpass_w_ / sumtotal_w_);
0074 }
0075 
0076 void HepMCFilterDriver::resetStatistics() {
0077   numEventsPassPos_ = 0;
0078   numEventsPassNeg_ = 0;
0079   numEventsTotalPos_ = 0;
0080   numEventsTotalNeg_ = 0;
0081   sumpass_w_ = 0;
0082   sumpass_w2_ = 0;
0083   sumtotal_w_ = 0;
0084   sumtotal_w2_ = 0;
0085 }