test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSimAsymmetricCls.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<stdlib.h>
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  RPCSim(config)
43 {
44 
45  aveEff = config.getParameter<double>("averageEfficiency");
46  aveCls = config.getParameter<double>("averageClusterSize");
47  resRPC = config.getParameter<double>("timeResolution");
48  timOff = config.getParameter<double>("timingRPCOffset");
49  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
50  resEle = config.getParameter<double>("timeJitter");
51  sspeed = config.getParameter<double>("signalPropagationSpeed");
52  lbGate = config.getParameter<double>("linkGateWidth");
53  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
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  std::cout <<"Average Efficiency = "<<aveEff<<std::endl;
62  std::cout <<"Average Cluster Size = "<<aveCls<<" strips"<<std::endl;
63  std::cout <<"RPC Time Resolution = "<<resRPC<<" ns"<<std::endl;
64  std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
65  std::cout <<"RPC adjacent strip delay = "<<dtimCs<<" ns"<<std::endl;
66  std::cout <<"Electronic Jitter = "<<resEle<<" ns"<<std::endl;
67  std::cout <<"Signal propagation time = "<<sspeed<<" x c"<<std::endl;
68  std::cout <<"Link Board Gate Width = "<<lbGate<<" ns"<<std::endl;
69  }
70 
71  _rpcSync = new RPCSynchronizer(config);
72 
73 }
74 
76 {
77  delete _rpcSync;
78 }
79 
80 int RPCSimAsymmetricCls::getClSize(uint32_t id,float posX, CLHEP::HepRandomEngine* engine)
81 {
82  std::vector<double> clsForDetId = getRPCSimSetUp()->getAsymmetricClsDistribution(id,slice(posX));
83 
84  int cnt = 1;
85  int min = 1;
86 
87  double rr_cl = CLHEP::RandFlat::shoot(engine);
88  for(unsigned int i = 0 ; i < clsForDetId.size(); i++){
89  cnt++;
90  if(rr_cl > clsForDetId[i]){
91  min = cnt;
92  }
93  else if(rr_cl < clsForDetId[i]){
94  break;
95  }
96  }
97  return min;
98 }
99 
100 int RPCSimAsymmetricCls::getClSize(float posX, CLHEP::HepRandomEngine* engine)
101 {
102  std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
103 
104  int cnt = 1;
105  int min = 1;
106  double func=0.0;
107  std::vector<double> sum_clsize;
108 
109  double rr_cl = CLHEP::RandFlat::shoot(engine);
110  if(0.0 <= posX && posX < 0.2) {
111  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
112  sum_clsize = clsMap[1];
113  }
114  if(0.2 <= posX && posX < 0.4) {
115  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
116  sum_clsize = clsMap[2];
117  }
118  if(0.4 <= posX && posX < 0.6) {
119  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
120  sum_clsize = clsMap[3];
121  }
122  if(0.6 <= posX && posX < 0.8) {
123  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
124  sum_clsize = clsMap[4];
125  }
126  if(0.8 <= posX && posX < 1.0) {
127  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
128  sum_clsize = clsMap[5];
129  }
130 
131  for(vector<double>::iterator iter = sum_clsize.begin();
132  iter != sum_clsize.end(); ++iter){
133  cnt++;
134  if(func > (*iter)){
135  min = cnt;
136  }
137  else if(func < (*iter)){
138  break;
139  }
140  }
141  return min;
142 }
143 
144 void
146  const edm::PSimHitContainer& rpcHits,
147  CLHEP::HepRandomEngine* engine)
148 {
151  theDetectorHitMap.clear();
153 
154  RPCDetId rpcId = roll->id();
155  RPCGeomServ RPCname(rpcId);
156  std::string nameRoll = RPCname.name();
157 
158  const Topology& topology=roll->specs()->topology();
159  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
160  _hit != rpcHits.end(); ++_hit){
161  if(_hit-> particleType() == 11) continue;
162  // Here I hould check if the RPC are up side down;
163  const LocalPoint& entr=_hit->entryPoint();
164 
165  int time_hit = _rpcSync->getSimHitBx(&(*_hit),engine);
166  float posX = roll->strip(_hit->localPosition())
167  - static_cast<int>(roll->strip(_hit->localPosition()));
168 
169  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
170 
171  // Effinciecy
172  int centralStrip = topology.channel(entr)+1;
173  float fire = CLHEP::RandFlat::shoot(engine);
174 
175  if (fire < veff[centralStrip-1]) {
176 
177  int fstrip=centralStrip;
178  int lstrip=centralStrip;
179 
180  // Compute the cluster size
181  double w = CLHEP::RandFlat::shoot(engine);
182  if (w < 1.e-10) w=1.e-10;
183 
184  int clsize = this->getClSize(rpcId.rawId(),posX, engine); // This is for cluster size chamber by chamber
185 
186  std::vector<int> cls;
187 
188  std::vector<double> TMPclsAsymmForDetId
189  = getRPCSimSetUp()->getAsymmetryForCls(rpcId,slice(posX),clsize);
190 
191  cls.push_back(centralStrip);
192  if (clsize > 1){
193  for (int cl = 0; cl < (clsize-1)/2; cl++){
194  if (centralStrip - cl -1 >= 1 ){
195  fstrip = centralStrip-cl-1;
196  cls.push_back(fstrip);
197  }
198  if (centralStrip + cl + 1 <= roll->nstrips() ){
199  lstrip = centralStrip+cl+1;
200  cls.push_back(lstrip);
201  }
202  }
203  if (clsize%2 == 0 ){
204  // insert the last strip according to the
205  // simhit position in the central strip
206  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
207  if (deltaw<0.) {
208  if (lstrip < roll->nstrips() ){
209  lstrip++;
210  cls.push_back(lstrip);
211  }
212  }else{
213  if (fstrip > 1 ){
214  fstrip--;
215  cls.push_back(fstrip);
216  }
217  }
218  }
219 
220  }
221 
222  //Now calculate the shift according to the distribution
223  float fire1 = CLHEP::RandFlat::shoot(engine);
224  int strip_shift=0;
225 
226  int offset;
227 
228  if(clsize%2==0){
229  offset = 2;
230  }
231  else {
232  offset = 1;
233  }
234 
235  for(unsigned int i = 0; i < TMPclsAsymmForDetId.size(); i ++){
236  if(fire1 < TMPclsAsymmForDetId[i]){
237  strip_shift = i - offset;
238  break;
239  }
240  }
241 
242  vector<int> shifted_cls;
243  shifted_cls.clear();
244 
245  int min_strip=100;
246  int max_strip=0;
247 
248  //correction for the edges
249  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
250  if(*i+strip_shift < min_strip){
251  min_strip = *i+strip_shift;
252  }
253  if(*i+strip_shift > max_strip){
254  max_strip = *i+strip_shift;
255  }
256  }
257 
258  if(min_strip<1 || max_strip-roll->nstrips()>0){
259  strip_shift = 0;
260  }
261  // if(min_strip<1){
262  // strip_shift = 0;
263  // }
264  // if(max_strip-roll->nstrips()>0){
265  // if(max_strip-roll->nstrips()==1){
266  // strip_shift--;
267  // }
268  // else{
269  // strip_shift = 0;
270  // }
271  // }
272 
273  //Now shift the cluster
274  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
275  shifted_cls.push_back(*i+strip_shift);
276  }
277  for (std::vector<int>::iterator i=shifted_cls.begin(); i!=shifted_cls.end();i++){
278  // Check the timing of the adjacent strip
279  if(*i != centralStrip){
280  if(CLHEP::RandFlat::shoot(engine) < veff[*i-1]){
281  std::pair<int, int> digi(*i,time_hit);
282  strips.insert(digi);
283 
284  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
285  }
286  }
287  else {
288  std::pair<int, int> digi(*i,time_hit);
289  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
290 
291  strips.insert(digi);
292  }
293  }
294  }
295  }
296 }
297 
299  CLHEP::HepRandomEngine* engine)
300 {
301 
302  RPCDetId rpcId = roll->id();
303 
304  RPCGeomServ RPCname(rpcId);
305  std::string nameRoll = RPCname.name();
306 
307  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
308  std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
309 
310  unsigned int nstrips = roll->nstrips();
311  double area = 0.0;
312 
313  if ( rpcId.region() == 0 )
314  {
315  const RectangularStripTopology* top_ = dynamic_cast<const
316  RectangularStripTopology*>(&(roll->topology()));
317  float xmin = (top_->localPosition(0.)).x();
318  float xmax = (top_->localPosition((float)roll->nstrips())).x();
319  float striplength = (top_->stripLength());
320  area = striplength*(xmax-xmin);
321  }
322  else
323  {
324  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
325  float xmin = (top_->localPosition(0.)).x();
326  float xmax = (top_->localPosition((float)roll->nstrips())).x();
327  float striplength = (top_->stripLength());
328  area = striplength*(xmax-xmin);
329  }
330 
331  for(unsigned int j = 0; j < vnoise.size(); ++j){
332 
333  if(j >= nstrips) break;
334 
335  // The efficiency of 0% does not imply on the noise rate.
336  // If the strip is masked the noise rate should be 0 Hz/cm^2
337  // if(veff[j] == 0) continue;
338 
339  // double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
340  // The vnoise is the noise rate per strip, so we shout multiply not
341  // by the chamber area,
342  // but the strip area which is area/((float)roll->nstrips()));
343  double ave =
344  vnoise[j]*nbxing*gate*area*1.0e-9*frate/((float)roll->nstrips());
345 
346  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
347  N_hits = randPoissonQ.fire();
348 
349  for (int i = 0; i < N_hits; i++ ){
350  int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot((nbxing*gate)/gate))) - nbxing/2;
351  std::pair<int, int> digi(j+1,time_hit);
352  strips.insert(digi);
353  }
354  }
355 }
356 
357 unsigned int RPCSimAsymmetricCls::slice(float posX){
358 
359  if(0.0 <= posX && posX < 0.2) {
360  return 0;
361  }
362  else if(0.2 <= posX && posX < 0.4) {
363  return 1;
364  }
365  else if(0.4 <= posX && posX < 0.6) {
366  return 2;
367  }
368  else if(0.6 <= posX && posX < 0.8) {
369  return 3;
370  }
371  else if(0.8 <= posX && posX < 1.0) {
372  return 4;
373  }
374  else return 2;
375 }
T getParameter(std::string const &) const
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:71
int i
Definition: DBlmapReader.cc:9
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
const Topology & topology() const
Definition: RPCRoll.cc:30
virtual float stripLength() const
std::map< int, std::vector< double > > clsMap
const double w
Definition: UKUtility.cc:23
CaloTopology const * topology(0)
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:71
void setRPCSimSetUp(RPCSimSetUp *simsetup)
int nstrips() const
Definition: RPCRoll.cc:46
const std::vector< double > & getAsymmetricClsDistribution(uint32_t id, uint32_t slice)
Definition: RPCSimSetUp.cc:231
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:50
const RPCRollSpecs * specs() const
Definition: RPCRoll.cc:18
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:60
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::vector< double > clsForDetId
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:35
RPCDetId id() const
Definition: RPCRoll.cc:24
virtual std::string name()
Definition: RPCGeomServ.cc:20
std::vector< double > sum_clsize
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:205
int j
Definition: DBlmapReader.cc:9
virtual int channel(const LocalPoint &p) const =0
Definition: RPCSim.h:30
T min(T a, T b)
Definition: MathUtil.h:58
unsigned int offset(bool)
Container::value_type value_type
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
const std::vector< double > & getAsymmetryForCls(uint32_t id, uint32_t slice, uint32_t cls)
Definition: RPCSimSetUp.cc:295
int getClSize(float posX, CLHEP::HepRandomEngine *)
string const
Definition: compareJSON.py:14
virtual LocalPoint localPosition(float strip) const
RPCSynchronizer * _rpcSync
RPCSimAsymmetricCls(const edm::ParameterSet &config)
void clear()
Definition: DetSet.h:69
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
Definition: DDAxes.h:10
virtual LocalPoint localPosition(float strip) const
T x() const
Definition: PV3DBase.h:62
virtual float stripLength() const
det heigth (strip length in the middle)
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:73
unsigned int slice(float posX)
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63