ATLAS Offline Software
Functions
MuonValidation_AddGaussianFitToPulls Namespace Reference

Functions

def AddGaussian (infile, HistDir, HistName)
 
def main (args)
 

Function Documentation

◆ AddGaussian()

def MuonValidation_AddGaussianFitToPulls.AddGaussian (   infile,
  HistDir,
  HistName 
)

Definition at line 15 of file MuonValidation_AddGaussianFitToPulls.py.

15 def AddGaussian( infile, HistDir, HistName ):
16  hist = infile.GetDirectory(HistDir).Get(HistName)
17  if hist.GetEntries() < 10:
18  print( 'INFO Skipping Fit. NumEntries = {0}: '.format(hist.GetEntries()) + HistName )
19  return
20  gaus2 = ROOT.TF1( "gaus2", "gaus", -2, 2 )
21  gaus5 = ROOT.TF1( "gaus", "gaus", -5, 5 )
22  if int(hist.Fit(gaus2,"RQ")) != 0:
23  print( 'WARNING fit failed for ' + HistName )
24  return
25  hist.GetListOfFunctions().Add(gaus5)
26  f1 = hist.GetFunction("gaus")
27  f1.SetParameters( hist.GetFunction("gaus2").GetParameters() )
28  hist.GetListOfFunctions().Remove( gaus2 )
29  f1.SetLineColor(ROOT.kRed)
30  print('INFO Overwriting histogram: ' + HistDir + '/' + HistName )
31  hist.GetDirectory().WriteTObject( hist, HistName, "Overwrite" )
32 
33 #---------------------------------------------------------------------------

◆ main()

def MuonValidation_AddGaussianFitToPulls.main (   args)

Definition at line 34 of file MuonValidation_AddGaussianFitToPulls.py.

34 def main( args ):
35  if len( args ) > 1:
36  filename = args[1]
37  else:
38  print( 'Usage: python {0} filename'.format( args[0] ) )
39  return
40 
41  if not os.path.exists( filename ):
42  print ( 'File not found: ' + filename )
43  return
44 
45  infile = ROOT.TFile.Open( filename, 'update' )
46 
47  MuonTypes = [ 'All', 'Prompt', 'InFlight', 'NonIsolated' ]
48  PullTypes = [ '', 'ID', 'MS' ]
49  Variables = [ 'phi', 'theta', 'qOverP', 'd0', 'z0' ]
50 
51  for MuonType in MuonTypes:
52  if not infile.Get( 'Muons/' + MuonType ):
53  print( 'INFO TDirectory not found: Muons/' + MuonType )
54  continue
55  AuthDir = infile.Get( 'Muons/{0}/matched'.format( MuonType ) )
56  Authors = [ i.GetName() for i in AuthDir.GetListOfKeys() if AuthDir.Get( i.GetName() ).InheritsFrom( 'TDirectory' ) ]
57  for Author in Authors:
58  DirName = 'Muons/{0}/matched/{1}/Pulls'.format( MuonType, Author )
59  Dir = infile.Get( DirName )
60  if not Dir:
61  print( 'INFO TDirectory not found: ' + DirName )
62  continue
63  for PullType, var in itertools.product( PullTypes, Variables ):
64  HistName = '_'.join( DirName.split('/') ) + '_Pull{0}_'.format(PullType) + var
65  if not Dir.Get( HistName ):
66  print( 'INFO Histogram not found: ' + HistName )
67  continue
68  AddGaussian( infile, DirName, HistName )
69  infile.Close()
70 
71 #---------------------------------------------------------------------------
72 
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonValidation_AddGaussianFitToPulls.AddGaussian
def AddGaussian(infile, HistDir, HistName)
Definition: MuonValidation_AddGaussianFitToPulls.py:15
Get
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
Definition: comparitor.cxx:178
MuonValidation_AddGaussianFitToPulls.main
def main(args)
Definition: MuonValidation_AddGaussianFitToPulls.py:34
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70