Skip to content

Commit

Permalink
FastSim scan made more configurable
Browse files Browse the repository at this point in the history
and minor cms-edgeZ fixes to friend tree production

Conflicts:
	CMGTools/TTHAnalysis/python/analyzers/ttHhistoCounterAnalyzer.py
  • Loading branch information
peruzzim authored and mdunser committed Jan 25, 2016
1 parent ece2fac commit a75e9a3
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CMGTools/TTHAnalysis/python/analyzers/susyCore_modules_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from CMGTools.TTHAnalysis.analyzers.ttHhistoCounterAnalyzer import ttHhistoCounterAnalyzer
susyCounter = cfg.Analyzer(
ttHhistoCounterAnalyzer, name="ttHhistoCounterAnalyzer",
SMS_max_mass = 3000, # maximum mass allowed in the scan
SMS_mass_1 = 'genSusyMScan1', # first scanned mass
SMS_mass_2 = 'genSusyMScan2', # second scanned mass
SMS_varying_masses = [], # other mass variables that are expected to change in the tree (e.g., in T1tttt it should be set to ['genSusyMGluino','genSusyMNeutralino'])
SMS_regexp_evtGenMass = 'genSusyM.+',
bypass_trackMass_check = True # bypass check that non-scanned masses are the same in all events
)

PDFWeights = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def readLHE(self,event):
scanline = re.compile(r"#\s*model\s+([A-Za-z0-9]+)_((\d+\.?\d*)(_\d+\.?\d*)*)(\s+(\d+\.?\d*))*\s*")
for i in xrange(lheprod.comments_size()):
comment = lheprod.getComment(i)
if (not hasattr(self,'model_printed')) and ('model' in comment):
print 'LHE contains this model string: %s (will not print the ones in the following events)'%comment
self.model_printed = True
m = re.match(scanline, comment)
if m:
event.susyModel = m.group(1)
Expand Down
60 changes: 52 additions & 8 deletions CMGTools/TTHAnalysis/python/analyzers/ttHhistoCounterAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

import ROOT
import os
import re

