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;
146 mergeDigis (ps.getParameter<bool>(
"mergeDigis")),
149 produces<ME0DigiPreRecoCollection>();
150 produces<ME0DigiPreRecoMap>();
153 if (!rng.isAvailable()){
155 <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n" 156 <<
"Add the service in the configuration file or remove the modules that require it.";
164 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - Must have at least one strip if using custom geometry.";
166 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - Must have at least one partition if using custom geometry.";
170 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::ME0PreRecoDigiProducer() - neutronAcceptance must be >= 0.";
189 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::beginRun() - No ME0Chambers in geometry.";
192 if(!nLayers)
throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::beginRun() - No layers in ME0 geometry.";
194 const unsigned int nPartitions =
chambers.front()->layers()[0]->nEtaPartitions();
202 throw cms::Exception(
"Configuration") <<
"ME0ReDigiProducer::beginRun() - The geometry has "<<nLayers
203 <<
" layers, but the readout of "<<
layerReadout.size() <<
" were specified with the layerReadout parameter." ;
207 <<
"Building temporary geometry:" << std::endl;
210 <<
"Done building temporary geometry!" << std::endl;
214 <<
" layers, but the readout of "<<
layerReadout.size() <<
" were specified with the layerReadout parameter." ;
245 CLHEP::HepRandomEngine* engine)
262 LogDebug(
"ME0ReDigiProducer::buildDigis") <<
"Begin building digis."<<std::endl;
264 for (me0dgIt = input_digis.begin(); me0dgIt != input_digis.end();
267 const auto& me0Id = (*me0dgIt).first;
268 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"Starting with roll: "<< me0Id<<std::endl;
276 digi != range.second;digi++) {
277 LogTrace(
"ME0ReDigiProducer::buildDigis") << std::endl<<
"(" <<digi->x() <<
","<< digi->y()<<
","<<digi->tof()<<
","<<digi->pdgid()<<
","<<digi->prompt()<<
")-> ";
296 int mapPartIDX = me0Id.roll() -1;
308 const int bxIdx = std::round(tof/
bxWidth);
309 LogTrace(
"ME0ReDigiProducer::buildDigis") << tof <<
"("<<bxIdx<<
") ";
316 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"("<<bxIdx<<
","<<mapPartIDX<<
","<<strip<<
") ";
318 int matchIDX =
fillDigiMap(chDigiMap, bxIdx,mapPartIDX,strip,newDigiIdx);
328 const float corrCoef = digiLocalError.
xy() /(sigmaX*
sigmaY);
332 sigmaX,
sigmaY, corrCoef, tof, digi->pdgid(), digi->prompt());
333 output_digis.insertDigi(me0Id, out_digi);
339 LogTrace(
"ME0ReDigiProducer::buildDigis") <<
"("<<digiLocalPoint.
x()<<
","<<digiLocalPoint.
y()<<
","<<sigmaX<<
","<<sigmaY<<
","<< tof<<
") ";
350 const auto* mainChamber =
geometry->chambers().front();
351 const unsigned int nLayers = mainChamber->nLayers();
354 tofs.resize(nLayers);
355 LogDebug(
"ME0ReDigiProducer::fillCentralTOFs()") <<
"TOF numbers [layer][partition]: " ;
356 for(
unsigned int iL = 0; iL <
nLayers; ++iL){
357 const auto* layer = mainChamber->layers()[iL];
358 const unsigned int mapLayIDX = layer->id().layer() -1;
359 const unsigned int nPartitions = layer->nEtaPartitions();
361 throw cms::Exception(
"Setup") <<
"ME0ReDigiProducer::fillCentralTOFs() - ME0Layer has no partitions.";
362 tofs[mapLayIDX].resize(nPartitions);
363 for(
unsigned int iP = 0; iP < nPartitions; ++iP){
364 const unsigned int mapPartIDX = layer->etaPartitions()[iP]->id().roll() -1;
365 const GlobalPoint centralGP(layer->etaPartitions()[iP]->position());
366 tofs[mapLayIDX][mapPartIDX] = (centralGP.mag() / (CLHEP::c_light/CLHEP::cm));
367 LogDebug(
"ME0ReDigiProducer::fillCentralTOFs()") <<
"["<<mapLayIDX<<
"]["<<mapPartIDX<<
"]="<< tofs[mapLayIDX][mapPartIDX] <<
" "<<std::endl;
373 LogTrace(
"ME0ReDigiProducer::buildDigis") << partIdx <<
" ";
384 const LocalPoint partLocalPoint(inDigi->
x(), inDigi->
y() - partCenter ,0.);
385 strip = topo->channel(partLocalPoint);
386 const float stripF =
float(strip)+0.5;
389 LocalPoint digiPartLocalPoint = topo->localPosition(stripF);
390 digiLocalError = topo->localError(stripF, 1./
sqrt(12.));
391 digiLocalPoint =
LocalPoint(digiPartLocalPoint.
x(),digiPartLocalPoint.
y() + partCenter,0.0);
401 const LocalPoint partLocalPoint(inDigi->
x(), inDigi->
y(),0.);
403 const float stripF =
float(strip)+0.5;
412 auto it1 = chDigiMap.find(newIDX);
413 if (it1 == chDigiMap.end()){
414 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
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)
virtual LocalError localError(float strip, float stripErr2) const =0
std::vector< int > layerReadout
std::vector< float > partitionTops
virtual ~ME0ReDigiProducer()
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
MuonDigiCollection< ME0DetId, int > ME0DigiPreRecoMap
MuonDigiCollection< ME0DetId, ME0DigiPreReco > ME0DigiPreRecoCollection
virtual LocalPoint localPosition(float strip) const =0
std::vector< TrapezoidalStripTopology * > stripTopos
const std::vector< const ME0Chamber * > & chambers() const
Return a vector of all ME0 chambers.
std::map< DigiIndicies, unsigned int > ChamberDigiMap
virtual int channel(const LocalPoint &p) const =0
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< ME0DigiPreReco >::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]
virtual void produce(edm::Event &, const edm::EventSetup &) override
virtual float stripLength() const
det heigth (strip length in the middle)
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
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override