CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes | Private Attributes
MixEvtVtxGenerator Class Reference
Inheritance diagram for MixEvtVtxGenerator:
edm::stream::EDProducer<>

Public Member Functions

virtual HepMC::FourVector * getRecVertex (edm::Event &)
 
virtual HepMC::FourVector * getVertex (edm::Event &)
 
 MixEvtVtxGenerator (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~MixEvtVtxGenerator () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Protected Attributes

TMatrixD * boost_
 
HepMC::FourVector * fVertex
 

Private Attributes

edm::EDGetTokenT< CrossingFrame< HepMCProduct > > cfLabel
 
edm::EDGetTokenT< reco::VertexCollectionhiLabel
 
edm::EDGetTokenT< HepMCProductsignalLabel
 
bool useCF_
 
bool useRecVertex
 
std::vector< double > vtxOffset
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 33 of file MixEvtVtxGenerator.cc.

Constructor & Destructor Documentation

◆ MixEvtVtxGenerator()

MixEvtVtxGenerator::MixEvtVtxGenerator ( const edm::ParameterSet pset)
explicit

Definition at line 58 of file MixEvtVtxGenerator.cc.

59  : fVertex(nullptr),
60  boost_(nullptr),
61  useRecVertex(pset.exists("useRecVertex") ? pset.getParameter<bool>("useRecVertex") : false)
62 
63 {
64  produces<edm::HepMCProduct>();
65  vtxOffset.resize(3);
66  if (pset.exists("vtxOffset"))
67  vtxOffset = pset.getParameter<std::vector<double> >("vtxOffset");
68 
69  if (useRecVertex)
70  useCF_ = false;
71  else {
72  useCF_ = pset.getUntrackedParameter<bool>("useCF", false);
73  cfLabel = consumes<CrossingFrame<HepMCProduct> >(pset.getParameter<edm::InputTag>("mixLabel"));
74  }
75  signalLabel = consumes<HepMCProduct>(pset.getParameter<edm::InputTag>("signalLabel"));
76 }

References cfLabel, muonDTDigis_cfi::pset, signalLabel, useCF_, useRecVertex, and vtxOffset.

◆ ~MixEvtVtxGenerator()

MixEvtVtxGenerator::~MixEvtVtxGenerator ( )
override

Definition at line 78 of file MixEvtVtxGenerator.cc.

78  {
79  delete fVertex;
80  if (boost_ != nullptr)
81  delete boost_;
82  // no need since now it's done in HepMCProduct
83  // delete fEvt ;
84 }

References boost_, and fVertex.

Member Function Documentation

◆ getRecVertex()

HepMC::FourVector * MixEvtVtxGenerator::getRecVertex ( edm::Event evt)
virtual

Definition at line 138 of file MixEvtVtxGenerator.cc.

138  {
140  evt.getByToken(hiLabel, input);
141 
142  double aX, aY, aZ;
143 
144  aX = input->begin()->position().x() + vtxOffset[0];
145  aY = input->begin()->position().y() + vtxOffset[1];
146  aZ = input->begin()->position().z() + vtxOffset[2];
147 
148  if (!fVertex)
149  fVertex = new HepMC::FourVector();
150  fVertex->set(10.0 * aX, 10.0 * aY, 10.0 * aZ, 0.0); // HepMC positions in mm (RECO in cm)
151 
152  return fVertex;
153 }

References fVertex, edm::Event::getByToken(), hiLabel, input, and vtxOffset.

Referenced by produce().

◆ getVertex()

HepMC::FourVector * MixEvtVtxGenerator::getVertex ( edm::Event evt)
virtual

Definition at line 86 of file MixEvtVtxGenerator.cc.

86  {
87  HepMC::GenVertex* genvtx = nullptr;
88  const HepMC::GenEvent* inev = nullptr;
89 
90  if (useCF_) {
92  evt.getByToken(cfLabel, cf);
94  if (mix.size() < 2) {
95  throw cms::Exception("MatchVtx") << "Mixing has " << mix.size() << " sub-events, should have been at least 2"
96  << endl;
97  }
98  const HepMCProduct& bkg = mix.getObject(1);
99  if (!(bkg.isVtxGenApplied())) {
100  throw cms::Exception("MatchVtx") << "Input background does not have smeared vertex!" << endl;
101  } else {
102  inev = bkg.GetEvent();
103  }
104  } else {
107  inev = input->GetEvent();
108  }
109 
110  genvtx = inev->signal_process_vertex();
111  if (!genvtx) {
112  HepMC::GenEvent::particle_const_iterator pt = inev->particles_begin();
113  HepMC::GenEvent::particle_const_iterator ptend = inev->particles_end();
114  while (!genvtx || (genvtx->particles_in_size() == 1 && pt != ptend)) {
115  if (pt == ptend)
116  cout << "End reached, No Gen Vertex!" << endl;
117  genvtx = (*pt)->production_vertex();
118  ++pt;
119  }
120  }
121  double aX, aY, aZ, aT;
122 
123  aX = genvtx->position().x();
124  aY = genvtx->position().y();
125  aZ = genvtx->position().z();
126  aT = genvtx->position().t();
127 
128  if (!fVertex) {
129  fVertex = new HepMC::FourVector();
130  }
131  LogInfo("MatchVtx") << " setting vertex "
132  << " aX " << aX << " aY " << aY << " aZ " << aZ << " aT " << aT << endl;
133  fVertex->set(aX, aY, aZ, aT);
134 
135  return fVertex;
136 }

References cfLabel, gather_cfg::cout, Exception, fVertex, edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), input, edm::HepMCProduct::isVtxGenApplied(), GeneratorMix_cff::mix, edm::Handle< T >::product(), DiDispStaMuonMonitor_cfi::pt, signalLabel, and useCF_.

