CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
pileupCalc Namespace Reference

Classes

class  EquidistantBinning
 

Functions

def fillPileupHistogram
 
def MyErf
 
def parseInputFile
 
def poisson
 

Variables

tuple binning = EquidistantBinning(options.numPileupBins, 0., options.maxPileupBin)
 
list choices = ['true', 'observed']
 
string default = 'pileup'
 
tuple hContents = np.zeros(binning.centers.shape)
 
string help = 'input Run/LS file for your analysis in JSON format'
 
tuple histFile = ROOT.TFile.Open(output, 'recreate')
 
tuple inpf = open(options.inputfile, 'r')
 
tuple inputfilecontent = inpf.read()
 
tuple inputPileupRange = parseInputFile(options.inputLumiJSON)
 
tuple inputRange = selectionParser.selectionParser(inputfilecontent)
 
list LSPUlist = inputPileupRange[run]
 
list lumiInfo = LSPUlist[LSnumber]
 
tuple options = parser.parse_args()
 
 output = options.outputfile
 
tuple parser = argparse.ArgumentParser(description = "Script to estimate pileup distribution using bunch instantaneous luminosity information and minimum bias cross section. Outputs a TH1D of the pileup distribution stored in a ROOT file.")
 

## Main Program

More...
 
tuple pileupHist
 
tuple req_group = parser.add_argument_group('required arguments')
 
tuple Sqrt2 = np.sqrt(2)
 
float type = 69200.0
 
string VERSION = '1.00'
 

Function Documentation

def pileupCalc.fillPileupHistogram (   lumiInfo,
  calcOption,
  binning,
  hContents,
  minbXsec,
  run,
  ls 
)
lumiinfo:[intlumi per LS, mean interactions ]

intlumi is the deadtime corrected average integrated lumi per lumisection

Definition at line 69 of file pileupCalc.py.

References MyErf(), poisson(), and print().

69 
70 def fillPileupHistogram(lumiInfo, calcOption, binning, hContents, minbXsec, run, ls):
71  '''
72  lumiinfo:[intlumi per LS, mean interactions ]
73 
74  intlumi is the deadtime corrected average integrated lumi per lumisection
75  '''
76 
77  LSintLumi = lumiInfo[0]
78  RMSInt = lumiInfo[1]*minbXsec
79  AveNumInt = lumiInfo[2]*minbXsec
80 
81  # First, re-constitute lumi distribution for this LS from RMS:
82  if RMSInt > 0:
83  areaAbove = MyErf((AveNumInt-binning.edges)/Sqrt2/RMSInt)
84  ## area above edge, so areaAbove[i]-areaAbove[i+1] = area in bin
85  ProbFromRMS = .5*(areaAbove[:-1]-areaAbove[1:])
86  else:
87  ProbFromRMS = np.zeros(hContents.shape)
88  obs = binning.find(AveNumInt)
89  if ( obs < binning.num ) and ( AveNumInt >= 1.0E-5 ): # just ignore zero values
90  ProbFromRMS[obs] = 1.0
91 
92  if calcOption == 'true': # Just put distribution into histogram
93  if RMSInt > 0:
94  hContents += ProbFromRMS*LSintLumi
95  totalProb = np.sum(ProbFromRMS)
96 
97  if 1.0-totalProb > 0.01:
98  print("Run %d, LS %d: Significant probability density outside of your histogram (mean %.2f," % (run, ls, AveNumInt))
99  print("rms %.2f, integrated probability %.3f). Consider using a higher value of --maxPileupBin." % (RMSInt, totalProb))
100  else:
101  hContents[obs] += LSintLumi ## obs = FindBin(AveNumInt), -1 because hContents has no overflows
102  else: # have to convolute with a poisson distribution to get observed Nint
103  if not hasattr(binning, "poissConv"): ## only depends on binning, cache
104  ## poissConv[i,j] = TMath.Poisson(e[i], c[j])
105  binning.poissConv = poisson(
106  binning.edges[:-1,np.newaxis], ## e'[i,] = e[i]
107  binning.centers[np.newaxis,:]) ## c'[,j] = c[j]
108  # prob[i] = sum_j ProbFromRMS[j]*TMath.Poisson(e[i], c[j])
109  prob = np.sum(binning.poissConv * ProbFromRMS[np.newaxis,:], axis=1)
110  hContents += prob*LSintLumi
111  #if ( not np.all(ProbFromRMS == 0) ) and 1.0-np.sum(prob) > 0.01:
112  # print("Run %d, LS %d: significant probability density outside of your histogram, %f" % (run, ls, np.sum(prob)))
113  # print("Consider using a higher value of --maxPileupBin")
def poisson
Definition: pileupCalc.py:49
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def fillPileupHistogram
Definition: pileupCalc.py:69
def pileupCalc.MyErf (   xInput)

Definition at line 24 of file pileupCalc.py.

Referenced by fillPileupHistogram().

