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