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 25 of file PhaseITreeProducer.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 159 of file PhaseITreeProducer.py.

159  def __init__(self, inputDQMName, outputDQMName, modDicName):
160  self.inputFileName = inputDQMName
161  self.outputFileName = outputDQMName
162  self.detIDsFileName = modDicName
163 
164  index = self.inputFileName.find('R000')
165  runNumber = self.inputFileName[index+4:index+10]
166 
167  self.dirs = ['DQMData/Run %s/PixelPhase1/Run summary/Phase1_MechanicalView' % (runNumber),
168  'DQMData/Run %s/PixelPhase1/Run summary/Tracks' % (runNumber)]
169  self.dirsAliases = {self.dirs[0]:"", self.dirs[1]: "T"}
170 
171  self.inputFile = TFile(self.inputFileName)
172  self.listOfNumHistograms = []
173  self.availableNames = []
174 
175  self.maxLadderToLayer = {6:1, 14:2, 22:3, 32:4}
176  self.maxBladeToRing = {11:1, 17:2}
177 
178  self.internalData = {}
179 
180  if self.inputFile.IsOpen():
181  print("%s opened successfully!" % (self.inputFileName))
182  #Get all neeeded histograms
183  for dir in self.dirs:
184  self.__TraverseDirTree(self.inputFile.Get(dir))
185  print("Histograms to read %d" % (len(self.listOfNumHistograms)))
186 
187  self.detDict = {}
188 
189  with open(self.detIDsFileName, "r") as detIDs: # create dictionary online -> rawid 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 
200 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define update(a, b)

◆ __del__()

def PhaseITreeProducer.ModuleLvlValuesReader.__del__ (   self)

Definition at line 316 of file PhaseITreeProducer.py.

References BufferedBoostIODBWriter.inputFile, InefficientDoubleROC.InefficientDeadROCs.inputFile, PhaseITreeProducer.ModuleLvlValuesReader.inputFile, and FastTimerService_cff.range.

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

Member Function Documentation

◆ __BuildOnlineBarrelName()

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().

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

◆ __BuildOnlineDiskName()

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().

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

◆ __CreateDummyStructAsStr()

def PhaseITreeProducer.ModuleLvlValuesReader.__CreateDummyStructAsStr (   self,
  dicData 
)
private

Definition at line 147 of file PhaseITreeProducer.py.

Referenced by PhaseITreeProducer.ModuleLvlValuesReader.CreateTree().

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

◆ __GetBarrelSector()

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

Definition at line 63 of file PhaseITreeProducer.py.

References funct.abs(), and FastTimerService_cff.range.

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

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

◆ __GetPartStr()

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  def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero):
54  if isXlowerThanZero and isYlowerThanZero:
55  return "mO"
56  if isXlowerThanZero and isYlowerThanZero == False:
57  return "mI"
58  if isXlowerThanZero == False and isYlowerThanZero:
59  return "pO"
60  if isXlowerThanZero == False and isYlowerThanZero == False:
61  return "pI"
62 

◆ __GroupHistograms()

def PhaseITreeProducer.ModuleLvlValuesReader.__GroupHistograms (   self)
private

Definition at line 128 of file PhaseITreeProducer.py.

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

◆ __TraverseDirTree()

def PhaseITreeProducer.ModuleLvlValuesReader.__TraverseDirTree (   self,
  dir 
)
private

Definition at line 29 of file PhaseITreeProducer.py.

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

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

29  def __TraverseDirTree(self, dir):
30 
31  currPath = (dir.GetPath().split(":/"))[1]
32 
33  for obj in dir.GetListOfKeys():
34  if not obj.IsFolder():
35  if obj.ReadObjectAny(TClass.GetClass("TH2")):
36  th2 = deepcopy(obj.ReadObj())
37  name = th2.GetName()
38  if 6 < th2.GetNbinsX() < 10 and name.find("per") != -1 and name.find("Lumisection") == -1: #take only module lvl plots
39  print(''.join([dir.GetPath(), '/', name]))
40 
41  # fix when there are plots starting with the same strings in different directories
42  prefix = ""
43  for i in self.dirs:
44  if currPath.startswith(i):
45  prefix = self.dirsAliases[i]
46  break
47  # print(currPath, prefix)
48  th2.SetName(prefix + th2.GetName())
49  self.listOfNumHistograms.append(th2)
50  else:
51  self.__TraverseDirTree(obj.ReadObj())
52 
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

