File indexing completed on 2024-04-06 12:30:50
0001 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
0002 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h"
0003 #include "SimMuon/RPCDigitizer/src/RPCSimAverageNoiseEffCls.h"
0004 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
0005
0006 #include "SimMuon/RPCDigitizer/src/RPCSynchronizer.h"
0007 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
0008 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
0009 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
0010
0011 #include <cmath>
0012
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017
0018 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0019 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0020 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0022 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0023 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
0024
0025 #include <cstring>
0026 #include <iostream>
0027 #include <fstream>
0028 #include <string>
0029 #include <vector>
0030 #include <cstdlib>
0031 #include <utility>
0032 #include <map>
0033
0034 #include "CLHEP/Random/RandFlat.h"
0035 #include "CLHEP/Random/RandPoissonQ.h"
0036
0037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0038
0039 using namespace std;
0040
0041 RPCSimAverageNoiseEffCls::RPCSimAverageNoiseEffCls(const edm::ParameterSet& config) : RPCSim(config) {
0042 aveEff = config.getParameter<double>("averageEfficiency");
0043 aveCls = config.getParameter<double>("averageClusterSize");
0044 resRPC = config.getParameter<double>("timeResolution");
0045 timOff = config.getParameter<double>("timingRPCOffset");
0046 dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
0047 resEle = config.getParameter<double>("timeJitter");
0048 sspeed = config.getParameter<double>("signalPropagationSpeed");
0049 lbGate = config.getParameter<double>("linkGateWidth");
0050 rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
0051 eledig = config.getParameter<bool>("digitizeElectrons");
0052
0053 rate = config.getParameter<double>("Rate");
0054 nbxing = config.getParameter<int>("Nbxing");
0055 gate = config.getParameter<double>("Gate");
0056 frate = config.getParameter<double>("Frate");
0057
0058 if (rpcdigiprint) {
0059 edm::LogInfo("RPC digitizer parameters") << "Average Efficiency = " << aveEff << '\n'
0060 << "Average Cluster Size = " << aveCls << " strips" << '\n'
0061 << "RPC Time Resolution = " << resRPC << " ns" << '\n'
0062 << "RPC Signal formation time = " << timOff << " ns" << '\n'
0063 << "RPC adjacent strip delay = " << dtimCs << " ns" << '\n'
0064 << "Electronic Jitter = " << resEle << " ns" << '\n'
0065 << "Signal propagation time = " << sspeed << " x c" << '\n'
0066 << "Link Board Gate Width = " << lbGate << " ns" << '\n';
0067 }
0068
0069 _rpcSync = new RPCSynchronizer(config);
0070 }
0071
0072 RPCSimAverageNoiseEffCls::~RPCSimAverageNoiseEffCls() { delete _rpcSync; }
0073
0074 int RPCSimAverageNoiseEffCls::getClSize(uint32_t id, float posX, CLHEP::HepRandomEngine* engine) {
0075 std::vector<double> clsForDetId = getRPCSimSetUp()->getCls(id);
0076
0077 int cnt = 1;
0078 int min = 1;
0079 double func = 0.0;
0080 std::vector<double> sum_clsize;
0081
0082 sum_clsize.clear();
0083 sum_clsize = clsForDetId;
0084 int vectOffset(0);
0085
0086 double rr_cl = CLHEP::RandFlat::shoot(engine);
0087
0088 if (0.0 <= posX && posX < 0.2) {
0089 func = clsForDetId[19] * (rr_cl);
0090 vectOffset = 0;
0091 }
0092 if (0.2 <= posX && posX < 0.4) {
0093 func = clsForDetId[39] * (rr_cl);
0094 vectOffset = 20;
0095 }
0096 if (0.4 <= posX && posX < 0.6) {
0097 func = clsForDetId[59] * (rr_cl);
0098 vectOffset = 40;
0099 }
0100 if (0.6 <= posX && posX < 0.8) {
0101 func = clsForDetId[79] * (rr_cl);
0102 vectOffset = 60;
0103 }
0104 if (0.8 <= posX && posX < 1.0) {
0105 func = clsForDetId[89] * (rr_cl);
0106 vectOffset = 80;
0107 }
0108
0109 for (int i = vectOffset; i < (vectOffset + 20); i++) {
0110 cnt++;
0111 if (func > clsForDetId[i]) {
0112 min = cnt;
0113 } else if (func < clsForDetId[i]) {
0114 break;
0115 }
0116 }
0117 return min;
0118 }
0119
0120 int RPCSimAverageNoiseEffCls::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
0121 std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
0122
0123 int cnt = 1;
0124 int min = 1;
0125 double func = 0.0;
0126 std::vector<double> sum_clsize;
0127
0128 double rr_cl = CLHEP::RandFlat::shoot(engine);
0129 if (0.0 <= posX && posX < 0.2) {
0130 func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
0131 sum_clsize = clsMap[1];
0132 }
0133 if (0.2 <= posX && posX < 0.4) {
0134 func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
0135 sum_clsize = clsMap[2];
0136 }
0137 if (0.4 <= posX && posX < 0.6) {
0138 func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
0139 sum_clsize = clsMap[3];
0140 }
0141 if (0.6 <= posX && posX < 0.8) {
0142 func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
0143 sum_clsize = clsMap[4];
0144 }
0145 if (0.8 <= posX && posX < 1.0) {
0146 func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
0147 sum_clsize = clsMap[5];
0148 }
0149
0150 for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
0151 cnt++;
0152 if (func > (*iter)) {
0153 min = cnt;
0154 } else if (func < (*iter)) {
0155 break;
0156 }
0157 }
0158 return min;
0159 }
0160
0161 void RPCSimAverageNoiseEffCls::simulate(const RPCRoll* roll,
0162 const edm::PSimHitContainer& rpcHits,
0163 CLHEP::HepRandomEngine* engine) {
0164 _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
0165 theRpcDigiSimLinks.clear();
0166 theDetectorHitMap.clear();
0167 theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
0168
0169 RPCDetId rpcId = roll->id();
0170 RPCGeomServ RPCname(rpcId);
0171
0172
0173 const Topology& topology = roll->specs()->topology();
0174
0175 for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
0176 if (!eledig && _hit->particleType() == 11)
0177 continue;
0178
0179 const LocalPoint& entr = _hit->entryPoint();
0180
0181 int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
0182 float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
0183
0184 std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
0185
0186
0187 int centralStrip = topology.channel(entr) + 1;
0188 ;
0189 float fire = CLHEP::RandFlat::shoot(engine);
0190
0191 if (fire < veff[centralStrip - 1]) {
0192 int fstrip = centralStrip;
0193 int lstrip = centralStrip;
0194
0195
0196 int clsize = this->getClSize(rpcId.rawId(), posX, engine);
0197 std::vector<int> cls;
0198 cls.push_back(centralStrip);
0199 if (clsize > 1) {
0200 for (int cl = 0; cl < (clsize - 1) / 2; cl++) {
0201 if (centralStrip - cl - 1 >= 1) {
0202 fstrip = centralStrip - cl - 1;
0203 cls.push_back(fstrip);
0204 }
0205 if (centralStrip + cl + 1 <= roll->nstrips()) {
0206 lstrip = centralStrip + cl + 1;
0207 cls.push_back(lstrip);
0208 }
0209 }
0210 if (clsize % 2 == 0) {
0211
0212
0213 double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
0214 if (deltaw < 0.) {
0215 if (lstrip < roll->nstrips()) {
0216 lstrip++;
0217 cls.push_back(lstrip);
0218 }
0219 } else {
0220 if (fstrip > 1) {
0221 fstrip--;
0222 cls.push_back(fstrip);
0223 }
0224 }
0225 }
0226 }
0227
0228 for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
0229
0230 if (*i != centralStrip) {
0231 if (CLHEP::RandFlat::shoot(engine) < veff[*i - 1]) {
0232 std::pair<int, int> digi(*i, time_hit);
0233 strips.insert(digi);
0234
0235 theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
0236 }
0237 } else {
0238 std::pair<int, int> digi(*i, time_hit);
0239 theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
0240
0241 strips.insert(digi);
0242 }
0243 }
0244 }
0245 }
0246 }
0247
0248 void RPCSimAverageNoiseEffCls::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
0249 RPCDetId rpcId = roll->id();
0250
0251 RPCGeomServ RPCname(rpcId);
0252
0253 std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
0254 std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
0255
0256 unsigned int nstrips = roll->nstrips();
0257 double area = 0.0;
0258
0259 if (rpcId.region() == 0) {
0260 const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
0261 float xmin = (top_->localPosition(0.)).x();
0262 float xmax = (top_->localPosition((float)roll->nstrips())).x();
0263 float striplength = (top_->stripLength());
0264 area = striplength * (xmax - xmin);
0265 } else {
0266 const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
0267 float xmin = (top_->localPosition(0.)).x();
0268 float xmax = (top_->localPosition((float)roll->nstrips())).x();
0269 float striplength = (top_->stripLength());
0270 area = striplength * (xmax - xmin);
0271 }
0272
0273 for (unsigned int j = 0; j < vnoise.size(); ++j) {
0274 if (j >= nstrips)
0275 break;
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 double ave = vnoise[j] * nbxing * gate * area * 1.0e-9 * frate / ((float)roll->nstrips());
0286
0287 CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
0288 N_hits = randPoissonQ.fire();
0289
0290 for (int i = 0; i < N_hits; i++) {
0291 int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
0292 std::pair<int, int> digi(j + 1, time_hit);
0293 strips.insert(digi);
0294 }
0295 }
0296 }