CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSimAverageNoise.cc
Go to the documentation of this file.
4 
8 
9 #include <cmath>
13 #include "CLHEP/Random/RandomEngine.h"
14 #include "CLHEP/Random/RandFlat.h"
15 #include <CLHEP/Random/RandGaussQ.h>
16 #include <CLHEP/Random/RandFlat.h>
17 
24 
31 
32 #include<cstring>
33 #include<iostream>
34 #include<fstream>
35 #include<string>
36 #include<vector>
37 #include<stdlib.h>
38 #include <utility>
39 #include <map>
40 
41 //#include "CLHEP/config/CLHEP.h"
42 #include "CLHEP/Random/Random.h"
43 #include "CLHEP/Random/RandFlat.h"
44 #include "CLHEP/Random/RandPoissonQ.h"
45 
46 using namespace std;
47 
49  RPCSim(config)
50 {
51  aveEff = config.getParameter<double>("averageEfficiency");
52  aveCls = config.getParameter<double>("averageClusterSize");
53  resRPC = config.getParameter<double>("timeResolution");
54  timOff = config.getParameter<double>("timingRPCOffset");
55  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
56  resEle = config.getParameter<double>("timeJitter");
57  sspeed = config.getParameter<double>("signalPropagationSpeed");
58  lbGate = config.getParameter<double>("linkGateWidth");
59  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
60  rate=config.getParameter<double>("Rate");
61  nbxing=config.getParameter<int>("Nbxing");
62  gate=config.getParameter<double>("Gate");
63  frate=config.getParameter<double>("Frate");
64 
65  if (rpcdigiprint) {
66  std::cout <<"Average Efficiency = "<<aveEff<<std::endl;
67  std::cout <<"Average Cluster Size = "<<aveCls<<" strips"<<std::endl;
68  std::cout <<"RPC Time Resolution = "<<resRPC<<" ns"<<std::endl;
69  std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
70  std::cout <<"RPC adjacent strip delay = "<<dtimCs<<" ns"<<std::endl;
71  std::cout <<"Electronic Jitter = "<<resEle<<" ns"<<std::endl;
72  std::cout <<"Signal propagation time = "<<sspeed<<" x c"<<std::endl;
73  std::cout <<"Link Board Gate Width = "<<lbGate<<" ns"<<std::endl;
74  }
75 
76  _rpcSync = new RPCSynchronizer(config);
77 
78 }
79 
80 void RPCSimAverageNoise::setRandomEngine(CLHEP::HepRandomEngine& eng){
81  flatDistribution = new CLHEP::RandFlat(eng);
82  flatDistribution2 = new CLHEP::RandFlat(eng);
83  poissonDistribution_ = new CLHEP::RandPoissonQ(eng);
85 }
86 
88 {
89  //Deleting the distribution defined in the constructor
90  delete flatDistribution;
91  delete flatDistribution2;
92  delete poissonDistribution_;
93  delete _rpcSync;
94 }
95 
97 {
98 
99  std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
100 
101  int cnt = 1;
102  int min = 1;
103  int max = 1;
104  double func=0.0;
105  std::vector<double> sum_clsize;
106 
107  double rr_cl = flatDistribution->fire();
108  if(0.0 <= posX && posX < 0.2) {
109  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
110  sum_clsize = clsMap[1];
111  }
112  if(0.2 <= posX && posX < 0.4) {
113  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
114  sum_clsize = clsMap[2];
115  }
116  if(0.4 <= posX && posX < 0.6) {
117  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
118  sum_clsize = clsMap[3];
119  }
120  if(0.6 <= posX && posX < 0.8) {
121  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
122  sum_clsize = clsMap[4];
123  }
124  if(0.8 <= posX && posX < 1.0) {
125  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
126  sum_clsize = clsMap[5];
127  }
128 
129  for(vector<double>::iterator iter = sum_clsize.begin();
130  iter != sum_clsize.end(); ++iter){
131  cnt++;
132  if(func > (*iter)){
133  min = cnt;
134  }
135  else if(func < (*iter)){
136  max = cnt;
137  break;
138  }
139  }
140  return min;
141 }
142 
143 
144 void
146  const edm::PSimHitContainer& rpcHits)
147 {
150  theDetectorHitMap.clear();
152 
153  const Topology& topology=roll->specs()->topology();
154 
155  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
156  _hit != rpcHits.end(); ++_hit){
157 
158  // Here I hould check if the RPC are up side down;
159  const LocalPoint& entr=_hit->entryPoint();
160  int time_hit = _rpcSync->getSimHitBx(&(*_hit));
161  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
162 
163  // Effinciecy
164 
165  if (flatDistribution->fire() < aveEff) {
166 
167  int centralStrip = topology.channel(entr)+1;
168  int fstrip=centralStrip;
169  int lstrip=centralStrip;
170  // Compute the cluster size
171  double w = flatDistribution->fire(1);
172  if (w < 1.e-10) w=1.e-10;
173  int clsize = this->getClSize(posX);
174 
175  std::vector<int> cls;
176  cls.push_back(centralStrip);
177  if (clsize > 1){
178  for (int cl = 0; cl < (clsize-1)/2; cl++)
179  {
180  if (centralStrip - cl -1 >= 1 ){
181  fstrip = centralStrip-cl-1;
182  cls.push_back(fstrip);
183  }
184  if (centralStrip + cl + 1 <= roll->nstrips() ){
185  lstrip = centralStrip+cl+1;
186  cls.push_back(lstrip);
187  }
188  }
189  if (clsize%2 == 0 ){
190  // insert the last strip according to the
191  // simhit position in the central strip
192  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
193  if (deltaw<0.) {
194  if (lstrip < roll->nstrips() ){
195  lstrip++;
196  cls.push_back(lstrip);
197  }
198  }else{
199  if (fstrip > 1 ){
200  fstrip--;
201  cls.push_back(fstrip);
202  }
203  }
204  }
205  }
206 
207  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
208  // Check the timing of the adjacent strip
209  std::pair<int, int> digi(*i,time_hit );
210 
211  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
212  strips.insert(digi);
213  }
214  }
215  }
216 }
217 
219 {
220  RPCDetId rpcId = roll->id();
221  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
222  unsigned int nstrips = roll->nstrips();
223 
224  double area = 0.0;
225 
226  if ( rpcId.region() == 0 )
227  {
228  const RectangularStripTopology* top_ = dynamic_cast<const
229  RectangularStripTopology*>(&(roll->topology()));
230  float xmin = (top_->localPosition(0.)).x();
231  float xmax = (top_->localPosition((float)roll->nstrips())).x();
232  float striplength = (top_->stripLength());
233  area = striplength*(xmax-xmin);
234  }
235  else
236  {
237  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
238  float xmin = (top_->localPosition(0.)).x();
239  float xmax = (top_->localPosition((float)roll->nstrips())).x();
240  float striplength = (top_->stripLength());
241  area = striplength*(xmax-xmin);
242  }
243  for(unsigned int j = 0; j < vnoise.size(); ++j){
244 
245  if(j >= nstrips) break;
246 
247  double ave = frate*vnoise[j]*nbxing*gate*area*1.0e-9;
248  N_hits = poissonDistribution_->fire(ave);
249 
250  for (int i = 0; i < N_hits; i++ ){
251  int time_hit = (static_cast<int>(flatDistribution2->fire((nbxing*gate)/gate))) - nbxing/2;
252  std::pair<int, int> digi(j+1,time_hit);
253  strips.insert(digi);
254  }
255  }
256 }
T getParameter(std::string const &) const
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:71
int i
Definition: DBlmapReader.cc:9
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
CLHEP::RandFlat * flatDistribution2
const Topology & topology() const
Definition: RPCRoll.cc:30
virtual float stripLength() const
DetectorHitMap theDetectorHitMap
Definition: RPCSim.h:68
void setRPCSimSetUp(RPCSimSetUp *simsetup)
int nstrips() const
Definition: RPCRoll.cc:46
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:47
#define min(a, b)
Definition: mlp_lapack.h:161
Container::value_type value_type
const RPCRollSpecs * specs() const
Definition: RPCRoll.cc:18
void simulateNoise(const RPCRoll *)
void setRandomEngine(CLHEP::HepRandomEngine &eng)
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:57
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
int getClSize(float posX)
std::map< int, std::vector< double > > clsMap
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:32
RPCDetId id() const
Definition: RPCRoll.cc:24
const T & max(const T &a, const T &b)
const std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:197
int j
Definition: DBlmapReader.cc:9
Definition: RPCSim.h:27
RPCSimAverageNoise(const edm::ParameterSet &config)
int getSimHitBx(const PSimHit *)
void setRandomEngine(CLHEP::HepRandomEngine &eng)
CLHEP::RandFlat * flatDistribution
RPCSynchronizer * _rpcSync
string const
Definition: compareJSON.py:14
virtual LocalPoint localPosition(float strip) const
tuple config
Definition: cmsDriver.py:17
CLHEP::RandPoissonQ * poissonDistribution_
void clear()
Definition: DetSet.h:59
tuple cout
Definition: gather_cfg.py:41
std::vector< PSimHit > PSimHitContainer
virtual LocalPoint localPosition(float strip) const
T x() const
Definition: PV3DBase.h:56
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits)
virtual float stripLength() const
det heigth (strip length in the middle)
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
std::vector< double > sum_clsize
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:65