◆ CreateTree()

def PhaseITreeProducer.ModuleLvlValuesReader.CreateTree (   self)

Definition at line 242 of file PhaseITreeProducer.py.

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

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

◆ CreateTree2()

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().

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

◆ DumpData()

def PhaseITreeProducer.ModuleLvlValuesReader.DumpData (   self)

Definition at line 304 of file PhaseITreeProducer.py.

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

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

◆ ReadHistograms()

def PhaseITreeProducer.ModuleLvlValuesReader.ReadHistograms (   self)

Definition at line 201 of file PhaseITreeProducer.py.

References PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineBarrelName(), PhaseITreeProducer.ModuleLvlValuesReader.__BuildOnlineDiskName(), mps_setup.append, PhaseITreeProducer.ModuleLvlValuesReader.availableNames, InefficientDoubleROC.InefficientDeadROCs.detDict, PhaseITreeProducer.ModuleLvlValuesReader.detDict, PhaseITreeProducer.ModuleLvlValuesReader.groupedHistograms, BufferedBoostIODBWriter.inputFile, InefficientDoubleROC.InefficientDeadROCs.inputFile, PhaseITreeProducer.ModuleLvlValuesReader.inputFile, createfilelist.int, PhaseITreeProducer.ModuleLvlValuesReader.internalData, join(), PhaseITreeProducer.ModuleLvlValuesReader.maxBladeToRing, PhaseITreeProducer.ModuleLvlValuesReader.maxLadderToLayer, print(), FastTimerService_cff.range, submitPVValidationJobs.split(), and update.

201  def ReadHistograms(self):
202  if self.inputFile.IsOpen():
203  for group in self.groupedHistograms:
204  # name = ''.join(group[0].GetName().split("_")[0:-1])
205  name = ''.join(group[0].GetName().split("_per_")[0])
206  self.availableNames.append(name)
207  # print(name)
208  for obj in group:
209  nbinsX = obj.GetNbinsX()
210  nbinsY = obj.GetNbinsY()
211 
212  if nbinsX == 9: # BARREL
213  maxX = nbinsX // 2
214  maxY = nbinsY // 2
215 
216  for x in range(-maxX, maxX + 1):
217  if x == 0:
218  continue
219  for y in range(-maxY, maxY + 1, 1):
220  if y == 0:
221  continue
222  onlineName = self.__BuildOnlineBarrelName(x, y, self.maxLadderToLayer[maxY])
223  self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, y + maxY + 1)})
224 
225  elif nbinsX == 7: # FORWARD
226  maxX = nbinsX // 2
227  maxY = nbinsY // 4
228 
229  for x in range(-maxX, maxX + 1):
230  if x == 0:
231  continue
232  for y in range(-maxY, maxY + 1):
233  if int(y) == 0:
234  continue
235  for panel in range(1, 3):
236  onlineName = self.__BuildOnlineDiskName(x, y, panel, self.maxBladeToRing[maxY])
237  self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, (y + maxY) * 2 + panel)})
238  else:
239  print("Unrecognized plot")
240  else:
241  print("Histograms saved to internal data structure")
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

◆ availableNames

◆ detDict

PhaseITreeProducer.ModuleLvlValuesReader.detDict

◆ detIDsFileName

PhaseITreeProducer.ModuleLvlValuesReader.detIDsFileName

Definition at line 162 of file PhaseITreeProducer.py.

◆ dirs

PhaseITreeProducer.ModuleLvlValuesReader.dirs

◆ dirsAliases

PhaseITreeProducer.ModuleLvlValuesReader.dirsAliases

◆ groupedHistograms

PhaseITreeProducer.ModuleLvlValuesReader.groupedHistograms

◆ inputFile

◆ inputFileName

PhaseITreeProducer.ModuleLvlValuesReader.inputFileName

Definition at line 160 of file PhaseITreeProducer.py.

◆ internalData

◆ listOfNumHistograms

PhaseITreeProducer.ModuleLvlValuesReader.listOfNumHistograms

◆ maxBladeToRing

PhaseITreeProducer.ModuleLvlValuesReader.maxBladeToRing

◆ maxLadderToLayer

PhaseITreeProducer.ModuleLvlValuesReader.maxLadderToLayer

◆ outputFile

PhaseITreeProducer.ModuleLvlValuesReader.outputFile

◆ outputFileName

PhaseITreeProducer.ModuleLvlValuesReader.outputFileName