class ttHhistoCounterAnalyzer( Analyzer ):
def __init__(self, cfg_ana, cfg_comp, looperName ):
super(ttHhistoCounterAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
self.doLHE = getattr(cfg_ana, 'doLHE', True)
self.cfg_ana = cfg_ana
self.isInitSMS = False

def declareHandles(self):
super(ttHhistoCounterAnalyzer, self).declareHandles()
Expand All @@ -32,33 +35,74 @@ def beginLoop(self, setup):
setup.services["outputfile"].file.cd()
self.inputCounter = ROOT.TH1D("Count","Count",1,0,2)
if self.cfg_comp.isMC:
self.inputCounterSMS = ROOT.TH3D("CountSMS","CountSMS",3001,-0.5,3000.5,3001,-0.5,3000.5,1,0,2)
self.maxSMSmass = getattr(self.cfg_ana, 'SMS_max_mass', 3000)
self.inputCounterSMS = ROOT.TH3D("CountSMS","CountSMS",int(self.maxSMSmass+1),-0.5,self.maxSMSmass+0.5,int(self.maxSMSmass+1),-0.5,self.maxSMSmass+0.5,1,0,2)
if self.doLHE:
self.inputLHE = ROOT.TH1D("CountLHE","CountLHE",20001,-0.5,20000.5)
# self.inputLHESMS = ROOT.TH3D("CountLHESMS","CountLHESMS",3001,-0.5,3000.5,3001,-0.5,3000.5,10001,-0.5,10000.5) ### too big!
self.inputLHE = ROOT.TH1D("CountLHE","CountLHE",10001,-0.5,10000.5)
# self.inputLHESMS = ROOT.TH3D("CountLHESMS","CountLHESMS",int(self.maxSMSmass+1),-0.5,self.maxSMSmass+0.5,int(self.maxSMSmass+1),-0.5,self.maxSMSmass+0.5,10001,-0.5,10000.5) ### too big!
self.inputGenWeights = ROOT.TH1D("SumGenWeights","SumGenWeights",1,0,2)
self.inputGenWeightsSMS = ROOT.TH3D("SumGenWeightsSMS","SumGenWeightsSMS",3001,-0.5,3000.5,3001,-0.5,3000.5,1,0,2)
self.inputGenWeightsSMS = ROOT.TH3D("SumGenWeightsSMS","SumGenWeightsSMS",int(self.maxSMSmass+1),-0.5,self.maxSMSmass+0.5,int(self.maxSMSmass+1),-0.5,self.maxSMSmass+0.5,1,0,2)

def initSMS(self,event):
if self.isInitSMS: raise RuntimeError, 'Trying to initSMS twice!'
self.massfill1 = getattr(self.cfg_ana, 'SMS_mass_1', 'genSusyMScan1')
self.massfill2 = getattr(self.cfg_ana, 'SMS_mass_2', 'genSusyMScan2')
self.masses_to_track = [self.massfill1,self.massfill2]
for mass in getattr(self.cfg_ana, 'SMS_varying_masses', []):
if mass not in self.masses_to_track: self.masses_to_track.append(mass)
self.allmasses={}
self.genMregexp = getattr(self.cfg_ana, 'SMS_regexp_evtGenMass', 'genSusyM.+')
for name in dir(event):
if not re.match(self.genMregexp,name): continue
self.allmasses[name]=-1
self.susyModel = event.susyModel
for trkM in self.masses_to_track:
if trkM not in self.allmasses: raise RuntimeError, 'Trying to track a SUSY SMS gen mass that does not exist in the event: %s'%trkM
for mass in self.allmasses:
self.allmasses[mass] = getattr(event,mass)
self.bypass_trackMass_check = getattr(self.cfg_ana, 'bypass_trackMass_check', False)
self.isInitSMS=True
print 'SUSY SMS: the first event looks like this:'
for mass,val in self.allmasses.iteritems():
tag = '???'
if mass == self.massfill1: tag = 'used as first tracked mass'
elif mass == self.massfill2: tag = 'used as second tracked mass'
elif mass in self.masses_to_track: tag = 'allowed to change between different events'
else: tag = 'not allowed to change between different events unless bypass_trackMass_check is set to True'
print '%s = %.1f, %s'%(mass,val,tag)

def process(self, event):
self.readCollections( event.input )
self.inputCounter.Fill(1)

isSMS = self.cfg_comp.isMC and event.susyModel

if isSMS:
if max(event.genSusyMScan1,event.genSusyMScan2)>3000: raise RuntimeError, 'Histograms are not wide enough to contain this mass point: %f,%f'%(event.genSusyMScan1,event.genSusyMScan2)
self.inputCounterSMS.Fill(event.genSusyMScan1,event.genSusyMScan2,1)

if not self.isInitSMS: self.initSMS(event)

if event.susyModel!=self.susyModel: raise RuntimeError, 'The SMS model changed in the middle of the run, from %s to %s!'%(self.susyModel,event.susyModel)
if not self.bypass_trackMass_check:
for mass,val in self.allmasses.iteritems():
if mass in self.masses_to_track: continue
if val!=getattr(event,mass): raise RuntimeError, 'An untracked SMS mass (%s) changed in the middle of the run! If expected, add it to the SMS_varying_masses list.'%mass

m1 = getattr(event,self.massfill1)
m2 = getattr(event,self.massfill2)
if max(m1,m2)>self.maxSMSmass: raise RuntimeError, 'SMS mass found too large to be contained in the histogram: %f. Adapt the SMS_regexp_evtGenMass parameter.'%max(m1,m2)
self.inputCounterSMS.Fill(m1,m2,1)

if self.cfg_comp.isMC:
if self.doLHE:
for w in event.LHE_weights:
id_ = float(w.id)
wgt_ = float(w.wgt)
self.inputLHE.Fill(id_, wgt_)
# if isSMS: self.inputLHESMS.Fill(event.genSusyMScan1,event.genSusyMScan2,id_, wgt_)
# if isSMS: self.inputLHESMS.Fill(m1,m2,id_, wgt_)

if self.cfg_comp.isMC:
genWeight_ = float(self.mchandles['GenInfo'].product().weight())
self.inputGenWeights.Fill(1, genWeight_);
if isSMS: self.inputGenWeightsSMS.Fill(event.genSusyMScan1,event.genSusyMScan2,1, genWeight_);
if isSMS: self.inputGenWeightsSMS.Fill(m1,m2,1, genWeight_);

return True
Loading

0 comments on commit a75e9a3

Please sign in to comment.