CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
31 
34 
37 
41 #include "CLHEP/Random/RandomEngine.h"
42 #include "TRandom3.h"
43 
44 //
45 // class declaration
46 //
47 
49 public:
50  explicit PPSSimTrackProducer(const edm::ParameterSet&);
51  ~PPSSimTrackProducer() override = default;
52 
53  //static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 private:
56  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58  // ----------member data ---------------------------
63 
66 };
67 
68 //
69 // constants, enums and typedefs
70 //
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80  : theTransporter(iConfig, consumesCollector()) {
81  m_InTag = iConfig.getParameter<edm::InputTag>("HepMCProductLabel");
82  m_InTagToken = consumes<edm::HepMCProduct>(m_InTag);
83 
84  m_verbosity = iConfig.getParameter<bool>("Verbosity");
85  m_eventsAnalysed = 0;
86  //m_transportMethod = iConfig.getParameter<std::string>("TransportMethod");
87 
88  produces<edm::HepMCProduct>();
89  produces<edm::LHCTransportLinkContainer>();
90 
92  if (!rng.isAvailable()) {
93  throw cms::Exception("Configuration")
94  << "LHCTransport (ProtonTransport) requires the RandomNumberGeneratorService\n"
95  "which is not present in the configuration file. You must add the service\n"
96  "in the configuration file or remove the modules that require it.";
97  }
98 }
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called to produce the data ------------
106  using namespace edm;
107  using namespace std;
108  HepMC::GenEvent* evt;
110  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
111  if (engine->name() != "TRandom3") {
112  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with ProtonTransport, Random "
113  "Number Generator Service not correctly configured!";
114  }
115 
117  Handle<HepMCProduct> HepMCEvt;
118  iEvent.getByToken(m_InTagToken, HepMCEvt);
119 
120  if (!HepMCEvt.isValid()) {
121  throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
122  }
123 
124  if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
125  throw cms::Exception("LogicError") << "LHCTrasport HepMCProduce already exists\n";
126  }
127  edm::LogVerbatim("ProtonTransportEventProcessing") << "produce begin for event " << m_eventsAnalysed;
128 
129  evt = new HepMC::GenEvent(HepMCEvt->GetEvent()->signal_process_id(), HepMCEvt->GetEvent()->event_number());
130 
131  theTransporter.process(HepMCEvt->GetEvent(), iSetup, engine);
132  theTransporter.addPartToHepMC(HepMCEvt->GetEvent(), evt);
133 
134  if (m_verbosity)
135  evt->print();
136 
137  unique_ptr<HepMCProduct> newProduct(new edm::HepMCProduct());
138  newProduct->addHepMCData(evt);
139 
140  iEvent.put(std::move(newProduct));
141 
142  unique_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
144  (*NewCorrespondenceMap).swap(thisLink);
145 
146  if (m_verbosity) {
147  for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); ++i)
148  LogDebug("ProtonTransportEventProcessing")
149  << "ProtonTransport correspondence table: " << (*NewCorrespondenceMap)[i];
150  }
151 
152  iEvent.put(std::move(NewCorrespondenceMap));
153  // There is no need to delete the pointer to the event, since it is deleted in HepMCProduct,
154  // in fact, it MUST NOT be delete here, as a protection is missing in above package
155  edm::LogVerbatim("ProtonTransportEventProcessing") << "produce end ";
156 }
157 
158 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
159 /* to be done */
160 //define this as a plug-in
Log< level::Info, true > LogVerbatim
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void addPartToHepMC(const HepMC::GenEvent *iev, HepMC::GenEvent *ev)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~PPSSimTrackProducer() override=default
ProtonTransport theTransporter
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void produce(edm::Event &, const edm::EventSetup &) override
int m_eventsAnalysed
just to count events that have been analysed
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::HepMCProduct > m_InTagToken
std::vector< LHCTransportLink > & getCorrespondenceMap()
def move
Definition: eostools.py:511
PPSSimTrackProducer(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
StreamID streamID() const
Definition: Event.h:98
std::vector< LHCTransportLink > LHCTransportLinkContainer
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine)
#define LogDebug(id)