Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-22 00:36:53

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