CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
GenXSecAnalyzer Class Reference

#include <GenXSecAnalyzer.h>

Inheritance diagram for GenXSecAnalyzer:
edm::one::EDAnalyzer< edm::one::WatchLuminosityBlocks > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

const double final_xsec_error () const
 
const double final_xsec_value () const
 
 GenXSecAnalyzer (const edm::ParameterSet &)
 
 ~GenXSecAnalyzer ()
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchLuminosityBlocks >
 EDAnalyzer ()=default
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDAnalyzerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &) override
 
virtual void beginJob () override
 
virtual void beginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) override
 
void compute ()
 
virtual void endJob () override
 
virtual void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) override
 

Private Attributes

edm::EDGetTokenT< GenFilterInfogenFilterInfoToken_
 
edm::EDGetTokenT
< GenLumiInfoProduct
genLumiInfoToken_
 
int hepidwtup_
 
GenFilterInfo jetMatchEffStat_
 
std::vector< GenLumiInfoProductproducts_
 
GenFilterInfo totalEffStat_
 
GenLumiInfoProduct::XSec xsec_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 30 of file GenXSecAnalyzer.h.

Constructor & Destructor Documentation

GenXSecAnalyzer::GenXSecAnalyzer ( const edm::ParameterSet iConfig)
explicit

Definition at line 6 of file GenXSecAnalyzer.cc.

References genFilterInfoToken_, genLumiInfoToken_, and products_.

6  :
7  hepidwtup_(-1),
8  xsec_(0,0),
9  jetMatchEffStat_(0,0,0,0,0.,0.,0.,0.),
10  totalEffStat_(0,0,0,0,0.,0.,0.,0.)
11 {
12  products_.clear();
13 
14  genFilterInfoToken_ = consumes<GenFilterInfo,edm::InLumi>(edm::InputTag("genFilterEfficiencyProducer",""));
15  genLumiInfoToken_ = consumes<GenLumiInfoProduct,edm::InLumi>(edm::InputTag("generator",""));
16 }
std::vector< GenLumiInfoProduct > products_
GenFilterInfo totalEffStat_
edm::EDGetTokenT< GenLumiInfoProduct > genLumiInfoToken_
GenFilterInfo jetMatchEffStat_
GenLumiInfoProduct::XSec xsec_
edm::EDGetTokenT< GenFilterInfo > genFilterInfoToken_
GenXSecAnalyzer::~GenXSecAnalyzer ( )

Definition at line 18 of file GenXSecAnalyzer.cc.

19 {
20 }

Member Function Documentation

void GenXSecAnalyzer::analyze ( const edm::Event ,
const edm::EventSetup  
)
overrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 28 of file GenXSecAnalyzer.cc.

29 {
30 }
void GenXSecAnalyzer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 23 of file GenXSecAnalyzer.cc.

References products_.

23  {
24  products_.clear();
25 }
std::vector< GenLumiInfoProduct > products_
void GenXSecAnalyzer::beginLuminosityBlock ( edm::LuminosityBlock const &  iLumi,
edm::EventSetup const &   
)
overrideprivatevirtual

Definition at line 34 of file GenXSecAnalyzer.cc.

34  {
35 }
void GenXSecAnalyzer::compute ( )
private

Definition at line 109 of file GenXSecAnalyzer.cc.

References GenLumiInfoProduct::ProcessInfo::accepted(), GenLumiInfoProduct::ProcessInfo::acceptedBr(), cuy::denominator, alignCSCRings::e, GenLumiInfoProduct::XSec::error(), hepidwtup_, i, GenLumiInfoProduct::ProcessInfo::killed(), GenLumiInfoProduct::ProcessInfo::lheXSec(), GenLumiInfoProduct::FinalStat::n(), GenLumiInfoProduct::ProcessInfo::nPassNeg(), GenLumiInfoProduct::ProcessInfo::nPassPos(), groupFilesInBlocks::ntotal, GenLumiInfoProduct::ProcessInfo::nTotalNeg(), GenLumiInfoProduct::ProcessInfo::nTotalPos(), cuy::numerator, funct::pow(), proc, products_, GenLumiInfoProduct::ProcessInfo::selected(), mathSSE::sqrt(), GenLumiInfoProduct::FinalStat::sum(), GenLumiInfoProduct::FinalStat::sum2(), GenLumiInfoProduct::ProcessInfo::tried(), GenLumiInfoProduct::XSec::value(), and xsec_.

