diff --git a/TrackerConditions/inc/StrawElectronics.hh b/TrackerConditions/inc/StrawElectronics.hh index 9f4191be96..74b0503cbf 100644 --- a/TrackerConditions/inc/StrawElectronics.hh +++ b/TrackerConditions/inc/StrawElectronics.hh @@ -45,6 +45,14 @@ namespace mu2e { _sigma(sigma), _t0(t0) {}; }; + // distance-dependent terms of the response of one cluster on one straw; maxResponseTime and maxLinearResponse use only distIndex and distFrac + struct ResponseGeometry { + int distIndex = 0; + double distFrac = 0.0; + double reflectionTime = 0.0; + double reflectionScale = 0.0; + }; + typedef std::shared_ptr ptr_t; typedef std::shared_ptr cptr_t; constexpr static const char* cxname = {"StrawElectronics"}; @@ -108,11 +116,15 @@ namespace mu2e { // linear response to a charge pulse. This does NOT include saturation effects, // since those are cumulative and cannot be computed for individual charges double linearResponse(Straw const& straw, Path ipath, double time, double charge, double distance, bool forsaturation=false) const; // mvolts per pCoulomb + // same as above, with the distance-dependent terms precomputed by responseGeometry + double linearResponse(Straw const& straw, Path ipath, double time, double charge, ResponseGeometry const& rgeom, bool forsaturation=false) const; + ResponseGeometry responseGeometry(Straw const& straw, double distance) const; double adcImpulseResponse(StrawId sid, double time, double charge) const; // Given a (linear) total voltage, compute the saturated voltage double saturatedResponse(double lineearresponse) const; // relative time when linear response is maximal double maxResponseTime(StrawId id, Path ipath,double distance) const; + double maxResponseTime(StrawId id, Path ipath, ResponseGeometry const& rgeom) const; // digization TrkTypes::ADCValue adcResponse(StrawId id, double mvolts) const; // ADC response to analog inputs TrkTypes::TDCValue tdcResponse(double time) const; // TDC response to a signal input to electronics at a given time (in ns since eventWindowMarker) @@ -155,6 +167,7 @@ namespace mu2e { double currentToVoltage(StrawId sid, Path ipath) const { return _dVdI[ipath][sid.uniqueStraw()]; } double maxLinearResponse(StrawId sid, Path ipath,double distance,double charge=1.0) const; + double maxLinearResponse(StrawId sid, Path ipath, ResponseGeometry const& rgeom, double charge=1.0) const; double clusterLookbackTime() const { return _clusterLookbackTime;} double truncationTime(Path ipath) const { return _ttrunc[ipath];} @@ -216,6 +229,8 @@ namespace mu2e { double timeDigitalToAnalog(TrkTypes::TDCValue time, StrawId& sid) const; private: + // wire-distance interpolation interval and weight + void fillDistanceInterval(double distance, ResponseGeometry& rgeom) const; bool _overrideDbTimeOffsets; // for digitization we override Db parameters and zero all time offsets // generic waveform parameters diff --git a/TrackerConditions/src/StrawElectronics.cc b/TrackerConditions/src/StrawElectronics.cc index ecd48ac0db..a9b9888406 100644 --- a/TrackerConditions/src/StrawElectronics.cc +++ b/TrackerConditions/src/StrawElectronics.cc @@ -67,30 +67,45 @@ namespace mu2e { response[i] *= 1 / gain_160; } + void StrawElectronics::fillDistanceInterval(double distance, ResponseGeometry& rgeom) const { + rgeom.distIndex = 0; + for (size_t i=1;i<_wPoints.size()-1;i++){ + if (distance < _wPoints[i]._distance) + break; + rgeom.distIndex = i; + } + rgeom.distFrac = 1 - (distance - _wPoints[rgeom.distIndex]._distance)/(_wPoints[rgeom.distIndex+1]._distance - _wPoints[rgeom.distIndex]._distance); + } + + StrawElectronics::ResponseGeometry StrawElectronics::responseGeometry(Straw const& straw, double distance) const { + ResponseGeometry rgeom; + double straw_length = 2*straw.halfLength(); + rgeom.reflectionTime = _reflectionTimeShift + (2*straw_length-2*distance)/_reflectionVelocity; + rgeom.reflectionScale = _reflectionFrac * exp(-(2*straw_length-2*distance)/_reflectionALength); + fillDistanceInterval(distance,rgeom); + return rgeom; + } + double StrawElectronics::linearResponse(Straw const& straw, Path ipath, double time, double charge, double distance, bool forsaturation) const { + return linearResponse(straw,ipath,time,charge,responseGeometry(straw,distance),forsaturation); + } + + double StrawElectronics::linearResponse(Straw const& straw, Path ipath, double time, double charge, ResponseGeometry const& rgeom, bool forsaturation) const { int index = time*_sampleRate + _responseBins/2.; if ( index >= _responseBins) index = _responseBins-1; if (index < 0) index = 0; - double straw_length = 2*straw.halfLength(); - double reflection_time = _reflectionTimeShift + (2*straw_length-2*distance)/_reflectionVelocity; - int index_refl = (time - reflection_time)*_sampleRate + _responseBins/2.; + int index_refl = (time - rgeom.reflectionTime)*_sampleRate + _responseBins/2.; if (index_refl >= _responseBins) index_refl = _responseBins-1; if (index_refl < 0) index_refl = 0; - double reflection_scale = _reflectionFrac * exp(-(2*straw_length-2*distance)/_reflectionALength); - - int distIndex = 0; - for (size_t i=1;i<_wPoints.size()-1;i++){ - if (distance < _wPoints[i]._distance) - break; - distIndex = i; - } - double distFrac = 1 - (distance - _wPoints[distIndex]._distance)/(_wPoints[distIndex+1]._distance - _wPoints[distIndex]._distance); + double reflection_scale = rgeom.reflectionScale; + int distIndex = rgeom.distIndex; + double distFrac = rgeom.distFrac; double p0, p1; if (ipath == thresh){ if (forsaturation){ @@ -124,13 +139,14 @@ namespace mu2e { } double StrawElectronics::maxResponseTime(StrawId sid, Path ipath,double distance) const { - int distIndex = 0; - for (size_t i=1;i<_wPoints.size()-1;i++){ - if (distance < _wPoints[i]._distance) - break; - distIndex = i; - } - double distFrac = 1 - (distance - _wPoints[distIndex]._distance)/(_wPoints[distIndex+1]._distance - _wPoints[distIndex]._distance); + ResponseGeometry rgeom; + fillDistanceInterval(distance,rgeom); + return maxResponseTime(sid,ipath,rgeom); + } + + double StrawElectronics::maxResponseTime(StrawId sid, Path ipath, ResponseGeometry const& rgeom) const { + int distIndex = rgeom.distIndex; + double distFrac = rgeom.distFrac; double p0 = _wPoints[distIndex]._tmax[ipath][sid.getStraw()]; double p1 = _wPoints[distIndex + 1]._tmax[ipath][sid.getStraw()]; @@ -138,13 +154,14 @@ namespace mu2e { } double StrawElectronics::maxLinearResponse(StrawId sid, Path ipath,double distance,double charge) const { - int distIndex = 0; - for (size_t i=1;i<_wPoints.size()-1;i++){ - if (distance < _wPoints[i]._distance) - break; - distIndex = i; - } - double distFrac = 1 - (distance - _wPoints[distIndex]._distance)/(_wPoints[distIndex+1]._distance - _wPoints[distIndex]._distance); + ResponseGeometry rgeom; + fillDistanceInterval(distance,rgeom); + return maxLinearResponse(sid,ipath,rgeom,charge); + } + + double StrawElectronics::maxLinearResponse(StrawId sid, Path ipath, ResponseGeometry const& rgeom, double charge) const { + int distIndex = rgeom.distIndex; + double distFrac = rgeom.distFrac; double p0 = _wPoints[distIndex]._linmax[ipath][sid.getStraw()]; double p1 = _wPoints[distIndex + 1]._linmax[ipath][sid.getStraw()]; diff --git a/TrackerMC/inc/StrawCluster.hh b/TrackerMC/inc/StrawCluster.hh index a7fb9c312d..a2e607c8e8 100644 --- a/TrackerMC/inc/StrawCluster.hh +++ b/TrackerMC/inc/StrawCluster.hh @@ -18,10 +18,12 @@ #include "Offline/DataProducts/inc/StrawEnd.hh" #include "Offline/TrackerMC/inc/StrawPosition.hh" #include "Offline/MCDataProducts/inc/StrawGasStep.hh" +#include "Offline/TrackerConditions/inc/StrawElectronics.hh" // toolkit includes #include "canvas/Persistency/Common/Ptr.h" namespace mu2e { + class Straw; namespace TrackerMC { class StrawCluster{ public: @@ -41,7 +43,9 @@ namespace mu2e { float drifttime, float proptime, art::Ptr const& sgs, - float ctime); + float ctime, + StrawElectronics const& strawele, + Straw const& straw); // use compiler version of copy, assignment // Accessors ClusterType type() const { return _type; } @@ -57,6 +61,8 @@ namespace mu2e { float propTime() const { return _proptime; } art::Ptr const& strawGasStep() const { return _sgsptr; } float cluTime() const { return _ctime; } + // distance-dependent electronics response terms of this cluster on its straw + StrawElectronics::ResponseGeometry const& responseGeometry() const { return _rgeom; } // Print contents of the object. void print( std::ostream& ost = std::cout, bool doEndl = true ) const; private: @@ -71,6 +77,7 @@ namespace mu2e { float _proptime; // propagation time to the wire end art::Ptr _sgsptr; float _ctime; + StrawElectronics::ResponseGeometry _rgeom; // computed at construction from _wdist }; } // namespace TrackerMC } // namespace mu2e diff --git a/TrackerMC/src/StrawCluster.cc b/TrackerMC/src/StrawCluster.cc index fa80678495..1bc954d8eb 100644 --- a/TrackerMC/src/StrawCluster.cc +++ b/TrackerMC/src/StrawCluster.cc @@ -5,6 +5,7 @@ // // mu2e includes #include "Offline/TrackerMC/inc/StrawCluster.hh" +#include "Offline/TrackerGeom/inc/Straw.hh" // general includes using namespace std; @@ -22,8 +23,11 @@ namespace mu2e { float drifttime, float proptime, art::Ptr const& sgsptr, - float ctime) : _type(type), _strawId(sid), _end(end), _time(time), - _charge(charge), _wdist(wdist), _pos(pos), _drifttime(drifttime), _proptime(proptime), _sgsptr(sgsptr), _ctime(ctime) {} + float ctime, + StrawElectronics const& strawele, + Straw const& straw) : _type(type), _strawId(sid), _end(end), _time(time), + _charge(charge), _wdist(wdist), _pos(pos), _drifttime(drifttime), _proptime(proptime), _sgsptr(sgsptr), _ctime(ctime), + _rgeom(strawele.responseGeometry(straw,_wdist)) {} // delegating constructors in C++11! StrawCluster::StrawCluster(const StrawCluster& primary, StrawId const& id, float xfactor) : diff --git a/TrackerMC/src/StrawDigisFromStrawGasSteps_module.cc b/TrackerMC/src/StrawDigisFromStrawGasSteps_module.cc index 78c9f85276..0e13a3e78c 100644 --- a/TrackerMC/src/StrawDigisFromStrawGasSteps_module.cc +++ b/TrackerMC/src/StrawDigisFromStrawGasSteps_module.cc @@ -669,7 +669,7 @@ namespace mu2e { // compute the time the signal arrives at the wire end double gtime = ctime + wireq._time + weq._time; // create the clust - StrawCluster clust(StrawCluster::primary,sid,end,(float)gtime,weq._charge,weq._wdist,wireq._pos,(float)wireq._time,(float)weq._time,sgsptr,(float)ctime); + StrawCluster clust(StrawCluster::primary,sid,end,(float)gtime,weq._charge,weq._wdist,wireq._pos,(float)wireq._time,(float)weq._time,sgsptr,(float)ctime,strawele,straw); // add the clusts to the appropriate sequence. shsp.clustSequence(end).insert(clust); // if required, add a 'ghost' copy of this clust diff --git a/TrackerMC/src/StrawWaveform.cc b/TrackerMC/src/StrawWaveform.cc index fc16391a90..37b1359f27 100644 --- a/TrackerMC/src/StrawWaveform.cc +++ b/TrackerMC/src/StrawWaveform.cc @@ -43,7 +43,7 @@ namespace mu2e { //// check if this clust could cross threshold //if(wfx._vstart + maxLinearResponse(wfx._iclust) > threshold){ // check the actual response - double maxtime = wfx._iclust->time()+strawele.maxResponseTime(_straw.id(),StrawElectronics::thresh,wfx._iclust->wireDistance()); + double maxtime = wfx._iclust->time()+strawele.maxResponseTime(_straw.id(),StrawElectronics::thresh,wfx._iclust->responseGeometry()); double maxresp = sampleWaveform(strawele,StrawElectronics::thresh,maxtime); if(maxresp > threshold){ // interpolate to find the precise crossing @@ -64,7 +64,7 @@ namespace mu2e { void StrawWaveform::returnCrossing(StrawElectronics const& strawele, double threshold, WFX& wfx) const { while(wfx._iclust != _cseq.clustList().end() && wfx._vstart > threshold) { // move forward in time at least as twice the time to the maxium for this clust - double time = wfx._iclust->time()+strawele.clusterLookbackTime() + 2*strawele.maxResponseTime(_straw.id(),StrawElectronics::thresh,wfx._iclust->wireDistance()); + double time = wfx._iclust->time()+strawele.clusterLookbackTime() + 2*strawele.maxResponseTime(_straw.id(),StrawElectronics::thresh,wfx._iclust->responseGeometry()); while(wfx._iclust != _cseq.clustList().end() && wfx._iclust->time()-strawele.clusterLookbackTime() < time){ ++(wfx._iclust); @@ -95,7 +95,7 @@ namespace mu2e { bool StrawWaveform::fineCrossing(StrawElectronics const& strawele, double threshold,double maxresp, WFX& wfx) const { static double timestep(0.020); // interpolation minimum to use linear threshold crossing calculation double pretime = wfx._iclust->time()-strawele.clusterLookbackTime(); - double posttime = pretime + strawele.clusterLookbackTime() + strawele.maxResponseTime(_straw.id(),StrawElectronics::thresh,wfx._iclust->wireDistance()); + double posttime = pretime + strawele.clusterLookbackTime() + strawele.maxResponseTime(_straw.id(),StrawElectronics::thresh,wfx._iclust->responseGeometry()); double presample = wfx._vstart; double postsample = maxresp; static const unsigned maxstep(10); // 10 steps max @@ -141,7 +141,7 @@ namespace mu2e { double StrawWaveform::maxLinearResponse(StrawElectronics const& strawele,StrawClusterList::const_iterator const& iclust) const { // ignore saturation effects - double linresp = strawele.maxLinearResponse(_straw.id(),StrawElectronics::thresh,iclust->wireDistance(),iclust->charge()); + double linresp = strawele.maxLinearResponse(_straw.id(),StrawElectronics::thresh,iclust->responseGeometry(),iclust->charge()); linresp *= (_xtalk._preamp + _xtalk._postamp); return linresp; } @@ -153,7 +153,7 @@ namespace mu2e { auto iclust = hlist.begin(); while(iclust != hlist.end() && iclust->time()-strawele.clusterLookbackTime() < time){ // compute the linear straw electronics response to this charge. This is pre-saturation - linresp += strawele.linearResponse(_straw,ipath,time-iclust->time(),iclust->charge(),iclust->wireDistance()); + linresp += strawele.linearResponse(_straw,ipath,time-iclust->time(),iclust->charge(),iclust->responseGeometry()); // move to next clust ++iclust; } @@ -207,7 +207,7 @@ namespace mu2e { double response = 0; auto jclust = iclust; while(jclust != _cseq.clustList().end() && jclust->time()-strawele.clusterLookbackTime() < time){ - response += strawele.linearResponse(_straw,StrawElectronics::thresh,time-jclust->time(),jclust->charge(),jclust->wireDistance(),true); + response += strawele.linearResponse(_straw,StrawElectronics::thresh,time-jclust->time(),jclust->charge(),jclust->responseGeometry(),true); ++jclust; } // now saturate it