CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/SimMuon/RPCDigitizer/src/RPCSimParam.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/RPCSimParam.h"
00004 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00005 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00006 
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "CLHEP/Random/RandomEngine.h"
00011 #include "CLHEP/Random/RandFlat.h"
00012 #include <cmath>
00013 
00014 //#include "CLHEP/config/CLHEP.h"
00015 #include "CLHEP/Random/Random.h"
00016 #include "CLHEP/Random/RandFlat.h"
00017 #include "CLHEP/Random/RandPoissonQ.h"
00018 
00019 RPCSimParam::RPCSimParam(const edm::ParameterSet& config) : RPCSim(config){
00020   aveEff = config.getParameter<double>("averageEfficiency");
00021   aveCls = config.getParameter<double>("averageClusterSize");
00022   resRPC = config.getParameter<double>("timeResolution");
00023   timOff = config.getParameter<double>("timingRPCOffset");
00024   dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
00025   resEle = config.getParameter<double>("timeJitter");
00026   sspeed = config.getParameter<double>("signalPropagationSpeed");
00027   lbGate = config.getParameter<double>("linkGateWidth");
00028   rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
00029 
00030   rate=config.getParameter<double>("Rate");
00031   nbxing=config.getParameter<int>("Nbxing");
00032   gate=config.getParameter<double>("Gate");
00033 
00034   if (rpcdigiprint) {
00035     std::cout <<"Average Efficiency        = "<<aveEff<<std::endl;
00036     std::cout <<"Average Cluster Size      = "<<aveCls<<" strips"<<std::endl;
00037     std::cout <<"RPC Time Resolution       = "<<resRPC<<" ns"<<std::endl;
00038     std::cout <<"RPC Signal formation time = "<<timOff<<" ns"<<std::endl;
00039     std::cout <<"RPC adjacent strip delay  = "<<dtimCs<<" ns"<<std::endl;
00040     std::cout <<"Electronic Jitter         = "<<resEle<<" ns"<<std::endl;
00041     std::cout <<"Signal propagation time   = "<<sspeed<<" x c"<<std::endl;
00042     std::cout <<"Link Board Gate Width     = "<<lbGate<<" ns"<<std::endl;
00043   }
00044 
00045   _rpcSync = new RPCSynchronizer(config);
00046 }
00047 
00048 void RPCSimParam::setRandomEngine(CLHEP::HepRandomEngine& eng){
00049   flatDistribution_ = new CLHEP::RandFlat(eng);
00050   flatDistribution1 = new CLHEP::RandFlat(eng);                     
00051   flatDistribution2 = new CLHEP::RandFlat(eng);                                                                                                                                                         
00052   poissonDistribution = new CLHEP::RandPoissonQ(eng); 
00053   _rpcSync->setRandomEngine(eng);
00054 }
00055 
00056 
00057 RPCSimParam::~RPCSimParam(){
00058   delete flatDistribution_;
00059   delete flatDistribution1;  
00060   delete flatDistribution2;   
00061   delete poissonDistribution; 
00062   delete _rpcSync;
00063 }
00064 
00065 
00066 void
00067 RPCSimParam::simulate(const RPCRoll* roll,
00068                       const edm::PSimHitContainer& rpcHits)
00069 {
00070   _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
00071   theRpcDigiSimLinks.clear();
00072   theDetectorHitMap.clear();
00073   theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
00074 
00075   const Topology& topology=roll->specs()->topology();
00076 
00077   for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
00078        _hit != rpcHits.end(); ++_hit){
00079 
00080     // Here I hould check if the RPC are up side down;
00081     const LocalPoint& entr=_hit->entryPoint();
00082     int time_hit = _rpcSync->getSimHitBx(&(*_hit));
00083 
00084     // Effinciecy
00085     float eff = flatDistribution_->fire(1);
00086     if (eff < aveEff) {
00087 
00088       int centralStrip = topology.channel(entr)+1;  
00089       int fstrip=centralStrip;
00090       int lstrip=centralStrip;
00091       // Compute the cluster size
00092       double w = flatDistribution_->fire(1);
00093       if (w < 1.e-10) w=1.e-10;
00094       int clsize = static_cast<int>( -1.*aveCls*log(w)+1.);
00095       std::vector<int> cls;
00096       cls.push_back(centralStrip);
00097       if (clsize > 1){
00098         for (int cl = 0; cl < (clsize-1)/2; cl++)
00099           if (centralStrip - cl -1 >= 1  ){
00100             fstrip = centralStrip-cl-1;
00101             cls.push_back(fstrip);
00102           }
00103         for (int cl = 0; cl < (clsize-1)/2; cl++)
00104           if (centralStrip + cl + 1 <= roll->nstrips() ){
00105             lstrip = centralStrip+cl+1;
00106             cls.push_back(lstrip);
00107           }
00108         if (clsize%2 == 0 ){
00109           // insert the last strip according to the 
00110           // simhit position in the central strip 
00111           double deltaw=roll->centreOfStrip(centralStrip).x()-entr.x();
00112           if (deltaw<0.) {
00113             if (lstrip < roll->nstrips() ){
00114               lstrip++;
00115               cls.push_back(lstrip);
00116             }
00117           }else{
00118             if (fstrip > 1 ){
00119               fstrip--;
00120               cls.push_back(fstrip);
00121             }
00122           }
00123         }
00124       }
00125 
00126       for (std::vector<int>::iterator i=cls.begin(); i!=cls.end();i++){
00127         // Check the timing of the adjacent strip
00128         std::pair<unsigned int, int> digi(*i,time_hit);
00129 
00130         theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00131         strips.insert(digi);
00132       }
00133     }
00134   }
00135 }
00136 
00137 
00138 void RPCSimParam::simulateNoise(const RPCRoll* roll)
00139 {
00140 
00141   RPCDetId rpcId = roll->id();
00142   int nstrips = roll->nstrips();
00143   double area = 0.0;
00144   
00145   if ( rpcId.region() == 0 )
00146     {
00147       const RectangularStripTopology* top_ = dynamic_cast<const
00148         RectangularStripTopology*>(&(roll->topology()));
00149       float xmin = (top_->localPosition(0.)).x();
00150       float xmax = (top_->localPosition((float)roll->nstrips())).x();
00151       float striplength = (top_->stripLength());
00152       area = striplength*(xmax-xmin);
00153     }
00154   else
00155     {
00156       const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
00157       float xmin = (top_->localPosition(0.)).x();
00158       float xmax = (top_->localPosition((float)roll->nstrips())).x();
00159       float striplength = (top_->stripLength());
00160       area = striplength*(xmax-xmin);
00161     }
00162 
00163   double ave = rate*nbxing*gate*area*1.0e-9;
00164   
00165   N_hits = poissonDistribution->fire(ave);
00166 
00167   for (int i = 0; i < N_hits; i++ ){   
00168     int strip = static_cast<int>(flatDistribution1->fire(1,nstrips));
00169     int time_hit;
00170     time_hit = (static_cast<int>(flatDistribution2->fire((nbxing*gate)/gate))) - nbxing/2;
00171     std::pair<int, int> digi(strip,time_hit);
00172     strips.insert(digi);
00173   }
00174 
00175 }