Referenced by endJob().

110 {
111  // for pure parton shower generator
112 
113  if(hepidwtup_== -1)
114  {
115  double sigSum = 0.0;
116  double totalN = 0.0;
117  for(unsigned int i=0; i < products_.size(); i++){
118 
119  GenLumiInfoProduct::ProcessInfo proc = products_[i].getProcessInfos()[0];
120  double hepxsec_value = proc.lheXSec().value();
121 
122  sigSum += proc.tried().sum() * hepxsec_value;
123  totalN += proc.tried().sum();
124  }
125  double sigAve = totalN>1e-6? sigSum/totalN: 0;
126  xsec_ = GenLumiInfoProduct::XSec(sigAve,-1);
127  }
128  // for ME+parton shower MC
129  else{
130 
131  double sum_numerator = 0;
132  double sum_denominator = 0;
133 
134  for(unsigned int i=0; i < products_.size(); i++){
135 
136  double sigSelSum = 0.0;
137  double sigSum = 0.0;
138  double sigBrSum = 0.0;
139  double err2Sum = 0.0;
140  double errBr2Sum = 0.0;
141 
142  unsigned int vectorSize = products_[i].getProcessInfos().size();
143  for(unsigned int ip=0; ip < vectorSize; ip++){
144  GenLumiInfoProduct::ProcessInfo proc = products_[i].getProcessInfos()[ip];
145  double hepxsec_value = proc.lheXSec().value();
146  double hepxsec_error = proc.lheXSec().error();
147 
148  if (!proc.killed().n())
149  continue;
150 
151  double sigma2Sum, sigma2Err;
152  sigma2Sum = hepxsec_value * hepxsec_value;
153  sigma2Err = hepxsec_error * hepxsec_error;
154 
155  double sigmaAvg = hepxsec_value;
156 
157  double fracAcc = 0;
158  double ntotal = proc.nTotalPos()-proc.nTotalNeg();
159  double npass = proc.nPassPos() -proc.nPassNeg();
160  switch(hepidwtup_){
161  case 3: case -3:
162  fracAcc = ntotal > 1e-6? npass/ntotal: -1;
163  break;
164  default:
165  fracAcc = proc.selected().sum() > 1e-6? proc.killed().sum() / proc.selected().sum():-1;
166  break;
167  }
168 
169  if(fracAcc<1e-6)continue;
170 
171  double fracBr = proc.accepted().sum() > 0.0 ?
172  proc.acceptedBr().sum() / proc.accepted().sum() : 1;
173  double sigmaFin = sigmaAvg * fracAcc * fracBr;
174  double sigmaFinBr = sigmaFin * fracBr;
175 
176  double relErr = 1.0;
177  if (proc.killed().n() > 1) {
178  double efferr2=0;
179  switch(hepidwtup_) {
180  case 3: case -3:
181  {
182  double ntotal_pos = proc.nTotalPos();
183  double effp = ntotal_pos > 1e-6?
184  (double)proc.nPassPos()/ntotal_pos:0;
185  double effp_err2 = ntotal_pos > 1e-6?
186  (1-effp)*effp/ntotal_pos: 0;
187 
188  double ntotal_neg = proc.nTotalNeg();
189  double effn = ntotal_neg > 1e-6?
190  (double)proc.nPassNeg()/ntotal_neg:0;
191  double effn_err2 = ntotal_neg > 1e-6?
192  (1-effn)*effn/ntotal_neg: 0;
193 
194  efferr2 = ntotal > 0 ?
195  (ntotal_pos*ntotal_pos*effp_err2 +
196  ntotal_neg*ntotal_neg*effn_err2)/ntotal/ntotal:0;
197  break;
198  }
199  default:
200  {
201  double denominator = pow(proc.selected().sum(),4);
202  double passw = proc.killed().sum();
203  double passw2 = proc.killed().sum2();
204  double failw = proc.selected().sum() - passw;
205  double failw2 = proc.selected().sum2() - passw2;
206  double numerator = (passw2*failw*failw + failw2*passw*passw);
207 
208  efferr2 = denominator>1e-6?
209  numerator/denominator:0;
210  break;
211  }
212  }
213  double delta2Veto = efferr2/fracAcc/fracAcc;
214  double delta2Sum = delta2Veto
215  + sigma2Err / sigma2Sum;
216  relErr = (delta2Sum > 0.0 ?
217  std::sqrt(delta2Sum) : 0.0);
218  }
219  double deltaFin = sigmaFin * relErr;
220  double deltaFinBr = sigmaFinBr * relErr;
221 
222  sigSelSum += sigmaAvg;
223  sigSum += sigmaFin;
224  sigBrSum += sigmaFinBr;
225  err2Sum += deltaFin * deltaFin;
226  errBr2Sum += deltaFinBr * deltaFinBr;
227 
228 
229 
230  } // end of loop over different processes
231 
232  double dN = std::sqrt(errBr2Sum);
233  sum_denominator += (dN> 1e-6)? 1/dN/dN: 0;
234  sum_numerator += (dN> 1e-6)? sigBrSum/dN/dN: 0;
235 
236 
237  } // end of loop over different samples
238  double final_value = sum_denominator > 0? sum_numerator/sum_denominator : 0;
239  double final_error = sum_denominator > 0? 1/sqrt(sum_denominator) : -1;
240  xsec_ = GenLumiInfoProduct::XSec(final_value, final_error);
241  }
242  return;
243 }
int i
Definition: DBlmapReader.cc:9
std::vector< GenLumiInfoProduct > products_
list numerator
Definition: cuy.py:483
TrainProcessor *const proc
Definition: MVATrainer.cc:101
GenLumiInfoProduct::XSec xsec_
list denominator
Definition: cuy.py:484
T sqrt(T t)
Definition: SSEVec.h:48
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void GenXSecAnalyzer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 247 of file GenXSecAnalyzer.cc.

