89 void combine(
double &,
double &,
double &,
const double &,
const double &,
const double &)
const;
138 xsecPreFilter_(-1, -1),
140 filterOnlyEffStat_(0, 0, 0, 0, 0., 0., 0., 0.),
141 hepMCFilterEffStat_(0, 0, 0, 0, 0., 0., 0., 0.) {
163 return std::make_shared<gxsec::RunCache>();
168 return std::shared_ptr<gxsec::LumiCache>();
180 std::vector<GenLumiInfoProduct::ProcessInfo>
const &theProcesses =
genLumiInfo->getProcessInfos();
182 unsigned int theProcesses_size = theProcesses.size();
187 if (theProcesses_size != 1) {
188 edm::LogError(
"GenXSecAnalyzer::endLuminosityBlock") <<
"Pure parton shower has thisProcessInfos size!=1";
193 for (
unsigned int ip = 0; ip < theProcesses_size; ip++) {
194 if (theProcesses[ip].lheXSec().
value() < 0) {
196 <<
"cross section of process " << ip <<
" value = " << theProcesses[ip].lheXSec().value();
212 runC->filterOnlyEffRun_.mergeProduct(*genFilter);
222 runC->hepMCFilterEffRun_.mergeProduct(*hepMCFilter);
228 for (
unsigned int ip = 0; ip < theProcesses_size; ip++) {
229 int id = theProcesses[ip].process();
234 double passw = temp_killed.
sum();
235 double passw2 = temp_killed.
sum2();
236 double totalw = temp_selected.
sum();
237 double totalw2 = temp_selected.
sum2();
239 theProcesses[ip].nPassNeg(),
240 theProcesses[ip].nTotalPos(),
241 theProcesses[ip].nTotalNeg(),
249 double currentValue = theProcesses[ip].lheXSec().value();
250 double currentError = theProcesses[ip].lheXSec().error();
253 auto &thisRunWeightPre = runC->thisRunWeightPre_;
255 x.mergeProduct(tempInfo);
256 double previousValue = runC->previousLumiBlockLHEXSec_[
id].value();
258 if (currentValue != previousValue)
260 double xsec =
y.value();
261 double err =
y.error();
262 combine(xsec,
err, thisRunWeightPre, currentValue, currentError, totalw);
265 thisRunWeightPre += totalw;
271 y = theProcesses[ip].lheXSec();
272 thisRunWeightPre += totalw;
275 runC->previousLumiBlockLHEXSec_[
id] = theProcesses[ip].lheXSec();
288 for (
unsigned int iSize = 0; iSize < thisHeprup.
XSECUP.size(); iSize++) {
296 auto runC = runCache(iRun.
index());
305 std::vector<GenLumiInfoProduct::ProcessInfo> newInfos;
306 for (std::map<int, GenLumiInfoProduct::XSec>::const_iterator iter = runC->currentLumiBlockLHEXSec_.begin();
307 iter != runC->currentLumiBlockLHEXSec_.end();
310 temp.setLheXSec(iter->second.value(), iter->second.error());
311 newInfos.push_back(
temp);
313 runC->product_.setProcessInfo(newInfos);
319 double thisHepFilterEff = 1;
320 double thisHepFilterErr = 0;
322 if (runC->hepMCFilterEffRun_.sumWeights2() > 0) {
323 thisHepFilterEff = runC->hepMCFilterEffRun_.filterEfficiency(
hepidwtup_);
324 thisHepFilterErr = runC->hepMCFilterEffRun_.filterEfficiencyError(
hepidwtup_);
325 if (thisHepFilterEff < 0) {
326 thisHepFilterEff = 1;
327 thisHepFilterErr = 0;
331 double thisGenFilterEff = 1;
332 double thisGenFilterErr = 0;
334 if (runC->filterOnlyEffRun_.sumWeights2() > 0) {
335 thisGenFilterEff = runC->filterOnlyEffRun_.filterEfficiency(
hepidwtup_);
336 thisGenFilterErr = runC->filterOnlyEffRun_.filterEfficiencyError(
hepidwtup_);
337 if (thisGenFilterEff < 0) {
338 thisGenFilterEff = 1;
339 thisGenFilterErr = 0;
342 double thisXsec = thisRunXSecPre.
value() > 0 ? thisHepFilterEff * thisGenFilterEff * thisRunXSecPre.
value() : 0;
344 thisRunXSecPre.
value() > 0
346 pow(thisHepFilterErr / thisHepFilterEff, 2) +
pow(thisGenFilterErr / thisGenFilterEff, 2))
355 const double ¤tValue,
356 const double ¤tError,
357 const double ¤tWeight)
const {
358 if (finalValue <= 0) {
359 finalValue = currentValue;
360 finalError = currentError;
361 finalWeight += currentWeight;
363 double wgt1 = (finalError <= 0 || currentError <= 0) ? finalWeight : 1 / (finalError * finalError);
364 double wgt2 = (finalError <= 0 || currentError <= 0) ? currentWeight : 1 / (currentError * currentError);
365 double xsec = (wgt1 * finalValue + wgt2 * currentValue) / (wgt1 + wgt2);
366 double err = (finalError <= 0 || currentError <= 0) ? 0 : 1.0 /
std::sqrt(wgt1 + wgt2);
369 finalWeight += currentWeight;
377 const double &thisw)
const {
380 double thisValue = thisRunXSec.
value();
381 double thisError = thisRunXSec.
error();
389 double sigSelSum = 0.0;
390 double err2SelSum = 0.0;
392 std::vector<GenLumiInfoProduct::XSec> tempVector_before;
393 std::vector<GenLumiInfoProduct::XSec> tempVector_after;
397 for (
unsigned int ip = 0; ip < vectorSize; ip++) {
399 double hepxsec_value =
proc.lheXSec().value();
400 double hepxsec_error =
proc.lheXSec().error() <= 0 ? 0 :
proc.lheXSec().error();
403 sigSelSum += hepxsec_value;
404 err2SelSum += hepxsec_error * hepxsec_error;
407 if (
proc.killed().n() < 1) {
415 double npass =
proc.nPassPos() -
proc.nPassNeg();
422 fracAcc =
proc.selected().sum() > 0 ?
proc.killed().sum() /
proc.selected().sum() : -1;
432 double sigmaFin = hepxsec_value * fracAcc;
440 double ntotal_pos =
proc.nTotalPos();
441 double effp = ntotal_pos > 0 ? (double)
proc.nPassPos() / ntotal_pos : 0;
442 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
444 double ntotal_neg =
proc.nTotalNeg();
445 double effn = ntotal_neg > 0 ? (double)
proc.nPassNeg() / ntotal_neg : 0;
446 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
449 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
ntotal /
ntotal 455 double passw =
proc.killed().sum();
456 double passw2 =
proc.killed().sum2();
457 double failw =
proc.selected().sum() - passw;
458 double failw2 =
proc.selected().sum2() - passw2;
459 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
465 double delta2Veto = efferr2 / fracAcc / fracAcc;
469 double sigma2Sum, sigma2Err;
470 sigma2Sum = hepxsec_value * hepxsec_value;
471 sigma2Err = hepxsec_error * hepxsec_error;
473 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
474 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
475 double deltaFin = sigmaFin * relErr;
485 double xsec_after = sigSelSum * total_matcheff;
486 double xsecerr_after = (total_matcheff > 0 && sigSelSum > 0)
487 ? xsec_after *
sqrt(err2SelSum / sigSelSum / sigSelSum +
488 total_matcherr * total_matcherr / total_matcheff / total_matcheff)
492 tempVector_after.push_back(
result);
502 <<
"------------------------------------" 504 <<
"GenXsecAnalyzer:" 506 <<
"------------------------------------";
509 edm::LogPrint(
"GenXSecAnalyzer") <<
"------------------------------------" 511 <<
"Cross-section summary not available" 513 <<
"------------------------------------";
518 double final_fract_neg_w = 0;
519 double final_fract_neg_w_unc = 0;
525 <<
"-----------------------------------------------------------------------------------------------------------" 526 "--------------------------------------------------------------- \n" 527 <<
"Overall cross-section summary \n" 528 <<
"-----------------------------------------------------------------------------------------------------------" 529 "---------------------------------------------------------------";
530 edm::LogPrint(
"GenXSecAnalyzer") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw " 531 "\txsec_match [pb]\t\t\taccepted [%]\t event_eff [%]";
534 const unsigned last = sizeOfInfos - 1;
537 double jetmatch_eff = 0;
538 double jetmatch_err = 0;
539 double matching_eff = 1;
540 double matching_efferr = 1;
562 <<
"-------------------------------------------------------------------------------------------------------" 563 "------------------------------------------------------------------- ";
569 final_fract_neg_w_unc =
571 ? final_fract_neg_w * final_fract_neg_w / thisEventEffStat.
numEventsPassed() *
580 edm::LogPrint(
"GenXSecAnalyzer") <<
title[
i] <<
"\t\t" << std::scientific << std::setprecision(3)
590 << (jetmatch_eff * 100) <<
" +/- " << (jetmatch_err * 100) <<
"\t" <<
std::fixed 600 <<
"-----------------------------------------------------------------------------------------------------------" 601 "---------------------------------------------------------------";
603 edm::LogPrint(
"GenXSecAnalyzer") <<
"Before matching: total cross section = " << std::scientific
607 edm::LogPrint(
"GenXSecAnalyzer") <<
"After matching: total cross section = " << std::scientific
611 edm::LogPrint(
"GenXSecAnalyzer") <<
"Matching efficiency = " <<
std::fixed << std::setprecision(1) << matching_eff
612 <<
" +/- " << matching_efferr <<
" [TO BE USED IN MCM]";
615 edm::LogPrint(
"GenXSecAnalyzer") <<
"Before Filter: total cross section = " << std::scientific
620 double hepMCFilter_eff = 1.0;
621 double hepMCFilter_err = 0.0;
625 edm::LogPrint(
"GenXSecAnalyzer") <<
"HepMC filter efficiency (taking into account weights)= " 629 <<
" = " << std::scientific << std::setprecision(3) << hepMCFilter_eff <<
" +- " 632 double hepMCFilter_event_total =
634 double hepMCFilter_event_pass =
636 double hepMCFilter_event_eff = hepMCFilter_event_total > 0 ? hepMCFilter_event_pass / hepMCFilter_event_total : 0;
637 double hepMCFilter_event_err =
638 hepMCFilter_event_total > 0
639 ?
sqrt((1 - hepMCFilter_event_eff) * hepMCFilter_event_eff / hepMCFilter_event_total)
641 edm::LogPrint(
"GenXSecAnalyzer") <<
"HepMC filter efficiency (event-level)= " 642 <<
"(" << hepMCFilter_event_pass <<
")" 644 <<
"(" << hepMCFilter_event_total <<
")" 645 <<
" = " << std::scientific << std::setprecision(3) << hepMCFilter_event_eff
646 <<
" +- " << hepMCFilter_event_err;
654 edm::LogPrint(
"GenXSecAnalyzer") <<
"Filter efficiency (taking into account weights)= " 658 <<
" = " << std::scientific << std::setprecision(3) << filterOnly_eff <<
" +- " 661 double filterOnly_event_total =
663 double filterOnly_event_pass =
665 double filterOnly_event_eff = filterOnly_event_total > 0 ? filterOnly_event_pass / filterOnly_event_total : 0;
666 double filterOnly_event_err = filterOnly_event_total > 0
667 ?
sqrt((1 - filterOnly_event_eff) * filterOnly_event_eff / filterOnly_event_total)
669 edm::LogPrint(
"GenXSecAnalyzer") <<
"Filter efficiency (event-level)= " 670 <<
"(" << filterOnly_event_pass <<
")" 672 <<
"(" << filterOnly_event_total <<
")" 673 <<
" = " << std::scientific << std::setprecision(3) << filterOnly_event_eff
674 <<
" +- " << filterOnly_event_err <<
" [TO BE USED IN MCM]";
679 final_fract_neg_w_unc =
681 ? final_fract_neg_w * final_fract_neg_w / filterOnly_event_pass *
688 edm::LogPrint(
"GenXSecAnalyzer") <<
"\nAfter filter: final cross section = " << std::scientific
691 edm::LogPrint(
"GenXSecAnalyzer") <<
"After filter: final fraction of events with negative weights = " 692 << std::scientific << std::setprecision(3) << final_fract_neg_w <<
" +- " 693 << final_fract_neg_w_unc;
696 double lumi_1M_evts =
697 xsec_.
value() > 0 ? 1e6 * (1 - 2 * final_fract_neg_w) * (1 - 2 * final_fract_neg_w) /
xsec_.
value() / 1
e3 : 0;
698 double lumi_1M_evts_unc =
699 xsec_.
value() > 0 ? (1 - 2 * final_fract_neg_w) * lumi_1M_evts *
700 sqrt(1
e-6 + 16 *
pow(final_fract_neg_w_unc, 2) /
pow(1 - 2 * final_fract_neg_w, 2) +
703 edm::LogPrint(
"GenXSecAnalyzer") <<
"After filter: final equivalent lumi for 1M events (1/fb) = " << std::scientific
704 << std::setprecision(3) << lumi_1M_evts <<
" +- " << lumi_1M_evts_unc;
std::vector< GenLumiInfoProduct::XSec > xsecBeforeMatching_
std::shared_ptr< gxsec::LumiCache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
std::map< int, GenFilterInfo > jetMatchEffStat_
edm::EDGetTokenT< GenFilterInfo > hepMCFilterInfoToken_
GenLumiInfoProduct product_
Run const & getRun() const
GenFilterInfo filterOnlyEffStat_
edm::EDGetTokenT< GenLumiInfoProduct > genLumiInfoToken_
void combine(GenLumiInfoProduct::XSec &, double &, const GenLumiInfoProduct::XSec &, const double &) const
GenLumiInfoProduct::XSec compute(const GenLumiInfoProduct &) const
GenFilterInfo filterOnlyEffRun_
unsigned int numTotalNegativeEvents() const
Log< level::Error, false > LogError
void globalEndRun(edm::Run const &, edm::EventSetup const &) const final
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
std::atomic< int > hepidwtup_
double sumWeights2() const
unsigned int numPassNegativeEvents() const
GenLumiInfoProduct::XSec xsec_
unsigned int numTotalPositiveEvents() const
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
GenFilterInfo hepMCFilterEffStat_
bool mergeProduct(GenFilterInfo const &other)
void analyze(edm::StreamID, const edm::Event &, const edm::EventSetup &) const final
const std::vector< ProcessInfo > & getProcessInfos() const
#define CMS_THREAD_GUARD(_var_)
#define DEFINE_FWK_MODULE(type)
double sumPassWeights() const
Log< level::Warning, true > LogPrint
std::vector< double > XERRUP
std::vector< double > XMAXUP
double filterEfficiency(int idwtup=+3) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double sumWeights() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double filterEfficiencyError(int idwtup=+3) const
unsigned int numEventsPassed() const
unsigned int numPassPositiveEvents() const
edm::EDGetTokenT< GenFilterInfo > genFilterInfoToken_
GenXSecAnalyzer(const edm::ParameterSet &)
std::vector< GenLumiInfoProduct::XSec > xsecAfterMatching_
~GenXSecAnalyzer() override
edm::EDGetTokenT< LHERunInfoProduct > lheRunInfoToken_
std::vector< double > XSECUP
unsigned int numEventsTotal() const
std::map< int, GenLumiInfoProduct::XSec > currentLumiBlockLHEXSec_
std::shared_ptr< gxsec::RunCache > globalBeginRun(edm::Run const &, edm::EventSetup const &) const final
GenFilterInfo hepMCFilterEffRun_
Power< A, B >::type pow(const A &a, const B &b)
GenLumiInfoProduct::XSec xsecPreFilter_
std::map< int, GenLumiInfoProduct::XSec > previousLumiBlockLHEXSec_