CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions
PhaseITreeProducer.ModuleLvlValuesReader Class Reference

Public Member Functions

def __del__ (self)
 
def __init__ (self, inputDQMName, outputDQMName, modDicName)
 
def CreateTree (self)
 
def CreateTree2 (self)
 
def DumpData (self)
 
def ReadHistograms (self)
 

Public Attributes

 availableNames
 
 detDict
 
 detIDsFileName
 
 dirs
 
 dirsAliases
 
 groupedHistograms
 
 inputFile
 
 inputFileName
 
 internalData
 
 listOfNumHistograms
 
 maxBladeToRing
 
 maxLadderToLayer
 
 outputFile
 
 outputFileName
 

Private Member Functions

def __BuildOnlineBarrelName (self, signedModule, signedLadder, layer)
 
def __BuildOnlineDiskName (self, signedDisk, signedBlade, panel, ring)
 
def __CreateDummyStructAsStr (self, dicData)
 
def __GetBarrelSector (self, layer, signedLadder, signedModule)
 
def __GetPartStr (self, isXlowerThanZero, isYlowerThanZero)
 
def __GroupHistograms (self)
 
def __TraverseDirTree (self, dir)
 

Detailed Description

Definition at line 24 of file PhaseITreeProducer.py.

Constructor & Destructor Documentation

def PhaseITreeProducer.ModuleLvlValuesReader.__init__ (   self,
  inputDQMName,
  outputDQMName,
  modDicName 
)

Definition at line 158 of file PhaseITreeProducer.py.

158  def __init__(self, inputDQMName, outputDQMName, modDicName):
159  self.inputFileName = inputDQMName
160  self.outputFileName = outputDQMName
161  self.detIDsFileName = modDicName
162 
163  index = self.inputFileName.find('R000')
164  runNumber = self.inputFileName[index+4:index+10]
165 
166  self.dirs = ['DQMData/Run %s/PixelPhase1/Run summary/Phase1_MechanicalView' % (runNumber),
167  'DQMData/Run %s/PixelPhase1/Run summary/Tracks' % (runNumber)]
168  self.dirsAliases = {self.dirs[0]:"", self.dirs[1]: "T"}
169 
170  self.inputFile = TFile(self.inputFileName)
172  self.availableNames = []
173 
174  self.maxLadderToLayer = {6:1, 14:2, 22:3, 32:4}
175  self.maxBladeToRing = {11:1, 17:2}
176 
177  self.internalData = {}
178 
179  if self.inputFile.IsOpen():
180  print("%s opened successfully!" % (self.inputFileName))
181  #Get all neeeded histograms
182  for dir in self.dirs:
183  self.__TraverseDirTree(self.inputFile.Get(dir))
184  print("Histograms to read %d" % (len(self.listOfNumHistograms)))
185 
186  self.detDict = {}
187 
188  with open(self.detIDsFileName, "r") as detIDs: # create dictionary online -> rawid
189  for entry in detIDs:
190  items = entry.replace("\n", " ").split(" ")
191  self.detDict.update({items[1] : int(items[0])})
192  # init internal data structure
193  self.internalData.update({int(items[0]) : {}})
194 
195  self.__GroupHistograms()
196 
197  else:
198  print("Unable to open file %s" % (self.inputFileName))
199 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def __init__(self, inputDQMName, outputDQMName, modDicName)
double split
Definition: MVATrainer.cc:139
def PhaseITreeProducer.ModuleLvlValuesReader.__del__ (   self)

Definition at line 315 of file PhaseITreeProducer.py.

315  def __del__(self):
316  if self.inputFile.IsOpen():
317  self.inputFile.Close()
318 
319 #--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--

Member Function Documentation

def PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineBarrelName (   self,
  signedModule,
  signedLadder,
  layer 
)
private

Definition at line 118 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.__GetBarrelSector(), PhaseITreeProducer.ModuleLvlValuesReader.__GetPartStr(), funct.abs(), and str.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.ReadHistograms(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.ReadHistograms().

118  def __BuildOnlineBarrelName(self, signedModule, signedLadder, layer): #in Phase1 it is assumed that there are only full modules
119  thePart = self.__GetPartStr(signedModule < 0, signedLadder < 0)
120  theSector = str(self.__GetBarrelSector(layer, signedLadder, signedModule))
121  return "BPix_B" + thePart + "_SEC" + theSector + "_LYR" + str(layer) + "_LDR" + str(abs(signedLadder)) + "F_MOD" + str(abs(signedModule))
122 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def __GetBarrelSector(self, layer, signedLadder, signedModule)
def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero)
#define str(s)
def __BuildOnlineBarrelName(self, signedModule, signedLadder, layer)
def PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineDiskName (   self,
  signedDisk,
  signedBlade,
  panel,
  ring 
)
private

