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 
25 
26 #include "HepMC/GenVertex.h"
27 #include "HepMC/GenEvent.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  sourceLabel = p.getParameter<edm::InputTag>("SourceLabel");
50  genParticleLabel = p.getParameter<edm::InputTag>("GenParticleLabel");
51  beamSpotLabel = p.getParameter<edm::InputTag>("BeamSpotLabel");
52 
53  // consume declarations
54  beamSpotToken = consumes<reco::BeamSpot>(beamSpotLabel);
55  genParticleToken = consumes<reco::GenParticleCollection>(genParticleLabel);
56  // FUTURE OBSOLETE CODE
57  sourceToken = consumes<edm::HepMCProduct>(sourceLabel);
58  edm::InputTag _label = edm::InputTag("famosPileUp","PileUpEvents");
59  puToken = consumes<edm::HepMCProduct>(_label);
60  // OBSOLETE CODE
61  _label = edm::InputTag("mixGenPU","generator");
62  mixSourceToken = consumes<CrossingFrame<edm::HepMCProduct> >(_label);
63  _label = edm::InputTag("genParticlesFromMixingModule");
64  mixGenParticleToken = consumes<reco::GenParticleCollection>(_label);
65 
66  // famos manager
67  famosManager_ = new FamosManager(p);
68 }
69 
71 { if ( famosManager_ ) delete famosManager_; }
72 
73 void
76 }
77 
79 {
80 }
81 
83 {
85  using namespace edm;
86 
88 
89  // // The beam spot position
90  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
91  iEvent.getByToken(beamSpotToken,recoBeamSpotHandle);
92  math::XYZPoint BSPosition_ = recoBeamSpotHandle->position();
93 
94  //Retrieve tracker topology from geometry
96  es.get<IdealGeometryRecord>().get(tTopoHand);
97  const TrackerTopology *tTopo=tTopoHand.product();
98 
99 
100  const HepMC::GenEvent* myGenEvent = 0;
101  FSimEvent* fevt = famosManager_->simEvent();
102  // fevt->setBeamSpot(BSPosition_);
103 
104  // Get the generated event(s) from the edm::Event
105  // 1. Check if a HepMCProduct exists
106  // a. Take the VtxSmeared if it exists
107  // b. Take the source otherwise
108  // 2. Otherwise go for the CandidateCollection
109 
110  Handle<HepMCProduct> theHepMCProduct;
111 
112  PrimaryVertexGenerator* theVertexGenerator = fevt->thePrimaryVertexGenerator();
113 
114 
115  const reco::GenParticleCollection* myGenParticlesXF = 0; //OBSOLETE
116  const reco::GenParticleCollection* myGenParticles = 0;
117  const HepMC::GenEvent* thePUEvents = 0;
118 
119  // BEGIN OBSOLETE CODE
120  Handle<CrossingFrame<HepMCProduct> > theHepMCProductCrossingFrame;
121  bool isPileUpXF = iEvent.getByToken(mixSourceToken,theHepMCProductCrossingFrame);
122  if (isPileUpXF){// take the GenParticle from crossingframe event collection, if it exists
124  bool genPartXF = iEvent.getByToken(mixGenParticleToken,genEvtXF);
125  if(genPartXF) myGenParticlesXF = &(*genEvtXF);
126  }
127  else{// otherwise, use the old famos PU
128  // END OBSOLETE CODE
129  // Get the generated signal event
130  // BEGIN FUTURE OBSOLETE CODE
131  bool source = iEvent.getByToken(sourceToken,theHepMCProduct);
132  if ( source ) {
133  myGenEvent = theHepMCProduct->GetEvent();
134  // First rotate in case of beam crossing angle (except if done already)
135  if ( theVertexGenerator ) {
136  TMatrixD* boost = theVertexGenerator->boost();
137  if ( boost ) theHepMCProduct->boostToLab(boost,"momentum");
138  }
139  myGenEvent = theHepMCProduct->GetEvent();
140  }
141 
142  fevt->setBeamSpot(BSPosition_);
143  // GEN LEVEL INFO NOT IN HEPMC FORMAT
144  // In case there is no HepMCProduct, seek a genParticle Candidate Collection
145  bool genPart = false;
146  if ( !myGenEvent ) {
147  //END FUTURE OBSOLETE CODE
148  // Look for the particle CandidateCollection
150  genPart = iEvent.getByToken(genParticleToken,genEvt);
151  if ( genPart ) myGenParticles = &(*genEvt);
152  }
153 
154  if ( !myGenEvent && !genPart )
155  std::cout << "There is no generator input for this event, under "
156  << "any form (HepMCProduct, genParticles)" << std::endl
157  << "Please check SourceLabel or GenParticleLabel" << std::endl;
158 
159  // BEGIN FUTURE OBSOLETE CODE
160  // Get the pile-up events from the pile-up producer
161  // There might be no pile-up events, by the way, in that case, just continue
162  Handle<HepMCProduct> thePileUpEvents;
163  bool isPileUp = iEvent.getByToken(puToken,thePileUpEvents);
164  thePUEvents = isPileUp ? thePileUpEvents->GetEvent() : 0;
165  // END FUTURE OBSOLETE CODE
166  }//end else
167 
168 
169  // pass the event to the Famos Manager for propagation and simulation
170  if (myGenParticlesXF) {// OBSOLETE OPTION
171  famosManager_->reconstruct(myGenParticlesXF,tTopo, &random);
172  } else {
173  famosManager_->reconstruct(myGenEvent,myGenParticles,thePUEvents,tTopo, &random); // FUTURE OBSOLETE ARGUMENTS: myGenEvents, thePUEvents
174  }
175 
176  // BEGIN FUTURE OBSOLETE CODE
177  // Set the vertex back to the HepMCProduct (except if it was smeared already)
178  if ( myGenEvent ) {
179  if ( theVertexGenerator ) {
180  HepMC::FourVector theVertex(
181  (theVertexGenerator->X()-theVertexGenerator->beamSpot().X()+BSPosition_.X())*10.,
182  (theVertexGenerator->Y()-theVertexGenerator->beamSpot().Y()+BSPosition_.Y())*10.,
183  (theVertexGenerator->Z()-theVertexGenerator->beamSpot().Z()+BSPosition_.Z())*10.,
184  0.);
185  if ( fabs(theVertexGenerator->Z()) > 1E-10 ) theHepMCProduct->applyVtxGen( &theVertex );
186  }
187  }
188  // END FUTURE OBSOLETE CODE
189 
192 
193  // Save everything in the edm::Event
194  std::auto_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
195  std::auto_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
196  std::auto_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
197  std::auto_ptr<FSimVertexTypeCollection> v1(new FSimVertexTypeCollection);
198  std::auto_ptr<edm::PSimHitContainer> p3(new edm::PSimHitContainer);
199  std::auto_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
200  std::auto_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
201  std::auto_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
202  std::auto_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
203 
204  fevt->load(*p1,*m1);
205  fevt->load(*p2);
206  fevt->load(*v1);
207  // fevt->print();
208  tracker->loadSimHits(*p3);
209 
210  // fevt->print();
211 
212  if ( calo ) {
213  calo->loadFromEcalBarrel(*p4);
214  calo->loadFromEcalEndcap(*p5);
215  calo->loadFromPreshower(*p6);
216  calo->loadFromHcal(*p7);
217  // update the muon SimTracks
218  calo->loadMuonSimTracks(*m1);
219  }
220 
221  // Write muon first, to allow tracking particles to work... (pending MixingModule fix)
222  if ( simulateMuons ) iEvent.put(m1,"MuonSimTracks");
223  iEvent.put(p1);
224  iEvent.put(p2);
225  iEvent.put(p3,"TrackerHits");
226  iEvent.put(v1,"VertexTypes");
227  iEvent.put(p4,"EcalHitsEB");
228  iEvent.put(p5,"EcalHitsEE");
229  iEvent.put(p6,"EcalHitsES");
230  iEvent.put(p7,"HcalHits");
231 
232 }
233 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
Definition: FamosProducer.h:43
std::vector< PCaloHit > PCaloHitContainer
virtual ~FamosProducer()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual void endJob() override
#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:63
edm::InputTag sourceLabel
Definition: FamosProducer.h:38
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken
Definition: FamosProducer.h:44
TRandom random
Definition: MVATrainer.cc:138
FamosManager * famosManager_
Definition: FamosProducer.h:33
edm::InputTag genParticleLabel
Definition: FamosProducer.h:39
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:116
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:47
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:46
edm::EDGetTokenT< reco::GenParticleCollection > mixGenParticleToken
Definition: FamosProducer.h:50
edm::InputTag beamSpotLabel
Definition: FamosProducer.h:40
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:49
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: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:43
Definition: Run.h:41
double p3[4]
Definition: TauolaWrapper.h:91