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
42 #include <iostream>
43 #include <memory>
44 #include <vector>
45 
46 using namespace HepMC;
47 
49  : iEvent(0),
50  myPileUpSimulator(0),
51  myCalorimetry(0),
52  m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
53  m_Tracking(p.getParameter<bool>("SimulateTracking")),
54  m_Calorimetry(p.getParameter<bool>("SimulateCalorimetry")),
55  m_Alignment(p.getParameter<bool>("ApplyAlignment")),
56  m_pRunNumber(p.getUntrackedParameter<int>("RunNumber",1)),
57  m_pVerbose(p.getUntrackedParameter<int>("Verbosity",1))
58 {
59 
60  // Initialize the random number generator service
62  if ( ! rng.isAvailable() ) {
63  throw cms::Exception("Configuration")
64  << "FamosManager requires the RandomGeneratorService\n"
65  "which is not present in the configuration file.\n"
66  "You must add the service in the configuration file\n"
67  "or remove the module that requires it";
68  }
69 
70  random = new RandomEngine(&(*rng));
71 
72  // Initialize the FSimEvent
73  mySimEvent =
74  new FSimEvent(p.getParameter<edm::ParameterSet>("VertexGenerator"),
75  p.getParameter<edm::ParameterSet>("ParticleFilter"),
76  random);
77 
81  p.getParameter<edm::ParameterSet>("MaterialEffects"),
82  p.getParameter<edm::ParameterSet>("TrackerSimHits"),
83  p.getParameter<edm::ParameterSet>("ActivateDecays"),
84  random);
85 
86  // Initialize PileUp Producer (if requested)
88 
89  // Initialize Calorimetry Fast Simulation (if requested)
90  if ( m_Calorimetry)
91  myCalorimetry =
93  p.getParameter<edm::ParameterSet>("Calorimetry"),
94  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInECAL"),
95  p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInHCAL"),
96  p.getParameter<edm::ParameterSet>("GFlash"),
97  random);
98 
99 }
100 
102 {
103  if ( mySimEvent ) delete mySimEvent;
105  if ( myPileUpSimulator ) delete myPileUpSimulator;
106  if ( myCalorimetry) delete myCalorimetry;
107  delete random;
108 }
109 
110 void
112 {
113  // Particle data table (from Pythia)
115  es.getData(pdt);
116  mySimEvent->initializePdt(&(*pdt));
117  ParticleTable::instance(&(*pdt));
118 
119  // Initialize the full (misaligned) tracker geometry
120  // (only if tracking is requested)
121  std::string misAligned = m_Alignment ? "MisAligned" : "";
122  // 1) By default, the aligned geometry is chosen (m_Alignment = false)
123  // 2) By default, the misaligned geometry is aligned
125  es.get<TrackerDigiGeometryRecord>().get(misAligned,tracker);
127 
128  // Initialize the tracker misaligned reco geometry (always needed)
129  // By default, the misaligned geometry is aligned
130  edm::ESHandle<GeometricSearchTracker> theGeomSearchTracker;
131  es.get<TrackerRecoGeometryRecord>().get(misAligned, theGeomSearchTracker );
132 
133  // Initialize the misaligned tracker interaction geometry
134  edm::ESHandle<TrackerInteractionGeometry> theTrackerInteractionGeometry;
135  es.get<TrackerInteractionGeometryRecord>().get(misAligned, theTrackerInteractionGeometry );
136 
137  // Initialize the magnetic field
138  double bField000 = 0.;
139  if (m_pUseMagneticField) {
140  edm::ESHandle<MagneticFieldMap> theMagneticFieldMap;
141  es.get<MagneticFieldMapRecord>().get(misAligned, theMagneticFieldMap);
142  const GlobalPoint g(0.,0.,0.);
143  bField000 = theMagneticFieldMap->inTeslaZ(g);
144  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
145  &(*theTrackerInteractionGeometry),
146  &(*theMagneticFieldMap));
147  } else {
148  myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
149  &(*theTrackerInteractionGeometry),
150  0);
151  bField000 = 4.0;
152  }
153  // The following should be on LogInfo
154  //std::cout << "B-field(T) at (0,0,0)(cm): " << bField000 << std::endl;
155 
156  // Initialize the calorimeter geometry
157  if ( myCalorimetry ) {
159  es.get<CaloGeometryRecord>().get(pG);
161 
162  edm::ESHandle<CaloTopology> theCaloTopology;
163  es.get<CaloTopologyRecord>().get(theCaloTopology);
164  myCalorimetry->getCalorimeter()->setupTopology(*theCaloTopology);
165  myCalorimetry->getCalorimeter()->initialize(bField000);
166  }
167 
168  m_pRunNumber = run.run();
169 
170 }
171 
172 
173 void
174 FamosManager::reconstruct(const HepMC::GenEvent* evt,
175  const reco::GenParticleCollection* particles,
176  const HepMC::GenEvent* pu)
177 {
178 
179  // myGenEvent = evt;
180 
181  if (evt != 0 || particles != 0) {
182  iEvent++;
184 
185 
186  // Fill the event from the original generated event
187  if (evt )
188  mySimEvent->fill(*evt,id);
189 
190  else
191  mySimEvent->fill(*particles,id);
192 
193  // mySimEvent->printMCTruth(*evt);
194  /*
195  mySimEvent->print();
196  std::cout << "----------------------------------------" << std::endl;
197  */
198 
199  // Get the pileup events and add the particles to the main event
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 }
228 
230  iEvent++;
232  mySimEvent->fill(*particles,id);
235 
236 
237 
238 }
239 
240 
241 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
bool m_pUseMagneticField
Definition: FamosManager.h:74
void initializeTrackerGeometry(const TrackerGeometry *geomTracker)
Initialize the full Tracker Geometry.
RunNumber_t run() const
Definition: RunBase.h:42
void setupGeometryAndField(edm::Run &run, const edm::EventSetup &es)
Get information from the Event Setup.
~FamosManager()
Destructor.
FSimEvent * mySimEvent
Definition: FamosManager.h:67
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:77
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:68
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:70
bool isAvailable() const
Definition: Service.h:47
FamosManager(edm::ParameterSet const &p)
Constructor.
Definition: FamosManager.cc:48
bool m_Calorimetry
Definition: FamosManager.h:76
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:69
void initialize(double bField)
Definition: Run.h:33
const RandomEngine * random
Definition: FamosManager.h:84