ATLAS Offline Software
Loading...
Searching...
No Matches
PlotCalibFromCool.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4#
5# PlotCalibFromCool.py
6# Using Part of ReadCalibfromCool.py to plot constants
7# Tigran Mkrtchyan 2017-06-15
8
9import getopt,sys,os,math
10os.environ['TERM'] = 'linux'
11
12def usage():
13 print ("How to use: ",sys.argv[0]," [OPTION] ... ")
14 print ("Plots the TileCal constants from various schemas / folders / tags as a function of run number/ lumiblock")
15 print ("")
16 print ("-h, --help shows this help")
17 print ("-T, --tree save all in a tree")
18 print ("-o, --opt= specify plotting option: line, noline or graph, bin, dist or 2d, default is dist")
19 print ("-z, --zAxis= specify label for Z axis on 2d plot")
20 print ("-x, --noTitle create plot without title")
21 print ("-L, --label= create plot with ATLAS/Tile label at the very top and this additional text")
22 print ("-M, --label2= second line of the label, if needed")
23 print ("-P, --print print all the values on the console")
24 print ("-n, --norm normalize everything to the first point")
25 print ("-f, --folder= specify status folder to use f.i. /TILE/OFL02/CALIB/CIS/LIN ")
26 print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or full suffix like RUN2-HLT-UPD1-00")
27 print ("-b, --begin= specify the starting run number")
28 print ("-e, --end= sepcify the last run number")
29 print ("-r, --run= specify fixed run number, will plot constants as a function of lumi")
30 print ("-l, --lumi= specify lumi block number, default is 0")
31 print ("-p, --part= specify which partition to plot, only for --plotopt=2d")
32 print ("-I, --modmin= specify minimal module to use for 2D plot, default is 1")
33 print ("-A, --modmax= specify maximal module to use for 2D plot, default is 64")
34 print ("-N, --chmin= specify minimal channel to use for 2D plot, default is 0")
35 print ("-X, --chmax= specify maximal channel to use for 2D plot, default is 47")
36 print ("-Y, --gmin= specify minimal gain to use for print option, default is 0")
37 print ("-Z, --gmax= specify maximal gain to use for print option, default is 1")
38 print ("-m, --module= specify module to use for 1D plots, default is LBA01")
39 print ("-c, --chan= specify channel to use for 1D plots, default is 0")
40 print ("-g, --gain=, -a, --adc= specify adc(gain) to use, default is 0 (low gain)")
41 print ("-v, --val=, -i, --ind= specify index of value to use, default is 0 ")
42 print ("-d, --vmin= specify minimal value for plot")
43 print ("-u, --vmax= specify maximal value for plot")
44 print ("-C, --cut= specify additional cut on displayed values")
45 print ("-s, --schema= specify schema to use, like 'COOLONL_TILE/CONDBR2' or 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2' or tileSqlite.db")
46 print ("-D, --dbname= specify dbname part of schema if schema only contains file name, default is CONDBR2")
47 print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
48
49
50letters = "hr:l:s:t:f:D:S:a:g:b:e:o:z:xL:M:Pp:Tv:i:m:c:I:A:N:X:Y:Z:d:u:C:n"
51words = ["help","run=","lumi=","schema=","tag=","folder=","dbname=","server=","adc=","gain=","print","module=","opt=","zAxis=","noTitle","label=","label2=","chan=","begin=","end=","tree","val=","ind=","part=","modmin=","modmax=","chmin=","chmax=","gmin=","gmax=","vmin=","vmax=","cut=","norm"]
52try:
53 options,args = getopt.getopt(sys.argv[1:],letters,words)
54except getopt.GetoptError as err:
55 print ()
56 print (str(err))
57 print ()
58 usage()
59 sys.exit(2)
60
61
62
63# defaults
64schema = 'COOLOFL_TILE/CONDBR2'
65dbname = ''
66server = ''
67folderPath = "/TILE/OFL02/CALIB/CIS/LIN"
68tag = "UPD4"
69line = False
70noline = False
71vsbin = False
72plotopt= "dist"
73save_tree = False
74print_msg = False
75opt2d = False
76zAxis = ""
77setTitle = True
78label = None
79label2 = ""
80partname = "LBA"
81modulename = "LBA01"
82modmin=0
83modmax=9999
84chanmin=0
85chanmax=9999
86gainmin=0
87gainmax=0
88valmin=None
89valmax=None
90mod_n = 0
91chan_n = 0
92gain_n = 0
93val_n = 0
94begin = 0
95end = 0
96runNum = 0
97lumiNum = 0
98one_run = False
99multi = False
100norm = False
101cut = None
102
103for o, a in options:
104 a = a.strip()
105 if o in ("-f","--folder"):
106 folderPath = a
107 elif o in ("-t","--tag"):
108 tag = a
109 elif o in ("-s","--schema"):
110 schema = a
111 elif o in ("-D","--dbname"):
112 dbname = a
113 elif o in ("-S","--server"):
114 server = a
115 elif o in ("-b","--begin"):
116 begin = int(a)
117 elif o in ("-e","--end"):
118 end = int(a)
119 elif o in ("-r","--run"):
120 runNum = int(a)
121 one_run = True
122 elif o in ("-l","--lumi"):
123 lumiNum = int(a)
124 elif o in ("-m","--module"):
125 modulename = a
126 elif o in ("-c","--chan"):
127 chan_n = int(a)
128 chanmin = chan_n
129 chanmax = chan_n
130 elif o in ("-a","--adc","-g","--gain"):
131 gain_n = int(a)
132 gainmin = gain_n
133 gainmax = gain_n
134 elif o in ("-v","--val","-i","--ind"):
135 val_n = int(a)
136 elif o in ("-p","--part"):
137 partname = a
138 modulename = partname+"00"
139 elif o in ("-I","--modmin"):
140 modmin = int(a)
141 elif o in ("-A","--modmax"):
142 modmax = int(a)
143 elif o in ("-N","--chmin"):
144 chanmin = int(a)
145 chan_n = chanmin
146 elif o in ("-X","--chmax"):
147 chanmax = int(a)
148 elif o in ("-d","--vmin"):
149 valmin = float(a)
150 elif o in ("-u","--vmax"):
151 valmax = float(a)
152 elif o in ("-Y","--gmin"):
153 gainmin = int(a)
154 gain_n = gainmin
155 elif o in ("-Z","--gmax"):
156 gainmax = int(a)
157 elif o in ("-o","--opt"):
158 plotopt = a
159 elif o in ("-z","--zAxis"):
160 zAxis = a
161 elif o in ("-x","--noTitle"):
162 setTitle = False
163 elif o in ("-L","--label"):
164 label = a
165 elif o in ("-M","--label2"):
166 label2 = a
167 elif o in ("-C","--cut"):
168 cut = a
169 elif o in ("-T","--tree"):
170 save_tree = True
171 elif o in ("-P","--print"):
172 print_msg = True
173 elif o in ("-n","--norm"):
174 norm = True
175 elif o in ("-h","--help"):
176 usage()
177 sys.exit(2)
178 else:
179 raise RuntimeError("unhandled option")
180
181
182#=== check parameters
183if len(dbname)<7:
184 dbname = 'COMP200' if max(begin,runNum)<232000 else 'CONDBR2'
185
186if 'COOLO' not in schema and ':' not in schema and ';' not in schema:
187 schema='sqlite://;schema='+schema+';dbname='+(dbname if len(dbname) else 'CONDBR2')
188
189if schema=='COOLONL_TILE/COMP200':
190 if not (folderPath.startswith('/TILE/ONL01/') or folderPath.startswith('/TILE/OFL01/')):
191 print ("Folder %s doesn't exist in schema %s " % (folderPath,schema))
192 sys.exit(2)
193
194if schema=='COOLONL_TILE/CONDBR2':
195 if not folderPath.startswith('/TILE/ONL01/'):
196 print ("Folder %s doesn't exist in schema %s, only /TILE/ONL01 " % (folderPath,schema))
197 sys.exit(2)
198
199if schema=='COOLOFL_TILE/COMP200' or schema=='COOLOFL_TILE/CONDBR2':
200 if not folderPath.startswith('/TILE/OFL02/'):
201 print ("Folder %s doesn't exist in schema %s " % (folderPath,schema))
202 sys.exit(2)
203
204
205if opt2d:
206 plotopt = "2d"
207if plotopt == "print":
208 print_msg = True
209elif plotopt == "line":
210 line = True
211elif plotopt == "bin":
212 vsbin = True
213elif plotopt == "noline" or plotopt == "graph":
214 noline = True
215elif plotopt == "2d":
216 opt2d = True
217 one_run = True
218
219chan_n=max(0,chan_n)
220gain_n=max(0,gain_n)
221val_n=max(0,val_n)
222modmin=max(1,modmin)
223modmax=min(64,modmax)
224chanmin=max(0,chanmin)
225chanmax=min(47,chanmax)
226gainmin=max(0,gainmin)
227gainmax=min(5,gainmax) # up to 6 gains for integrators
228nval=1
229
230if opt2d:
231 partname=partname[:3]
232 modulename=partname+"00"
233else:
234 if len(modulename) < 5 or len(modulename) > 5:
235 print ("Wrong module name:",modulename)
236 sys.exit(2)
237 partname=modulename[:3]
238 modnum=modulename[3:]
239 if modnum.isdigit():
240 mod_n=int(modnum)
241 if mod_n<0 or mod_n>64:
242 print ("Wrong module name:",modulename)
243 sys.exit(2)
244 elif mod_n>0:
245 modmin=mod_n
246 modmax=mod_n
247 else:
248 print ("Wrong module name:",modulename)
249 sys.exit(2)
250
251part_dict = {'AUX':0,'LBA':1,'LBC':2,'EBA':3,'EBC':4,'ALL':5}
252if partname in part_dict:
253 ros=part_dict[partname]
254 if ros==5:
255 rosmin=0
256 rosmax=5
257 ros=-1
258 else:
259 rosmin=ros
260 rosmax=ros+1
261else:
262 if opt2d:
263 print ("Wrong partition name:",partname)
264 else:
265 print ("Wrong module name:",modulename)
266 sys.exit(2)
267
268many=False
269if modmin!=modmax:
270 many=True
271 modulename="%s%2.2d-%s%2.2d" % (partname,modmin,partname,modmax)
272else:
273 mod_n=modmin
274 modulename="%s%2.2d" % (partname,mod_n)
275
276if chanmin!=chanmax:
277 many=True
278 channame="%2.2d-%2.2d" % (chanmin,chanmax)
279else:
280 chan_n=chanmin
281 channame="%2.2d" % (chan_n)
282
283if gainmin!=gainmax:
284 many=True
285 gain_n = -1
286
287if one_run and plotopt == "dist":
288 print ("Switching to noline mode")
289 noline = True
290 plotopt = "noline"
291
292if many:
293 many=(line or noline)
294
295if not many and gain_n==-1:
296 gain_n=gainmin
297
298if gain_n == -1:
299 gainname = "AllG"
300elif gain_n == 0:
301 gainname = "LG"
302elif gain_n == 1:
303 gainname = "HG"
304else:
305 gainname = "G"+str(gain_n)
306if val_n>0:
307 gainname += " val[%d]" % (val_n)
308
309
310import ROOT
311from ROOT import TCanvas, TH2D, TGraph, TTree, TLegend, TLatex
312from ROOT import kTRUE
313import numpy as np
314
315
316from TileCalibBlobPython import TileCalibTools
317from TileCalibBlobObjs.Classes import TileCalibUtils
318from TileCalibBlobPython.TileCalibLogger import getLogger
319log = getLogger("PlotCalibFromCool")
320import logging
321logLevel=logging.DEBUG
322log.setLevel(logLevel)
323log1 = getLogger("PlotCalibFromCool")
324log1.setLevel(logLevel)
325
326folderPath=folderPath.split(",")
327folderTag=[]
328for fp in folderPath:
329 ft = TileCalibTools.getFolderTag(schema , fp, tag)
330 log.info("Initializing folder %s with tag %s", fp, ft)
331 folderTag += [ft]
332multi=(len(folderPath)>1)
333if multi and many:
334 print ("Can not calculate product of "+" ".join(folderPath)+" in multi-channel mode")
335 sys.exit(2)
336
337
338#=== Get list of IOVs for given drawer or for comments record
339if ros!=-1:
340 modmax=min(modmax,TileCalibUtils.getMaxDrawer(ros))
341if ros!=-1 and modmin==modmax:
342 COOL_part = ros
343 COOL_chan = modmin-1
344elif ros==0 and modmin==1:
345 COOL_part = ros
346 COOL_chan = modmin-1
347else:
348 COOL_part = -1
349 COOL_chan = 1000
350idb = TileCalibTools.openDbConn(schema,server)
351iovList = []
352blobReader = []
353for (fp,ft) in zip(folderPath,folderTag):
354 try:
355 br = TileCalibTools.TileBlobReader(idb,fp, ft)
356 blobReader += [br]
357 dbobjs = br.getDBobjsWithinRange(COOL_part, COOL_chan)
358 if (dbobjs is None):
359 raise Exception("No DB objects retrieved when building IOV list!")
360 while dbobjs.goToNext():
361 obj = dbobjs.currentRef()
362 objsince = obj.since()
363 sinceRun = objsince >> 32
364 sinceLum = objsince & 0xFFFFFFFF
365 since = (sinceRun, sinceLum)
366 objuntil = obj.until()
367 untilRun = objuntil >> 32
368 untilLum = objuntil & 0xFFFFFFFF
369 until = (untilRun, untilLum)
370
371 if multi:
372 iov = (since, since)
373 else:
374 iov = (since, until)
375 iovList.append(iov)
376 except Exception:
377 print ("Warning: can not read IOVs from input DB file")
378 sys.exit(2)
379
380if multi:
381 il=[]
382 iov1=(-1,-1)
383 for iov in sorted(iovList):
384 iov2=iov[0]
385 if iov1!=iov2:
386 il.append(iov)
387 iov1=iov2
388 iovList=[]
389 for i in range(len(il)-1):
390 iovList.append(((il[i][0][0],il[i][0][1]),(il[i+1][1][0],il[i+1][1][1])))
391 i=len(il)-1
392 iovList.append(((il[i][0][0],il[i][0][1]),(0xFFFFFFFF,0xFFFFFFFF)))
393
394
395print ("\nPlotting in %s mode" % plotopt)
396print ('-'*20)
397
398be=iovList[0][0][0]
399en=iovList[-1][0][0]
400
401lastrun=TileCalibTools.getLastRunNumber()
402
403if runNum <= 0:
404 runNum = en
405if one_run:
406 begin = runNum
407 end = runNum
408 if line or noline:
409 lumiNum = 0
410else:
411 if begin <= 0:
412 begin = be
413 if end <= 0:
414 end = lastrun
415
416veryEnd = end if (end<lastrun or begin>lastrun) else lastrun
417
418if begin != be or end != en:
419 ib=0
420 ie=len(iovList)
421 for i,iovs in enumerate(iovList):
422 run = iovs[0][0]
423 lumi = iovs[0][1]
424 if (run<begin and run>be) or (run==begin and lumi<=lumiNum):
425 be=run
426 ib=i
427 if run>end and run<en:
428 en=run
429 ie=i+1
430 if be != begin:
431 print ("Changing begin run from",begin,"to",be,"(start of IOV)")
432 begin=be
433 if en != end:
434 if en>end:
435 print ("Changing end run from",end,"to",en,"(start of next IOV)")
436 else:
437 print ("Changing end run from",end,"to",en,"(start of last IOV)")
438 end=en
439 iovList=iovList[ib:ie]
440
441if one_run:
442 if opt2d and not (line or noline):
443 iovList=iovList[:1]
444 print ("Plotting values for (Run,Lumi) = (%i,%i) " % (runNum,lumiNum))
445 print ("from IOV",iovList[0])
446 elif len(iovList)<=2 and iovList[-1][0][0]!=runNum:
447 print ("Too few points to plot value as a function of lumi block")
448 print ("Just one IOV around run", runNum)
449 print (iovList[0])
450 print ("Plotting value as a function of run number")
451 one_run=False
452 else:
453 print ("Plotting Run: %i" % runNum)
454 print ("IOV around this run")
455 print (iovList)
456 if not line and runNum!=iovList[-1][0][0]:
457 iovList=iovList[:-1]
458
459if not one_run:
460 print ("Plotting Runs: %i to %i" % (begin, end))
461 print (len(iovList),"different IOVs in total")
462 if iovList[0][0][0]!=begin or iovList[-1][0][0]!=end:
463 print ("Congratulations! You found the bug in this script")
464 print ("Please, contact authors")
465 sys.exit(2)
466
467
468
469
470
471ROOT.gROOT.SetBatch(kTRUE)
472
473labels = ROOT.vector('string')()
474vals = ROOT.vector('double')()
475
476titsuff=""
477if one_run or opt2d:
478 if lumiNum<=0:
479 titsuff=" Run " + str(runNum)
480 else:
481 titsuff=" Run " + str(runNum) + " LB " + str(lumiNum)
482titsuff+=" Tag " + " ".join(folderTag)
483rlt=titsuff.replace(" ","_").replace("_Tag","")
484gtitle = modulename +" " + " Channel" +("s " if (chanmin!=chanmax) else " ") + channame +" " + gainname + titsuff
485
486if opt2d:
487 fname="%s_g%d_v%d%s_%s" % ( partname,gain_n,val_n,rlt,plotopt)
488else:
489 fname="%s_ch%s_g%d_v%d%s_%s" % ( modulename,channame,gain_n,val_n,rlt,plotopt)
490
491if save_tree:
492 tree_file = ROOT.TFile(fname+".root","RECREATE")
493
494tree = TTree("tree","ttree")
495run_n = np.zeros(1, dtype = float)
496lumi_n = np.zeros(1, dtype = float)
497channel_n = np.zeros(1, dtype = float)
498module_n = np.zeros(1, dtype = int)
499ros_n = np.zeros(1, dtype = int)
500value = np.zeros(1, dtype = float)
501scale = np.zeros(1, dtype = float)
502
503tree.Branch("runnumber",run_n,'runnumber/D')
504tree.Branch("luminum",lumi_n,'luminum/D')
505tree.Branch("channel",channel_n,'channel/D')
506tree.Branch("module",module_n,'module/I')
507tree.Branch("ros",ros_n,'ros/I')
508tree.Branch("labels", labels)
509tree.Branch("vals", vals)
510if multi:
511 tree.Branch("value", value,'value/D')
512if norm:
513 tree.Branch("scale", scale,'scale/D')
514
515
517first=True
518value[0]=1.
519scale[0]=1.
520vals.clear()
521labels.clear()
522one_iov = (len(iovList)<2)
523
524for iovs in iovList:
525
526 if one_iov:
527 run = runNum
528 lumi = lumiNum
529 rl = "(%i,%i) - (%i,%i)" % (iovs[0][0],iovs[0][1],iovs[1][0],iovs[1][1])
530 else:
531 run = iovs[0][0]
532 lumi = iovs[0][1]
533 rl = "(%i,%i)" % (run,lumi)
534 if one_run and run!=runNum:
535 if run<runNum:
536 lumi=-1
537 if run>runNum:
538 lumi=2000
539 run=runNum
540
541 run_n[0] = run
542 lumi_n[0] = lumi
543 if vals.size()>0:
544 if first:
545 scale[0]=value[0]
546 first=False
547 tree.Fill()
548 labels.clear()
549 vals.clear()
550 value[0]=1.
551
552 for ros in range(rosmin,rosmax):
553 ros_n[0] = ros
554 for mod in range(modmin-1, min(modmax,TileCalibUtils.getMaxDrawer(ros))):
555 module_n[0] = mod
557 for (fp,ft,br) in zip(folderPath,folderTag,blobReader):
558 try:
559 flt = br.getDrawer(ros, mod,(run,lumi), False, False) # modified
560 if flt is None or isinstance(flt, (int)):
561 if one_iov or ros!=0:
562 print ("%s is missing in DB" % modName)
563 else:
564 nchan = flt.getNChans()
565 ngain = flt.getNGains()
566 nval = flt.getObjSizeUint32()
567 for chn in range(chanmin,min(chanmax+1,nchan)):
568 for adc in range(gainmin,min(gainmax+1,ngain)):
569 msg = "%s %s %2i %1i " % (rl, modName, chn, adc )
570 for val in range(nval):
571 msg += " %f" % flt.getData(chn, adc, val)
572 vals.push_back(flt.getData(chn, adc, val))
573 if val==0:
574 value[0] *= flt.getData(chn, adc, val)
575 if print_msg:
576 if multi:
577 print (fp,msg)
578 else:
579 print (msg)
580 channel_n[0] = chn
581 if one_run:
582 labels.push_back(str(lumi))
583 else:
584 labels.push_back(str(run))
585 if not multi or opt2d:
586 if first:
587 if vals.size()>val_n:
588 scale[0]=vals[val_n]
589 first=False
590 tree.Fill()
591 if not line or many:
592 labels.clear()
593 vals.clear()
594 value[0] = 1.
595
596 except Exception as e:
597 print (e)
598
599 if multi and not opt2d and vals.size()>0:
600 if first:
601 scale[0]=value[0]
602 first=False
603 tree.Fill()
604 if not line:
605 labels.clear()
606 vals.clear()
607 value[0] = 1.
608
609
610if not opt2d and vals.size()>0:
611 run_n[0] = veryEnd
612 lumi_n[0] = 0
613 if first:
614 scale[0]=value[0]
615 first=False
616 tree.Fill()
617 labels.clear()
618 vals.clear()
619 value[0]=1.
620
621idb.closeDatabase()
622
623if plotopt == "print":
624 sys.exit(0)
625
626
627
628
629ROOT.gROOT.SetStyle("Plain")
630ROOT.gROOT.ForceStyle()
631ROOT.gStyle.SetOptStat(0)
632ROOT.gStyle.SetPalette(1)
633ROOT.gStyle.SetOptTitle(setTitle)
634
635
636if one_run:
637 cut_cond = "runnumber == " + str(runNum)
638else:
639 cut_cond = "runnumber >= " + str(begin) + " && " + "runnumber <= " + str(veryEnd)
640
641
642if multi:
643 data = "value"
644elif many:
645 data = "vals[%d]"
646else:
647 data = "vals[" + str(val_n) + "]"
648
649if cut:
650 if "val" not in cut:
651 cut = data + cut
652 cut_cond = "(" + cut_cond + ") && (" + cut + ")"
653
654if norm:
655 data += "/scale"
656
657if (line or noline) and not one_run:
658 data += ":runnumber"
659
660elif vsbin:
661 data +=":labels"
662
663elif one_run:
664 data += ":luminum"
665
666cx = 1600
667cy = 800
668#if label is not None:
669# cy = int(1.05*cy)
670canv = TCanvas("PlotCalib","plotCalib",0,0,cx,cy)
671
672if opt2d:
673 hhh = TH2D("hhh","hhh",modmax-modmin+1,modmin-0.5,modmax+0.5,chanmax-chanmin+1,chanmin-0.5,chanmax+0.5)
674
675if not many and not opt2d:
676 print ("Plotting",data)
677 print ("With cut",cut_cond)
678 if vsbin:
679 tree.Draw(data,cut_cond,"goff",15)
680 else:
681 tree.Draw(data,cut_cond,"goff")
682
683 if tree.GetSelectedRows() <= 0:
684 print ("Not enough points to plot")
685 sys.exit(2)
686
687 if vsbin:
688 if tree.GetSelectedRows() >= 15:
689 print ("Maximum number of bins is 15")
690
691if line or noline:
692 if many:
693 first=True
694 color=1
695 grall=[]
696 vmin=1.e+38
697 vmax=-1.e+38
698 cut0 = cut_cond
699 data1 = data
700 leg = TLegend(0.7,0.7,0.9,0.9)
701 for ros in range(rosmin,rosmax):
702 for mod in range(modmin-1, modmax):
703 for chn in range(chanmin,chanmax+1):
704 for adc in range(gainmin,gainmax+1):
705 if "%d" in data:
706 data1 = data.replace("%d",str((adc-gainmin)*nval+val_n))
707 if "%d" in cut_cond:
708 cut0 = cut_cond.replace("%d",str((adc-gainmin)*nval+val_n))
709 cut1 = "(ros == %d && module == %d && channel == %d) && %s" % (ros,mod,chn,cut0)
710 tree.Project("htemp",data1,cut1)
711 if tree.GetSelectedRows() > 0:
712 color = color + 1
713 gr = TGraph(tree.GetSelectedRows(),tree.GetV2(),tree.GetV1())
714 yy=gr.GetY()
715 for ii in range(len(yy)):
716 vv=yy[ii]
717 if vv<vmin:
718 vmin=vv
719 if vv>vmax:
720 vmax=vv
721 grall += [gr]
722 leg.AddEntry(gr,"%s%2.2d ch %2.2d" % ( list(part_dict.keys())[list(part_dict.values()).index(ros)],mod+1,chn),"lep")
723 gr.SetMarkerStyle(20)
724 gr.SetMarkerSize(1.3)
725 gr.SetMarkerColor(color)
726 gr.SetLineColor(color)
727 if first:
728 print ("First plot:")
729 print ("Plotting",data1)
730 print ("With cut",cut1)
731 print ("Note that in TTree module number starts from 0")
732 gr.SetTitle(gtitle)
733 gr.GetXaxis().SetNoExponent(kTRUE)
734 if one_run:
735 gr.GetXaxis().SetTitle("Lumi")
736 else:
737 gr.GetXaxis().SetTitle("Runs")
738 if noline:
739 gr.Draw("ap")
740 else:
741 gr.Draw("apl")
742 first=False
743 else:
744 if noline:
745 gr.Draw("p")
746 else:
747 gr.Draw("pl")
748 lg=len(grall)
749 if lg==0:
750 print ("Plotting",data)
751 print ("With cut",cut_cond)
752 print ("Not enough points to plot")
753 sys.exit(2)
754 if lg>400:
755 nc=20
756 elif lg>144:
757 nc=int(math.sqrt(lg))
758 else:
759 nc=int((lg-1)/12+1)
760 leg.SetNColumns(nc)
761 extra = (2+0.4*int(lg/nc+1))
762 dv=(vmax-vmin)/10.
763 if valmin is None:
764 grall[0].SetMinimum(vmin-dv)
765 else:
766 grall[0].SetMinimum(valmin)
767 if valmax is None:
768 grall[0].SetMaximum(vmax+dv*extra)
769 else:
770 grall[0].SetMaximum(valmax)
771 if nc>8:
772 nc=8
773 leg.SetX1(0.9-0.1*nc)
774 leg.SetY1(0.9-0.8*(extra-1)/(11+extra))
775 leg.Draw()
776 else:
777 gr = TGraph(tree.GetSelectedRows(),tree.GetV2(),tree.GetV1())
778 gr.SetTitle(gtitle)
779 gr.SetMarkerStyle(20)
780 gr.SetMarkerSize(1.3)
781 gr.SetMarkerColor(2)
782 gr.SetLineColor(2)
783 gr.GetXaxis().SetNoExponent(kTRUE)
784 if one_run:
785 gr.GetXaxis().SetTitle("Lumi")
786 else:
787 gr.GetXaxis().SetTitle("Runs")
788 if valmin is not None:
789 grall[0].SetMinimum(valmin)
790 if valmax is not None:
791 grall[0].SetMaximum(valmax)
792 if noline:
793 gr.Draw("ap")
794 else:
795 gr.Draw("apl")
796
797elif opt2d:
798 nentries = tree.GetEntries()
799 hhh.SetName(modulename)
800 hhh.SetTitle(gtitle)
801 if 'zAxis' in dir() and len(zAxis)>0:
802 hhh.GetZaxis().SetTitle(zAxis)
803 canv.SetRightMargin(0.14)
804 hhh.GetYaxis().SetTitle("Channel")
805 hhh.GetXaxis().SetTitle("Module")
806
807 if multi:
808 Matrix = [[1 for y in range(48)] for x in range(64)]
809 for i in range(nentries):
810 tree.GetEntry(i)
811 if vals.size()>0:
812 x=int(module_n[0])
813 y=int(channel_n[0])
814 Matrix[x][y] *= vals[0]
815 sc = Matrix[modmax-1][chanmax] if norm and Matrix[modmax-1][chanmax]>0 else 1
816 for x in range(modmin,modmax+1):
817 for y in range(chanmin,chanmax+1):
818 hhh.Fill(x, y, Matrix[x-1][y]/sc)
819 else:
820 for i in range(nentries):
821 tree.GetEntry(i)
822 #print (("%f %f %f") % (module_n[0], channel_n[0],vals[0]))
823 if norm:
824 hhh.Fill(module_n[0]+1, channel_n[0],vals[val_n]/scale[0])
825 else:
826 hhh.Fill(module_n[0]+1, channel_n[0],vals[val_n])
827
828 if valmin is not None:
829 hhh.SetMinimum(valmin)
830 if valmax is not None:
831 hhh.SetMaximum(valmax)
832 hhh.Draw("colz")
833
834else:
835 h = ROOT.gDirectory.Get("htemp")
836 h.SetName(modulename)
837 h.SetTitle(gtitle)
838 h.SetLineColor(2)
839 h.SetLineWidth(2)
840 h.GetXaxis().SetTitle("Value")
841 if vsbin or one_run:
842 h.SetMarkerStyle(21)
843 h.SetMarkerSize(1.4)
844 h.SetMarkerColor(2)
845 h.GetXaxis().SetTitle("Run")
846 if one_run:
847 h.GetXaxis().SetTitle("Lumi")
848 h.SetTitle(gtitle)
849 h.GetYaxis().SetTitle("")
850 h.GetYaxis().SetTitleOffset(1.35)
851 if valmin is not None:
852 h.SetMinimum(valmin)
853 if valmax is not None:
854 h.SetMaximum(valmax)
855 try:
856 h.Draw()
857 except Exception:
858 print ("Empty ")
859
860if label is not None:
861 canv.SetTopMargin(0.15)
862 x = 0.1
863 y = 0.93
864 dy = 0.05
865 delx = 0.115*696*ROOT.gPad.GetWh()/(472*ROOT.gPad.GetWw())
866
867 lat = TLatex()
868 lat.SetNDC()
869 lat.SetTextFont(72)
870 lat.DrawLatex(x,y,"ATLAS")
871 p = TLatex()
872 p.SetNDC()
873 p.SetTextFont(42)
874 p.DrawLatex(x+delx,y,"Preliminary")
875 p.DrawLatex(x,y-dy,"Tile Calorimeter")
876
877 ll = max(len(label),len(label2))
878 if ll>0:
879 x = 0.9 - delx*ll/6.5
880 p.DrawLatex(x,y,label)
881 p.DrawLatex(x,y-dy,label2)
882
883canv.SetGridx()
884canv.SetGridy()
885
886canv.Update()
887
888
889
890if valmin is not None:
891 fname += "_min_%s" % (valmin)
892if valmax is not None:
893 fname += "_max_%s" % (valmax)
894
895canv.Print(fname+".eps")
896canv.Print(fname+".png")
897
898if save_tree:
899 tree_file.Write()
900 tree_file.Close()
901
902
903#=== display plot
904os.system("display "+fname+".png")
905
906
907#
908#if __name__ == '__main__':
909# rep = ''
910# while not rep in [ 'q', 'Q' ]:
911# rep = raw_input( 'enter "q" to quit: ' )
912# if 1 < len(rep):
913# rep = rep[0]
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
Definition index.py:1