12 from CondCore.Utilities
import iovInspector
as inspect
13 from ROOT
import TCanvas,TH1F, TH2F, gStyle, TChain, TTree, TLegend, TFile
19 '''List all available tags for a given db '''
21 db.startReadOnlyTransaction()
23 db.commitTransaction()
24 for tag
in tags.split():
30 '''List all available iovs for a given tag'''
33 iov = inspect.Iov(db,tag)
35 print "Available iovs for tag: ",tag
37 print " Since " , p[1],
" Till " , p[2]
40 print " listIovs exception ",er
42 def dumpXML(db,tag,since,filename='dump.xml'):
43 '''Dump record in XML format for a given tag '''
45 iov = inspect.Iov(db,tag)
46 db.startReadOnlyTransaction()
47 Plug = __import__(str(db.payloadModules(tag)[0]))
48 payload = Plug.Object(db)
49 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
51 for elem
in db.iov(tag).elements :
53 if str(elem.since())==str(since):
56 db.commitTransaction()
57 payload = inspect.PayLoad(db, tag, elem)
58 out = open(filename,
'w')
62 print " dumpXML exception ",er
64 def plot (db, tag,since,filename='plot.root'):
65 '''Invoke the plot function from the wrapper and save to the specified \
66 file. The file format will reflect the extension given.'''
69 iov = inspect.Iov(db,tag)
70 db.startReadOnlyTransaction()
71 Plug = __import__(str(db.payloadModules(tag)[0]))
72 payload = Plug.Object(db)
73 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
75 for elem
in db.iov(tag).elements :
77 if str(elem.since())==str(since):
80 db.commitTransaction()
81 payload = inspect.PayLoad(db, tag, elem)
82 payload.plot(filename,
"",[],[])
85 print " plot exception ",er
89 tag2,db2,since2,filename=
'compare.root'):
90 '''Produce comparison plots for two records. Save plots to file \
91 according to format. tag can be an xml file'''
92 print "EcalCondTools.py compare tag1 ", tag1,
"since1 : ", since1,
" tag2 ", tag2,
" s2 ", since2
100 if tag1.find(
".xml") < 0:
103 db1.startReadOnlyTransaction()
104 Plug = __import__(str(db1.payloadModules(tag1)[0]))
105 payload = Plug.Object(db1)
106 listOfIovElem= [iovElem
for iovElem
in db1.iov(tag1).elements]
107 what = {
'how':
'barrel'}
108 w = inspect.setWhat(Plug.What(),what)
109 exb = Plug.Extractor(w)
110 what = {
'how':
'endcap'}
111 w = inspect.setWhat(Plug.What(),what)
112 exe = Plug.Extractor(w)
116 for elem
in db1.iov(tag1).elements :
117 if str(elem.since())==str(since1):
121 coeff_1_b = [i
for i
in exb.values()]
123 coeff_1_e = [i
for i
in exe.values()]
124 db1.commitTransaction()
126 except Exception,er :
127 print " compare first set exception ",er
129 print "Could not retrieve payload for tag: " , tag1,
" since: ", since1
135 if tag2.find(
".xml")<0:
138 db2.startReadOnlyTransaction()
139 Plug = __import__(str(db2.payloadModules(tag2)[0]))
140 what = {
'how':
'barrel'}
141 w = inspect.setWhat(Plug.What(),what)
142 exb = Plug.Extractor(w)
143 what = {
'how':
'endcap'}
144 w = inspect.setWhat(Plug.What(),what)
145 exe = Plug.Extractor(w)
148 for elem
in db2.iov(tag2).elements :
149 if str(elem.since())==str(since2):
153 coeff_2_b = [i
for i
in exb.values()]
155 coeff_2_e = [i
for i
in exe.values()]
156 db2.commitTransaction()
158 except Exception, er :
159 print " compare second set exception ",er
161 print "Could not retrieve payload for tag: " , tag2,
" since: ", since2
169 savefile = TFile(filename,
"RECREATE")
171 ebhisto,ebmap, profx, profy=
compareBarrel(coeff_1_b,coeff_2_b)
172 eephisto,eepmap,eemhisto,eemmap=
compareEndcap(coeff_1_e,coeff_2_e)
207 eeborderphisto,eeborderpmap,eebordermhisto,eebordermmap=
compareEndcapBorder(coeff_1_e,coeff_2_e)
210 border_diff_distro_can = TCanvas(
"border_difference",
"borders difference")
211 border_diff_distro_can.Divide(2,3)
213 border_diff_distro_can.cd(1)
215 border_diff_distro_can.cd(2)
216 ebbordermap.Draw(
"colz")
217 border_diff_distro_can.cd(3)
218 eeborderphisto.Draw()
219 border_diff_distro_can.cd(4)
220 eeborderpmap.Draw(
"colz")
221 border_diff_distro_can.cd(5)
222 eebordermhisto.Draw()
223 border_diff_distro_can.cd(6)
224 eebordermmap.Draw(
"colz")
226 bordersfilename =
"borders_"+filename
227 prof_filename =
"profiles_"+filename
235 def histo (db, tag,since,filename='histo.root'):
236 '''Make histograms and save to file. tag can be an xml file'''
241 if tag.find(
".xml")< 0:
245 db.startReadOnlyTransaction()
246 Plug = __import__(str(db.payloadModules(tag)[0]))
247 payload = Plug.Object(db)
248 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
249 what = {
'how':
'barrel'}
250 w = inspect.setWhat(Plug.What(),what)
251 exb = Plug.Extractor(w)
252 what = {
'how':
'endcap'}
253 w = inspect.setWhat(Plug.What(),what)
254 exe = Plug.Extractor(w)
255 for elem
in db.iov(tag).elements :
256 if str(elem.since())==str(since):
260 coeff_barl = [i
for i
in exb.values()]
262 coeff_endc = [i
for i
in exe.values()]
263 db.commitTransaction()
265 except Exception, er :
266 print " histo exception ",er
268 print "Could not retrieve payload for tag: " , tag,
" since: ", since
274 savefile = TFile(filename,
"RECREATE")
276 ebmap, ebeta, ebphi, eePmap, ebdist, eeMmap, prof_eePL, prof_eePR, prof_eeML, prof_eeMR, ebBorderdist =
makedist(coeff_barl, coeff_endc)
280 c = TCanvas(
"CCdist")
294 prof_eb_eta = ebeta.ProfileX()
295 prof_eb_phi = ebphi.ProfileX()
297 c2 = TCanvas(
"CCprofiles")
300 leg = TLegend(0.1,0.7,0.48,0.9)
307 prof_eePL.SetMarkerStyle(8)
309 prof_eePR.SetMarkerStyle(8)
310 prof_eePR.SetMarkerColor(2)
311 prof_eePR.Draw(
"same")
312 prof_eeML.SetMarkerStyle(8)
313 prof_eeML.SetMarkerColor(3)
314 prof_eeML.Draw(
"same")
315 prof_eeMR.SetMarkerStyle(8)
316 prof_eeMR.SetMarkerColor(5)
317 prof_eeMR.Draw(
"same")
318 leg.AddEntry(prof_eePL,
"Dee1",
"lp")
319 leg.AddEntry(prof_eePR,
"Dee2",
"lp")
320 leg.AddEntry(prof_eeMR,
"Dee3",
"lp")
321 leg.AddEntry(prof_eeML,
"Dee4",
"lp")
326 extrafilename =
"profiles_"+filename
333 ''' Return payload token for a given iov, tag, db'''
335 iov = inspect.Iov(db,tag)
339 if str(tmpsince)==str(since) :
341 print "Could not retrieve token for tag: " , tag,
" since: ", since
344 except Exception, er :
349 ''' Return payload object for a given iov, tag, db'''
353 db.startReadOnlyTransaction()
354 Plug = __import__(str(db.payloadModules(tag)[0]))
355 print " getObject Plug"
356 payload = Plug.Object(db)
357 db.commitTransaction()
358 listOfIovElem= [iovElem
for iovElem
in db.iov(tag).elements]
359 print " getObject before loop"
360 for elem
in db.iov(tag).elements :
361 if str(elem.since())==str(since):
363 print " getObject found ", elem.since()
367 except Exception, er :
368 print " getObject exception ",er
371 print "Could not retrieve payload for tag: " , tag,
" since: ", since
377 ebmap = TH2F(
"EB",
"EB",360,1,261,171, -85,86)
378 eePmap = TH2F(
"EE",
"EE",100, 1,101,100,1,101)
379 eeMmap = TH2F(
"EEminus",
"EEminus",100,1,101,100,1,101)
380 ebdist = TH1F(
"EBdist",
"EBdist",100,-2,2)
381 ebBorderdist = TH1F(
"EBBorderdist",
"EBBorderdist",100,-2,2)
383 ebeta = TH2F(
"ebeta",
"ebeta",171,-85,86,100,-2,2)
384 ebphi = TH2F(
"ebphi",
"ebphi",360,1,361,100,-2,2)
386 eePL = TH2F(
"EEPL",
"EEPlus Left",50,10,55,100,-2,2)
387 eePR = TH2F(
"EEPR",
"EEPlus Right",50,10,55,100,-2,2)
388 eeML = TH2F(
"EEML",
"EEMinus Left",50,10,55,100,-2,2)
389 eeMR = TH2F(
"EEMR",
"EEMinus Right",50,10,55,100,-2,2)
391 for i,c
in enumerate(coeff_barl):
393 ebmap.Fill(iphi,ieta,c)
398 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):
402 for i,c
in enumerate(coeff_endc):
404 R =
sqrt((ix-50)*(ix-50)+(iy-50)*(iy-50))
420 prof_eePL = eePL.ProfileX()
421 prof_eePR = eePR.ProfileX()
422 prof_eeML = eeML.ProfileX()
423 prof_eeMR = eeMR.ProfileX()
425 return ebmap, ebeta, ebphi, eePmap, ebdist, eeMmap, prof_eePL, prof_eePR, prof_eeML, prof_eeMR, ebBorderdist
428 '''Return an histogram and a map of the differences '''
430 diff_distro_h = TH1F(
"diffh",
"diffh",100,-2,2)
431 diff_distro_m = TH2F(
"diffm",
"diffm",360,1,361,171,-85,86)
432 diff_distro_m.SetStats(0)
433 ebeta = TH2F(
"ebeta",
"ebeta",171,-85,86,100,-2,2)
434 ebphi = TH2F(
"ebphi",
"ebphi",360,1,361,100,-2,2)
437 for i,c
in enumerate(coeff_barl_1):
438 diff = c - coeff_barl_2[i]
440 diff_distro_h.Fill(diff)
441 diff_distro_m.Fill(iphi,ieta,diff)
442 ebeta.Fill(ieta,diff)
443 ebphi.Fill(iphi,diff)
445 prof_x_h = ebeta.ProfileX()
446 prof_y_h = ebphi.ProfileX()
448 return diff_distro_h, diff_distro_m, prof_x_h, prof_y_h
453 '''Return an histogram and a map of the differences '''
455 diff_distro_border_h = TH1F(
"diffborderh",
"diffh",100,-2,2)
456 diff_distro_border_m = TH2F(
"diffborderm",
"diffm",360,1,361,171,-85,86)
457 diff_distro_border_m.SetStats(0)
459 for i,c
in enumerate(coeff_barl_1):
460 diff = c - coeff_barl_2[i]
462 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):
463 diff_distro_border_h.Fill(diff)
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==0
or iphi%20==1):
465 diff_distro_border_m.Fill(iphi,ieta,diff)
467 return diff_distro_border_h, diff_distro_border_m
474 ''' Return an histogram and a map of the differences for each endcap'''
476 diff_distro_h_eep = TH1F(
"diff EE+",
"diff EE+",100,-2,2)
477 diff_distro_h_eem = TH1F(
"diff EE-",
"diff EE-",100,-2,2)
480 diff_distro_m_eep = TH2F(
"map EE+",
"map EE+",100,1,101,100,1,101)
481 diff_distro_m_eem = TH2F(
"map EE-",
"map EE-",100,1,101,100,1,101)
483 temp_h = TH1F(
"tempR",
"tempR",50,0,50)
485 diff_distro_m_eep.SetStats(0)
486 diff_distro_m_eem.SetStats(0)
489 for i,c
in enumerate(coeff_endc_1):
490 diff = c - coeff_endc_2[i]
492 R =
sqrt((ix-50)*(ix-50)+(iy-50)*(iy-50))
495 diff_distro_h_eep.Fill(diff)
496 diff_distro_m_eep.Fill(ix,iy,diff)
499 diff_distro_h_eem.Fill(diff)
500 diff_distro_m_eem.Fill(ix,iy,diff)
502 return diff_distro_h_eep, \
510 ''' Return an histogram and a map of the differences for each endcap'''
512 border_diff_distro_h_eep = TH1F(
"borderdiff EE+",
"diff EE+",100,-2,2)
513 border_diff_distro_h_eem = TH1F(
"borderdiff EE-",
"diff EE-",100,-2,2)
516 border_diff_distro_m_eep = TH2F(
"bordermap EE+",
"map EE+",100,1,101,100,1,101)
517 border_diff_distro_m_eem = TH2F(
"bordermap EE-",
"map EE-",100,1,101,100,1,101)
519 border_diff_distro_m_eep.SetStats(0)
520 border_diff_distro_m_eem.SetStats(0)
523 for i,c
in enumerate(coeff_endc_1):
524 diff = c - coeff_endc_2[i]
526 Rsq = ((ix-50.0)**2+(iy-50.0)**2)
528 if (iz >0
and (Rsq<144.0
or Rsq>2500.0)):
529 border_diff_distro_h_eep.Fill(diff)
530 border_diff_distro_m_eep.Fill(ix,iy,diff)
531 elif (iz<0
and (Rsq<144.0
or Rsq>2500.0)):
532 border_diff_distro_h_eem.Fill(diff)
533 border_diff_distro_m_eem.Fill(ix,iy,diff)
536 return border_diff_distro_h_eep, \
537 border_diff_distro_m_eep, \
538 border_diff_distro_h_eem, \
539 border_diff_distro_m_eem
Abs< T >::type abs(const T &t)