ATLAS Offline Software
Functions | Variables
CombineRootAndConfigFilesAfterReduction Namespace Reference

Functions

def GetKeyNames (self, dir="")
 
def CombineRootFiles (fullFileName, reducedFileName, combinedFileName)
 
def readSanitizedLine (file)
 
def sanitizeComponentName (aName)
 
def getDescFromName (aName)
 
def getCategoryFromName (aName)
 
def checkIfWasCategoryReduction (listOfNames)
 
def replaceComponentNumber (line, newNumber)
 
def CombineConfigFiles (fullFileName, combinedFileName, combinedRootFileName, componentNames)
 

Variables

 sharePath = sys.argv[1]
 
 fullConfigFile = sys.argv[2]
 
 fullRootFile = sys.argv[3]
 
 reducedRootFile = sys.argv[4]
 
 outConfigFile = sys.argv[5]
 
 outRootFile = sys.argv[6]
 
 GetKeyNames
 
def compNames = CombineRootFiles(sharePath+"/"+fullRootFile,reducedRootFile,sharePath+"/"+outRootFile)
 

Function Documentation

◆ checkIfWasCategoryReduction()

def CombineRootAndConfigFilesAfterReduction.checkIfWasCategoryReduction (   listOfNames)

Definition at line 126 of file CombineRootAndConfigFilesAfterReduction.py.

126 def checkIfWasCategoryReduction(listOfNames):
127  for aName in listOfNames:
128  if "Stat" in aName:
129  return True
130  elif "Detector" in aName:
131  return True
132  elif "Model" in aName:
133  return True
134  elif "Mixed" in aName:
135  return True
136  return False
137 

◆ CombineConfigFiles()

def CombineRootAndConfigFilesAfterReduction.CombineConfigFiles (   fullFileName,
  combinedFileName,
  combinedRootFileName,
  componentNames 
)

Definition at line 144 of file CombineRootAndConfigFilesAfterReduction.py.

144 def CombineConfigFiles(fullFileName,combinedFileName,combinedRootFileName,componentNames):
145  print "Creating reduced config file..."
146 
147  # Open the input file for reading, output file for writing
148  inputFile = open(fullFileName,"r")
149  outputFile = open(combinedFileName,"w")
150 
151  # Determine the type of reduction (for the header)
152  reductionString = ""
153  if "GlobalReduction" in combinedFileName:
154  reductionString = "Reduction was applied globally"
155  elif "CategoryReduction" in combinedFileName:
156  reductionString = "Reduction was applied within each category"
157  else:
158  reductionString = "Unknown type of reduction"
159 
160  # Create the file header
161  now = datetime.datetime.now()
162  outputFile.write("\n#######################################\n#\n")
163  outputFile.write("# JESProvider Input Settings\n")
164  outputFile.write("# Reduced set of nuisance parameters from final 2011 iteration of the in-situ JES\n")
165  outputFile.write("# %s\n"%(reductionString))
166  #outputFile.write("# %s\n"%(fullFileName))
167  outputFile.write("# %s %d, %d\n#\n"%(calendar.month_name[now.month],now.day,now.year))
168  #outputFile.write("# \n") # AUTHORS HERE
169  outputFile.write("#\n#######################################\n\n")
170 
171  # Specify the root file that goes with the header
172  outputFile.write("JESUncertaintyRootFile: %s\n"%(combinedRootFileName))
173 
174  # Settings header
175  outputFile.write("\n#######################################\n#\n")
176  outputFile.write("# Settings for JES Components\n")
177  outputFile.write("#\n#######################################\n\n")
178 
179  # JES Components
180  # Parse the base names
181  compNamesSanitized = []
182  for aName in componentNames:
183  sanitizedName = sanitizeComponentName(aName)
184  if sanitizedName not in compNamesSanitized:
185  compNamesSanitized.append(sanitizedName)
186 
187  i=1
188  for aName in compNamesSanitized:
189  outputFile.write("JESComponent.%d.Desc: %s\n"%(i,getDescFromName(aName)))
190  outputFile.write("JESComponent.%d.Name: %s\n"%(i,aName))
191  outputFile.write("JESComponent.%d.Type: %s\n"%(i,getCategoryFromName(aName)))
192  outputFile.write("\n")
193  i = i + 1
194 
195  # Special components
196  # Currently, read from other config file
197  outputFile.write("\n#######################################\n\n")
198 
199  # Look for "Special" type components in the original file
200  # EOF returns an empty string
201  inputFile = open(fullFileName,"r")
202  nextLine = readSanitizedLine(inputFile)
203  currLine = ""
204  previousLine = ""
205  while (nextLine != ""):
206  if "Special" not in nextLine and "EtaIntercal" not in currLine:
207  # Not interesting (except for eta intercal), just iterate
208  previousLine = currLine
209  currLine = nextLine
210  nextLine = readSanitizedLine(inputFile)
211  else:
212  # Found a special component, so save it
213  outputFile.write(replaceComponentNumber(previousLine,i))
214  outputFile.write(replaceComponentNumber(currLine,i))
215  outputFile.write(replaceComponentNumber(nextLine,i))
216 
217  # Iterate
218  previousLine = currLine
219  currLine = nextLine
220  nextLine = readSanitizedLine(inputFile)
221 
222  # Check if sub-components or correlated sub-components
223  if ("SubComponent" in nextLine):
224  outputFile.write(replaceComponentNumber(nextLine,i))
225  previousLine = currLine
226  currLine = nextLine
227  nextLine = readSanitizedLine(inputFile)
228 
229  outputFile.write("\n")
230  i = i + 1
231 
232 
233  outputFile.write("\n#\n#######################################\n")
234 
235  # Done, close files
236  inputFile.close()
237  outputFile.close()
238  print "Created config file: %s\n"%(combinedFileName)
239 
240 # Main method here