Referenced by produce().

◆ produce()

void MixEvtVtxGenerator::produce ( edm::Event evt,
const edm::EventSetup  
)
override

Definition at line 155 of file MixEvtVtxGenerator.cc.

155  {
156  Handle<HepMCProduct> HepUnsmearedMCEvt;
157 
158  evt.getByToken(signalLabel, HepUnsmearedMCEvt);
159 
160  // generate new vertex & apply the shift
161  //
162  if (HepUnsmearedMCEvt->isVtxGenApplied())
163  throw cms::Exception("MatchVtx")
164  << "Signal HepMCProduct is not compatible for embedding - it's vertex is already smeared." << std::endl;
165  // Copy the HepMC::GenEvent
166  HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
167  std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
168  // generate new vertex & apply the shift
169  //
170  HepMCEvt->applyVtxGen(useRecVertex ? getRecVertex(evt) : getVertex(evt));
171 
172  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
173  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
174 
175  evt.put(std::move(HepMCEvt));
176 
177  return;
178 }

References edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), getRecVertex(), getVertex(), edm::HepMCProduct::isVtxGenApplied(), eostools::move(), edm::Event::put(), signalLabel, and useRecVertex.

Member Data Documentation

◆ boost_

TMatrixD* MixEvtVtxGenerator::boost_
protected

Definition at line 46 of file MixEvtVtxGenerator.cc.

Referenced by ~MixEvtVtxGenerator().

◆ cfLabel

edm::EDGetTokenT<CrossingFrame<HepMCProduct> > MixEvtVtxGenerator::cfLabel
private

Definition at line 51 of file MixEvtVtxGenerator.cc.

Referenced by getVertex(), and MixEvtVtxGenerator().

◆ fVertex

HepMC::FourVector* MixEvtVtxGenerator::fVertex
protected

Definition at line 45 of file MixEvtVtxGenerator.cc.

Referenced by getRecVertex(), getVertex(), and ~MixEvtVtxGenerator().

◆ hiLabel

edm::EDGetTokenT<reco::VertexCollection> MixEvtVtxGenerator::hiLabel
private

Definition at line 49 of file MixEvtVtxGenerator.cc.

Referenced by getRecVertex().

◆ signalLabel

edm::EDGetTokenT<HepMCProduct> MixEvtVtxGenerator::signalLabel
private

Definition at line 50 of file MixEvtVtxGenerator.cc.

Referenced by getVertex(), MixEvtVtxGenerator(), and produce().

◆ useCF_

bool MixEvtVtxGenerator::useCF_
private

Definition at line 55 of file MixEvtVtxGenerator.cc.

Referenced by getVertex(), and MixEvtVtxGenerator().

◆ useRecVertex

bool MixEvtVtxGenerator::useRecVertex
private

Definition at line 53 of file MixEvtVtxGenerator.cc.

Referenced by MixEvtVtxGenerator(), and produce().

◆ vtxOffset

std::vector<double> MixEvtVtxGenerator::vtxOffset
private

Definition at line 54 of file MixEvtVtxGenerator.cc.

Referenced by getRecVertex(), and MixEvtVtxGenerator().

input
static const std::string input
Definition: EdmProvDump.cc:48
edm::Handle::product
T const * product() const
Definition: Handle.h:70
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::LogInfo
Definition: MessageLogger.h:254
MixEvtVtxGenerator::fVertex
HepMC::FourVector * fVertex
Definition: MixEvtVtxGenerator.cc:45
MixEvtVtxGenerator::boost_
TMatrixD * boost_
Definition: MixEvtVtxGenerator.cc:46
edm::Handle< reco::VertexCollection >
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
MixCollection
Definition: MixCollection.h:11
MixEvtVtxGenerator::cfLabel
edm::EDGetTokenT< CrossingFrame< HepMCProduct > > cfLabel
Definition: MixEvtVtxGenerator.cc:51
MixEvtVtxGenerator::getVertex
virtual HepMC::FourVector * getVertex(edm::Event &)
Definition: MixEvtVtxGenerator.cc:86
MixEvtVtxGenerator::useRecVertex
bool useRecVertex
Definition: MixEvtVtxGenerator.cc:53
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
edm::HepMCProduct::isVtxGenApplied
bool isVtxGenApplied() const
Definition: HepMCProduct.h:36
MixEvtVtxGenerator::vtxOffset
std::vector< double > vtxOffset
Definition: MixEvtVtxGenerator.cc:54
MixEvtVtxGenerator::hiLabel
edm::EDGetTokenT< reco::VertexCollection > hiLabel
Definition: MixEvtVtxGenerator.cc:49
eostools.move
def move(src, dest)
Definition: eostools.py:511
MixEvtVtxGenerator::signalLabel
edm::EDGetTokenT< HepMCProduct > signalLabel
Definition: MixEvtVtxGenerator.cc:50
Exception
Definition: hltDiff.cc:246
cms::Exception
Definition: Exception.h:70
edm::HepMCProduct
Definition: HepMCProduct.h:18
GeneratorMix_cff.mix
mix
Definition: GeneratorMix_cff.py:6
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MixEvtVtxGenerator::getRecVertex
virtual HepMC::FourVector * getRecVertex(edm::Event &)
Definition: MixEvtVtxGenerator.cc:138
MixEvtVtxGenerator::useCF_
bool useCF_
Definition: MixEvtVtxGenerator.cc:55