CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FamosProducer.cc
Go to the documentation of this file.
5 
8 
10 
15 
24 
25 #include "HepMC/GenVertex.h"
26 #include "HepMC/GenEvent.h"
27 
28 #include <iostream>
29 #include <memory>
30 #include <vector>
31 
33 {
34 
35  produces<edm::SimTrackContainer>();
36  produces<edm::SimVertexContainer>();
37  produces<FSimVertexTypeCollection>("VertexTypes");
38  produces<edm::PSimHitContainer>("TrackerHits");
39  produces<edm::PCaloHitContainer>("EcalHitsEB");
40  produces<edm::PCaloHitContainer>("EcalHitsEE");
41  produces<edm::PCaloHitContainer>("EcalHitsES");
42  produces<edm::PCaloHitContainer>("HcalHits");
43  // Temporary facility to allow for the crossing frame to work...
44  simulateMuons = p.getParameter<bool>("SimulateMuons");
45  if ( simulateMuons ) produces<edm::SimTrackContainer>("MuonSimTracks");
46 
47  // The generator input label
48  sourceLabel = p.getParameter<edm::InputTag>("SourceLabel");
49  genParticleLabel = p.getParameter<edm::InputTag>("GenParticleLabel");
50  beamSpotLabel = p.getParameter<edm::InputTag>("BeamSpotLabel");
51 
52  // consume declarations
53  beamSpotToken = consumes<reco::BeamSpot>(beamSpotLabel);
54  genParticleToken = consumes<reco::GenParticleCollection>(genParticleLabel);
55  // FUTURE OBSOLETE CODE
56  sourceToken = consumes<edm::HepMCProduct>(sourceLabel);
57  edm::InputTag _label = edm::InputTag("famosPileUp","PileUpEvents");
58  puToken = consumes<edm::HepMCProduct>(_label);
59  // OBSOLETE CODE
60  _label = edm::InputTag("mixGenPU","generator");
61  mixSourceToken = consumes<CrossingFrame<edm::HepMCProduct> >(_label);
62  _label = edm::InputTag("genParticlesFromMixingModule");
63  mixGenParticleToken = consumes<reco::GenParticleCollection>(_label);
64 
65  // famos manager
66  famosManager_ = new FamosManager(p);
67 }
68 
70 { if ( famosManager_ ) delete famosManager_; }
71 
72 void
75 }
76 
78 {
80  using namespace edm;
81 
83 
84  // // The beam spot position
85  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
86  iEvent.getByToken(beamSpotToken,recoBeamSpotHandle);
87  math::XYZPoint BSPosition_ = recoBeamSpotHandle->position();
88 
89  //Retrieve tracker topology from geometry
91  es.get<IdealGeometryRecord>().get(tTopoHand);
92  const TrackerTopology *tTopo=tTopoHand.product();
93 
94 
95  const HepMC::GenEvent* myGenEvent = 0;
96  FSimEvent* fevt = famosManager_->simEvent();
97  // fevt->setBeamSpot(BSPosition_);
98 
99  // Get the generated event(s) from the edm::Event
100  // 1. Check if a HepMCProduct exists
101  // a. Take the VtxSmeared if it exists
102  // b. Take the source otherwise
103  // 2. Otherwise go for the CandidateCollection
104 
105  Handle<HepMCProduct> theHepMCProduct;
106 
107  const reco::GenParticleCollection* myGenParticlesXF = 0; //OBSOLETE
108  const reco::GenParticleCollection* myGenParticles = 0;
109  const HepMC::GenEvent* thePUEvents = 0;
110 
111  // BEGIN OBSOLETE CODE
112  Handle<CrossingFrame<HepMCProduct> > theHepMCProductCrossingFrame;
113  bool isPileUpXF = iEvent.getByToken(mixSourceToken,theHepMCProductCrossingFrame);
114  if (isPileUpXF){// take the GenParticle from crossingframe event collection, if it exists
116  bool genPartXF = iEvent.getByToken(mixGenParticleToken,genEvtXF);
117  if(genPartXF) myGenParticlesXF = &(*genEvtXF);
118  }
119  else{// otherwise, use the old famos PU
120  // END OBSOLETE CODE
121  // Get the generated signal event
122  // BEGIN FUTURE OBSOLETE CODE
123  bool source = iEvent.getByToken(sourceToken,theHepMCProduct);
124  if ( source ) {
125  myGenEvent = theHepMCProduct->GetEvent();
126  }
127 
128  fevt->setBeamSpot(BSPosition_);
129  // GEN LEVEL INFO NOT IN HEPMC FORMAT
130  // In case there is no HepMCProduct, seek a genParticle Candidate Collection
131  bool genPart = false;
132  if ( !myGenEvent ) {
133  //END FUTURE OBSOLETE CODE
134  // Look for the particle CandidateCollection
136  genPart = iEvent.getByToken(genParticleToken,genEvt);
137  if ( genPart ) myGenParticles = &(*genEvt);
138  }
139 
140  if ( !myGenEvent && !genPart )
141  std::cout << "There is no generator input for this event, under "
142  << "any form (HepMCProduct, genParticles)" << std::endl
143  << "Please check SourceLabel or GenParticleLabel" << std::endl;
144 
145  // BEGIN FUTURE OBSOLETE CODE
146  // Get the pile-up events from the pile-up producer
147  // There might be no pile-up events, by the way, in that case, just continue
148  Handle<HepMCProduct> thePileUpEvents;
149  bool isPileUp = iEvent.getByToken(puToken,thePileUpEvents);
150  thePUEvents = isPileUp ? thePileUpEvents->GetEvent() : 0;
151  // END FUTURE OBSOLETE CODE
152  }//end else
153 
154 
155  // pass the event to the Famos Manager for propagation and simulation
156  if (myGenParticlesXF) {// OBSOLETE OPTION
157  famosManager_->reconstruct(myGenParticlesXF,tTopo, &random);
158  } else {
159  famosManager_->reconstruct(myGenEvent,myGenParticles,thePUEvents,tTopo, &random); // FUTURE OBSOLETE ARGUMENTS: myGenEvents, thePUEvents
160  }
161 
164 
165  // Save everything in the edm::Event
166  std::auto_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
167  std::auto_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
168  std::auto_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
169  std::auto_ptr<FSimVertexTypeCollection> v1(new FSimVertexTypeCollection);
170  std::auto_ptr<edm::PSimHitContainer> p3(new edm::PSimHitContainer);
171  std::auto_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
172  std::auto_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
173  std::auto_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
174  std::auto_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
175 
176  fevt->load(*p1,*m1);
177  fevt->load(*p2);
178  fevt->load(*v1);
179  // fevt->print();
180  tracker->loadSimHits(*p3);
181 
182  // fevt->print();
183 
184  if ( calo ) {
185  calo->loadFromEcalBarrel(*p4);
186  calo->loadFromEcalEndcap(*p5);
187  calo->loadFromPreshower(*p6);
188  calo->loadFromHcal(*p7);
189  // update the muon SimTracks
190  calo->loadMuonSimTracks(*m1);
191  }
192 
193  // Write muon first, to allow tracking particles to work... (pending MixingModule fix)
194  if ( simulateMuons ) iEvent.put(m1,"MuonSimTracks");
195  iEvent.put(p1);
196  iEvent.put(p2);
197  iEvent.put(p3,"TrackerHits");
198  iEvent.put(v1,"VertexTypes");
199  iEvent.put(p4,"EcalHitsEB");
200  iEvent.put(p5,"EcalHitsEE");
201  iEvent.put(p6,"EcalHitsES");
202  iEvent.put(p7,"HcalHits");
203 
204 }
205 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
Definition: FamosProducer.h:42
std::vector< PCaloHit > PCaloHitContainer
virtual ~FamosProducer()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const HepPDT::ParticleDataTable * theTable() const
Get the pointer to the particle data table.
Definition: FBaseSimEvent.h:57
edm::InputTag sourceLabel
Definition: FamosProducer.h:37
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken
Definition: FamosProducer.h:43
TRandom random
Definition: MVATrainer.cc:138
FamosManager * famosManager_
Definition: FamosProducer.h:32
edm::InputTag genParticleLabel
Definition: FamosProducer.h:38
virtual void beginRun(edm::Run const &run, const edm::EventSetup &es) override
FamosProducer(edm::ParameterSet const &p)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
double p4[4]
Definition: TauolaWrapper.h:92
std::vector< FSimVertexType > FSimVertexTypeCollection
collection of FSimVertexType objects
double p2[4]
Definition: TauolaWrapper.h:90
edm::EDGetTokenT< edm::HepMCProduct > puToken
Definition: FamosProducer.h:46
void reconstruct(const HepMC::GenEvent *evt, const reco::GenParticleCollection *particles, const HepMC::GenEvent *pu, const TrackerTopology *tTopo, RandomEngineAndDistribution const *)
The real thing is done here.
CalorimetryManager * calorimetryManager() const
The calorimeter.
Definition: FamosManager.h:66
edm::EDGetTokenT< edm::HepMCProduct > sourceToken
Definition: FamosProducer.h:45
edm::EDGetTokenT< reco::GenParticleCollection > mixGenParticleToken
Definition: FamosProducer.h:49
edm::InputTag beamSpotLabel
Definition: FamosProducer.h:39
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:55
std::vector< SimVertex > SimVertexContainer
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixSourceToken
Definition: FamosProducer.h:48
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
double p1[4]
Definition: TauolaWrapper.h:89
StreamID streamID() const
Definition: Event.h:72
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
TrajectoryManager * trackerManager() const
The tracker.
Definition: FamosManager.h:63
FSimEvent * simEvent() const
The generated event.
Definition: FamosManager.h:49
std::vector< SimTrack > SimTrackContainer
void setupGeometryAndField(edm::Run const &run, const edm::EventSetup &es)
Get information from the Event Setup.
Definition: FamosManager.cc:91
static std::string const source
Definition: EdmProvDump.cc:42
Definition: Run.h:41
double p3[4]
Definition: TauolaWrapper.h:91