Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 76543
b: "refs/heads/CMSSW_7_1_X"
c: bf63cb8
h: "refs/heads/CMSSW_7_1_X"
i:
  76541: 57eefa9
  76539: 3f86bb3
  76535: c1808fb
  76527: 261405e
  76511: 6bb7057
  76479: e8eebd3
  76415: bb7eb60
  76287: 41a603e
v: v3
  • Loading branch information
Matti Kortelainen committed Oct 28, 2009
1 parent 12cd8d6 commit 4ba77f8
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 91 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
refs/heads/gh-pages: 09c786f70121f131b3715aaf3464996502bbeb7e
"refs/heads/CMSSW_7_1_X": 3c6756e9d1040466c8ee29ddb760d3d69bd4b972
"refs/heads/CMSSW_7_1_X": bf63cb8a7a2d877cfd32081b640041bd1254959e
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "TauAnalysis/MCEmbeddingTools/interface/ParticleReplacerBase.h"

#include<string>

#include<boost/shared_ptr.hpp>

class MCParticleReplacer : public edm::EDProducer
Expand All @@ -39,9 +41,12 @@ class MCParticleReplacer : public edm::EDProducer
virtual void endJob();

private:
enum HepMcMode { kInvalid=0, kNew, kReplace };
static HepMcMode stringToHepMcMode(const std::string& name);

edm::InputTag src_;
edm::InputTag srcHepMC_;
unsigned int replacementMode_;
HepMcMode hepMcMode_;
boost::shared_ptr<ParticleReplacerBase> replacer_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "TTree.h"

#include<string>

class ParticleReplacerClass : public ParticleReplacerBase
{
public:
explicit ParticleReplacerClass(const edm::ParameterSet&);
explicit ParticleReplacerClass(const edm::ParameterSet&, bool);
~ParticleReplacerClass();

virtual std::auto_ptr<HepMC::GenEvent> produce(const reco::MuonCollection& muons, const reco::Vertex *pvtx=0, const HepMC::GenEvent *genEvt=0);
Expand All @@ -76,7 +78,7 @@ class ParticleReplacerClass : public ParticleReplacerBase
// 0 fullEvent (incl. all other particles)
// 1 taus only (create an event only with the two decaying taus)
unsigned int replacementMode_;
unsigned int generatorMode_;
std::string generatorMode_;
bool noInitialisation_;

// this variable defines the type of decay to simulate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#include "TauAnalysis/MCEmbeddingTools/interface/ParticleReplacerBase.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include<string>

#include<boost/shared_ptr.hpp>

class ParticleReplacerFactory {
public:
static boost::shared_ptr<ParticleReplacerBase> create(int algo, const edm::ParameterSet& iConfig);
static boost::shared_ptr<ParticleReplacerBase> create(const std::string& algo, const edm::ParameterSet& iConfig);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class ParticleReplacerParticleGun: public ParticleReplacerBase {
public:
explicit ParticleReplacerParticleGun(const edm::ParameterSet&);
explicit ParticleReplacerParticleGun(const edm::ParameterSet&, bool);
virtual ~ParticleReplacerParticleGun();

virtual void beginJob();
Expand All @@ -51,6 +51,7 @@ class ParticleReplacerParticleGun: public ParticleReplacerBase {
std::string particleOrigin_;
std::string forceTauPolarization_;
std::string forceTauDecay_;
std::string generatorMode_;
int gunParticle_;
int forceTauPlusHelicity_;
int forceTauMinusHelicity_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
Tauola = cms.PSet(
TauolaPolar,
TauolaDefaultInputCards
)
),
parameterSets = cms.vstring('Tauola')
),
PythiaParameters = cms.PSet(
pythiaUESettingsBlock,
Expand All @@ -47,7 +48,8 @@
cms.PSet(
InputCards = cms.vstring('TAUOLA = 0 0 102 ! TAUOLA ') # 114=l+jet, 102=only muons
)
)
),
parameterSets = cms.vstring('Tauola')
),
PythiaParameters = cms.PSet(
pythiaUESettingsBlock,
Expand Down
55 changes: 5 additions & 50 deletions trunk/TauAnalysis/MCEmbeddingTools/python/example_cfg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FWCore.ParameterSet.Config as cms
process = cms.Process("EXAMPLE")

process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) )

