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<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

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
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

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
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 35 of file MixEvtVtxGenerator.cc.

Constructor & Destructor Documentation

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

Definition at line 65 of file MixEvtVtxGenerator.cc.

References cfLabel, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), signalLabel, useCF_, useRecVertex, and vtxOffset.

66  : fVertex(nullptr), boost_(nullptr),
67  useRecVertex(pset.exists("useRecVertex")?pset.getParameter<bool>("useRecVertex"):false)
68 
69 {
70  produces<edm::HepMCProduct>();
71  vtxOffset.resize(3);
72  if(pset.exists("vtxOffset")) vtxOffset=pset.getParameter< std::vector<double> >("vtxOffset");
73 
74  if(useRecVertex) useCF_ = false;
75  else{
76  useCF_ = pset.getUntrackedParameter<bool>("useCF",false);
77  cfLabel = consumes<CrossingFrame<HepMCProduct> >(pset.getParameter<edm::InputTag>("mixLabel"));
78  }
79  signalLabel = consumes<HepMCProduct>(pset.getParameter<edm::InputTag>("signalLabel"));
80 
81 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > vtxOffset
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< CrossingFrame< HepMCProduct > > cfLabel
edm::EDGetTokenT< HepMCProduct > signalLabel
HepMC::FourVector * fVertex
MixEvtVtxGenerator::~MixEvtVtxGenerator ( )
override

Definition at line 83 of file MixEvtVtxGenerator.cc.

References boost_, and fVertex.

84 {
85  delete fVertex ;
86  if (boost_ != nullptr ) delete boost_;
87  // no need since now it's done in HepMCProduct
88  // delete fEvt ;
89 }
HepMC::FourVector * fVertex

Member Function Documentation

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

Definition at line 146 of file MixEvtVtxGenerator.cc.

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

Referenced by produce().

146  {
147 
149  evt.getByToken(hiLabel,input);
150 
151  double aX,aY,aZ;
152 
153  aX = input->begin()->position().x() + vtxOffset[0];
154  aY = input->begin()->position().y() + vtxOffset[1];
155  aZ = input->begin()->position().z() + vtxOffset[2];
156 
157  if(!fVertex) fVertex = new HepMC::FourVector();
158  fVertex->set(10.0*aX,10.0*aY,10.0*aZ,0.0); // HepMC positions in mm (RECO in cm)
159 
160  return fVertex;
161 
162 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
std::vector< double > vtxOffset
static std::string const input
Definition: EdmProvDump.cc:44
edm::EDGetTokenT< reco::VertexCollection > hiLabel
HepMC::FourVector * fVertex
HepMC::FourVector * MixEvtVtxGenerator::getVertex ( edm::Event evt)
virtual

Definition at line 91 of file MixEvtVtxGenerator.cc.

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

Referenced by produce().

91  {
92 
93  HepMC::GenVertex* genvtx = nullptr;
94  const HepMC::GenEvent* inev = nullptr;
95 
96  if(useCF_){
98  evt.getByToken(cfLabel,cf);
100  if(mix.size() < 2){
101  throw cms::Exception("MatchVtx")
102  <<"Mixing has "<<mix.size()<<" sub-events, should have been at least 2"
103  <<endl;
104  }
105  const HepMCProduct& bkg = mix.getObject(1);
106  if(!(bkg.isVtxGenApplied())){
107  throw cms::Exception("MatchVtx")<<"Input background does not have smeared vertex!"<<endl;
108  }else{
109  inev = bkg.GetEvent();
110  }
111  }else{
113  evt.getByToken(signalLabel,input);
114  inev = input->GetEvent();
115  }
116 
117  genvtx = inev->signal_process_vertex();
118  if(!genvtx){
119  HepMC::GenEvent::particle_const_iterator pt=inev->particles_begin();
120  HepMC::GenEvent::particle_const_iterator ptend=inev->particles_end();
121  while(!genvtx || ( genvtx->particles_in_size() == 1 && pt != ptend ) ){
122  if(pt == ptend) cout<<"End reached, No Gen Vertex!"<<endl;
123  genvtx = (*pt)->production_vertex();
124  ++pt;
125  }
126  }
127  double aX,aY,aZ,aT;
128 
129  aX = genvtx->position().x();
130  aY = genvtx->position().y();
131  aZ = genvtx->position().z();
132  aT = genvtx->position().t();
133 
134  if(!fVertex){
135  fVertex = new HepMC::FourVector();
136  }
137  LogInfo("MatchVtx")<<" setting vertex "<<" aX "<<aX<<" aY "<<aY<<" aZ "<<aZ<<" aT "<<aT<<endl;
138  fVertex->set(aX,aY,aZ,aT);
139 
140 
141  return fVertex;
142 
143 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
static std::string const input
Definition: EdmProvDump.cc:44
edm::EDGetTokenT< CrossingFrame< HepMCProduct > > cfLabel
edm::EDGetTokenT< HepMCProduct > signalLabel
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
T const * product() const
Definition: Handle.h:81
HepMC::FourVector * fVertex
bool isVtxGenApplied() const
Definition: HepMCProduct.h:40
void MixEvtVtxGenerator::produce ( edm::Event evt,
const edm::EventSetup  
)
override

Definition at line 164 of file MixEvtVtxGenerator.cc.

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

165 {
166  Handle<HepMCProduct> HepUnsmearedMCEvt ;
167 
168  evt.getByToken( signalLabel, HepUnsmearedMCEvt ) ;
169 
170  // generate new vertex & apply the shift
171  //
172  if(HepUnsmearedMCEvt->isVtxGenApplied()) throw cms::Exception("MatchVtx")
173  <<"Signal HepMCProduct is not compatible for embedding - it's vertex is already smeared."
174  <<std::endl;
175  // Copy the HepMC::GenEvent
176  HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
177  std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
178  // generate new vertex & apply the shift
179  //
180  HepMCEvt->applyVtxGen( useRecVertex ? getRecVertex(evt) : getVertex(evt) ) ;
181 
182  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
183  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
184 
185  evt.put(std::move(HepMCEvt)) ;
186 
187  return ;
188 
189 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
virtual HepMC::FourVector * getRecVertex(edm::Event &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
virtual HepMC::FourVector * getVertex(edm::Event &)
edm::EDGetTokenT< HepMCProduct > signalLabel
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
bool isVtxGenApplied() const
Definition: HepMCProduct.h:40
return(e1-e2)*(e1-e2)+dp *dp
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

TMatrixD* MixEvtVtxGenerator::boost_
protected

Definition at line 51 of file MixEvtVtxGenerator.cc.

Referenced by ~MixEvtVtxGenerator().

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

Definition at line 57 of file MixEvtVtxGenerator.cc.

Referenced by getVertex(), and MixEvtVtxGenerator().

HepMC::FourVector* MixEvtVtxGenerator::fVertex
protected

Definition at line 50 of file MixEvtVtxGenerator.cc.

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

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

Definition at line 55 of file MixEvtVtxGenerator.cc.

Referenced by getRecVertex().

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

Definition at line 56 of file MixEvtVtxGenerator.cc.

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

bool MixEvtVtxGenerator::useCF_
private

Definition at line 61 of file MixEvtVtxGenerator.cc.

Referenced by getVertex(), and MixEvtVtxGenerator().

bool MixEvtVtxGenerator::useRecVertex
private

Definition at line 59 of file MixEvtVtxGenerator.cc.

Referenced by MixEvtVtxGenerator(), and produce().

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

Definition at line 60 of file MixEvtVtxGenerator.cc.

Referenced by getRecVertex(), and MixEvtVtxGenerator().