ATLAS Offline Software
Loading...
Searching...
No Matches
dumpHVPathFromNtuple.py
Go to the documentation of this file.
1#!/bin/env python
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
4import sys
5import ROOT
6
7def DumpPathology(inf, hvline, outfile, append):
8
9 if not inf.IsOpen():
10 print('File not open ?')
11 return
12
13 try:
14 if append:
15 fout=open(outfile,'a')
16 else:
17 fout=open(outfile,'w')
18 except Exception as e:
19 print('Could not open output file ',outfile)
20 print (e)
21 return
22
23 tree=inf.Get("hv/mytree")
24 # start to dump the HV for the asked HVLine, first collect one line per cell
25 br_hvline=tree.GetBranch("HVline")
26 hvdict={}
27 for i in range(0,tree.GetEntries()):
28 if i%10000 == 0: print(i)
29 br_hvline.GetEntry(i)
30 if tree.HVline != hvline: continue
31 tree.GetEntry(i)
32 bec=tree.barrel_ec
33 side=tree.side
34 FT=tree.FT
35 slot=tree.slot
36 channel=tree.channel
37 idlist=[bec,side,FT,slot,channel]
38 if str(idlist) in hvdict: continue
39 hv=tree.hv
40 ihv=int(hv)
41 hvlist=[bec,side,FT,slot,channel,ihv]
42 hvdict[str(idlist)]=hvlist
43 pass
44 #print hvdict
45 # now write to a file
46 if not append: fout.write('/LAR/HVPathologiesOfl/Pathologies\n')
47 for k in list(hvdict.keys()):
48 ll=hvdict[k]
49 if len(ll) != 6:
50 print('Wrong list: ',ll,' continue to next!!!')
51 continue
52 wstr=str(ll[0])+' '+str(ll[1])+' '+str(ll[2])+' '+str(ll[3])+' '+str(ll[4])+' '+str(hvline/1000)+' '+str(hvline%1000)+' '+str((ihv<<4)&0xFFF0)+'\n'
53 fout.write(wstr)
54 pass
55 fout.close()
56 return
57
58if __name__=="__main__":
59
60 # Get the input parameter
61 try:
62 infile = sys.argv[1]
63 inf = ROOT.TFile(infile,'read')
64 except Exception as e:
65 print('HV ntuple ',infile,' doesnt exist ?')
66 print(e)
67 sys.exit()
68
69 print('HV ntuple file: ',infile)
70
71 try:
72 hvline = int(sys.argv[2])
73 except Exception as e:
74 print('HVline number doesnt exist ?')
75 print (e)
76 sys.exit()
77
78 if hvline < 1000 or hvline > 400000:
79 print('wrong HV line number: ',hvline)
80 sys.exit()
81
82 if len(sys.argv) > 3:
83 outfile=sys.argv[3]
84 else:
85 outfile='hvpat.txt'
86
87 print('Output file: ',outfile)
88
89 if len(sys.argv) > 4:
90 if int(sys.argv[4])==0:
91 append=False
92 else:
93 append=True
94 else:
95 append=False
96
97 print('Append to out file: ',append)
98
99 DumpPathology(inf, hvline, outfile, append)
100 inf.Close()
101
102
103
void print(char *figname, TCanvas *c1)
DumpPathology(inf, hvline, outfile, append)