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());
302 std::vector<GenLumiInfoProduct::ProcessInfo> newInfos;
303 for (std::map<int, GenLumiInfoProduct::XSec>::const_iterator iter = runC->currentLumiBlockLHEXSec_.begin();
304 iter != runC->currentLumiBlockLHEXSec_.end();
307 temp.setLheXSec(iter->second.value(), iter->second.error());
308 newInfos.push_back(
temp);
310 runC->product_.setProcessInfo(newInfos);
316 double thisHepFilterEff = 1;
317 double thisHepFilterErr = 0;
319 if (runC->hepMCFilterEffRun_.sumWeights2() > 0) {
320 thisHepFilterEff = runC->hepMCFilterEffRun_.filterEfficiency(
hepidwtup_);
321 thisHepFilterErr = runC->hepMCFilterEffRun_.filterEfficiencyError(
hepidwtup_);
322 if (thisHepFilterEff < 0) {
323 thisHepFilterEff = 1;
324 thisHepFilterErr = 0;
328 double thisGenFilterEff = 1;
329 double thisGenFilterErr = 0;
331 if (runC->filterOnlyEffRun_.sumWeights2() > 0) {
332 thisGenFilterEff = runC->filterOnlyEffRun_.filterEfficiency(
hepidwtup_);
333 thisGenFilterErr = runC->filterOnlyEffRun_.filterEfficiencyError(
hepidwtup_);
334 if (thisGenFilterEff < 0) {
335 thisGenFilterEff = 1;
336 thisGenFilterErr = 0;
339 double thisXsec = thisRunXSecPre.
value() > 0 ? thisHepFilterEff * thisGenFilterEff * thisRunXSecPre.
value() : 0;
341 thisRunXSecPre.
value() > 0
343 pow(thisHepFilterErr / thisHepFilterEff, 2) +
pow(thisGenFilterErr / thisGenFilterEff, 2))
352 const double ¤tValue,
353 const double ¤tError,
354 const double ¤tWeight)
const {
355 if (finalValue <= 0) {
356 finalValue = currentValue;
357 finalError = currentError;
358 finalWeight += currentWeight;
360 double wgt1 = (finalError <= 0 || currentError <= 0) ? finalWeight : 1 / (finalError * finalError);
361 double wgt2 = (finalError <= 0 || currentError <= 0) ? currentWeight : 1 / (currentError * currentError);
362 double xsec = (wgt1 * finalValue + wgt2 * currentValue) / (wgt1 + wgt2);
363 double err = (finalError <= 0 || currentError <= 0) ? 0 : 1.0 /
std::sqrt(wgt1 + wgt2);
366 finalWeight += currentWeight;
374 const double &thisw)
const {
377 double thisValue = thisRunXSec.
value();
378 double thisError = thisRunXSec.
error();
386 double sigSelSum = 0.0;
387 double err2SelSum = 0.0;
389 std::vector<GenLumiInfoProduct::XSec> tempVector_before;
390 std::vector<GenLumiInfoProduct::XSec> tempVector_after;
394 for (
unsigned int ip = 0; ip < vectorSize; ip++) {
396 double hepxsec_value =
proc.lheXSec().value();
397 double hepxsec_error =
proc.lheXSec().error() <= 0 ? 0 :
proc.lheXSec().error();
400 sigSelSum += hepxsec_value;
401 err2SelSum += hepxsec_error * hepxsec_error;
404 if (
proc.killed().n() < 1) {
412 double npass =
proc.nPassPos() -
proc.nPassNeg();
419 fracAcc =
proc.selected().sum() > 0 ?
proc.killed().sum() /
proc.selected().sum() : -1;
429 double sigmaFin = hepxsec_value * fracAcc;
437 double ntotal_pos =
proc.nTotalPos();
438 double effp = ntotal_pos > 0 ? (double)
proc.nPassPos() / ntotal_pos : 0;
439 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
441 double ntotal_neg =
proc.nTotalNeg();
442 double effn = ntotal_neg > 0 ? (double)
proc.nPassNeg() / ntotal_neg : 0;
443 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
446 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) /
ntotal /
ntotal 452 double passw =
proc.killed().sum();
453 double passw2 =
proc.killed().sum2();
454 double failw =
proc.selected().sum() - passw;
455 double failw2 =
proc.selected().sum2() - passw2;
456 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
462 double delta2Veto = efferr2 / fracAcc / fracAcc;
466 double sigma2Sum, sigma2Err;
467 sigma2Sum = hepxsec_value * hepxsec_value;
468 sigma2Err = hepxsec_error * hepxsec_error;
470 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
471 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
472 double deltaFin = sigmaFin * relErr;
482 double xsec_after = sigSelSum * total_matcheff;
483 double xsecerr_after = (total_matcheff > 0 && sigSelSum > 0)
484 ? xsec_after *
sqrt(err2SelSum / sigSelSum / sigSelSum +
485 total_matcherr * total_matcherr / total_matcheff / total_matcheff)
489 tempVector_after.push_back(
result);
499 <<
"------------------------------------" 501 <<
"GenXsecAnalyzer:" 503 <<
"------------------------------------";
506 edm::LogPrint(
"GenXSecAnalyzer") <<
"------------------------------------" 508 <<
"Cross-section summary not available" 510 <<
"------------------------------------";
515 double final_fract_neg_w = 0;
516 double final_fract_neg_w_unc = 0;
522 <<
"-----------------------------------------------------------------------------------------------------------" 523 "--------------------------------------------------------------- \n" 524 <<
"Overall cross-section summary \n" 525 <<
"-----------------------------------------------------------------------------------------------------------" 526 "---------------------------------------------------------------";
527 edm::LogPrint(
"GenXSecAnalyzer") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw " 528 "\txsec_match [pb]\t\t\taccepted [%]\t event_eff [%]";
531 const unsigned last = sizeOfInfos - 1;
534 double jetmatch_eff = 0;
535 double jetmatch_err = 0;
536 double matching_eff = 1;
537 double matching_efferr = 1;
559 <<
"-------------------------------------------------------------------------------------------------------" 560 "------------------------------------------------------------------- ";
566 final_fract_neg_w_unc =
568 ? final_fract_neg_w * final_fract_neg_w / thisEventEffStat.
numEventsPassed() *
577 edm::LogPrint(
"GenXSecAnalyzer") <<
title[
i] <<
"\t\t" << std::scientific << std::setprecision(3)
587 << (jetmatch_eff * 100) <<
" +/- " << (jetmatch_err * 100) <<
"\t" <<
std::fixed 597 <<
"-----------------------------------------------------------------------------------------------------------" 598 "---------------------------------------------------------------";
600 edm::LogPrint(
"GenXSecAnalyzer") <<
"Before matching: total cross section = " << std::scientific
604 edm::LogPrint(
"GenXSecAnalyzer") <<
"After matching: total cross section = " << std::scientific
608 edm::LogPrint(
"GenXSecAnalyzer") <<
"Matching efficiency = " <<
std::fixed << std::setprecision(1) << matching_eff
609 <<
" +/- " << matching_efferr <<
" [TO BE USED IN MCM]";
612 edm::LogPrint(
"GenXSecAnalyzer") <<
"Before Filter: total cross section = " << std::scientific
617 double hepMCFilter_eff = 1.0;
618 double hepMCFilter_err = 0.0;
622 edm::LogPrint(
"GenXSecAnalyzer") <<
"HepMC filter efficiency (taking into account weights)= " 626 <<
" = " << std::scientific << std::setprecision(3) << hepMCFilter_eff <<
" +- " 629 double hepMCFilter_event_total =
631 double hepMCFilter_event_pass =
633 double hepMCFilter_event_eff = hepMCFilter_event_total > 0 ? hepMCFilter_event_pass / hepMCFilter_event_total : 0;
634 double hepMCFilter_event_err =
635 hepMCFilter_event_total > 0
636 ?
sqrt((1 - hepMCFilter_event_eff) * hepMCFilter_event_eff / hepMCFilter_event_total)
638 edm::LogPrint(
"GenXSecAnalyzer") <<
"HepMC filter efficiency (event-level)= " 639 <<
"(" << hepMCFilter_event_pass <<
")" 641 <<
"(" << hepMCFilter_event_total <<
")" 642 <<
" = " << std::scientific << std::setprecision(3) << hepMCFilter_event_eff
643 <<
" +- " << hepMCFilter_event_err;
651 edm::LogPrint(
"GenXSecAnalyzer") <<
"Filter efficiency (taking into account weights)= " 655 <<
" = " << std::scientific << std::setprecision(3) << filterOnly_eff <<
" +- " 658 double filterOnly_event_total =
660 double filterOnly_event_pass =
662 double filterOnly_event_eff = filterOnly_event_total > 0 ? filterOnly_event_pass / filterOnly_event_total : 0;
663 double filterOnly_event_err = filterOnly_event_total > 0
664 ?
sqrt((1 - filterOnly_event_eff) * filterOnly_event_eff / filterOnly_event_total)
666 edm::LogPrint(
"GenXSecAnalyzer") <<
"Filter efficiency (event-level)= " 667 <<
"(" << filterOnly_event_pass <<
")" 669 <<
"(" << filterOnly_event_total <<
")" 670 <<
" = " << std::scientific << std::setprecision(3) << filterOnly_event_eff
671 <<
" +- " << filterOnly_event_err <<
" [TO BE USED IN MCM]";
676 final_fract_neg_w_unc =
678 ? final_fract_neg_w * final_fract_neg_w / filterOnly_event_pass *
685 edm::LogPrint(
"GenXSecAnalyzer") <<
"\nAfter filter: final cross section = " << std::scientific
688 edm::LogPrint(
"GenXSecAnalyzer") <<
"After filter: final fraction of events with negative weights = " 689 << std::scientific << std::setprecision(3) << final_fract_neg_w <<
" +- " 690 << final_fract_neg_w_unc;
693 double lumi_1M_evts =
694 xsec_.
value() > 0 ? 1e6 * (1 - 2 * final_fract_neg_w) * (1 - 2 * final_fract_neg_w) /
xsec_.
value() / 1
e3 : 0;
695 double lumi_1M_evts_unc =
696 xsec_.
value() > 0 ? (1 - 2 * final_fract_neg_w) * lumi_1M_evts *
697 sqrt(1
e-6 + 16 *
pow(final_fract_neg_w_unc, 2) /
pow(1 - 2 * final_fract_neg_w, 2) +
700 edm::LogPrint(
"GenXSecAnalyzer") <<
"After filter: final equivalent lumi for 1M events (1/fb) = " << std::scientific
701 << 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_