Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-23 03:27:42

0001 #!/usr/bin/env python
0002 
0003 from __future__ import print_function
0004 import os, sys
0005 
0006 #====================== check input ==========================
0007 
0008 VERSION = os.environ.get('CMSSW_VERSION')
0009 if VERSION is None:
0010     print('''No environment CMSSW_VERSION''')
0011         sys.exit()
0012 
0013 if len(sys.argv) < 5:
0014     print('Usage: python run.py PhysList Particle Fhcal VAR')
0015     print('Example: python run.py FTFP_BERT pi- 106.5 RR')
0016     sys.exit()
0017 else:   
0018     phys = sys.argv[1]
0019     part = sys.argv[2]
0020     hcal = sys.argv[3]
0021     var  = sys.argv[4]
0022 
0023 text = 'Start RUN for ' + phys + ' ' + part + ' ' + hcal + ' ' + var
0024 print(text)
0025 
0026 cmd = 'mkdir -p ' + VERSION
0027 os.system(cmd)
0028 
0029 fname = VERSION + '/' + phys + '_' + part + '_' + var + '_'
0030 
0031 #====================== beam choice ==========================
0032 
0033 listEpin  = ['2','2.5','3','4','5','6','7','8','9','20','30','50','100','150','200','300']
0034 listEpip  = ['2','3','4','5','6','7','8','9','20']
0035 listEp    = ['2.21','3.14','4.11','5.09','6.07','7.06','8.05','9.05','20','30','350']
0036 listPp    = ['2','3','4','5','6','7','8','9','20','30','350']
0037 listEpbar = ['2.21','2.67','3.14','4.11','5.09','6.07','7.06','8.05','9.05']
0038 listPpbar = ['2','2.5','3','4','5','6','7','8','9']
0039 listEkp   = ['2.06','3.08','4.03','5','6','7','8','9']
0040 listPkp   = ['2','3','4','5','6','7','8','9']
0041 listEkn   = ['2.55','3.08','4.03','5','6','7','8','9']
0042 listPkn   = ['2.5','3','4','5','6','7','8','9']
0043 listEe    = ['50']
0044 
0045 pdg = '-211'
0046 geom = 'SimG4CMS.HcalTestBeam.TB2006GeometryXML_cfi'
0047 nE = int(16)
0048 ecal = '1.01'
0049 stat = '5000'
0050 
0051 if(part == 'e-') :
0052   pdg = '11'
0053   listE = listEe
0054   listP = listEe
0055   nE = int(1)
0056   hcal = '100'
0057   geom = 'SimG4CMS.HcalTestBeam.TB2006GeometryNoEcalXML_cfi'
0058 
0059 if(part == 'pi-') :
0060   listE = listEpin
0061   listP = listEpin
0062 
0063 if(part == 'pi+') :
0064   pdg = '211'
0065   listE = listEpip
0066   listP = listEpip
0067   nE = int(9)
0068 
0069 if(part == 'p') :
0070   pdg = '2212'
0071   listE = listEp
0072   listP = listPp
0073   nE = int(11)
0074 
0075 if(part == 'pbar') :
0076   pdg = '-2212'
0077   listE = listEpbar
0078   listP = listPpbar
0079   nE = int(9)
0080 
0081 if(part == 'kaon+') :
0082   pdg = '321'
0083   listE = listEkp
0084   listP = listPkp
0085   nE = int(8)
0086 
0087 if(part == 'kaon-') :
0088   pdg = '-321'
0089   listE = listEkn
0090   listP = listPkn
0091   nE = int(8)
0092 
0093 if(var == 'NO') :
0094   geom = 'SimG4CMS.HcalTestBeam.TB2006GeometryNoEcalXML_cfi'
0095   
0096 #====================== event loop ==========================
0097 
0098 outf = fname + '.log'
0099 cmd4 = 'rm -f ' + outf
0100 os.system(cmd4)
0101 cmd1 = 'echo "Start loop" > ' + outf
0102 print(cmd1)
0103 os.system(cmd1)
0104 
0105 for i in range( nE) :
0106   fnametmp = fname + '.py'
0107   cmd3 = 'rm -f ' + fnametmp
0108   os.system(cmd3)
0109   pfile = open(fnametmp, "w")
0110   pfile.write('import FWCore.ParameterSet.Config as cms \n\n' )
0111   pfile.write('from Configuration.Eras.Modifier_h2tb_cff import h2tb   \n\n' )
0112   pfile.write('process = cms.Process("PROD", h2tb) \n\n' )
0113   pfile.write('process.load("' + geom + '") \n\n')
0114   pfile.write('from SimG4CMS.HcalTestBeam.TB2006Analysis_cfi import * \n')
0115   pfile.write('process = testbeam2006(process) \n\n')
0116   pfile.write('process.TFileService = cms.Service("TFileService", \n')
0117   pfile.write('  fileName = cms.string("' + fname + listP[i] + 'gev.root") \n')
0118   pfile.write(') \n\n')
0119   pfile.write('process.common_beam_direction_parameters.MinE = cms.double('+listE[i]+') \n')
0120   pfile.write('process.common_beam_direction_parameters.MaxE = cms.double('+listE[i]+') \n')
0121   pfile.write('process.common_beam_direction_parameters.PartID = cms.vint32('+pdg+') \n')
0122   pfile.write('process.generator.PGunParameters.MinE = process.common_beam_direction_parameters.MinE \n')
0123   pfile.write('process.generator.PGunParameters.MaxE = process.common_beam_direction_parameters.MaxE \n')
0124   pfile.write('process.generator.PGunParameters.PartID = process.common_beam_direction_parameters.PartID \n')
0125   pfile.write('process.VtxSmeared.MinE = process.common_beam_direction_parameters.MinE \n')
0126   pfile.write('process.VtxSmeared.MaxE = process.common_beam_direction_parameters.MaxE \n')
0127   pfile.write('process.VtxSmeared.PartID = process.common_beam_direction_parameters.PartID \n')
0128   pfile.write('process.testbeam.MinE = process.common_beam_direction_parameters.MinE \n')
0129   pfile.write('process.testbeam.MaxE = process.common_beam_direction_parameters.MaxE \n')
0130   pfile.write('process.testbeam.PartID = process.common_beam_direction_parameters.PartID \n')
0131   if(part == 'e-') : pfile.write('process.testbeam.ECAL = cms.bool(False) \n')
0132   if(var == 'NO') : pfile.write('process.testbeam.ECAL = cms.bool(False) \n')
0133   pfile.write('process.testbeam.TestBeamAnalysis.EcalFactor = cms.double(' + ecal + ') \n')
0134   pfile.write('process.testbeam.TestBeamAnalysis.HcalFactor = cms.double(' + hcal + ') \n\n')
0135   pfile.write('process.maxEvents = cms.untracked.PSet( \n')
0136   pfile.write('  input = cms.untracked.int32(' + stat + ') \n')
0137   pfile.write(') \n\n')
0138   pfile.write('process.g4SimHits.Physics.type = "SimG4Core/Physics/' + phys + '" \n\n')
0139   pfile.write('process.g4SimHits.OnlySDs = ["CaloTrkProcessing", "EcalTBH4BeamDetector", "HcalTB02SensitiveDetector", "HcalTB06BeamDetector", "EcalSensitiveDetector", "HcalSensitiveDetector"] \n\n')
0140   pfile.close()
0141   cmd2 = 'cmsRun ' + fnametmp + ' >> ' + outf 
0142   os.system(cmd2)
0143 
0144 #====================== end ==========================