CMS 3D CMS Logo

RPCSimAverage.cc
Go to the documentation of this file.
4 
8 
9 #include <cmath>
10 
16 
23 
24 #include <cstring>
25 #include <iostream>
26 #include <fstream>
27 #include <string>
28 #include <vector>
29 #include <cstdlib>
30 #include <utility>
31 #include <map>
32 
33 #include "CLHEP/Random/RandFlat.h"
34 #include "CLHEP/Random/RandPoissonQ.h"
35 
36 using namespace std;
37 
39  aveEff = config.getParameter<double>("averageEfficiency");
40  aveCls = config.getParameter<double>("averageClusterSize");
41  resRPC = config.getParameter<double>("timeResolution");
42  timOff = config.getParameter<double>("timingRPCOffset");
43  dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
44  resEle = config.getParameter<double>("timeJitter");
45  sspeed = config.getParameter<double>("signalPropagationSpeed");
46  lbGate = config.getParameter<double>("linkGateWidth");
47  rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
48  rate = config.getParameter<double>("Rate");
49  nbxing = config.getParameter<int>("Nbxing");
50  gate = config.getParameter<double>("Gate");
51 
52  if (rpcdigiprint) {
53  std::cout << "Average Efficiency = " << aveEff << std::endl;
54  std::cout << "Average Cluster Size = " << aveCls << " strips" << std::endl;
55  std::cout << "RPC Time Resolution = " << resRPC << " ns" << std::endl;
56  std::cout << "RPC Signal formation time = " << timOff << " ns" << std::endl;
57  std::cout << "RPC adjacent strip delay = " << dtimCs << " ns" << std::endl;
58  std::cout << "Electronic Jitter = " << resEle << " ns" << std::endl;
59  std::cout << "Signal propagation time = " << sspeed << " x c" << std::endl;
60  std::cout << "Link Board Gate Width = " << lbGate << " ns" << std::endl;
61  }
62 
64 }
65 
67 
68 int RPCSimAverage::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
69  std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
70 
71  int cnt = 1;
72  int min = 1;
73  double func = 0.0;
74  std::vector<double> sum_clsize;
75 
76  double rr_cl = CLHEP::RandFlat::shoot(engine);
77  if (0.0 <= posX && posX < 0.2) {
78  func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
79  sum_clsize = clsMap[1];
80  }
81  if (0.2 <= posX && posX < 0.4) {
82  func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
83  sum_clsize = clsMap[2];
84  }
85  if (0.4 <= posX && posX < 0.6) {
86  func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
87  sum_clsize = clsMap[3];
88  }
89  if (0.6 <= posX && posX < 0.8) {
90  func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
91  sum_clsize = clsMap[4];
92  }
93  if (0.8 <= posX && posX < 1.0) {
94  func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
95  sum_clsize = clsMap[5];
96  }
97 
98  for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
99  cnt++;
100  if (func > (*iter)) {
101  min = cnt;
102  } else if (func < (*iter)) {
103  break;
104  }
105  }
106  return min;
107 }
108 
110  const edm::PSimHitContainer& rpcHits,
111  CLHEP::HepRandomEngine* engine) {
114  theDetectorHitMap.clear();
116 
117  const Topology& topology = roll->specs()->topology();
118 
119  for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
120  // Here I hould check if the RPC are up side down;
121  const LocalPoint& entr = _hit->entryPoint();
122 
123  // const LocalPoint& exit=_hit->exitPoint();
124 
125  float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
126  int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
127 
128  // Effinciecy
129 
130  if (CLHEP::RandFlat::shoot(engine) < aveEff) {
131  int centralStrip = topology.channel(entr) + 1;
132  int fstrip = centralStrip;
133  int lstrip = centralStrip;
134  // Compute the cluster size
135  //double w = CLHEP::RandFlat::shoot(engine);
136  //if (w < 1.e-10) w=1.e-10;
137  int clsize = this->getClSize(posX, engine);
138 
139  std::vector<int> cls;
140  cls.push_back(centralStrip);
141  if (clsize > 1) {
142  for (int cl = 0; cl < (clsize - 1) / 2; cl++)
143  if (centralStrip - cl - 1 >= 1) {
144  fstrip = centralStrip - cl - 1;
145  cls.push_back(fstrip);
146  }
147  for (int cl = 0; cl < (clsize - 1) / 2; cl++)
148  if (centralStrip + cl + 1 <= roll->nstrips()) {
149  lstrip = centralStrip + cl + 1;
150  cls.push_back(lstrip);
151  }
152  if (clsize % 2 == 0) {
153  // insert the last strip according to the
154  // simhit position in the central strip
155  double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
156  if (deltaw < 0.) {
157  if (lstrip < roll->nstrips()) {
158  lstrip++;
159  cls.push_back(lstrip);
160  }
161  } else {
162  if (fstrip > 1) {
163  fstrip--;
164  cls.push_back(fstrip);
165  }
166  }
167  }
168  }
169 
170  for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
171  // Check the timing of the adjacent strip
172  std::pair<int, int> digi(*i, time_hit);
173  theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
174  strips.insert(digi);
175  }
176  }
177  }
178 }
179 
180 void RPCSimAverage::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
181  RPCDetId rpcId = roll->id();
182  int nstrips = roll->nstrips();
183  double area = 0.0;
184 
185  if (rpcId.region() == 0) {
186  const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
187  float xmin = (top_->localPosition(0.)).x();
188  float xmax = (top_->localPosition((float)roll->nstrips())).x();
189  float striplength = (top_->stripLength());
190  area = striplength * (xmax - xmin);
191  } else {
192  const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
193  float xmin = (top_->localPosition(0.)).x();
194  float xmax = (top_->localPosition((float)roll->nstrips())).x();
195  float striplength = (top_->stripLength());
196  area = striplength * (xmax - xmin);
197  }
198 
199  double ave = rate * nbxing * gate * area * 1.0e-9;
200 
201  CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
202  N_hits = randPoissonQ.fire();
203 
204  for (int i = 0; i < N_hits; i++) {
205  int strip = static_cast<int>(CLHEP::RandFlat::shoot(engine, 1, nstrips));
206  int time_hit;
207  time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
208  std::pair<int, int> digi(strip, time_hit);
209  strips.insert(digi);
210  }
211 }
RPCRoll
Definition: RPCRoll.h:12
RPCSynchronizer::setRPCSimSetUp
void setRPCSimSetUp(RPCSimSetUp *simsetup)
Definition: RPCSynchronizer.h:43
RPCSimAverage::resEle
double resEle
Definition: RPCSimAverage.h:47
RPCSim::getRPCSimSetUp
RPCSimSetUp * getRPCSimSetUp()
Definition: RPCSim.h:45
mps_fire.i
i
Definition: mps_fire.py:428
TrapezoidalStripTopology::stripLength
float stripLength() const override
det heigth (strip length in the middle)
Definition: TrapezoidalStripTopology.h:63
RPCDetId::region
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
RPCSimAverage::RPCSimAverage
RPCSimAverage(const edm::ParameterSet &config)
Definition: RPCSimAverage.cc:38
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
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
RPCDetId
Definition: RPCDetId.h:16
RPCSimAverage::getClSize
int getClSize(float posX, CLHEP::HepRandomEngine *)
Definition: RPCSimAverage.cc:68
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RPCSynchronizer
Definition: RPCSynchronizer.h:36
PSimHitContainer.h
RPCSimAverage::clsMap
std::map< int, std::vector< double > > clsMap
Definition: RPCSimAverage.h:57
RPCSynchronizer::getSimHitBx
int getSimHitBx(const PSimHit *, CLHEP::HepRandomEngine *)
Definition: RPCSynchronizer.cc:57
RPCSimAverage::aveCls
double aveCls
Definition: RPCSimAverage.h:43
RPCRoll.h
RPCSimAverage::nbxing
int nbxing
Definition: RPCSimAverage.h:53
RPCSimAverage::lbGate
double lbGate
Definition: RPCSimAverage.h:49
EDAnalyzer.h
DDAxes::x
RPCSim::strips
std::set< std::pair< int, int > > strips
Definition: RPCSim.h:55
RectangularStripTopology.h
RPCSimAverage::simulate
void simulate(const RPCRoll *roll, const edm::PSimHitContainer &rpcHits, CLHEP::HepRandomEngine *) override
Definition: RPCSimAverage.cc:109
RectangularStripTopology::localPosition
LocalPoint localPosition(float strip) const override
Definition: RectangularStripTopology.cc:17
RPCRoll::topology
const Topology & topology() const override
Definition: RPCRoll.cc:18
RPCSimAverage::rate
double rate
Definition: RPCSimAverage.h:54
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
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
RPCSim::theRpcDigiSimLinks
RPCDigiSimLinks theRpcDigiSimLinks
Definition: RPCSim.h:70
RPCSimAverage::N_hits
int N_hits
Definition: RPCSimAverage.h:52
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:411
RPCSimAverage.h
Point3DBase< float, LocalTag >
RPCRoll::strip
float strip(const LocalPoint &lp) const
Definition: RPCRoll.cc:35
RPCSimAverage::gate
double gate
Definition: RPCSimAverage.h:55
RPCDetId.h
RPCSimAverage::sspeed
double sspeed
Definition: RPCSimAverage.h:48
RPCRoll::centreOfStrip
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:26
RPCSimAverage::sum_clsize
std::vector< double > sum_clsize
Definition: RPCSimAverage.h:58
RectangularStripTopology::stripLength
float stripLength() const override
Definition: RectangularStripTopology.h:44
RPCRollSpecs.h
RPCSimAverage::dtimCs
double dtimCs
Definition: RPCSimAverage.h:46
RPCSimAverage::~RPCSimAverage
~RPCSimAverage() override
Definition: RPCSimAverage.cc:66
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
RPCRoll::nstrips
int nstrips() const
Definition: RPCRoll.cc:24
RPCSimAverage::timOff
double timOff
Definition: RPCSimAverage.h:45
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
RPCSimAverage::aveEff
double aveEff
Definition: RPCSimAverage.h:39
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
TrapezoidalStripTopology.h
RPCSimAverage::_rpcSync
RPCSynchronizer * _rpcSync
Definition: RPCSimAverage.h:61
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
RPCSimAverage::resRPC
double resRPC
Definition: RPCSimAverage.h:44
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
RPCSimAverage::rpcdigiprint
bool rpcdigiprint
Definition: RPCSimAverage.h:50
RPCSim::RPCDigiSimLinks
edm::DetSet< RPCDigiSimLink > RPCDigiSimLinks
Definition: RPCSim.h:33
custom_jme_cff.area
area
Definition: custom_jme_cff.py:140
RPCGeometry.h
RPCSynchronizer.h
RPCSimAverage::simulateNoise
void simulateNoise(const RPCRoll *, CLHEP::HepRandomEngine *) override
Definition: RPCSimAverage.cc:180