CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
overlapValidationPlot Namespace Reference

Functions

def hist
 
def plot
 
def subdetCondition
 

Variables

tuple detNameList = ("BPIX", "FPIX", "TIB", "TID", "TOB", "TEC")
 
list dirNameList = ["z","r","phi"]
 

Function Documentation

def overlapValidationPlot.hist (   tree_file_name,
  hist_name,
  subdet_ids,
  module_directions,
  overlap_directions,
  profile_directions 
)

Definition at line 18 of file overlapValidationPlot.py.

References funct.abs(), bitset_utilities.append(), HcalObjRepresent.Fill(), min(), print(), sistrip::SpyUtilities.range(), SetDirectory(), and str.

Referenced by plot().

18 
19 def hist(tree_file_name, hist_name,subdet_ids,module_directions,overlap_directions,profile_directions):
20  f = ROOT.TFile(tree_file_name)
21  t = f.Get("analysis/Overlaps")
22  h = []
23  for subdet in range(6):#Creates a 4-D list of empty histograms for permutations of subdetector, overlap direction, module direction and profile direction.
24  h.append([])
25  for module in range(3):
26  h[subdet].append([])
27  for overlap in range(3):
28  h[subdet][module].append([])
29  for profile in range(4):
30  if subdetConditon(subdet,module,overlap):
31  h[subdet][module][overlap].append(0)
32  continue
33  name = hist_name + "{0}_{1}_{2}".format(dirNameList[module],dirNameList[overlap],detNameList[subdet])
34  if not ((subdet_ids[subdet]) and (module_directions[module]) and (profile_directions[profile]) and overlap_directions[overlap]): #puts a 0 in any unwanted plots
35  h[subdet][module][overlap].append(0)
36  continue
37  if (profile>0):
38  if profile == 3: bins, xmin, xmax = 10, -math.pi, math.pi
39  if subdet+1 == 1 and profile == 1: bins, xmin, xmax = 10, -30, -30
40  if subdet+1 == 2 and profile == 1: bins, xmin, xmax = 40, -60, 60
41  if subdet+1 == 3 and profile == 1: bins, xmin, xmax = 10, -70, 70
42  if subdet+1 == 4 and profile == 1: bins, xmin, xmax = 40, -110, 110
43  if subdet+1 == 5 and profile == 1: bins, xmin, xmax = 10, -110, 110
44  if subdet+1 == 6 and profile == 1: bins, xmin, xmax = 20, -280, 280
45  if subdet+1 == 1 and profile == 2: bins, xmin, xmax = 10, 0, 20
46  if subdet+1 == 2 and profile == 2: bins, xmin, xmax = 10, 0, 20
47  if subdet+1 == 3 and profile == 2: bins, xmin, xmax = 10, 20, 55
48  if subdet+1 == 4 and profile == 2: bins, xmin, xmax = 10, 20, 55
49  if subdet+1 == 5 and profile == 2: bins, xmin, xmax = 10, 55, 110
50  if subdet+1 == 6 and profile == 2: bins, xmin, xmax = 10, 20, 110
51  h[subdet][module][overlap].append(ROOT.TProfile(hist_name, hist_name, bins, xmin, xmax))
52  elif subdet+1==4 or subdet+1==6:
53  h[subdet][module][overlap].append(ROOT.TH1F(name, name, 100, -5000, 5000))
54  else:
55  h[subdet][module][overlap].append(ROOT.TH1F(name, name, 100, -300, 300))
56  h[subdet][module][overlap][profile].SetDirectory(0)
57 
58  nentries = t.GetEntries()
59 
60  for i, entry in enumerate(t, start=1):#loops through the tree, filling in relevant histograms for each event
61  if i % 10000 == 0 or i == nentries:
62  print(i, "/", nentries)
63 
64  subdet_id = t.subdetID
65  if subdet_ids[subdet_id-1]==False:
66  continue
67 
68  modulePhi0 = math.atan2(t.moduleY[0], t.moduleX[0])
69  modulePhi1 = math.atan2(t.moduleY[1], t.moduleX[1])
70  phidiff = min(abs(modulePhi0-modulePhi1), abs(math.pi - abs(modulePhi0-modulePhi1)))
71  moduleR0 = math.sqrt(t.moduleY[0]**2+t.moduleX[0]**2)
72  moduleR1 = math.sqrt(t.moduleY[1]**2+t.moduleX[1]**2)
73 
74  #determines the direction the modules are in respect to each other for each event
75  if subdet_id%2 == 1 and ((abs(t.moduleZ[0] - t.moduleZ[1]) > 1)):
76  module_direction = 0 #0 refers to Z, 1 to R and 2 to phi
77  elif subdet_id%2 == 0 and (abs(moduleR0 - moduleR1)>1):
78  module_direction = 1
79  elif ((moduleR0*phidiff)>1):
80  module_direction = 2
81  else: #prints if this method of selecting module_direction misses anything
82  print(str(i)+" skipped")
83  continue
84  if module_directions[module_direction]==False:
85  continue
86  avgList=[(t.moduleZ[0]+t.moduleZ[1])/2,(moduleR0+moduleR1)/2,(modulePhi0+modulePhi1)/2]
87  if overlap_directions[2]:
88  overlap_direction = 2
89  if modulePhi0 > modulePhi1:
90  hitXA = t.hitX[1]
91  hitXB = t.hitX[0]
92  predXA = t.predX[1]
93  predXB = t.predX[0]
94  overlapSignA = t.localxdotglobalphi[1]
95  overlapSignB = t.localxdotglobalphi[0]
96  else:
97  hitXA = t.hitX[0]
98  hitXB = t.hitX[1]
99  predXA = t.predX[0]
100  predXB = t.predX[1]
101  overlapSignA = t.localxdotglobalphi[0]
102  overlapSignB = t.localxdotglobalphi[1]
103  residualA = hitXA - predXA
104  residualB = hitXB - predXB
105  if overlapSignA < 0:
106  residualA *= -1
107  if overlapSignB < 0:
108  residualB *= -1
109  A = 10000*(residualA - residualB)
110  h[subdet_id-1][module_direction][overlap_direction][0].Fill(A)
111  for profile in range(3):
112  if profile_directions[profile+1]:
113  h[subdet_id-1][module_direction][overlap_direction][profile+1].Fill(avgList[profile],A)
114 
115 
116  if subdet_id==1 and module_direction != 1 and overlap_directions[0]:
117  overlap_direction = 0
118  if t.moduleZ[0] > t.moduleZ[1]:
119  hitXA = t.hitY[1]
120  hitXB = t.hitY[0]
121  predXA = t.predY[1]
122  predXB = t.predY[0]
123  overlapSignA = t.localydotglobalz[1]
124  overlapSignB = t.localydotglobalz[0]
125  else:
126  hitXA = t.hitY[0]
127  hitXB = t.hitY[1]
128  predXA = t.predY[0]
129  predXB = t.predY[1]
130  overlapSignA = t.localydotglobalz[0]
131  overlapSignB = t.localydotglobalz[1]
132  residualA = hitXA - predXA
133  residualB = hitXB - predXB
134  if overlapSignA < 0:
135  residualA *= -1
136  if overlapSignB < 0:
137  residualB *= -1
138  A = 10000*(residualA - residualB)
139  h[subdet_id-1][module_direction][overlap_direction][0].Fill(A)
140  for profile in range(3):
141  if profile_directions[profile+1]:
142  h[subdet_id-1][module_direction][overlap_direction][profile+1].Fill(avgList[profile],A)
143 
144  if subdet_id==2 and module_direction !=0 and overlap_directions[1]:
145  overlap_direction = 1
146  if moduleR0 > moduleR1:
147  hitXA = t.hitY[1]
148  hitXB = t.hitY[0]
149  predXA = t.predY[1]
150  predXB = t.predY[0]
151  overlapSignA = t.localydotglobalr[1]
152  overlapSignB = t.localydotglobalr[0]
153  else:
154  hitXA = t.hitY[0]
155  hitXB = t.hitY[1]
156  predXA = t.predY[0]
157  predXB = t.predY[1]
158  overlapSignA = t.localydotglobalr[0]
159  overlapSignB = t.localydotglobalr[1]
160 
161  residualA = hitXA - predXA
162  residualB = hitXB - predXB
163  if overlapSignA < 0:
164  residualA *= -1
165  if overlapSignB < 0:
166  residualB *= -1
167  A = 10000*(residualA - residualB)
168  h[subdet_id-1][module_direction][overlap_direction][0].Fill(A)
169  for profile in range(3):
170  if profile_directions[profile+1]:
171  h[subdet_id-1][module_direction][overlap_direction][profile+1].Fill(avgList[profile],A)
172  return h
HitsTree SetDirectory(Hit_Tree)
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
const uint16_t range(const Frame &aFrame)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
#define str(s)
def overlapValidationPlot.plot (   file_name,
  subdet_ids,
  module_directions,
  overlap_directions,
  profile_directions,
  filesTitlesColorsStyles 
)