process.load("Configuration.Generator.PythiaUESettings_cfi")

Expand All @@ -11,7 +11,7 @@
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Geometry.CaloEventSetup.CaloTopology_cfi")
process.load("Configuration.StandardSequences.Reconstruction_cff")
process.GlobalTag.globaltag = 'IDEAL_V9::All'
process.GlobalTag.globaltag = 'MC_31X_V5::All'


TauolaDefaultInputCards = cms.PSet(
Expand All @@ -24,54 +24,9 @@
UseTauolaPolarization = cms.bool(True)
)

process.newSource = cms.EDProducer('MCParticleReplacer',
desiredReplacerClass=cms.untracked.int32(1),
# replacementMode =
# 0 - remove Myons from existing HepMCProduct and implant taus (+decay products)
# 1 - build new HepMCProduct only with taus (+decay products)
replacementMode = cms.untracked.int32(1),
#
# generatorMode =
# 0 - use Pythia
# 1 - use Tauola
generatorMode = cms.untracked.int32(1),

printEvent = cms.untracked.bool(True),

#maxEventsToPrint = cms.untracked.int32(5),
#pythiaPylistVerbosity = cms.untracked.int32(1),
filterEfficiency = cms.untracked.double(1.0),
pythiaHepMCVerbosity = cms.untracked.bool(False),
ExternalGenerators = cms.PSet(
Tauola = cms.untracked.PSet(
TauolaPolar,
TauolaDefaultInputCards
),
parameterSets = cms.vstring('Tauola')
),
UseExternalGenerators = cms.untracked.bool(True),
PythiaParameters = cms.PSet(
process.pythiaUESettingsBlock,
ZtautauParameters = cms.vstring('MSEL = 11 ',
'MDME( 174,1) = 0 !Z decay into d dbar',
'MDME( 175,1) = 0 !Z decay into u ubar',
'MDME( 176,1) = 0 !Z decay into s sbar',
'MDME( 177,1) = 0 !Z decay into c cbar',
'MDME( 178,1) = 0 !Z decay into b bbar',
'MDME( 179,1) = 0 !Z decay into t tbar',
'MDME( 182,1) = 0 !Z decay into e- e+',
'MDME( 183,1) = 0 !Z decay into nu_e nu_ebar',
'MDME( 184,1) = 0 !Z decay into mu- mu+',
'MDME( 185,1) = 0 !Z decay into nu_mu nu_mubar',
'MDME( 186,1) = 1 !Z decay into tau- tau+',
'MDME( 187,1) = 0 !Z decay into nu_tau nu_taubar',
'CKIN( 1) = 40. !(D=2. GeV)',
'CKIN( 2) = -1. !(D=-1. GeV)',
'MSTJ(28) = 1 ! no tau decays in pythia, use tauola instead'),
parameterSets = cms.vstring('pythiaUESettings',
'ZtautauParameters')
)
)
process.load("TauAnalysis.MCEmbeddingTools.MCParticleReplacer_cfi")
process.newSource.algorithm = "Ztautau"
process.newSource.verbose = True

