CMS 3D CMS Logo

HectorProducer.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  m_HepMC(consumes<edm::HepMCProduct>(p.getParameter<std::string>("HepMCProductLabel")))
34 {
35  m_verbosity = p.getParameter<bool>("Verbosity");
36  m_FP420Transport = p.getParameter<bool>("FP420Transport");
37  m_ZDCTransport = p.getParameter<bool>("ZDCTransport");
38  m_evtAnalysed = 0;
39 
40  produces<edm::HepMCProduct>();
41  produces<edm::LHCTransportLinkContainer>();
42 
43  m_Hector = new Hector(p, m_verbosity, m_FP420Transport, m_ZDCTransport);
44 
46  if ( ! rng.isAvailable() ) {
47  throw cms::Exception("Configuration")
48  << "LHCTransport (HectorProducer) 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  edm::LogInfo("SimTransportHectorProducer") << "Hector is created";
53 }
54 
56 
58 
60 
62 
64  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
65  if ( engine->name() != "TRandom3" ) {
66  throw cms::Exception("Configuration")
67  << "The TRandom3 engine type must be used with HectorProducer, "
68  << "Random Number Generator Service not correctly configured!";
69  }
70  TRandom3* rootEngine = ( (edm::TRandomAdaptor*) engine )->getRootEngine();
71 
72  ++m_evtAnalysed;
73 
74  edm::LogInfo("SimTransportHectorProducer") << "produce evt " << m_evtAnalysed;
75 
77  iEvent.getByToken(m_HepMC, HepMCEvt);
78 
79  if ( !HepMCEvt.isValid() )
80  {
81  throw cms::Exception("InvalidReference")
82  << "Invalid reference to HepMCProduct\n";
83  }
84 
85  if ( HepMCEvt.provenance()->moduleLabel() == "LHCTransport" )
86  {
87  throw cms::Exception("LogicError")
88  << "HectorTrasported HepMCProduce already exists\n";
89  }
90 
91  evt_ = new HepMC::GenEvent( *HepMCEvt->GetEvent() );
93  if(m_FP420Transport) {
94  m_Hector->clear();
95  m_Hector->add( evt_ ,es);
96  m_Hector->filterFP420(rootEngine);
97  }
98  if(m_ZDCTransport) {
99  m_Hector->clear();
100  m_Hector->add( evt_ ,es);
101  m_Hector->filterZDC(rootEngine);
102 
103  m_Hector->clear();
104  m_Hector->add( evt_ ,es);
105  m_Hector->filterD1(rootEngine);
106  }
108  if (m_verbosity) {
109  evt_->print();
110  }
111 
112  edm::LogInfo("SimTransportHectorProducer") << "new HepMC product ";
113 
114  unique_ptr<edm::HepMCProduct> NewProduct(new edm::HepMCProduct());
115  NewProduct->addHepMCData( evt_ ) ;
116 
117  iEvent.put(std::move(NewProduct));
118 
119  edm::LogInfo("SimTransportHectorProducer") << "new LHCTransportLinkContainer ";
120  unique_ptr<edm::LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
122  (*NewCorrespondenceMap).swap(thisLink);
123 
124  if ( m_verbosity ) {
125  for ( unsigned int i = 0; i < (*NewCorrespondenceMap).size(); i++)
126  LogDebug("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
127  }
128 
129  iEvent.put(std::move(NewCorrespondenceMap));
130  edm::LogInfo("SimTransportHectorProducer") << "produce end ";
131 
132 }
133 
#define LogDebug(id)
T getParameter(std::string const &) const
int m_evtAnalysed
just to count events that have been analysed
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual void beginRun(const edm::Run &r, const edm::EventSetup &c) override
edm::EDGetTokenT< edm::HepMCProduct > m_HepMC
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
HectorProducer(edm::ParameterSet const &p)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void clear()
Definition: Hector.cc:142
virtual void endRun(const edm::Run &r, const edm::EventSetup &c) override
int iEvent
Definition: GenABIO.cc:230
void filterD1(TRandom3 *)
Definition: Hector.cc:386
bool isAvailable() const
Definition: Service.h:46
void filterFP420(TRandom3 *)
Definition: Hector.cc:231
bool isValid() const
Definition: HandleBase.h:74
void filterZDC(TRandom3 *)
Definition: Hector.cc:315
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
Hector * m_Hector
std::string const & moduleLabel() const
Definition: Provenance.h:50
virtual ~HectorProducer()
void add(const HepMC::GenEvent *ev, const edm::EventSetup &es)
Definition: Hector.cc:165
HLT enums.
std::vector< LHCTransportLink > & getCorrespondenceMap()
Definition: Hector.h:72
HepMC::GenEvent * addPartToHepMC(HepMC::GenEvent *event)
Definition: Hector.cc:477
StreamID streamID() const
Definition: Event.h:81
std::vector< LHCTransportLink > LHCTransportLinkContainer
HepMC::GenEvent * evt_
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42
Provenance const * provenance() const
Definition: HandleBase.h:83
void clearApertureFlags()
Definition: Hector.cc:136
virtual void produce(edm::Event &e, const edm::EventSetup &c) override