Go to the documentation of this file.00001 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00002 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h"
00003 #include "SimMuon/RPCDigitizer/src/RPCSimAverageNoiseEffCls.h"
00004 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
00005
00006 #include "SimMuon/RPCDigitizer/src/RPCSynchronizer.h"
00007 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00008 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00009 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00010
00011 #include <cmath>
00012 #include "FWCore/ServiceRegistry/interface/Service.h"
00013 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00014 #include "FWCore/Utilities/interface/Exception.h"
00015 #include "CLHEP/Random/RandomEngine.h"
00016 #include "CLHEP/Random/RandFlat.h"
00017 #include <CLHEP/Random/RandGaussQ.h>
00018 #include <CLHEP/Random/RandFlat.h>
00019
00020 #include <FWCore/Framework/interface/Frameworkfwd.h>
00021 #include <FWCore/Framework/interface/EventSetup.h>
00022 #include <FWCore/Framework/interface/EDAnalyzer.h>
00023 #include <FWCore/Framework/interface/Event.h>
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025 #include <FWCore/Framework/interface/ESHandle.h>
00026
00027 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00028 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00029 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00030 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00031 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00032 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
00033
00034 #include<cstring>
00035 #include<iostream>
00036 #include<fstream>
00037 #include<string>
00038 #include<vector>
00039 #include<stdlib.h>
00040 #include <utility>
00041 #include <map>
00042
00043
00044 #include "CLHEP/Random/Random.h"
00045 #include "CLHEP/Random/RandFlat.h"
00046 #include "CLHEP/Random/RandPoissonQ.h"
00047
00048 using namespace std;
00049
00050 RPCSimAverageNoiseEffCls::RPCSimAverageNoiseEffCls(const edm::ParameterSet& config) :
00051 RPCSim(config)
00052 {
00053
00054 aveEff = config.getParameter<double>("averageEfficiency");
00055 aveCls = config.getParameter<double>("averageClusterSize");
00056 resRPC = config.getParameter<double>("timeResolution");
00057 timOff = config.getParameter<double>("timingRPCOffset");
00058 dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
00059 resEle = config.getParameter<double>("timeJitter");
00060 sspeed = config.getParameter<double>("signalPropagationSpeed");
00061 lbGate = config.getParameter<double>("linkGateWidth");
00062 rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
00063
00064 rate=config.getParameter<double>("Rate");
00065 nbxing=config.getParameter<int>("Nbxing");
00066 gate=config.getParameter<double>("Gate");
00067 frate=config.getParameter<double>("Frate");
00068
00069 if (rpcdigiprint) {
00070 std::cout <<"Average Efficiency = "<<aveEff<<std::endl;
00071 std::cout <<"Average Cluster Size = "<<aveCls<<" strips"<<std::endl;
00072 std::cout <<"RPC Time Resolution = "<<resRPC<<" ns"<<std::endl;
00073 std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
00074 std::cout <<"RPC adjacent strip delay = "<<dtimCs<<" ns"<<std::endl;
00075 std::cout <<"Electronic Jitter = "<<resEle<<" ns"<<std::endl;
00076 std::cout <<"Signal propagation time = "<<sspeed<<" x c"<<std::endl;
00077 std::cout <<"Link Board Gate Width = "<<lbGate<<" ns"<<std::endl;
00078 }
00079
00080 _rpcSync = new RPCSynchronizer(config);
00081
00082 }
00083
00084 void RPCSimAverageNoiseEffCls::setRandomEngine(CLHEP::HepRandomEngine& eng){
00085 flatDistribution = new CLHEP::RandFlat(eng);
00086 flatDistribution2 = new CLHEP::RandFlat(eng);
00087 poissonDistribution_ = new CLHEP::RandPoissonQ(eng);
00088 _rpcSync->setRandomEngine(eng);
00089 }
00090
00091 RPCSimAverageNoiseEffCls::~RPCSimAverageNoiseEffCls()
00092 {
00093
00094 delete flatDistribution;
00095 delete flatDistribution2;
00096 delete poissonDistribution_;
00097 delete _rpcSync;
00098 }
00099
00100
00101 int RPCSimAverageNoiseEffCls::getClSize(uint32_t id,float posX)
00102 {
00103 std::vector<double> clsForDetId = getRPCSimSetUp()->getCls(id);
00104
00105 int cnt = 1;
00106 int min = 1;
00107 int max = 1;
00108 double func=0.0;
00109 std::vector<double> sum_clsize;
00110
00111 sum_clsize.clear();
00112 sum_clsize = clsForDetId;
00113 int vectOffset(0);
00114
00115 double rr_cl = flatDistribution->fire(1);
00116
00117 if(0.0 <= posX && posX < 0.2) {
00118 func = clsForDetId[19]*(rr_cl);
00119 vectOffset = 0;
00120 }
00121 if(0.2 <= posX && posX < 0.4) {
00122 func = clsForDetId[39]*(rr_cl);
00123 vectOffset = 20;
00124 }
00125 if(0.4 <= posX && posX < 0.6) {
00126 func = clsForDetId[59]*(rr_cl);
00127 vectOffset = 40;
00128 }
00129 if(0.6 <= posX && posX < 0.8) {
00130 func = clsForDetId[79]*(rr_cl);
00131 vectOffset = 60;
00132 }
00133 if(0.8 <= posX && posX < 1.0) {
00134 func = clsForDetId[89]*(rr_cl);
00135 vectOffset = 80;
00136 }
00137
00138
00139 for(int i = vectOffset; i<(vectOffset+20); i++){
00140 cnt++;
00141 if(func > clsForDetId[i]){
00142 min = cnt;
00143 }
00144 else if(func < clsForDetId[i]){
00145 max = cnt;
00146 break;
00147 }
00148 }
00149 return min;
00150 }
00151
00152 int RPCSimAverageNoiseEffCls::getClSize(float posX)
00153 {
00154
00155 std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
00156
00157 int cnt = 1;
00158 int min = 1;
00159 int max = 1;
00160 double func=0.0;
00161 std::vector<double> sum_clsize;
00162
00163 double rr_cl = flatDistribution->fire(1);
00164 if(0.0 <= posX && posX < 0.2) {
00165 func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
00166 sum_clsize = clsMap[1];
00167 }
00168 if(0.2 <= posX && posX < 0.4) {
00169 func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
00170 sum_clsize = clsMap[2];
00171 }
00172 if(0.4 <= posX && posX < 0.6) {
00173 func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
00174 sum_clsize = clsMap[3];
00175 }
00176 if(0.6 <= posX && posX < 0.8) {
00177 func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
00178 sum_clsize = clsMap[4];
00179 }
00180 if(0.8 <= posX && posX < 1.0) {
00181 func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
00182 sum_clsize = clsMap[5];
00183 }
00184
00185 for(vector<double>::iterator iter = sum_clsize.begin();
00186 iter != sum_clsize.end(); ++iter){
00187 cnt++;
00188 if(func > (*iter)){
00189 min = cnt;
00190 }
00191 else if(func < (*iter)){
00192 max = cnt;
00193 break;
00194 }
00195 }
00196 return min;
00197 }
00198
00199 void
00200 RPCSimAverageNoiseEffCls::simulate(const RPCRoll* roll,
00201 const edm::PSimHitContainer& rpcHits)
00202 {
00203
00204 _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
00205 theRpcDigiSimLinks.clear();
00206 theDetectorHitMap.clear();
00207 theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
00208
00209 RPCDetId rpcId = roll->id();
00210 RPCGeomServ RPCname(rpcId);
00211 std::string nameRoll = RPCname.name();
00212
00213 const Topology& topology=roll->specs()->topology();
00214
00215 for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
00216 _hit != rpcHits.end(); ++_hit){
00217
00218 if(_hit-> particleType() == 11) continue;
00219
00220
00221 const LocalPoint& entr=_hit->entryPoint();
00222
00223 int time_hit = _rpcSync->getSimHitBx(&(*_hit));
00224 float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
00225
00226 std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
00227
00228
00229 int centralStrip = topology.channel(entr)+1;;
00230 float fire = flatDistribution->fire(1);
00231
00232 if (fire < veff[centralStrip-1]) {
00233
00234 int fstrip=centralStrip;
00235 int lstrip=centralStrip;
00236
00237
00238 double w = flatDistribution->fire(1);
00239 if (w < 1.e-10) w=1.e-10;
00240
00241 int clsize = this->getClSize(rpcId.rawId(),posX);
00242 std::vector<int> cls;
00243 cls.push_back(centralStrip);
00244 if (clsize > 1){
00245 for (int cl = 0; cl < (clsize-1)/2; cl++){
00246 if (centralStrip - cl -1 >= 1 ){
00247 fstrip = centralStrip-cl-1;
00248 cls.push_back(fstrip);
00249 }
00250 if (centralStrip + cl + 1 <= roll->nstrips() ){
00251 lstrip = centralStrip+cl+1;
00252 cls.push_back(lstrip);
00253 }
00254 }
00255 if (clsize%2 == 0 ){
00256
00257
00258 double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
00259 if (deltaw<0.) {
00260 if (lstrip < roll->nstrips() ){
00261 lstrip++;
00262 cls.push_back(lstrip);
00263 }
00264 }else{
00265 if (fstrip > 1 ){
00266 fstrip--;
00267 cls.push_back(fstrip);
00268 }
00269 }
00270 }
00271 }
00272
00273 for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
00274
00275 if(*i != centralStrip){
00276 if(flatDistribution->fire(1) < veff[*i-1]){
00277 std::pair<int, int> digi(*i,time_hit);
00278 strips.insert(digi);
00279
00280 theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00281 }
00282 }
00283 else {
00284 std::pair<int, int> digi(*i,time_hit);
00285 theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00286
00287 strips.insert(digi);
00288 }
00289 }
00290 }
00291 }
00292 }
00293
00294 void RPCSimAverageNoiseEffCls::simulateNoise(const RPCRoll* roll)
00295 {
00296
00297 RPCDetId rpcId = roll->id();
00298
00299 RPCGeomServ RPCname(rpcId);
00300 std::string nameRoll = RPCname.name();
00301
00302 std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
00303 std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
00304
00305 unsigned int nstrips = roll->nstrips();
00306 double area = 0.0;
00307
00308 if ( rpcId.region() == 0 )
00309 {
00310 const RectangularStripTopology* top_ = dynamic_cast<const
00311 RectangularStripTopology*>(&(roll->topology()));
00312 float xmin = (top_->localPosition(0.)).x();
00313 float xmax = (top_->localPosition((float)roll->nstrips())).x();
00314 float striplength = (top_->stripLength());
00315 area = striplength*(xmax-xmin);
00316 }
00317 else
00318 {
00319 const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
00320 float xmin = (top_->localPosition(0.)).x();
00321 float xmax = (top_->localPosition((float)roll->nstrips())).x();
00322 float striplength = (top_->stripLength());
00323 area = striplength*(xmax-xmin);
00324 }
00325
00326 for(unsigned int j = 0; j < vnoise.size(); ++j){
00327
00328 if(j >= nstrips) break;
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 double ave =
00339 vnoise[j]*nbxing*gate*area*1.0e-9*frate/((float)roll->nstrips());
00340
00341 N_hits = poissonDistribution_->fire(ave);
00342
00343 for (int i = 0; i < N_hits; i++ ){
00344
00345 int time_hit = (static_cast<int>(flatDistribution2->fire((nbxing*gate)/gate))) - nbxing/2;
00346 std::pair<int, int> digi(j+1,time_hit);
00347 strips.insert(digi);
00348 }
00349 }
00350 }
00351