CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FamosManager.cc
Go to the documentation of this file.
1 // CMSSW Header
10 
12 
14 
15 //#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
16 //#include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
21 
25 //#include "Geometry/CaloTopology/interface/CaloTopology.h"
26 
27 // HepMC headers
28 //#include "HepMC/GenEvent.h"
29 
30 // FAMOS Header
40 #include <iostream>
41 #include <memory>
42 #include <vector>
43 
44 using namespace HepMC;
45 
47  : iEvent(0),
48  myPileUpSimulator(0),
49  myCalorimetry(0),
50  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
51  m_Tracking(p.getParameter<bool>("SimulateTracking")),
52  m_Calorimetry(p.getParameter<bool>("SimulateCalorimetry")),
53  m_Alignment(p.getParameter<bool>("ApplyAlignment")),
54  m_pRunNumber(p.getUntrackedParameter<int>("RunNumber",1)),
55  m_pVerbose(p.getUntrackedParameter<int>("Verbosity",1))
56 {
57  // Initialize the FSimEvent
58  mySimEvent =
59  new FSimEvent(p.getParameter<edm::ParameterSet>("VertexGenerator"),
60  p.getParameter<edm::ParameterSet>("ParticleFilter"));
61 
65  p.getParameter<edm::ParameterSet>("MaterialEffects"),
66  p.getParameter<edm::ParameterSet>("TrackerSimHits"),
67  p.getParameter<edm::ParameterSet>("ActivateDecays"));
68 
69  // Initialize PileUp Producer (if requested)
71 
72  // Initialize Calorimetry Fast Simulation (if requested)
73  if ( m_Calorimetry)
74  myCalorimetry =
76  p.getParameter<edm::ParameterSet>("Calorimetry"),
77  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInECAL"),
78  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInHCAL"),
79  p.getParameter<edm::ParameterSet>("GFlash"));
80 }
81 
83 {
84  if ( mySimEvent ) delete mySimEvent;
87  if ( myCalorimetry) delete myCalorimetry;
88 }
89 
90 void
92 {
93  // Particle data table (from Pythia)
95  es.getData(pdt);
96  mySimEvent->initializePdt(&(*pdt));
97  ParticleTable::instance(&(*pdt));
98 
99  // Initialize the full (misaligned) tracker geometry
100  // (only if tracking is requested)
101  std::string misAligned = m_Alignment ? "MisAligned" : "";
102  // 1) By default, the aligned geometry is chosen (m_Alignment = false)
103  // 2) By default, the misaligned geometry is aligned
105  es.get<TrackerDigiGeometryRecord>().get(misAligned,tracker);
107 
108  // Initialize the tracker misaligned reco geometry (always needed)
109  // By default, the misaligned geometry is aligned
110  edm::ESHandle<GeometricSearchTracker> theGeomSearchTracker;
111  es.get<TrackerRecoGeometryRecord>().get(misAligned, theGeomSearchTracker );
112 
113  // Initialize the misaligned tracker interaction geometry
114  edm::ESHandle<TrackerInteractionGeometry> theTrackerInteractionGeometry;
115  es.get<TrackerInteractionGeometryRecord>().get(misAligned, theTrackerInteractionGeometry );
116 
117  // Initialize the magnetic field
118  double bField000 = 0.;
119  if (m_pUseMagneticField) {
120  edm::ESHandle<MagneticFieldMap> theMagneticFieldMap;
121  es.get<MagneticFieldMapRecord>().get(misAligned, theMagneticFieldMap);
122  const GlobalPoint g(0.,0.,0.);
123  bField000 = theMagneticFieldMap->inTeslaZ(g);
124  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
125  &(*theTrackerInteractionGeometry),
126  &(*theMagneticFieldMap));
127  } else {
128  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
129  &(*theTrackerInteractionGeometry),
130  0);
131  bField000 = 4.0;
132  }
133  // The following should be on LogInfo
134  //std::cout << "B-field(T) at (0,0,0)(cm): " << bField000 << std::endl;
135 
136  // Initialize the calorimeter geometry
137  if ( myCalorimetry ) {
139  es.get<CaloGeometryRecord>().get(pG);
141 
142  edm::ESHandle<CaloTopology> theCaloTopology;
143  es.get<CaloTopologyRecord>().get(theCaloTopology);
144  myCalorimetry->getCalorimeter()->setupTopology(*theCaloTopology);
145  myCalorimetry->getCalorimeter()->initialize(bField000);
146  }
147 
148  m_pRunNumber = run.run();
149 
150 }
151 
152 
153 void
154 FamosManager::reconstruct(const HepMC::GenEvent* evt,
155  const reco::GenParticleCollection* particles,
156  const HepMC::GenEvent* pu,
157  const TrackerTopology *tTopo,
159 {
160 
161  // myGenEvent = evt;
162 
163  if (evt != 0 || particles != 0) {
164  iEvent++;
166 
167 
168  // Fill the event from the original generated event
169  if (evt )
170  mySimEvent->fill(*evt,id, random);
171 
172  else
173  mySimEvent->fill(*particles,id, random);
174 
175  // mySimEvent->printMCTruth(*evt);
176  /*
177  mySimEvent->print();
178  std::cout << "----------------------------------------" << std::endl;
179  */
180 
181  // Get the pileup events and add the particles to the main event
183  /*
184  mySimEvent->print();
185  std::cout << "----------------------------------------" << std::endl;
186  */
187 
188  // And propagate the particles through the detector
189  myTrajectoryManager->reconstruct(tTopo, random);
190  /*
191  mySimEvent->print();
192  std::cout << "========================================="
193  << std::endl
194  << std::endl;
195  */
196 
197  if ( myCalorimetry ) myCalorimetry->reconstruct(random);
198  }
199 
200  // Should be moved to LogInfo
201  edm::LogInfo("FamosManager") << " saved : Event " << iEvent
202  << " of weight " << mySimEvent->weight()
203  << " with " << mySimEvent->nTracks()
204  << " tracks and " << mySimEvent->nVertices()
205  << " vertices, generated by "
206  << mySimEvent->nGenParts() << " particles " << std::endl;
207 }
208 
210  iEvent++;
212  mySimEvent->fill(*particles, id, random);
213  myTrajectoryManager->reconstruct(tTopo, random);
214  if ( myCalorimetry ) myCalorimetry->reconstruct(random);
215 }
void reconstruct(const TrackerTopology *tTopo, RandomEngineAndDistribution const *)
Does the real job.
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
bool m_pUseMagneticField
Definition: FamosManager.h:79
void initializeTrackerGeometry(const TrackerGeometry *geomTracker)
Initialize the full Tracker Geometry.
void fill(const HepMC::GenEvent &hev, edm::EventID &Id, RandomEngineAndDistribution const *)
fill the FBaseSimEvent from the current HepMC::GenEvent
Definition: FSimEvent.cc:25
RunNumber_t run() const
Definition: RunBase.h:42
~FamosManager()
Destructor.
Definition: FamosManager.cc:82
FSimEvent * mySimEvent
Definition: FamosManager.h:72
bool m_Alignment
Definition: FamosManager.h:82
void setupTopology(const CaloTopology &)
Definition: Calorimeter.cc:127
void initializeRecoGeometry(const GeometricSearchTracker *geomSearchTracker, const TrackerInteractionGeometry *interactionGeometry, const MagneticFieldMap *aFieldMap)
Initialize the Reconstruction Geometry.
CaloGeometryHelper * getCalorimeter() const
TRandom random
Definition: MVATrainer.cc:138
TrajectoryManager * myTrajectoryManager
Definition: FamosManager.h:73
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void getData(T &iHolder) const
Definition: EventSetup.h:67
int iEvent
Definition: GenABIO.cc:243
void reconstruct(RandomEngineAndDistribution const *)
CalorimetryManager * myCalorimetry
Definition: FamosManager.h:75
FamosManager(edm::ParameterSet const &p)
Constructor.
Definition: FamosManager.cc:46
bool m_Calorimetry
Definition: FamosManager.h:81
unsigned int nTracks() const
Number of tracks.
Definition: FSimEvent.cc:47
void setupGeometry(const CaloGeometry &pG)
Definition: Calorimeter.cc:117
unsigned int nGenParts() const
Number of MC particles.
Definition: FSimEvent.cc:57
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.
static ParticleTable * instance()
Definition: ParticleTable.h:15
const T & get() const
Definition: EventSetup.h:55
unsigned int nVertices() const
Number of vertices.
Definition: FSimEvent.cc:52
void produce(const HepMC::GenEvent *pu)
Produce N minimum bias events, and add them to the FSimEvent.
float weight() const
Method to return the event weight.
Definition: FSimEvent.cc:42
void initializePdt(const HepPDT::ParticleDataTable *aPdt)
Initialize the particle data table.
PileUpSimulator * myPileUpSimulator
Definition: FamosManager.h:74
void initialize(double bField)
void setupGeometryAndField(edm::Run const &run, const edm::EventSetup &es)
Get information from the Event Setup.
Definition: FamosManager.cc:91
Definition: Run.h:41