14 xsecPreFilter_(-1, -1),
17 filterOnlyEffRun_(0, 0, 0, 0, 0., 0., 0., 0.),
18 hepMCFilterEffRun_(0, 0, 0, 0, 0., 0., 0., 0.),
19 filterOnlyEffStat_(0, 0, 0, 0, 0., 0., 0., 0.),
20 hepMCFilterEffStat_(0, 0, 0, 0, 0., 0., 0., 0.) {
76 std::vector<GenLumiInfoProduct::ProcessInfo> theProcesses = genLumiInfo->
getProcessInfos();
78 unsigned int theProcesses_size = theProcesses.size();
83 if (theProcesses_size != 1) {
84 edm::LogError(
"GenXSecAnalyzer::endLuminosityBlock") <<
"Pure parton shower has thisProcessInfos size!=1";
89 for (
unsigned int ip = 0; ip < theProcesses_size; ip++) {
90 if (theProcesses[ip].lheXSec().
value() < 0) {
92 <<
"cross section of process " << ip <<
" value = " << theProcesses[ip].lheXSec().value();
117 for (
unsigned int ip = 0; ip < theProcesses_size; ip++) {
118 int id = theProcesses[ip].process();
123 double passw = temp_killed.
sum();
124 double passw2 = temp_killed.
sum2();
125 double totalw = temp_selected.
sum();
126 double totalw2 = temp_selected.
sum2();
128 theProcesses[ip].nPassNeg(),
129 theProcesses[ip].nTotalPos(),
130 theProcesses[ip].nTotalNeg(),
138 double currentValue = theProcesses[ip].lheXSec().value();
139 double currentError = theProcesses[ip].lheXSec().error();
146 if (currentValue != previousValue)
148 double xsec = y.
value();
159 y = theProcesses[ip].lheXSec();
176 for (
unsigned int iSize = 0; iSize < thisHeprup_.
XSECUP.size(); iSize++) {
179 << std::setw(14) <<
std::fixed << thisHeprup_.
LPRUP[iSize] << std::endl;
187 std::vector<GenLumiInfoProduct::ProcessInfo> newInfos;
192 temp.
setLheXSec(iter->second.value(), iter->second.error());
193 newInfos.push_back(temp);
201 double thisHepFilterEff = 1;
202 double thisHepFilterErr = 0;
207 if (thisHepFilterEff < 0) {
208 thisHepFilterEff = 1;
209 thisHepFilterErr = 0;
213 double thisGenFilterEff = 1;
214 double thisGenFilterErr = 0;
219 if (thisGenFilterEff < 0) {
220 thisGenFilterEff = 1;
221 thisGenFilterErr = 0;
224 double thisXsec = thisRunXSecPre.
value() > 0 ? thisHepFilterEff * thisGenFilterEff * thisRunXSecPre.
value() : 0;
226 thisRunXSecPre.
value() > 0
228 pow(thisHepFilterErr / thisHepFilterEff, 2) +
pow(thisGenFilterErr / thisGenFilterEff, 2))
237 const double& currentValue,
238 const double& currentError,
239 const double& currentWeight) {
240 if (finalValue <= 0) {
241 finalValue = currentValue;
242 finalError = currentError;
243 finalWeight += currentWeight;
245 double wgt1 = (finalError <= 0 || currentError <= 0) ? finalWeight : 1 / (finalError * finalError);
246 double wgt2 = (finalError <= 0 || currentError <= 0) ? currentWeight : 1 / (currentError * currentError);
247 double xsec = (wgt1 * finalValue + wgt2 * currentValue) / (wgt1 + wgt2);
248 double err = (finalError <= 0 || currentError <= 0) ? 0 : 1.0 /
std::sqrt(wgt1 + wgt2);
251 finalWeight += currentWeight;
259 const double& thisw) {
262 double thisValue = thisRunXSec.
value();
263 double thisError = thisRunXSec.
error();
264 combine(value, error, totalw, thisValue, thisError, thisw);
271 double sigSelSum = 0.0;
272 double err2SelSum = 0.0;
274 double err2Sum = 0.0;
276 std::vector<GenLumiInfoProduct::XSec> tempVector_before;
277 std::vector<GenLumiInfoProduct::XSec> tempVector_after;
281 for (
unsigned int ip = 0; ip < vectorSize; ip++) {
287 sigSelSum += hepxsec_value;
288 err2SelSum += hepxsec_error * hepxsec_error;
303 fracAcc = ntotal > 0 ? npass / ntotal : -1;
316 double sigmaFin = hepxsec_value * fracAcc;
325 double effp = ntotal_pos > 0 ? (double)proc.
nPassPos() / ntotal_pos : 0;
326 double effp_err2 = ntotal_pos > 0 ? (1 - effp) * effp / ntotal_pos : 0;
329 double effn = ntotal_neg > 0 ? (double)proc.
nPassNeg() / ntotal_neg : 0;
330 double effn_err2 = ntotal_neg > 0 ? (1 - effn) * effn / ntotal_neg : 0;
333 ? (ntotal_pos * ntotal_pos * effp_err2 + ntotal_neg * ntotal_neg * effn_err2) / ntotal / ntotal
343 double numerator = (passw2 * failw * failw + failw2 * passw * passw);
345 efferr2 = denominator > 0 ? numerator / denominator : 0;
349 double delta2Veto = efferr2 / fracAcc / fracAcc;
353 double sigma2Sum, sigma2Err;
354 sigma2Sum = hepxsec_value * hepxsec_value;
355 sigma2Err = hepxsec_error * hepxsec_error;
357 double delta2Sum = delta2Veto + sigma2Err / sigma2Sum;
358 relErr = (delta2Sum > 0.0 ?
std::sqrt(delta2Sum) : 0.0);
359 double deltaFin = sigmaFin * relErr;
365 err2Sum += deltaFin * deltaFin;
373 double xsec_after = sigSelSum * total_matcheff;
374 double xsecerr_after = (total_matcheff > 0 && sigSelSum > 0)
375 ? xsec_after *
sqrt(err2SelSum / sigSelSum / sigSelSum +
376 total_matcherr * total_matcherr / total_matcheff / total_matcheff)
380 tempVector_after.push_back(result);
390 <<
"------------------------------------" 392 <<
"GenXsecAnalyzer:" 394 <<
"------------------------------------";
397 edm::LogPrint(
"GenXSecAnalyzer") <<
"------------------------------------" 399 <<
"Cross-section summary not available" 401 <<
"------------------------------------";
406 double final_fract_neg_w = 0;
407 double final_fract_neg_w_unc = 0;
413 <<
"-----------------------------------------------------------------------------------------------------------" 414 "--------------------------------------------------------------- \n" 415 <<
"Overall cross-section summary \n" 416 <<
"-----------------------------------------------------------------------------------------------------------" 417 "---------------------------------------------------------------";
418 edm::LogPrint(
"GenXSecAnalyzer") <<
"Process\t\txsec_before [pb]\t\tpassed\tnposw\tnnegw\ttried\tnposw\tnnegw " 419 "\txsec_match [pb]\t\t\taccepted [%]\t event_eff [%]";
422 const unsigned last = sizeOfInfos - 1;
425 double jetmatch_eff = 0;
426 double jetmatch_err = 0;
427 double matching_eff = 1;
428 double matching_efferr = 1;
450 <<
"-------------------------------------------------------------------------------------------------------" 451 "------------------------------------------------------------------- ";
457 final_fract_neg_w_unc =
459 ? final_fract_neg_w * final_fract_neg_w / thisEventEffStat.
numEventsPassed() *
465 title[
i] = Form(
"%d", i);
468 edm::LogPrint(
"GenXSecAnalyzer") << title[
i] <<
"\t\t" << std::scientific << std::setprecision(3)
478 << (jetmatch_eff * 100) <<
" +/- " << (jetmatch_err * 100) <<
"\t" <<
std::fixed 488 <<
"-----------------------------------------------------------------------------------------------------------" 489 "---------------------------------------------------------------";
491 edm::LogPrint(
"GenXSecAnalyzer") <<
"Before matching: total cross section = " << std::scientific
495 edm::LogPrint(
"GenXSecAnalyzer") <<
"After matching: total cross section = " << std::scientific
499 edm::LogPrint(
"GenXSecAnalyzer") <<
"Matching efficiency = " <<
std::fixed << std::setprecision(1) << matching_eff
500 <<
" +/- " << matching_efferr <<
" [TO BE USED IN MCM]";
503 edm::LogPrint(
"GenXSecAnalyzer") <<
"Before Filter: total cross section = " << std::scientific
508 double hepMCFilter_eff = 1.0;
509 double hepMCFilter_err = 0.0;
513 edm::LogPrint(
"GenXSecAnalyzer") <<
"HepMC filter efficiency (taking into account weights)= " 517 <<
" = " << std::scientific << std::setprecision(3) << hepMCFilter_eff <<
" +- " 520 double hepMCFilter_event_total =
522 double hepMCFilter_event_pass =
524 double hepMCFilter_event_eff = hepMCFilter_event_total > 0 ? hepMCFilter_event_pass / hepMCFilter_event_total : 0;
525 double hepMCFilter_event_err =
526 hepMCFilter_event_total > 0
527 ?
sqrt((1 - hepMCFilter_event_eff) * hepMCFilter_event_eff / hepMCFilter_event_total)
529 edm::LogPrint(
"GenXSecAnalyzer") <<
"HepMC filter efficiency (event-level)= " 530 <<
"(" << hepMCFilter_event_pass <<
")" 532 <<
"(" << hepMCFilter_event_total <<
")" 533 <<
" = " << std::scientific << std::setprecision(3) << hepMCFilter_event_eff
534 <<
" +- " << hepMCFilter_event_err;
542 edm::LogPrint(
"GenXSecAnalyzer") <<
"Filter efficiency (taking into account weights)= " 546 <<
" = " << std::scientific << std::setprecision(3) << filterOnly_eff <<
" +- " 549 double filterOnly_event_total =
551 double filterOnly_event_pass =
553 double filterOnly_event_eff = filterOnly_event_total > 0 ? filterOnly_event_pass / filterOnly_event_total : 0;
554 double filterOnly_event_err = filterOnly_event_total > 0
555 ?
sqrt((1 - filterOnly_event_eff) * filterOnly_event_eff / filterOnly_event_total)
557 edm::LogPrint(
"GenXSecAnalyzer") <<
"Filter efficiency (event-level)= " 558 <<
"(" << filterOnly_event_pass <<
")" 560 <<
"(" << filterOnly_event_total <<
")" 561 <<
" = " << std::scientific << std::setprecision(3) << filterOnly_event_eff
562 <<
" +- " << filterOnly_event_err <<
" [TO BE USED IN MCM]";
567 final_fract_neg_w_unc =
569 ? final_fract_neg_w * final_fract_neg_w / filterOnly_event_pass *
576 edm::LogPrint(
"GenXSecAnalyzer") <<
"\nAfter filter: final cross section = " << std::scientific
579 edm::LogPrint(
"GenXSecAnalyzer") <<
"After filter: final fraction of events with negative weights = " 580 << std::scientific << std::setprecision(3) << final_fract_neg_w <<
" +- " 581 << final_fract_neg_w_unc;
584 double lumi_1M_evts =
585 xsec_.
value() > 0 ? 1e6 * (1 - 2 * final_fract_neg_w) * (1 - 2 * final_fract_neg_w) /
xsec_.
value() / 1
e3 : 0;
586 double lumi_1M_evts_unc =
587 xsec_.
value() > 0 ? (1 - 2 * final_fract_neg_w) * lumi_1M_evts *
588 sqrt(1
e-6 + 16 *
pow(final_fract_neg_w_unc, 2) /
pow(1 - 2 * final_fract_neg_w, 2) +
591 edm::LogPrint(
"GenXSecAnalyzer") <<
"After filter: final equivalent lumi for 1M events (1/fb) = " << std::scientific
592 << std::setprecision(3) << lumi_1M_evts <<
" +- " << lumi_1M_evts_unc;
std::vector< GenLumiInfoProduct::XSec > xsecBeforeMatching_
const std::vector< ProcessInfo > & getProcessInfos() const
std::map< int, GenFilterInfo > jetMatchEffStat_
unsigned int nTotalNeg() const
void combine(GenLumiInfoProduct::XSec &, double &, const GenLumiInfoProduct::XSec &, const double &)
edm::EDGetTokenT< GenFilterInfo > hepMCFilterInfoToken_
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
unsigned int numTotalPositiveEvents() const
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double filterEfficiency(int idwtup=+3) const
GenFilterInfo filterOnlyEffStat_
edm::EDGetTokenT< GenLumiInfoProduct > genLumiInfoToken_
unsigned int nPassPos() const
std::map< int, GenLumiInfoProduct::XSec > currentLumiBlockLHEXSec_
const lhef::HEPRUP & heprup() const
GenLumiInfoProduct::XSec xsec_
GenFilterInfo hepMCFilterEffRun_
GenFilterInfo hepMCFilterEffStat_
unsigned int nPassNeg() const
bool mergeProduct(GenFilterInfo const &other)
double sumPassWeights() const
unsigned int numEventsPassed() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginRun(edm::Run const &, edm::EventSetup const &) override
GenLumiInfoProduct::XSec compute(const GenLumiInfoProduct &)
unsigned int numTotalNegativeEvents() const
std::vector< double > XERRUP
unsigned int numEventsTotal() const
std::map< int, GenLumiInfoProduct::XSec > previousLumiBlockLHEXSec_
std::vector< double > XMAXUP
double filterEfficiencyError(int idwtup=+3) const
virtual bool mergeProduct(const GenLumiInfoProduct &other)
unsigned int numPassPositiveEvents() const
void setLheXSec(double value, double err)
double sumWeights2() const
GenFilterInfo filterOnlyEffRun_
FinalStat selected() const
edm::EDGetTokenT< GenFilterInfo > genFilterInfoToken_
GenXSecAnalyzer(const edm::ParameterSet &)
std::vector< GenLumiInfoProduct::XSec > xsecAfterMatching_
~GenXSecAnalyzer() override
void endRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< LHERunInfoProduct > lheRunInfoToken_
std::vector< double > XSECUP
unsigned int nTotalPos() const
double sumWeights() const
Power< A, B >::type pow(const A &a, const B &b)
void setProcessInfo(const std::vector< ProcessInfo > &processes)
GenLumiInfoProduct::XSec xsecPreFilter_
GenLumiInfoProduct product_
const int getHEPIDWTUP() const
unsigned int numPassNegativeEvents() const