Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-20 03:22:23

0001 #include <iostream>
0002 #include <algorithm>
0003 #include <utility>
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "SimDataFormats/GeneratorProducts/interface/GenFilterInfo.h"
0008 
0009 using namespace edm;
0010 using namespace std;
0011 
0012 GenFilterInfo::GenFilterInfo()
0013     : numPassPositiveEvents_(0),
0014       numPassNegativeEvents_(0),
0015       numTotalPositiveEvents_(0),
0016       numTotalNegativeEvents_(0),
0017       sumPassWeights_(0.),
0018       sumPassWeights2_(0.),
0019       sumTotalWeights_(0.),
0020       sumTotalWeights2_(0.) {}
0021 
0022 GenFilterInfo::GenFilterInfo(unsigned int tried, unsigned int pass)
0023     : numPassPositiveEvents_(pass),
0024       numPassNegativeEvents_(0),
0025       numTotalPositiveEvents_(tried),
0026       numTotalNegativeEvents_(0),
0027       sumPassWeights_(pass),
0028       sumPassWeights2_(pass),
0029       sumTotalWeights_(tried),
0030       sumTotalWeights2_(tried) {}
0031 
0032 GenFilterInfo::GenFilterInfo(unsigned int passp,
0033                              unsigned int passn,
0034                              unsigned int totalp,
0035                              unsigned int totaln,
0036                              double passw,
0037                              double passw2,
0038                              double totalw,
0039                              double totalw2)
0040     : numPassPositiveEvents_(passp),
0041       numPassNegativeEvents_(passn),
0042       numTotalPositiveEvents_(totalp),
0043       numTotalNegativeEvents_(totaln),
0044       sumPassWeights_(passw),
0045       sumPassWeights2_(passw2),
0046       sumTotalWeights_(totalw),
0047       sumTotalWeights2_(totalw2) {}
0048 
0049 GenFilterInfo::~GenFilterInfo() {}
0050 
0051 bool GenFilterInfo::mergeProduct(GenFilterInfo const& other) {
0052   // merging two GenFilterInfos means that the numerator and
0053   // denominator from the original product need to besummed with
0054   // those in the product we are going to merge
0055 
0056   numPassPositiveEvents_ += other.numPassPositiveEvents_;
0057   numPassNegativeEvents_ += other.numPassNegativeEvents_;
0058   numTotalPositiveEvents_ += other.numTotalPositiveEvents_;
0059   numTotalNegativeEvents_ += other.numTotalNegativeEvents_;
0060   sumPassWeights_ += other.sumPassWeights_;
0061   sumPassWeights2_ += other.sumPassWeights2_;
0062   sumTotalWeights_ += other.sumTotalWeights_;
0063   sumTotalWeights2_ += other.sumTotalWeights2_;
0064 
0065   return true;
0066 }
0067 
0068 void GenFilterInfo::swap(GenFilterInfo& other) {
0069   std::swap(numPassPositiveEvents_, other.numPassPositiveEvents_);
0070   std::swap(numPassNegativeEvents_, other.numPassNegativeEvents_);
0071   std::swap(numTotalPositiveEvents_, other.numTotalPositiveEvents_);
0072   std::swap(numTotalNegativeEvents_, other.numTotalNegativeEvents_);
0073   std::swap(sumPassWeights_, other.sumPassWeights_);
0074   std::swap(sumPassWeights2_, other.sumPassWeights2_);
0075   std::swap(sumTotalWeights_, other.sumTotalWeights_);
0076   std::swap(sumTotalWeights2_, other.sumTotalWeights2_);
0077 }
0078 
0079 double GenFilterInfo::filterEfficiency(int idwtup) const {
0080   double eff = -1;
0081   switch (idwtup) {
0082     case 3:
0083     case -3:
0084       eff = numEventsTotal() > 0 ? (double)numEventsPassed() / (double)numEventsTotal() : -1;
0085       break;
0086     default:
0087       eff = sumWeights() > 0 ? sumPassWeights() / sumWeights() : -1;
0088       break;
0089   }
0090   return eff;
0091 }
0092 
0093 double GenFilterInfo::filterEfficiencyError(int idwtup) const {
0094   double efferr = -1;
0095   switch (idwtup) {
0096     case 3:
0097     case -3: {
0098       double effp =
0099           numTotalPositiveEvents() > 0 ? (double)numPassPositiveEvents() / (double)numTotalPositiveEvents() : 0;
0100       double effp_err2 = numTotalPositiveEvents() > 0 ? (1 - effp) * effp / (double)numTotalPositiveEvents() : 0;
0101 
0102       double effn =
0103           numTotalNegativeEvents() > 0 ? (double)numPassNegativeEvents() / (double)numTotalNegativeEvents() : 0;
0104       double effn_err2 = numTotalNegativeEvents() > 0 ? (1 - effn) * effn / (double)numTotalNegativeEvents() : 0;
0105 
0106       efferr = numEventsTotal() > 0
0107                    ? sqrt(((double)numTotalPositiveEvents() * (double)numTotalPositiveEvents() * effp_err2 +
0108                            (double)numTotalNegativeEvents() * (double)numTotalNegativeEvents() * effn_err2) /
0109                           (double)numEventsTotal() / (double)numEventsTotal())
0110                    : -1;
0111       break;
0112     }
0113     default: {
0114       double denominator = sumWeights() * sumWeights() * sumWeights() * sumWeights();
0115       double numerator = sumPassWeights2() * sumFailWeights() * sumFailWeights() +
0116                          sumFailWeights2() * sumPassWeights() * sumPassWeights();
0117       efferr = denominator > 0 ? sqrt(numerator / denominator) : -1;
0118       break;
0119     }
0120   }
0121 
0122   return efferr;
0123 }