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
11 
13 
15 
16 //#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
17 //#include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
22 
26 //#include "Geometry/CaloTopology/interface/CaloTopology.h"
27 
28 // HepMC headers
29 //#include "HepMC/GenEvent.h"
30 
31 // FAMOS Header
41 #include <iostream>
42 #include <memory>
43 #include <vector>
44 
45 using namespace HepMC;
46 
48  : iEvent(0),
49  myPileUpSimulator(0),
50  myCalorimetry(0),
51  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
52  m_Tracking(p.getParameter<bool>("SimulateTracking")),
53  m_Calorimetry(p.getParameter<bool>("SimulateCalorimetry")),
54  m_Alignment(p.getParameter<bool>("ApplyAlignment")),
55  m_pRunNumber(p.getUntrackedParameter<int>("RunNumber",1)),
56  m_pVerbose(p.getUntrackedParameter<int>("Verbosity",1))
57 {
58 
59  // Initialize the random number generator service
61  if ( ! rng.isAvailable() ) {
62  throw cms::Exception("Configuration")
63  << "FamosManager requires the RandomGeneratorService\n"
64  "which is not present in the configuration file.\n"
65  "You must add the service in the configuration file\n"
66  "or remove the module that requires it";
67  }
68 
69  random = new RandomEngine(&(*rng));
70 
71  // Initialize the FSimEvent
72  mySimEvent =
73  new FSimEvent(p.getParameter<edm::ParameterSet>("VertexGenerator"),
74  p.getParameter<edm::ParameterSet>("ParticleFilter"),
75  random);
76 
80  p.getParameter<edm::ParameterSet>("MaterialEffects"),
81  p.getParameter<edm::ParameterSet>("TrackerSimHits"),
82  p.getParameter<edm::ParameterSet>("ActivateDecays"),
83  random);
84 
85  // Initialize PileUp Producer (if requested)
87 
88  // Initialize Calorimetry Fast Simulation (if requested)
89  if ( m_Calorimetry)
90  myCalorimetry =
92  p.getParameter<edm::ParameterSet>("Calorimetry"),
93  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInECAL"),
94  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInHCAL"),
95  p.getParameter<edm::ParameterSet>("GFlash"),
96  random);
97 
98 }
99 
101 {
102  if ( mySimEvent ) delete mySimEvent;
104  if ( myPileUpSimulator ) delete myPileUpSimulator;
105  if ( myCalorimetry) delete myCalorimetry;
106  delete random;
107 }
108 
109 void
111 {
112  // Particle data table (from Pythia)
114  es.getData(pdt);
115  mySimEvent->initializePdt(&(*pdt));
116  ParticleTable::instance(&(*pdt));
117 
118  // Initialize the full (misaligned) tracker geometry
119  // (only if tracking is requested)
120  std::string misAligned = m_Alignment ? "MisAligned" : "";
121  // 1) By default, the aligned geometry is chosen (m_Alignment = false)
122  // 2) By default, the misaligned geometry is aligned
124  es.get<TrackerDigiGeometryRecord>().get(misAligned,tracker);
126 
127  // Initialize the tracker misaligned reco geometry (always needed)
128  // By default, the misaligned geometry is aligned
129  edm::ESHandle<GeometricSearchTracker> theGeomSearchTracker;
130  es.get<TrackerRecoGeometryRecord>().get(misAligned, theGeomSearchTracker );
131 
132  // Initialize the misaligned tracker interaction geometry
133  edm::ESHandle<TrackerInteractionGeometry> theTrackerInteractionGeometry;
134  es.get<TrackerInteractionGeometryRecord>().get(misAligned, theTrackerInteractionGeometry );
135 
136  // Initialize the magnetic field
137  double bField000 = 0.;
138  if (m_pUseMagneticField) {
139  edm::ESHandle<MagneticFieldMap> theMagneticFieldMap;
140  es.get<MagneticFieldMapRecord>().get(misAligned, theMagneticFieldMap);
141  const GlobalPoint g(0.,0.,0.);
142  bField000 = theMagneticFieldMap->inTeslaZ(g);
143  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
144  &(*theTrackerInteractionGeometry),
145  &(*theMagneticFieldMap));
146  } else {
147  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
148  &(*theTrackerInteractionGeometry),
149  0);
150  bField000 = 4.0;
151  }
152  // The following should be on LogInfo
153  //std::cout << "B-field(T) at (0,0,0)(cm): " << bField000 << std::endl;
154 
155  // Initialize the calorimeter geometry
156  if ( myCalorimetry ) {
158  es.get<CaloGeometryRecord>().get(pG);
160 
161  edm::ESHandle<CaloTopology> theCaloTopology;
162  es.get<CaloTopologyRecord>().get(theCaloTopology);
163  myCalorimetry->getCalorimeter()->setupTopology(*theCaloTopology);
164  myCalorimetry->getCalorimeter()->initialize(bField000);
165  }
166 
167  m_pRunNumber = run.run();
168 
169 }
170 
171 
172 void
173 FamosManager::reconstruct(const HepMC::GenEvent* evt,
174  const reco::GenParticleCollection* particles,
175  const HepMC::GenEvent* pu)
176 {
177 
178  // myGenEvent = evt;
179 
180  if (evt != 0 || particles != 0) {
181  iEvent++;
183 
184 
185  // Fill the event from the original generated event
186  if (evt )
187  mySimEvent->fill(*evt,id);
188  else
189  mySimEvent->fill(*particles,id);
190 
191 
192  // mySimEvent->printMCTruth(*evt);
193  /*
194  mySimEvent->print();
195  std::cout << "----------------------------------------" << std::endl;
196  */
197 
198  // Get the pileup events and add the particles to the main event
200 
201  /*
202  mySimEvent->print();
203  std::cout << "----------------------------------------" << std::endl;
204  */
205 
206  // And propagate the particles through the detector
208  /*
209  mySimEvent->print();
210  std::cout << "========================================="
211  << std::endl
212  << std::endl;
213  */
214 
216 
217  }
218 
219 // Should be moved to LogInfo
220  edm::LogInfo("FamosManager") << " saved : Event " << iEvent
221  << " of weight " << mySimEvent->weight()
222  << " with " << mySimEvent->nTracks()
223  << " tracks and " << mySimEvent->nVertices()
224  << " vertices, generated by "
225  << mySimEvent->nGenParts() << " particles " << std::endl;
226 
227 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
bool m_pUseMagneticField
Definition: FamosManager.h:71
void initializeTrackerGeometry(const TrackerGeometry *geomTracker)
Initialize the full Tracker Geometry.
RunNumber_t run() const
Definition: RunBase.h:44
void setupGeometryAndField(edm::Run &run, const edm::EventSetup &es)
Get information from the Event Setup.
~FamosManager()
Destructor.
FSimEvent * mySimEvent
Definition: FamosManager.h:64
void reconstruct(const HepMC::GenEvent *evt, const reco::GenParticleCollection *particles, const HepMC::GenEvent *pu)
The real thing is done here.
bool m_Alignment
Definition: FamosManager.h:74
void setupTopology(const CaloTopology &)
Definition: Calorimeter.cc:125
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:26
CaloGeometryHelper * getCalorimeter() const
TrajectoryManager * myTrajectoryManager
Definition: FamosManager.h:65
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()
Does the real job.
CalorimetryManager * myCalorimetry
Definition: FamosManager.h:67
bool isAvailable() const
Definition: Service.h:47
FamosManager(edm::ParameterSet const &p)
Constructor.
Definition: FamosManager.cc:47
bool m_Calorimetry
Definition: FamosManager.h:73
unsigned int nTracks() const
Number of tracks.
Definition: FSimEvent.cc:48
void setupGeometry(const CaloGeometry &pG)
Definition: Calorimeter.cc:115
unsigned int nGenParts() const
Number of MC particles.
Definition: FSimEvent.cc:58
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:53
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:43
void initializePdt(const HepPDT::ParticleDataTable *aPdt)
Initialize the particle data table.
PileUpSimulator * myPileUpSimulator
Definition: FamosManager.h:66
void initialize(double bField)
Definition: Run.h:32
const RandomEngine * random
Definition: FamosManager.h:81