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
33 
36 
40 #include "TRandom3.h"
42 
43 //
44 // class declaration
45 //
46 
48 public:
49  explicit PPSSimTrackProducer(const edm::ParameterSet&);
50  ~PPSSimTrackProducer() override;
51 
52  //static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void beginStream(edm::StreamID) override;
56  void produce(edm::Event&, const edm::EventSetup&) override;
57  void endStream() override;
58 
59  // ----------member data ---------------------------
64 
67 };
68 
69 //
70 // constants, enums and typedefs
71 //
72 
73 //
74 // static data member definitions
75 //
76 
77 //
78 // constructors and destructor
79 //
81  //now do what ever other initialization is needed
82  // TransportHector
83  theTransporter = new ProtonTransport(iConfig);
84 
85  m_InTag = iConfig.getParameter<edm::InputTag>("HepMCProductLabel");
86  m_InTagToken = consumes<edm::HepMCProduct>(m_InTag);
87 
88  m_verbosity = iConfig.getParameter<bool>("Verbosity");
89  //m_transportMethod = iConfig.getParameter<std::string>("TransportMethod");
90 
91  produces<edm::HepMCProduct>();
92  produces<edm::LHCTransportLinkContainer>();
93 
95  if (!rng.isAvailable()) {
96  throw cms::Exception("Configuration")
97  << "LHCTransport (ProtonTransport) requires the RandomNumberGeneratorService\n"
98  "which is not present in the configuration file. You must add the service\n"
99  "in the configuration file or remove the modules that require it.";
100  }
101 }
102 
104  // do anything here that needs to be done at destruction time
105  // (e.g. close files, deallocate resources etc.)
106  if (theTransporter) {
107  delete theTransporter;
108  theTransporter = nullptr;
109  }
110 }
111 
112 //
113 // member functions
114 //
115 
116 // ------------ method called to produce the data ------------
118  using namespace edm;
119  using namespace std;
120  HepMC::GenEvent* evt;
122  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
123  if (engine->name() != "TRandom3") {
124  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with ProtonTransport, Random "
125  "Number Generator Service not correctly configured!";
126  }
127 
129  Handle<HepMCProduct> HepMCEvt;
130  iEvent.getByToken(m_InTagToken, HepMCEvt);
131 
132  if (!HepMCEvt.isValid()) {
133  throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
134  }
135 
136  if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
137  throw cms::Exception("LogicError") << "LHCTrasport HepMCProduce already exists\n";
138  }
139 
140  evt = new HepMC::GenEvent(*HepMCEvt->GetEvent());
141 
142  //theTransporter->clear();
143  theTransporter->process(evt, iSetup, engine);
144 
145  if (m_verbosity)
146  evt->print();
147 
148  unique_ptr<HepMCProduct> newProduct(new edm::HepMCProduct());
149  newProduct->addHepMCData(evt);
150 
151  iEvent.put(std::move(newProduct));
152 
153  unique_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
155  (*NewCorrespondenceMap).swap(thisLink);
156 
157  if (m_verbosity) {
158  for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); i++)
159  LogDebug("ProtonTransportEventProcessing")
160  << "ProtonTransport correspondence table: " << (*NewCorrespondenceMap)[i];
161  }
162 
163  iEvent.put(std::move(NewCorrespondenceMap));
164  // There is no need to delete the pointer to the event, since it is deleted in HepMCProduct,
165  // in fact, it MUST NOT be delete here, as a protection is missing in above package
166 }
167 // The methods below are pure virtual, so it needs to be implemented even if not used
168 //
169 // ------------ method called once each stream before processing any runs, lumis or events ------------
171 
172 // ------------ method called once each stream after processing all runs, lumis and events ------------
174 
175 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
176 /*
177 void PPSSimTrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
178  //The following says we do not know what parameters are allowed so do no validation
179  // Please change this to state exactly what you do use, even if it is no parameters
180  edm::ParameterSetDescription desc;
181  desc.setUnknown();
182  descriptions.addDefault(desc);
183 }
184 */
185 //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:65
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:355
edm::LHCTransportLinkContainer
std::vector< LHCTransportLink > LHCTransportLinkContainer
Definition: LHCTransportLinkContainer.h:8
ESHandle.h
PPSSimTrackProducer::m_verbosity
bool m_verbosity
Definition: PPSSimTrackProducer.cc:60
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:63
EDProducer.h
PPSSimTrackProducer::m_InTag
edm::InputTag m_InTag
Definition: PPSSimTrackProducer.cc:62
PPSSimTrackProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PPSSimTrackProducer.cc:117
PPSSimTrackProducer::PPSSimTrackProducer
PPSSimTrackProducer(const edm::ParameterSet &)
Definition: PPSSimTrackProducer.cc:80
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:47
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PPSSimTrackProducer::endStream
void endStream() override
Definition: PPSSimTrackProducer.cc:173
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:670
edm::ParameterSet
Definition: ParameterSet.h:36
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:61
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
PPSSimTrackProducer::m_eventsAnalysed
int m_eventsAnalysed
just to count events that have been analysed
Definition: PPSSimTrackProducer.cc:66
InputTag.h
ProtonTransport::process
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine)
Definition: ProtonTransport.h:21
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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:170
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
PPSSimTrackProducer::~PPSSimTrackProducer
~PPSSimTrackProducer() override
Definition: PPSSimTrackProducer.cc:103
edm::HepMCProduct
Definition: HepMCProduct.h:18
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