ATLAS Offline Software
Loading...
Searching...
No Matches
python.AsgAnalysisConfig.GeneratorAnalysisBlock Class Reference
Inheritance diagram for python.AsgAnalysisConfig.GeneratorAnalysisBlock:
Collaboration diagram for python.AsgAnalysisConfig.GeneratorAnalysisBlock:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeAlgs (self, config)

Public Attributes

 runNumber = config.runNumber()
 saveCutBookkeepers
 histPattern
 detailedPDFinfo
 doPDFReweighting
 outPDFName
 doHFProdFracReweighting

Detailed Description

the ConfigBlock for generator algorithms

Definition at line 475 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.GeneratorAnalysisBlock.__init__ ( self)

Definition at line 478 of file AsgAnalysisConfig.py.

478 def __init__ (self) :
479 super().__init__ ()
480 self.addOption ('saveCutBookkeepers', True, type=bool,
481 info="whether to save the cut bookkeepers information into the "
482 "output file.")
483 self.addOption ('runNumber', None, type=int,
484 info="the MC `runNumber`. If left empty, autoconfigure from the sample metadata.")
485 self.addOption ('cutBookkeepersSystematics', None, type=bool,
486 info="whether to also save the cut bookkeepers systematics. The "
487 "default is `None` (follows the global systematics flag). Set to "
488 "`False` or `True` to override.")
489 self.addOption ('histPattern', None, type=str,
490 info="the histogram name pattern for the cut-bookkeeper histogram names.")
491 self.addOption ('streamName', None, type=str,
492 info="name of the output stream to save the cut bookkeeper in.")
493 self.addOption ('detailedPDFinfo', False, type=bool,
494 info="save the necessary information to run the LHAPDF tool offline.")
495 self.addOption ('doPDFReweighting', False, type=bool,
496 info="perform the PDF reweighting to do the PDF sensitivity studies with the existing sample, intrinsic charm PDFs as the default here. WARNING: the reweighting closure should be validated within analysis (it has been proved to be good for Madgraph, aMC@NLO, Pythia8, Herwig, and Alpgen, but not good for Sherpa and Powheg).")
497 self.addOption ('inPDFName', None, type=str, info="PDF set the input sample was produced with, for use in PDF reweighting")
498 self.addOption ('outPDFName', [
499 "CT14nnloIC/0", "CT14nnloIC/1", "CT14nnloIC/2",
500 "CT18FC/0", "CT18FC/3", "CT18FC/6", "CT18FC/9",
501 "CT18NNLO/0", "CT18XNNLO/0",
502 "NNPDF40_nnlo_pch_as_01180/0", "NNPDF40_nnlo_as_01180/0"
503 ], type=list, info="list of PDF sets to use for PDF reweighting.")
504 self.addOption ('doHFProdFracReweighting', False, type=bool,
505 info="whether to apply HF production fraction reweighting.")
506 self.addOption ('truthParticleContainer', 'TruthParticles', type=str,
507 info="the name of the truth particle container to use for HF production fraction reweighting.")
508

Member Function Documentation

◆ instanceName()

python.AsgAnalysisConfig.GeneratorAnalysisBlock.instanceName ( self)
Return the instance name for this block

Definition at line 509 of file AsgAnalysisConfig.py.

509 def instanceName (self) :
510 """Return the instance name for this block"""
511 return self.streamName or "DEFAULT"
512

◆ makeAlgs()

python.AsgAnalysisConfig.GeneratorAnalysisBlock.makeAlgs ( self,
config )

Definition at line 513 of file AsgAnalysisConfig.py.

