1 #ifndef SimMuon_GEMDigitizer_ME0ReDigiProducer_h
2 #define SimMuon_GEMDigitizer_ME0ReDigiProducer_h
30 #include "CLHEP/Random/RandGaussQ.h"
31 #include "CLHEP/Random/RandFlat.h"
32 #include "CLHEP/Units/PhysicalConstants.h"
68 std::vector<std::vector<double>>
tofs;
84 CLHEP::HepRandomEngine* engine);
101 typedef std::tuple<unsigned int, unsigned int, unsigned int>
DigiIndicies;
125 std::vector<std::vector<double>>
tofs;
129 const unsigned int numberOfStrips,
130 const unsigned int numberOfPartitions) {
135 <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - No ME0Chambers in geometry.";
136 const auto* mainChamber =
chambers.front();
140 <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - ME0Chamber has no layers.";
141 const auto* mainLayer = mainChamber->layers()[0];
142 if (!mainLayer->nEtaPartitions())
144 <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - ME0Layer has no partitions.";
145 if (mainLayer->nEtaPartitions() != 1)
146 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - This module is only "
147 "compatitble with geometries that contain only one partition per ME0Layer.";
149 const auto* mainPartition = mainLayer->etaPartitions()[0];
152 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - ME0 strip topology "
153 "must be of type TrapezoidalStripTopology. This module cannot be used";
155 for (
const auto& chamber : geometry->
chambers()) {
156 if (chamber->nLayers() != int(nLayers))
157 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all "
158 "ME0Chambers have the same number of layers. This module cannot be used.";
159 for (
unsigned int iL = 0; iL <
nLayers; ++iL) {
160 if (chamber->layers()[iL]->nEtaPartitions() != mainLayer->nEtaPartitions())
161 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all "
162 "ME0Layers have the same number of partitions. This module cannot be used.";
163 if (chamber->layers()[iL]->etaPartitions()[0]->specs()->parameters() != mainPartition->specs()->parameters())
164 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all ME0 ETA "
165 "partitions have the same properties. This module cannot be used.";
166 if (std::fabs(chamber->layers()[iL]->etaPartitions()[0]->position().z()) !=
167 std::fabs(mainChamber->layers()[iL]->etaPartitions()[0]->position().z()))
169 <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all ME0 ETA partitions in a single "
170 "layer have the same Z position. This module cannot be used.";
180 const auto globalTop = mainPartition->toGlobal(localTop);
181 const auto globalBottom = mainPartition->toGlobal(localBottom);
182 const double etaTop = globalTop.
eta();
183 const double etaBottom = globalBottom.eta();
184 const double zBottom = globalBottom.z();
189 const auto& mainPars = mainPartition->specs()->parameters();
191 const double eta = (etaTop - etaBottom) *
double(iP + 1) / double(numberOfPartitions) + etaBottom;
192 const double distFromBeam = std::fabs(zBottom / std::sinh(eta));
194 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry") <<
"Top of new partition: " <<
partitionTops.back() << std::endl;
196 std::vector<float>
params(4, 0);
199 auto getWidth = [&](
float locY) ->
float {
200 return (mainPars[2] * (mainPars[1] + mainPars[0]) + locY * (mainPars[1] - mainPars[0])) / (2 * mainPars[2]);
203 params[0] = iP == 0 ? mainPars[0] : getWidth(
partitionTops[iP - 1]);
205 iP + 1 == numberOfPartitions ? mainPars[1] : getWidth(
partitionTops[iP]);
206 params[2] = ((iP + 1 == numberOfPartitions ? localTop.y() :
partitionTops[iP]) -
215 tofs.resize(nLayers);
216 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry") <<
"TOF numbers [layer][partition]: ";
217 for (
unsigned int iL = 0; iL <
nLayers; ++iL) {
218 tofs[iL].resize(numberOfPartitions);
221 const GlobalPoint centralGP(mainChamber->layers()[iL]->etaPartitions()[0]->toGlobal(partCenter));
222 tofs[iL][iP] = (centralGP.mag() / (CLHEP::c_light / CLHEP::cm));
223 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry")
224 <<
"[" << iL <<
"][" << iP <<
"]=" << tofs[iL][iP] <<
" " << std::endl;
230 unsigned int etaPart = stripTopos.size() - 1;
231 for (
unsigned int iP = 0; iP < stripTopos.size(); ++iP) {
232 if (locY < partitionTops[iP]) {
241 return stripTopos[
partIdx]->radius() - middleDistanceFromBeam;
245 for (
auto*
p : stripTopos) {
254 float r0 = h * (B +
b) / (B - b);
255 float striplength = h * 2;
257 float pitch = (b +
B) / strips;
258 int nstrip =
static_cast<int>(
strips);
260 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry")
261 <<
"New partition parameters: "
262 <<
"bottom width(" << 2 * b <<
") top width(" << 2 * B <<
") height(" << 2 * h <<
") radius to center(" << r0
263 <<
") nStrips(" << strips <<
") pitch(" << pitch <<
")" << std::endl;
271 usePads(ps.getParameter<bool>(
"usePads")),
279 mergeDigis(ps.getParameter<bool>(
"mergeDigis")),
282 produces<ME0DigiPreRecoCollection>();
283 produces<ME0DigiPreRecoMap>();
286 if (!rng.isAvailable()) {
288 <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - RandomNumberGeneratorService is not present in configuration "
290 <<
"Add the service in the configuration file or remove the modules that require it.";
301 <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - Must have at least one strip if using custom geometry.";
304 <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - Must have at least one partition if using custom geometry.";
308 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - neutronAcceptance must be >= 0.";
323 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::beginRun() - No ME0Chambers in geometry.";
327 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::beginRun() - No layers in ME0 geometry.";
329 const unsigned int nPartitions =
chambers.front()->layers()[0]->nEtaPartitions();
338 <<
"ME0ReDigiProducer::beginRun() - The geometry has " << nLayers <<
" layers, but the readout of "
339 <<
layerReadout.size() <<
" were specified with the layerReadout parameter.";
342 LogDebug(
"ME0ReDigiProducer") <<
"Building temporary geometry:" << std::endl;
344 LogDebug(
"ME0ReDigiProducer") <<
"Done building temporary geometry!" << std::endl;
348 <<
"ME0ReDigiProducer::beginRun() - The geometry has " <<
tempGeo->
numLayers()
349 <<
" layers, but the readout of " <<
layerReadout.size()
350 <<
" were specified with the layerReadout parameter.";
375 CLHEP::HepRandomEngine* engine) {
390 LogDebug(
"ME0ReDigiProducer::buildDigis") <<
"Begin building digis." << std::endl;
392 for (me0dgIt = input_digis.begin(); me0dgIt != input_digis.end(); ++me0dgIt) {
393 const auto& me0Id = (*me0dgIt).first;
394 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"Starting with roll: " << me0Id << std::endl;
402 LogTrace(
"ME0ReDigiProducer::buildDigis") << std::endl
403 <<
"(" << digi->x() <<
"," << digi->y() <<
"," << digi->tof() <<
","
404 << digi->pdgid() <<
"," << digi->prompt() <<
")-> ";
423 int mapPartIDX = me0Id.roll() - 1;
434 const int bxIdx = std::round(tof /
bxWidth);
435 LogTrace(
"ME0ReDigiProducer::buildDigis") << tof <<
"(" << bxIdx <<
") ";
447 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"(" << bxIdx <<
"," << mapPartIDX <<
"," << strip <<
") ";
449 int matchIDX =
fillDigiMap(chDigiMap, bxIdx, mapPartIDX, strip, newDigiIdx);
459 const float corrCoef = digiLocalError.
xy() / (sigmaX *
sigmaY);
463 digiLocalPoint.
x(), digiLocalPoint.
y(),
sigmaX,
sigmaY, corrCoef, tof, digi->pdgid(), digi->prompt());
464 output_digis.insertDigi(me0Id, out_digi);
470 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"(" << digiLocalPoint.
x() <<
"," << digiLocalPoint.
y() <<
","
471 << sigmaX <<
"," << sigmaY <<
"," << tof <<
") ";
480 const unsigned int nLayers = mainChamber->nLayers();
483 tofs.resize(nLayers);
484 LogDebug(
"ME0ReDigiProducer::fillCentralTOFs()") <<
"TOF numbers [layer][partition]: ";
485 for (
unsigned int iL = 0; iL <
nLayers; ++iL) {
486 const auto*
layer = mainChamber->layers()[iL];
487 const unsigned int mapLayIDX =
layer->id().layer() - 1;
488 const unsigned int nPartitions =
layer->nEtaPartitions();
490 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::fillCentralTOFs() - ME0Layer has no partitions.";
491 tofs[mapLayIDX].resize(nPartitions);
492 for (
unsigned int iP = 0; iP < nPartitions; ++iP) {
493 const unsigned int mapPartIDX =
layer->etaPartitions()[iP]->id().roll() - 1;
495 tofs[mapLayIDX][mapPartIDX] = (centralGP.mag() / (CLHEP::c_light / CLHEP::cm));
496 LogDebug(
"ME0ReDigiProducer::fillCentralTOFs()")
497 <<
"[" << mapLayIDX <<
"][" << mapPartIDX <<
"]=" << tofs[mapLayIDX][mapPartIDX] <<
" " << std::endl;
508 LogTrace(
"ME0ReDigiProducer::buildDigis") << partIdx <<
" ";
519 const LocalPoint partLocalPoint(inDigi->
x(), inDigi->
y() - partCenter, 0.);
520 strip = topo->channel(partLocalPoint);
521 const float stripF = float(strip) + 0.5;
524 LocalPoint digiPartLocalPoint = topo->localPosition(stripF);
525 digiLocalError = topo->localError(
530 digiLocalPoint =
LocalPoint(digiPartLocalPoint.
x(), digiPartLocalPoint.
y() + partCenter, 0.0);
548 const LocalPoint partLocalPoint(inDigi->
x(), inDigi->
y(), 0.);
549 strip = topo.channel(partLocalPoint);
550 const float stripF = float(strip) + 0.5;
553 digiLocalPoint = topo.localPosition(stripF);
554 digiLocalError = topo.localError(stripF, 1. /
sqrt(12.));
560 auto it1 = chDigiMap.find(newIDX);
561 if (it1 == chDigiMap.end()) {
562 chDigiMap[newIDX] = currentIDX;
edm::ESGetToken< ME0Geometry, MuonGeometryRecord > geom_token_
std::vector< std::vector< double > > tofs
const StripTopology & specificTopology() const
static unsigned int partIdx(const InputGenJetsParticleSelector::ParticleVector &p, const reco::Candidate *particle)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
unsigned int numLayers() const
const ME0Geometry * geometry
Point3DBase< Scalar, LocalTag > LocalPoint
int getCustomStripProperties(const ME0DetId &detId, const ME0DigiPreReco *inDigi, float &tof, int &strip, LocalPoint &digiLocalPoint, LocalError &digiLocalError) const
float getCentralTOF(const ME0DetId &me0Id, unsigned int partIdx) const
int nstrips() const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
float middleDistanceFromBeam
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< ME0DigiPreRecoCollection > token
void buildDigis(const ME0DigiPreRecoCollection &, ME0DigiPreRecoCollection &, ME0DigiPreRecoMap &, CLHEP::HepRandomEngine *engine)
std::vector< int > layerReadout
~ME0ReDigiProducer() override
std::vector< float > partitionTops
void insertDigi(const IndexType &index, const DigiType &digi)
insert a digi for a given DetUnit
unsigned int fillDigiMap(ChamberDigiMap &chDigiMap, unsigned int bx, unsigned int part, unsigned int strip, unsigned int currentIDX) const
std::tuple< unsigned int, unsigned int, unsigned int > DigiIndicies
TemporaryGeometry(const ME0Geometry *geometry, const unsigned int numberOfStrips, const unsigned int numberOfPartitions)
const ME0EtaPartition * etaPartition(ME0DetId id) const
Return a etaPartition given its id.
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
constexpr std::array< uint8_t, layerIndexSize > layer
TrapezoidalStripTopology * buildTopo(const std::vector< float > &_p) const
const uint16_t range(const Frame &aFrame)
MuonDigiCollection< ME0DetId, ME0DigiPreReco > ME0DigiPreRecoCollection
tuple strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
const std::vector< const ME0Chamber * > & chambers() const
Return a vector of all ME0 chambers.
std::map< DigiIndicies, unsigned int > ChamberDigiMap
unsigned int findEtaPartition(float locY) const
float getPartCenter(const unsigned int partIdx) const
TemporaryGeometry * tempGeo
T const * product() const
unsigned int numberOfPartitions
bool useCusGeoFor1PartGeo
unsigned int numberOfStrips
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
MuonDigiCollection< ME0DetId, int > ME0DigiPreRecoMap
float pitch() const override
std::vector< TrapezoidalStripTopology * > stripTopos
ME0ReDigiProducer(const edm::ParameterSet &ps)
StreamID streamID() const
std::vector< std::vector< double > > tofs
int layer() const
Layer id: each chamber has six layers of chambers: layer 1 is the inner layer and layer 6 is the oute...
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
float stripLength() const override
det heigth (strip length in the middle)
static char chambers[264][20]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void produce(edm::Event &, const edm::EventSetup &) override
const TrapezoidalStripTopology * getTopo(const unsigned int partIdx) const
void getStripProperties(const ME0EtaPartition *etaPart, const ME0DigiPreReco *inDigi, float &tof, int &strip, LocalPoint &digiLocalPoint, LocalError &digiLocalError) const
void beginRun(const edm::Run &, const edm::EventSetup &) override
A container for a generic type of digis indexed by some index, implemented with a map<IndexType...