CMS 3D CMS Logo

PPSSimTrackProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimPPS/PPSSimTrackProducer
4 // Class: PPSSimTrackProducer
5 //
13 //
14 // Original Author: Luiz Martins Mundim Filho
15 // Created: Sun, 03 Dec 2017 00:25:54 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
32 
35 
38 
42 #include "TRandom3.h"
44 
45 //
46 // class declaration
47 //
48 
50 public:
51  explicit PPSSimTrackProducer(const edm::ParameterSet&);
52  ~PPSSimTrackProducer() override;
53 
54  //static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void beginStream(edm::StreamID) override;
58  void produce(edm::Event&, const edm::EventSetup&) override;
59  void endStream() override;
60 
61  // ----------member data ---------------------------
66 
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83  //now do what ever other initialization is needed
84  // TransportHector
85  theTransporter = new ProtonTransport(iConfig);
86 
87  m_InTag = iConfig.getParameter<edm::InputTag>("HepMCProductLabel");
88  m_InTagToken = consumes<edm::HepMCProduct>(m_InTag);
89 
90  m_verbosity = iConfig.getParameter<bool>("Verbosity");
91  m_eventsAnalysed = 0;
92  //m_transportMethod = iConfig.getParameter<std::string>("TransportMethod");
93 
94  produces<edm::HepMCProduct>();
95  produces<edm::LHCTransportLinkContainer>();
96 
98  if (!rng.isAvailable()) {
99  throw cms::Exception("Configuration")
100  << "LHCTransport (ProtonTransport) requires the RandomNumberGeneratorService\n"
101  "which is not present in the configuration file. You must add the service\n"
102  "in the configuration file or remove the modules that require it.";
103  }
104 }
105 
107  // do anything here that needs to be done at destruction time
108  // (e.g. close files, deallocate resources etc.)
109  if (theTransporter) {
110  delete theTransporter;
111  theTransporter = nullptr;
112  }
113 }
114 
115 //
116 // member functions
117 //
118 
119 // ------------ method called to produce the data ------------
121  using namespace edm;
122  using namespace std;
123  HepMC::GenEvent* evt;
125  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
126  if (engine->name() != "TRandom3") {
127  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with ProtonTransport, Random "
128  "Number Generator Service not correctly configured!";
129  }
130 
132  Handle<HepMCProduct> HepMCEvt;
133  iEvent.getByToken(m_InTagToken, HepMCEvt);
134 
135  if (!HepMCEvt.isValid()) {
136  throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
137  }
138 
139  if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
140  throw cms::Exception("LogicError") << "LHCTrasport HepMCProduce already exists\n";
141  }
142  edm::LogVerbatim("ProtonTransportEventProcessing") << "produce begin for event " << m_eventsAnalysed;
143 
144  evt = new HepMC::GenEvent(HepMCEvt->GetEvent()->signal_process_id(), HepMCEvt->GetEvent()->event_number());
145 
146  theTransporter->process(HepMCEvt->GetEvent(), iSetup, engine);
147  theTransporter->addPartToHepMC(HepMCEvt->GetEvent(), evt);
148 
149  if (m_verbosity)
150  evt->print();
151 
152  unique_ptr<HepMCProduct> newProduct(new edm::HepMCProduct());
153  newProduct->addHepMCData(evt);
154 
155  iEvent.put(std::move(newProduct));
156 
157  unique_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
159  (*NewCorrespondenceMap).swap(thisLink);
160 
161  if (m_verbosity) {
162  for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); ++i)
163  LogDebug("ProtonTransportEventProcessing")
164  << "ProtonTransport correspondence table: " << (*NewCorrespondenceMap)[i];
165  }
166 
167  iEvent.put(std::move(NewCorrespondenceMap));
168  // There is no need to delete the pointer to the event, since it is deleted in HepMCProduct,
169  // in fact, it MUST NOT be delete here, as a protection is missing in above package
170  edm::LogVerbatim("ProtonTransportEventProcessing") << "produce end ";
171 }
172 // The methods below are pure virtual, so it needs to be implemented even if not used
173 //
174 // ------------ method called once each stream before processing any runs, lumis or events ------------
176 
177 // ------------ method called once each stream after processing all runs, lumis and events ------------
179 
180 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
181 /* to be done */
182 //define this as a plug-in
edm::Provenance::moduleLabel
std::string const & moduleLabel() const
Definition: Provenance.h:55
PPSSimTrackProducer::m_transportMethod
std::string m_transportMethod
Definition: PPSSimTrackProducer.cc:67
edm::StreamID
Definition: StreamID.h:30
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
mps_fire.i
i
Definition: mps_fire.py:428
edm::LHCTransportLinkContainer
std::vector< LHCTransportLink > LHCTransportLinkContainer
Definition: LHCTransportLinkContainer.h:8
MessageLogger.h
ESHandle.h
PPSSimTrackProducer::m_verbosity
bool m_verbosity
Definition: PPSSimTrackProducer.cc:62
edm::EDGetTokenT< edm::HepMCProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
ProtonTransport.h
PPSSimTrackProducer::m_InTagToken
edm::EDGetTokenT< edm::HepMCProduct > m_InTagToken
Definition: PPSSimTrackProducer.cc:65
EDProducer.h
PPSSimTrackProducer::m_InTag
edm::InputTag m_InTag
Definition: PPSSimTrackProducer.cc:64
PPSSimTrackProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PPSSimTrackProducer.cc:120
PPSSimTrackProducer::PPSSimTrackProducer
PPSSimTrackProducer(const edm::ParameterSet &)
Definition: PPSSimTrackProducer.cc:82
edm::Handle
Definition: AssociativeIterator.h:50
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
PPSSimTrackProducer
Definition: PPSSimTrackProducer.cc:49
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PPSSimTrackProducer::endStream
void endStream() override
Definition: PPSSimTrackProducer.cc:178
TRandomAdaptor.h
Service.h
edm::HandleBase::provenance
Provenance const * provenance() const
Definition: HandleBase.h:74
EDGetToken.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ProtonTransport
Definition: ProtonTransport.h:12
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ProtonTransport::getCorrespondenceMap
std::vector< LHCTransportLink > & getCorrespondenceMap()
Definition: ProtonTransport.h:20
edm::Service< edm::RandomNumberGenerator >
iEvent
int iEvent
Definition: GenABIO.cc:224
PPSSimTrackProducer::theTransporter
ProtonTransport * theTransporter
Definition: PPSSimTrackProducer.cc:63
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
PPSSimTrackProducer::m_eventsAnalysed
int m_eventsAnalysed
just to count events that have been analysed
Definition: PPSSimTrackProducer.cc:68
InputTag.h
ProtonTransport::process
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine)
Definition: ProtonTransport.h:21
ProtonTransport::addPartToHepMC
void addPartToHepMC(const HepMC::GenEvent *iev, HepMC::GenEvent *ev)
Definition: ProtonTransport.h:24
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PPSSimTrackProducer::beginStream
void beginStream(edm::StreamID) override
Definition: PPSSimTrackProducer.cc:175
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
PPSSimTrackProducer::~PPSSimTrackProducer
~PPSSimTrackProducer() override
Definition: PPSSimTrackProducer.cc:106
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::HepMCProduct
Definition: HepMCProduct.h:21
ParameterSet.h
HepMCProduct.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15