Go to the documentation of this file.00001
00002 #include "FWCore/Framework/interface/EventSetup.h"
00003 #include "FWCore/Framework/interface/Run.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "DataFormats/Provenance/interface/EventID.h"
00011
00012 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00013
00014 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00015
00016
00017
00018 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00019 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00020 #include "FastSimulation/TrackerSetup/interface/TrackerInteractionGeometryRecord.h"
00021 #include "FastSimulation/ParticlePropagator/interface/MagneticFieldMapRecord.h"
00022
00023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00024 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00025 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00026
00027
00028
00029
00030
00031
00032 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00033 #include "FastSimulation/EventProducer/interface/FamosManager.h"
00034 #include "FastSimulation/TrajectoryManager/interface/TrajectoryManager.h"
00035 #include "FastSimulation/PileUpProducer/interface/PileUpSimulator.h"
00036 #include "FastSimulation/Event/interface/FSimEvent.h"
00037 #include "FastSimulation/ParticlePropagator/interface/MagneticFieldMap.h"
00038 #include "FastSimulation/Particle/interface/ParticleTable.h"
00039 #include "FastSimulation/Calorimetry/interface/CalorimetryManager.h"
00040 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00041 #include <iostream>
00042 #include <memory>
00043 #include <vector>
00044
00045 using namespace HepMC;
00046
00047 FamosManager::FamosManager(edm::ParameterSet const & p)
00048 : iEvent(0),
00049 myPileUpSimulator(0),
00050 myCalorimetry(0),
00051 m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
00052 m_Tracking(p.getParameter<bool>("SimulateTracking")),
00053 m_Calorimetry(p.getParameter<bool>("SimulateCalorimetry")),
00054 m_Alignment(p.getParameter<bool>("ApplyAlignment")),
00055 m_pRunNumber(p.getUntrackedParameter<int>("RunNumber",1)),
00056 m_pVerbose(p.getUntrackedParameter<int>("Verbosity",1))
00057 {
00058
00059
00060 edm::Service<edm::RandomNumberGenerator> rng;
00061 if ( ! rng.isAvailable() ) {
00062 throw cms::Exception("Configuration")
00063 << "FamosManager requires the RandomGeneratorService\n"
00064 "which is not present in the configuration file.\n"
00065 "You must add the service in the configuration file\n"
00066 "or remove the module that requires it";
00067 }
00068
00069 random = new RandomEngine(&(*rng));
00070
00071
00072 mySimEvent =
00073 new FSimEvent(p.getParameter<edm::ParameterSet>("VertexGenerator"),
00074 p.getParameter<edm::ParameterSet>("ParticleFilter"),
00075 random);
00076
00078 myTrajectoryManager =
00079 new TrajectoryManager(mySimEvent,
00080 p.getParameter<edm::ParameterSet>("MaterialEffects"),
00081 p.getParameter<edm::ParameterSet>("TrackerSimHits"),
00082 p.getParameter<edm::ParameterSet>("ActivateDecays"),
00083 random);
00084
00085
00086 myPileUpSimulator = new PileUpSimulator(mySimEvent);
00087
00088
00089 if ( m_Calorimetry)
00090 myCalorimetry =
00091 new CalorimetryManager(mySimEvent,
00092 p.getParameter<edm::ParameterSet>("Calorimetry"),
00093 p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInECAL"),
00094 p.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInHCAL"),
00095 p.getParameter<edm::ParameterSet>("GFlash"),
00096 random);
00097
00098 }
00099
00100 FamosManager::~FamosManager()
00101 {
00102 if ( mySimEvent ) delete mySimEvent;
00103 if ( myTrajectoryManager ) delete myTrajectoryManager;
00104 if ( myPileUpSimulator ) delete myPileUpSimulator;
00105 if ( myCalorimetry) delete myCalorimetry;
00106 delete random;
00107 }
00108
00109 void
00110 FamosManager::setupGeometryAndField(edm::Run & run, const edm::EventSetup & es)
00111 {
00112
00113 edm::ESHandle < HepPDT::ParticleDataTable > pdt;
00114 es.getData(pdt);
00115 mySimEvent->initializePdt(&(*pdt));
00116 ParticleTable::instance(&(*pdt));
00117
00118
00119
00120 std::string misAligned = m_Alignment ? "MisAligned" : "";
00121
00122
00123 edm::ESHandle<TrackerGeometry> tracker;
00124 es.get<TrackerDigiGeometryRecord>().get(misAligned,tracker);
00125 if (m_Tracking) myTrajectoryManager->initializeTrackerGeometry(&(*tracker));
00126
00127
00128
00129 edm::ESHandle<GeometricSearchTracker> theGeomSearchTracker;
00130 es.get<TrackerRecoGeometryRecord>().get(misAligned, theGeomSearchTracker );
00131
00132
00133 edm::ESHandle<TrackerInteractionGeometry> theTrackerInteractionGeometry;
00134 es.get<TrackerInteractionGeometryRecord>().get(misAligned, theTrackerInteractionGeometry );
00135
00136
00137 double bField000 = 0.;
00138 if (m_pUseMagneticField) {
00139 edm::ESHandle<MagneticFieldMap> theMagneticFieldMap;
00140 es.get<MagneticFieldMapRecord>().get(misAligned, theMagneticFieldMap);
00141 const GlobalPoint g(0.,0.,0.);
00142 bField000 = theMagneticFieldMap->inTeslaZ(g);
00143 myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
00144 &(*theTrackerInteractionGeometry),
00145 &(*theMagneticFieldMap));
00146 } else {
00147 myTrajectoryManager->initializeRecoGeometry(&(*theGeomSearchTracker),
00148 &(*theTrackerInteractionGeometry),
00149 0);
00150 bField000 = 4.0;
00151 }
00152
00153
00154
00155
00156 if ( myCalorimetry ) {
00157 edm::ESHandle<CaloGeometry> pG;
00158 es.get<CaloGeometryRecord>().get(pG);
00159 myCalorimetry->getCalorimeter()->setupGeometry(*pG);
00160
00161 edm::ESHandle<CaloTopology> theCaloTopology;
00162 es.get<CaloTopologyRecord>().get(theCaloTopology);
00163 myCalorimetry->getCalorimeter()->setupTopology(*theCaloTopology);
00164 myCalorimetry->getCalorimeter()->initialize(bField000);
00165 }
00166
00167 m_pRunNumber = run.run();
00168
00169 }
00170
00171
00172 void
00173 FamosManager::reconstruct(const HepMC::GenEvent* evt,
00174 const reco::GenParticleCollection* particles,
00175 const HepMC::GenEvent* pu)
00176 {
00177
00178
00179
00180 if (evt != 0 || particles != 0) {
00181 iEvent++;
00182 edm::EventID id(m_pRunNumber,1U,iEvent);
00183
00184
00185
00186 if (evt )
00187 mySimEvent->fill(*evt,id);
00188 else
00189 mySimEvent->fill(*particles,id);
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 myPileUpSimulator->produce(pu);
00200
00201
00202
00203
00204
00205
00206
00207 myTrajectoryManager->reconstruct();
00208
00209
00210
00211
00212
00213
00214
00215 if ( myCalorimetry ) myCalorimetry->reconstruct();
00216
00217 }
00218
00219
00220 edm::LogInfo("FamosManager") << " saved : Event " << iEvent
00221 << " of weight " << mySimEvent->weight()
00222 << " with " << mySimEvent->nTracks()
00223 << " tracks and " << mySimEvent->nVertices()
00224 << " vertices, generated by "
00225 << mySimEvent->nGenParts() << " particles " << std::endl;
00226
00227 }