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 "DataFormats/Provenance/interface/EventID.h"
00010
00011 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00012
00013 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00014
00015
00016
00017 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00018 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00019 #include "FastSimulation/TrackerSetup/interface/TrackerInteractionGeometryRecord.h"
00020 #include "FastSimulation/ParticlePropagator/interface/MagneticFieldMapRecord.h"
00021
00022 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00023 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00024 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00025
00026
00027
00028
00029
00030
00031 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00032 #include "FastSimulation/EventProducer/interface/FamosManager.h"
00033 #include "FastSimulation/TrajectoryManager/interface/TrajectoryManager.h"
00034 #include "FastSimulation/PileUpProducer/interface/PileUpSimulator.h"
00035 #include "FastSimulation/Event/interface/FSimEvent.h"
00036 #include "FastSimulation/ParticlePropagator/interface/MagneticFieldMap.h"
00037 #include "FastSimulation/Particle/interface/ParticleTable.h"
00038 #include "FastSimulation/Calorimetry/interface/CalorimetryManager.h"
00039 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00040 #include <iostream>
00041 #include <memory>
00042 #include <vector>
00043
00044 using namespace HepMC;
00045
00046 FamosManager::FamosManager(edm::ParameterSet const & p)
00047 : iEvent(0),
00048 myPileUpSimulator(0),
00049 myCalorimetry(0),
00050 m_pUseMagneticField(p.getParameter<bool>("UseMagneticField")),
00051 m_Tracking(p.getParameter<bool>("SimulateTracking")),
00052 m_Calorimetry(p.getParameter<bool>("SimulateCalorimetry")),
00053 m_Alignment(p.getParameter<bool>("ApplyAlignment")),
00054 m_pRunNumber(p.getUntrackedParameter<int>("RunNumber",1)),
00055 m_pVerbose(p.getUntrackedParameter<int>("Verbosity",1))
00056 {
00057
00058 std::cout << " FamosManager initializing " << std::endl;
00059
00060
00061 edm::Service<edm::RandomNumberGenerator> rng;
00062 if ( ! rng.isAvailable() ) {
00063 throw cms::Exception("Configuration")
00064 << "FamosManager requires the RandomGeneratorService\n"
00065 "which is not present in the configuration file.\n"
00066 "You must add the service in the configuration file\n"
00067 "or remove the module that requires it";
00068 }
00069
00070 random = new RandomEngine(&(*rng));
00071
00072
00073 mySimEvent =
00074 new FSimEvent(p.getParameter<edm::ParameterSet>("VertexGenerator"),
00075 p.getParameter<edm::ParameterSet>("ParticleFilter"),
00076 random);
00077
00079 myTrajectoryManager =
00080 new TrajectoryManager(mySimEvent,
00081 p.getParameter<edm::ParameterSet>("MaterialEffects"),
00082 p.getParameter<edm::ParameterSet>("TrackerSimHits"),
00083 p.getParameter<edm::ParameterSet>("ActivateDecays"),
00084 random);
00085
00086
00087 myPileUpSimulator = new PileUpSimulator(mySimEvent);
00088
00089
00090 if ( m_Calorimetry)
00091 myCalorimetry =
00092 new CalorimetryManager(mySimEvent,
00093 p.getParameter<edm::ParameterSet>("Calorimetry"),
00094 random);
00095
00096 }
00097
00098 FamosManager::~FamosManager()
00099 {
00100 if ( mySimEvent ) delete mySimEvent;
00101 if ( myTrajectoryManager ) delete myTrajectoryManager;
00102 if ( myPileUpSimulator ) delete myPileUpSimulator;
00103 if ( myCalorimetry) delete myCalorimetry;
00104 delete random;
00105 }
00106
00107 void
00108 FamosManager::setupGeometryAndField(edm::Run & run, const edm::EventSetup & es)
00109 {
00110 std::cout << "FamosManager : setup geometry and field" << std::endl;
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 std::cout << "B-field(T) at (0,0,0)(cm): " << bField000 << std::endl;
00153
00154
00155 if ( myCalorimetry ) {
00156 edm::ESHandle<CaloGeometry> pG;
00157 es.get<CaloGeometryRecord>().get(pG);
00158 myCalorimetry->getCalorimeter()->setupGeometry(*pG);
00159
00160 edm::ESHandle<CaloTopology> theCaloTopology;
00161 es.get<CaloTopologyRecord>().get(theCaloTopology);
00162 myCalorimetry->getCalorimeter()->setupTopology(*theCaloTopology);
00163 myCalorimetry->getCalorimeter()->initialize(bField000);
00164 }
00165
00166 m_pRunNumber = run.run();
00167
00168 }
00169
00170
00171 void
00172 FamosManager::reconstruct(const HepMC::GenEvent* evt,
00173 const reco::GenParticleCollection* particles,
00174 const HepMC::GenEvent* pu)
00175 {
00176
00177
00178
00179 if (evt != 0 || particles != 0) {
00180 iEvent++;
00181 edm::EventID id(m_pRunNumber,iEvent);
00182
00183
00184
00185 if (evt )
00186 mySimEvent->fill(*evt,id);
00187 else
00188 mySimEvent->fill(*particles,id);
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 myPileUpSimulator->produce(pu);
00199
00200
00201
00202
00203
00204
00205
00206 myTrajectoryManager->reconstruct();
00207
00208
00209
00210
00211
00212
00213
00214 if ( myCalorimetry ) myCalorimetry->reconstruct();
00215
00216 }
00217
00218 std::cout << " saved : Event " << iEvent
00219 << " of weight " << mySimEvent->weight()
00220 << " with " << mySimEvent->nTracks()
00221 << " tracks and " << mySimEvent->nVertices()
00222 << " vertices, generated by "
00223 << mySimEvent->nGenParts() << " particles " << std::endl;
00224
00225 }