CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions
PhaseITreeProducer.ModuleLvlValuesReader Class Reference

Public Member Functions

def __del__
 
def __init__
 
def CreateTree
 
def CreateTree2
 
def DumpData
 
def ReadHistograms
 

Public Attributes

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

Private Member Functions

def __BuildOnlineBarrelName
 
def __BuildOnlineDiskName
 
def __CreateDummyStructAsStr
 
def __GetBarrelSector
 
def __GetPartStr
 
def __GroupHistograms
 
def __TraverseDirTree
 

Detailed Description

Definition at line 25 of file PhaseITreeProducer.py.

Constructor & Destructor Documentation

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

Definition at line 159 of file PhaseITreeProducer.py.

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

Definition at line 316 of file PhaseITreeProducer.py.

References sistrip::SpyUtilities.range().

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

Member Function Documentation

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

Definition at line 119 of file PhaseITreeProducer.py.

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

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

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

Definition at line 124 of file PhaseITreeProducer.py.

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

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

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

Definition at line 147 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.CreateTree().

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

Definition at line 63 of file PhaseITreeProducer.py.

References funct.abs(), and sistrip::SpyUtilities.range().

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

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

Definition at line 53 of file PhaseITreeProducer.py.

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

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

Definition at line 128 of file PhaseITreeProducer.py.

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

Definition at line 29 of file PhaseITreeProducer.py.

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

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

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

Definition at line 242 of file PhaseITreeProducer.py.

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

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

Definition at line 277 of file PhaseITreeProducer.py.

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

278  def CreateTree2(self): # use for TkCommissioner
279  if len(self.internalData):
280 
281  self.outputFile = TFile(self.outputFileName, "recreate")
282  tree = TTree("tree", "readData")
283 
284  key = array("i", [0])
285  tree.Branch("detid", key, "detid/i")
286 
287  dat = {}
288  for k in self.internalData:
289  for d in self.internalData[k]:
290  dat.update({d : array("f", [0])})
291  tree.Branch(d, dat[d], d + "/F")
292  break
293 
294  for k in self.internalData:
295  key[0] = k
296  for d in self.internalData[k]:
297  (dat[d])[0] = (self.internalData[k])[d]
298  tree.Fill()
299 
300  tree.Write()
301  self.outputFile.Close()
302 
303  print("Data saved as TTree object")
tuple array
Definition: mps_check.py:216
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def PhaseITreeProducer.ModuleLvlValuesReader.DumpData (   self)

Definition at line 304 of file PhaseITreeProducer.py.

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

305  def DumpData(self):
306  for key in self.internalData:
307  print("#"*20)
308  print(key)
309  module = self.internalData[key]
310  for d in module:
311  print((d, module[d]))
312 
313  for i in self.availableNames:
314  print(i)
315  print(len(self.availableNames))
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def PhaseITreeProducer.ModuleLvlValuesReader.ReadHistograms (   self)

Definition at line 201 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineBarrelName(), PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineDiskName(), InefficientDoubleROC.InefficientDeadROCs.detDict, PhaseITreeProducer.ModuleLvlValuesReader.detDict, PhaseITreeProducer.ModuleLvlValuesReader.groupedHistograms, PhaseITreeProducer.ModuleLvlValuesReader.internalData, join(), PhaseITreeProducer.ModuleLvlValuesReader.maxBladeToRing, PhaseITreeProducer.ModuleLvlValuesReader.maxLadderToLayer, print(), sistrip::SpyUtilities.range(), submitPVValidationJobs.split(), and update.

202  def ReadHistograms(self):
203  if self.inputFile.IsOpen():
204  for group in self.groupedHistograms:
205  # name = ''.join(group[0].GetName().split("_")[0:-1])
206  name = ''.join(group[0].GetName().split("_per_")[0])
207  self.availableNames.append(name)
208  # print(name)
209  for obj in group:
210  nbinsX = obj.GetNbinsX()
211  nbinsY = obj.GetNbinsY()
212 
213  if nbinsX == 9: # BARREL
214  maxX = nbinsX // 2
215  maxY = nbinsY // 2
216 
217  for x in range(-maxX, maxX + 1):
218  if x == 0:
219  continue
220  for y in range(-maxY, maxY + 1, 1):
221  if y == 0:
222  continue
223  onlineName = self.__BuildOnlineBarrelName(x, y, self.maxLadderToLayer[maxY])
224  self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, y + maxY + 1)})
225 
226  elif nbinsX == 7: # FORWARD
227  maxX = nbinsX // 2
228  maxY = nbinsY // 4
229 
230  for x in range(-maxX, maxX + 1):
231  if x == 0:
232  continue
233  for y in range(-maxY, maxY + 1):
234  if int(y) == 0:
235  continue
236  for panel in range(1, 3):
237  onlineName = self.__BuildOnlineDiskName(x, y, panel, self.maxBladeToRing[maxY])
238  self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, (y + maxY) * 2 + panel)})
239  else:
240  print("Unrecognized plot")
241  else:
print("Histograms saved to internal data structure")
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#define update(a, b)

Member Data Documentation

PhaseITreeProducer.ModuleLvlValuesReader.availableNames

Definition at line 173 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.detDict

Definition at line 187 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.detIDsFileName

Definition at line 162 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.dirs

Definition at line 167 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.dirsAliases

Definition at line 169 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.groupedHistograms

Definition at line 131 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.inputFile

Definition at line 171 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.inputFileName

Definition at line 160 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.internalData

Definition at line 178 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.CreateTree(), PhaseITreeProducer.ModuleLvlValuesReader.CreateTree2(), PhaseITreeProducer.ModuleLvlValuesReader.DumpData(), TH2PolyOfflineMaps.TH2PolyOfflineMaps.DumpData(), TH2PolyOfflineMaps.TH2PolyOfflineMaps.PrintTrackerMaps(), PhaseITreeProducer.ModuleLvlValuesReader.ReadHistograms(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.ReadHistograms().

PhaseITreeProducer.ModuleLvlValuesReader.listOfNumHistograms

Definition at line 172 of file PhaseITreeProducer.py.

PhaseITreeProducer.ModuleLvlValuesReader.maxBladeToRing

Definition at line 176 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.maxLadderToLayer

Definition at line 175 of file PhaseITreeProducer.py.

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

PhaseITreeProducer.ModuleLvlValuesReader.outputFile

Definition at line 259 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.CreateTree2().

PhaseITreeProducer.ModuleLvlValuesReader.outputFileName

Definition at line 161 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.CreateTree2().