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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

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<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::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.

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

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 }
std::vector< double > vtxOffset
edm::EDGetTokenT< CrossingFrame< HepMCProduct > > cfLabel
edm::EDGetTokenT< HepMCProduct > signalLabel
HepMC::FourVector * fVertex

◆ ~MixEvtVtxGenerator()

MixEvtVtxGenerator::~MixEvtVtxGenerator ( )
override

Definition at line 78 of file MixEvtVtxGenerator.cc.

References boost_, and fVertex.

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 }
HepMC::FourVector * fVertex

Member Function Documentation

◆ getRecVertex()

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

Definition at line 138 of file MixEvtVtxGenerator.cc.

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

Referenced by produce().

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 }
std::vector< double > vtxOffset
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
static std::string const input
Definition: EdmProvDump.cc:50
edm::EDGetTokenT< reco::VertexCollection > hiLabel
HepMC::FourVector * fVertex

◆ getVertex()

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

Definition at line 86 of file MixEvtVtxGenerator.cc.

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().

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 }
bool isVtxGenApplied() const
Definition: HepMCProduct.h:39
T const * product() const
Definition: Handle.h:70
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
static std::string const input
Definition: EdmProvDump.cc:50
edm::EDGetTokenT< CrossingFrame< HepMCProduct > > cfLabel
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
Log< level::Info, false > LogInfo
edm::EDGetTokenT< HepMCProduct > signalLabel
HepMC::FourVector * fVertex

◆ produce()

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

Definition at line 155 of file MixEvtVtxGenerator.cc.

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

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 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
virtual HepMC::FourVector * getRecVertex(edm::Event &)
bool isVtxGenApplied() const
Definition: HepMCProduct.h:39
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
virtual HepMC::FourVector * getVertex(edm::Event &)
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
edm::EDGetTokenT< HepMCProduct > signalLabel
def move(src, dest)
Definition: eostools.py:511

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().