Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:40

0001 #include "SimMuon/CSCDigitizer/src/CSCDigiProducer.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 
0005 #include "SimMuon/CSCDigitizer/src/CSCConfigurableStripConditions.h"
0006 #include "SimMuon/CSCDigitizer/src/CSCDbStripConditions.h"
0007 
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0016 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0017 
0018 #include <string>
0019 
0020 CSCDigiProducer::CSCDigiProducer(const edm::ParameterSet &ps) : theDigitizer(ps), theStripConditions(nullptr) {
0021   geom_Token =
0022       esConsumes<CSCGeometry, MuonGeometryRecord>(edm::ESInputTag("", ps.getParameter<std::string>("GeometryType")));
0023   magfield_Token = esConsumes<MagneticField, IdealMagneticFieldRecord>();
0024   pdt_Token = esConsumes<ParticleDataTable, edm::DefaultRecord>();
0025   produces<CSCWireDigiCollection>("MuonCSCWireDigi");
0026   produces<CSCStripDigiCollection>("MuonCSCStripDigi");
0027   produces<CSCComparatorDigiCollection>("MuonCSCComparatorDigi");
0028   produces<DigiSimLinks>("MuonCSCWireDigiSimLinks");
0029   produces<DigiSimLinks>("MuonCSCStripDigiSimLinks");
0030   std::string stripConditions(ps.getParameter<std::string>("stripConditions"));
0031 
0032   edm::ParameterSet stripPSet = ps.getParameter<edm::ParameterSet>("strips");
0033   if (stripConditions == "Configurable") {
0034     theStripConditions = new CSCConfigurableStripConditions(stripPSet);
0035   } else if (stripConditions == "Database") {
0036     theStripConditions = new CSCDbStripConditions(stripPSet, consumesCollector());
0037   } else {
0038     throw cms::Exception("CSCDigiProducer") << "Bad option for strip conditions: " << stripConditions;
0039   }
0040   theDigitizer.setStripConditions(theStripConditions);
0041 
0042   edm::Service<edm::RandomNumberGenerator> rng;
0043   if (!rng.isAvailable()) {
0044     throw cms::Exception("Configuration") << "CSCDigitizer requires the RandomNumberGeneratorService\n"
0045                                              "which is not present in the configuration file.  You must add the "
0046                                              "service\n"
0047                                              "in the configuration file or remove the modules that require it.";
0048   }
0049 
0050   std::string mix_ = ps.getParameter<std::string>("mixLabel");
0051   std::string collection_ = ps.getParameter<std::string>("InputCollection");
0052   cf_token = consumes<CrossingFrame<PSimHit>>(edm::InputTag(mix_, collection_));
0053 }
0054 
0055 CSCDigiProducer::~CSCDigiProducer() { delete theStripConditions; }
0056 
0057 void CSCDigiProducer::produce(edm::Event &ev, const edm::EventSetup &eventSetup) {
0058   edm::LogVerbatim("CSCDigitizer") << "[CSCDigiProducer::produce] starting event " << ev.id().event() << " of run "
0059                                    << ev.id().run();
0060   edm::Service<edm::RandomNumberGenerator> rng;
0061   CLHEP::HepRandomEngine *engine = &rng->getEngine(ev.streamID());
0062 
0063   edm::Handle<CrossingFrame<PSimHit>> cf;
0064   ev.getByToken(cf_token, cf);
0065 
0066   std::unique_ptr<MixCollection<PSimHit>> hits(new MixCollection<PSimHit>(cf.product()));
0067 
0068   // Create empty output
0069 
0070   std::unique_ptr<CSCWireDigiCollection> pWireDigis(new CSCWireDigiCollection());
0071   std::unique_ptr<CSCStripDigiCollection> pStripDigis(new CSCStripDigiCollection());
0072   std::unique_ptr<CSCComparatorDigiCollection> pComparatorDigis(new CSCComparatorDigiCollection());
0073   std::unique_ptr<DigiSimLinks> pWireDigiSimLinks(new DigiSimLinks());
0074   std::unique_ptr<DigiSimLinks> pStripDigiSimLinks(new DigiSimLinks());
0075 
0076   //@@ DOES NOTHING IF NO HITS.  Remove this for when there's real neutrons
0077   if (hits->size() > 0) {
0078     // find the geometry & conditions for this event
0079     edm::ESHandle<CSCGeometry> hGeom = eventSetup.getHandle(geom_Token);
0080     const CSCGeometry *pGeom = &*hGeom;
0081 
0082     theDigitizer.setGeometry(pGeom);
0083 
0084     // find the magnetic field
0085     edm::ESHandle<MagneticField> magfield = eventSetup.getHandle(magfield_Token);
0086 
0087     theDigitizer.setMagneticField(&*magfield);
0088 
0089     // set the particle table
0090     edm::ESHandle<ParticleDataTable> pdt = eventSetup.getHandle(pdt_Token);
0091     theDigitizer.setParticleDataTable(&*pdt);
0092 
0093     theStripConditions->initializeEvent(eventSetup);
0094 
0095     // run the digitizer
0096     theDigitizer.doAction(
0097         *hits, *pWireDigis, *pStripDigis, *pComparatorDigis, *pWireDigiSimLinks, *pStripDigiSimLinks, engine);
0098   }
0099 
0100   // store them in the event
0101   ev.put(std::move(pWireDigis), "MuonCSCWireDigi");
0102   ev.put(std::move(pStripDigis), "MuonCSCStripDigi");
0103   ev.put(std::move(pComparatorDigis), "MuonCSCComparatorDigi");
0104   ev.put(std::move(pWireDigiSimLinks), "MuonCSCWireDigiSimLinks");
0105   ev.put(std::move(pStripDigiSimLinks), "MuonCSCStripDigiSimLinks");
0106 }