SelectionDefinitions.h
Go to the documentation of this file.
2  private:
3  double fEndZLow, fEndZHigh;
4  double fThreshold;
5  public:
6  new_interaction_topology(double endz_low, double endz_high,
7  double threshold)
8  : fEndZLow(endz_low), fEndZHigh(endz_high), fThreshold(threshold) {}
9 
10  int operator()(int pdg, double endZ,
11  std::string process, int nPi0,
12  std::vector<int> & true_daughter_pdg,
13  std::vector<double> & true_daughter_startP/*,
14  std::vector<double> & incidentEnergies*/) {
15 
16  int topology = -1;
17  if (pdg == 211) {
18  if (endZ < fEndZLow/*-.49375*/) {
19  topology = 4;
20  }
21  //After FV
22  else if (endZ > fEndZHigh/*222.10561*/) {
23  topology = 6;
24  }
25  else if (process == "pi+Inelastic") {
26  //daughters with & without thresholds
27  bool has_pion_above_threshold = false;
28  for (size_t i = 0; i < true_daughter_startP.size(); ++i) {
29  if (abs(true_daughter_pdg[i]) == 211 &&
30  true_daughter_startP[i] > fThreshold/*.150*/) {
31  has_pion_above_threshold = true;
32  break;
33  }
34  }
35 
36  if (has_pion_above_threshold) {
37  topology = 3;
38  }
39  else if (nPi0 == 0) {
40  topology = 1;
41  }
42  else if (nPi0 > 0) {
43  topology = 2;
44  }
45  }
46  else {
47  topology = 7;
48  }
49  }
50  else if (pdg == -13) {
51  topology = 5;
52  }
53  else {
54  topology = 7;
55  }
56 
57  return topology;
58 
59  }
60 };
61 
62 auto selection_ID = [](bool beam_is_track, bool ends_in_APA3,
63  bool no_pion_daughter,
64  bool beam_cuts, bool has_shower) {
65  if (!beam_is_track) {
66  return 6;
67  }
68 
69  if (!beam_cuts) {
70  return 5;
71  }
72 
73  if (!ends_in_APA3) {
74  return 4;
75  }
76 
77  if (!no_pion_daughter) {
78  return 3;
79  }
80 
81  if (has_shower) {
82  return 2;
83  }
84  else {
85  return 1;
86  }
87 };
88 
89 auto daughter_PDG_types(const std::vector<int> bt_PDGs) {
90  std::vector<int> results;
91  for (const int PDG : bt_PDGs) {
92  if (abs(PDG) == 211) {
93  results.push_back(1);
94  }
95  else if (abs(PDG) == 13) {
96  results.push_back(2);
97  }
98  else if (abs(PDG) == 2212) {
99  results.push_back(3);
100  }
101  else if (abs(PDG) == 22) {
102  results.push_back(4);
103  }
104  else if (abs(PDG) > 2212) {
105  results.push_back(5);
106  }
107  else if (abs(PDG) == 11) {
108  results.push_back(6);
109  }
110  else {
111  results.push_back(7);
112  }
113  }
114  return results;
115 }
116 
118  const int beam_ID,
119  const std::vector<int> bt_origins, const std::vector<int> bt_IDs,
120  const std::vector<int> bt_PDGs, const std::vector<int> bt_ParIDs,
121  const std::vector<int> bt_ParPDGs,
122  const std::vector<int> true_daughters,
123  const std::vector<int> true_grand_daughters) {
124  std::vector<int> results;
125  for (size_t i = 0; i < bt_origins.size(); ++i) {
126  if (bt_IDs[i] == beam_ID) {
127  results.push_back(1);
128  }
129  else if (bt_origins[i] == 2) {
130  results.push_back(2);
131  }
132  else if (abs(bt_PDGs[i]) == 11 && (abs(bt_ParPDGs[i]) == 13)) {
133  results.push_back(10);
134  }
135  else if (std::find(true_daughters.begin(), true_daughters.end(), bt_IDs[i]) !=
136  true_daughters.end()) {
137  if (abs(bt_PDGs[i]) == 211) {
138  results.push_back(3);
139  }
140  else if (abs(bt_PDGs[i]) == 13) {
141  results.push_back(4);
142  }
143  else if (bt_PDGs[i] == 2212) {
144  results.push_back(5);
145  }
146  else if (bt_PDGs[i] == 22) {
147  results.push_back(6);
148  }
149  else if (bt_PDGs[i] > 2212) {
150  results.push_back(7);
151  }
152  else {
153  //std::cout << bt_PDGs[i] << " " << bt_ParPDGs[i] << " " << (abs(bt_PDGs[i]) == 11 && (abs(bt_ParPDGs[i]) == 13)) << std::endl;
154  results.push_back(12);
155  }
156  }
157  else if (std::find(true_grand_daughters.begin(),
158  true_grand_daughters.end(), bt_IDs[i]) !=
159  true_grand_daughters.end()) {
160  if ((bt_PDGs[i] == 22 || abs(bt_PDGs[i]) == 11) && bt_ParPDGs[i] == 111) {
161  results.push_back(11);
162  }
163  else {
164  results.push_back(8);
165  }
166  }
167  else if (std::find(true_grand_daughters.begin(),
168  true_grand_daughters.end(), bt_ParIDs[i]) !=
169  true_grand_daughters.end()) {
170  results.push_back(9);
171  }
172  else {
173  //std::cout << bt_PDGs[i] << " " << bt_ParPDGs[i] << " " << (abs(bt_PDGs[i]) == 11 && (abs(bt_ParPDGs[i]) == 13)) << std::endl;
174  results.push_back(12);
175  }
176  }
177  return results;
178 };
179 
180 auto leading_p_costheta = [](const double & Px,
181  const double & Py, const double & Pz,
182  const std::vector<int> & dPDGs,
183  const std::vector<double> & dPx,
184  const std::vector<double> & dPy,
185  const std::vector<double> & dPz) {
186  double costheta = -999.;
187  double max_p = -999.;
188  double P = sqrt(Px*Px + Py*Py + Pz*Pz);
189  for (size_t i = 0; i < dPDGs.size(); ++i) {
190  if (dPDGs[i] != 2212) continue;
191 
192  double dP = sqrt(dPx[i]*dPx[i] + dPy[i]*dPy[i] + dPz[i]*dPz[i]);
193  if (dP > max_p) {
194  costheta = (dPx[i]*Px + dPy[i]*Py + dPz[i]*Pz)/(dP*P);
195  }
196  }
197  return costheta;
198 };
199 
201  private:
202  int fPDG;
203  public:
204  leading_costheta(int pdg) : fPDG(pdg) {}
205 
206  double operator()(const double & Px,
207  const double & Py, const double & Pz,
208  const std::vector<int> & dPDGs,
209  const std::vector<double> & dPx,
210  const std::vector<double> & dPy,
211  const std::vector<double> & dPz) {
212  double costheta = -999.;
213  double max_p = -999.;
214  double P = sqrt(Px*Px + Py*Py + Pz*Pz);
215  for (size_t i = 0; i < dPDGs.size(); ++i) {
216  if (dPDGs[i] != fPDG) continue;
217 
218  double dP = sqrt(dPx[i]*dPx[i] + dPy[i]*dPy[i] + dPz[i]*dPz[i]);
219  if (dP > max_p) {
220  costheta = (dPx[i]*Px + dPy[i]*Py + dPz[i]*Pz)/(dP*P);
221  }
222  }
223  return costheta;
224  }
225 };
226 
228  const bool matched,
229  const int origin, const int PDG) {
230  if (process == "primary" && matched && origin == 4 && PDG == 211) {
231  return 1;
232  }
233  else if (process == "primary" && matched && origin == 4 && PDG == -13) {
234  return 2;
235  }
236  else if (origin == 2) {
237  return 3;
238  }
239  else if (process == "primaryBackground") {
240  return 4;
241  }
242  else if (process.find("Inelastic") != std::string::npos) {
243  return 5;
244  }
245  else if (process == "Decay") {
246  return 6;
247  }
248  else {
249  return 7;
250  }
251 };
252 
253 
255  private:
256  double fLimit;
257  public:
258  truncatedMean_pos(double limit)
259  : fLimit(limit) {}
260 
261  std::vector<double> operator()(
262  std::vector<std::vector<double>> &vecs_dEdX) {
263  //size_t size = 0;
264  std::vector<double> trunc_mean;
265  //std::vector<double> help_vec;
266  double truncate_high = 1 - fLimit;
267  int i_low = 0;
268  int i_high = 0;
269 
270  //sort the dEdX vecotrs in matrix
271  for(auto &&vec : vecs_dEdX){
272  //size = vec.size();
273  std::vector<double> help_vec;
274 
275 
276  //check dEdX vector isn't empty!
277  if(vec.empty()){
278  trunc_mean.push_back(-9999.);
279  continue;
280  }
281 
282  else{
283  std::vector<double> temp_vec;
284  for (double d : vec) {
285  if (d < 0.) {
286  continue;
287  }
288  temp_vec.push_back(d);
289  }
290  for (double d : temp_vec) {
291  if (d < 0.) {
292  std::cout << d << std::endl;
293  }
294  }
295  if (temp_vec.empty()) {
296  trunc_mean.push_back(-9999.);
297  continue;
298  }
299  //Sort Vector
300  sort(temp_vec.begin(), temp_vec.end());
301 
302  //Discard upper and lower part of signal
303  //rint rounds to integer
304  i_low = rint ( temp_vec.size()*fLimit);
305  i_high = rint( temp_vec.size()*truncate_high);
306 
307 
308  //if (i_high >= temp_vec.size()) std::cout << "Warning: too high" << std::endl;
309  for(int i = i_low; i </*=*/ i_high; i++){
310  if (temp_vec[i] < 0) {
311  std::cout << "added " << temp_vec[i] << " " << i << std::endl;
312  }
313  help_vec.push_back(temp_vec[i]);
314  };
315 
316  //Mean of help vector
317 
318  trunc_mean.push_back(accumulate(help_vec.begin(), help_vec.end(), 0.0) / help_vec.size());
319  if (trunc_mean.back() < 0 && trunc_mean.back() != -9999. && trunc_mean.back() != -999.) {
320  std::cout << accumulate(help_vec.begin(), help_vec.end(), 0.0) << " " << help_vec.size() << std::endl;
321  std::cout << temp_vec.size() << " " << i_low << " " << i_high << std::endl;
322  for (size_t i = 0; i < help_vec.size(); ++i) {
323  std::cout << "\t" << help_vec[i] << std::endl;
324  }
325  }
326  }
327 
328 
329  }
330  return trunc_mean;
331  }
332 
333 };
334 
335 
337  private:
339  public:
340  shower_dists(double cut)
341  : fTrackScoreCut(cut) {}
342  std::vector<double> operator ()(const std::vector<double> &track_score,
343  const std::vector<double> &shower_x,
344  const std::vector<double> &shower_y,
345  const std::vector<double> &shower_z,
346  double & x, double & y, double & z) {
347  std::vector<double> results;
348  for(size_t i = 0; i < track_score.size(); ++i){
349  if ((track_score[i] < fTrackScoreCut) &&
350  (track_score[i] > 0.)) {
351  double dist = sqrt(std::pow((shower_x[i] - x), 2) +
352  std::pow((shower_y[i] - y), 2) +
353  std::pow((shower_z[i] - z), 2));
354  results.push_back(dist);
355  }
356  else {
357  results.push_back(-999.);
358  }
359  }
360 
361  return results;
362  }
363 };
364 
365 
367  private:
369  public:
371  : fTrackScoreCut(cut) {}
372  bool operator()(const std::vector<double> &track_score,
373  const std::vector<double> &shower_x,
374  const std::vector<double> &shower_y,
375  const std::vector<double> &shower_z,
376  const std::vector<double> &energy,
377  double & x, double & y, double & z) {
378  for(size_t i = 0; i < track_score.size(); ++i){
379  double dist = sqrt(std::pow((shower_x[i] - x), 2) +
380  std::pow((shower_y[i] - y), 2) +
381  std::pow((shower_z[i] - z), 2));
382  if ((track_score[i] < fTrackScoreCut) &&
383  (track_score[i] > 0.) &&
384  (dist > 5. && dist < 1000.) &&
385  (energy[i] > 80. && energy[i] < 1000.)) {
386  return true;
387  }
388  }
389 
390  return false;
391  }
392 };
393 
394 class isBeamType {
395  private:
397  public:
398  isBeamType(bool check_calo)
399  : fCheckCalo(check_calo) {}
400  bool operator()(int reco_beam_type, std::vector<double> energies) {
401  if (fCheckCalo) {
402  return (energies.size() > 0 && reco_beam_type == 13);
403  }
404 
405  return (reco_beam_type == 13);
406  }
407 };
408 
409 class endAPA3 {
410  private:
411  double fEndZCut;
412  public:
413  endAPA3(double cut)
414  : fEndZCut(cut) {}
415 
416  bool operator()(double reco_beam_endZ) {
417  return (reco_beam_endZ < fEndZCut);
418  }
419 };
420 
422  private:
424  double fChi2Cut;
425  double fdEdXLow, fdEdXMed, fdEdXHigh;
426  public:
427  secondary_noPion(double track_score_cut, double chi2_cut,
428  double dEdX_low, double dEdX_med, double dEdX_high)
429  : fTrackScoreCut(track_score_cut),
430  fChi2Cut(chi2_cut),
431  fdEdXLow(dEdX_low),
432  fdEdXMed(dEdX_med),
433  fdEdXHigh(dEdX_high) {}
435  const std::vector<double> &track_score,
436  const std::vector<int> &trackID,
437  const std::vector<double> &dEdX,
438  const std::vector<double> &chi2,
439  const std::vector<int> &ndof) {
440  for( size_t i = 0; i < track_score.size(); ++i ) {
441  if ((trackID[i] != -999) && (track_score[i] > fTrackScoreCut)) {
442  if (dEdX[i] < fdEdXMed/*2.8*/ && dEdX[i] > fdEdXLow/*0.5*/) {
443  return false;
444  }
445  //else if (dEdX[i] > 2.8 && dEdX[i] < 3.4) {
446  else if (dEdX[i] < fdEdXHigh) {
447  if (ndof[i] > 0 && chi2[i]/ndof[i] > fChi2Cut) {
448  return false;
449  }
450  }
451  }
452  }
453 
454  return true;
455  }
456 };
457 
458 auto data_beam_PID = [](const std::vector<int>& pidCandidates){
459  auto pid_search = std::find(pidCandidates.begin(), pidCandidates.end(), 211);
460  return (pid_search != pidCandidates.end());
461 };
462 
464  private:
465  bool fDoTracks;
466  public:
467  data_BI_quality(bool do_tracks)
468  : fDoTracks(do_tracks) {}
469  bool operator()(int data_BI_nMomenta, int data_BI_nTracks) {
470 
471  if (fDoTracks) {
472  return (data_BI_nMomenta == 1 && data_BI_nTracks == 1);
473  }
474  else {
475  return (data_BI_nMomenta == 1);
476  }
477  }
478 };
479 
480 class beam_cut_BI {
481  private:
482  double fXLow, fXHigh,
483  fYLow, fYHigh,
484  fZLow, fZHigh,
485  fCosLow;
486  public:
487  beam_cut_BI(double x_low, double x_high,
488  double y_low, double y_high,
489  double z_low, double z_high,
490  double cos_low)
491  : fXLow(x_low), fXHigh(x_high),
492  fYLow(y_low), fYHigh(y_high),
493  fZLow(z_low), fZHigh(z_high),
494  fCosLow(cos_low) {}
495  bool operator()(double startX,
496  double startY, double startZ,
497  double dirX, double dirY,
498  double dirZ, double BI_X,
499  double BI_Y, double BI_dirX,
500  double BI_dirY, double BI_dirZ) {
501 
502  double deltaX = startX - BI_X;
503  double deltaY = startY - BI_Y;
504  double cos = BI_dirX*dirX + BI_dirY*dirY +
505  BI_dirZ*dirZ;
506  if( (deltaX < fXLow) || (deltaX > fXHigh) )
507  return false;
508 
509  if ( (deltaY < fYLow) || (deltaY > fYHigh) )
510  return false;
511 
512  if ( (startZ < fZLow) || (startZ > fZHigh) )
513  return false;
514 
515  if (cos < fCosLow)
516  return false;
517 
518  return true;
519  }
520 };
521 
523  private:
524  bool fDoAngle;
525  //double fXCut, fYCut, fZCut, fCosLow;
526  double fXYZCut, fCosCut;
527  double fMeanX, fMeanY, fMeanZ;
528  double fSigmaX, fSigmaY, fSigmaZ;
529  double fMeanThetaX, fMeanThetaY, fMeanThetaZ;
530 
531  public:
532  beam_cut_TPC(bool do_angle, double xyz_cut, double cos_cut,
533  double mean_x, double mean_y, double mean_z,
534  double sigma_x, double sigma_y, double sigma_z,
535  double mean_theta_x, double mean_theta_y, double mean_theta_z)
536  : fDoAngle(do_angle),
537  fXYZCut(xyz_cut), fCosCut(cos_cut),
538  fMeanX(mean_x), fMeanY(mean_y), fMeanZ(mean_z),
539  fSigmaX(sigma_x), fSigmaY(sigma_y), fSigmaZ(sigma_z),
540  fMeanThetaX(mean_theta_x), fMeanThetaY(mean_theta_y),
541  fMeanThetaZ(mean_theta_z) {}
542 
543  bool operator()(double calo_beam_startX, double calo_beam_startY,
544  double calo_beam_startZ, double calo_beam_endX,
545  double calo_beam_endY, double calo_beam_endZ) {
546 
547  double diffX = calo_beam_endX - calo_beam_startX;
548  double diffY = calo_beam_endY - calo_beam_startY;
549  double diffZ = calo_beam_endZ - calo_beam_startZ;
550  double r = sqrt(diffX*diffX + diffY*diffY + diffZ*diffZ);
551 
552  double cosTrk_thetaX = diffX / r;
553  double cosTrk_thetaY = diffY / r;
554  double cosTrk_thetaZ = diffZ / r;
555 
556  double cosTheta = cos(fMeanThetaX*TMath::Pi()/180.)*cosTrk_thetaX +
557  cos(fMeanThetaY*TMath::Pi()/180.)*cosTrk_thetaY +
558  cos(fMeanThetaZ*TMath::Pi()/180.)*cosTrk_thetaZ;
559 
560  if (abs((calo_beam_startX - fMeanX)/fSigmaX) > fXYZCut)
561  return false;
562 
563  if (abs((calo_beam_startY - fMeanY)/fSigmaY) > fXYZCut)
564  return false;
565 
566  if (abs((calo_beam_startZ - fMeanZ)/fSigmaZ) > fXYZCut)
567  return false;
568 
569  if (fDoAngle && (cosTheta < fCosCut))
570  return false;
571 
572  return true;
573  }
574 };
beam_cut_BI(double x_low, double x_high, double y_low, double y_high, double z_low, double z_high, double cos_low)
bool operator()(int reco_beam_type, std::vector< double > energies)
std::string string
Definition: nybbler.cc:12
int operator()(int pdg, double endZ, std::string process, int nPi0, std::vector< int > &true_daughter_pdg, std::vector< double > &true_daughter_startP)
auto data_beam_PID
truncatedMean_pos(double limit)
constexpr T pow(T x)
Definition: pow.h:72
struct vector vector
std::pair< float, std::string > P
bool operator()(int data_BI_nMomenta, int data_BI_nTracks)
double dEdX(double KE, const simb::MCParticle *part)
endAPA3(double cut)
const uint PDG
Definition: qregexp.cpp:140
def process(f, kind)
Definition: search.py:254
T abs(T value)
auto leading_p_costheta
auto backtrack_beam
std::vector< double > operator()(std::vector< std::vector< double >> &vecs_dEdX)
auto selection_ID
data_BI_quality(bool do_tracks)
auto daughter_PDG_types(const std::vector< int > bt_PDGs)
auto categorize_daughters
isBeamType(bool check_calo)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
bool operator()(double calo_beam_startX, double calo_beam_startY, double calo_beam_startZ, double calo_beam_endX, double calo_beam_endY, double calo_beam_endZ)
secondary_noPion(double track_score_cut, double chi2_cut, double dEdX_low, double dEdX_med, double dEdX_high)
beam_cut_TPC(bool do_angle, double xyz_cut, double cos_cut, double mean_x, double mean_y, double mean_z, double sigma_x, double sigma_y, double sigma_z, double mean_theta_x, double mean_theta_y, double mean_theta_z)
bool operator()(const std::vector< double > &track_score, const std::vector< int > &trackID, const std::vector< double > &dEdX, const std::vector< double > &chi2, const std::vector< int > &ndof)
list x
Definition: train.py:276
bool operator()(const std::vector< double > &track_score, const std::vector< double > &shower_x, const std::vector< double > &shower_y, const std::vector< double > &shower_z, const std::vector< double > &energy, double &x, double &y, double &z)
bool operator()(double startX, double startY, double startZ, double dirX, double dirY, double dirZ, double BI_X, double BI_Y, double BI_dirX, double BI_dirY, double BI_dirZ)
bool operator()(double reco_beam_endZ)
double operator()(const double &Px, const double &Py, const double &Pz, const std::vector< int > &dPDGs, const std::vector< double > &dPx, const std::vector< double > &dPy, const std::vector< double > &dPz)
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
QTextStream & endl(QTextStream &s)
new_interaction_topology(double endz_low, double endz_high, double threshold)
shower_dists(double cut)