00001 #include "Geometry/RPCGeometry/interface/RPCRoll.h" 00002 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h" 00003 #include "SimMuon/RPCDigitizer/src/RPCSynchronizer.h" 00004 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h" 00005 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h" 00006 00007 #include <FWCore/Framework/interface/Frameworkfwd.h> 00008 #include <FWCore/Framework/interface/EventSetup.h> 00009 #include <FWCore/Framework/interface/EDAnalyzer.h> 00010 #include <FWCore/Framework/interface/Event.h> 00011 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00012 #include <FWCore/Framework/interface/ESHandle.h> 00013 00014 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" 00015 #include "SimDataFormats/TrackingHit/interface/PSimHit.h" 00016 #include "Geometry/RPCGeometry/interface/RPCGeometry.h" 00017 #include <Geometry/Records/interface/MuonGeometryRecord.h> 00018 #include "DataFormats/MuonDetId/interface/RPCDetId.h" 00019 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h" 00020 #include "SimDataFormats/TrackingHit/interface/PSimHit.h" 00021 00022 #include "FWCore/ServiceRegistry/interface/Service.h" 00023 #include "FWCore/Utilities/interface/RandomNumberGenerator.h" 00024 #include "FWCore/Utilities/interface/Exception.h" 00025 #include "CLHEP/Random/RandomEngine.h" 00026 #include "CLHEP/Random/RandFlat.h" 00027 #include <CLHEP/Random/RandGaussQ.h> 00028 #include <CLHEP/Random/RandFlat.h> 00029 00030 #include<cstring> 00031 #include<iostream> 00032 #include<fstream> 00033 #include<string> 00034 #include<vector> 00035 #include<stdlib.h> 00036 #include <cmath> 00037 00038 using namespace std; 00039 00040 RPCSynchronizer::RPCSynchronizer(const edm::ParameterSet& config){ 00041 00042 resRPC = config.getParameter<double>("timeResolution"); 00043 timOff = config.getParameter<double>("timingRPCOffset"); 00044 dtimCs = config.getParameter<double>("deltatimeAdjacentStrip"); 00045 resEle = config.getParameter<double>("timeJitter"); 00046 sspeed = config.getParameter<double>("signalPropagationSpeed"); 00047 lbGate = config.getParameter<double>("linkGateWidth"); 00048 00049 cosmics = config.getParameter<bool>("cosmics"); 00050 00051 edm::Service<edm::RandomNumberGenerator> rng; 00052 if ( ! rng.isAvailable()) { 00053 throw cms::Exception("Configuration") 00054 << "RPCDigitizer requires the RandomNumberGeneratorService\n" 00055 "which is not present in the configuration file. You must add the service\n" 00056 "in the configuration file or remove the modules that require it."; 00057 } 00058 00059 rndEngine = &(rng->getEngine()); 00060 flatDistribution_ = new CLHEP::RandFlat(rndEngine); 00061 00062 } 00063 00064 int RPCSynchronizer::getSimHitBx(const PSimHit* simhit) 00065 { 00066 RPCSimSetUp* simsetup = this->getRPCSimSetUp(); 00067 const RPCGeometry * geometry = simsetup->getGeometry(); 00068 float timeref = simsetup->getTime(simhit->detUnitId()); 00069 00070 int bx = -999; 00071 LocalPoint simHitPos = simhit->localPosition(); 00072 float tof = simhit->timeOfFlight(); 00073 gaussian_ = new CLHEP::RandGaussQ(rndEngine,0.,resEle); 00074 float rr_el = gaussian_->fire(); 00075 00076 RPCDetId SimDetId(simhit->detUnitId()); 00077 00078 const RPCRoll* SimRoll = 0; 00079 00080 for(TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end(); it++){ 00081 00082 if( dynamic_cast< RPCChamber* >( *it ) != 0 ){ 00083 00084 RPCChamber* ch = dynamic_cast< RPCChamber* >( *it ); 00085 RPCDetId detId=ch->id(); 00086 00087 std::vector< const RPCRoll*> rollsRaf = (ch->rolls()); 00088 for(std::vector<const RPCRoll*>::iterator r = rollsRaf.begin(); 00089 r != rollsRaf.end(); ++r){ 00090 00091 if((*r)->id() == SimDetId) { 00092 SimRoll = &(*(*r)); 00093 break; 00094 } 00095 } 00096 } 00097 } 00098 00099 if(SimRoll != 0){ 00100 00101 float distanceFromEdge = 0; 00102 float stripL = 0.; 00103 00104 if(SimRoll->id().region() == 0){ 00105 const RectangularStripTopology* top_= dynamic_cast<const RectangularStripTopology*> (&(SimRoll->topology())); 00106 distanceFromEdge = top_->stripLength() - simHitPos.y(); 00107 stripL = top_->stripLength(); 00108 }else{ 00109 const TrapezoidalStripTopology* top_= dynamic_cast<const TrapezoidalStripTopology*> (&(SimRoll->topology())); 00110 distanceFromEdge = top_->stripLength() - simHitPos.y(); 00111 stripL = top_->stripLength(); 00112 } 00113 00114 float prop_time = distanceFromEdge/(sspeed*3e+10); 00115 gaussian_ = new CLHEP::RandGaussQ(rndEngine,0.,resRPC); 00116 double rr_tim1 = gaussian_->fire(); 00117 double total_time = tof + prop_time + timOff + rr_tim1 + rr_el; 00118 00119 // Bunch crossing assignment 00120 double time_differ = 0.; 00121 00122 if(cosmics){ 00123 time_differ = total_time/37.62 - (timeref + ((stripL/(2*sspeed*3e+10) ) + timOff))/37.62; 00124 } 00125 else if(!cosmics){ 00126 time_differ = total_time - (timeref + ( stripL/(2*sspeed*3e+10) ) + timOff); 00127 } 00128 00129 double inf_time = 0; 00130 double sup_time = 0; 00131 00132 for(int n = -5; n <= 5; ++n){ 00133 00134 if(cosmics){ 00135 inf_time = -lbGate/(2*37.62) + n*lbGate/37.62; 00136 sup_time = lbGate/(2*37.62) + n*lbGate/37.62; 00137 } 00138 else if(!cosmics){ 00139 inf_time = -lbGate/2 + n*lbGate; 00140 sup_time = lbGate/2 + n*lbGate; 00141 } 00142 00143 if(inf_time < time_differ && time_differ < sup_time) { 00144 bx = n; 00145 break; 00146 } 00147 } 00148 } 00149 00150 return bx; 00151 } 00152 00153 RPCSynchronizer::~RPCSynchronizer(){ 00154 if(gaussian_ != 0) delete gaussian_; 00155 if(poissonDistribution_ != 0) delete poissonDistribution_; 00156 } 00157 00158