CMS 3D CMS Logo

PPSFilteredProtonProducer.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kaspar
4  ****************************************************************************/
5 
10 
15 
16 #include <ostream>
17 
18 //----------------------------------------------------------------------------------------------------
19 
22 public:
24  ~PPSFilteredProtonProducer() override = default;
25 
26  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
27 
28 private:
29  void produce(edm::Event &, const edm::EventSetup &) override;
30  void endStream() override;
31 
33 
34  bool verbosity_;
35 
37 
38  std::vector<unsigned int> tracks_pixel_forbidden_RecoInfo_values_;
41 
45 
49 
53 
57 
59  bool IsTrackOK(const CTPPSLocalTrackLite &tr, unsigned int idx, std::ostringstream &log);
60 };
61 
62 //----------------------------------------------------------------------------------------------------
63 
65  : verbosity_(iConfig.getUntrackedParameter<bool>("verbosity")),
70  const auto &tracks_all = iConfig.getParameterSet("tracks_all");
71  tracks_all_local_angle_x_max_ = tracks_all.getParameter<double>("local_angle_x_max");
72  tracks_all_local_angle_y_max_ = tracks_all.getParameter<double>("local_angle_y_max");
73 
74  const auto &tracks_pixel = iConfig.getParameterSet("tracks_pixel");
76  tracks_pixel.getParameter<std::vector<unsigned int>>("forbidden_RecoInfo_values");
77  tracks_pixel_number_of_hits_min_ = tracks_pixel.getParameter<unsigned int>("number_of_hits_min");
78  tracks_pixel_normalised_chi_sq_max_ = tracks_pixel.getParameter<double>("normalised_chi_sq_max");
79 
80  const auto &protons_single_rp = iConfig.getParameterSet("protons_single_rp");
81  protons_single_rp_include_ = protons_single_rp.getParameter<bool>("include");
83  consumes<reco::ForwardProtonCollection>(protons_single_rp.getParameter<edm::InputTag>("input_tag"));
84  protons_single_rp_output_label_ = protons_single_rp.getParameter<std::string>("output_label");
85 
86  const auto &protons_multi_rp = iConfig.getParameterSet("protons_multi_rp");
87  protons_multi_rp_include_ = protons_multi_rp.getParameter<bool>("include");
89  consumes<reco::ForwardProtonCollection>(protons_multi_rp.getParameter<edm::InputTag>("input_tag"));
90  protons_multi_rp_output_label_ = protons_multi_rp.getParameter<std::string>("output_label");
91  protons_multi_rp_check_valid_fit_ = protons_multi_rp.getParameter<bool>("check_valid_fit");
92  protons_multi_rp_chi_sq_max_ = protons_multi_rp.getParameter<double>("chi_sq_max");
93  protons_multi_rp_normalised_chi_sq_max_ = protons_multi_rp.getParameter<double>("normalised_chi_sq_max");
94 
96  produces<reco::ForwardProtonCollection>(protons_single_rp_output_label_);
97 
99  produces<reco::ForwardProtonCollection>(protons_multi_rp_output_label_);
100 }
101 
102 //----------------------------------------------------------------------------------------------------
103 
106 
107  desc.addUntracked<bool>("verbosity", false)->setComment("verbosity");
108 
109  edm::ParameterSetDescription tracks_all;
110  tracks_all.add<double>("local_angle_x_max", 0.020)
111  ->setComment("maximum absolute value of local horizontal angle, in rad");
112  tracks_all.add<double>("local_angle_y_max", 0.020)
113  ->setComment("maximum absolute value of local horizontal angle, in rad");
114  desc.add<edm::ParameterSetDescription>("tracks_all", tracks_all)->setComment("settings for all tracks");
115 
116  edm::ParameterSetDescription tracks_pixel;
117  const std::vector<unsigned int> def_for_RecoInfo_vals = {
120  tracks_pixel.add<std::vector<unsigned int>>("forbidden_RecoInfo_values", def_for_RecoInfo_vals)
121  ->setComment("list of forbidden RecoInfo values");
122  tracks_pixel.add<unsigned int>("number_of_hits_min", 0)->setComment("minimum required number of hits");
123  tracks_pixel.add<double>("normalised_chi_sq_max", 1E100)->setComment("maximum tolerated chi square / ndof");
124  desc.add<edm::ParameterSetDescription>("tracks_pixel", tracks_pixel)
125  ->setComment("specific settings for pixel-RP tracks");
126 
128  protons_single_rp.add<bool>("include", true)->setComment("flag whether single-RP protons should be processed");
129  protons_single_rp.add<edm::InputTag>("input_tag", edm::InputTag("ctppsProtons", "singleRP"))->setComment("input tag");
130  protons_single_rp.add<std::string>("output_label", "singleRP")->setComment("output label");
131  desc.add<edm::ParameterSetDescription>("protons_single_rp", protons_single_rp)
132  ->setComment("settings for single-RP protons");
133 
134  edm::ParameterSetDescription protons_multi_rp;
135  protons_multi_rp.add<bool>("include", true)->setComment("flag whether multi-RP protons should be processed");
136  protons_multi_rp.add<edm::InputTag>("input_tag", edm::InputTag("ctppsProtons", "multiRP"))->setComment("input tag");
137  protons_multi_rp.add<std::string>("output_label", "multiRP")->setComment("output label");
138  protons_multi_rp.add<bool>("check_valid_fit", true)->setComment("flag whether validFit should be checked");
139  protons_multi_rp.add<double>("chi_sq_max", 1E-4)->setComment("maximum tolerated value of chi square");
140  protons_multi_rp.add<double>("normalised_chi_sq_max", 1E100)
141  ->setComment("maximum tolerated value of chi square / ndof, applied only if ndof > 0");
142  desc.add<edm::ParameterSetDescription>("protons_multi_rp", protons_multi_rp)
143  ->setComment("settings for multi-RP protons");
144 
145  descriptions.add("ppsFilteredProtonProducer", desc);
146 }
147 
148 //----------------------------------------------------------------------------------------------------
149 
150 bool PPSFilteredProtonProducer::IsTrackOK(const CTPPSLocalTrackLite &tr, unsigned int idx, std::ostringstream &log) {
151  bool ok = true;
152 
153  // checks for all tracks
156 
157  // pixel checks
158  const CTPPSDetId rpId(tr.getRPId());
159  if (rpId.subdetId() == CTPPSDetId::sdTrackingPixel) {
165  }
166 
167  if (!ok && verbosity_)
168  log << "track idx=" << idx << " does not fulfil criteria." << std::endl;
169 
170  return ok;
171 }
172 
173 //----------------------------------------------------------------------------------------------------
174 
176  std::ostringstream ssLog;
177 
178  // process single-RP protons
181  std::unique_ptr<reco::ForwardProtonCollection> pOutputProtons(new reco::ForwardProtonCollection);
182 
183  for (const auto &proton : hInputProtons) {
184  bool keep = true;
185 
186  // no specific checks for single-RP protons
187 
188  // test contributing tracks
189  for (const auto &tr_ref : proton.contributingLocalTracks()) {
190  if (!keep)
191  break;
192 
193  keep &= IsTrackOK(*tr_ref, tr_ref.key(), ssLog);
194  }
195 
197 
198  if (keep) {
200  pOutputProtons->push_back(proton);
201  } else {
202  if (verbosity_)
203  ssLog << "single-RP proton idx=" << n_protons_single_rp_all - 1 << " excluded." << std::endl;
204  }
205  }
206 
207  iEvent.put(std::move(pOutputProtons), protons_single_rp_output_label_);
208  }
209 
210  // process multi-RP protons
212  reco::ForwardProtonCollection const &hInputProtons = iEvent.get(protons_multi_rp_input_token_);
213  std::unique_ptr<reco::ForwardProtonCollection> pOutputProtons(new reco::ForwardProtonCollection);
214 
215  for (const auto &proton : hInputProtons) {
216  bool keep = true;
217 
218  // multi-RP proton checks
220  keep &= proton.validFit();
221 
222  keep &= (proton.chi2() <= protons_multi_rp_chi_sq_max_);
223 
224  if (proton.ndof() > 0)
225  keep &= (proton.normalizedChi2() <= protons_multi_rp_normalised_chi_sq_max_);
226 
227  // test contributing tracks
228  for (const auto &tr_ref : proton.contributingLocalTracks()) {
229  if (!keep)
230  break;
231 
232  keep &= IsTrackOK(*tr_ref, tr_ref.key(), ssLog);
233  }
234 
236 
237  if (keep) {
239  pOutputProtons->push_back(proton);
240  } else {
241  if (verbosity_)
242  ssLog << "multi-RP proton idx=" << n_protons_multi_rp_all - 1 << " excluded." << std::endl;
243  }
244  }
245 
246  iEvent.put(std::move(pOutputProtons), protons_multi_rp_output_label_);
247  }
248 
249  if (verbosity_ && !ssLog.str().empty())
250  edm::LogInfo("PPS") << ssLog.str();
251 }
252 
253 //----------------------------------------------------------------------------------------------------
254 
256  edm::LogInfo("PPS")
257  << "single-RP protons: total=" << n_protons_single_rp_all << ", kept=" << n_protons_single_rp_kept
258  << " --> keep rate="
260  << "%\n"
261  << "multi-RP protons: total=" << n_protons_multi_rp_all << ", kept=" << n_protons_multi_rp_kept
262  << " --> keep rate="
263  << ((n_protons_multi_rp_all > 0) ? double(n_protons_multi_rp_kept) / n_protons_multi_rp_all * 100. : 0.) << "%";
264 }
265 
266 //----------------------------------------------------------------------------------------------------
267 
void setComment(std::string const &value)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Local (=single RP) track with essential information only.
edm::EDGetTokenT< reco::ForwardProtonCollection > protons_single_rp_input_token_
float getTx() const
returns the track horizontal angle
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
CTPPSpixelLocalTrackReconstructionInfo getPixelTrackRecoInfo() const
returns the track reconstruction info byte
uint32_t getRPId() const
returns the RP id
const int keep
PPSFilteredProtonProducer(const edm::ParameterSet &)
float getChiSquaredOverNDF() const
returns the track fit chi Squared over NDF
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tracksToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:326
unsigned int n_protons_single_rp_all
counters
edm::EDGetTokenT< reco::ForwardProtonCollection > protons_multi_rp_input_token_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool IsTrackOK(const CTPPSLocalTrackLite &tr, unsigned int idx, std::ostringstream &log)
check one track
ParameterSet const & getParameterSet(std::string const &) const
void produce(edm::Event &, const edm::EventSetup &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
unsigned short getNumberOfPointsUsedForFit() const
returns the number of points used for fit
~PPSFilteredProtonProducer() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
std::vector< unsigned int > tracks_pixel_forbidden_RecoInfo_values_
float getTy() const
returns the track vertical angle
def move(src, dest)
Definition: eostools.py:511
Module to apply Proton POG quality criteria.