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 {
79 }
80 
82 {
84  using namespace edm;
85 
87 
88  // // The beam spot position
89  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
90  iEvent.getByToken(beamSpotToken,recoBeamSpotHandle);
91  math::XYZPoint BSPosition_ = recoBeamSpotHandle->position();
92 
93  //Retrieve tracker topology from geometry
95  es.get<IdealGeometryRecord>().get(tTopoHand);
96  const TrackerTopology *tTopo=tTopoHand.product();
97 
98 
99  const HepMC::GenEvent* myGenEvent = 0;
100  FSimEvent* fevt = famosManager_->simEvent();
101  // fevt->setBeamSpot(BSPosition_);
102 
103  // Get the generated event(s) from the edm::Event
104  // 1. Check if a HepMCProduct exists
105  // a. Take the VtxSmeared if it exists
106  // b. Take the source otherwise
107  // 2. Otherwise go for the CandidateCollection
108 
109  Handle<HepMCProduct> theHepMCProduct;
110 
111  const reco::GenParticleCollection* myGenParticlesXF = 0; //OBSOLETE
112  const reco::GenParticleCollection* myGenParticles = 0;
113  const HepMC::GenEvent* thePUEvents = 0;
114 
115  // BEGIN OBSOLETE CODE
116  Handle<CrossingFrame<HepMCProduct> > theHepMCProductCrossingFrame;
117  bool isPileUpXF = iEvent.getByToken(mixSourceToken,theHepMCProductCrossingFrame);
118  if (isPileUpXF){// take the GenParticle from crossingframe event collection, if it exists
120  bool genPartXF = iEvent.getByToken(mixGenParticleToken,genEvtXF);
121  if(genPartXF) myGenParticlesXF = &(*genEvtXF);
122  }
123  else{// otherwise, use the old famos PU
124  // END OBSOLETE CODE
125  // Get the generated signal event
126  // BEGIN FUTURE OBSOLETE CODE
127  bool source = iEvent.getByToken(sourceToken,theHepMCProduct);
128  if ( source ) {
129  myGenEvent = theHepMCProduct->GetEvent();
130  }
131 
132  fevt->setBeamSpot(BSPosition_);
133  // GEN LEVEL INFO NOT IN HEPMC FORMAT
134  // In case there is no HepMCProduct, seek a genParticle Candidate Collection
135  bool genPart = false;
136  if ( !myGenEvent ) {
137  //END FUTURE OBSOLETE CODE
138  // Look for the particle CandidateCollection
140  genPart = iEvent.getByToken(genParticleToken,genEvt);
141  if ( genPart ) myGenParticles = &(*genEvt);
142  }
143 
144  if ( !myGenEvent && !genPart )
145  std::cout << "There is no generator input for this event, under "
146  << "any form (HepMCProduct, genParticles)" << std::endl
147  << "Please check SourceLabel or GenParticleLabel" << std::endl;
148 
149  // BEGIN FUTURE OBSOLETE CODE
150  // Get the pile-up events from the pile-up producer
151  // There might be no pile-up events, by the way, in that case, just continue
152  Handle<HepMCProduct> thePileUpEvents;
153  bool isPileUp = iEvent.getByToken(puToken,thePileUpEvents);
154  thePUEvents = isPileUp ? thePileUpEvents->GetEvent() : 0;
155  // END FUTURE OBSOLETE CODE
156  }//end else
157 
158 
159  // pass the event to the Famos Manager for propagation and simulation
160  if (myGenParticlesXF) {// OBSOLETE OPTION
161  famosManager_->reconstruct(myGenParticlesXF,tTopo, &random);
162  } else {
163  famosManager_->reconstruct(myGenEvent,myGenParticles,thePUEvents,tTopo, &random); // FUTURE OBSOLETE ARGUMENTS: myGenEvents, thePUEvents
164  }
165 
168 
169  // Save everything in the edm::Event
170  std::auto_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
171  std::auto_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
172  std::auto_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
173  std::auto_ptr<FSimVertexTypeCollection> v1(new FSimVertexTypeCollection);
174  std::auto_ptr<edm::PSimHitContainer> p3(new edm::PSimHitContainer);
175  std::auto_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
176  std::auto_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
177  std::auto_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
178  std::auto_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
179 
180  fevt->load(*p1,*m1);
181  fevt->load(*p2);
182  fevt->load(*v1);
183  // fevt->print();
184  tracker->loadSimHits(*p3);
185 
186  // fevt->print();
187 
188  if ( calo ) {
189  calo->loadFromEcalBarrel(*p4);
190  calo->loadFromEcalEndcap(*p5);
191  calo->loadFromPreshower(*p6);
192  calo->loadFromHcal(*p7);
193  // update the muon SimTracks
194  calo->loadMuonSimTracks(*m1);
195  }
196 
197  // Write muon first, to allow tracking particles to work... (pending MixingModule fix)
198  if ( simulateMuons ) iEvent.put(m1,"MuonSimTracks");
199  iEvent.put(p1);
200  iEvent.put(p2);
201  iEvent.put(p3,"TrackerHits");
202  iEvent.put(v1,"VertexTypes");
203  iEvent.put(p4,"EcalHitsEB");
204  iEvent.put(p5,"EcalHitsEE");
205  iEvent.put(p6,"EcalHitsES");
206  iEvent.put(p7,"HcalHits");
207 
208 }
209 
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:446
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:57
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: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: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: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:90
static std::string const source
Definition: EdmProvDump.cc:43
Definition: Run.h:41
double p3[4]
Definition: TauolaWrapper.h:91