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  double func=0.0;
104  std::vector<double> sum_clsize;
105 
106  double rr_cl = flatDistribution->fire();
107  if(0.0 <= posX && posX < 0.2) {
108  func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
109  sum_clsize = clsMap[1];
110  }
111  if(0.2 <= posX && posX < 0.4) {
112  func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
113  sum_clsize = clsMap[2];
114  }
115  if(0.4 <= posX && posX < 0.6) {
116  func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
117  sum_clsize = clsMap[3];
118  }
119  if(0.6 <= posX && posX < 0.8) {
120  func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
121  sum_clsize = clsMap[4];
122  }
123  if(0.8 <= posX && posX < 1.0) {
124  func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
125  sum_clsize = clsMap[5];
126  }
127 
128  for(vector<double>::iterator iter = sum_clsize.begin();
129  iter != sum_clsize.end(); ++iter){
130  cnt++;
131  if(func > (*iter)){
132  min = cnt;
133  }
134  else if(func < (*iter)){
135  break;
136  }
137  }
138  return min;
139 }
140 
141 
142 void
144  const edm::PSimHitContainer& rpcHits)
145 {
148  theDetectorHitMap.clear();
150 
151  const Topology& topology=roll->specs()->topology();
152 
153  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
154  _hit != rpcHits.end(); ++_hit){
155 
156  // Here I hould check if the RPC are up side down;
157  const LocalPoint& entr=_hit->entryPoint();
158  int time_hit = _rpcSync->getSimHitBx(&(*_hit));
159  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
160 
161  // Effinciecy
162 
163  if (flatDistribution->fire() < aveEff) {
164 
165  int centralStrip = topology.channel(entr)+1;
166  int fstrip=centralStrip;
167  int lstrip=centralStrip;
168  // Compute the cluster size
169  double w = flatDistribution->fire(1);
170  if (w < 1.e-10) w=1.e-10;
171  int clsize = this->getClSize(posX);
172 
173  std::vector<int> cls;
174  cls.push_back(centralStrip);
175  if (clsize > 1){
176  for (int cl = 0; cl < (clsize-1)/2; cl++)
177  {
178  if (centralStrip - cl -1 >= 1 ){
179  fstrip = centralStrip-cl-1;
180  cls.push_back(fstrip);
181  }
182  if (centralStrip + cl + 1 <= roll->nstrips() ){
183  lstrip = centralStrip+cl+1;
184  cls.push_back(lstrip);
185  }
186  }
187  if (clsize%2 == 0 ){
188  // insert the last strip according to the
189  // simhit position in the central strip
190  double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
191  if (deltaw<0.) {
192  if (lstrip < roll->nstrips() ){
193  lstrip++;
194  cls.push_back(lstrip);
195  }
196  }else{
197  if (fstrip > 1 ){
198  fstrip--;
199  cls.push_back(fstrip);
200  }
201  }
202  }
203  }
204 
205  for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
206  // Check the timing of the adjacent strip
207  std::pair<int, int> digi(*i,time_hit );
208 
209  theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
210  strips.insert(digi);
211  }
212  }
213  }
214 }
215 
217 {
218  RPCDetId rpcId = roll->id();
219  std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
220  unsigned int nstrips = roll->nstrips();
221 
222  double area = 0.0;
223 
224  if ( rpcId.region() == 0 )
225  {
226  const RectangularStripTopology* top_ = dynamic_cast<const
227  RectangularStripTopology*>(&(roll->topology()));
228  float xmin = (top_->localPosition(0.)).x();
229  float xmax = (top_->localPosition((float)roll->nstrips())).x();
230  float striplength = (top_->stripLength());
231  area = striplength*(xmax-xmin);
232  }
233  else
234  {
235  const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
236  float xmin = (top_->localPosition(0.)).x();
237  float xmax = (top_->localPosition((float)roll->nstrips())).x();
238  float striplength = (top_->stripLength());
239  area = striplength*(xmax-xmin);
240  }
241  for(unsigned int j = 0; j < vnoise.size(); ++j){
242 
243  if(j >= nstrips) break;
244 
245  double ave = frate*vnoise[j]*nbxing*gate*area*1.0e-9;
246  N_hits = poissonDistribution_->fire(ave);
247 
248  for (int i = 0; i < N_hits; i++ ){
249  int time_hit = (static_cast<int>(flatDistribution2->fire((nbxing*gate)/gate))) - nbxing/2;
250  std::pair<int, int> digi(j+1,time_hit);
251  strips.insert(digi);
252  }
253  }
254 }
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
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 std::map< int, std::vector< double > > & getClsMap()
Definition: RPCSimSetUp.cc:195
int j
Definition: DBlmapReader.cc:9
Definition: RPCSim.h:27
Container::value_type value_type
RPCSimAverageNoise(const edm::ParameterSet &config)
float cl
Definition: Combine.cc:71
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
CLHEP::RandPoissonQ * poissonDistribution_
void clear()
Definition: DetSet.h:70
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
virtual LocalPoint localPosition(float strip) const
x
Definition: VDTMath.h:216
T x() const
Definition: PV3DBase.h:61
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
T w() const
const Topology & topology() const
Definition: RPCRollSpecs.cc:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:67