1 from __future__
import print_function
2 from __future__
import absolute_import
14 from CondCore.Utilities
import iovInspector
as inspect
15 from ROOT
import TCanvas,TH1F, TH2F, gStyle, TChain, TTree, TLegend, TFile
16 from .
import EcalPyUtils
21 '''List all available tags for a given db '''
23 db.startReadOnlyTransaction()
25 db.commitTransaction()
26 for tag
in tags.split():
32 '''List all available iovs for a given tag'''
35 iov = inspect.Iov(db,tag)
37 print(
"Available iovs for tag: ",tag)
39 print(
" Since " , p[1],
" Till " , p[2])
41 except Exception
as er :
42 print(
" listIovs exception ",er)
44 def dumpXML(db,tag,since,filename='dump.xml'):
45 '''Dump record in XML format for a given tag '''
47 iov = inspect.Iov(db,tag)
48 db.startReadOnlyTransaction()
49 Plug = __import__(
str(db.payloadModules(tag)[0]))
50 payload = Plug.Object(db)
51 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
53 for elem
in db.iov(tag).elements :
55 if str(elem.since())==
str(since):
58 db.commitTransaction()
59 payload = inspect.PayLoad(db, tag, elem)
60 out = open(filename,
'w')
61 print(payload, file=out)
63 except Exception
as er :
64 print(
" dumpXML exception ",er)
66 def plot (db, tag,since,filename='plot.root'):
67 '''Invoke the plot function from the wrapper and save to the specified \
68 file. The file format will reflect the extension given.'''
71 iov = inspect.Iov(db,tag)
72 db.startReadOnlyTransaction()
73 Plug = __import__(
str(db.payloadModules(tag)[0]))
74 payload = Plug.Object(db)
75 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
77 for elem
in db.iov(tag).elements :
79 if str(elem.since())==
str(since):
82 db.commitTransaction()
83 payload = inspect.PayLoad(db, tag, elem)
84 payload.plot(filename,
"",[],[])
86 except Exception
as er :
87 print(
" plot exception ",er)
91 tag2,db2,since2,filename='compare.root'):
92 '''Produce comparison plots for two records. Save plots to file \
93 according to format. tag can be an xml file'''
94 print(
"EcalCondTools.py compare tag1 ", tag1,
"since1 : ", since1,
" tag2 ", tag2,
" s2 ", since2)
102 if tag1.find(
".xml") < 0:
105 db1.startReadOnlyTransaction()
106 Plug = __import__(
str(db1.payloadModules(tag1)[0]))
107 payload = Plug.Object(db1)
108 listOfIovElem= [iovElem
for iovElem
in db1.iov(tag1).elements]
109 what = {
'how':
'barrel'}
110 w = inspect.setWhat(Plug.What(),what)
111 exb = Plug.Extractor(w)
112 what = {
'how':
'endcap'}
113 w = inspect.setWhat(Plug.What(),what)
114 exe = Plug.Extractor(w)
117 print(
" before loop")
118 for elem
in db1.iov(tag1).elements :
119 if str(elem.since())==
str(since1):
123 coeff_1_b = [i
for i
in exb.values()]
125 coeff_1_e = [i
for i
in exe.values()]
126 db1.commitTransaction()
128 except Exception
as er :
129 print(
" compare first set exception ",er)
131 print(
"Could not retrieve payload for tag: " , tag1,
" since: ", since1)
137 if tag2.find(
".xml")<0:
140 db2.startReadOnlyTransaction()
141 Plug = __import__(
str(db2.payloadModules(tag2)[0]))
142 what = {
'how':
'barrel'}
143 w = inspect.setWhat(Plug.What(),what)
144 exb = Plug.Extractor(w)
145 what = {
'how':
'endcap'}
146 w = inspect.setWhat(Plug.What(),what)
147 exe = Plug.Extractor(w)
150 for elem
in db2.iov(tag2).elements :
151 if str(elem.since())==
str(since2):
155 coeff_2_b = [i
for i
in exb.values()]
157 coeff_2_e = [i
for i
in exe.values()]
158 db2.commitTransaction()
160 except Exception
as er :
161 print(
" compare second set exception ",er)
163 print(
"Could not retrieve payload for tag: " , tag2,
" since: ", since2)
171 savefile = TFile(filename,
"RECREATE")
173 ebhisto,ebmap, profx, profy=
compareBarrel(coeff_1_b,coeff_2_b)
174 eephisto,eepmap,eemhisto,eemmap=
compareEndcap(coeff_1_e,coeff_2_e)
209 eeborderphisto,eeborderpmap,eebordermhisto,eebordermmap=
compareEndcapBorder(coeff_1_e,coeff_2_e)
212 border_diff_distro_can = TCanvas(
"border_difference",
"borders difference")
213 border_diff_distro_can.Divide(2,3)
215 border_diff_distro_can.cd(1)
217 border_diff_distro_can.cd(2)
218 ebbordermap.Draw(
"colz")
219 border_diff_distro_can.cd(3)
220 eeborderphisto.Draw()
221 border_diff_distro_can.cd(4)
222 eeborderpmap.Draw(
"colz")
223 border_diff_distro_can.cd(5)
224 eebordermhisto.Draw()
225 border_diff_distro_can.cd(6)
226 eebordermmap.Draw(
"colz")
228 bordersfilename =
"borders_"+filename
229 prof_filename =
"profiles_"+filename
237 def histo (db, tag,since,filename='histo.root'):
238 '''Make histograms and save to file. tag can be an xml file'''
243 if tag.find(
".xml")< 0:
247 db.startReadOnlyTransaction()
248 Plug = __import__(
str(db.payloadModules(tag)[0]))
249 payload = Plug.Object(db)
250 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
251 what = {
'how':
'barrel'}
252 w = inspect.setWhat(Plug.What(),what)
253 exb = Plug.Extractor(w)
254 what = {
'how':
'endcap'}
255 w = inspect.setWhat(Plug.What(),what)
256 exe = Plug.Extractor(w)
257 for elem
in db.iov(tag).elements :
258 if str(elem.since())==
str(since):
262 coeff_barl = [i
for i
in exb.values()]
264 coeff_endc = [i
for i
in exe.values()]
265 db.commitTransaction()
267 except Exception
as er :
268 print(
" histo exception ",er)
270 print(
"Could not retrieve payload for tag: " , tag,
" since: ", since)
276 savefile = TFile(filename,
"RECREATE")
278 ebmap, ebeta, ebphi, eePmap, ebdist, eeMmap, prof_eePL, prof_eePR, prof_eeML, prof_eeMR, ebBorderdist =
makedist(coeff_barl, coeff_endc)
282 c = TCanvas(
"CCdist")
296 prof_eb_eta = ebeta.ProfileX()
297 prof_eb_phi = ebphi.ProfileX()
299 c2 = TCanvas(
"CCprofiles")
302 leg = TLegend(0.1,0.7,0.48,0.9)
309 prof_eePL.SetMarkerStyle(8)
311 prof_eePR.SetMarkerStyle(8)
312 prof_eePR.SetMarkerColor(2)
313 prof_eePR.Draw(
"same")
314 prof_eeML.SetMarkerStyle(8)
315 prof_eeML.SetMarkerColor(3)
316 prof_eeML.Draw(
"same")
317 prof_eeMR.SetMarkerStyle(8)
318 prof_eeMR.SetMarkerColor(5)
319 prof_eeMR.Draw(
"same")
320 leg.AddEntry(prof_eePL,
"Dee1",
"lp")
321 leg.AddEntry(prof_eePR,
"Dee2",
"lp")
322 leg.AddEntry(prof_eeMR,
"Dee3",
"lp")
323 leg.AddEntry(prof_eeML,
"Dee4",
"lp")
328 extrafilename =
"profiles_"+filename
335 ''' Return payload token for a given iov, tag, db'''
337 iov = inspect.Iov(db,tag)
341 if str(tmpsince)==
str(since) :
343 print(
"Could not retrieve token for tag: " , tag,
" since: ", since)
346 except Exception
as er :
351 ''' Return payload object for a given iov, tag, db'''
355 db.startReadOnlyTransaction()
356 Plug = __import__(
str(db.payloadModules(tag)[0]))
357 print(
" getObject Plug")
358 payload = Plug.Object(db)
359 db.commitTransaction()
360 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
361 print(
" getObject before loop")
362 for elem
in db.iov(tag).elements :
363 if str(elem.since())==
str(since):
365 print(
" getObject found ", elem.since())
369 except Exception
as er :
370 print(
" getObject exception ",er)
373 print(
"Could not retrieve payload for tag: " , tag,
" since: ", since)
379 ebmap = TH2F(
"EB",
"EB",360,1,261,171, -85,86)
380 eePmap = TH2F(
"EE",
"EE",100, 1,101,100,1,101)
381 eeMmap = TH2F(
"EEminus",
"EEminus",100,1,101,100,1,101)
382 ebdist = TH1F(
"EBdist",
"EBdist",100,-2,2)
383 ebBorderdist = TH1F(
"EBBorderdist",
"EBBorderdist",100,-2,2)
385 ebeta = TH2F(
"ebeta",
"ebeta",171,-85,86,100,-2,2)
386 ebphi = TH2F(
"ebphi",
"ebphi",360,1,361,100,-2,2)
388 eePL = TH2F(
"EEPL",
"EEPlus Left",50,10,55,100,-2,2)
389 eePR = TH2F(
"EEPR",
"EEPlus Right",50,10,55,100,-2,2)
390 eeML = TH2F(
"EEML",
"EEMinus Left",50,10,55,100,-2,2)
391 eeMR = TH2F(
"EEMR",
"EEMinus Right",50,10,55,100,-2,2)
393 for i,c
in enumerate(coeff_barl):
395 ebmap.Fill(iphi,ieta,c)
400 if (
abs(ieta)==85
or abs(ieta)==65
or abs(ieta)==64
or abs(ieta)==45
or abs(ieta)==44
or abs(ieta)==25
or abs(ieta)==24
or abs(ieta)==1
or iphi%20==1
or iphi%20==0):
404 for i,c
in enumerate(coeff_endc):
406 R =
sqrt((ix-50)*(ix-50)+(iy-50)*(iy-50))
422 prof_eePL = eePL.ProfileX()
423 prof_eePR = eePR.ProfileX()
424 prof_eeML = eeML.ProfileX()
425 prof_eeMR = eeMR.ProfileX()
427 return ebmap, ebeta, ebphi, eePmap, ebdist, eeMmap, prof_eePL, prof_eePR, prof_eeML, prof_eeMR, ebBorderdist
430 '''Return an histogram and a map of the differences '''
432 diff_distro_h = TH1F(
"diffh",
"diffh",100,-2,2)
433 diff_distro_m = TH2F(
"diffm",
"diffm",360,1,361,171,-85,86)
434 diff_distro_m.SetStats(0)
435 ebeta = TH2F(
"ebeta",
"ebeta",171,-85,86,100,-2,2)
436 ebphi = TH2F(
"ebphi",
"ebphi",360,1,361,100,-2,2)
439 for i,c
in enumerate(coeff_barl_1):
440 diff = c - coeff_barl_2[i]
442 diff_distro_h.Fill(diff)
443 diff_distro_m.Fill(iphi,ieta,diff)
444 ebeta.Fill(ieta,diff)
445 ebphi.Fill(iphi,diff)
447 prof_x_h = ebeta.ProfileX()
448 prof_y_h = ebphi.ProfileX()
450 return diff_distro_h, diff_distro_m, prof_x_h, prof_y_h
455 '''Return an histogram and a map of the differences '''
457 diff_distro_border_h = TH1F(
"diffborderh",
"diffh",100,-2,2)
458 diff_distro_border_m = TH2F(
"diffborderm",
"diffm",360,1,361,171,-85,86)
459 diff_distro_border_m.SetStats(0)
461 for i,c
in enumerate(coeff_barl_1):
462 diff = c - coeff_barl_2[i]
464 if (
abs(ieta)==85
or abs(ieta)==65
or abs(ieta)==64
or abs(ieta)==45
or abs(ieta)==44
or abs(ieta)==25
or abs(ieta)==24
or abs(ieta)==1
or iphi%20==1
or iphi%20==0):
465 diff_distro_border_h.Fill(diff)
466 if (
abs(ieta)==85
or abs(ieta)==65
or abs(ieta)==64
or abs(ieta)==45
or abs(ieta)==44
or abs(ieta)==25
or abs(ieta)==24
or abs(ieta)==1
or iphi%20==0
or iphi%20==1):
467 diff_distro_border_m.Fill(iphi,ieta,diff)
469 return diff_distro_border_h, diff_distro_border_m
476 ''' Return an histogram and a map of the differences for each endcap'''
478 diff_distro_h_eep = TH1F(
"diff EE+",
"diff EE+",100,-2,2)
479 diff_distro_h_eem = TH1F(
"diff EE-",
"diff EE-",100,-2,2)
482 diff_distro_m_eep = TH2F(
"map EE+",
"map EE+",100,1,101,100,1,101)
483 diff_distro_m_eem = TH2F(
"map EE-",
"map EE-",100,1,101,100,1,101)
485 temp_h = TH1F(
"tempR",
"tempR",50,0,50)
487 diff_distro_m_eep.SetStats(0)
488 diff_distro_m_eem.SetStats(0)
491 for i,c
in enumerate(coeff_endc_1):
492 diff = c - coeff_endc_2[i]
494 R =
sqrt((ix-50)*(ix-50)+(iy-50)*(iy-50))
497 diff_distro_h_eep.Fill(diff)
498 diff_distro_m_eep.Fill(ix,iy,diff)
501 diff_distro_h_eem.Fill(diff)
502 diff_distro_m_eem.Fill(ix,iy,diff)
504 return diff_distro_h_eep, \
512 ''' Return an histogram and a map of the differences for each endcap'''
514 border_diff_distro_h_eep = TH1F(
"borderdiff EE+",
"diff EE+",100,-2,2)
515 border_diff_distro_h_eem = TH1F(
"borderdiff EE-",
"diff EE-",100,-2,2)
518 border_diff_distro_m_eep = TH2F(
"bordermap EE+",
"map EE+",100,1,101,100,1,101)
519 border_diff_distro_m_eem = TH2F(
"bordermap EE-",
"map EE-",100,1,101,100,1,101)
521 border_diff_distro_m_eep.SetStats(0)
522 border_diff_distro_m_eem.SetStats(0)
525 for i,c
in enumerate(coeff_endc_1):
526 diff = c - coeff_endc_2[i]
528 Rsq = ((ix-50.0)**2+(iy-50.0)**2)
530 if (iz >0
and (Rsq<144.0
or Rsq>2500.0)):
531 border_diff_distro_h_eep.Fill(diff)
532 border_diff_distro_m_eep.Fill(ix,iy,diff)
533 elif (iz<0
and (Rsq<144.0
or Rsq>2500.0)):
534 border_diff_distro_h_eem.Fill(diff)
535 border_diff_distro_m_eem.Fill(ix,iy,diff)
538 return border_diff_distro_h_eep, \
539 border_diff_distro_m_eep, \
540 border_diff_distro_h_eem, \
541 border_diff_distro_m_eem