References compute(), GenLumiInfoProduct::XSec::error(), GenFilterInfo::filterEfficiency(), GenFilterInfo::filterEfficiencyError(), hepidwtup_, jetMatchEffStat_, products_, mathSSE::sqrt(), GenFilterInfo::sumPassWeights(), GenFilterInfo::sumWeights(), totalEffStat_, GenLumiInfoProduct::XSec::value(), and xsec_.

247  {
248 
249  edm::LogPrint("GenXSecAnalyzer") << "\n"
250  << "------------------------------------" << "\n"
251  << "GenXsecAnalyzer:" << "\n"
252  << "------------------------------------";
253 
254  if(!products_.size()) {
255  edm::LogPrint("GenXSecAnalyzer") << "------------------------------------" << "\n"
256  << "Cross-section summary not available" << "\n"
257  << "------------------------------------";
258  return;
259  }
260 
261 
262  compute();
263 
264  double filterOnly_eff = totalEffStat_.filterEfficiency(hepidwtup_);
265  double filterOnly_err = totalEffStat_.filterEfficiencyError(hepidwtup_);
266 
267  double jetmatching_eff_total = jetMatchEffStat_.filterEfficiency(hepidwtup_);
268  double jetmatching_err_total = jetMatchEffStat_.filterEfficiencyError(hepidwtup_);
269 
270  edm::LogPrint("GenXSecAnalyzer") << "------------------------------------" << "\n"
271  << "Overall cross-section summary:" << "\n"
272  << "------------------------------------";
273 
274  edm::LogPrint("GenXSecAnalyzer") << "jet matching efficiency = " <<
275  jetMatchEffStat_.sumPassWeights() << "/" <<
276  jetMatchEffStat_.sumWeights() << " = "
277  << std::setprecision(6) << jetmatching_eff_total << " +- " << jetmatching_err_total << "\n";
278 
279  edm::LogPrint("GenXSecAnalyzer") << "Before filter: cross section = " << std::setprecision(6) << xsec_.value() << " +- " << std::setprecision(6) << xsec_.error() << " pb";
280 
281  edm::LogPrint("GenXSecAnalyzer") << "Filter efficiency = " << std::setprecision(6)
282  << filterOnly_eff << " +- " << filterOnly_err;
283 
284 
285  double xsec_after = xsec_.value()*filterOnly_eff ;
286  double error_after = xsec_after*sqrt(xsec_.error()*xsec_.error()/xsec_.value()/xsec_.value()+
287  filterOnly_err*filterOnly_err/filterOnly_eff/filterOnly_eff);
288 
289  edm::LogPrint("GenXSecAnalyzer") << "After filter: cross section = "
290  << std::setprecision(6) << xsec_after
291  << " +- "
292  << std::setprecision(6) << error_after
293  << " pb";
294 
295 }
std::vector< GenLumiInfoProduct > products_
GenFilterInfo totalEffStat_
double filterEfficiency(int idwtup=+3) const
GenFilterInfo jetMatchEffStat_
GenLumiInfoProduct::XSec xsec_
double sumPassWeights() const
Definition: GenFilterInfo.h:34
T sqrt(T t)
Definition: SSEVec.h:48
double filterEfficiencyError(int idwtup=+3) const
double sumWeights() const
Definition: GenFilterInfo.h:40
void GenXSecAnalyzer::endLuminosityBlock ( edm::LuminosityBlock const &  iLumi,
edm::EventSetup const &   
)
overrideprivatevirtual

