Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:45

0001 #ifndef SimMuon_GEMDigitizer_GEMDigiProducer_h
0002 #define SimMuon_GEMDigitizer_GEMDigiProducer_h
0003 
0004 #include "SimMuon/GEMDigitizer/interface/GEMDigiModule.h"
0005 
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Framework/interface/stream/EDProducer.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Utilities/interface/ESGetToken.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/ConsumesCollector.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 #include "DataFormats/Common/interface/Handle.h"
0019 #include "DataFormats/Common/interface/DetSetVector.h"
0020 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
0021 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0022 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0023 #include "SimDataFormats/GEMDigiSimLink/interface/GEMDigiSimLink.h"
0024 
0025 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0026 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0027 
0028 #include <sstream>
0029 #include <string>
0030 #include <map>
0031 #include <vector>
0032 
0033 namespace CLHEP {
0034   class HepRandomEngine;
0035 }
0036 
0037 class GEMDigiProducer : public edm::stream::EDProducer<> {
0038 public:
0039   typedef edm::DetSetVector<GEMDigiSimLink> GEMDigiSimLinks;
0040 
0041   explicit GEMDigiProducer(const edm::ParameterSet& ps);
0042 
0043   ~GEMDigiProducer() override;
0044 
0045   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0046 
0047   void produce(edm::Event&, const edm::EventSetup&) override;
0048 
0049   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050 
0051 private:
0052   //Name of Collection used for create the XF
0053   edm::EDGetTokenT<CrossingFrame<PSimHit> > cf_token;
0054   edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geom_token_;
0055 
0056   const GEMGeometry* geometry_;
0057 
0058   std::unique_ptr<GEMDigiModule> gemDigiModule_;
0059 };
0060 
0061 GEMDigiProducer::GEMDigiProducer(const edm::ParameterSet& ps) : gemDigiModule_(std::make_unique<GEMDigiModule>(ps)) {
0062   produces<GEMDigiCollection>();
0063   produces<GEMDigiSimLinks>("GEM");
0064 
0065   edm::Service<edm::RandomNumberGenerator> rng;
0066   if (!rng.isAvailable()) {
0067     throw cms::Exception("Configuration")
0068         << "GEMDigiProducer::GEMDigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n"
0069         << "Add the service in the configuration file or remove the modules that require it.";
0070   }
0071 
0072   std::string mix_(ps.getParameter<std::string>("mixLabel"));
0073   std::string collection_(ps.getParameter<std::string>("inputCollection"));
0074 
0075   cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_));
0076   geom_token_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
0077 }
0078 
0079 GEMDigiProducer::~GEMDigiProducer() = default;
0080 
0081 void GEMDigiProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0082   edm::ParameterSetDescription desc;
0083   desc.add<std::string>("inputCollection", "g4SimHitsMuonGEMHits");
0084   desc.add<std::string>("mixLabel", "mix");
0085 
0086   desc.add<double>("signalPropagationSpeed", 0.66);
0087   desc.add<double>("timeResolution", 18.);
0088   desc.add<double>("timeJitter", 1.0);
0089   desc.add<double>("averageShapingTime", 50.0);
0090   desc.add<double>("averageEfficiency", 0.98);
0091   desc.add<double>("averageNoiseRate", 0.001);
0092   // intrinsic noise rate (Hz/cm^2)
0093 
0094   // in terms of 25 ns
0095   desc.add<int>("minBunch", -5);
0096   desc.add<int>("maxBunch", 3);
0097 
0098   desc.add<bool>("fixedRollRadius", true);
0099   // Uses fixed radius in the center of the roll
0100   desc.add<bool>("digitizeOnlyMuons", false);
0101   desc.add<bool>("simulateBkgNoise", false);
0102   // false == No background simulation
0103   desc.add<bool>("simulateNoiseCLS", true);
0104   desc.add<bool>("simulateElectronBkg", true);
0105   // flase == simulate only neutral bkg
0106   desc.add<bool>("simulateIntrinsicNoise", false);
0107 
0108   desc.add<double>("instLumi", 7.5);
0109   // in units of 1E34 cm^-2 s^-1. Internally the background is parmetrized from FLUKA+GEANT result at 5E+34 (PU 140). We are adding a 1.5 factor for PU 200
0110   desc.add<double>("rateFact", 1.0);
0111   // We are adding also a safety factor of 2 to tak into account the new beam pipe effect (not yet known). Hits can be thrown away later at re-digi step. Parameters are kept in sync with the ones used in the GEM digitizer
0112   desc.add<double>("bxWidth", 25E-9);
0113   desc.add<double>("referenceInstLumi", 5.);
0114   // referecne inst. luminosity 5E+34 cm^-2s^-1
0115   desc.add<double>("resolutionX", 0.03);
0116 
0117   // The follwing parameters are needed to model the background contribution
0118   // The parameters have been obtained after the fit of th perdicted by FLUKA
0119   // By default the backgroundmodeling with these parameters should be disabled with
0120   // the 9_2_X release setting simulateBkgNoise = false
0121   desc.add<double>("GE11ModNeuBkgParam0", 5710.23);
0122   desc.add<double>("GE11ModNeuBkgParam1", -43.3928);
0123   desc.add<double>("GE11ModNeuBkgParam2", 0.0863681);
0124   desc.add<double>("GE21ModNeuBkgParam0", 1440.44);
0125   desc.add<double>("GE21ModNeuBkgParam1", -7.48607);
0126   desc.add<double>("GE21ModNeuBkgParam2", 0.0103078);
0127   desc.add<double>("GE11ElecBkgParam0", 406.249);
0128   desc.add<double>("GE11ElecBkgParam1", -2.90939);
0129   desc.add<double>("GE11ElecBkgParam2", 0.00548191);
0130   desc.add<double>("GE21ElecBkgParam0", 97.0505);
0131   desc.add<double>("GE21ElecBkgParam1", -43.3928);
0132   desc.add<double>("GE21ElecBkgParam2", 00.000550599);
0133 
0134   descriptions.add("simMuonGEMDigisDef", desc);
0135 }
0136 
0137 void GEMDigiProducer::beginRun(const edm::Run&, const edm::EventSetup& eventSetup) {
0138   edm::ESHandle<GEMGeometry> hGeom = eventSetup.getHandle(geom_token_);
0139   gemDigiModule_->setGeometry(&*hGeom);
0140   geometry_ = &*hGeom;
0141 }
0142 
0143 void GEMDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0144   edm::Service<edm::RandomNumberGenerator> rng;
0145   CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
0146 
0147   edm::Handle<CrossingFrame<PSimHit> > cf;
0148   e.getByToken(cf_token, cf);
0149 
0150   MixCollection<PSimHit> hits{cf.product()};
0151 
0152   // Create empty output
0153   auto digis = std::make_unique<GEMDigiCollection>();
0154   auto gemDigiSimLinks = std::make_unique<GEMDigiSimLinks>();
0155 
0156   // arrange the hits by eta partition
0157   std::map<uint32_t, edm::PSimHitContainer> hitMap;
0158   for (const auto& hit : hits) {
0159     hitMap[GEMDetId(hit.detUnitId()).rawId()].emplace_back(hit);
0160   }
0161 
0162   // simulate signal and noise for each eta partition
0163   const auto& etaPartitions(geometry_->etaPartitions());
0164 
0165   for (const auto& roll : etaPartitions) {
0166     const GEMDetId detId(roll->id());
0167     const uint32_t rawId(detId.rawId());
0168     const auto& simHits(hitMap[rawId]);
0169 
0170     LogDebug("GEMDigiProducer") << "GEMDigiProducer: found " << simHits.size() << " hit(s) in eta partition" << rawId;
0171 
0172     gemDigiModule_->simulate(roll, simHits, engine);
0173     gemDigiModule_->fillDigis(rawId, *digis);
0174     (*gemDigiSimLinks).insert(gemDigiModule_->gemDigiSimLinks());
0175   }
0176 
0177   // store them in the event
0178   e.put(std::move(digis));
0179   e.put(std::move(gemDigiSimLinks), "GEM");
0180 }
0181 
0182 DEFINE_FWK_MODULE(GEMDigiProducer);
0183 #endif