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 
14 
23 
24 #include "HepMC/GenVertex.h"
25 #include "HepMC/GenEvent.h"
26 
27 #include <iostream>
28 #include <memory>
29 #include <vector>
30 
32 {
33 
34  produces<edm::SimTrackContainer>();
35  produces<edm::SimVertexContainer>();
36  produces<FSimVertexTypeCollection>("VertexTypes");
37  produces<edm::PSimHitContainer>("TrackerHits");
38  produces<edm::PCaloHitContainer>("EcalHitsEB");
39  produces<edm::PCaloHitContainer>("EcalHitsEE");
40  produces<edm::PCaloHitContainer>("EcalHitsES");
41  produces<edm::PCaloHitContainer>("HcalHits");
42  // Temporary facility to allow for the crossing frame to work...
43  simulateMuons = p.getParameter<bool>("SimulateMuons");
44  if ( simulateMuons ) produces<edm::SimTrackContainer>("MuonSimTracks");
45 
46  // The generator input label
47  sourceLabel = p.getParameter<edm::InputTag>("SourceLabel");
48  genParticleLabel = p.getParameter<edm::InputTag>("GenParticleLabel");
49 
50  // consume declarations
51  genParticleToken = consumes<reco::GenParticleCollection>(genParticleLabel);
52  // FUTURE OBSOLETE CODE
53  sourceToken = consumes<edm::HepMCProduct>(sourceLabel);
54  edm::InputTag _label = edm::InputTag("famosPileUp","PileUpEvents");
55  puToken = consumes<edm::HepMCProduct>(_label);
56  // OBSOLETE CODE
57  _label = edm::InputTag("mixGenPU","generator");
58  mixSourceToken = consumes<CrossingFrame<edm::HepMCProduct> >(_label);
59  _label = edm::InputTag("genParticlesFromMixingModule");
60  mixGenParticleToken = consumes<reco::GenParticleCollection>(_label);
61 
62  // famos manager
63  famosManager_ = new FamosManager(p);
64 }
65 
67 { if ( famosManager_ ) delete famosManager_; }
68 
69 void
72 }
73 
75 {
77  using namespace edm;
78 
80 
81  //Retrieve tracker topology from geometry
83  es.get<IdealGeometryRecord>().get(tTopoHand);
84  const TrackerTopology *tTopo=tTopoHand.product();
85 
86 
87  const HepMC::GenEvent* myGenEvent = 0;
88  FSimEvent* fevt = famosManager_->simEvent();
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  const reco::GenParticleCollection* myGenParticlesXF = 0; //OBSOLETE
99  const reco::GenParticleCollection* myGenParticles = 0;
100  const HepMC::GenEvent* thePUEvents = 0;
101 
102  // BEGIN OBSOLETE CODE
103  Handle<CrossingFrame<HepMCProduct> > theHepMCProductCrossingFrame;
104  bool isPileUpXF = iEvent.getByToken(mixSourceToken,theHepMCProductCrossingFrame);
105  if (isPileUpXF){// take the GenParticle from crossingframe event collection, if it exists
107  bool genPartXF = iEvent.getByToken(mixGenParticleToken,genEvtXF);
108  if(genPartXF) myGenParticlesXF = &(*genEvtXF);
109  }
110  else{// otherwise, use the old famos PU
111  // END OBSOLETE CODE
112  // Get the generated signal event
113  // BEGIN FUTURE OBSOLETE CODE
114  bool source = iEvent.getByToken(sourceToken,theHepMCProduct);
115  if ( source ) {
116  myGenEvent = theHepMCProduct->GetEvent();
117  }
118 
119  // GEN LEVEL INFO NOT IN HEPMC FORMAT
120  // In case there is no HepMCProduct, seek a genParticle Candidate Collection
121  bool genPart = false;
122  if ( !myGenEvent ) {
123  //END FUTURE OBSOLETE CODE
124  // Look for the particle CandidateCollection
126  genPart = iEvent.getByToken(genParticleToken,genEvt);
127  if ( genPart ) myGenParticles = &(*genEvt);
128  }
129 
130  if ( !myGenEvent && !genPart )
131  std::cout << "There is no generator input for this event, under "
132  << "any form (HepMCProduct, genParticles)" << std::endl
133  << "Please check SourceLabel or GenParticleLabel" << std::endl;
134 
135  // BEGIN FUTURE OBSOLETE CODE
136  // Get the pile-up events from the pile-up producer
137  // There might be no pile-up events, by the way, in that case, just continue
138  Handle<HepMCProduct> thePileUpEvents;
139  bool isPileUp = iEvent.getByToken(puToken,thePileUpEvents);
140  thePUEvents = isPileUp ? thePileUpEvents->GetEvent() : 0;
141  // END FUTURE OBSOLETE CODE
142  }//end else
143 
144 
145  // pass the event to the Famos Manager for propagation and simulation
146  if (myGenParticlesXF) {// OBSOLETE OPTION
147  famosManager_->reconstruct(myGenParticlesXF,tTopo, &random);
148  } else {
149  famosManager_->reconstruct(myGenEvent,myGenParticles,thePUEvents,tTopo, &random); // FUTURE OBSOLETE ARGUMENTS: myGenEvents, thePUEvents
150  }
151 
154 
155  // Save everything in the edm::Event
156  std::auto_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
157  std::auto_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
158  std::auto_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
159  std::auto_ptr<FSimVertexTypeCollection> v1(new FSimVertexTypeCollection);
160  std::auto_ptr<edm::PSimHitContainer> p3(new edm::PSimHitContainer);
161  std::auto_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
162  std::auto_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
163  std::auto_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
164  std::auto_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
165 
166  fevt->load(*p1,*m1);
167  fevt->load(*p2);
168  fevt->load(*v1);
169  // fevt->print();
170  tracker->loadSimHits(*p3);
171 
172  // fevt->print();
173 
174  if ( calo ) {
175  calo->loadFromEcalBarrel(*p4);
176  calo->loadFromEcalEndcap(*p5);
177  calo->loadFromPreshower(*p6);
178  calo->loadFromHcal(*p7);
179  // update the muon SimTracks
180  calo->loadMuonSimTracks(*m1);
181  }
182 
183  // Write muon first, to allow tracking particles to work... (pending MixingModule fix)
184  if ( simulateMuons ) iEvent.put(m1,"MuonSimTracks");
185  iEvent.put(p1);
186  iEvent.put(p2);
187  iEvent.put(p3,"TrackerHits");
188  iEvent.put(v1,"VertexTypes");
189  iEvent.put(p4,"EcalHitsEB");
190  iEvent.put(p5,"EcalHitsEE");
191  iEvent.put(p6,"EcalHitsES");
192  iEvent.put(p7,"HcalHits");
193 
194 }
195 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
std::vector< PCaloHit > PCaloHitContainer
virtual ~FamosProducer()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#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:36
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken
Definition: FamosProducer.h:40
TRandom random
Definition: MVATrainer.cc:138
FamosManager * famosManager_
Definition: FamosProducer.h:31
edm::InputTag genParticleLabel
Definition: FamosProducer.h:37
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:43
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:42
edm::EDGetTokenT< reco::GenParticleCollection > mixGenParticleToken
Definition: FamosProducer.h:46
const T & get() const
Definition: EventSetup.h:55
std::vector< SimVertex > SimVertexContainer
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixSourceToken
Definition: FamosProducer.h:45
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:91
static std::string const source
Definition: EdmProvDump.cc:42
Definition: Run.h:41
double p3[4]
Definition: TauolaWrapper.h:91