CMS 3D CMS Logo

FamosManager.cc

Go to the documentation of this file.
00001 // CMSSW Header
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 //#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00016 //#include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
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 //#include "Geometry/CaloTopology/interface/CaloTopology.h"
00026 
00027 // HepMC headers
00028 //#include "HepMC/GenEvent.h"
00029 
00030 // FAMOS Header
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   // Initialize the random number generator service
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   // Initialize the FSimEvent
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   // Initialize PileUp Producer (if requested)
00087   myPileUpSimulator = new PileUpSimulator(mySimEvent);
00088 
00089   // Initialize Calorimetry Fast Simulation (if requested)
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   // Particle data table (from Pythia)
00113   edm::ESHandle < HepPDT::ParticleDataTable > pdt;
00114   es.getData(pdt);
00115   mySimEvent->initializePdt(&(*pdt));
00116   ParticleTable::instance(&(*pdt));
00117 
00118   // Initialize the full (misaligned) tracker geometry 
00119   // (only if tracking is requested)
00120   std::string misAligned = m_Alignment ? "MisAligned" : "";
00121   // 1) By default, the aligned geometry is chosen (m_Alignment = false)
00122   // 2) By default, the misaligned geometry is aligned
00123   edm::ESHandle<TrackerGeometry> tracker;
00124   es.get<TrackerDigiGeometryRecord>().get(misAligned,tracker);
00125   if (m_Tracking)  myTrajectoryManager->initializeTrackerGeometry(&(*tracker)); 
00126 
00127   // Initialize the tracker misaligned reco geometry (always needed)
00128   // By default, the misaligned geometry is aligned
00129   edm::ESHandle<GeometricSearchTracker>       theGeomSearchTracker;
00130   es.get<TrackerRecoGeometryRecord>().get(misAligned, theGeomSearchTracker );
00131 
00132   // Initialize the misaligned tracker interaction geometry 
00133   edm::ESHandle<TrackerInteractionGeometry>  theTrackerInteractionGeometry;
00134   es.get<TrackerInteractionGeometryRecord>().get(misAligned, theTrackerInteractionGeometry );
00135 
00136   // Initialize the magnetic field
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   //  Initialize the calorimeter geometry
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   //  myGenEvent = evt;
00178 
00179   if (evt != 0 || particles != 0) {
00180     iEvent++;
00181     edm::EventID id(m_pRunNumber,iEvent);
00182 
00183 
00184     // Fill the event from the original generated event
00185     if (evt ) 
00186       mySimEvent->fill(*evt,id);
00187     else
00188       mySimEvent->fill(*particles,id);
00189 
00190 
00191     //    mySimEvent->printMCTruth(*evt);
00192     /*
00193     mySimEvent->print();
00194     std::cout << "----------------------------------------" << std::endl;
00195     */
00196 
00197     // Get the pileup events and add the particles to the main event
00198     myPileUpSimulator->produce(pu);
00199 
00200     /*
00201     mySimEvent->print();
00202     std::cout << "----------------------------------------" << std::endl;
00203     */
00204 
00205     // And propagate the particles through the detector
00206     myTrajectoryManager->reconstruct();
00207     /*
00208     mySimEvent->print();
00209     std::cout << "=========================================" 
00210               << std::endl
00211               << std::endl;
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 }

Generated on Tue Jun 9 17:35:08 2009 for CMSSW by  doxygen 1.5.4