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 
9 
11 
16 
28 
29 #include "HepMC/GenEvent.h"
30 #include "HepMC/GenVertex.h"
31 
32 #include <iostream>
33 #include <memory>
34 #include <vector>
35 
37 {
38 
39  produces<edm::SimTrackContainer>();
40  produces<edm::SimVertexContainer>();
41  produces<FSimVertexTypeCollection>("VertexTypes");
42  produces<edm::PSimHitContainer>("TrackerHits");
43  produces<edm::PCaloHitContainer>("EcalHitsEB");
44  produces<edm::PCaloHitContainer>("EcalHitsEE");
45  produces<edm::PCaloHitContainer>("EcalHitsES");
46  produces<edm::PCaloHitContainer>("HcalHits");
47  // Temporary facility to allow for the crossing frame to work...
48  simulateMuons = p.getParameter<bool>("SimulateMuons");
49  if ( simulateMuons ) produces<edm::SimTrackContainer>("MuonSimTracks");
50 
51  // The generator input label
52  theSourceLabel = p.getParameter<edm::InputTag>("SourceLabel");
53  theGenParticleLabel = p.getParameter<edm::InputTag>("GenParticleLabel");
54  theBeamSpotLabel = p.getParameter<edm::InputTag>("BeamSpotLabel");
55 
56  famosManager_ = new FamosManager(p);
57 
58 }
59 
61 { if ( famosManager_ ) delete famosManager_; }
62 
63 void
66 }
67 
69 {
70 }
71 
73 {
74  using namespace edm;
75 
77 
78  // // The beam spot position
79  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
80  iEvent.getByLabel(theBeamSpotLabel,recoBeamSpotHandle);
81  math::XYZPoint BSPosition_ = recoBeamSpotHandle->position();
82 
83  //Retrieve tracker topology from geometry
85  es.get<IdealGeometryRecord>().get(tTopoHand);
86  const TrackerTopology *tTopo=tTopoHand.product();
87 
88 
89  const HepMC::GenEvent* myGenEvent = 0;
90  FSimEvent* fevt = famosManager_->simEvent();
91  // fevt->setBeamSpot(BSPosition_);
92 
93  // Get the generated event(s) from the edm::Event
94  // 1. Check if a HepMCProduct exists
95  // a. Take the VtxSmeared if it exists
96  // b. Take the source otherwise
97  // 2. Otherwise go for the CandidateCollection
98 
99  Handle<HepMCProduct> theHepMCProduct;
100 
101  PrimaryVertexGenerator* theVertexGenerator = fevt->thePrimaryVertexGenerator();
102 
103 
104  const reco::GenParticleCollection* myGenParticlesXF = 0;
105  const reco::GenParticleCollection* myGenParticles = 0;
106  const HepMC::GenEvent* thePUEvents = 0;
107 
108  Handle<CrossingFrame<HepMCProduct> > theHepMCProductCrossingFrame;
109  bool isPileUpXF = iEvent.getByLabel("mixGenPU","generator",theHepMCProductCrossingFrame);
110 
111  if (isPileUpXF){// take the GenParticle from crossingframe event collection, if it exists
113  bool genPartXF = iEvent.getByLabel("genParticlesFromMixingModule",genEvtXF);
114  if(genPartXF) myGenParticlesXF = &(*genEvtXF);
115  }
116  else{// otherwise, use the old famos PU
117  // Get the generated signal event
118  bool source = iEvent.getByLabel(theSourceLabel,theHepMCProduct);
119  if ( source ) {
120  myGenEvent = theHepMCProduct->GetEvent();
121  // First rotate in case of beam crossing angle (except if done already)
122  if ( theVertexGenerator ) {
123  TMatrixD* boost = theVertexGenerator->boost();
124  if ( boost ) theHepMCProduct->boostToLab(boost,"momentum");
125  }
126  myGenEvent = theHepMCProduct->GetEvent();
127  }
128 
129  fevt->setBeamSpot(BSPosition_);
130 
131  // In case there is no HepMCProduct, seek a genParticle Candidate Collection
132  bool genPart = false;
133  if ( !myGenEvent ) {
134  // Look for the particle CandidateCollection
136  genPart = iEvent.getByLabel(theGenParticleLabel,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  // Get the pile-up events from the pile-up producer
146  // There might be no pile-up events, by the way, in that case, just continue
147  Handle<HepMCProduct> thePileUpEvents;
148  bool isPileUp = iEvent.getByLabel("famosPileUp","PileUpEvents",thePileUpEvents);
149  thePUEvents = isPileUp ? thePileUpEvents->GetEvent() : 0;
150 
151  }//end else
152 
153  // pass the event to the Famos Manager for propagation and simulation
154  if (myGenParticlesXF) {
155  famosManager_->reconstruct(myGenParticlesXF,tTopo, &random);
156  } else {
157  famosManager_->reconstruct(myGenEvent,myGenParticles,thePUEvents,tTopo, &random);
158  }
159 
160  // Set the vertex back to the HepMCProduct (except if it was smeared already)
161  if ( myGenEvent ) {
162  if ( theVertexGenerator ) {
163  HepMC::FourVector theVertex(
164  (theVertexGenerator->X()-theVertexGenerator->beamSpot().X()+BSPosition_.X())*10.,
165  (theVertexGenerator->Y()-theVertexGenerator->beamSpot().Y()+BSPosition_.Y())*10.,
166  (theVertexGenerator->Z()-theVertexGenerator->beamSpot().Z()+BSPosition_.Z())*10.,
167  0.);
168  if ( fabs(theVertexGenerator->Z()) > 1E-10 ) theHepMCProduct->applyVtxGen( &theVertex );
169  }
170  }
171 
174 
175  // Save everything in the edm::Event
176  std::auto_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
177  std::auto_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
178  std::auto_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
179  std::auto_ptr<FSimVertexTypeCollection> v1(new FSimVertexTypeCollection);
180  std::auto_ptr<edm::PSimHitContainer> p3(new edm::PSimHitContainer);
181  std::auto_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
182  std::auto_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
183  std::auto_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
184  std::auto_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
185 
186  fevt->load(*p1,*m1);
187  fevt->load(*p2);
188  fevt->load(*v1);
189  // fevt->print();
190  tracker->loadSimHits(*p3);
191 
192  // fevt->print();
193 
194  if ( calo ) {
195  calo->loadFromEcalBarrel(*p4);
196  calo->loadFromEcalEndcap(*p5);
197  calo->loadFromPreshower(*p6);
198  calo->loadFromHcal(*p7);
199  // update the muon SimTracks
200  calo->loadMuonSimTracks(*m1);
201  }
202 
203  // Write muon first, to allow tracking particles to work... (pending MixingModule fix)
204  if ( simulateMuons ) iEvent.put(m1,"MuonSimTracks");
205  iEvent.put(p1);
206  iEvent.put(p2);
207  iEvent.put(p3,"TrackerHits");
208  iEvent.put(v1,"VertexTypes");
209  iEvent.put(p4,"EcalHitsEB");
210  iEvent.put(p5,"EcalHitsEE");
211  iEvent.put(p6,"EcalHitsES");
212  iEvent.put(p7,"HcalHits");
213 
214 }
215 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
std::vector< PCaloHit > PCaloHitContainer
virtual ~FamosProducer()
virtual void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag theBeamSpotLabel
Definition: FamosProducer.h:33
TRandom random
Definition: MVATrainer.cc:138
FamosManager * famosManager_
Definition: FamosProducer.h:28
virtual void beginRun(edm::Run const &run, const edm::EventSetup &es) override
FamosProducer(edm::ParameterSet const &p)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
double p4[4]
Definition: TauolaWrapper.h:92
edm::InputTag theSourceLabel
Definition: FamosProducer.h:31
std::vector< FSimVertexType > FSimVertexTypeCollection
collection of FSimVertexType objects
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
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.
edm::InputTag theGenParticleLabel
Definition: FamosProducer.h:32
CalorimetryManager * calorimetryManager() const
The calorimeter.
Definition: FamosManager.h:65
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
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
double p1[4]
Definition: TauolaWrapper.h:89
StreamID streamID() const
Definition: Event.h:75
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
TrajectoryManager * trackerManager() const
The tracker.
Definition: FamosManager.h:62
FSimEvent * simEvent() const
The generated event.
Definition: FamosManager.h:48
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:43
Definition: Run.h:41
double p3[4]
Definition: TauolaWrapper.h:91