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 401 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.GeneratorAnalysisBlock.__init__ ( self)

Definition at line 404 of file AsgAnalysisConfig.py.

404 def __init__ (self) :
405 super (GeneratorAnalysisBlock, self).__init__ ()
406 self.addOption ('saveCutBookkeepers', True, type=bool,
407 info="whether to save the cut bookkeepers information into the "
408 "output file.")
409 self.addOption ('runNumber', None, type=int,
410 info="the MC `runNumber`. If left empty, autoconfigure from the sample metadata.")
411 self.addOption ('cutBookkeepersSystematics', None, type=bool,
412 info="whether to also save the cut bookkeepers systematics. The "
413 "default is `None` (follows the global systematics flag). Set to "
414 "`False` or `True` to override.")
415 self.addOption ('histPattern', None, type=str,
416 info="the histogram name pattern for the cut-bookkeeper histogram names.")
417 self.addOption ('streamName', None, type=str,
418 info="name of the output stream to save the cut bookkeeper in.")
419 self.addOption ('detailedPDFinfo', False, type=bool,
420 info="save the necessary information to run the LHAPDF tool offline.")
421 self.addOption ('doPDFReweighting', False, type=bool,
422 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).")
423 self.addOption ('inPDFName', None, type=str, info="PDF set the input sample was produced with, for use in PDF reweighting")
424 self.addOption ('outPDFName', [
425 "CT14nnloIC/0", "CT14nnloIC/1", "CT14nnloIC/2",
426 "CT18FC/0", "CT18FC/3", "CT18FC/6", "CT18FC/9",
427 "CT18NNLO/0", "CT18XNNLO/0",
428 "NNPDF40_nnlo_pch_as_01180/0", "NNPDF40_nnlo_as_01180/0"
429 ], type=list, info="list of PDF sets to use for PDF reweighting.")
430 self.addOption ('doHFProdFracReweighting', False, type=bool,
431 info="whether to apply HF production fraction reweighting.")
432 self.addOption ('truthParticleContainer', 'TruthParticles', type=str,
433 info="the name of the truth particle container to use for HF production fraction reweighting.")
434

Member Function Documentation

◆ instanceName()

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

Definition at line 435 of file AsgAnalysisConfig.py.

435 def instanceName (self) :
436 """Return the instance name for this block"""
437 return self.streamName or "DEFAULT"
438

◆ makeAlgs()

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

Definition at line 439 of file AsgAnalysisConfig.py.