◆ CombineRootFiles()

def CombineRootAndConfigFilesAfterReduction.CombineRootFiles (   fullFileName,
  reducedFileName,
  combinedFileName 
)

Definition at line 17 of file CombineRootAndConfigFilesAfterReduction.py.

17 def CombineRootFiles(fullFileName,reducedFileName,combinedFileName):
18  print "Creating reduced root file..."
19  print "Full file: " + fullFileName
20  print "Reduced file: " + reducedFileName
21  print "Output file: " + combinedFileName
22  AllNuisanceParametersFile = TFile.Open(fullFileName,"READ")
23  ReducedNuisanceParametersFile = TFile.Open(reducedFileName,"READ")
24  OutputFile = TFile.Open(combinedFileName,"RECREATE")
25 
26  for histName in AllNuisanceParametersFile.GetKeyNames():
27  hist = AllNuisanceParametersFile.Get(histName)
28  OutputFile.cd()
29  hist.Write(histName)
30 
31  reducedComponentNames = []
32  for histName in ReducedNuisanceParametersFile.GetKeyNames():
33  if "EffectiveNP_" in histName:
34  hist = ReducedNuisanceParametersFile.Get(histName)
35  OutputFile.cd()
36  hist.Write(histName)
37  reducedComponentNames.append(histName)
38 
39  ''' This method is no longer relevant due to Reduction changes, retained in case this changes
40 
41  for histName in ReducedNuisanceParametersFile.GetKeyNames():
42  hist = ReducedNuisanceParametersFile.Get(histName)
43  OutputFile.cd()
44  hist.Write(histName)
45  reducedComponentNames.append(histName)
46 
47  for histName in AllNuisanceParametersFile.GetKeyNames():
48  alreadyCopied = False
49  for aComponent in reducedComponentNames:
50  if histName in aComponent:
51  alreadyCopied = True
52  break
53  if not alreadyCopied:
54  hist = AllNuisanceParametersFile.Get(histName)
55  OutputFile.cd()
56  hist.Write(histName)
57  '''
58 
59  AllNuisanceParametersFile.Close()
60  ReducedNuisanceParametersFile.Close()
61  OutputFile.Close()
62 
63  return reducedComponentNames
64 
65 # Needed due to end of line differences between OS

