ATLAS Offline Software
Loading...
Searching...
No Matches
python.MGC.ParamCard Class Reference
Collaboration diagram for python.MGC.ParamCard:

Public Member Functions

 __init__ (self, param_card_input=None, param_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, output_location=None)
 read_paramCard (self)
 read_decayParams (self, cardloc=None)
 modify_paramCardDict (self, params={})
 write_paramCard (self, output_location=None)

Public Attributes

str paramCard_loc = process_dir+'/Cards/param_card.dat'
str paramCard_default_loc = param_card_backup
 output_location = output_location
 process_dir = process_dir
dict paramCardDict = {}

Static Protected Member Functions

 _block_name (line)

Detailed Description

Definition at line 714 of file MGC.py.

Constructor & Destructor Documentation

◆ __init__()

python.MGC.ParamCard.__init__ ( self,
param_card_input = None,
param_card_backup = None,
process_dir = MADGRAPH_GRIDPACK_LOCATION,
output_location = None )

Definition at line 715 of file MGC.py.

715 def __init__(self, param_card_input=None, param_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION,output_location=None):
716
717 if param_card_input is None:
718 self.paramCard_loc = process_dir+'/Cards/param_card.dat'
719 else:
720 self.paramCard_loc = param_card_input
721
722
723
724 self.paramCard_default_loc = param_card_backup
725 self.output_location = output_location
726 self.process_dir = process_dir
727
728 #read in the paramCard and store as a dictionary
729 self.read_paramCard()
730

Member Function Documentation

◆ _block_name()

python.MGC.ParamCard._block_name ( line)
staticprotected

Definition at line 732 of file MGC.py.

732 def _block_name(line):
733 # Comments and scale qualifiers are not part of the block name.
734 # QNUMBERS blocks must remain distinct for each particle.
735 fields = line.partition('#')[0].split()
736 if fields[1].lower() == 'qnumbers':
737 return ' '.join(fields[1:3])
738 return fields[1]
739
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ modify_paramCardDict()

python.MGC.ParamCard.modify_paramCardDict ( self,
params = {} )
 Simple function to update the paramCardDictionary that uses nested dictionaries.
The input params should also be a set of nested dictionaries

Definition at line 803 of file MGC.py.

803 def modify_paramCardDict(self,params={}):
804 """ Simple function to update the paramCardDictionary that uses nested dictionaries.
805 The input params should also be a set of nested dictionaries
806 """
807
808 dict_lower = [v.lower() for v in self.paramCardDict]
809 for block in params: #for each block in the params dictionary
810 if block.strip().lower() in dict_lower:# if the block is found
811 # need to make this case-insensitive
812 for value in self.paramCardDict:
813 if block.strip().lower() == value.strip().lower():
814 name = value
815
816 for key in params[block]: #look at each key in the block sub-dictionary
817 k = key.strip()
818 if k in self.paramCardDict[name]: # if the key is in the paramCardDict block then update it
819 self.paramCardDict[name][key] = params[block][key]
820 elif len(k.split(' ',1)) > 1:
821 new_k = k.split(' ',1)[0].strip() + ' ' + k.split(' ',1)[1].strip()
822 if new_k in self.paramCardDict[name]:
823 self.paramCardDict[name][new_k] = params[block][key]
824 else:
825 mglog.warning("Looks like the parameter "+str(block)+" : "+str(key)+" isn't in the parameter card dictionary. Adding now!")
826 self.paramCardDict[name][new_k] = params[block][key]
827 else:
828 # if we can't find it we may be trying to update the parameter based on the name, not the block number
829 for value in self.paramCardDict[name]:
830 found = False
831 if '# '+str(key)+' ' in str(self.paramCardDict[str(name)][str(value)]): # look at the values for each element in the sub-dictionary
832 self.paramCardDict[name][value] = params[block][key] # if we find the key in the value, we will update that value
833 found = True
834 continue
835 if not found: # if we can't find that value, we will add a new one
836 mglog.warning("Looks like the parameter "+str(block)+" : "+str(key)+" isn't in the parameter card dictionary. Adding now!")
837 self.paramCardDict[name][key] = params[block][key]
838
839 else:# if the block is not in the paramCardDict, we will add the whole block
840 self.paramCardDict[block] = params[block]
841
842

◆ read_decayParams()

python.MGC.ParamCard.read_decayParams ( self,
cardloc = None )
Read each width together with its branching-ratio table.

Definition at line 773 of file MGC.py.

773 def read_decayParams(self, cardloc=None):
774 """Read each width together with its branching-ratio table."""
775 if cardloc is None:
776 if os.access(self.paramCard_loc, os.R_OK):
777 cardloc = self.paramCard_loc
778 elif self.paramCard_default_loc is not None and os.access(self.paramCard_default_loc, os.R_OK):
779 cardloc = self.paramCard_default_loc
780 else:
781 raise RuntimeError('Cannot find parameter card for reading DECAY parameters: %s' % self.paramCard_loc)
782
783 decays = {}
784 key = None
785 with open(cardloc) as card:
786 for line in card:
787 stripped = line.strip()
788 columns = stripped.partition('#')[0].split()
789 if not columns:
790 continue
791 if columns[0].lower() == 'decay':
792 key = columns[1]
793 decays[key] = stripped
794 elif columns[0].lower() == 'block':
795 key = None
796 elif key is not None:
797 decays[key] += '\n' + stripped
798
799 if decays:
800 self.paramCardDict['DECAY'] = decays
801 mglog.info('Successfully read in Decay parameters')
802

