CMS 3D CMS Logo

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