CMS 3D CMS Logo

CTPPSHectorProducer.cc
Go to the documentation of this file.
1 // Framework headers
9 
10 // SimpleConfigurable replacement
12 
13 // HepMC headers
14 #include "HepMC/GenEvent.h"
15 
16 // Hector headers
19 
20 // SimDataFormats headers
23 
24 #include "CLHEP/Random/RandomEngine.h"
25 
26 #include <iostream>
27 #include <memory>
28 #include <string>
29 
30 class TRandom3;
31 
33 
34  // TransportHector
35  m_InTag = parameters.getParameter<std::string>("HepMCProductLabel") ;
36  m_InTagToken = consumes<edm::HepMCProduct>(m_InTag);
37  m_verbosity = parameters.getParameter<bool>("Verbosity");
38  m_CTPPSTransport = parameters.getParameter<bool>("CTPPSTransport");
39 
40  produces<edm::HepMCProduct>();
41  produces<edm::LHCTransportLinkContainer>();
42 
43  hector_ctpps = new CTPPSHector(parameters, m_verbosity,m_CTPPSTransport);
44 
46  if ( ! rng.isAvailable() ) {
47  throw cms::Exception("Configuration")
48  << "LHCTransport (CTPPSHectorProducer) requires the RandomNumberGeneratorService\n"
49  "which is not present in the configuration file. You must add the service\n"
50  "in the configuration file or remove the modules that require it.";
51  }
52 }
53 
55 
56 
58 
59 
61 
63 
64  using namespace edm;
65  using namespace std;
66  HepMC::GenEvent * evt_;
68  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
69  if ( engine->name() != "TRandom3" ) {
70  throw cms::Exception("Configuration")
71  << "The TRandom3 engine type must be used with CTPPSHectorProducer, Random Number Generator Service not correctly configured!";
72  }
73  TRandom3* rootEngine = ( (edm::TRandomAdaptor*) engine )->getRootEngine();
74 
76  Handle<HepMCProduct> HepMCEvt;
77  iEvent.getByToken( m_InTagToken, HepMCEvt ) ;
78 
79  if ( !HepMCEvt.isValid() ){
80  throw cms::Exception("InvalidReference")
81  << "Invalid reference to HepMCProduct\n";
82  }
83 
84  if ( HepMCEvt.provenance()->moduleLabel() == "LHCTransport" ){
85  throw cms::Exception("LogicError")
86  << "HectorTrasported HepMCProduce already exists\n";
87  }
88 
89  evt_ = new HepMC::GenEvent( *HepMCEvt->GetEvent() );
91  if(m_CTPPSTransport) {
93  hector_ctpps->add( evt_ ,es ,engine);
94  hector_ctpps->filterCTPPS(rootEngine);
95  }
96 
97  evt_ = hector_ctpps->addPartToHepMC( evt_ );
98  if (m_verbosity) {
99  evt_->print();
100  }
101 
102  unique_ptr<HepMCProduct> NewProduct(new edm::HepMCProduct()) ;
103  NewProduct->addHepMCData( evt_ ) ;
104 
105  iEvent.put(std::move(NewProduct)) ;
106 
107  unique_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer() );
109  (*NewCorrespondenceMap).swap(thisLink);
110 
111  if ( m_verbosity ) {
112  for ( unsigned int i = 0; i < (*NewCorrespondenceMap).size(); i++)
113  LogDebug("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
114  }
115 
116  iEvent.put(std::move(NewCorrespondenceMap));
117  hector_ctpps->clear();
118 
119 }
#define LogDebug(id)
HepMC::GenEvent * addPartToHepMC(HepMC::GenEvent *event)
Definition: CTPPSHector.cc:345
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::HepMCProduct > m_InTagToken
void clearApertureFlags()
Definition: CTPPSHector.cc:107
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
CTPPSHectorProducer(edm::ParameterSet const &p)
default constructor
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void produce(edm::Event &e, const edm::EventSetup &c) override
int iEvent
Definition: GenABIO.cc:230
CTPPSHector * hector_ctpps
void add(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine)
Definition: CTPPSHector.cc:123
bool isAvailable() const
Definition: Service.h:46
bool isValid() const
Definition: HandleBase.h:74
void clear()
Definition: CTPPSHector.cc:111
int eventsAnalysed
just to count events that have been analysed
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
void endRun(const edm::Run &r, const edm::EventSetup &c) override
std::string const & moduleLabel() const
Definition: Provenance.h:50
~CTPPSHectorProducer() override
default destructor
HLT enums.
StreamID streamID() const
Definition: Event.h:86
std::vector< LHCTransportLink > LHCTransportLinkContainer
void filterCTPPS(TRandom3 *)
Definition: CTPPSHector.cc:197
std::vector< LHCTransportLink > & getCorrespondenceMap()
Definition: CTPPSHector.h:76
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:43
Provenance const * provenance() const
Definition: HandleBase.h:83