11 #ifndef RecoCTPPS_TotemRPLocal_CTPPSTimingTrackRecognition 12 #define RecoCTPPS_TotemRPLocal_CTPPSTimingTrackRecognition 22 #include <unordered_map> 30 template<
typename TRACK_TYPE,
typename HIT_TYPE>
35 threshold_ (iConfig.getParameter<double>(
"threshold")),
37 resolution_ (iConfig.getParameter<double>(
"resolution")),
38 sigma_ (iConfig.getParameter<double>(
"sigma")),
39 tolerance_ (iConfig.getParameter<double>(
"tolerance")),
43 <<
"Invalid number of parameters to the pixel efficiency function! " 93 const HitVector&
hits,
95 float (*getHitCenter)(
const HIT_TYPE&),
96 float (*getHitRangeWidth)(
const HIT_TYPE&),
97 void (*setTrackCenter)(TRACK_TYPE&,
float),
98 void (*setTrackSigma)(TRACK_TYPE&,
float),
111 bool timeEval(
const HitVector& hits,
float&
meanTime,
float& timeSigma)
const;
118 template<
class TRACK_TYPE,
class HIT_TYPE>
inline 120 const HitVector& hits,
122 float (*getHitCenter)(
const HIT_TYPE&),
123 float (*getHitRangeWidth)(
const HIT_TYPE&),
124 void (*setTrackCenter)(TRACK_TYPE&,
float),
125 void (*setTrackSigma)(TRACK_TYPE&,
float),
127 int numberOfTracks = 0;
129 const float profileRangeMargin = sigma_ * 3.;
130 const float profileRangeBegin = param.
rangeBegin - profileRangeMargin;
131 const float profileRangeEnd = param.
rangeEnd + profileRangeMargin;
133 std::vector<float> hitProfile((profileRangeEnd - profileRangeBegin) * invResolution + 1, 0.);
135 *hitProfile.rbegin() = -1.f;
138 for (
auto const&
hit : hits) {
139 const float center = getHitCenter(
hit), rangeWidth = getHitRangeWidth(
hit);
140 std::vector<double> params{center, rangeWidth, sigma_};
141 for (
unsigned int i = 0;
i < hitProfile.size(); ++
i)
142 hitProfile[
i] += pixelEfficiencyFunction_.
evaluate(std::vector<double>{profileRangeBegin + i*resolution_}, params);
145 bool underThreshold =
true;
146 float rangeMaximum = -1.0f;
147 bool trackRangeFound =
false;
148 int trackRangeBegin = 0, trackRangeEnd = 0;
151 for (
unsigned int i = 0;
i < hitProfile.size();
i++) {
152 if (hitProfile[
i] > rangeMaximum)
153 rangeMaximum = hitProfile[
i];
156 if (underThreshold && hitProfile[
i] > threshold_) {
157 underThreshold =
false;
159 rangeMaximum = hitProfile[
i];
163 else if (!underThreshold && hitProfile[
i] <= threshold_) {
164 underThreshold =
true;
166 trackRangeFound =
true;
170 if (trackRangeFound) {
173 bool underTrackThreshold =
true;
175 for (
int j = trackRangeBegin; j <= trackRangeEnd; j++) {
176 if (underTrackThreshold && hitProfile[j] > trackThreshold) {
177 underTrackThreshold =
false;
180 else if (!underTrackThreshold && hitProfile[j] <= trackThreshold) {
181 underTrackThreshold =
true;
183 float leftMargin = profileRangeBegin + resolution_ * trackBegin;
184 float rightMargin = profileRangeBegin + resolution_ * j;
185 setTrackCenter(track, 0.5
f*(leftMargin + rightMargin));
186 setTrackSigma(track, 0.5
f*(rightMargin - leftMargin));
187 result.push_back(track);
191 trackRangeFound =
false;
196 template<
class TRACK_TYPE,
class HIT_TYPE>
inline 200 bool initialized =
false;
203 for (
const auto&
hit : hits) {
204 const float xBegin =
hit.getX() - 0.5f*
hit.getXWidth(), xEnd =
hit.getX() + 0.5f*
hit.getXWidth();
205 const float yBegin =
hit.getY() - 0.5f*
hit.getYWidth(), yEnd =
hit.getY() + 0.5f*
hit.getYWidth();
206 const float zBegin =
hit.getZ() - 0.5f*
hit.getZWidth(), zEnd =
hit.getZ() + 0.5f*
hit.getZWidth();
229 template<
class TRACK_TYPE,
class HIT_TYPE>
inline 233 float mean_num = 0.f, mean_denom = 0.f;
234 bool valid_hits =
false;
235 for (
const auto&
hit : hits) {
236 if (
hit.getTPrecision() <= 0.)
239 mean_num += weight*
hit.getT();
243 mean_time = valid_hits ? (mean_num/mean_denom) : 0.
f;
244 time_sigma = valid_hits ?
std::sqrt(1.
f/mean_denom) : 0.f;
std::vector< HIT_TYPE > HitVector
SpatialRange getHitSpatialRange(const HitVector &hits)
Structure representing a 3D range in space.
void producePartialTracks(const HitVector &hits, const DimensionParameters ¶m, float(*getHitCenter)(const HIT_TYPE &), float(*getHitRangeWidth)(const HIT_TYPE &), void(*setTrackCenter)(TRACK_TYPE &, float), void(*setTrackSigma)(TRACK_TYPE &, float), TrackVector &result)
virtual ~CTPPSTimingTrackRecognition()=default
virtual void clear()
Reset internal state of a class instance.
const float thresholdFromMaximum_
CTPPSTimingTrackRecognition(const edm::ParameterSet &iConfig)
std::unordered_map< int, HitVector > HitVectorMap
bool timeEval(const HitVector &hits, float &meanTime, float &timeSigma) const
reco::FormulaEvaluator pixelEfficiencyFunction_
std::vector< TRACK_TYPE > TrackVector
HitVectorMap hitVectorMap_
RecHit vectors that should be processed separately while reconstructing tracks.
virtual void addHit(const HIT_TYPE &recHit)=0
Add new hit to the set from which the tracks are reconstructed.
Power< A, B >::type pow(const A &a, const B &b)
virtual int produceTracks(edm::DetSet< TRACK_TYPE > &tracks)=0
Produce a collection of tracks, given its hits collection.