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>("ParticleFilter"));
60 
64  p.getParameter<edm::ParameterSet>("MaterialEffects"),
65  p.getParameter<edm::ParameterSet>("TrackerSimHits"),
66  p.getParameter<edm::ParameterSet>("ActivateDecays"));
67 
68  // Initialize PileUp Producer (if requested)
70 
71  // Initialize Calorimetry Fast Simulation (if requested)
72  if ( m_Calorimetry)
73  myCalorimetry =
75  p.getParameter<edm::ParameterSet>("Calorimetry"),
76  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInECAL"),
77  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInHCAL"),
78  p.getParameter<edm::ParameterSet>("GFlash"));
79 }
80 
82 {
83  if ( mySimEvent ) delete mySimEvent;
86  if ( myCalorimetry) delete myCalorimetry;
87 }
88 
89 void
91 {
92  // Particle data table (from Pythia)
94  es.getData(pdt);
95  mySimEvent->initializePdt(&(*pdt));
96 
97  // Initialize the full (misaligned) tracker geometry
98  // (only if tracking is requested)
99  std::string misAligned = m_Alignment ? "MisAligned" : "";
100  // 1) By default, the aligned geometry is chosen (m_Alignment = false)
101  // 2) By default, the misaligned geometry is aligned
103  es.get<TrackerDigiGeometryRecord>().get(misAligned,tracker);
105 
106  // Initialize the tracker misaligned reco geometry (always needed)
107  // By default, the misaligned geometry is aligned
108  edm::ESHandle<GeometricSearchTracker> theGeomSearchTracker;
109  es.get<TrackerRecoGeometryRecord>().get(misAligned, theGeomSearchTracker );
110 
111  // Initialize the misaligned tracker interaction geometry
112  edm::ESHandle<TrackerInteractionGeometry> theTrackerInteractionGeometry;
113  es.get<TrackerInteractionGeometryRecord>().get(misAligned, theTrackerInteractionGeometry );
114 
115  // Initialize the magnetic field
116  double bField000 = 0.;
117  if (m_pUseMagneticField) {
118  edm::ESHandle<MagneticFieldMap> theMagneticFieldMap;
119  es.get<MagneticFieldMapRecord>().get(misAligned, theMagneticFieldMap);
120  const GlobalPoint g(0.,0.,0.);
121  bField000 = theMagneticFieldMap->inTeslaZ(g);
122  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
123  &(*theTrackerInteractionGeometry),
124  &(*theMagneticFieldMap));
125  } else {
126  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
127  &(*theTrackerInteractionGeometry),
128  0);
129  bField000 = 4.0;
130  }
131  // The following should be on LogInfo
132  //std::cout << "B-field(T) at (0,0,0)(cm): " << bField000 << std::endl;
133 
134  // Initialize the calorimeter geometry
135  if ( myCalorimetry ) {
137  es.get<CaloGeometryRecord>().get(pG);
139 
140  edm::ESHandle<CaloTopology> theCaloTopology;
141  es.get<CaloTopologyRecord>().get(theCaloTopology);
142  myCalorimetry->getCalorimeter()->setupTopology(*theCaloTopology);
143  myCalorimetry->getCalorimeter()->initialize(bField000);
144  }
145 
146  m_pRunNumber = run.run();
147 
148 }
149 
150 
151 void
152 FamosManager::reconstruct(const HepMC::GenEvent* evt,
153  const reco::GenParticleCollection* particles,
154  const HepMC::GenEvent* pu,
155  const TrackerTopology *tTopo,
157 {
158  // myGenEvent = evt;
159 
160  if (evt != 0 || particles != 0) {
161  iEvent++;
163 
164 
165  // Fill the event from the original generated event
166  if (evt )
167  mySimEvent->fill(*evt,id);
168 
169  else
170  mySimEvent->fill(*particles,id);
171 
172  // mySimEvent->printMCTruth(*evt);
173  /*
174  mySimEvent->print();
175  std::cout << "----------------------------------------" << std::endl;
176  */
177 
178  // Get the pileup events and add the particles to the main event
180  /*
181  mySimEvent->print();
182  std::cout << "----------------------------------------" << std::endl;
183  */
184 
185  // And propagate the particles through the detector
186  myTrajectoryManager->reconstruct(tTopo, random);
187  /*
188  mySimEvent->print();
189  std::cout << "========================================="
190  << std::endl
191  << std::endl;
192  */
193 
194  if ( myCalorimetry ) myCalorimetry->reconstruct(random);
195  }
196 
197  // Should be moved to LogInfo
198  edm::LogInfo("FamosManager") << " saved : Event " << iEvent
199  << " of weight " << mySimEvent->weight()
200  << " with " << mySimEvent->nTracks()
201  << " tracks and " << mySimEvent->nVertices()
202  << " vertices, generated by "
203  << mySimEvent->nGenParts() << " particles " << std::endl;
204 }
205 
207  iEvent++;
209  mySimEvent->fill(*particles, id);
210  myTrajectoryManager->reconstruct(tTopo, random);
211  if ( myCalorimetry ) myCalorimetry->reconstruct(random);
212 }
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:80
void initializeTrackerGeometry(const TrackerGeometry *geomTracker)
Initialize the full Tracker Geometry.
RunNumber_t run() const
Definition: RunBase.h:42
~FamosManager()
Destructor.
Definition: FamosManager.cc:81
FSimEvent * mySimEvent
Definition: FamosManager.h:73
bool m_Alignment
Definition: FamosManager.h:83
void setupTopology(const CaloTopology &)
Definition: Calorimeter.cc:127
void initializeRecoGeometry(const GeometricSearchTracker *geomSearchTracker, const TrackerInteractionGeometry *interactionGeometry, const MagneticFieldMap *aFieldMap)
Initialize the Reconstruction Geometry.
void fill(const HepMC::GenEvent &hev, edm::EventID &Id)
fill the FBaseSimEvent from the current HepMC::GenEvent
Definition: FSimEvent.cc:20
CaloGeometryHelper * getCalorimeter() const
TRandom random
Definition: MVATrainer.cc:138
TrajectoryManager * myTrajectoryManager
Definition: FamosManager.h:74
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:78
int iEvent
Definition: GenABIO.cc:230
void reconstruct(RandomEngineAndDistribution const *)
CalorimetryManager * myCalorimetry
Definition: FamosManager.h:76
FamosManager(edm::ParameterSet const &p)
Constructor.
Definition: FamosManager.cc:46
bool m_Calorimetry
Definition: FamosManager.h:82
unsigned int nTracks() const
Number of tracks.
Definition: FSimEvent.cc:42
void setupGeometry(const CaloGeometry &pG)
Definition: Calorimeter.cc:117
unsigned int nGenParts() const
Number of MC particles.
Definition: FSimEvent.cc:52
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.
const T & get() const
Definition: EventSetup.h:55
unsigned int nVertices() const
Number of vertices.
Definition: FSimEvent.cc:47
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:37
void initializePdt(const HepPDT::ParticleDataTable *aPdt)
Initialize the particle data table.
PileUpSimulator * myPileUpSimulator
Definition: FamosManager.h:75
void initialize(double bField)
void setupGeometryAndField(edm::Run const &run, const edm::EventSetup &es)
Get information from the Event Setup.
Definition: FamosManager.cc:90
Definition: Run.h:41