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