Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:50

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(const GenFilterInfo& other)
0050     : numPassPositiveEvents_(other.numPassPositiveEvents_),
0051       numPassNegativeEvents_(other.numPassNegativeEvents_),
0052       numTotalPositiveEvents_(other.numTotalPositiveEvents_),
0053       numTotalNegativeEvents_(other.numTotalNegativeEvents_),
0054       sumPassWeights_(other.sumPassWeights_),
0055       sumPassWeights2_(other.sumPassWeights2_),
0056       sumTotalWeights_(other.sumTotalWeights_),
0057       sumTotalWeights2_(other.sumTotalWeights2_) {}
0058 
0059 GenFilterInfo::~GenFilterInfo() {}
0060 
0061 bool GenFilterInfo::mergeProduct(GenFilterInfo const& other) {
0062   // merging two GenFilterInfos means that the numerator and
0063   // denominator from the original product need to besummed with
0064   // those in the product we are going to merge
0065 
0066   numPassPositiveEvents_ += other.numPassPositiveEvents_;
0067   numPassNegativeEvents_ += other.numPassNegativeEvents_;
0068   numTotalPositiveEvents_ += other.numTotalPositiveEvents_;
0069   numTotalNegativeEvents_ += other.numTotalNegativeEvents_;
0070   sumPassWeights_ += other.sumPassWeights_;
0071   sumPassWeights2_ += other.sumPassWeights2_;
0072   sumTotalWeights_ += other.sumTotalWeights_;
0073   sumTotalWeights2_ += other.sumTotalWeights2_;
0074 
0075   return true;
0076 }
0077 
0078 void GenFilterInfo::swap(GenFilterInfo& other) {
0079   std::swap(numPassPositiveEvents_, other.numPassPositiveEvents_);
0080   std::swap(numPassNegativeEvents_, other.numPassNegativeEvents_);
0081   std::swap(numTotalPositiveEvents_, other.numTotalPositiveEvents_);
0082   std::swap(numTotalNegativeEvents_, other.numTotalNegativeEvents_);
0083   std::swap(sumPassWeights_, other.sumPassWeights_);
0084   std::swap(sumPassWeights2_, other.sumPassWeights2_);
0085   std::swap(sumTotalWeights_, other.sumTotalWeights_);
0086   std::swap(sumTotalWeights2_, other.sumTotalWeights2_);
0087 }
0088 
0089 double GenFilterInfo::filterEfficiency(int idwtup) const {
0090   double eff = -1;
0091   switch (idwtup) {
0092     case 3:
0093     case -3:
0094       eff = numEventsTotal() > 0 ? (double)numEventsPassed() / (double)numEventsTotal() : -1;
0095       break;
0096     default:
0097       eff = sumWeights() > 0 ? sumPassWeights() / sumWeights() : -1;
0098       break;
0099   }
0100   return eff;
0101 }
0102 
0103 double GenFilterInfo::filterEfficiencyError(int idwtup) const {
0104   double efferr = -1;
0105   switch (idwtup) {
0106     case 3:
0107     case -3: {
0108       double effp =
0109           numTotalPositiveEvents() > 0 ? (double)numPassPositiveEvents() / (double)numTotalPositiveEvents() : 0;
0110       double effp_err2 = numTotalPositiveEvents() > 0 ? (1 - effp) * effp / (double)numTotalPositiveEvents() : 0;
0111 
0112       double effn =
0113           numTotalNegativeEvents() > 0 ? (double)numPassNegativeEvents() / (double)numTotalNegativeEvents() : 0;
0114       double effn_err2 = numTotalNegativeEvents() > 0 ? (1 - effn) * effn / (double)numTotalNegativeEvents() : 0;
0115 
0116       efferr = numEventsTotal() > 0
0117                    ? sqrt(((double)numTotalPositiveEvents() * (double)numTotalPositiveEvents() * effp_err2 +
0118                            (double)numTotalNegativeEvents() * (double)numTotalNegativeEvents() * effn_err2) /
0119                           (double)numEventsTotal() / (double)numEventsTotal())
0120                    : -1;
0121       break;
0122     }
0123     default: {
0124       double denominator = sumWeights() * sumWeights() * sumWeights() * sumWeights();
0125       double numerator = sumPassWeights2() * sumFailWeights() * sumFailWeights() +
0126                          sumFailWeights2() * sumPassWeights() * sumPassWeights();
0127       efferr = denominator > 0 ? sqrt(numerator / denominator) : -1;
0128       break;
0129     }
0130   }
0131 
0132   return efferr;
0133 }