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 
39 #include "TRandom3.h"
41 //
42 // class declaration
43 //
44 
46 public:
47  explicit PPSSimTrackProducer(const edm::ParameterSet&);
48  ~PPSSimTrackProducer() override;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  void beginStream(edm::StreamID) override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55  void endStream() override;
56 
57  // ----------member data ---------------------------
62 
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructors and destructor
77 //
79  //now do what ever other initialization is needed
80  // TransportHector
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_transportMethod = iConfig.getParameter<std::string>("TransportMethod");
86 
87  produces<edm::HepMCProduct>();
88  produces<edm::LHCTransportLinkContainer>();
89 
90  theTransporter = nullptr;
91 
92  if (m_transportMethod == "Totem") {
93  theTransporter = new TotemTransport(iConfig, m_verbosity);
94  } else if (m_transportMethod == "Hector") {
95  theTransporter = new HectorTransport(iConfig, m_verbosity);
96  } else {
97  throw cms::Exception("Configuration")
98  << "LHCTransport (ProtonTransport) requires a Method (Hector or Totem) \n"
99  "which is not present in the configuration file. You should add one of the method\n"
100  "above in the configuration file or remove the module that requires it.";
101  }
102 
104  if (!rng.isAvailable()) {
105  throw cms::Exception("Configuration")
106  << "LHCTransport (ProtonTransport) requires the RandomNumberGeneratorService\n"
107  "which is not present in the configuration file. You must add the service\n"
108  "in the configuration file or remove the modules that require it.";
109  }
110 }
111 
113  // do anything here that needs to be done at destruction time
114  // (e.g. close files, deallocate resources etc.)
115  if (theTransporter) {
116  delete theTransporter;
117  theTransporter = nullptr;
118  }
119 }
120 
121 //
122 // member functions
123 //
124 
125 // ------------ method called to produce the data ------------
127  using namespace edm;
128  using namespace std;
129  HepMC::GenEvent* evt;
131  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
132  if (engine->name() != "TRandom3") {
133  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with ProtonTransport, Random "
134  "Number Generator Service not correctly configured!";
135  }
136 
138  Handle<HepMCProduct> HepMCEvt;
139  iEvent.getByToken(m_InTagToken, HepMCEvt);
140 
141  if (!HepMCEvt.isValid()) {
142  throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
143  }
144 
145  if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
146  throw cms::Exception("LogicError") << "HectorTrasported HepMCProduce already exists\n";
147  }
148 
149  evt = new HepMC::GenEvent(*HepMCEvt->GetEvent());
150 
152  theTransporter->process(evt, iSetup, engine);
153 
154  if (m_verbosity)
155  evt->print();
156 
157  unique_ptr<HepMCProduct> newProduct(new edm::HepMCProduct());
158  newProduct->addHepMCData(evt);
159 
160  iEvent.put(std::move(newProduct));
161 
162  unique_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
164  (*NewCorrespondenceMap).swap(thisLink);
165 
166  if (m_verbosity) {
167  for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); i++)
168  LogDebug("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
169  }
170 
171  iEvent.put(std::move(NewCorrespondenceMap));
172  // There is no need to delete the pointer to the event, since it is deleted in HepMCProduct,
173  // in fact, it MUST NOT be delete here, as a protection is missing in above package
174 }
175 // The methods below are pure virtual, so it needs to be implemented even if not used
176 //
177 // ------------ method called once each stream before processing any runs, lumis or events ------------
179 
180 // ------------ method called once each stream after processing all runs, lumis and events ------------
182 
183 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
185  //The following says we do not know what parameters are allowed so do no validation
186  // Please change this to state exactly what you do use, even if it is no parameters
188  desc.setUnknown();
189  descriptions.addDefault(desc);
190 }
191 
192 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
void beginStream(edm::StreamID) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
ProtonTransport * theTransporter
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::HepMCProduct > m_InTagToken
std::vector< LHCTransportLink > & getCorrespondenceMap()
bool isAvailable() const
Definition: Service.h:40
PPSSimTrackProducer(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:74
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
std::string const & moduleLabel() const
Definition: Provenance.h:53
HLT enums.
StreamID streamID() const
Definition: Event.h:95
std::vector< LHCTransportLink > LHCTransportLinkContainer
virtual void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine)=0
def move(src, dest)
Definition: eostools.py:511
Provenance const * provenance() const
Definition: HandleBase.h:83