CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HectorProducer.cc
Go to the documentation of this file.
1 // Framework headers
7 
8 // SimpleConfigurable replacement
10 
11 // HepMC headers
12 #include "HepMC/GenEvent.h"
13 
14 // Hector headers
17 
18 // SimDataFormats headers
21 
22 #include "CLHEP/Random/RandomEngine.h"
23 
24 #include <iostream>
25 #include <memory>
26 #include <string>
27 
28 class TRandom3;
29 
30 using std::cout;
31 using std::endl;
32 
34 
35 
36  // TransportHector
37 
38  m_InTag = parameters.getParameter<std::string>("HepMCProductLabel") ;
39  m_verbosity = parameters.getParameter<bool>("Verbosity");
40  m_FP420Transport = parameters.getParameter<bool>("FP420Transport");
41  m_ZDCTransport = parameters.getParameter<bool>("ZDCTransport");
42 
43  produces<edm::HepMCProduct>();
44  produces<edm::LHCTransportLinkContainer>();
45 
46  hector = new Hector(parameters,
47  m_verbosity,
48  m_FP420Transport,
49  m_ZDCTransport);
50 
52  if ( ! rng.isAvailable() ) {
53  throw cms::Exception("Configuration")
54  << "LHCTransport (HectorProducer) requires the RandomNumberGeneratorService\n"
55  "which is not present in the configuration file. You must add the service\n"
56  "in the configuration file or remove the modules that require it.";
57  }
58 }
59 
61 
62  if(m_verbosity) {
63  LogDebug("HectorSetup") << "Delete HectorProducer"
64  << "Number of events analysed: " << eventsAnalysed;
65  }
66 
67 }
68 
70 
71  using namespace edm;
72  using namespace std;
73 
75  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
76  if ( engine->name() != "TRandom3" ) {
77  throw cms::Exception("Configuration")
78  << "The TRandom3 engine type must be used with HectorProducer, Random Number Generator Service not correctly configured!";
79  }
80  TRandom3* rootEngine = ( (edm::TRandomAdaptor*) engine )->getRootEngine();
81 
83 
84  Handle<HepMCProduct> HepMCEvt;
85  iEvent.getByLabel( m_InTag, HepMCEvt ) ;
86 
87  if ( !HepMCEvt.isValid() )
88  {
89  throw cms::Exception("InvalidReference")
90  << "Invalid reference to HepMCProduct\n";
91  }
92 
93  if ( HepMCEvt.provenance()->moduleLabel() == "LHCTransport" )
94  {
95  throw cms::Exception("LogicError")
96  << "HectorTrasported HepMCProduce already exists\n";
97  }
98 
99  evt_ = new HepMC::GenEvent( *HepMCEvt->GetEvent() );
101  if(m_FP420Transport) {
102  hector->clear();
103  hector->add( evt_ ,es);
104  hector->filterFP420(rootEngine);
105  }
106  if(m_ZDCTransport) {
107  hector->clear();
108  hector->add( evt_ ,es);
109  hector->filterZDC(rootEngine);
110 
111  hector->clear();
112  hector->add( evt_ ,es);
113  hector->filterD1(rootEngine);
114  }
116  if (m_verbosity) {
117  evt_->print();
118  }
119 
120  auto_ptr<HepMCProduct> NewProduct(new HepMCProduct()) ;
121  NewProduct->addHepMCData( evt_ ) ;
122 
123  iEvent.put( NewProduct ) ;
124 
125  auto_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer() );
127  (*NewCorrespondenceMap).swap(thisLink);
128 
129  if ( m_verbosity ) {
130  for ( unsigned int i = 0; i < (*NewCorrespondenceMap).size(); i++)
131  LogDebug("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
132  }
133 
134  iEvent.put( NewCorrespondenceMap );
135 
136 }
137 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
std::string m_InTag
void produce(edm::Event &iEvent, const edm::EventSetup &es)
this method will do the user analysis
HectorProducer(edm::ParameterSet const &p)
default constructor
Definition: Hector.h:40
void clear()
Definition: Hector.cc:142
int iEvent
Definition: GenABIO.cc:230
void filterD1(TRandom3 *)
Definition: Hector.cc:386
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
bool isAvailable() const
Definition: Service.h:46
void filterFP420(TRandom3 *)
Definition: Hector.cc:231
int eventsAnalysed
just to count events that have been analysed
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
void filterZDC(TRandom3 *)
Definition: Hector.cc:315
virtual ~HectorProducer()
default destructor
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
void add(const HepMC::GenEvent *ev, const edm::EventSetup &es)
Definition: Hector.cc:165
std::vector< LHCTransportLink > & getCorrespondenceMap()
Definition: Hector.h:72
HepMC::GenEvent * addPartToHepMC(HepMC::GenEvent *event)
Definition: Hector.cc:477
StreamID streamID() const
Definition: Event.h:74
std::vector< LHCTransportLink > LHCTransportLinkContainer
tuple cout
Definition: gather_cfg.py:121
HepMC::GenEvent * evt_
void clearApertureFlags()
Definition: Hector.cc:136