439 def makeAlgs (self, config) :
440
441 if config.dataType() is DataType.Data:
442 # there are no generator weights in data!
443 return
444 log = logging.getLogger('GeneratorAnalysis')
445
446 # Setup stream name
447 streamName = self.streamName or config.defaultHistogramStream()
448
449 if self.runNumber is None:
450 self.runNumber = config.runNumber()
451
452 if self.saveCutBookkeepers and not self.runNumber:
453 raise ValueError ("invalid run number: " + str(self.runNumber))
454
455 # Set up the CutBookkeepers algorithm:
456 if self.saveCutBookkeepers:
457 alg = config.createAlgorithm('CP::AsgCutBookkeeperAlg', 'CutBookkeeperAlg')
458 alg.RootStreamName = streamName
459 alg.runNumber = self.runNumber
460 if self.cutBookkeepersSystematics is None:
461 alg.enableSystematics = not config.noSystematics()
462 else:
463 alg.enableSystematics = self.cutBookkeepersSystematics
464 if self.histPattern:
465 alg.histPattern = self.histPattern
466 config.addPrivateTool( 'truthWeightTool', 'PMGTools::PMGTruthWeightTool' )
467
468 # Set up the weights algorithm:
469 alg = config.createAlgorithm( 'CP::PMGTruthWeightAlg', 'PMGTruthWeightAlg' )
470 config.addPrivateTool( 'truthWeightTool', 'PMGTools::PMGTruthWeightTool' )
471 alg.decoration = 'generatorWeight_%SYS%'
472 config.addOutputVar ('EventInfo', 'generatorWeight_%SYS%', 'weight_mc')
473
474 if self.detailedPDFinfo:
475 alg = config.createAlgorithm( 'CP::PDFinfoAlg', 'PDFinfoAlg', reentrant=True )
476 for var in ["PDFID1","PDFID2","PDGID1","PDGID2","Q","X1","X2","XF1","XF2"]:
477 config.addOutputVar ('EventInfo', var, 'PDFinfo_' + var, noSys=True)
478
479 if self.doPDFReweighting:
480 generatorInfo = config.flags.Input.GeneratorsInfo
481 log.info(f"Loaded generator info: {generatorInfo}")
482
483 if not generatorInfo:
484 warnings.warn_explicit("No generator info found.", GeneratorWeightWarning, filename='', lineno=0)
485 elif isinstance(generatorInfo, dict):
486
487 unsupported_generators = {
488 "Sherpa": "PDF reweighting for Sherpa is not proven to be reliable. The reweighting closure should be validated within the analysis.",
489 "Powheg": "PDF reweighting for Powheg is not proven to be reliable. The reweighting closure should be validated within the analysis."
490 }
491
492 # Check for unsupported generators
493 for generator, message in unsupported_generators.items():
494 if generator in generatorInfo:
495 warnings.warn_explicit(
496 message,
497 GeneratorWeightWarning,
498 filename='',
499 lineno=0
500 )
501
502 alg = config.createAlgorithm( 'CP::PDFReweightAlg', 'PDFReweightAlg', reentrant=True )
503
504 if self.inPDFName is None:
505 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 …")
506 else:
507 alg.inPDFName = self.inPDFName
508
509 alg.outPDFName = self.outPDFName
510
511 for pdf_set in self.outPDFName:
512 config.addOutputVar('EventInfo', f'PDFReweightSF_{pdf_set.replace("/", "_")}',
513 f'PDFReweightSF_{pdf_set.replace("/", "_")}', noSys=True, auxType='float')
514
515
516 if self.doHFProdFracReweighting:
517 generatorInfo = config.flags.Input.GeneratorsInfo
518 log.info(f"Loaded generator info: {generatorInfo}")
519
520 DSID = "000000"
521
522 if not generatorInfo:
523 warnings.warn_explicit(
524 "No generator info found.",
525 GeneratorWeightWarning, filename='', lineno=0)
526 DSID = "000000"
527 elif isinstance(generatorInfo, dict):
528 if "Pythia8" in generatorInfo:
529 DSID = "410470"
530 elif "Sherpa" in generatorInfo and "2.2.8" in generatorInfo["Sherpa"]:
531 DSID = "421152"
532 elif "Sherpa" in generatorInfo and "2.2.10" in generatorInfo["Sherpa"]:
533 DSID = "700122"
534 elif "Sherpa" in generatorInfo and "2.2.11" in generatorInfo["Sherpa"]:
535 warnings.warn_explicit(
536 "HF production fraction reweighting is not configured"
537 " for Sherpa 2.2.11. Using weights for Sherpa 2.2.10"
538 " instead.",
539 GeneratorWeightWarning, filename='', lineno=0)
540 DSID = "700122"
541 elif "Sherpa" in generatorInfo and "2.2.12" in generatorInfo["Sherpa"]:
542 warnings.warn_explicit(
543 "HF production fraction reweighting is not configured"
544 " for Sherpa 2.2.12. Using weights for Sherpa 2.2.10"
545 " instead.",
546 GeneratorWeightWarning, filename='', lineno=0)
547 DSID = "700122"
548 elif "Sherpa" in generatorInfo and "2.2.14" in generatorInfo["Sherpa"]:
549 warnings.warn_explicit(
550 "HF production fraction reweighting is not configured"
551 " for Sherpa 2.2.14. New weights need to be"
552 " calculated.",
553 GeneratorWeightWarning, filename='', lineno=0)
554 DSID = "000000"
555 elif "Sherpa" in generatorInfo and "2.2.1" in generatorInfo["Sherpa"]:
556 DSID = "410250"
557 elif "Herwig7" in generatorInfo and "7.1.3" in generatorInfo["Herwig7"]:
558 DSID = "411233"
559 elif "Herwig7" in generatorInfo and "7.2.1" in generatorInfo["Herwig7"]:
560 DSID = "600666"
561 elif "Herwig7" in generatorInfo and "7." in generatorInfo["Herwig7"]:
562 DSID = "410558"
563 elif "amc@NLO" in generatorInfo:
564 DSID = "410464"
565 else:
566 warnings.warn_explicit(
567 f"HF production fraction reweighting is not configured"
568 f" for this generator: {generatorInfo}."
569 f" New weights need to be calculated.",
570 GeneratorWeightWarning, filename='', lineno=0)
571 DSID = "000000"
572 else:
573 warnings.warn_explicit(
574 "Failed to determine generator from metadata",
575 GeneratorWeightWarning, filename='', lineno=0)
576 DSID = "000000"
577
578 log.info(f"Using HF production fraction weights calculated using DSID {DSID}")
579 if DSID == "000000":
580 warnings.warn_explicit(
581 "HF production fraction reweighting will return dummy"
582 " weights of 1.0",
583 GeneratorWeightWarning, filename='', lineno=0)
584
585 alg = config.createAlgorithm( 'CP::SysTruthWeightAlg', f'SysTruthWeightAlg_{streamName}' )
586 config.addPrivateTool( 'sysTruthWeightTool', 'PMGTools::PMGHFProductionFractionTool' )
587 alg.decoration = 'prodFracWeight_%SYS%'
588 alg.TruthParticleContainer = self.truthParticleContainer
589 alg.sysTruthWeightTool.ShowerGenerator = DSID
590 config.addOutputVar ('EventInfo', 'prodFracWeight_%SYS%', 'weight_HF_prod_frac')
591

Member Data Documentation

◆ detailedPDFinfo

python.AsgAnalysisConfig.GeneratorAnalysisBlock.detailedPDFinfo

Definition at line 474 of file AsgAnalysisConfig.py.

◆ doHFProdFracReweighting

python.AsgAnalysisConfig.GeneratorAnalysisBlock.doHFProdFracReweighting

Definition at line 516 of file AsgAnalysisConfig.py.

◆ doPDFReweighting

python.AsgAnalysisConfig.GeneratorAnalysisBlock.doPDFReweighting

Definition at line 479 of file AsgAnalysisConfig.py.

◆ histPattern

python.AsgAnalysisConfig.GeneratorAnalysisBlock.histPattern

Definition at line 464 of file AsgAnalysisConfig.py.

◆ outPDFName

python.AsgAnalysisConfig.GeneratorAnalysisBlock.outPDFName

Definition at line 511 of file AsgAnalysisConfig.py.

◆ runNumber

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

Definition at line 450 of file AsgAnalysisConfig.py.

◆ saveCutBookkeepers

python.AsgAnalysisConfig.GeneratorAnalysisBlock.saveCutBookkeepers

Definition at line 456 of file AsgAnalysisConfig.py.


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