91 th_y_cut_apply = ps.
getParameter<
bool> (
"th_y_cut_apply");
92 th_y_cut_mean = ps.
getParameter<
double>(
"th_y_cut_mean");
93 th_y_cut_value = ps.
getParameter<
double>(
"th_y_cut_value");
103 desc.
add<
bool>(
"x_cut_apply",
false)->setComment(
"whether to apply track-association cut in x");
104 desc.
add<
double>(
"x_cut_mean", 0E-6)->setComment(
"mean of track-association cut in x, mm");
105 desc.
add<
double>(
"x_cut_value", 800E-6)->setComment(
"threshold of track-association cut in x, mm");
107 desc.
add<
bool>(
"y_cut_apply",
false)->setComment(
"whether to apply track-association cut in y");
108 desc.
add<
double>(
"y_cut_mean", 0E-6)->setComment(
"mean of track-association cut in y, mm");
109 desc.
add<
double>(
"y_cut_value", 600E-6)->setComment(
"threshold of track-association cut in y, mm");
111 desc.
add<
bool>(
"xi_cut_apply",
true)->setComment(
"whether to apply track-association cut in xi");
112 desc.
add<
double>(
"xi_cut_mean", 0.)->
setComment(
"mean of track-association cut in xi");
113 desc.
add<
double>(
"xi_cut_value", 0.013)->
setComment(
"threshold of track-association cut in xi");
115 desc.
add<
bool>(
"th_y_cut_apply",
true)->setComment(
"whether to apply track-association cut in th_y");
116 desc.
add<
double>(
"th_y_cut_mean", 0E-6)->setComment(
"mean of track-association cut in th_y, rad");
117 desc.
add<
double>(
"th_y_cut_value", 20E-6)->setComment(
"threshold of track-association cut in th_y, rad");
119 desc.
add<
double>(
"ti_tr_min", -1.)->
setComment(
"minimum value for timing-tracking association cut");
120 desc.
add<
double>(
"ti_tr_max", +1.)->
setComment(
"maximum value for timing-tracking association cut");
146 verbosity_ (iConfig.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
158 default_time_ (iConfig.getParameter<double>(
"default_time")),
165 const unsigned int arm = (sector ==
"45") ? 0 : 1;
183 ->setComment(
"specification of the input lite-track collection");
185 desc.
add<
bool>(
"pixelDiscardBXShiftedTracks",
false)
186 ->setComment(
"whether to discard pixel tracks built from BX-shifted planes");
188 desc.
add<
std::string>(
"lhcInfoLabel",
"")->setComment(
"label of the LHCInfo record");
189 desc.
add<
std::string>(
"opticsLabel",
"")->setComment(
"label of the optics record");
191 desc.
addUntracked<
unsigned int>(
"verbosity", 0)->setComment(
"verbosity level");
193 desc.
add<
bool>(
"doSingleRPReconstruction",
true)
194 ->setComment(
"flag whether to apply single-RP reconstruction strategy");
196 desc.
add<
bool>(
"doMultiRPReconstruction",
true)
197 ->setComment(
"flag whether to apply multi-RP reconstruction strategy");
200 ->setComment(
"output label for single-RP reconstruction products");
203 ->setComment(
"output label for multi-RP reconstruction products");
205 desc.
add<
double>(
"localAngleXMin", -0.03)->
setComment(
"minimal accepted value of local horizontal angle (rad)");
206 desc.
add<
double>(
"localAngleXMax", +0.03)->
setComment(
"maximal accepted value of local horizontal angle (rad)");
207 desc.
add<
double>(
"localAngleYMin", -0.04)->
setComment(
"minimal accepted value of local vertical angle (rad)");
208 desc.
add<
double>(
"localAngleYMax", +0.04)->
setComment(
"maximal accepted value of local vertical angle (rad)");
213 ->setComment(
"track-association cuts for sector " + sector);
216 std::vector<edm::ParameterSet>
config;
218 desc.
add<
unsigned int>(
"max_n_timing_tracks", 5)->setComment(
"maximum number of timing tracks per RP");
220 desc.
add<
double>(
"default_time", 0.)->
setComment(
"proton time to be used when no timing information available");
222 desc.
add<
bool>(
"fitVtxY",
true)
223 ->setComment(
"for multi-RP reconstruction, flag whether y* should be free fit parameter");
225 desc.
add<
bool>(
"useImprovedInitialEstimate",
true)
226 ->setComment(
"for multi-RP reconstruction, flag whether a quadratic estimate of the initial point should be used");
228 descriptions.
add(
"ctppsProtons", desc);
245 if (!hTracks->empty())
260 if (hOpticalFunctions->empty()) {
261 edm::LogInfo(
"CTPPSProtonProducer") <<
"No optical functions available, reconstruction disabled.";
275 std::ostringstream ssLog;
277 ssLog <<
"* input tracks:" << std::endl;
280 std::map<unsigned int, std::vector<unsigned int>> trackingSelection, timingSelection;
282 for (
unsigned int idx = 0;
idx < hTracks->size(); ++
idx)
284 const auto& tr = hTracks->at(
idx);
301 <<
"[" <<
idx <<
"] " 302 << tr.getRPId() <<
" (" << (
rpId.arm()*100 +
rpId.station()*10 +
rpId.rp()) <<
"): " 303 <<
"x=" << tr.getX() <<
" +- " << tr.getXUnc() <<
" mm, " 304 <<
"y=" << tr.getY() <<
" +- " << tr.getYUnc() <<
" mm" << std::endl;
309 trackingSelection[
rpId.arm()].push_back(
idx);
311 timingSelection[
rpId.arm()].push_back(
idx);
315 for (
const auto &arm_it : trackingSelection)
317 const auto &indices = arm_it.second;
322 std::map<unsigned int, reco::ForwardProton> singleRPResultsIndexed;
325 for (
const auto &
idx : indices)
328 ssLog << std::endl <<
"* reconstruction from track " <<
idx << std::endl;
337 std::set<unsigned int>
rpIds;
338 for (
const auto &
idx : indices)
339 rpIds.insert(hTracks->at(
idx).getRPId());
345 std::vector<std::pair<unsigned int, unsigned int>> idx_pairs;
346 std::map<unsigned int, unsigned int> idx_pair_multiplicity;
347 for (
const auto &
i : indices)
349 for (
const auto &j : indices)
351 const auto &tr_i = hTracks->at(
i);
352 const auto &tr_j = hTracks->at(j);
357 const auto &pr_i = singleRPResultsIndexed[
i];
358 const auto &pr_j = singleRPResultsIndexed[j];
360 if (tr_i.getRPId() == tr_j.getRPId())
368 if (ac.x_cut_apply &&
std::abs(tr_i.getX() - tr_j.getX() - ac.x_cut_mean) > ac.x_cut_value)
370 else if (ac.y_cut_apply &&
std::abs(tr_i.getY() - tr_j.getY() - ac.y_cut_mean) > ac.y_cut_value)
372 else if (ac.xi_cut_apply &&
std::abs(pr_i.xi() - pr_j.xi() - ac.xi_cut_mean) > ac.xi_cut_value)
374 else if (ac.th_y_cut_apply &&
std::abs(pr_i.thetaY() - pr_j.thetaY() - ac.th_y_cut_mean) > ac.th_y_cut_value)
380 idx_pairs.emplace_back(
i, j);
381 idx_pair_multiplicity[
i]++;
382 idx_pair_multiplicity[j]++;
387 std::map<unsigned int, unsigned int> timing_RP_track_multiplicity;
388 for (
const auto &ti : timingSelection[arm_it.first])
390 const auto &tr = hTracks->at(ti);
391 timing_RP_track_multiplicity[tr.getRPId()]++;
395 std::map<unsigned int, std::vector<unsigned int>> matched_timing_track_indices;
396 std::map<unsigned int, unsigned int> matched_timing_track_multiplicity;
397 for (
unsigned int pr_idx = 0; pr_idx < idx_pairs.size(); ++pr_idx)
399 const auto &
i = idx_pairs[pr_idx].first;
400 const auto &j = idx_pairs[pr_idx].second;
403 if (idx_pair_multiplicity[
i] > 1 || idx_pair_multiplicity[j] > 1)
406 const auto &tr_i = hTracks->at(
i);
407 const auto &tr_j = hTracks->at(j);
412 for (
const auto &ti : timingSelection[arm_it.first])
414 const auto &tr_ti = hTracks->at(ti);
422 const double f_i = (z_ti - z_j) / (z_i - z_j), f_j = (z_i - z_ti) / (z_i - z_j);
423 const double x_inter = f_i * tr_i.getX() + f_j * tr_j.getX();
424 const double x_inter_unc_sq = f_i*f_i * tr_i.getXUnc()*tr_i.getXUnc() + f_j*f_j * tr_j.getXUnc()*tr_j.getXUnc();
426 const double de_x = tr_ti.getX() - x_inter;
427 const double de_x_unc =
sqrt(tr_ti.getXUnc()*tr_ti.getXUnc() + x_inter_unc_sq);
428 const double r = (de_x_unc > 0.) ? de_x / de_x_unc : 1E100;
430 const bool matching = (ac.ti_tr_min < r && r < ac.ti_tr_max);
433 ssLog <<
"ti=" << ti <<
", i=" <<
i <<
", j=" << j
434 <<
" | z_ti=" << z_ti <<
", z_i=" << z_i <<
", z_j=" << z_j
435 <<
" | x_ti=" << tr_ti.getX() <<
", x_inter=" << x_inter <<
", de_x=" << de_x <<
", de_x_unc=" << de_x_unc
436 <<
", matching=" << matching << std::endl;
441 matched_timing_track_indices[pr_idx].push_back(ti);
442 matched_timing_track_multiplicity[ti]++;
447 for (
unsigned int pr_idx = 0; pr_idx < idx_pairs.size(); ++pr_idx)
449 const auto &
i = idx_pairs[pr_idx].first;
450 const auto &j = idx_pairs[pr_idx].second;
453 if (idx_pair_multiplicity[
i] > 1 || idx_pair_multiplicity[j] > 1)
457 ssLog << std::endl <<
"* reconstruction from tracking-RP tracks: " <<
i <<
", " << j <<
" and timing-RP tracks: ";
467 double sw=0., swt=0.;
468 for (
const auto &ti : matched_timing_track_indices[pr_idx])
471 if (matched_timing_track_multiplicity[ti] > 1)
479 const auto &tr = hTracks->at(ti);
480 const double t_unc = tr.getTimeUnc();
481 const double w = (t_unc > 0.) ? 1./t_unc/t_unc : 1.;
483 swt += w * tr.getTime();
490 time_unc = 1. /
sqrt(sw);
494 ssLog << std::endl <<
" time = " << time <<
" +- " << time_unc << std::endl;
504 pOutMultiRP->emplace_back(proton);
509 for (
const auto &
p : singleRPResultsIndexed)
510 pOutSingleRP->emplace_back(
std::move(
p.second));
T getParameter(std::string const &) const
void setComment(std::string const &value)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::string lhcInfoLabel_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
reco::ForwardProton reconstructFromSingleRP(const CTPPSLocalTrackLiteRef &track, const LHCInfo &lhcInfo, std::ostream &os) const
run proton reconstruction using single-RP strategy
bool doMultiRPReconstruction_
bool pixelDiscardBXShiftedTracks_
void load(const edm::ParameterSet &ps)
~CTPPSProtonProducer() override=default
unsigned int max_n_timing_tracks_
Event setup record containing the real (actual) geometry information.
void init(const LHCInterpolatedOpticalFunctionsSetCollection &opticalFunctions)
#define DEFINE_FWK_MODULE(type)
void setTimeError(float time_err)
reco::ForwardProton reconstructFromMultiRP(const CTPPSLocalTrackLiteRefVector &tracks, const LHCInfo &lhcInfo, std::ostream &os) const
run proton reconstruction using multiple-RP strategy
CTPPSProtonProducer(const edm::ParameterSet &)
edm::ESWatcher< CTPPSInterpolatedOpticsRcd > opticsWatcher_
Abs< T >::type abs(const T &t)
edm::Ref< CTPPSLocalTrackLiteCollection > CTPPSLocalTrackLiteRef
Persistent reference to a CTPPSLocalTrackLite.
std::map< unsigned int, AssociationCuts > association_cuts_
static edm::ParameterSetDescription getDefaultParameters()
ParameterDescriptionBase * add(U const &iLabel, T const &value)
CLHEP::Hep3Vector getRPTranslation(unsigned int id) const
std::vector< CTPPSLocalTrackLite > CTPPSLocalTrackLiteCollection
Collection of CTPPSLocalTrackLite objects.
ParameterSet const & getParameterSet(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
bool check(const edm::EventSetup &iSetup)
Base class for CTPPS detector IDs.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ProtonReconstructionAlgorithm algorithm_
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
void setContributingLocalTracks(const CTPPSLocalTrackLiteRefVector &v)
store the list of RP tracks that contributed to this global track
std::string singleRPReconstructionLabel_
std::string multiRPReconstructionLabel_
bool doSingleRPReconstruction_
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tracksToken_