Definition at line 123 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.__GetPartStr(), funct.abs(), and str.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.ReadHistograms(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.ReadHistograms().

123  def __BuildOnlineDiskName(self, signedDisk, signedBlade, panel, ring):
124  thePart = self.__GetPartStr(signedDisk < 0, signedBlade < 0)
125  return "FPix_B" + thePart + "_D" + str(abs(signedDisk)) + "_BLD" + str(abs(signedBlade)) + "_PNL" + str(panel) + "_RNG" + str(ring)
126 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero)
def __BuildOnlineDiskName(self, signedDisk, signedBlade, panel, ring)
#define str(s)
def PhaseITreeProducer.ModuleLvlValuesReader.__CreateDummyStructAsStr (   self,
  dicData 
)
private

Definition at line 146 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.CreateTree().

146  def __CreateDummyStructAsStr(self, dicData):
147  str = "struct MyStruct{"
148  str = str + "Int_t key;"
149  leafStr = "key/I"
150  for k in dicData:
151  str = str + "Float_t " + k + ";"
152  leafStr = leafStr + ":" + k + "/F"
153  str = str + "};"
154  return str, leafStr
155 
def PhaseITreeProducer.ModuleLvlValuesReader.__GetBarrelSector (   self,
  layer,
  signedLadder,
  signedModule 
)
private

Definition at line 62 of file PhaseITreeProducer.py.

References funct.abs().

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineBarrelName(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.__BuildOnlineBarrelName().

62  def __GetBarrelSector(self, layer, signedLadder, signedModule): #adapted from PixelBarrelName
63  theLadder = abs(signedLadder)
64  theModule = abs(signedModule)
65 
66  sector = 0
67 
68  if layer == 1:
69 
70  if theLadder == 1:
71  if theModule >= 2:
72  return 1
73  else:
74  return 2
75  if theLadder == 2:
76  if theModule >= 3:
77  return 2
78  else:
79  return 3
80  if theLadder == 3:
81  if theModule >= 4:
82  return 3
83  else:
84  return 4
85  if theLadder == 4:
86  if theModule >= 2:
87  return 5
88  else:
89  return 6
90  if theLadder == 5:
91  if theModule >= 3:
92  return 6
93  else:
94  return 7
95  if theLadder == 6:
96  if theModule >= 4:
97  return 7
98  else:
99  return 8
100  # here is used simplified form of assignment, see source file for reference
101  elif layer == 2:
102  i = theLadder // 5
103  sector = i * 3
104  shortLadder = theLadder - 5 * i
105  for i in range(0, shortLadder, 2):
106  sector = sector + 1
107  return sector
108  elif layer == 3:
109  sector = 1
110  for i in range(2, theLadder, 3):
111  if (i + 1) % 3 == 0:
112  sector = sector + 1
113  return sector
114  elif layer == 4:
115  sector = (theLadder + 3) // 4
116  return sector
117 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def __GetBarrelSector(self, layer, signedLadder, signedModule)
def PhaseITreeProducer.ModuleLvlValuesReader.__GetPartStr (   self,
  isXlowerThanZero,
  isYlowerThanZero 
)
private

Definition at line 52 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineBarrelName(), TH2PolyOfflineMaps.TH2PolyOfflineMaps.__BuildOnlineBarrelName(), PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineDiskName(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.__BuildOnlineDiskName().

52  def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero):
53  if isXlowerThanZero and isYlowerThanZero:
54  return "mO"
55  if isXlowerThanZero and isYlowerThanZero == False:
56  return "mI"
57  if isXlowerThanZero == False and isYlowerThanZero:
58  return "pO"
59  if isXlowerThanZero == False and isYlowerThanZero == False:
60  return "pI"
61 
def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero)
def PhaseITreeProducer.ModuleLvlValuesReader.__GroupHistograms (   self)
private

Definition at line 127 of file PhaseITreeProducer.py.