◆ getCategoryFromName()

def CombineRootAndConfigFilesAfterReduction.getCategoryFromName (   aName)

Definition at line 105 of file CombineRootAndConfigFilesAfterReduction.py.

105 def getCategoryFromName(aName):
106  # Special for eta intercalibration components
107  if "etaintercalibration_totalstat" in aName.lower():
108  return "Statistical"
109  elif "etaintercalibration_modelling" in aName.lower():
110  return "Modelling"
111  elif "stat" in aName.lower():
112  return "Statistical"
113  elif "detector" in aName.lower():
114  return "Detector"
115  elif "model" in aName.lower():
116  return "Modelling"
117  elif "mixed" in aName.lower():
118  return "Mixed"
119  elif "special" in aName.lower():
120  return "Special"
121  elif "EffectiveNP_" in aName:
122  return "Special" # Global reduction parameters are of type "Special"
123  else:
124  return "UNKNOWN"
125 

◆ getDescFromName()

def CombineRootAndConfigFilesAfterReduction.getDescFromName (   aName)

Definition at line 81 of file CombineRootAndConfigFilesAfterReduction.py.

81 def getDescFromName(aName):
82  if "Stat" in aName:
83  return "Effective JES Statistical and Method Component %c"%(aName[-1])
84  elif "Detector" in aName:
85  return "Effective JES Detector Component %c"%(aName[-1])
86  elif "Model" in aName:
87  return "Effective JES Modelling Component %c"%(aName[-1])
88  elif "Mixed" in aName:
89  return "Effective JES Mixed Modelling and Detector Component %c"%(aName[-1])
90  elif "Special" in aName:
91  print "WARNING: Including a special component directly - %s"%(aName)
92  return "Effective JES Special Component %c"%(aName[-1])
93  elif "UNKNOWN" in aName:
94  print "WARNING: Including an unknown component - %s"%(aName)
95  return "Effecitve JES Unknown Category Component %c"%(aName[-1])
96  elif "EffectiveNP_" in aName:
97  if "restTerm" in aName:
98  return "Effective JES Uncertainty Component %c"%(aName[-9])
99  else:
100  return "Effective JES Uncertainty Component %c"%(aName[-1])
101  else:
102  print "ERROR: Including an unrecognized component"
103  exit(1)
104 

◆ GetKeyNames()

def CombineRootAndConfigFilesAfterReduction.GetKeyNames (   self,
  dir = "" 
)

Definition at line 11 of file CombineRootAndConfigFilesAfterReduction.py.

11 def GetKeyNames(self,dir=""):
12  self.cd(dir)
13  return [key.GetName() for key in gDirectory.GetListOfKeys()]
14 
15 #Copy everything from the reduced file to the output file
16 #Copy everything excluding any overlap with the reduced file from the full file to the output file

◆ readSanitizedLine()

def CombineRootAndConfigFilesAfterReduction.readSanitizedLine (   file)

Definition at line 66 of file CombineRootAndConfigFilesAfterReduction.py.

66 def readSanitizedLine(file):
67  line = file.readline()
68  sanitizedLine = re.sub('\r','',line)
69 # line = re.sub('\n','',sanitizedLine)
70 # sanitizedLine = line+"\n\r"
71  return sanitizedLine
72 

◆ replaceComponentNumber()

def CombineRootAndConfigFilesAfterReduction.replaceComponentNumber (   line,
  newNumber 
)

Definition at line 138 of file CombineRootAndConfigFilesAfterReduction.py.

138 def replaceComponentNumber(line,newNumber):
139  # Line is in the following form:
140  # JESComponent.#.etc
141  # Replace the first part
142  return re.sub("JESComponent.[0-9]*.","JESComponent.%d."%(newNumber),line)
143 

◆ sanitizeComponentName()

def CombineRootAndConfigFilesAfterReduction.sanitizeComponentName (   aName)

Definition at line 73 of file CombineRootAndConfigFilesAfterReduction.py.