Definition at line 38 of file GenXSecAnalyzer.cc.

References alignCSCRings::e, genFilterInfoToken_, genLumiInfoToken_, edm::LuminosityBlock::getByToken(), hepidwtup_, i, edm::HandleBase::isValid(), jetMatchEffStat_, GenFilterInfo::mergeProduct(), products_, GenLumiInfoProduct::FinalStat::sum(), GenLumiInfoProduct::FinalStat::sum2(), totalEffStat_, and relativeConstraints::value.

38  {
39 
41  iLumi.getByToken(genFilterInfoToken_,genFilter);
42  if(genFilter.isValid())
43  totalEffStat_.mergeProduct(*genFilter);
44 
45 
47  iLumi.getByToken(genLumiInfoToken_,genLumiInfo);
48  if (!genLumiInfo.isValid()) return;
49 
50  hepidwtup_ = genLumiInfo->getHEPIDWTUP();
51 
52  std::vector<GenLumiInfoProduct::ProcessInfo> theProcesses = genLumiInfo->getProcessInfos();
53  unsigned int theProcesses_size = theProcesses.size();
54  // if it's a pure parton-shower generator, check there should be only one element in thisProcessInfos
55  // the error of lheXSec is -1
56  if(hepidwtup_== -1)
57  {
58  if(theProcesses_size!=1){
59  edm::LogError("GenXSecAnalyzer::endLuminosityBlock") << "Pure parton shower has thisProcessInfos size!=1";
60  return;
61  }
62  if(theProcesses[0].lheXSec().value()<1e-6){
63  edm::LogError("GenXSecAnalyzer::endLuminosityBlock") << "cross section value = " << theProcesses[0].lheXSec().value();
64  return;
65  }
66  }
67 
68  // doing generic summing
69  for(unsigned int ip=0; ip < theProcesses_size; ip++)
70  {
71  GenLumiInfoProduct::FinalStat temp_killed = theProcesses[ip].killed();
72  GenLumiInfoProduct::FinalStat temp_selected = theProcesses[ip].selected();
73  double passw = temp_killed.sum();
74  double passw2 = temp_killed.sum2();
75  double totalw = temp_selected.sum();
76  double totalw2 = temp_selected.sum2();
78  theProcesses[ip].nPassPos(),
79  theProcesses[ip].nPassNeg(),
80  theProcesses[ip].nTotalPos(),
81  theProcesses[ip].nTotalNeg(),
82  passw,
83  passw2,
84  totalw,
85  totalw2)
86  );
87 
88  }
89  // now determine if this LuminosityBlock has the same lheXSec as existing products
90  bool sameMC = false;
91  for(unsigned int i=0; i < products_.size(); i++){
92 
93  if(products_[i].mergeProduct(*genLumiInfo))
94  sameMC = true;
95  else if(!products_[i].samePhysics(*genLumiInfo))
96  {
97  edm::LogError("GenXSecAnalyzer::endLuminosityBlock") << "Merging samples that come from different physics processes";
98  return;
99  }
100 
101  }
102 
103  if(!sameMC)
104  products_.push_back(*genLumiInfo);
105  return;
106 }
int i
Definition: DBlmapReader.cc:9
std::vector< GenLumiInfoProduct > products_
GenFilterInfo totalEffStat_
edm::EDGetTokenT< GenLumiInfoProduct > genLumiInfoToken_
GenFilterInfo jetMatchEffStat_
bool mergeProduct(GenFilterInfo const &other)
bool isValid() const
Definition: HandleBase.h:76
edm::EDGetTokenT< GenFilterInfo > genFilterInfoToken_
const double GenXSecAnalyzer::final_xsec_error ( ) const
inline

