14 #include "CLHEP/Random/RandGaussQ.h" 15 #include "CLHEP/Random/RandFlat.h" 16 #include "CLHEP/Units/PhysicalConstants.h" 28 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - No ME0Chambers in geometry.";
29 const auto* mainChamber =
chambers.front();
32 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - ME0Chamber has no layers.";
33 const auto* mainLayer = mainChamber->layers()[0];
34 if(!mainLayer->nEtaPartitions())
35 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - ME0Layer has no partitions.";
36 if(mainLayer->nEtaPartitions() != 1)
37 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - This module is only compatitble with geometries that contain only one partition per ME0Layer.";
39 const auto* mainPartition = mainLayer->etaPartitions()[0];
42 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - ME0 strip topology must be of type TrapezoidalStripTopology. This module cannot be used";
46 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all ME0Chambers have the same number of layers. This module cannot be used.";
47 for(
unsigned int iL = 0; iL <
nLayers; ++iL){
48 if(
chamber->layers()[iL]->nEtaPartitions() != mainLayer->nEtaPartitions())
49 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all ME0Layers have the same number of partitions. This module cannot be used.";
50 if(
chamber->layers()[iL]->etaPartitions()[0]->specs()->parameters() != mainPartition->specs()->parameters())
51 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all ME0 ETA partitions have the same properties. This module cannot be used.";
52 if(std::fabs(
chamber->layers()[iL]->etaPartitions()[0]->position().z()) != std::fabs(mainChamber->layers()[iL]->etaPartitions()[0]->position().z()))
53 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::TemporaryGeometry::TemporaryGeometry() - Not all ME0 ETA partitions in a single layer have the same Z position. This module cannot be used.";
63 const auto globalTop = mainPartition->toGlobal(localTop);
64 const auto globalBottom = mainPartition->toGlobal(localBottom);
65 const double etaTop = globalTop.
eta();
66 const double etaBottom = globalBottom.eta();
67 const double zBottom = globalBottom.z();
72 const auto& mainPars = mainPartition->specs()->parameters();
74 const double eta = (etaTop -etaBottom)*
double(iP + 1)/double(numberOfPartitions) + etaBottom;
75 const double distFromBeam = std::fabs(zBottom /std::sinh(eta));
77 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry") <<
"Top of new partition: " <<
partitionTops.back() << std::endl;
79 std::vector<float> params(4,0);
82 auto getWidth = [&] (
float locY ) ->
float {
return (mainPars[2]*(mainPars[1]+mainPars[0]) +locY*(mainPars[1] - mainPars[0]) )/(2*mainPars[2]);};
84 params[0] = iP == 0 ? mainPars[0] : getWidth(
partitionTops[iP -1]);
85 params[1] = iP +1 == numberOfPartitions ? mainPars[1] : getWidth(
partitionTops[iP]);
86 params[2] = ((iP + 1 == numberOfPartitions ? localTop.y() :
partitionTops[iP] ) - (iP == 0 ? localBottom.
y() :
partitionTops[iP-1] ) )/2;
94 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry") <<
"TOF numbers [layer][partition]: " ;
95 for(
unsigned int iL = 0; iL <
nLayers; ++iL){
96 tofs[iL].resize(numberOfPartitions);
99 const GlobalPoint centralGP(mainChamber->layers()[iL]->etaPartitions()[0]->toGlobal(partCenter));
100 tofs[iL][iP] = (centralGP.mag() / (CLHEP::c_light/CLHEP::cm));
101 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry") <<
"["<<iL<<
"]["<<iP<<
"]="<< tofs[iL][iP] <<
" "<<std::endl;
108 for(
unsigned int iP = 0; iP <
stripTopos.size(); ++iP ){
124 float r0 = h*(B +
b)/(B - b);
125 float striplength = h*2;
127 float pitch = (b +
B)/strips;
128 int nstrip =
static_cast<int>(
strips);
130 LogDebug(
"ME0ReDigiProducer::TemporaryGeometry") <<
"New partition parameters: " <<
131 "bottom width("<< 2*b <<
") top width("<<2*B<<
") height("<< 2*h <<
") radius to center("<< r0 <<
") nStrips("<< strips <<
") pitch(" << pitch<<
")"<< std::endl;
150 produces<ME0DigiPreRecoCollection>();
151 produces<ME0DigiPreRecoMap>();
154 if (!rng.isAvailable()){
156 <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n" 157 <<
"Add the service in the configuration file or remove the modules that require it.";
167 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - Must have at least one strip if using custom geometry.";
169 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - Must have at least one partition if using custom geometry.";
173 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - neutronAcceptance must be >= 0.";
192 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::beginRun() - No ME0Chambers in geometry.";
195 if(!nLayers)
throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::beginRun() - No layers in ME0 geometry.";
197 const unsigned int nPartitions =
chambers.front()->layers()[0]->nEtaPartitions();
205 throw cms::Exception(
"Configuration") <<
"ME0ReDigiProducer::beginRun() - The geometry has "<<nLayers
206 <<
" layers, but the readout of "<<
layerReadout.size() <<
" were specified with the layerReadout parameter." ;
210 <<
"Building temporary geometry:" << std::endl;
213 <<
"Done building temporary geometry!" << std::endl;
217 <<
" layers, but the readout of "<<
layerReadout.size() <<
" were specified with the layerReadout parameter." ;
248 CLHEP::HepRandomEngine* engine)
265 LogDebug(
"ME0ReDigiProducer::buildDigis") <<
"Begin building digis."<<std::endl;
267 for (me0dgIt = input_digis.begin(); me0dgIt != input_digis.end();
270 const auto& me0Id = (*me0dgIt).first;
271 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"Starting with roll: "<< me0Id<<std::endl;
279 digi != range.second;digi++) {
280 LogTrace(
"ME0ReDigiProducer::buildDigis") << std::endl<<
"(" <<digi->x() <<
","<< digi->y()<<
","<<digi->tof()<<
","<<digi->pdgid()<<
","<<digi->prompt()<<
")-> ";
299 int mapPartIDX = me0Id.roll() -1;
311 const int bxIdx = std::round(tof/
bxWidth);
312 LogTrace(
"ME0ReDigiProducer::buildDigis") << tof <<
"("<<bxIdx<<
") ";
319 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"("<<bxIdx<<
","<<mapPartIDX<<
","<<strip<<
") ";
321 int matchIDX =
fillDigiMap(chDigiMap, bxIdx,mapPartIDX,strip,newDigiIdx);
331 const float corrCoef = digiLocalError.
xy() /(sigmaX*
sigmaY);
335 sigmaX,
sigmaY, corrCoef, tof, digi->pdgid(), digi->prompt());
336 output_digis.insertDigi(me0Id, out_digi);
342 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"("<<digiLocalPoint.
x()<<
","<<digiLocalPoint.
y()<<
","<<sigmaX<<
","<<sigmaY<<
","<< tof<<
") ";
353 const auto* mainChamber =
geometry->chambers().front();
354 const unsigned int nLayers = mainChamber->nLayers();
357 tofs.resize(nLayers);
358 LogDebug(
"ME0ReDigiProducer::fillCentralTOFs()") <<
"TOF numbers [layer][partition]: " ;
359 for(
unsigned int iL = 0; iL <
nLayers; ++iL){
360 const auto* layer = mainChamber->layers()[iL];
361 const unsigned int mapLayIDX = layer->id().layer() -1;
362 const unsigned int nPartitions = layer->nEtaPartitions();
364 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::fillCentralTOFs() - ME0Layer has no partitions.";
365 tofs[mapLayIDX].resize(nPartitions);
366 for(
unsigned int iP = 0; iP < nPartitions; ++iP){
367 const unsigned int mapPartIDX = layer->etaPartitions()[iP]->id().roll() -1;
368 const GlobalPoint centralGP(layer->etaPartitions()[iP]->position());
369 tofs[mapLayIDX][mapPartIDX] = (centralGP.mag() / (CLHEP::c_light/CLHEP::cm));
370 LogDebug(
"ME0ReDigiProducer::fillCentralTOFs()") <<
"["<<mapLayIDX<<
"]["<<mapPartIDX<<
"]="<< tofs[mapLayIDX][mapPartIDX] <<
" "<<std::endl;
376 LogTrace(
"ME0ReDigiProducer::buildDigis") << partIdx <<
" ";
387 const LocalPoint partLocalPoint(inDigi->
x(), inDigi->
y() - partCenter ,0.);
388 strip = topo->channel(partLocalPoint);
389 const float stripF =
float(strip)+0.5;
392 LocalPoint digiPartLocalPoint = topo->localPosition(stripF);
393 digiLocalError = topo->localError(stripF, 1./
sqrt(12.));
394 digiLocalPoint =
LocalPoint(digiPartLocalPoint.
x(),digiPartLocalPoint.
y() + partCenter,0.0);
408 const LocalPoint partLocalPoint(inDigi->
x(), inDigi->
y(),0.);
409 strip = topo.channel(partLocalPoint);
410 const float stripF =
float(strip)+0.5;
413 digiLocalPoint = topo.localPosition(stripF);
414 digiLocalError = topo.localError(stripF, 1./
sqrt(12.));
419 auto it1 = chDigiMap.find(newIDX);
420 if (it1 == chDigiMap.end()){
421 chDigiMap[newIDX] = currentIDX;
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
Point3DBase< Scalar, LocalTag > LocalPoint
int getCustomStripProperties(const ME0DetId &detId, const ME0DigiPreReco *inDigi, float &tof, int &strip, LocalPoint &digiLocalPoint, LocalError &digiLocalError) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
float getCentralTOF(const ME0DetId &me0Id, unsigned int partIdx) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
float middleDistanceFromBeam
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)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
TrapezoidalStripTopology * buildTopo(const std::vector< float > &_p) const
MuonDigiCollection< ME0DetId, int > ME0DigiPreRecoMap
float pitch() const override
MuonDigiCollection< ME0DetId, ME0DigiPreReco > ME0DigiPreRecoCollection
std::vector< TrapezoidalStripTopology * > stripTopos
const std::vector< const ME0Chamber * > & chambers() const
Return a vector of all ME0 chambers.
std::map< DigiIndicies, unsigned int > ChamberDigiMap
float stripLength() const override
det heigth (strip length in the middle)
static const std::string B
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::vector< DigiType >::const_iterator const_iterator
ME0ReDigiProducer(const edm::ParameterSet &ps)
StreamID streamID() const
std::vector< std::vector< double > > tofs
std::pair< const_iterator, const_iterator > Range
int layer() const
Layer id: each chamber has six layers of chambers: layer 1 is the inner layer and layer 6 is the oute...
static char chambers[264][20]
void produce(edm::Event &, const edm::EventSetup &) override
int nstrips() const 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...