◆ read_paramCard()

python.MGC.ParamCard.read_paramCard ( self)

Definition at line 740 of file MGC.py.

740 def read_paramCard(self):
741 if os.access(self.paramCard_loc, os.R_OK):
742 param_card = self.paramCard_loc
743 elif self.paramCard_default_loc is not None and os.access(self.paramCard_default_loc, os.R_OK):
744 param_card = self.paramCard_default_loc
745 else:
746 raise RuntimeError('Cannot find param_card.dat or param_card_default.dat! I was looking here: %s' % self.paramCard_loc)
747
748 mglog.info('Copying default param card from ' + str(param_card))
749 self.paramCardDict = {}
750 name = None
751 with open(param_card) as card:
752 for line in card:
753 data, separator, comment = line.strip().partition('#')
754 columns = data.split()
755 if not columns:
756 continue
757 if columns[0].lower() == 'block':
758 name = self._block_name(line)
759 self.paramCardDict[name] = {}
760 elif columns[0].lower() == 'decay':
761 # Branching ratios belong to the decay, never to the
762 # preceding ordinary block (often YUKAWA).
763 name = None
764 elif name is not None and len(columns) >= 2:
765 key, value = ' '.join(columns[:-1]), columns[-1]
766 if separator:
767 value += ' # ' + comment.strip() + ' '
768 self.paramCardDict[name][key] = value
769
770 self.read_decayParams(cardloc=param_card)
771 mglog.info('Successfully read param_card.dat as a dictionary paramCardDict')
772

◆ write_paramCard()

python.MGC.ParamCard.write_paramCard ( self,
output_location = None )
Write the updated card, preserving section headers and comments.

Only BLOCK and DECAY headers delimit sections; empty lines do not.
Decay dictionary values already contain their header and branching
ratios, so they must not be written as ordinary key/value entries.

Definition at line 843 of file MGC.py.

843 def write_paramCard(self, output_location=None):
844 """Write the updated card, preserving section headers and comments.
845
846 Only BLOCK and DECAY headers delimit sections; empty lines do not.
847 Decay dictionary values already contain their header and branching
848 ratios, so they must not be written as ordinary key/value entries.
849 """
850 if self.paramCard_default_loc is None or not os.path.isfile(self.paramCard_default_loc):
851 self.paramCard_default_loc = self.paramCard_loc + '.old_to_be_deleted'
852 os.rename(self.paramCard_loc, self.paramCard_default_loc)
853
854 with open(self.paramCard_default_loc) as card:
855 lines = card.readlines()
856
857 block_names = {name.lower(): name for name in self.paramCardDict}
858 written = {name: set() for name in self.paramCardDict}
859 output = self.paramCard_loc if output_location is None else output_location
860 with open(output, 'w') as newCard:
861 def write_entry(name, key):
862 value = self.paramCardDict[name][key]
863 if name.lower() == 'decay':
864 newCard.write(str(value).rstrip() + '\n')
865 else:
866 newCard.write(f' {key} {value}\n')
867 written[name].add(key)
868
869 def finish_block(name):
870 if name is not None and name.lower() != 'decay':
871 for key in self.paramCardDict[name]:
872 if key not in written[name]:
873 write_entry(name, key)
874
875 name = None
876 for line in lines:
877 columns = line.partition('#')[0].split()
878 if not columns:
879 newCard.write(line.rstrip('\r\n') + '\n')
880 elif columns[0].lower() == 'block':
881 finish_block(name)
882 block = self._block_name(line)
883 if block.lower() not in block_names:
884 raise RuntimeError('Cannot find %s in paramCardDict' % block)
885 name = block_names[block.lower()]
886 newCard.write(line.rstrip() + '\n')
887 elif columns[0].lower() == 'decay':
888 finish_block(name)
889 name = block_names['decay']
890 key = columns[1]
891 if key not in written[name]:
892 write_entry(name, key)
893 elif name is None:
894 newCard.write(line.rstrip('\r\n') + '\n')
895 elif name.lower() != 'decay':
896 key = ' '.join(columns[:-1])
897 write_entry(name, key)
898 # Original branching-ratio rows have already been replaced
899 # by the complete DECAY entry above.
900 finish_block(name)
901
902 # Add newly requested blocks and decays only once, after processing
903 # all existing sections (decays need not be contiguous in SLHA).
904 for name, settings in self.paramCardDict.items():
905 missing = [key for key in settings if key not in written[name]]
906 if not missing:
907 continue
908 newCard.write('\n')
909 if name.lower() != 'decay':
910 newCard.write(f'Block {name}\n')
911 for key in missing:
912 write_entry(name, key)
913
914 mglog.info('Finished writing paramCardDict to ' + str(output))
STL class.
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55

Member Data Documentation

◆ output_location

python.MGC.ParamCard.output_location = output_location

Definition at line 725 of file MGC.py.

◆ paramCard_default_loc

python.MGC.ParamCard.paramCard_default_loc = param_card_backup

Definition at line 724 of file MGC.py.

◆ paramCard_loc

python.MGC.ParamCard.paramCard_loc = process_dir+'/Cards/param_card.dat'

Definition at line 718 of file MGC.py.

◆ paramCardDict

dict python.MGC.ParamCard.paramCardDict = {}

Definition at line 749 of file MGC.py.

◆ process_dir

python.MGC.ParamCard.process_dir = process_dir

Definition at line 726 of file MGC.py.


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