Definition at line 37 of file GenXSecAnalyzer.h.

References GenLumiInfoProduct::XSec::error(), and xsec_.

37 {return xsec_.error();}
GenLumiInfoProduct::XSec xsec_
const double GenXSecAnalyzer::final_xsec_value ( ) const
inline

Definition at line 36 of file GenXSecAnalyzer.h.

References GenLumiInfoProduct::XSec::value(), and xsec_.

36 {return xsec_.value();}
GenLumiInfoProduct::XSec xsec_

Member Data Documentation

edm::EDGetTokenT<GenFilterInfo> GenXSecAnalyzer::genFilterInfoToken_
private

Definition at line 48 of file GenXSecAnalyzer.h.

Referenced by endLuminosityBlock(), and GenXSecAnalyzer().

edm::EDGetTokenT<GenLumiInfoProduct> GenXSecAnalyzer::genLumiInfoToken_
private

Definition at line 49 of file GenXSecAnalyzer.h.

Referenced by endLuminosityBlock(), and GenXSecAnalyzer().

int GenXSecAnalyzer::hepidwtup_
private

Definition at line 51 of file GenXSecAnalyzer.h.

Referenced by compute(), endJob(), and endLuminosityBlock().

GenFilterInfo GenXSecAnalyzer::jetMatchEffStat_
private

Definition at line 53 of file GenXSecAnalyzer.h.

Referenced by endJob(), and endLuminosityBlock().

std::vector<GenLumiInfoProduct> GenXSecAnalyzer::products_
private

Definition at line 56 of file GenXSecAnalyzer.h.

Referenced by beginJob(), compute(), endJob(), endLuminosityBlock(), and GenXSecAnalyzer().

GenFilterInfo GenXSecAnalyzer::totalEffStat_
private

Definition at line 54 of file GenXSecAnalyzer.h.

Referenced by endJob(), and endLuminosityBlock().

GenLumiInfoProduct::XSec GenXSecAnalyzer::xsec_
private

Definition at line 52 of file GenXSecAnalyzer.h.

Referenced by compute(), endJob(), final_xsec_error(), and final_xsec_value().