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/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
00052 cosmicPar=37.62;
00053
00054 double c=299792458;
00055
00056 cspeed=c*1e+2*1e-9;
00057
00058 sspeed=sspeed*cspeed;
00059
00060 }
00061
00062 void RPCSynchronizer::setRandomEngine(CLHEP::HepRandomEngine& eng){
00063 gauss1 = new CLHEP::RandGaussQ(eng);
00064 gauss2 = new CLHEP::RandGaussQ(eng);
00065 }
00066
00067
00068 RPCSynchronizer::~RPCSynchronizer(){
00069 delete gauss1;
00070 delete gauss2;
00071 }
00072
00073
00074 int RPCSynchronizer::getSimHitBx(const PSimHit* simhit)
00075 {
00076
00077 RPCSimSetUp* simsetup = this->getRPCSimSetUp();
00078 const RPCGeometry * geometry = simsetup->getGeometry();
00079 float timeref = simsetup->getTime(simhit->detUnitId());
00080
00081 int bx = -999;
00082 LocalPoint simHitPos = simhit->localPosition();
00083 float tof = simhit->timeOfFlight();
00084
00085
00086
00087 float rr_el = gauss1->fire(0.,resEle);
00088
00089 RPCDetId SimDetId(simhit->detUnitId());
00090
00091 const RPCRoll* SimRoll = 0;
00092
00093 for(TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end(); it++){
00094
00095 if( dynamic_cast< RPCChamber* >( *it ) != 0 ){
00096
00097 RPCChamber* ch = dynamic_cast< RPCChamber* >( *it );
00098 RPCDetId detId=ch->id();
00099
00100 std::vector< const RPCRoll*> rollsRaf = (ch->rolls());
00101 for(std::vector<const RPCRoll*>::iterator r = rollsRaf.begin();
00102 r != rollsRaf.end(); ++r){
00103
00104 if((*r)->id() == SimDetId) {
00105 SimRoll = &(*(*r));
00106 break;
00107 }
00108 }
00109 }
00110 }
00111
00112 if(SimRoll != 0){
00113
00114 float distanceFromEdge = 0;
00115 float half_stripL = 0.;
00116
00117 if(SimRoll->id().region() == 0){
00118 const RectangularStripTopology* top_= dynamic_cast<const RectangularStripTopology*> (&(SimRoll->topology()));
00119 half_stripL = top_->stripLength()/2;
00120 distanceFromEdge = half_stripL + simHitPos.y();
00121 }else{
00122 const TrapezoidalStripTopology* top_= dynamic_cast<const TrapezoidalStripTopology*> (&(SimRoll->topology()));
00123 half_stripL = top_->stripLength()/2;
00124 distanceFromEdge = half_stripL - simHitPos.y();
00125 }
00126
00127
00128 float prop_time = distanceFromEdge/sspeed;
00129
00130 double rr_tim1 = gauss2->fire(0.,resEle);
00131 double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
00132
00133
00134 double time_differ = 0.;
00135
00136 if(cosmics){
00137 time_differ = (total_time - (timeref + ((half_stripL/sspeed ) + timOff)))/cosmicPar;
00138 }
00139 else if(!cosmics){
00140 time_differ = total_time - (timeref + ( half_stripL/sspeed ) + timOff);
00141 }
00142
00143 double inf_time = 0;
00144 double sup_time = 0;
00145
00146
00147 for(int n = -5; n <= 5; ++n){
00148
00149 if(cosmics){
00150 inf_time = (-lbGate/2 + n*lbGate )/cosmicPar;
00151 sup_time = ( lbGate/2 + n*lbGate )/cosmicPar;
00152 }
00153 else if(!cosmics){
00154 inf_time = -lbGate/2 + n*lbGate;
00155 sup_time = lbGate/2 + n*lbGate;
00156 }
00157
00158 if(inf_time < time_differ && time_differ < sup_time) {
00159 bx = n;
00160 break;
00161 }
00162 }
00163 }
00164
00165
00166 return bx;
00167 }
00168