513 def makeAlgs (self, config) :
514
515 if config.dataType() is DataType.Data:
516 # there are no generator weights in data!
517 return
518 log = logging.getLogger('GeneratorAnalysis')
519
520 # Setup stream name
521 streamName = self.streamName or config.defaultHistogramStream()
522
523 if self.runNumber is None:
524 self.runNumber = config.runNumber()
525
526 if self.saveCutBookkeepers and not self.runNumber:
527 raise ValueError ("invalid run number: " + str(self.runNumber))
528
529 # Set up the CutBookkeepers algorithm:
530 if self.saveCutBookkeepers:
531 alg = config.createAlgorithm('CP::AsgCutBookkeeperAlg', 'CutBookkeeperAlg')
532 alg.RootStreamName = streamName
533 alg.runNumber = self.runNumber
534 if self.cutBookkeepersSystematics is None:
535 alg.enableSystematics = not config.noSystematics()
536 else:
537 alg.enableSystematics = self.cutBookkeepersSystematics
538 if self.histPattern:
539 alg.histPattern = self.histPattern
540 config.addPrivateTool( 'truthWeightTool', 'PMGTools::PMGTruthWeightTool' )
541
542 # Set up the weights algorithm:
543 alg = config.createAlgorithm( 'CP::PMGTruthWeightAlg', 'PMGTruthWeightAlg' )
544 config.addPrivateTool( 'truthWeightTool', 'PMGTools::PMGTruthWeightTool' )
545 alg.decoration = 'generatorWeight_%SYS%'
546 config.addOutputVar ('EventInfo', 'generatorWeight_%SYS%', 'weight_mc')
547
548 if self.detailedPDFinfo:
549 alg = config.createAlgorithm( 'CP::PDFinfoAlg', 'PDFinfoAlg', reentrant=True )
550 for var in ["PDFID1","PDFID2","PDGID1","PDGID2","Q","X1","X2","XF1","XF2"]:
551 config.addOutputVar ('EventInfo', var, 'PDFinfo_' + var, noSys=True)
552
553 if self.doPDFReweighting:
554 generatorInfo = config.flags.Input.GeneratorsInfo
555 log.info(f"Loaded generator info: {generatorInfo}")
556
557 if not generatorInfo:
558 warnings.warn_explicit("No generator info found.", GeneratorWeightWarning, filename='', lineno=0)
559 elif isinstance(generatorInfo, dict):
560
561 unsupported_generators = {
562 "Sherpa": "PDF reweighting for Sherpa is not proven to be reliable. The reweighting closure should be validated within the analysis.",
563 "Powheg": "PDF reweighting for Powheg is not proven to be reliable. The reweighting closure should be validated within the analysis."
564 }
565
566 # Check for unsupported generators
567 for generator, message in unsupported_generators.items():
568 if generator in generatorInfo:
569 warnings.warn_explicit(
570 message,
571 GeneratorWeightWarning,
572 filename='',
573 lineno=0
574 )
575
576 alg = config.createAlgorithm( 'CP::PDFReweightAlg', 'PDFReweightAlg', reentrant=True )
577
578 if self.inPDFName is None:
579 log.error("Option inPDFName not specified, but is required for PDF reweighting. This means the PDF set the input dataset was generated with is determined as …")
580 else:
581 alg.inPDFName = self.inPDFName
582
583 alg.outPDFName = self.outPDFName
584
585 for pdf_set in self.outPDFName:
586 config.addOutputVar('EventInfo', f'PDFReweightSF_{pdf_set.replace("/", "_")}',
587 f'PDFReweightSF_{pdf_set.replace("/", "_")}', noSys=True, auxType='float')
588
589 if self.doHFProdFracReweighting:
590 generatorInfo = config.flags.Input.GeneratorsInfo
591 log.info(f"Loaded generator info: {generatorInfo}")
592
593 DSID = "000000"
594
595 if not generatorInfo:
596 warnings.warn_explicit(
597 "No generator info found.",
598 GeneratorWeightWarning, filename='', lineno=0)
599 DSID = "000000"
600 elif isinstance(generatorInfo, dict):
601 if "Pythia8" in generatorInfo:
602 DSID = "410470"
603 elif "Sherpa" in generatorInfo and "2.2.8" in generatorInfo["Sherpa"]:
604 DSID = "421152"
605 elif "Sherpa" in generatorInfo and "2.2.10" in generatorInfo["Sherpa"]:
606 DSID = "700122"
607 elif "Sherpa" in generatorInfo and "2.2.11" in generatorInfo["Sherpa"]:
608 warnings.warn_explicit(
609 "HF production fraction reweighting is not configured"
610 " for Sherpa 2.2.11. Using weights for Sherpa 2.2.10"
611 " instead.",
612 GeneratorWeightWarning, filename='', lineno=0)
613 DSID = "700122"
614 elif "Sherpa" in generatorInfo and "2.2.12" in generatorInfo["Sherpa"]:
615 warnings.warn_explicit(
616 "HF production fraction reweighting is not configured"
617 " for Sherpa 2.2.12. Using weights for Sherpa 2.2.10"
618 " instead.",
619 GeneratorWeightWarning, filename='', lineno=0)
620 DSID = "700122"
621 elif "Sherpa" in generatorInfo and "2.2.14" in generatorInfo["Sherpa"]:
622 warnings.warn_explicit(
623 "HF production fraction reweighting is not configured"
624 " for Sherpa 2.2.14. New weights need to be"
625 " calculated.",
626 GeneratorWeightWarning, filename='', lineno=0)
627 DSID = "000000"
628 elif "Sherpa" in generatorInfo and "2.2.1" in generatorInfo["Sherpa"]:
629 DSID = "410250"
630 elif "Herwig7" in generatorInfo and "7.1.3" in generatorInfo["Herwig7"]:
631 DSID = "411233"
632 elif "Herwig7" in generatorInfo and "7.2.1" in generatorInfo["Herwig7"]:
633 DSID = "600666"
634 elif "Herwig7" in generatorInfo and "7." in generatorInfo["Herwig7"]:
635 DSID = "410558"
636 elif "amc@NLO" in generatorInfo:
637 DSID = "410464"
638 else:
639 warnings.warn_explicit(
640 f"HF production fraction reweighting is not configured"
641 f" for this generator: {generatorInfo}."
642 f" New weights need to be calculated.",
643 GeneratorWeightWarning, filename='', lineno=0)
644 DSID = "000000"
645 else:
646 warnings.warn_explicit(
647 "Failed to determine generator from metadata",
648 GeneratorWeightWarning, filename='', lineno=0)
649 DSID = "000000"
650
651 log.info(f"Using HF production fraction weights calculated using DSID {DSID}")
652 if DSID == "000000":
653 warnings.warn_explicit(
654 "HF production fraction reweighting will return dummy"
655 " weights of 1.0",
656 GeneratorWeightWarning, filename='', lineno=0)
657
658 alg = config.createAlgorithm( 'CP::SysTruthWeightAlg', f'SysTruthWeightAlg_{streamName}' )
659 config.addPrivateTool( 'sysTruthWeightTool', 'PMGTools::PMGHFProductionFractionTool' )
660 alg.decoration = 'prodFracWeight_%SYS%'
661 alg.TruthParticleContainer = self.truthParticleContainer
662 alg.sysTruthWeightTool.ShowerGenerator = DSID
663 config.addOutputVar ('EventInfo', 'prodFracWeight_%SYS%', 'weight_HF_prod_frac')
664

