CMS 3D CMS Logo

RPCSimAverageNoiseEffCls.cc
Go to the documentation of this file.
5 
10 
11 #include <cmath>
12 
18 
25 
26 #include <cstring>
27 #include <iostream>
28 #include <fstream>
29 #include <string>
30 #include <vector>
31 #include <cstdlib>
32 #include <utility>
33 #include <map>
34 
35 #include "CLHEP/Random/RandFlat.h"
36 #include "CLHEP/Random/RandPoissonQ.h"
37 
39 
40 using namespace std;
41 
43  aveEff = config.getParameter<double>("averageEfficiency");
44  aveCls = config.getParameter<double>("averageClusterSize");
45  resRPC = config.getParameter<double>("timeResolution");
46  timOff = config.getParameter<double>("timingRPCOffset");
47  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
48  resEle = config.getParameter<double>("timeJitter");
49  sspeed = config.getParameter<double>("signalPropagationSpeed");
50  lbGate = config.getParameter<double>("linkGateWidth");
51  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
52  eledig = config.getParameter<bool>("digitizeElectrons"); //flag to turn on/off electron digitization
53 
54  rate = config.getParameter<double>("Rate");
55  nbxing = config.getParameter<int>("Nbxing");
56  gate = config.getParameter<double>("Gate");
57  frate = config.getParameter<double>("Frate");
58 
59  if (rpcdigiprint) {
60  edm::LogInfo("RPC digitizer parameters") << "Average Efficiency = " << aveEff << '\n'
61  << "Average Cluster Size = " << aveCls << " strips" << '\n'
62  << "RPC Time Resolution = " << resRPC << " ns" << '\n'
63  << "RPC Signal formation time = " << timOff << " ns" << '\n'
64  << "RPC adjacent strip delay = " << dtimCs << " ns" << '\n'
65  << "Electronic Jitter = " << resEle << " ns" << '\n'
66  << "Signal propagation time = " << sspeed << " x c" << '\n'
67  << "Link Board Gate Width = " << lbGate << " ns" << '\n';
68  }
69 
71 }
72 
74 
75 int RPCSimAverageNoiseEffCls::getClSize(uint32_t id, float posX, CLHEP::HepRandomEngine* engine) {
76  std::vector<double> clsForDetId = getRPCSimSetUp()->getCls(id);
77 
78  int cnt = 1;
79  int min = 1;
80  double func = 0.0;
81  std::vector<double> sum_clsize;
82 
83  sum_clsize.clear();
85  int vectOffset(0);
86 
87  double rr_cl = CLHEP::RandFlat::shoot(engine);
88 
89  if (0.0 <= posX && posX < 0.2) {
90  func = clsForDetId[19] * (rr_cl);
91  vectOffset = 0;
92  }
93  if (0.2 <= posX && posX < 0.4) {
94  func = clsForDetId[39] * (rr_cl);
95  vectOffset = 20;
96  }
97  if (0.4 <= posX && posX < 0.6) {
98  func = clsForDetId[59] * (rr_cl);
99  vectOffset = 40;
100  }
101  if (0.6 <= posX && posX < 0.8) {
102  func = clsForDetId[79] * (rr_cl);
103  vectOffset = 60;
104  }
105  if (0.8 <= posX && posX < 1.0) {
106  func = clsForDetId[89] * (rr_cl);
107  vectOffset = 80;
108  }
109 
110  for (int i = vectOffset; i < (vectOffset + 20); i++) {
111  cnt++;
112  if (func > clsForDetId[i]) {
113  min = cnt;
114  } else if (func < clsForDetId[i]) {
115  break;
116  }
117  }
118  return min;
119 }
120 
121 int RPCSimAverageNoiseEffCls::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
122  std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
123 
124  int cnt = 1;
125  int min = 1;
126  double func = 0.0;
127  std::vector<double> sum_clsize;
128 
129  double rr_cl = CLHEP::RandFlat::shoot(engine);
130  if (0.0 <= posX && posX < 0.2) {
131  func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
132  sum_clsize = clsMap[1];
133  }
134  if (0.2 <= posX && posX < 0.4) {
135  func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
136  sum_clsize = clsMap[2];
137  }
138  if (0.4 <= posX && posX < 0.6) {
139  func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
140  sum_clsize = clsMap[3];
141  }
142  if (0.6 <= posX && posX < 0.8) {
143  func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
144  sum_clsize = clsMap[4];
145  }
146  if (0.8 <= posX && posX < 1.0) {
147  func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
148  sum_clsize = clsMap[5];
149  }
150 
151  for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
152  cnt++;
153  if (func > (*iter)) {
154  min = cnt;
155  } else if (func < (*iter)) {
156  break;
157  }
158  }
159  return min;
160 }
161 
163  const edm::PSimHitContainer& rpcHits,
164  CLHEP::HepRandomEngine* engine) {
167  theDetectorHitMap.clear();
169 
170  RPCDetId rpcId = roll->id();
171  RPCGeomServ RPCname(rpcId);
172  //std::string nameRoll = RPCname.name();
173 
174  const Topology& topology = roll->specs()->topology();
175 
176  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
177  if (!eledig && _hit->particleType() == 11)
178  continue;
179  // Here I hould check if the RPC are up side down;
180  const LocalPoint& entr = _hit->entryPoint();
181 
182  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
183  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
184 
185  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
186 
187  // Effinciecy
188  int centralStrip = topology.channel(entr) + 1;
189  ;
190  float fire = CLHEP::RandFlat::shoot(engine);
191 
192  if (fire < veff[centralStrip - 1]) {
193  int fstrip = centralStrip;
194  int lstrip = centralStrip;
195 
196  // Compute the cluster size
197  int clsize = this->getClSize(rpcId.rawId(), posX, engine); // This is for cluster size chamber by chamber
198  std::vector<int> cls;
199  cls.push_back(centralStrip);
200  if (clsize > 1) {
201  for (int cl = 0; cl < (clsize - 1) / 2; cl++) {
202  if (centralStrip - cl - 1 >= 1) {
203  fstrip = centralStrip - cl - 1;
204  cls.push_back(fstrip);
205  }
206  if (centralStrip + cl + 1 <= roll->nstrips()) {
207  lstrip = centralStrip + cl + 1;
208  cls.push_back(lstrip);
209  }
210  }
211  if (clsize % 2 == 0) {
212  // insert the last strip according to the
213  // simhit position in the central strip
214  double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
215  if (deltaw < 0.) {
216  if (lstrip < roll->nstrips()) {
217  lstrip++;
218  cls.push_back(lstrip);
219  }
220  } else {
221  if (fstrip > 1) {
222  fstrip--;
223  cls.push_back(fstrip);
224  }
225  }
226  }
227  }
228 
229  for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
230  // Check the timing of the adjacent strip
231  if (*i != centralStrip) {
232  if (CLHEP::RandFlat::shoot(engine) < veff[*i - 1]) {
233  std::pair<int, int> digi(*i, time_hit);
234  strips.insert(digi);
235 
236  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
237  }
238  } else {
239  std::pair<int, int> digi(*i, time_hit);
240  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
241 
242  strips.insert(digi);
243  }
244  }
245  }
246  }
247 }
248 
249 void RPCSimAverageNoiseEffCls::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
250  RPCDetId rpcId = roll->id();
251 
252  RPCGeomServ RPCname(rpcId);
253 
254  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
255  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
256 
257  unsigned int nstrips = roll->nstrips();
258  double area = 0.0;
259 
260  if (rpcId.region() == 0) {
261  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
262  float xmin = (top_->localPosition(0.)).x();
263  float xmax = (top_->localPosition((float)roll->nstrips())).x();
264  float striplength = (top_->stripLength());
265  area = striplength * (xmax - xmin);
266  } else {
267  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
268  float xmin = (top_->localPosition(0.)).x();
269  float xmax = (top_->localPosition((float)roll->nstrips())).x();
270  float striplength = (top_->stripLength());
271  area = striplength * (xmax - xmin);
272  }
273 
274  for (unsigned int j = 0; j < vnoise.size(); ++j) {
275  if (j >= nstrips)
276  break;
277 
278  // The efficiency of 0% does not imply on the noise rate.
279  // If the strip is masked the noise rate should be 0 Hz/cm^2
280  // if(veff[j] == 0) continue;
281 
282  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
283  // The vnoise is the noise rate per strip, so we shout multiply not
284  // by the chamber area,
285  // but the strip area which is area/((float)roll->nstrips()));
286  double ave = vnoise[j] * nbxing * gate * area * 1.0e-9 * frate / ((float)roll->nstrips());
287 
288  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
289  N_hits = randPoissonQ.fire();
290 
291  for (int i = 0; i < N_hits; i++) {
292  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
293  std::pair<int, int> digi(j + 1, time_hit);
294  strips.insert(digi);
295  }
296  }
297 }
RPCRoll
Definition: RPCRoll.h:12
RPCSynchronizer::setRPCSimSetUp
void setRPCSimSetUp(RPCSimSetUp *simsetup)
Definition: RPCSynchronizer.h:43
RPCSimAverageNoiseEffCls::dtimCs
double dtimCs
Definition: RPCSimAverageNoiseEffCls.h:49
RPCSim::getRPCSimSetUp
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:45
RPCSimAverageNoiseEffCls::resEle
double resEle
Definition: RPCSimAverageNoiseEffCls.h:50
mps_fire.i
i
Definition: mps_fire.py:428
TrapezoidalStripTopology::stripLength
float stripLength() const override
det heigth (strip length in the middle)
Definition: TrapezoidalStripTopology.h:63
RPCGeomServ
Definition: RPCGeomServ.h:8
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
RPCDetId::region
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
RPCSimAverageNoiseEffCls::sspeed
double sspeed
Definition: RPCSimAverageNoiseEffCls.h:51
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::DetSet::clear
void clear()
Definition: DetSet.h:71
RPCDetId
Definition: RPCDetId.h:16
RPCSimAverageNoiseEffCls::frate
double frate
Definition: RPCSimAverageNoiseEffCls.h:60
RPCSynchronizer
Definition: RPCSynchronizer.h:36
PSimHitContainer.h
RPCSynchronizer::getSimHitBx
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
Definition: RPCSynchronizer.cc:57
RPCRoll.h
RPCSimAverageNoiseEffCls::getClSize
int getClSize(float posX, CLHEP::HepRandomEngine *)
Definition: RPCSimAverageNoiseEffCls.cc:121
EDAnalyzer.h
DDAxes::x
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
RPCSim::strips
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:55
RPCSimAverageNoiseEffCls::simulate
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
Definition: RPCSimAverageNoiseEffCls.cc:162
RectangularStripTopology.h
RectangularStripTopology::localPosition
LocalPoint localPosition(float strip) const override
Definition: RectangularStripTopology.cc:17
RPCRoll::topology
const Topology & topology() const override
Definition: RPCRoll.cc:18
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
config
Definition: config.py:1
RPCRoll::id
RPCDetId id() const
Definition: RPCRoll.cc:16
RPCSimAverageNoiseEffCls::aveEff
double aveEff
Definition: RPCSimAverageNoiseEffCls.h:43
RPCGeomServ.h
PSimHit.h
RectangularStripTopology
Definition: RectangularStripTopology.h:11
RPCSim::theDetectorHitMap
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:68
RPCSimAverageNoiseEffCls::clsForDetId
std::vector< double > clsForDetId
Definition: RPCSimAverageNoiseEffCls.h:64
TrapezoidalStripTopology
Definition: TrapezoidalStripTopology.h:21
Topology::channel
virtual int channel(const LocalPoint &p) const =0
RPCSim::theRpcDigiSimLinks
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
RPCSimSetUp::getCls
const std::vector< double > & getCls(uint32_t id)
Definition: RPCSimSetUp.cc:458
RPCRollSpecs::topology
const Topology & topology() const override
Definition: RPCRollSpecs.cc:36
RecoTauValidation_cfi.posX
posX
Definition: RecoTauValidation_cfi.py:288
RPCSimSetUp::getClsMap
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:450
RPCSimAverageNoiseEffCls::aveCls
double aveCls
Definition: RPCSimAverageNoiseEffCls.h:46
Point3DBase< float, LocalTag >
RPCSimAverageNoiseEffCls::lbGate
double lbGate
Definition: RPCSimAverageNoiseEffCls.h:52
RPCRoll::strip
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:35
RPCSimAverageNoiseEffCls::rpcdigiprint
bool rpcdigiprint
Definition: RPCSimAverageNoiseEffCls.h:53
RPCSimAverageNoiseEffCls::timOff
double timOff
Definition: RPCSimAverageNoiseEffCls.h:48
RPCSimAverageNoiseEffCls::nbxing
int nbxing
Definition: RPCSimAverageNoiseEffCls.h:57
RPCDetId.h
RPCRoll::centreOfStrip
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:26
RectangularStripTopology::stripLength
float stripLength() const override
Definition: RectangularStripTopology.h:44
RPCRollSpecs.h
edm::ParameterSet
Definition: ParameterSet.h:47
RPCSimAverageNoiseEffCls::sum_clsize
std::vector< double > sum_clsize
Definition: RPCSimAverageNoiseEffCls.h:63
Event.h
RPCRoll::nstrips
int nstrips() const
Definition: RPCRoll.cc:24
RPCSimAverageNoiseEffCls::clsMap
std::map< int, std::vector< double > > clsMap
Definition: RPCSimAverageNoiseEffCls.h:62
RPCSimAverageNoiseEffCls::simulateNoise
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
Definition: RPCSimAverageNoiseEffCls.cc:249
RPCSimAverageNoiseEffCls::~RPCSimAverageNoiseEffCls
~RPCSimAverageNoiseEffCls() override
Definition: RPCSimAverageNoiseEffCls.cc:73
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
RPCSim
Definition: RPCSim.h:30
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
RPCSimAverageNoiseEffCls::_rpcSync
RPCSynchronizer * _rpcSync
Definition: RPCSimAverageNoiseEffCls.h:67
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
TrapezoidalStripTopology.h
RPCSimAverageNoiseEffCls::eledig
bool eledig
Definition: RPCSimAverageNoiseEffCls.h:54
RPCSimAverageNoiseEffCls::RPCSimAverageNoiseEffCls
RPCSimAverageNoiseEffCls(const edm::ParameterSet &config)
Definition: RPCSimAverageNoiseEffCls.cc:42
RPCSimAverageNoiseEffCls::rate
double rate
Definition: RPCSimAverageNoiseEffCls.h:58
Frameworkfwd.h
TrackerOfflineValidation_Dqm_cff.xmax
xmax
Definition: TrackerOfflineValidation_Dqm_cff.py:11
RPCRoll::specs
const RPCRollSpecs * specs() const
Definition: RPCRoll.cc:14
EventSetup.h
TrapezoidalStripTopology::localPosition
LocalPoint localPosition(float strip) const override
Definition: TrapezoidalStripTopology.cc:27
RPCSimAverageNoiseEffCls::gate
double gate
Definition: RPCSimAverageNoiseEffCls.h:59
RPCSimSetUp.h
RPCSimAverageNoiseEffCls::N_hits
int N_hits
Definition: RPCSimAverageNoiseEffCls.h:56
Topology
Definition: Topology.h:39
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
ParameterSet.h
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10
MuonGeometryRecord.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
RPCSimAverageNoiseEffCls::resRPC
double resRPC
Definition: RPCSimAverageNoiseEffCls.h:47
RPCSim::RPCDigiSimLinks
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:33
custom_jme_cff.area
area
Definition: custom_jme_cff.py:140
RPCGeometry.h
RPCSynchronizer.h
RPCSimAverageNoiseEffCls.h