Skip to content

Commit

Permalink
Merge pull request cms-sw#245 from CMSRA1/heppy_7_2_2_patch2
Browse files Browse the repository at this point in the history
Cherry picked Heppy only commits related to PR 242
  • Loading branch information
gpetruc committed Feb 11, 2015
2 parents 557e9bd + fb96110 commit 195501c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
20 changes: 20 additions & 0 deletions PhysicsTools/Heppy/python/analyzers/objects/METAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ def makeMETNoMu(self, event):
px,py = event.metNoMuNoPU.px()-mupx, event.metNoMuNoPU.py()-mupy
event.metNoMuNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))

def makeMETNoPhoton(self, event):
event.metNoPhoton = copy.deepcopy(event.met)
event.metNoPhotonNoPU = copy.deepcopy(event.metNoPU)

phopx = 0
phopy = 0
#sum photon momentum
for pho in event.selectedPhotons:
phopx += pho.px()
phopy += pho.py()

#subtract photon momentum and construct met
px,py = event.metNoPhoton.px()-phopx, event.metNoPhoton.py()-phopy
event.metNoPhoton.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
px,py = event.metNoPhotonNoPU.px()-phopx, event.metNoPhotonNoPU.py()-phopy
event.metNoPhotonNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))


def makeMETs(self, event):
event.met = self.handles['met'].product()[0]
Expand All @@ -96,6 +113,8 @@ def makeMETs(self, event):
if self.cfg_ana.doMetNoMu and hasattr(event, 'selectedMuons'):
self.makeMETNoMu(event)

if self.cfg_ana.doMetNoPhoton and hasattr(event, 'selectedPhotons'):
self.makeMETNoPhoton(event)

def process(self, event):
self.readCollections( event.input)
Expand All @@ -117,6 +136,7 @@ def process(self, event):
recalibrate = True,
doTkMet = False,
doMetNoMu = False,
doMetNoPhoton = False,
candidates='packedPFCandidates',
candidatesTypes='std::vector<pat::PackedCandidate>',
dzMax = 0.1,
Expand Down
19 changes: 14 additions & 5 deletions PhysicsTools/HeppyCore/python/utils/batchmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def RunningMode(self, batch):
"LXPLUS" : batch command is bsub, and logged on lxplus
"PSI" : batch command is qsub, and logged to t3uiXX
"IC" : batch command is qsub, and logged to hep.ph.ic.ac.uk
"LOCAL" : batch command is nohup.
In all other cases, a CmsBatchException is raised
'''
Expand All @@ -239,6 +240,7 @@ def RunningMode(self, batch):
onLxplus = hostName.startswith('lxplus')
onPSI = hostName.startswith('t3ui' )
onPISA = re.match('.*gridui.*',hostName) or re.match('.*faiwn.*',hostName)
onIC = 'hep.ph.ic.ac.uk' in hostName
batchCmd = batch.split()[0]

if batchCmd == 'bsub':
Expand All @@ -252,12 +254,19 @@ def RunningMode(self, batch):
print 'running on LSF lxplus: %s from %s' % (batchCmd, hostName)
return 'LXPLUS'
elif batchCmd == "qsub":
if not onPSI:
err = 'Cannot run %s on %s' % (batchCmd, hostName)
raise ValueError( err )
#if not onPSI:
# err = 'Cannot run %s on %s' % (batchCmd, hostName)
# raise ValueError( err )

if onIC:
print 'running on IC : %s from %s' % (batchCmd, hostName)
return 'IC'

else:
print 'running on SGE : %s from %s' % (batchCmd, hostName)
return 'PSI'
if onPSI:
print 'running on SGE : %s from %s' % (batchCmd, hostName)
return 'PSI'

elif batchCmd == 'nohup' or batchCmd == './batchScript.sh':
print 'running locally : %s on %s' % (batchCmd, hostName)
return 'LOCAL'
Expand Down
22 changes: 21 additions & 1 deletion PhysicsTools/HeppyCore/scripts/heppy_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ def batchScriptPSI( index, jobDir, remoteDir=''):

return script

def batchScriptIC(jobDir):
'''prepare a IC version of the batch script'''


cmssw_release = os.environ['CMSSW_BASE']
script = """#!/bin/bash
export X509_USER_PROXY=/home/hep/$USER/myproxy
source /vols/cms/grid/setup.sh
cd {jobdir}
cd {cmssw}/src
eval `scramv1 ru -sh`
cd -
echo 'running'
python {cmssw}/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck
echo
echo 'sending the job directory back'
mv Loop/* ./
""".format(jobdir = jobDir,cmssw = cmssw_release)
return script

def batchScriptLocal( remoteDir, index ):
'''prepare a local version of the batch script, to run using nohup'''
Expand All @@ -175,7 +194,6 @@ def batchScriptLocal( remoteDir, index ):
return script



class MyBatchManager( BatchManager ):
'''Batch manager specific to cmsRun processes.'''

Expand All @@ -197,6 +215,8 @@ def PrepareJobUser(self, jobDir, value ):
scriptFile.write( batchScriptLocal( storeDir, value) ) # watch out arguments are swapped (although not used)
elif mode == 'PISA' :
scriptFile.write( batchScriptPISA( storeDir, value) )
elif mode == 'IC':
scriptFile.write( batchScriptIC(jobDir) )
scriptFile.close()
os.system('chmod +x %s' % scriptFileName)

Expand Down

0 comments on commit 195501c

Please sign in to comment.