127  def __GroupHistograms(self):
128  currentGroupName = ""
129  groupOfHists = []
131 
132  ##### GROUP ALL LAYERS/RINGS HAVING SIMILAR INFORMATION
133  for obj in self.listOfNumHistograms:
134  objName = obj.GetName()
135  objNameSplit = objName.split("_")
136  objNameCollected = ''.join(objNameSplit[0:-1])
137  if objNameCollected != currentGroupName:
138  if len(groupOfHists):
139  self.groupedHistograms.append(groupOfHists)
140  groupOfHists = []
141 
142  currentGroupName = objNameCollected
143  groupOfHists.append(obj)
144  self.groupedHistograms.append(groupOfHists) #the last group
145 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def PhaseITreeProducer.ModuleLvlValuesReader.__TraverseDirTree (   self,
  dir 
)
private

Definition at line 28 of file PhaseITreeProducer.py.

References InefficientDoubleROC.InefficientDeadROCs.__TraverseDirTree(), PhaseITreeProducer.ModuleLvlValuesReader.__TraverseDirTree(), InefficientDoubleROC.InefficientDeadROCs.dirs, PhaseITreeProducer.ModuleLvlValuesReader.dirs, PhaseITreeProducer.ModuleLvlValuesReader.dirsAliases, join(), edm.print(), and split.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.__TraverseDirTree(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.__TraverseDirTree().

28  def __TraverseDirTree(self, dir):
29 
30  currPath = (dir.GetPath().split(":/"))[1]
31 
32  for obj in dir.GetListOfKeys():
33  if not obj.IsFolder():
34  if obj.ReadObjectAny(TClass.GetClass("TH2")):
35  th2 = deepcopy(obj.ReadObj())
36  name = th2.GetName()
37  if 6 < th2.GetNbinsX() < 10 and name.find("per") != -1 and name.find("Lumisection") == -1: #take only module lvl plots
38  print(''.join([dir.GetPath(), '/', name]))
39 
40  # fix when there are plots starting with the same strings in different directories
41  prefix = ""
42  for i in self.dirs:
43  if currPath.startswith(i):
44  prefix = self.dirsAliases[i]
45  break
46  # print(currPath, prefix)
47  th2.SetName(prefix + th2.GetName())
48  self.listOfNumHistograms.append(th2)
49  else:
50  self.__TraverseDirTree(obj.ReadObj())
51 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139
def PhaseITreeProducer.ModuleLvlValuesReader.CreateTree (   self)

Definition at line 241 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.__CreateDummyStructAsStr(), PhaseITreeProducer.ModuleLvlValuesReader.internalData, and edm.print().

241  def CreateTree(self): # too much complication lvl, use CreateTree2
242  if len(self.internalData):
243  # <- TOTAL WORKAROUND: START -> #
244  # SEE: http://wlav.web.cern.ch/wlav/pyroot/tpytree.html
245 
246  leafStr = ""
247  for key in self.internalData:
248  s, leafStr = self.__CreateDummyStructAsStr(self.internalData[key])
249  print(s)
250  print(leafStr)
251  gROOT.ProcessLine(s)
252  break #all modules are assumed to have the same set of measured parameters
253 
254  from ROOT import MyStruct
255  ms = MyStruct()
256  # <- TOTAL WORKAROUND: END -> #
257 
258  self.outputFile = TFile(self.outputFileName, "recreate")
259  tree = TTree("tree", "readData")
260  tree.Branch("b", ms, leafStr)
261 
262  tree.SetBranchAddress("b", tree)
263 
264  for key in self.internalData:
265  setattr(ms, "key", key)
266  for d in self.internalData[key]:
267  setattr(ms, d, (self.internalData[key])[d])
268  tree.Fill()
269 
270  # break
271  tree.Write()
272  self.outputFile.Close()
273 
274  print("Data saved as TTree object")
275 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def PhaseITreeProducer.ModuleLvlValuesReader.CreateTree2 (   self)

Definition at line 276 of file PhaseITreeProducer.py.

References mps_check.array, PhaseITreeProducer.ModuleLvlValuesReader.internalData, RPCTTUMonitor.outputFile, Vx3DHLTAnalyzer.outputFile, DTDataIntegrityTask.outputFile, PlotAlignmentValidation.outputFile, PhaseITreeProducer.ModuleLvlValuesReader.outputFile, DTSurveyConvert.outputFileName, InefficientDoubleROC.InefficientDeadROCs.outputFileName, SiStripGainCosmicCalculator.outputFileName, CSCSkim.outputFileName, PhaseITreeProducer.ModuleLvlValuesReader.outputFileName, and edm.print().

276  def CreateTree2(self): # use for TkCommissioner
277  if len(self.internalData):
278 
279  self.outputFile = TFile(self.outputFileName, "recreate")
280  tree = TTree("tree", "readData")
281 
282  key = array("i", [0])
283  tree.Branch("detid", key, "detid/i")
284 
285  dat = {}
286  for k in self.internalData:
287  for d in self.internalData[k]:
288  dat.update({d : array("f", [0])})
289  tree.Branch(d, dat[d], d + "/F")
290  break
291 
292  for k in self.internalData:
293  key[0] = k
294  for d in self.internalData[k]:
295  (dat[d])[0] = (self.internalData[k])[d]
296  tree.Fill()
297 
298  tree.Write()
299  self.outputFile.Close()
300 
301  print("Data saved as TTree object")
302 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def PhaseITreeProducer.ModuleLvlValuesReader.DumpData (   self)

Definition at line 303 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.availableNames, PhaseITreeProducer.ModuleLvlValuesReader.internalData, and edm.print().

303  def DumpData(self):
304  for key in self.internalData:
305  print("#"*20)
306  print(key)
307  module = self.internalData[key]
308  for d in module:
309  print(d, module[d])
310 
311  for i in self.availableNames:
312  print(i)
313  print(len(self.availableNames))
314 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def PhaseITreeProducer.ModuleLvlValuesReader.ReadHistograms (   self)

Definition at line 200 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineBarrelName(), PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineDiskName(), InefficientDoubleROC.InefficientDeadROCs.detDict, PhaseITreeProducer.ModuleLvlValuesReader.detDict, PhaseITreeProducer.ModuleLvlValuesReader.groupedHistograms, createfilelist.int, PhaseITreeProducer.ModuleLvlValuesReader.internalData, join(), PhaseITreeProducer.ModuleLvlValuesReader.maxBladeToRing, PhaseITreeProducer.ModuleLvlValuesReader.maxLadderToLayer, edm.print(), split, and update.

200  def ReadHistograms(self):
201  if self.inputFile.IsOpen():
202  for group in self.groupedHistograms:
203  # name = ''.join(group[0].GetName().split("_")[0:-1])
204  name = ''.join(group[0].GetName().split("_per_")[0])
205  self.availableNames.append(name)
206  # print(name)
207  for obj in group:
208  nbinsX = obj.GetNbinsX()
209  nbinsY = obj.GetNbinsY()
210 
211  if nbinsX == 9: # BARREL
212  maxX = nbinsX // 2
213  maxY = nbinsY // 2
214 
215  for x in range(-maxX, maxX + 1):
216  if x == 0:
217  continue
218  for y in range(-maxY, maxY + 1, 1):
219  if y == 0:
220  continue
221  onlineName = self.__BuildOnlineBarrelName(x, y, self.maxLadderToLayer[maxY])
222  self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, y + maxY + 1)})
223 
224  elif nbinsX == 7: # FORWARD
225  maxX = nbinsX // 2
226  maxY = nbinsY // 4
227 
228  for x in range(-maxX, maxX + 1):
229  if x == 0:
230  continue
231  for y in range(-maxY, maxY + 1):
232  if int(y) == 0:
233  continue
234  for panel in range(1, 3):
235  onlineName = self.__BuildOnlineDiskName(x, y, panel, self.maxBladeToRing[maxY])
236  self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, (y + maxY) * 2 + panel)})
237  else:
238  print("Unrecognized plot")
239  else:
240  print("Histograms saved to internal data structure")
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
#define update(a, b)
def __BuildOnlineDiskName(self, signedDisk, signedBlade, panel, ring)
double split
Definition: MVATrainer.cc:139
def __BuildOnlineBarrelName(self, signedModule, signedLadder, layer)

Member Data Documentation

PhaseITreeProducer.ModuleLvlValuesReader.availableNames
PhaseITreeProducer.ModuleLvlValuesReader.detDict
PhaseITreeProducer.ModuleLvlValuesReader.detIDsFileName

Definition at line 161 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.dirs
PhaseITreeProducer.ModuleLvlValuesReader.dirsAliases
PhaseITreeProducer.ModuleLvlValuesReader.groupedHistograms
PhaseITreeProducer.ModuleLvlValuesReader.inputFile

Definition at line 170 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.inputFileName

Definition at line 159 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.internalData
PhaseITreeProducer.ModuleLvlValuesReader.listOfNumHistograms

Definition at line 171 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.maxBladeToRing
PhaseITreeProducer.ModuleLvlValuesReader.maxLadderToLayer
PhaseITreeProducer.ModuleLvlValuesReader.outputFile
PhaseITreeProducer.ModuleLvlValuesReader.outputFileName