CMS 3D CMS Logo

RPCSimAverageNoiseEff.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 
39 using namespace std;
40 
42  aveEff = config.getParameter<double>("averageEfficiency");
43  aveCls = config.getParameter<double>("averageClusterSize");
44  resRPC = config.getParameter<double>("timeResolution");
45  timOff = config.getParameter<double>("timingRPCOffset");
46  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
47  resEle = config.getParameter<double>("timeJitter");
48  sspeed = config.getParameter<double>("signalPropagationSpeed");
49  lbGate = config.getParameter<double>("linkGateWidth");
50  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
51 
52  rate = config.getParameter<double>("Rate");
53  nbxing = config.getParameter<int>("Nbxing");
54  gate = config.getParameter<double>("Gate");
55  frate = config.getParameter<double>("Frate");
56 
57  if (rpcdigiprint) {
58  std::cout << "Average Efficiency = " << aveEff << std::endl;
59  std::cout << "Average Cluster Size = " << aveCls << " strips" << std::endl;
60  std::cout << "RPC Time Resolution = " << resRPC << " ns" << std::endl;
61  std::cout << "RPC Signal formation time = " << timOff << " ns" << std::endl;
62  std::cout << "RPC adjacent strip delay = " << dtimCs << " ns" << std::endl;
63  std::cout << "Electronic Jitter = " << resEle << " ns" << std::endl;
64  std::cout << "Signal propagation time = " << sspeed << " x c" << std::endl;
65  std::cout << "Link Board Gate Width = " << lbGate << " ns" << std::endl;
66  }
67 
69 }
70 
72 
73 int RPCSimAverageNoiseEff::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
74  std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
75 
76  int cnt = 1;
77  int min = 1;
78  double func = 0.0;
79  std::vector<double> sum_clsize;
80 
81  double rr_cl = CLHEP::RandFlat::shoot(engine);
82  if (0.0 <= posX && posX < 0.2) {
83  func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
84  sum_clsize = clsMap[1];
85  }
86  if (0.2 <= posX && posX < 0.4) {
87  func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
88  sum_clsize = clsMap[2];
89  }
90  if (0.4 <= posX && posX < 0.6) {
91  func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
92  sum_clsize = clsMap[3];
93  }
94  if (0.6 <= posX && posX < 0.8) {
95  func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
96  sum_clsize = clsMap[4];
97  }
98  if (0.8 <= posX && posX < 1.0) {
99  func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
100  sum_clsize = clsMap[5];
101  }
102 
103  for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
104  cnt++;
105  if (func > (*iter)) {
106  min = cnt;
107  } else if (func < (*iter)) {
108  break;
109  }
110  }
111  return min;
112 }
113 
115  const edm::PSimHitContainer& rpcHits,
116  CLHEP::HepRandomEngine* engine) {
119  theDetectorHitMap.clear();
121 
122  RPCDetId rpcId = roll->id();
123  RPCGeomServ RPCname(rpcId);
124  std::string nameRoll = RPCname.name();
125 
126  const Topology& topology = roll->specs()->topology();
127 
128  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
129  if (_hit->particleType() == 11)
130  continue;
131 
132  // Here I hould check if the RPC are up side down;
133  const LocalPoint& entr = _hit->entryPoint();
134 
135  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
136  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
137 
138  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
139 
140  // Effinciecy
141  int centralStrip = topology.channel(entr) + 1;
142  ;
143  float fire = CLHEP::RandFlat::shoot(engine);
144 
145  if (fire < veff[centralStrip - 1]) {
146  int fstrip = centralStrip;
147  int lstrip = centralStrip;
148 
149  // Compute the cluster size
150  //double w = CLHEP::RandFlat::shoot(engine);
151  //if (w < 1.e-10) w=1.e-10;
152  int clsize = this->getClSize(posX, engine);
153 
154  std::vector<int> cls;
155  cls.push_back(centralStrip);
156  if (clsize > 1) {
157  for (int cl = 0; cl < (clsize - 1) / 2; cl++) {
158  if (centralStrip - cl - 1 >= 1) {
159  fstrip = centralStrip - cl - 1;
160  cls.push_back(fstrip);
161  }
162  if (centralStrip + cl + 1 <= roll->nstrips()) {
163  lstrip = centralStrip + cl + 1;
164  cls.push_back(lstrip);
165  }
166  }
167  if (clsize % 2 == 0) {
168  // insert the last strip according to the
169  // simhit position in the central strip
170  double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
171  if (deltaw < 0.) {
172  if (lstrip < roll->nstrips()) {
173  lstrip++;
174  cls.push_back(lstrip);
175  }
176  } else {
177  if (fstrip > 1) {
178  fstrip--;
179  cls.push_back(fstrip);
180  }
181  }
182  }
183  }
184 
185  for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
186  // Check the timing of the adjacent strip
187  if (*i != centralStrip) {
188  if (CLHEP::RandFlat::shoot(engine) < veff[*i - 1]) {
189  std::pair<int, int> digi(*i, time_hit);
190  strips.insert(digi);
191 
192  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
193  }
194  } else {
195  std::pair<int, int> digi(*i, time_hit);
196  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
197 
198  strips.insert(digi);
199  }
200  }
201  }
202  }
203 }
204 
205 void RPCSimAverageNoiseEff::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
206  RPCDetId rpcId = roll->id();
207 
208  RPCGeomServ RPCname(rpcId);
209  std::string nameRoll = RPCname.name();
210 
211  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
212  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
213 
214  unsigned int nstrips = roll->nstrips();
215  double area = 0.0;
216 
217  if (rpcId.region() == 0) {
218  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
219  float xmin = (top_->localPosition(0.)).x();
220  float xmax = (top_->localPosition((float)roll->nstrips())).x();
221  float striplength = (top_->stripLength());
222  area = striplength * (xmax - xmin);
223  } else {
224  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
225  float xmin = (top_->localPosition(0.)).x();
226  float xmax = (top_->localPosition((float)roll->nstrips())).x();
227  float striplength = (top_->stripLength());
228  area = striplength * (xmax - xmin);
229  }
230 
231  for (unsigned int j = 0; j < vnoise.size(); ++j) {
232  if (j >= nstrips)
233  break;
234 
235  // The efficiency of 0% does not imply on the noise rate.
236  // If the strip is masked the noise rate should be 0 Hz/cm^2
237  // if(veff[j] == 0) continue;
238 
239  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
240  // The vnoise is the noise rate per strip, so we shout multiply not
241  // by the chamber area,
242  // but the strip area which is area/((float)roll->nstrips()));
243  double ave = vnoise[j] * nbxing * gate * area * 1.0e-9 * frate / ((float)roll->nstrips());
244 
245  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
246  N_hits = randPoissonQ.fire();
247 
248  for (int i = 0; i < N_hits; i++) {
249  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
250  std::pair<int, int> digi(j + 1, time_hit);
251  strips.insert(digi);
252  }
253  }
254 }
RPCSimAverageNoiseEff::getClSize
int getClSize(float posX, CLHEP::HepRandomEngine *)
Definition: RPCSimAverageNoiseEff.cc:73
RPCRoll
Definition: RPCRoll.h:12
RPCSynchronizer::setRPCSimSetUp
void setRPCSimSetUp(RPCSimSetUp *simsetup)
Definition: RPCSynchronizer.h:43
RPCSimAverageNoiseEff::aveEff
double aveEff
Definition: RPCSimAverageNoiseEff.h:41
RPCSim::getRPCSimSetUp
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:45
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
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
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
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RPCSynchronizer
Definition: RPCSynchronizer.h:36
PSimHitContainer.h
RPCSynchronizer::getSimHitBx
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
Definition: RPCSynchronizer.cc:58
RPCRoll.h
EDAnalyzer.h
DDAxes::x
RPCSimAverageNoiseEff::lbGate
double lbGate
Definition: RPCSimAverageNoiseEff.h:51
RPCSim::strips
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:55
RectangularStripTopology.h
RPCSimAverageNoiseEff::dtimCs
double dtimCs
Definition: RPCSimAverageNoiseEff.h:48
RectangularStripTopology::localPosition
LocalPoint localPosition(float strip) const override
Definition: RectangularStripTopology.cc:17
RPCRoll::topology
const Topology & topology() const override
Definition: RPCRoll.cc:18
RPCSimAverageNoiseEff::_rpcSync
RPCSynchronizer * _rpcSync
Definition: RPCSimAverageNoiseEff.h:64
RPCSimAverageNoiseEff::rpcdigiprint
bool rpcdigiprint
Definition: RPCSimAverageNoiseEff.h:52
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
RPCGeomServ.h
RPCSimAverageNoiseEff::rate
double rate
Definition: RPCSimAverageNoiseEff.h:56
RPCSimAverageNoiseEff::resRPC
double resRPC
Definition: RPCSimAverageNoiseEff.h:46
PSimHit.h
RectangularStripTopology
Definition: RectangularStripTopology.h:11
RPCSim::theDetectorHitMap
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:68
ecaldqm::topology
const CaloTopology * topology(nullptr)
TrapezoidalStripTopology
Definition: TrapezoidalStripTopology.h:21
RPCSimAverageNoiseEff::gate
double gate
Definition: RPCSimAverageNoiseEff.h:57
RPCSim::theRpcDigiSimLinks
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
RPCRollSpecs::topology
const Topology & topology() const override
Definition: RPCRollSpecs.cc:36
RecoTauValidation_cfi.posX
posX
Definition: RecoTauValidation_cfi.py:288
RPCSimAverageNoiseEff::aveCls
double aveCls
Definition: RPCSimAverageNoiseEff.h:45
RPCGeomServ::name
virtual std::string name()
Definition: RPCGeomServ.cc:11
RPCSimSetUp::getClsMap
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:413
Point3DBase< float, LocalTag >
RPCSimAverageNoiseEff::~RPCSimAverageNoiseEff
~RPCSimAverageNoiseEff() override
Definition: RPCSimAverageNoiseEff.cc:71
RPCRoll::strip
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:35
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
RPCSimAverageNoiseEff::sum_clsize
std::vector< double > sum_clsize
Definition: RPCSimAverageNoiseEff.h:61
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
RPCSimAverageNoiseEff::sspeed
double sspeed
Definition: RPCSimAverageNoiseEff.h:50
RPCSimAverageNoiseEff::resEle
double resEle
Definition: RPCSimAverageNoiseEff.h:49
RPCRoll::nstrips
int nstrips() const
Definition: RPCRoll.cc:24
RPCSimAverageNoiseEff::frate
double frate
Definition: RPCSimAverageNoiseEff.h:58
RPCSimAverageNoiseEff::RPCSimAverageNoiseEff
RPCSimAverageNoiseEff(const edm::ParameterSet &config)
Definition: RPCSimAverageNoiseEff.cc:41
RPCSimAverageNoiseEff::nbxing
int nbxing
Definition: RPCSimAverageNoiseEff.h:55
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
RPCSimAverageNoiseEff::N_hits
int N_hits
Definition: RPCSimAverageNoiseEff.h:54
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
TrapezoidalStripTopology.h
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
RPCSimAverageNoiseEff::timOff
double timOff
Definition: RPCSimAverageNoiseEff.h:47
TrapezoidalStripTopology::localPosition
LocalPoint localPosition(float strip) const override
Definition: TrapezoidalStripTopology.cc:27
RPCSimSetUp.h
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
RPCSim::RPCDigiSimLinks
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:33
RPCSimAverageNoiseEff::simulateNoise
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
Definition: RPCSimAverageNoiseEff.cc:205
RPCSimAverageNoiseEff::simulate
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
Definition: RPCSimAverageNoiseEff.cc:114
RPCSimAverageNoiseEff::clsMap
std::map< int, std::vector< double > > clsMap
Definition: RPCSimAverageNoiseEff.h:60
custom_jme_cff.area
area
Definition: custom_jme_cff.py:169
RPCSimAverageNoiseEff.h
RPCGeometry.h
RPCSynchronizer.h