1 from __future__
import print_function
13 from CondCore.Utilities
import iovInspector
as inspect
14 from ROOT
import TCanvas,TH1F, TH2F, gStyle, TChain, TTree, TLegend, TFile
20 '''List all available tags for a given db ''' 22 db.startReadOnlyTransaction()
24 db.commitTransaction()
25 for tag
in tags.split():
31 '''List all available iovs for a given tag''' 34 iov = inspect.Iov(db,tag)
36 print(
"Available iovs for tag: ",tag)
38 print(
" Since " , p[1],
" Till " , p[2])
40 except Exception
as er :
41 print(
" listIovs exception ",er)
43 def dumpXML(db,tag,since,filename='dump.xml'):
44 '''Dump record in XML format for a given tag ''' 46 iov = inspect.Iov(db,tag)
47 db.startReadOnlyTransaction()
48 Plug = __import__(
str(db.payloadModules(tag)[0]))
49 payload = Plug.Object(db)
50 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
52 for elem
in db.iov(tag).elements :
54 if str(elem.since())==
str(since):
57 db.commitTransaction()
58 payload = inspect.PayLoad(db, tag, elem)
59 out = open(filename,
'w')
60 print(payload, file=out)
62 except Exception
as er :
63 print(
" dumpXML exception ",er)
65 def plot (db, tag,since,filename='plot.root'):
66 '''Invoke the plot function from the wrapper and save to the specified \ 67 file. The file format will reflect the extension given.''' 70 iov = inspect.Iov(db,tag)
71 db.startReadOnlyTransaction()
72 Plug = __import__(
str(db.payloadModules(tag)[0]))
73 payload = Plug.Object(db)
74 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
76 for elem
in db.iov(tag).elements :
78 if str(elem.since())==
str(since):
81 db.commitTransaction()
82 payload = inspect.PayLoad(db, tag, elem)
83 payload.plot(filename,
"",[],[])
85 except Exception
as er :
86 print(
" plot exception ",er)
90 tag2,db2,since2,filename=
'compare.root'):
91 '''Produce comparison plots for two records. Save plots to file \ 92 according to format. tag can be an xml file''' 93 print(
"EcalCondTools.py compare tag1 ", tag1,
"since1 : ", since1,
" tag2 ", tag2,
" s2 ", since2)
101 if tag1.find(
".xml") < 0:
104 db1.startReadOnlyTransaction()
105 Plug = __import__(
str(db1.payloadModules(tag1)[0]))
106 payload = Plug.Object(db1)
107 listOfIovElem= [iovElem
for iovElem
in db1.iov(tag1).elements]
108 what = {
'how':
'barrel'}
109 w = inspect.setWhat(Plug.What(),what)
110 exb = Plug.Extractor(w)
111 what = {
'how':
'endcap'}
112 w = inspect.setWhat(Plug.What(),what)
113 exe = Plug.Extractor(w)
116 print(
" before loop")
117 for elem
in db1.iov(tag1).elements :
118 if str(elem.since())==
str(since1):
122 coeff_1_b = [i
for i
in exb.values()]
124 coeff_1_e = [i
for i
in exe.values()]
125 db1.commitTransaction()
127 except Exception
as er :
128 print(
" compare first set exception ",er)
130 print(
"Could not retrieve payload for tag: " , tag1,
" since: ", since1)
136 if tag2.find(
".xml")<0:
139 db2.startReadOnlyTransaction()
140 Plug = __import__(
str(db2.payloadModules(tag2)[0]))
141 what = {
'how':
'barrel'}
142 w = inspect.setWhat(Plug.What(),what)
143 exb = Plug.Extractor(w)
144 what = {
'how':
'endcap'}
145 w = inspect.setWhat(Plug.What(),what)
146 exe = Plug.Extractor(w)
149 for elem
in db2.iov(tag2).elements :
150 if str(elem.since())==
str(since2):
154 coeff_2_b = [i
for i
in exb.values()]
156 coeff_2_e = [i
for i
in exe.values()]
157 db2.commitTransaction()
159 except Exception
as er :
160 print(
" compare second set exception ",er)
162 print(
"Could not retrieve payload for tag: " , tag2,
" since: ", since2)
170 savefile = TFile(filename,
"RECREATE")
172 ebhisto,ebmap, profx, profy=
compareBarrel(coeff_1_b,coeff_2_b)
173 eephisto,eepmap,eemhisto,eemmap=
compareEndcap(coeff_1_e,coeff_2_e)
208 eeborderphisto,eeborderpmap,eebordermhisto,eebordermmap=
compareEndcapBorder(coeff_1_e,coeff_2_e)
211 border_diff_distro_can = TCanvas(
"border_difference",
"borders difference")
212 border_diff_distro_can.Divide(2,3)
214 border_diff_distro_can.cd(1)
216 border_diff_distro_can.cd(2)
217 ebbordermap.Draw(
"colz")
218 border_diff_distro_can.cd(3)
219 eeborderphisto.Draw()
220 border_diff_distro_can.cd(4)
221 eeborderpmap.Draw(
"colz")
222 border_diff_distro_can.cd(5)
223 eebordermhisto.Draw()
224 border_diff_distro_can.cd(6)
225 eebordermmap.Draw(
"colz")
227 bordersfilename =
"borders_"+filename
228 prof_filename =
"profiles_"+filename
236 def histo (db, tag,since,filename='histo.root'):
237 '''Make histograms and save to file. tag can be an xml file''' 242 if tag.find(
".xml")< 0:
246 db.startReadOnlyTransaction()
247 Plug = __import__(
str(db.payloadModules(tag)[0]))
248 payload = Plug.Object(db)
249 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
250 what = {
'how':
'barrel'}
251 w = inspect.setWhat(Plug.What(),what)
252 exb = Plug.Extractor(w)
253 what = {
'how':
'endcap'}
254 w = inspect.setWhat(Plug.What(),what)
255 exe = Plug.Extractor(w)
256 for elem
in db.iov(tag).elements :
257 if str(elem.since())==
str(since):
261 coeff_barl = [i
for i
in exb.values()]
263 coeff_endc = [i
for i
in exe.values()]
264 db.commitTransaction()
266 except Exception
as er :
267 print(
" histo exception ",er)
269 print(
"Could not retrieve payload for tag: " , tag,
" since: ", since)
275 savefile = TFile(filename,
"RECREATE")
277 ebmap, ebeta, ebphi, eePmap, ebdist, eeMmap, prof_eePL, prof_eePR, prof_eeML, prof_eeMR, ebBorderdist =
makedist(coeff_barl, coeff_endc)
281 c = TCanvas(
"CCdist")
295 prof_eb_eta = ebeta.ProfileX()
296 prof_eb_phi = ebphi.ProfileX()
298 c2 = TCanvas(
"CCprofiles")
301 leg = TLegend(0.1,0.7,0.48,0.9)
308 prof_eePL.SetMarkerStyle(8)
310 prof_eePR.SetMarkerStyle(8)
311 prof_eePR.SetMarkerColor(2)
312 prof_eePR.Draw(
"same")
313 prof_eeML.SetMarkerStyle(8)
314 prof_eeML.SetMarkerColor(3)
315 prof_eeML.Draw(
"same")
316 prof_eeMR.SetMarkerStyle(8)
317 prof_eeMR.SetMarkerColor(5)
318 prof_eeMR.Draw(
"same")
319 leg.AddEntry(prof_eePL,
"Dee1",
"lp")
320 leg.AddEntry(prof_eePR,
"Dee2",
"lp")
321 leg.AddEntry(prof_eeMR,
"Dee3",
"lp")
322 leg.AddEntry(prof_eeML,
"Dee4",
"lp")
327 extrafilename =
"profiles_"+filename
334 ''' Return payload token for a given iov, tag, db''' 336 iov = inspect.Iov(db,tag)
340 if str(tmpsince)==
str(since) :
342 print(
"Could not retrieve token for tag: " , tag,
" since: ", since)
345 except Exception
as er :
350 ''' Return payload object for a given iov, tag, db''' 354 db.startReadOnlyTransaction()
355 Plug = __import__(
str(db.payloadModules(tag)[0]))
356 print(
" getObject Plug")
357 payload = Plug.Object(db)
358 db.commitTransaction()
359 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
360 print(
" getObject before loop")
361 for elem
in db.iov(tag).elements :
362 if str(elem.since())==
str(since):
364 print(
" getObject found ", elem.since())
368 except Exception
as er :
369 print(
" getObject exception ",er)
372 print(
"Could not retrieve payload for tag: " , tag,
" since: ", since)
378 ebmap = TH2F(
"EB",
"EB",360,1,261,171, -85,86)
379 eePmap = TH2F(
"EE",
"EE",100, 1,101,100,1,101)
380 eeMmap = TH2F(
"EEminus",
"EEminus",100,1,101,100,1,101)
381 ebdist = TH1F(
"EBdist",
"EBdist",100,-2,2)
382 ebBorderdist = TH1F(
"EBBorderdist",
"EBBorderdist",100,-2,2)
384 ebeta = TH2F(
"ebeta",
"ebeta",171,-85,86,100,-2,2)
385 ebphi = TH2F(
"ebphi",
"ebphi",360,1,361,100,-2,2)
387 eePL = TH2F(
"EEPL",
"EEPlus Left",50,10,55,100,-2,2)
388 eePR = TH2F(
"EEPR",
"EEPlus Right",50,10,55,100,-2,2)
389 eeML = TH2F(
"EEML",
"EEMinus Left",50,10,55,100,-2,2)
390 eeMR = TH2F(
"EEMR",
"EEMinus Right",50,10,55,100,-2,2)
392 for i,c
in enumerate(coeff_barl):
394 ebmap.Fill(iphi,ieta,c)
399 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):
403 for i,c
in enumerate(coeff_endc):
405 R =
sqrt((ix-50)*(ix-50)+(iy-50)*(iy-50))
421 prof_eePL = eePL.ProfileX()
422 prof_eePR = eePR.ProfileX()
423 prof_eeML = eeML.ProfileX()
424 prof_eeMR = eeMR.ProfileX()
426 return ebmap, ebeta, ebphi, eePmap, ebdist, eeMmap, prof_eePL, prof_eePR, prof_eeML, prof_eeMR, ebBorderdist
429 '''Return an histogram and a map of the differences ''' 431 diff_distro_h = TH1F(
"diffh",
"diffh",100,-2,2)
432 diff_distro_m = TH2F(
"diffm",
"diffm",360,1,361,171,-85,86)
433 diff_distro_m.SetStats(0)
434 ebeta = TH2F(
"ebeta",
"ebeta",171,-85,86,100,-2,2)
435 ebphi = TH2F(
"ebphi",
"ebphi",360,1,361,100,-2,2)
438 for i,c
in enumerate(coeff_barl_1):
439 diff = c - coeff_barl_2[i]
441 diff_distro_h.Fill(diff)
442 diff_distro_m.Fill(iphi,ieta,diff)
443 ebeta.Fill(ieta,diff)
444 ebphi.Fill(iphi,diff)
446 prof_x_h = ebeta.ProfileX()
447 prof_y_h = ebphi.ProfileX()
449 return diff_distro_h, diff_distro_m, prof_x_h, prof_y_h
454 '''Return an histogram and a map of the differences ''' 456 diff_distro_border_h = TH1F(
"diffborderh",
"diffh",100,-2,2)
457 diff_distro_border_m = TH2F(
"diffborderm",
"diffm",360,1,361,171,-85,86)
458 diff_distro_border_m.SetStats(0)
460 for i,c
in enumerate(coeff_barl_1):
461 diff = c - coeff_barl_2[i]
463 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):
464 diff_distro_border_h.Fill(diff)
465 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):
466 diff_distro_border_m.Fill(iphi,ieta,diff)
468 return diff_distro_border_h, diff_distro_border_m
475 ''' Return an histogram and a map of the differences for each endcap''' 477 diff_distro_h_eep = TH1F(
"diff EE+",
"diff EE+",100,-2,2)
478 diff_distro_h_eem = TH1F(
"diff EE-",
"diff EE-",100,-2,2)
481 diff_distro_m_eep = TH2F(
"map EE+",
"map EE+",100,1,101,100,1,101)
482 diff_distro_m_eem = TH2F(
"map EE-",
"map EE-",100,1,101,100,1,101)
484 temp_h = TH1F(
"tempR",
"tempR",50,0,50)
486 diff_distro_m_eep.SetStats(0)
487 diff_distro_m_eem.SetStats(0)
490 for i,c
in enumerate(coeff_endc_1):
491 diff = c - coeff_endc_2[i]
493 R =
sqrt((ix-50)*(ix-50)+(iy-50)*(iy-50))
496 diff_distro_h_eep.Fill(diff)
497 diff_distro_m_eep.Fill(ix,iy,diff)
500 diff_distro_h_eem.Fill(diff)
501 diff_distro_m_eem.Fill(ix,iy,diff)
503 return diff_distro_h_eep, \
511 ''' Return an histogram and a map of the differences for each endcap''' 513 border_diff_distro_h_eep = TH1F(
"borderdiff EE+",
"diff EE+",100,-2,2)
514 border_diff_distro_h_eem = TH1F(
"borderdiff EE-",
"diff EE-",100,-2,2)
517 border_diff_distro_m_eep = TH2F(
"bordermap EE+",
"map EE+",100,1,101,100,1,101)
518 border_diff_distro_m_eem = TH2F(
"bordermap EE-",
"map EE-",100,1,101,100,1,101)
520 border_diff_distro_m_eep.SetStats(0)
521 border_diff_distro_m_eem.SetStats(0)
524 for i,c
in enumerate(coeff_endc_1):
525 diff = c - coeff_endc_2[i]
527 Rsq = ((ix-50.0)**2+(iy-50.0)**2)
529 if (iz >0
and (Rsq<144.0
or Rsq>2500.0)):
530 border_diff_distro_h_eep.Fill(diff)
531 border_diff_distro_m_eep.Fill(ix,iy,diff)
532 elif (iz<0
and (Rsq<144.0
or Rsq>2500.0)):
533 border_diff_distro_h_eem.Fill(diff)
534 border_diff_distro_m_eem.Fill(ix,iy,diff)
537 return border_diff_distro_h_eep, \
538 border_diff_distro_m_eep, \
539 border_diff_distro_h_eem, \
540 border_diff_distro_m_eem
S & print(S &os, JobReport::InputFile const &f)
Abs< T >::type abs(const T &t)