CMS 3D CMS Logo

RPCSimAverageNoiseEff.cc

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/RPCSimAverageNoiseEff.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 #include "CLHEP/config/CLHEP.h"
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 RPCSimAverageNoiseEff::RPCSimAverageNoiseEff(const edm::ParameterSet& config) : 
00051   RPCSim(config)
00052 {
00053   _rpcSync = new RPCSynchronizer(config);
00054 
00055   aveEff = config.getParameter<double>("averageEfficiency");
00056   aveCls = config.getParameter<double>("averageClusterSize");
00057   resRPC = config.getParameter<double>("timeResolution");
00058   timOff = config.getParameter<double>("timingRPCOffset");
00059   dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
00060   resEle = config.getParameter<double>("timeJitter");
00061   sspeed = config.getParameter<double>("signalPropagationSpeed");
00062   lbGate = config.getParameter<double>("linkGateWidth");
00063   rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
00064 
00065   rate=config.getParameter<double>("Rate");
00066   nbxing=config.getParameter<int>("Nbxing");
00067   gate=config.getParameter<double>("Gate");
00068   frate=config.getParameter<double>("Frate");
00069 
00070   if (rpcdigiprint) {
00071     std::cout <<"Average Efficiency        = "<<aveEff<<std::endl;
00072     std::cout <<"Average Cluster Size      = "<<aveCls<<" strips"<<std::endl;
00073     std::cout <<"RPC Time Resolution       = "<<resRPC<<" ns"<<std::endl;
00074     std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
00075     std::cout <<"RPC adjacent strip delay  = "<<dtimCs<<" ns"<<std::endl;
00076     std::cout <<"Electronic Jitter         = "<<resEle<<" ns"<<std::endl;
00077     std::cout <<"Signal propagation time   = "<<sspeed<<" x c"<<std::endl;
00078     std::cout <<"Link Board Gate Width     = "<<lbGate<<" ns"<<std::endl;
00079   }
00080 
00081   edm::Service<edm::RandomNumberGenerator> rng;
00082   if ( ! rng.isAvailable()) {
00083     throw cms::Exception("Configuration")
00084       << "RPCDigitizer requires the RandomNumberGeneratorService\n"
00085       "which is not present in the configuration file.  You must add the service\n"
00086       "in the configuration file or remove the modules that require it.";
00087   }
00088   
00089   rndEngine = &(rng->getEngine());
00090   flatDistribution = new CLHEP::RandFlat(rndEngine);
00091 }
00092 
00093 RPCSimAverageNoiseEff::~RPCSimAverageNoiseEff(){}
00094 
00095 int RPCSimAverageNoiseEff::getClSize(float posX)
00096 {
00097 
00098   std::map< int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
00099 
00100   int cnt = 1;
00101   int min = 1;
00102   int max = 1;
00103   double func=0.0;
00104   std::vector<double> sum_clsize;
00105 
00106   double rr_cl = flatDistribution->fire(1);
00107   if(0.0 <= posX && posX < 0.2)  {
00108     func = (clsMap[1])[(clsMap[1]).size()-1]*(rr_cl);
00109     sum_clsize = clsMap[1];
00110   }
00111   if(0.2 <= posX && posX < 0.4) {
00112     func = (clsMap[2])[(clsMap[2]).size()-1]*(rr_cl);
00113     sum_clsize = clsMap[2];
00114   }
00115   if(0.4 <= posX && posX < 0.6) {
00116     func = (clsMap[3])[(clsMap[3]).size()-1]*(rr_cl);
00117     sum_clsize = clsMap[3];
00118   }
00119   if(0.6 <= posX && posX < 0.8) {
00120     func = (clsMap[4])[(clsMap[4]).size()-1]*(rr_cl);
00121     sum_clsize = clsMap[4];
00122   }
00123   if(0.8 <= posX && posX < 1.0)  {
00124     func = (clsMap[5])[(clsMap[5]).size()-1]*(rr_cl);
00125     sum_clsize = clsMap[5];
00126   }
00127 
00128   for(vector<double>::iterator iter = sum_clsize.begin();
00129       iter != sum_clsize.end(); ++iter){
00130     cnt++;
00131     if(func > (*iter)){
00132       min = cnt;
00133     }
00134     else if(func < (*iter)){
00135       max = cnt;
00136       break;
00137     }
00138   }
00139   return min;
00140 }
00141 
00142 void
00143 RPCSimAverageNoiseEff::simulate(const RPCRoll* roll,
00144                         const edm::PSimHitContainer& rpcHits)
00145 {
00146 
00147   _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
00148   theRpcDigiSimLinks.clear();
00149   theDetectorHitMap.clear();
00150   theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
00151 
00152   RPCDetId rpcId = roll->id();
00153   RPCGeomServ RPCname(rpcId);
00154   std::string nameRoll = RPCname.name();
00155 
00156   const Topology& topology=roll->specs()->topology();
00157 
00158   for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
00159        _hit != rpcHits.end(); ++_hit){
00160 
00161     if(abs(_hit-> particleType()) != 13) continue;
00162 
00163     // Here I hould check if the RPC are up side down;
00164     const LocalPoint& entr=_hit->entryPoint();
00165 
00166     int time_hit = _rpcSync->getSimHitBx(&(*_hit));
00167     float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
00168 
00169     std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
00170 
00171     // Effinciecy
00172     int centralStrip = topology.channel(entr)+1;;
00173     float fire = flatDistribution->fire(1);
00174 
00175     if (fire < veff[centralStrip-1]) {
00176 
00177       int fstrip=centralStrip;
00178       int lstrip=centralStrip;
00179 
00180       // Compute the cluster size
00181       double w = flatDistribution->fire(1);
00182       if (w < 1.e-10) w=1.e-10;
00183       int clsize = this->getClSize(posX);
00184 
00185       std::vector<int> cls;
00186       cls.push_back(centralStrip);
00187       if (clsize > 1){
00188         for (int cl = 0; cl < (clsize-1)/2; cl++)
00189           if (centralStrip - cl -1 >= 1  ){
00190             fstrip = centralStrip-cl-1;
00191             cls.push_back(fstrip);
00192           }
00193         for (int cl = 0; cl < (clsize-1)/2; cl++)
00194           if (centralStrip + cl + 1 <= roll->nstrips() ){
00195             lstrip = centralStrip+cl+1;
00196             cls.push_back(lstrip);
00197           }
00198         if (clsize%2 == 0 ){
00199           // insert the last strip according to the 
00200           // simhit position in the central strip 
00201           double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
00202           if (deltaw<0.) {
00203             if (lstrip < roll->nstrips() ){
00204               lstrip++;
00205               cls.push_back(lstrip);
00206             }
00207           }else{
00208             if (fstrip > 1 ){
00209               fstrip--;
00210               cls.push_back(fstrip);
00211             }
00212           }
00213         }
00214       }
00215 
00216       for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
00217         // Check the timing of the adjacent strip
00218         if(*i != centralStrip){
00219           if(flatDistribution->fire(1) < veff[*i-1]){
00220             std::pair<int, int> digi(*i,time_hit);
00221             strips.insert(digi);
00222 
00223             theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00224           }
00225         } 
00226         else {
00227           std::pair<int, int> digi(*i,time_hit);
00228           theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00229 
00230           strips.insert(digi);
00231         }
00232       }
00233     }
00234   }
00235 }
00236 
00237 void RPCSimAverageNoiseEff::simulateNoise(const RPCRoll* roll)
00238 {
00239 
00240   RPCDetId rpcId = roll->id();
00241 
00242   RPCGeomServ RPCname(rpcId);
00243   std::string nameRoll = RPCname.name();
00244 
00245   std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
00246   std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
00247 
00248   unsigned int nstrips = roll->nstrips();
00249   double area = 0.0;
00250   
00251   if ( rpcId.region() == 0 )
00252     {
00253       const RectangularStripTopology* top_ = dynamic_cast<const
00254         RectangularStripTopology*>(&(roll->topology()));
00255       float xmin = (top_->localPosition(0.)).x();
00256       float xmax = (top_->localPosition((float)roll->nstrips())).x();
00257       float striplength = (top_->stripLength());
00258       area = striplength*(xmax-xmin);
00259     }
00260   else
00261     {
00262       const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
00263       float xmin = (top_->localPosition(0.)).x();
00264       float xmax = (top_->localPosition((float)roll->nstrips())).x();
00265       float striplength = (top_->stripLength());
00266       area = striplength*(xmax-xmin);
00267     }
00268 
00269   for(unsigned int j = 0; j < vnoise.size(); ++j){
00270     
00271     if(j >= nstrips) break; 
00272     if(veff[j] == 0) continue;
00273 
00274     double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
00275     poissonDistribution_ = new CLHEP::RandPoissonQ(rndEngine, ave);
00276     N_hits = poissonDistribution_->fire();
00277 
00278     for (int i = 0; i < N_hits; i++ ){
00279       flatDistribution = new CLHEP::RandFlat(rndEngine, (nbxing*gate)/gate);
00280       int time_hit = (static_cast<int>(flatDistribution->fire())) - nbxing/2;
00281       std::pair<int, int> digi(j+1,time_hit);
00282       strips.insert(digi);
00283     }
00284   }
00285 }
00286 

Generated on Tue Jun 9 17:47:47 2009 for CMSSW by  doxygen 1.5.4