Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-07 23:36:47

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", 5.);
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   desc.add<bool>("bx0filter", false);
0108 
0109   desc.add<double>("instLumi", 7.5);
0110   // 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
0111   desc.add<double>("rateFact", 1.0);
0112   // 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
0113   desc.add<double>("bxWidth", 25E-9);
0114   desc.add<double>("referenceInstLumi", 5.);
0115   // referecne inst. luminosity 5E+34 cm^-2s^-1
0116   desc.add<double>("resolutionX", 0.03);
0117 
0118   // The follwing parameters are needed to model the background contribution
0119   // The parameters have been obtained after the fit of th perdicted by FLUKA
0120   // By default the backgroundmodeling with these parameters should be disabled with
0121   // the 9_2_X release setting simulateBkgNoise = false
0122   desc.add<double>("GE11ModNeuBkgParam0", 5710.23);
0123   desc.add<double>("GE11ModNeuBkgParam1", -43.3928);
0124   desc.add<double>("GE11ModNeuBkgParam2", 0.0863681);
0125   desc.add<double>("GE21ModNeuBkgParam0", 1440.44);
0126   desc.add<double>("GE21ModNeuBkgParam1", -7.48607);
0127   desc.add<double>("GE21ModNeuBkgParam2", 0.0103078);
0128   desc.add<double>("GE11ElecBkgParam0", 406.249);
0129   desc.add<double>("GE11ElecBkgParam1", -2.90939);
0130   desc.add<double>("GE11ElecBkgParam2", 0.00548191);
0131   desc.add<double>("GE21ElecBkgParam0", 97.0505);
0132   desc.add<double>("GE21ElecBkgParam1", -43.3928);
0133   desc.add<double>("GE21ElecBkgParam2", 00.000550599);
0134 
0135   descriptions.add("simMuonGEMDigisDef", desc);
0136 }
0137 
0138 void GEMDigiProducer::beginRun(const edm::Run&, const edm::EventSetup& eventSetup) {
0139   edm::ESHandle<GEMGeometry> hGeom = eventSetup.getHandle(geom_token_);
0140   gemDigiModule_->setGeometry(&*hGeom);
0141   geometry_ = &*hGeom;
0142 }
0143 
0144 void GEMDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0145   edm::Service<edm::RandomNumberGenerator> rng;
0146   CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
0147 
0148   edm::Handle<CrossingFrame<PSimHit> > cf;
0149   e.getByToken(cf_token, cf);
0150 
0151   MixCollection<PSimHit> hits{cf.product()};
0152 
0153   // Create empty output
0154   auto digis = std::make_unique<GEMDigiCollection>();
0155   auto gemDigiSimLinks = std::make_unique<GEMDigiSimLinks>();
0156 
0157   // arrange the hits by eta partition
0158   std::map<uint32_t, edm::PSimHitContainer> hitMap;
0159   for (const auto& hit : hits) {
0160     hitMap[GEMDetId(hit.detUnitId()).rawId()].emplace_back(hit);
0161   }
0162 
0163   // simulate signal and noise for each eta partition
0164   const auto& etaPartitions(geometry_->etaPartitions());
0165 
0166   for (const auto& roll : etaPartitions) {
0167     const GEMDetId detId(roll->id());
0168     const uint32_t rawId(detId.rawId());
0169     const auto& simHits(hitMap[rawId]);
0170 
0171     LogDebug("GEMDigiProducer") << "GEMDigiProducer: found " << simHits.size() << " hit(s) in eta partition" << rawId;
0172 
0173     gemDigiModule_->simulate(roll, simHits, engine);
0174     gemDigiModule_->fillDigis(rawId, *digis);
0175     (*gemDigiSimLinks).insert(gemDigiModule_->gemDigiSimLinks());
0176   }
0177 
0178   // store them in the event
0179   e.put(std::move(digis));
0180   e.put(std::move(gemDigiSimLinks), "GEM");
0181 }
0182 
0183 DEFINE_FWK_MODULE(GEMDigiProducer);
0184 #endif