process.selectMuons = cms.EDProducer('SelectParticles',
TrackAssociatorParameters = cms.PSet(
Expand Down
23 changes: 16 additions & 7 deletions trunk/TauAnalysis/MCEmbeddingTools/src/MCParticleReplacer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@
// 0 - remove Myons from existing HepMCProduct and implant taus (+decay products)
// 1 - build new HepMCProduct only with taus (+decay products)
MCParticleReplacer::MCParticleReplacer(const edm::ParameterSet& pset):
src_(pset.getParameter<edm::InputTag>("selectedParticles")),
srcHepMC_(pset.getParameter<edm::InputTag>("HepMCSource")),
replacementMode_(pset.getParameter<unsigned int>("replacementMode")),
replacer_(ParticleReplacerFactory::create(pset.getUntrackedParameter<int>("desiredReplacerClass", 1), pset)) {
src_(pset.getParameter<edm::InputTag>("src")),
srcHepMC_(pset.getParameter<edm::InputTag>("hepMcSrc")),
hepMcMode_(stringToHepMcMode(pset.getParameter<std::string>("hepMcMode"))),
replacer_(ParticleReplacerFactory::create(pset.getParameter<std::string>("algorithm"), pset)) {

produces<edm::HepMCProduct>();
}

MCParticleReplacer::~MCParticleReplacer()
{}

MCParticleReplacer::HepMcMode MCParticleReplacer::stringToHepMcMode(const std::string& name) {
if(name == "new")
return kNew;
else if(name == "replace")
return kReplace;
else
throw cms::Exception("Configuration") << "Unsupported hepMcMode " << name << ", should be 'new' or 'replace'" << std::endl;
}

// ------------ method called to produce the data ------------
void
MCParticleReplacer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
Expand All @@ -30,17 +39,17 @@ MCParticleReplacer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
return;

std::auto_ptr<HepMC::GenEvent> evt;
if(replacementMode_ == 0) {
if(hepMcMode_ == kReplace) {
edm::Handle<edm::HepMCProduct> HepMCHandle;
iEvent.getByLabel(srcHepMC_, HepMCHandle);

evt = replacer_->produce(*muons, 0, HepMCHandle->GetEvent());
}
else if(replacementMode_ == 1){
else if(hepMcMode_ == kNew) {
evt = replacer_->produce(*muons);
}
else
throw cms::Exception("Configuration") << "Unsupported replacementMode " << replacementMode_ << ", should be 1 or 0" << std::endl;
throw cms::Exception("LogicError") << "Invalid hepMcMode " << hepMcMode_ << std::endl;


if(evt.get() != 0) {
Expand Down
19 changes: 7 additions & 12 deletions trunk/TauAnalysis/MCEmbeddingTools/src/ParticleReplacerClass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ extern "C" {
}
#endif

ParticleReplacerClass::ParticleReplacerClass(const edm::ParameterSet& pset):
ParticleReplacerClass::ParticleReplacerClass(const edm::ParameterSet& pset, bool verbose):
ParticleReplacerBase(pset),
tauola_(pset)
generatorMode_(pset.getParameter<std::string>("generatorMode")),
tauola_(pset),
printEvent_(verbose)
{
// using namespace reco;
using namespace edm;
Expand Down Expand Up @@ -48,20 +50,13 @@ ParticleReplacerClass::ParticleReplacerClass(const edm::ParameterSet& pset):
}
}

// generatorMode =
// 0 - use Pythia
// 1 - use Tauola
generatorMode_ = pset.getUntrackedParameter<int>("generatorMode",0);

// If one wants to use two instances of this module in one
// configuration file, there might occur some segmentation
// faults due to the second initialisation of Tauola. This
// can be prevented by setting noInitialisation to false.
// Caution: This option is not tested!
noInitialisation_ = pset.getUntrackedParameter<bool>("noInitialisation",false);

printEvent_ = pset.getUntrackedParameter<bool>("printEvent",false);

motherParticleID_ = pset.getUntrackedParameter<int>("motherParticleID",23);

// requires the visible decay products of a tau to have a sum transverse momentum
Expand Down Expand Up @@ -232,7 +227,7 @@ std::auto_ptr<HepMC::GenEvent> ParticleReplacerClass::produce(const reco::MuonCo
reco::Particle::Point production_point = particles.begin()->vertex();
GenVertex * decayvtx = new GenVertex(FourVector(production_point.x(),production_point.y(),production_point.z(),0));

HepMC::GenParticle * mother_particle = new HepMC::GenParticle((FourVector)mother_particle_p4, motherParticleID_, (generatorMode_==0 ? 3 : 2), Flow(), Polarization(0,0));
HepMC::GenParticle * mother_particle = new HepMC::GenParticle((FourVector)mother_particle_p4, motherParticleID_, (generatorMode_=="Pythia" ? 3 : 2), Flow(), Polarization(0,0));

decayvtx->add_particle_in(mother_particle);

Expand All @@ -254,13 +249,13 @@ std::auto_ptr<HepMC::GenEvent> ParticleReplacerClass::produce(const reco::MuonCo
{
nr_of_trials++;

if (generatorMode_==0) // Pythia
if (generatorMode_ == "Pythia") // Pythia
{
LogError("Replacer") << "Pythia is currently not supported!";
retevt=evt;
}

if (generatorMode_==1) // TAUOLA
if (generatorMode_ == "Tauola") // TAUOLA
retevt=tauola_.decay(evt);

if (retevt==0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#include "TauAnalysis/MCEmbeddingTools/interface/ParticleReplacerClass.h"
#include "TauAnalysis/MCEmbeddingTools/interface/ParticleReplacerParticleGun.h"

boost::shared_ptr<ParticleReplacerBase> ParticleReplacerFactory::create(int algo, const edm::ParameterSet& iConfig) {
if(algo == 1)
return boost::shared_ptr<ParticleReplacerBase>(new ParticleReplacerClass(iConfig));
else if(algo == 2)
return boost::shared_ptr<ParticleReplacerBase>(new ParticleReplacerParticleGun(iConfig));
boost::shared_ptr<ParticleReplacerBase> ParticleReplacerFactory::create(const std::string& algo, const edm::ParameterSet& iConfig) {
bool verbose = iConfig.getParameter<bool>("verbose");
if(algo == "ZTauTau")
return boost::shared_ptr<ParticleReplacerBase>(new ParticleReplacerClass(iConfig.getParameter<edm::ParameterSet>("ZTauTau"), verbose));
else if(algo == "ParticleGun")
return boost::shared_ptr<ParticleReplacerBase>(new ParticleReplacerParticleGun(iConfig.getParameter<edm::ParameterSet>("ParticleGun"), verbose));
else
throw cms::Exception("Configuration") << "Unknown particle replacer algorithm " << algo
<< ". Supported algorithms: 1 for ParticleReplacerClass, 2 for ParticleReplacerParticleGun" << std::endl;
<< ". Supported algorithms: 'ZTauTau', 'ParticleGun'." << std::endl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
#include "HepMC/PythiaWrapper.h"
#include "HepMC/IO_HEPEVT.h"

ParticleReplacerParticleGun::ParticleReplacerParticleGun(const edm::ParameterSet& iConfig):
ParticleReplacerParticleGun::ParticleReplacerParticleGun(const edm::ParameterSet& iConfig, bool verbose):
ParticleReplacerBase(iConfig),
tauola_(iConfig.getParameter<edm::ParameterSet>("ExternalDecays").getParameter<edm::ParameterSet>("Tauola")),
pythia_(iConfig),
particleOrigin_(iConfig.getParameter<std::string>("ParticleOrigin")),
forceTauPolarization_(iConfig.getParameter<std::string>("ForceTauPolarization")),
forceTauDecay_(iConfig.getParameter<std::string>("ForceTauDecay")),
gunParticle_(iConfig.getParameter<int>("GunParticle")),
forceTauPlusHelicity_(iConfig.getParameter<int>("ForceTauPlusHelicity")),
forceTauMinusHelicity_(iConfig.getParameter<int>("ForceTauMinusHelicity")),
printout_(iConfig.getUntrackedParameter<bool>("Print", false)) {
particleOrigin_(iConfig.getParameter<std::string>("particleOrigin")),
forceTauPolarization_(iConfig.getParameter<std::string>("forceTauPolarization")),
forceTauDecay_(iConfig.getParameter<std::string>("forceTauDecay")),
generatorMode_(iConfig.getParameter<std::string>("generatorMode")),
gunParticle_(iConfig.getParameter<int>("gunParticle")),
forceTauPlusHelicity_(iConfig.getParameter<int>("forceTauPlusHelicity")),
forceTauMinusHelicity_(iConfig.getParameter<int>("forceTauMinusHelicity")),
printout_(verbose) {

srand(time(NULL)); // Should we use RandomNumberGenerator service?

Expand All @@ -36,6 +37,9 @@ ParticleReplacerParticleGun::ParticleReplacerParticleGun(const edm::ParameterSet
std::memset(pol1_, 0, 4*sizeof(float));
std::memset(pol2_, 0, 4*sizeof(float));

if(generatorMode_ != "Tauola")
throw cms::Exception("Configuration") << "Generator mode other than Tauola is not supported" << std::endl;

throw cms::Exception("UnimplementedFeature") << "ParticleReplacerParticleGun is not usable yet." << std::endl;
}

Expand Down

0 comments on commit 4ba77f8

Please sign in to comment.