73 def sanitizeComponentName(aName):
74  sanitizedName = re.sub(';1','',aName)
75  sanitizedName = re.sub('_AntiKt4Topo_EMJES','',sanitizedName)
76  sanitizedName = re.sub('_AntiKt6Topo_EMJES','',sanitizedName)
77  sanitizedName = re.sub('_AntiKt4Topo_LCJES','',sanitizedName)
78  sanitizedName = re.sub('_AntiKt6Topo_LCJES','',sanitizedName)
79  return sanitizedName
80 

Variable Documentation

◆ compNames

def CombineRootAndConfigFilesAfterReduction.compNames = CombineRootFiles(sharePath+"/"+fullRootFile,reducedRootFile,sharePath+"/"+outRootFile)

Definition at line 262 of file CombineRootAndConfigFilesAfterReduction.py.

◆ fullConfigFile

CombineRootAndConfigFilesAfterReduction.fullConfigFile = sys.argv[2]

Definition at line 252 of file CombineRootAndConfigFilesAfterReduction.py.

◆ fullRootFile

CombineRootAndConfigFilesAfterReduction.fullRootFile = sys.argv[3]

Definition at line 253 of file CombineRootAndConfigFilesAfterReduction.py.

◆ GetKeyNames

CombineRootAndConfigFilesAfterReduction.GetKeyNames

Definition at line 259 of file CombineRootAndConfigFilesAfterReduction.py.

◆ outConfigFile

CombineRootAndConfigFilesAfterReduction.outConfigFile = sys.argv[5]

Definition at line 255 of file CombineRootAndConfigFilesAfterReduction.py.

◆ outRootFile

CombineRootAndConfigFilesAfterReduction.outRootFile = sys.argv[6]

Definition at line 256 of file CombineRootAndConfigFilesAfterReduction.py.

◆ reducedRootFile

CombineRootAndConfigFilesAfterReduction.reducedRootFile = sys.argv[4]

Definition at line 254 of file CombineRootAndConfigFilesAfterReduction.py.

◆ sharePath

CombineRootAndConfigFilesAfterReduction.sharePath = sys.argv[1]

Definition at line 251 of file CombineRootAndConfigFilesAfterReduction.py.

CombineRootAndConfigFilesAfterReduction.checkIfWasCategoryReduction
def checkIfWasCategoryReduction(listOfNames)
Definition: CombineRootAndConfigFilesAfterReduction.py:126
CombineRootAndConfigFilesAfterReduction.replaceComponentNumber
def replaceComponentNumber(line, newNumber)
Definition: CombineRootAndConfigFilesAfterReduction.py:138
CombineRootAndConfigFilesAfterReduction.getDescFromName
def getDescFromName(aName)
Definition: CombineRootAndConfigFilesAfterReduction.py:81
CombineRootAndConfigFilesAfterReduction.getCategoryFromName
def getCategoryFromName(aName)
Definition: CombineRootAndConfigFilesAfterReduction.py:105
CombineRootAndConfigFilesAfterReduction.sanitizeComponentName
def sanitizeComponentName(aName)
Definition: CombineRootAndConfigFilesAfterReduction.py:73
CombineRootAndConfigFilesAfterReduction.GetKeyNames
def GetKeyNames(self, dir="")
Definition: CombineRootAndConfigFilesAfterReduction.py:11
calibdata.exit
exit
Definition: calibdata.py:236
CombineRootAndConfigFilesAfterReduction.CombineRootFiles
def CombineRootFiles(fullFileName, reducedFileName, combinedFileName)
Definition: CombineRootAndConfigFilesAfterReduction.py:17
CombineRootAndConfigFilesAfterReduction.CombineConfigFiles
def CombineConfigFiles(fullFileName, combinedFileName, combinedRootFileName, componentNames)
Definition: CombineRootAndConfigFilesAfterReduction.py:144
CombineRootAndConfigFilesAfterReduction.readSanitizedLine
def readSanitizedLine(file)
Definition: CombineRootAndConfigFilesAfterReduction.py:66
Trk::open
@ open
Definition: BinningType.h:40