Member Data Documentation

◆ detailedPDFinfo

python.AsgAnalysisConfig.GeneratorAnalysisBlock.detailedPDFinfo

Definition at line 548 of file AsgAnalysisConfig.py.

◆ doHFProdFracReweighting

python.AsgAnalysisConfig.GeneratorAnalysisBlock.doHFProdFracReweighting

Definition at line 589 of file AsgAnalysisConfig.py.

◆ doPDFReweighting

python.AsgAnalysisConfig.GeneratorAnalysisBlock.doPDFReweighting

Definition at line 553 of file AsgAnalysisConfig.py.

◆ histPattern

python.AsgAnalysisConfig.GeneratorAnalysisBlock.histPattern

Definition at line 538 of file AsgAnalysisConfig.py.

◆ outPDFName

python.AsgAnalysisConfig.GeneratorAnalysisBlock.outPDFName

Definition at line 585 of file AsgAnalysisConfig.py.

◆ runNumber

python.AsgAnalysisConfig.GeneratorAnalysisBlock.runNumber = config.runNumber()

Definition at line 524 of file AsgAnalysisConfig.py.

◆ saveCutBookkeepers

python.AsgAnalysisConfig.GeneratorAnalysisBlock.saveCutBookkeepers

Definition at line 530 of file AsgAnalysisConfig.py.


The documentation for this class was generated from the following file: