CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/SimMuon/GEMDigitizer/src/GEMSynchronizer.cc

Go to the documentation of this file.
00001 #include "SimMuon/GEMDigitizer/src/GEMSynchronizer.h"
00002 #include "SimMuon/GEMDigitizer/src/GEMSimSetUp.h"
00003 
00004 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00005 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00006 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00007 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
00008 
00009 #include "CLHEP/Random/RandGaussQ.h"
00010 
00011 
00012 namespace 
00013 {
00014   // "magic" parameter for cosmics
00015   const double COSMIC_PAR =  37.62;
00016 }
00017 
00018 
00019 GEMSynchronizer::GEMSynchronizer(const edm::ParameterSet& config):
00020   gauss1_(0), gauss2_(0)
00021 {
00022   timeResolution_ = config.getParameter<double>("timeResolution");
00023   averageShapingTime_ = config.getParameter<double>("averageShapingTime");
00024   timeJitter_ = config.getParameter<double>("timeJitter");
00025   signalPropagationSpeed_ = config.getParameter<double>("signalPropagationSpeed");
00026   cosmics_ = config.getParameter<bool>("cosmics");
00027   bxwidth_ = config.getParameter<double>("bxwidth");
00028 
00029   // signal propagation speed in vacuum in [m/s]
00030   const double cspeed = 299792458;
00031   // signal propagation speed in material in [cm/ns]
00032   signalPropagationSpeed_ = signalPropagationSpeed_ * cspeed * 1e+2 * 1e-9;
00033 }
00034 
00035 
00036 void GEMSynchronizer::setRandomEngine(CLHEP::HepRandomEngine& eng)
00037 {
00038   gauss1_ = new CLHEP::RandGaussQ(eng);
00039   gauss2_ = new CLHEP::RandGaussQ(eng);
00040 }
00041 
00042 
00043 GEMSynchronizer::~GEMSynchronizer()
00044 {
00045   if (gauss1_) delete gauss1_;
00046   if (gauss2_) delete gauss2_;
00047 }
00048 
00049 
00050 int GEMSynchronizer::getSimHitBx(const PSimHit* simhit)
00051 {
00052   GEMSimSetUp* simsetup = getGEMSimSetUp();
00053   const GEMGeometry * geometry = simsetup->getGeometry();
00054   // calibration offset for a particular detector part
00055   float calibrationTime = simsetup->getTime(simhit->detUnitId());
00056 
00057   int bx = -999;
00058   LocalPoint simHitPos = simhit->localPosition();
00059   float tof = simhit->timeOfFlight();
00060   // random Gaussian time correction due to electronics jitter
00061   float randomJitterTime = gauss1_->fire(0., timeJitter_);
00062   
00063   GEMDetId shdetid(simhit->detUnitId());
00064 
00065   const GEMEtaPartition* shRoll = 0;
00066 
00067   for(const auto &det: geometry->dets())
00068   {
00069     if( dynamic_cast< GEMEtaPartition* >( det ) != 0 )
00070     {
00071       GEMEtaPartition* roll = dynamic_cast< GEMEtaPartition* >( det );
00072 
00073       if(roll->id() == shdetid)
00074       {
00075         shRoll = roll;
00076         break;
00077       }
00078     }
00079   }
00080 
00081   if(shRoll != 0)
00082   {
00083     float distanceFromEdge = 0;
00084     float halfStripLength = 0.;
00085 
00086     if(shRoll->id().region() == 0)
00087     {
00088       throw cms::Exception("Geometry")
00089         << "GEMSynchronizer::getSimHitBx() - this GEM id is from barrel, which cannot happen:  "<<shRoll->id()<< "\n";
00090     }
00091     else
00092     {
00093       const TrapezoidalStripTopology* top = dynamic_cast<const TrapezoidalStripTopology*> (&(shRoll->topology()));
00094       halfStripLength = 0.5 * top->stripLength();
00095       distanceFromEdge = halfStripLength - simHitPos.y();
00096     }
00097     
00098     // average time for the signal to propagate from the SimHit to the top of a strip
00099     float averagePropagationTime =  distanceFromEdge/signalPropagationSpeed_;
00100     // random Gaussian time correction due to the finite timing resolution of the detector
00101     float randomResolutionTime = gauss2_->fire(0., timeResolution_);
00102 
00103     float simhitTime = tof + (averageShapingTime_ + randomResolutionTime) + (averagePropagationTime + randomJitterTime);
00104     float referenceTime = calibrationTime + halfStripLength/signalPropagationSpeed_ + averageShapingTime_;
00105     float timeDifference = cosmics_ ? (simhitTime - referenceTime)/COSMIC_PAR : simhitTime - referenceTime;
00106 
00107     // assign the bunch crossing
00108     bx = static_cast<int>( std::round((timeDifference)/bxwidth_) );
00109 
00110     // check time
00111     const bool debug( false );
00112     if (debug)
00113       {
00114         std::cout<<"checktime "<<bx<<" "<<timeDifference<<" "<<simhitTime<<" "<<referenceTime<<" "<<tof<<" "<<averagePropagationTime<<std::endl;
00115       }
00116   }
00117   return bx;
00118 }
00119