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