Definition at line 173 of file overlapValidationPlot.py.

References bitset_utilities.append(), TkAlStyle.drawStandardTitle(), hist(), TkAlStyle.legend(), sistrip::SpyUtilities.range(), and subdetCondition().

174 def plot(file_name,subdet_ids,module_directions,overlap_directions,profile_directions,*filesTitlesColorsStyles):
175 
176  legend=[]
177  hstack=[]
178 
179  for subdet in range(6):#creates lists of empty THStacks and legends to be filled later
180  hstack.append([])
181  legend.append([])
182  for module in range(3):
183  hstack[subdet].append([])
184  legend[subdet].append([])
185  for overlap in range(3):
186  hstack[subdet][module].append([])
187  legend[subdet][module].append([])
188  for profile in range(4):
189  if subdetCondition(subdet,module,overlap):
190  hstack[subdet][module][overlap].append(0)
191  legend[subdet][module][overlap].append(0)
192  continue
193  if not ((subdet_ids[subdet]) and (module_directions[module]) and (profile_directions[profile]) and overlap_directions[overlap]):
194  legend[subdet][module][overlap].append(0)
195  hstack[subdet][module][overlap].append(0)
196  continue
197  else:
198  hstack[subdet][module][overlap].append(ROOT.THStack("hstack",""))
199  legend[subdet][module][overlap].append(TkAlStyle.legend(len(filesTitlesColorsStyles), 1))
200  legend[subdet][module][overlap][profile].SetBorderSize(0)
201  legend[subdet][module][overlap][profile].SetFillStyle(0)
202  for files, title, color, style in filesTitlesColorsStyles:
203  h = hist(files,files.replace("/",""),subdet_ids,module_directions,overlap_directions,profile_directions)
204  for subdet in range(6):
205  for module in range(3):
206  for overlap in range(3):
207  if subdetCondition(subdet,module,overlap):
208  continue
209  for profile in range(4):
210  if not((subdet_ids[subdet]) and (module_directions[module]) and (profile_directions[profile]) and overlap_directions[overlap]):
211  continue
212  g = h[subdet][module][overlap][profile]
213  g.SetLineColor(color)
214  g.SetLineStyle(style)
215  hMean = g.GetMean(1)
216  hMeanError = g.GetMeanError(1)
217  if (profile==0):
218  legend[subdet][module][overlap][profile].AddEntry(g, title + ", mean = {0}#pm{1}#mum ".format(round(hMean,3),round(hMeanError,3)), "l")
219  g.Scale(1 / g.Integral())
220  else:
221  legend[subdet][module][overlap][profile].AddEntry(g, title, "l")
222  hstack[subdet][module][overlap][profile].Add(g)
223  for subdet in range(6):
224  for module in range(3):
225  for overlap in range(3):
226  if subdetCondition(subdet,module,overlap):
227  continue
228  for profile in range(4):
229  if not((subdet_ids[subdet]) and (module_directions[module]) and (profile_directions[profile]) and overlap_directions[overlap]):
230  continue
231  currLegend = legend[subdet][module][overlap][profile]
232  currhstack = hstack[subdet][module][overlap][profile]
233  currhstack.SetMaximum(currhstack.GetMaximum("nostack") * 1.2)
234  c = ROOT.TCanvas()
235  currhstack.Draw("hist nostack" if profile == 0 else "nostack")
236  currLegend.Draw()
237  xTitle = "hit_{A} - pred_{A} - (hit_{B} - pred_{B}) (#mum)"
238  yTitle="fraction of events"
239  save_as_file_name = file_name + "{0}_{1}_{2}".format(dirNameList[module],dirNameList[overlap],detNameList[subdet])
240  if profile>0:
241  save_as_file_name = file_name +"Profiles/profile_{0}_{1}_{2}_{3}".format(dirNameList[module],dirNameList[overlap],detNameList[subdet],dirNameList[profile-1])
242  yTitle= xTitle
243  xTitle= dirNameList[profile-1]
244  currhstack.GetXaxis().SetTitle(xTitle)
245  currhstack.GetYaxis().SetTitle(yTitle)
246  if profile==0:
247  currhstack.GetXaxis().SetNdivisions(404)
248 
250 
251  for ext in "png", "eps", "root", "pdf":
252  c.SaveAs(save_as_file_name+"." +ext)
253 
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
const uint16_t range(const Frame &aFrame)
static void drawStandardTitle()
Definition: TkAlStyle.cc:75
static TLegend * legend(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.cc:109
def overlapValidationPlot.subdetCondition (   subdet,
  module,
  overlap 
)

Definition at line 13 of file overlapValidationPlot.py.

Referenced by plot().

13 
14 def subdetCondition(subdet,module,overlap):
15  if (subdet+1 == 1 and (module == 1 or overlap ==1))or (subdet+1== 2 and (module == 0 or overlap == 0))or ((subdet+1== 3 or subdet+1== 5) and (overlap != 2 or module == 1))or ((subdet+1== 4 or subdet+1== 6) and (overlap != 2 or module == 0)):
16  return True
17  else:
return False

Variable Documentation

tuple overlapValidationPlot.detNameList = ("BPIX", "FPIX", "TIB", "TID", "TOB", "TEC")

Definition at line 12 of file overlapValidationPlot.py.

list overlapValidationPlot.dirNameList = ["z","r","phi"]

Definition at line 11 of file overlapValidationPlot.py.