Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:40

0001 ######################################################
0002 #                                                    #
0003 #       relval_simulation_module                     #
0004 #                                                    #  
0005 #  This module is a collection of the simulation     # 
0006 #  procedues. The random number service is built     #
0007 #  by the function random_generator_service(energy)  #
0008 #                                                    #
0009 ######################################################
0010 
0011 import FWCore.ParameterSet.Config as cms
0012 import relval_common_module as common
0013 
0014 from math import pi as PI
0015 import os
0016 import sys
0017 
0018 #---------------------------------------------------
0019 # This just simplifies the use of the logger
0020 mod_id="["+os.path.basename(sys._getframe().f_code.co_filename)[:-3]+"]"
0021 
0022 #----------------------------
0023 # Some useful constants:
0024 ETA_MAX=2.5
0025 ETA_MIN=-2.5
0026 
0027 def generate(step, evt_type, energy, evtnumber):
0028     """
0029     This function calls all the other functions specific for
0030     an event evt_type.
0031     """
0032    
0033     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0034     common.log( func_id+" Entering... ")
0035     
0036     # Build the switch cases:
0037     
0038     # Particle Gun
0039     if evt_type in ("MU+","MU-","E","DIE","GAMMA","TAU","PI0","PI+","PI-"):
0040        generator = _generate_PGUN\
0041          (step, evt_type, energy, evtnumber)
0042      
0043     elif evt_type in ("HZZMUMUMUMU", "HZZEEEE", "HZZTTTT", "HZZLLLL","HGG"):
0044        generator = _generate_Higgs\
0045          (step, evt_type, energy, evtnumber)
0046      
0047     elif evt_type in ("B_JETS", "C_JETS"):
0048        generator = _generate_udscb_jets\
0049          (step, evt_type, energy, evtnumber)        
0050     
0051     elif evt_type in ("QCD","TTBAR","ZPJJ","MINBIAS","RS1GG","HpT"):
0052         generator = eval("_generate_"+evt_type+"(step, evt_type, energy, evtnumber)") 
0053     
0054     elif evt_type in ("ZEE","ZTT","ZMUMU"):
0055         generator = _generate_Zll\
0056          (step, evt_type, energy, evtnumber)
0057 
0058     elif evt_type in ("ZPEE","ZPTT","ZPMUMU"):
0059         generator = _generate_ZPll\
0060          (step, evt_type, energy, evtnumber)         
0061              
0062     elif evt_type in ("WE","WM","WT"):
0063         generator = _generate_Wl(step, evt_type, energy, evtnumber)
0064          
0065     else:
0066       raise RuntimeError("Event type Type not yet implemented.")
0067              
0068     common.log( func_id+" Returning Generator")
0069     
0070     return generator
0071 
0072 #------------------------------       
0073 
0074 def _generate_PGUN(step, evt_type, energy, evtnumber):
0075     """
0076     Here the settings for the simple generation of a muon, electron or gamma
0077     are stated.
0078     """
0079     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0080     common.log( func_id+" Entering... ")
0081 
0082    # pythia ID: configure the ID of the particle through a dictionary
0083     py_id_dict = {"MU-":13, 
0084                   "MU+":-13,
0085                   "E" :11,
0086                   "DIE":11,
0087                   "TAU":15,
0088                   "GAMMA":22,
0089                   "PI+":211,
0090                   "PI-":-211,
0091                   "PI0":111}
0092     
0093     # Build the id string of the event name:
0094     id_string = evt_type+" "+energy+" nevts "+ str(evtnumber)    
0095                   
0096     # We have to check if we want to generate a particle with pt=X or Energy=X                  
0097     pt_flag=True
0098     if 'pt' in energy[0:2] or \
0099        'Pt' in energy[0:2] or \
0100        'PT' in energy[0:2]:
0101         energy=energy[2:]
0102     else:
0103         pt_flag=False         
0104                   
0105     # Energy boundaries are now set:      
0106     lower_energy = ""
0107     upper_energy = ""
0108     
0109 
0110 
0111     # Build the partID string
0112     part_id = cms.untracked.vint32 ()
0113 
0114     part_id.append(py_id_dict[evt_type])
0115     upper_energy=''
0116     lower_energy=''
0117     if energy.find('_')!=-1:
0118         upper_energy,lower_energy=energy_split(energy)
0119     else:    
0120         epsilon= 0.001
0121         lower_energy = str ( int(energy) - epsilon) # We want a calculation and
0122         upper_energy = str ( int(energy) + epsilon) # the result as a string   
0123     
0124     # Build the process source
0125     if evt_type in ("TAU","E"):
0126         # Add the corresponding opposite sign particle. Only for taus and es.
0127         part_id.append(-1*part_id[0])
0128     
0129     antip_flag=False
0130     if evt_type=="DIE":
0131         antip_flag=True  
0132     
0133     if pt_flag:        
0134         common.log( func_id+ "This is a pt particle gun ..." )
0135         generator = cms.EDProducer("FlatRandomPtGunProducer",
0136                             psethack = cms.string(id_string),
0137                             firstRun = cms.untracked.uint32(1),
0138                             PGunParameters = cms.PSet(
0139                                 PartID = part_id,
0140                                 MinEta = cms.double(ETA_MAX),
0141                                 MaxEta = cms.double(ETA_MIN),
0142                                 MinPhi = cms.double(-PI),
0143                                 MaxPhi = cms.double(PI),
0144                                 MinPt  = cms.double(lower_energy),
0145                                 MaxPt  = cms.double(upper_energy) 
0146                             ),
0147                             AddAntiParticle=cms.bool(antip_flag),
0148                             Verbosity = cms.untracked.int32(0)
0149                         )
0150     else:
0151         common.log( func_id+ " This is an Energy particle gun ..." )
0152         generator = cms.EDProducer("FlatRandomEGunProducer",
0153                             psethack = cms.string(id_string),
0154                             firstRun = cms.untracked.uint32(1),
0155                             PGunParameters = cms.PSet(
0156                                 PartID = part_id,
0157                                 MinEta = cms.double(ETA_MAX),
0158                                 MaxEta = cms.double(ETA_MIN),
0159                                 MinPhi = cms.double(-PI),
0160                                 MaxPhi = cms.double(PI),
0161                                 MinE = cms.double(lower_energy),
0162                                 MaxE = cms.double(upper_energy) 
0163                             ),
0164                             AddAntiParticle=cms.bool(antip_flag),
0165                             Verbosity = cms.untracked.int32(0)
0166                         )       
0167                         
0168     common.log( func_id+" Returning Generator...")
0169         
0170     return generator 
0171    
0172 #---------------------------
0173     
0174 def _generate_QCD(step, evt_type, energy, evtnumber):
0175     """
0176     Here the settings for the generation of QCD events 
0177     """
0178     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0179     common.log( func_id+" Entering... ")   
0180         
0181     # Recover the energies from the string:
0182     upper_energy, lower_energy = energy_split(energy)
0183     
0184     # Build the process source   
0185     generator = cms.EDFilter("Pythia6GeneratorFilter",
0186                         pythiaPylistVerbosity=cms.untracked.int32(0),
0187                         pythiaHepMCVerbosity=cms.untracked.bool(False),
0188                         maxEventsToPrint = cms.untracked.int32(0), 
0189                         filterEfficiency = cms.untracked.double(1),  
0190                         PythiaParameters = cms.PSet\
0191                         (parameterSets = cms.vstring\
0192                                             ("pythiaUESettings",
0193                                             "processParameters"),
0194                             pythiaUESettings = user_pythia_ue_settings(),
0195                             processParameters = cms.vstring("MSEL=1",
0196                                                 "CKIN(3)="+upper_energy,
0197                                                 "CKIN(4)="+lower_energy))
0198                         )
0199      
0200     common.log( func_id+" Returning Generator...")                 
0201     return generator
0202  
0203 #---------------------------------
0204 
0205 def _generate_MINBIAS(step, evt_type, energy, evtnumber):
0206     """
0207     Settings for MINBIAS events generation
0208     """
0209     
0210     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0211     common.log( func_id+" Entering... ")     
0212     
0213     # Build the process source   
0214     generator = cms.EDFilter("Pythia6GeneratorFilter",
0215                       pythiaPylistVerbosity=cms.untracked.int32(0),
0216                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0217                       maxEventsToPrint = cms.untracked.int32(0), 
0218                       filterEfficiency = cms.untracked.double(1),  
0219                         PythiaParameters = cms.PSet\
0220                         (parameterSets = cms.vstring\
0221                                             ("pythiaUESettings",
0222                                              "processParameters"),
0223                             pythiaUESettings = user_pythia_ue_settings(),
0224                             processParameters = cms.vstring(
0225                                                 "MSEL=0",
0226                                                 "MSUB(11)=1",
0227                                                 "MSUB(12)=1",
0228                                                 "MSUB(13)=1",
0229                                                 "MSUB(28)=1",
0230                                                 "MSUB(53)=1",
0231                                                 "MSUB(68)=1",
0232                                                 "MSUB(92)=1",
0233                                                 "MSUB(93)=1",
0234                                                 "MSUB(94)=1",
0235                                                 "MSUB(95)=1"))
0236                         )
0237     common.log( func_id+" Returning Generator...")                 
0238     
0239     return generator   
0240     
0241 #---------------------------------
0242 
0243 def _generate_Higgs(step, evt_type, energy, evtnumber):
0244     """    
0245     Here the settings for the generation of Higgs->ZZ->ll events 
0246     The energy parameter is not used. According to the evt_type ("HZZMUMUMUMU" 
0247     or "HZZEEEE") the final state is chosen.
0248     """
0249     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0250     common.log( func_id+" Entering... ")      
0251     
0252     # Choose between muon, tau or electron decay of the Z
0253     z_flag="0"
0254     electron_flag = "0"
0255     muon_flag = "0"
0256     tau_flag = "0"
0257     gamma_flag="0"
0258     if evt_type == "HZZEEEE":
0259         electron_flag = "1"
0260         z_flag="1"
0261     elif evt_type == "HZZMUMUMUMU":
0262         muon_flag = "1"    
0263         z_flag="1"
0264     elif evt_type == "HZZTTTT":
0265         tau_flag = "1"
0266         z_flag="1"
0267     elif evt_type == "HZZLLLL":
0268         electron_flag=muon_flag=tau_flag= "1"
0269         z_flag="1"
0270     elif evt_type == "HGG":
0271         gamma_flag="1"    
0272 
0273   
0274     # Prepare The Pythia params  
0275     params = cms.vstring(
0276         "PMAS(25,1)=%s" %energy,      #mass of Higgs",
0277         "MSEL=0",                  
0278         #(D=1) to select between full user control
0279         #(0, then use MSUB) and some preprogrammed alternative: QCD hight pT
0280         #processes (1, then ISUB=11, 12, 13, 28, 53, 68), QCD low pT processes
0281         #(2, then ISUB=11, #12, 13, 28, 53, 68, 91, 92, 94, 95)",
0282         #
0283     #Check on possible errors during program
0284         #execution",
0285         "MSUB(102)=1",             #ggH",
0286         "MSUB(123)=1",             #ZZ fusion to H",
0287         "MSUB(124)=1",             #WW fusion to H",
0288         "CKIN(45)=5.",                       
0289         "CKIN(46)=150.",           
0290         #high mass cut on secondary resonance m1 in
0291         #2->1->2 process Registered by Alexandre.Nikitenko@cern.ch",
0292         "CKIN(47)=5.",             
0293         #low mass cut on secondary resonance m2 in
0294         #2->1->2 process Registered by Alexandre.Nikitenko@cern.ch",
0295         "CKIN(48)=150.",           
0296         #high mass cut on secondary resonance m2 in
0297         #2->1->2 process Registered by Alexandre.Nikitenko@cern.ch",
0298         "MDME(174,1)=0",           #Z decay into d dbar",        
0299         "MDME(175,1)=0",          #Z decay into u ubar",
0300         "MDME(176,1)=0",           #Z decay into s sbar",
0301         "MDME(177,1)=0",           #Z decay into c cbar",
0302         "MDME(178,1)=0",           #Z decay into b bbar",
0303         "MDME(179,1)=0",           #Z decay into t tbar",
0304         "MDME(182,1)=%s" %electron_flag,#Z decay into e- e+",
0305         "MDME(183,1)=0",           #Z decay into nu_e nu_ebar",
0306         "MDME(184,1)=%s" %muon_flag,#Z decay into mu- mu+",
0307         "MDME(185,1)=0",           #Z decay into nu_mu nu_mubar",
0308         "MDME(186,1)=%s" %tau_flag,#Z decay into tau- tau+",
0309         "MDME(187,1)=0",          #Z decay into nu_tau nu_taubar",
0310         "MDME(210,1)=0",           #Higgs decay into dd",
0311         "MDME(211,1)=0",           #Higgs decay into uu",
0312         "MDME(212,1)=0",           #Higgs decay into ss",
0313         "MDME(213,1)=0",           #Higgs decay into cc",
0314         "MDME(214,1)=0",           #Higgs decay into bb",
0315         "MDME(215,1)=0",           #Higgs decay into tt",
0316         "MDME(216,1)=0",           #Higgs decay into",
0317         "MDME(217,1)=0",           #Higgs decay into Higgs decay",
0318         "MDME(218,1)=0",           #Higgs decay into e nu e",
0319         "MDME(219,1)=0",           #Higgs decay into mu nu mu",
0320         "MDME(220,1)=0",           #Higgs decay into tau nu tau",
0321         "MDME(221,1)=0",           #Higgs decay into Higgs decay",
0322         "MDME(222,1)=0",           #Higgs decay into g g",
0323         "MDME(223,1)=%s" %gamma_flag,#Higgs decay into gam gam",
0324         "MDME(224,1)=0",           #Higgs decay into gam Z",
0325         "MDME(225,1)=%s" %z_flag,  #Higgs decay into Z Z",
0326         "MDME(226,1)=0",           #Higgs decay into W W"
0327         ) 
0328 
0329     # Build the process source   
0330     generator = cms.EDFilter('Pythia6GeneratorFilter',
0331                       pythiaPylistVerbosity=cms.untracked.int32(0),
0332                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0333                       maxEventsToPrint = cms.untracked.int32(0), 
0334                       filterEfficiency = cms.untracked.double(1),  
0335                       pythiaVerbosity =cms.untracked.bool(False),
0336                       PythiaParameters = cms.PSet\
0337                        (parameterSets = cms.vstring('PythiaUESettings','processParameters'),
0338                         PythiaUESettings = user_pythia_ue_settings(),
0339                         processParameters=params
0340                        )     
0341                      )
0342 
0343     common.log( func_id+" Returning Generator...")
0344      
0345     return generator      
0346 
0347 #---------------------------------
0348 
0349 def _generate_udscb_jets\
0350         (step, evt_type, energy, evtnumber):
0351     """
0352     Here the settings necessary to udscb jets generation are added. According
0353     to the flavour the Pythia parameters are changed slightly.
0354     For the time being the energy parameter is not used.
0355     """
0356     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0357     common.log( func_id+" Entering... ")
0358     
0359     # Recover the energies from the string:
0360     upper_energy, lower_energy = energy_split(energy)
0361    
0362     # According to the evt_type build the Pythia settings:
0363     pythia_jet_settings=cms.vstring("MSEL=0")  # User defined process
0364     pythia_jet_settings+=cms.vstring("MSUB(81)=1", #qq->QQ massive
0365                                      "MSUB(82)=1") #gg->QQ massive
0366     if evt_type == "C_JETS":
0367             pythia_jet_settings+=cms.vstring("MSTP(7)=4") #ccbar
0368             common.log( func_id+" Including settings for c jets")
0369     else:
0370             pythia_jet_settings+=cms.vstring("MSTP(7)=5") #bbbar
0371             common.log( func_id+" Including settings for b jets")
0372              
0373     # Common part to all cases         
0374     pythia_common=cms.vstring("CKIN(3)="+upper_energy,  # Pt low cut 
0375                               "CKIN(4)="+lower_energy,  # Pt high cut
0376                               "CKIN(13)=0.",            # eta min            
0377                               "CKIN(14)=2.5",           # etamax           
0378                               "CKIN(15)=-2.5",          # -etamin 
0379                               "CKIN(16)=0"              # -etamax
0380                               )
0381     
0382     pythia_jet_settings+=pythia_common
0383     
0384     # Build the process source
0385     generator = cms.EDFilter('Pythia6GeneratorFilter',
0386                       pythiaVerbosity =cms.untracked.bool(True),
0387                       PythiaParameters = cms.PSet\
0388                                (parameterSets = cms.vstring\
0389                                                    ("pythiaUESettings","pythiaJets"),
0390                                 pythiaUESettings = user_pythia_ue_settings(),
0391                                 pythiaJets = pythia_jet_settings
0392                                )
0393                      )                       
0394    
0395     common.log(func_id+" Returning Generator...")
0396      
0397     return generator
0398 
0399 #-----------------------------------
0400     
0401 def _generate_TTBAR(step, evt_type, energy, evtnumber):
0402     """
0403     Here the settings for the ttbar pairs are added to the process.
0404     """
0405       
0406     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0407     common.log(func_id+" Entering... ")      
0408     
0409     # Build the process source    
0410     generator = cms.EDFilter('Pythia6GeneratorFilter',
0411                       pythiaPylistVerbosity=cms.untracked.int32(0),
0412                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0413                       maxEventsToPrint = cms.untracked.int32(0), 
0414                       filterEfficiency = cms.untracked.double(1),                     
0415                       PythiaParameters = cms.PSet\
0416                                 (parameterSets = cms.vstring\
0417                                                    ('pythiaUESettings',
0418                                                     'processParameters'),
0419                                 pythiaUESettings = user_pythia_ue_settings(),
0420                                 # Tau jets (config by A. Nikitenko)
0421                                 # No tau -> electron
0422                                 # No tau -> muon
0423                                 processParameters =cms.vstring\
0424                                     ("MSEL=0",       # userdef process
0425                                      "MSUB(81)=1",   # qqbar->QQbar
0426                                      "MSUB(82)=1",   # gg to QQbar
0427                                      "MSTP(7)=6",    # flavour top
0428                                      "PMAS(6,1)=175" # top mass
0429                                      )
0430                                 ) 
0431                       )  
0432 
0433     common.log(func_id+" Returning Generator...")
0434      
0435     return generator   
0436  
0437 #---------------------------------
0438 
0439 def _generate_Zll(step, evt_type, energy, evtnumber):
0440     """
0441     Here the settings for the Z ee simulation are added to the process.
0442     Energy parameter is not used.
0443     """
0444       
0445     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0446     common.log( func_id+" Entering... ")      
0447 
0448     # Choose between muon or electron decay of the Z
0449     user_param_sets = "pythiaZll"
0450     electron_flag = "0"
0451     muon_flag = "0"
0452     tau_flag = "0"
0453     if evt_type == "ZEE":
0454         electron_flag = "1"
0455     elif evt_type == "ZMUMU":
0456         muon_flag = "1"    
0457     elif evt_type == "ZTT":
0458         tau_flag = "1"
0459     else:
0460         electron_flag=muon_flag=tau_flag= "1"    
0461     
0462     pythia_param_sets = cms.vstring(
0463                  "MSEL = 11 ",           
0464                  "MDME( 174,1) = 0",            #Z decay into d dbar",
0465                  "MDME( 175,1) = 0",            #Z decay into u ubar",
0466                  "MDME( 176,1) = 0",            #Z decay into s sbar",
0467                  "MDME( 177,1) = 0",            #Z decay into c cbar",
0468                  "MDME( 178,1) = 0",            #Z decay into b bbar",
0469                  "MDME( 179,1) = 0",            #Z decay into t tbar",
0470                  "MDME( 182,1) = %s" %electron_flag,#Z decay into e- e+",
0471                  "MDME( 183,1) = 0",            #Z decay into nu_e nu_ebar",
0472                  "MDME( 184,1) = %s" %muon_flag,#Z decay into mu- mu+",
0473                  "MDME( 185,1) = 0",            #Z decay into nu_mu nu_mubar",
0474                  "MDME( 186,1) = %s" %tau_flag, #Z decay into tau- tau+",
0475                  "MDME( 187,1) = 0",            #Z decay into nu_tau nu_taubar",
0476                  "MSTJ( 11) = 3",    #Choice of the fragmentation function",
0477                  "MSTP( 2) = 1",            #which order running alphaS",
0478                  "MSTP( 33) = 0",            #(D=0) ",
0479                  "MSTP( 51) = 7",            #structure function chosen",
0480                  "MSTP( 81) = 1",            #multiple parton interactions 1 is
0481                                              #Pythia default,
0482                  "MSTP( 82) = 4",            #Defines the multi-parton model",
0483                  "PARJ( 71) = 10.",            #for which ctau  10 mm",
0484                  "PARP( 82) = 1.9",   #pt cutoff for multiparton interactions",
0485                  "PARP( 89) = 1000.", #sqrts for which PARP82 is set",
0486                  "PARP( 83) = 0.5", #Multiple interactions: matter distrbn
0487                                     #parameter Registered byChris.Seez@cern.ch
0488                  "PARP( 84) = 0.4",   #Multiple interactions: matterdistribution
0489                                   #parameter Registered by Chris.Seez@cern.ch
0490                  "PARP( 90) = 0.16",  #Multiple interactions:rescaling power
0491                                       #Registered by Chris.Seez@cern.ch
0492                  "CKIN( 1) = 40.",            #(D=2. GeV)
0493                  "CKIN( 2) = -1.",            #(D=-1. GeV)      \
0494                  )     
0495                  
0496     # Build the process source
0497     generator = cms.EDFilter('Pythia6GeneratorFilter', 
0498                       pythiaPylistVerbosity=cms.untracked.int32(0),
0499                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0500                       maxEventsToPrint = cms.untracked.int32(0), 
0501                       filterEfficiency = cms.untracked.double(1),    
0502                       PythiaParameters = cms.PSet\
0503                                (parameterSets = cms.vstring('PythiaUESettings','processParameters'),
0504                                 PythiaUESettings=user_pythia_ue_settings(),
0505                                 processParameters=pythia_param_sets )
0506                      )
0507 
0508     common.log(func_id+" Returning Generator...")
0509      
0510     return generator   
0511 #---------------------------------
0512 
0513 def _generate_Wl(step, evt_type, energy, evtnumber):
0514     """
0515     Here the settings for the Z ee simulation are added to the process.
0516     Energy parameter is not used.
0517     """
0518       
0519     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0520     common.log( func_id+" Entering... ")      
0521 
0522     # Choose between muon or electron decay of the Z
0523     electron_flag = "0"
0524     muon_flag = "0"
0525     tau_flag = "0"
0526     if evt_type == "WE":
0527         electron_flag = "1"
0528     elif evt_type == "WM":
0529         muon_flag = "1"    
0530     elif evt_type == "WT":
0531         tau_flag = "1"    
0532         
0533     # Build the process source
0534     generator = cms.EDFilter('Pythia6GeneratorFilter', 
0535                       pythiaPylistVerbosity=cms.untracked.int32(0),
0536                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0537                       maxEventsToPrint = cms.untracked.int32(0), 
0538                       filterEfficiency = cms.untracked.double(1),
0539                       PythiaParameters = cms.PSet\
0540                                (parameterSets = cms.vstring('PythiaUESettings','processParameters'),
0541                                 PythiaUESettings=user_pythia_ue_settings(),
0542                                 processParameters=cms.vstring('MSEL=0    !User defined processes',
0543                                                               'MSUB(2)     = 1',#    !W production 
0544                                                               'MDME(190,1) = 0',#    !W decay into dbar u 
0545                                                               'MDME(191,1) = 0',#    !W decay into dbar c 
0546                                                               'MDME(192,1) = 0',#    !W decay into dbar t 
0547                                                               'MDME(194,1) = 0',#    !W decay into sbar u 
0548                                                               'MDME(195,1) = 0',#    !W decay into sbar c 
0549                                                               'MDME(196,1) = 0',#    !W decay into sbar t 
0550                                                               'MDME(198,1) = 0',#    !W decay into bbar u 
0551                                                               'MDME(199,1) = 0',#    !W decay into bbar c 
0552                                                               'MDME(200,1) = 0',#    !W decay into bbar t 
0553                                                               'MDME(205,1) = 0',#    !W decay into bbar tp 
0554                                                               'MDME(206,1) = %s' %electron_flag,#   !W decay into e+ nu_e 
0555                                                               'MDME(207,1) = %s' %muon_flag,#   !W decay into mu+ nu_mu 
0556                                                               'MDME(208,1) = %s' %tau_flag,#   !W decay into tau+ nu_tau
0557                                                              )
0558                               )
0559                      )
0560 
0561     common.log(func_id+" Returning Generator...")
0562      
0563     return generator       
0564                                    
0565 #---------------------------------
0566 
0567 def _generate_ZPJJ(step, evt_type, energy, evtnumber):
0568     """
0569     Here the settings for the Zprime to JJ simulation are added to the
0570     process. 
0571     """
0572     
0573     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0574     common.log(func_id+" Entering... ")            
0575     common.log( func_id+" Returning Generator...")
0576     # You might wonder why this time it's not pythonised..Me too: due to the excessive fragmentation of the 
0577     # cfgs it's not worth to do that at the moment. It also obliges to have two functions for the ZP instead of one.
0578     return common.include_files('Configuration/JetMET/data/calorimetry-gen-Zprime_Dijets_700.cff')[0].source                                   
0579 
0580 #---------------------------------
0581 
0582 def _generate_ZPll(step, evt_type, energy, evtnumber):
0583     """
0584     Here the settings for the Z ee simulation are added to the process.
0585     Energy parameter is not used.
0586     """
0587       
0588     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0589     common.log( func_id+" Entering... ")      
0590 
0591     # Choose between muon or electron decay of the Z
0592     electron_flag = "0"
0593     muon_flag = "0"
0594     tau_flag = "0"
0595     if evt_type == "ZPEE":
0596         electron_flag = "1"
0597     elif evt_type == "ZPMUMU":
0598         muon_flag = "1"    
0599     elif evt_type == "ZPTT":
0600         tau_flag = "1"
0601     else:
0602         electron_flag=muon_flag=tau_flag= "1"    
0603     
0604     # Build the process source
0605     generator = cms.EDFilter('Pythia6GeneratorFilter', 
0606                       pythiaPylistVerbosity=cms.untracked.int32(0),
0607                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0608                       maxEventsToPrint = cms.untracked.int32(0), 
0609                       filterEfficiency = cms.untracked.double(1),    
0610                       PythiaParameters = cms.PSet\
0611                                (parameterSets = cms.vstring('PythiaUESettings','processParameters'),
0612                                 PythiaUESettings=user_pythia_ue_settings(),
0613                                 processParameters=\
0614                                     cms.vstring('MSEL       = 0    ', 
0615                                                 'MSUB(141)  = 1    ',#  !ff  gamma z0 Z0', 
0616                                                 'MSTP(44)   = 3    ',#  !only select the Z process', 
0617                                                 'PMAS(32,1) = %s' %energy,#  !mass of Zprime', 
0618                                                 'CKIN(1)    = 400  ',#  !(D=2. GeV)', 
0619                                                 'MDME(289,1)= 0    ',#  !d dbar', 
0620                                                 'MDME(290,1)= 0    ',#  !u ubar', 
0621                                                 'MDME(291,1)= 0    ',#  !s sbar', 
0622                                                 'MDME(292,1)= 0    ',#  !c cbar', 
0623                                                 'MDME(293,1)= 0    ',#  !b bar', 
0624                                                 'MDME(294,1)= 0    ',#  !t tbar', 
0625                                                 'MDME(295,1)= 0    ',#  !4th gen Q Qbar', 
0626                                                 'MDME(296,1)= 0    ',# !4th gen Q Qbar', 
0627                                                 'MDME(297,1)= %s ' %electron_flag,#  !e e', 
0628                                                 'MDME(298,1)= 0    ',#  !neutrino e e', 
0629                                                 'MDME(299,1)= %s ' %muon_flag,#  ! mu mu', 
0630                                                 'MDME(300,1)= 0    ',#  !neutrino mu mu', 
0631                                                 'MDME(301,1)= %s    ' %tau_flag,#  !tau tau', 
0632                                                 'MDME(302,1)= 0    ',#  !neutrino tau tau', 
0633                                                 'MDME(303,1)= 0    ',#  !4th generation lepton', 
0634                                                 'MDME(304,1)= 0    ',#  !4th generation neutrino', 
0635                                                 'MDME(305,1)= 0    ',#  !W W', 
0636                                                 'MDME(306,1)= 0    ',#  !H  charged higgs', 
0637                                                 'MDME(307,1)= 0    ',#  !Z', 
0638                                                 'MDME(308,1)= 0    ',#  !Z', 
0639                                                 'MDME(309,1)= 0    ',#  !sm higgs', 
0640                                                 'MDME(310,1)= 0    ' #  !weird neutral higgs HA')
0641                                                )
0642                                )
0643                      )
0644 
0645     common.log(func_id+" Returning Generator...")
0646      
0647     return generator                   
0648                                       
0649 #-----------------------------------
0650 
0651 def _generate_RS1GG(step, evt_type, energy, evtnumber):
0652     """
0653     Here the settings for the RS1 graviton into gamma gamma.
0654     """
0655       
0656     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0657     common.log( func_id+" Entering... ")         
0658     
0659     # Build the process source
0660     generator = cms.EDFilter('Pythia6GeneratorFilter', 
0661                       pythiaPylistVerbosity=cms.untracked.int32(0),
0662                       pythiaHepMCVerbosity=cms.untracked.bool(False),
0663                       maxEventsToPrint = cms.untracked.int32(0), 
0664                       filterEfficiency = cms.untracked.double(1),    
0665                       PythiaParameters = cms.PSet\
0666                                (parameterSets = cms.vstring('PythiaUESettings','processParameters'),
0667                                 PythiaUESettings=user_pythia_ue_settings(),
0668                                 processParameters=\
0669                                     cms.vstring('MSEL=0   ', 
0670                                                 'MSUB(391)   =1   ', 
0671                                                 'MSUB(392)   =1   ', 
0672                                                 'PMAS(347,1) = %s ' %energy,# ! minv ', 
0673                                                 'PARP(50)    = 0.54 ',# ! 0.54 == c=0.1', 
0674                                                 'MDME(4158,1)=0   ',
0675                                                 'MDME(4159,1)=0   ',
0676                                                 'MDME(4160,1)=0   ',
0677                                                 'MDME(4161,1)=0   ',
0678                                                 'MDME(4162,1)=0   ',
0679                                                 'MDME(4163,1)=0   ',
0680                                                 'MDME(4164,1)=0   ',
0681                                                 'MDME(4165,1)=0   ',
0682                                                 'MDME(4166,1)=0   ',
0683                                                 'MDME(4167,1)=0   ',
0684                                                 'MDME(4168,1)=0   ',
0685                                                 'MDME(4169,1)=0   ',
0686                                                 'MDME(4170,1)=0   ',
0687                                                 'MDME(4170,1)=0   ',
0688                                                 'MDME(4171,1)=0   ',
0689                                                 'MDME(4172,1)=0   ',
0690                                                 'MDME(4173,1)=0   ',
0691                                                 'MDME(4174,1)=0   ',
0692                                                 'MDME(4175,1)=1   ',#! gamma gamma ', 
0693                                                 'MDME(4176,1)=0   ', 
0694                                                 'MDME(4177,1)=0   ', 
0695                                                 'MDME(4178,1)=0   ', 
0696                                                 'CKIN(3)=20.      ',#! minimum pt hat for hard interactions', 
0697                                                 'CKIN(4)=-1.      '#! maximum pt hat for hard interactions'
0698                                                )
0699                                )
0700                      )
0701 
0702     common.log(func_id+" Returning Generator...")
0703      
0704     return generator                     
0705 #-----------------------------------
0706 
0707 def _generate_HpT(step, evt_type, energy, evtnumber):
0708     """
0709     Here the settings for the RS1 graviton into gamma gamma.
0710     """
0711       
0712     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0713     common.log( func_id+" Entering... ")         
0714     
0715     # Build the process source
0716     generator = cms.EDFilter("Pythia6GeneratorFilter",
0717                       pythiaPylistVerbosity = cms.untracked.int32(0),
0718                       pythiaHepMCVerbosity = cms.untracked.bool(False),
0719                       maxEventsToPrint = cms.untracked.int32(0),
0720                       filterEfficiency = cms.untracked.double(1.0),
0721                       PythiaParameters = cms.PSet(\
0722                        parameterSets = cms.vstring('PythiaUESettings', 'processParameters', 'pythiaMSSMmhmax'),
0723                        PythiaUESettings=user_pythia_ue_settings(),
0724                        processParameters=cms.vstring\
0725                                ('MSEL = 0       ',#         ! user control', 
0726                                 'MSUB(401) = 1  ',#         ! gg->tbH+ Registered by Alexandre.Nikitenko@cern.ch', 
0727                                 'MSUB(402) = 1  ',#         ! qq->tbH+ Registered by Alexandre.Nikitenko@cern.ch', 
0728                                 'IMSS(1)= 1     ',#         ! MSSM ', 'RMSS(5) = 30.           ! TANBETA', 
0729                                 'RMSS(19) = 200.',#         ! (D=850.) m_A', 
0730                                 'MDME(503,1)=0  ',#         !Higgs(H+) decay into dbar            u', 
0731                                 'MDME(504,1)=0  ',#         !Higgs(H+) decay into sbar            c', 
0732                                 'MDME(505,1)=0  ',#         !Higgs(H+) decay into bbar            t', 
0733                                 'MDME(506,1)=0  ',#         !Higgs(H+) decay into b bar           t', 
0734                                 'MDME(507,1)=0  ',#         !Higgs(H+) decay into e+              nu_e', 
0735                                 'MDME(508,1)=0  ',#         !Higgs(H+) decay into mu+             nu_mu', 
0736                                 'MDME(509,1)=1  ',#        !Higgs(H+) decay into tau+            nu_tau', 
0737                                 'MDME(510,1)=0  ',#         !Higgs(H+) decay into tau prime+           nu_tau', 
0738                                 'MDME(511,1)=0  ',#         !Higgs(H+) decay into W+              h0', 
0739                                 'MDME(512,1)=0  ',#         !Higgs(H+) decay into ~chi_10         ~chi_1+', 
0740                                 'MDME(513,1)=0  ',#         !Higgs(H+) decay into ~chi_10         ~chi_2+', 
0741                                 'MDME(514,1)=0  ',#         !Higgs(H+) decay into ~chi_20         ~chi_1+', 
0742                                 'MDME(515,1)=0  ',#         !Higgs(H+) decay into ~chi_20         ~chi_2+', 
0743                                 'MDME(516,1)=0  ',#         !Higgs(H+) decay into ~chi_30         ~chi_1+', 
0744                                 'MDME(517,1)=0  ',#         !Higgs(H+) decay into ~chi_30         ~chi_2+', 
0745                                 'MDME(518,1)=0  ',#         !Higgs(H+) decay into ~chi_40         ~chi_1+', 
0746                                 'MDME(519,1)=0  ',#         !Higgs(H+) decay into ~chi_40         ~chi_2+', 
0747                                 'MDME(520,1)=0  ',#         !Higgs(H+) decay into ~t_1            ~b_1bar', 
0748                                 'MDME(521,1)=0  ',#         !Higgs(H+) decay into ~t_2            ~b_1bar', 
0749                                 'MDME(522,1)=0  ',#         !Higgs(H+) decay into ~t_1            ~b_2bar', 
0750                                 'MDME(523,1)=0  ',#         !Higgs(H+) decay into ~t_2            ~b_2bar', 
0751                                 'MDME(524,1)=0  ',#        !Higgs(H+) decay into ~d_Lbar         ~u_L', 
0752                                 'MDME(525,1)=0  ',#        !Higgs(H+) decay into ~s_Lbar         ~c_L', 
0753                                 'MDME(526,1)=0  ',#         !Higgs(H+) decay into ~e_L+           ~nu_eL', 
0754                                 'MDME(527,1)=0  ',#         !Higgs(H+) decay into ~mu_L+          ~nu_muL', 
0755                                 'MDME(528,1)=0  ',#         !Higgs(H+) decay into ~tau_1+         ~nu_tauL', 
0756                                 'MDME(529,1)=0  '#        !Higgs(H+) decay into ~tau_2+         ~nu_tauL'),
0757                                ),          
0758                         pythiaMSSMmhmax = cms.vstring\
0759                               ('RMSS(2)= 200.    ',#       ! SU(2) gaugino mass ', 
0760                                'RMSS(3)= 800.    ',#       ! SU(3) (gluino) mass ', 
0761                                'RMSS(4)= 200.    ',#      ! higgsino mass parameter', 
0762                                'RMSS(6)= 1000.   ',#       ! left slepton mass', 
0763                                'RMSS(7)= 1000.   ',#       ! right slepton mass', 
0764                                'RMSS(8)= 1000.   ',#       ! right slepton mass', 
0765                                'RMSS(9)= 1000.   ',#       ! right squark mass', 
0766                                'RMSS(10)= 1000.  ',#       ! left sq mass for 3th gen/heaviest stop mass', 
0767                                'RMSS(11)= 1000.  ',#       ! right sbottom mass/lightest sbotoom mass', 
0768                                'RMSS(12)= 1000.  ',#       ! right stop mass/lightest stop mass', 
0769                                'RMSS(13)= 1000.  ',#       ! left stau mass', 
0770                                'RMSS(14)= 1000.  ',#       ! right stau mass', 
0771                                'RMSS(15)= 2449.  ',#       ! Ab', 
0772                                'RMSS(16)= 2449.  ',#       ! At', 
0773                                'RMSS(17)= 2449.  '#       ! Atau'
0774                               )
0775                        )
0776                      )
0777 
0778 
0779     common.log(func_id+" Returning Generator...")
0780      
0781     return generator     
0782     
0783 #---------------------------------    
0784 
0785 def energy_split(energy):
0786     """
0787     Extract from a string of the form "lowenergy*highenergy" two 
0788     bounds. It checks on its consistency. If the format is unknown 
0789     the program stops.
0790     """
0791     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0792     common.log( func_id+" Entering... ") 
0793     
0794     separator_list = ["-", #fault tolerance is good
0795                       "_",
0796                       "*",
0797                       "/",
0798                       ";",
0799                       ","]
0800     for separator in separator_list:
0801         if energy.count(separator)==1:
0802             common.log( func_id+" Found separator in energy string...") 
0803             low,high = energy.split(separator)
0804             if float(high) > float(low):
0805                 common.log(func_id+" Returning Energy...")
0806                 return (low,high)
0807     
0808     raise RuntimeError("Energy Format: Unrecognised energy format.")
0809 
0810 #-----------------------------------
0811 
0812 def user_pythia_ue_settings():
0813     """
0814     The function simply returns a cms.vstring which is a summary of the 
0815     Pythia settings for the event generation
0816     """
0817     
0818     
0819     
0820     func_id=mod_id+"["+sys._getframe().f_code.co_name+"]"
0821     common.log(func_id+" Returning PythiaUE settings...")
0822     
0823     return common.include_files('Configuration/Generator/data/PythiaUESettings.cfi')[0].pythiaUESettings
0824