24 
25 def MyErf(xInput):
26  # Abramowitz and Stegun approximations for Erf (equations 7.1.25-28)
27  X = np.abs(xInput)
28 
29  p = 0.47047
30  b1 = 0.3480242
31  b2 = -0.0958798
32  b3 = 0.7478556
33 
34  T = 1.0/(1.0+p*X)
35  cErf = 1.0 - (b1*T + b2*T*T + b3*T*T*T)*np.exp(-1.0*X*X)
36 
37  # Alternate Erf approximation:
38  #A1 = 0.278393
39  #A2 = 0.230389
40  #A3 = 0.000972
41  #A4 = 0.078108
42 
43  #term = 1.0+ A1*X+ A2*X*X+ A3*X*X*X+ A4*X*X*X*X
44  #denom = term*term*term*term
45 
46  #dErf = 1.0 - 1.0/denom
47 
48  return np.where(xInput < 0, -cErf, cErf)
def pileupCalc.parseInputFile (   inputfilename)
output ({run:[ls:[inlumi, meanint]]})

Definition at line 12 of file pileupCalc.py.

12 
13 def parseInputFile(inputfilename):
14  '''
15  output ({run:[ls:[inlumi, meanint]]})
16  '''
17  selectf=open(inputfilename,'r')
18  inputfilecontent=selectf.read()
19  p=pileupParser.pileupParser(inputfilecontent)
20 
21 # p=inputFilesetParser.inputFilesetParser(inputfilename)
22  runlsbyfile=p.runsandls()
23  return runlsbyfile
def parseInputFile
Definition: pileupCalc.py:12
def pileupCalc.poisson (   x,
  par 
)

Definition at line 49 of file pileupCalc.py.

Referenced by fillPileupHistogram().

49 
50 def poisson(x, par):
51  ## equivalent to TMath::Poisson (without x<0 and par<0 checks)
52  return np.where(x == 0., np.exp(-par),
53  np.exp(x*np.log(par)-loggamma(x+1)-par))
def poisson
Definition: pileupCalc.py:49

Variable Documentation

tuple pileupCalc.binning = EquidistantBinning(options.numPileupBins, 0., options.maxPileupBin)

Definition at line 163 of file pileupCalc.py.

Referenced by TagProbeFitTreeAnalyzer.calculateEfficiency().

list pileupCalc.choices = ['true', 'observed']

Definition at line 135 of file pileupCalc.py.

string pileupCalc.default = 'pileup'

Definition at line 146 of file pileupCalc.py.

tuple pileupCalc.hContents = np.zeros(binning.centers.shape)

Definition at line 164 of file pileupCalc.py.

string pileupCalc.help = 'input Run/LS file for your analysis in JSON format'

Definition at line 130 of file pileupCalc.py.

tuple pileupCalc.histFile = ROOT.TFile.Open(output, 'recreate')

Definition at line 209 of file pileupCalc.py.

tuple pileupCalc.inpf = open(options.inputfile, 'r')

Definition at line 166 of file pileupCalc.py.

tuple pileupCalc.inputfilecontent = inpf.read()

Definition at line 167 of file pileupCalc.py.

tuple pileupCalc.inputPileupRange = parseInputFile(options.inputLumiJSON)

Definition at line 172 of file pileupCalc.py.

tuple pileupCalc.inputRange = selectionParser.selectionParser(inputfilecontent)

Definition at line 168 of file pileupCalc.py.

Referenced by SiStripNoiseNormalizedWithApvGainBuilder.analyze(), SiStripApvGainBuilderFromTag.analyze(), SiStripGain.fillNewGain(), cms::ReconstructerFP420.produce(), cms::TrackerizerFP420.produce(), cms::ClusterizerFP420.produce(), cms::DigitizerFP420.produce(), CTPPSPixelDigiCollection.put(), PixelDigiCollection.put(), DigiCollectionFP420.put(), ClusterCollectionFP420.put(), TrackCollectionFP420.put(), RecoCollectionFP420.put(), TrackCollectionFP420.putclear(), RecoCollectionFP420.putclear(), ClusterCollectionFP420.putclear(), DigiCollectionFP420.putclear(), FP420TrackMain.run(), and FP420ClusterMain.run().

list pileupCalc.LSPUlist = inputPileupRange[run]

Definition at line 182 of file pileupCalc.py.

list pileupCalc.lumiInfo = LSPUlist[LSnumber]

Definition at line 187 of file pileupCalc.py.

tuple pileupCalc.options = parser.parse_args()

Definition at line 150 of file pileupCalc.py.

pileupCalc.output = options.outputfile

Definition at line 151 of file pileupCalc.py.

tuple pileupCalc.parser = argparse.ArgumentParser(description = "Script to estimate pileup distribution using bunch instantaneous luminosity information and minimum bias cross section. Outputs a TH1D of the pileup distribution stored in a ROOT file.")

## Main Program

Definition at line 124 of file pileupCalc.py.

tuple pileupCalc.pileupHist
Initial value:
1 = ROOT.TH1D(options.pileupHistName, options.pileupHistName,
2  options.numPileupBins, 0., options.maxPileupBin)

Definition at line 204 of file pileupCalc.py.

tuple pileupCalc.req_group = parser.add_argument_group('required arguments')

Definition at line 127 of file pileupCalc.py.

tuple pileupCalc.Sqrt2 = np.sqrt(2)

Definition at line 67 of file pileupCalc.py.

int pileupCalc.type = 69200.0

Definition at line 139 of file pileupCalc.py.

string pileupCalc.VERSION = '1.00'

Definition at line 4 of file pileupCalc.py.