CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CaloParticleSelector.h
Go to the documentation of this file.
1 #ifndef Validation_HGCalValidation_CaloParticleSelector_h
2 #define Validation_HGCalValidation_CaloParticleSelector_h
3 
9 
11 public:
14  double ptMax,
15  double minRapidity,
16  double maxRapidity,
17  double lip,
18  double tip,
19  int minHit,
20  unsigned int maxSimClusters,
21  bool signalOnly,
22  bool intimeOnly,
23  bool chargedOnly,
24  bool stableOnly,
25  bool notConvertedOnly,
26  const std::vector<int>& pdgId = std::vector<int>(),
27  double minPhi = -3.2,
28  double maxPhi = 3.2)
29  : ptMin2_(ptMin * ptMin),
30  ptMax2_(ptMax * ptMax),
31  minRapidity_(minRapidity),
32  maxRapidity_(maxRapidity),
33  lip_(lip),
34  tip2_(tip * tip),
35  meanPhi_((minPhi + maxPhi) / 2.),
36  rangePhi_((maxPhi - minPhi) / 2.),
37  minHit_(minHit),
38  maxSimClusters_(maxSimClusters),
39  signalOnly_(signalOnly),
40  intimeOnly_(intimeOnly),
41  chargedOnly_(chargedOnly),
42  stableOnly_(stableOnly),
43  notConvertedOnly_(notConvertedOnly),
44  pdgId_(pdgId) {
45  if (minPhi >= maxPhi) {
46  throw cms::Exception("Configuration")
47  << "CaloParticleSelector: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi
48  << "). The range is constructed from minPhi to maxPhi around their average.";
49  }
50  if (minPhi >= M_PI) {
51  throw cms::Exception("Configuration")
52  << "CaloParticleSelector: minPhi (" << minPhi
53  << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
54  }
55  if (maxPhi <= -M_PI) {
56  throw cms::Exception("Configuration")
57  << "CaloParticleSelector: maxPhi (" << maxPhi
58  << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
59  }
60  }
61 
62  // Operator() performs the selection: e.g. if (cPSelector(cp)) {...}
63  // For the moment there shouldn't be any SimTracks from different crossings in the CaloParticle.
64  bool operator()(const CaloParticle& cp, std::vector<SimVertex> const& simVertices) const {
65  // signal only means no PU particles
66  if (signalOnly_ && !(cp.eventId().bunchCrossing() == 0 && cp.eventId().event() == 0))
67  return false;
68  // intime only means no OOT PU particles
69  if (intimeOnly_ && !(cp.eventId().bunchCrossing() == 0))
70  return false;
71 
72  if (cp.simClusters().size() > maxSimClusters_)
73  return false;
74 
75  auto pdgid = cp.pdgId();
76  if (!pdgId_.empty()) {
77  bool testId = false;
78  for (auto id : pdgId_) {
79  if (id == pdgid) {
80  testId = true;
81  break;
82  }
83  }
84  if (!testId)
85  return false;
86  }
87 
88  if (chargedOnly_ && cp.charge() == 0)
89  return false; //select only if charge!=0
90 
91  // select only stable particles
92  if (stableOnly_) {
94  if (j->get() == nullptr || j->get()->status() != 1) {
95  return false;
96  }
97  }
98 
99  // test for remaining unstabled due to lack of genparticle pointer
100  std::vector<int> pdgids{11, 13, 211, 321, 2212, 3112, 3222, 3312, 3334};
101  if (cp.status() == -99 && (!std::binary_search(pdgids.begin(), pdgids.end(), std::abs(pdgid)))) {
102  return false;
103  }
104  }
105 
106  // select only particles which did not convert/decay before the calorimeter
107  // in case of electrons, bremsstrahlung is usually the cause, thus this selection is skipped
108  if (std::abs(pdgid) != 11) {
109  if (notConvertedOnly_) {
110  if (cp.g4Tracks()[0].getPositionAtBoundary() == math::XYZTLorentzVectorF(0, 0, 0, 0)) {
111  return false;
112  }
113  if (cp.g4Tracks()[0].getMomentumAtBoundary() == math::XYZTLorentzVectorF(0, 0, 0, 0)) {
114  return false;
115  }
116  }
117  }
118 
119  auto etaOk = [&](const CaloParticle& p) -> bool {
120  float eta = etaFromXYZ(p.px(), p.py(), p.pz());
121  return (eta >= minRapidity_) & (eta <= maxRapidity_);
122  };
123  auto phiOk = [&](const CaloParticle& p) {
124  float dphi = deltaPhi(atan2f(p.py(), p.px()), meanPhi_);
125  return dphi >= -rangePhi_ && dphi <= rangePhi_;
126  };
127  auto ptOk = [&](const CaloParticle& p) {
128  double pt2 = cp.p4().perp2();
129  return pt2 >= ptMin2_ && pt2 <= ptMax2_;
130  };
131 
132  return (ptOk(cp) && etaOk(cp) && phiOk(cp));
133  }
134 
135 private:
136  double ptMin2_;
137  double ptMax2_;
140  double lip_;
141  double tip2_;
142  float meanPhi_;
143  float rangePhi_;
144  int minHit_;
145  unsigned int maxSimClusters_;
151  std::vector<int> pdgId_;
152 };
153 
156 
157 namespace reco {
158  namespace modules {
159 
160  template <>
163 
165  return CaloParticleSelector(cfg.getParameter<double>("ptMinCP"),
166  cfg.getParameter<double>("ptMaxCP"),
167  cfg.getParameter<double>("minRapidityCP"),
168  cfg.getParameter<double>("maxRapidityCP"),
169  cfg.getParameter<double>("lip"),
170  cfg.getParameter<double>("tip"),
171  cfg.getParameter<int>("minHitCP"),
172  cfg.getParameter<int>("maxSimClustersCP"),
173  cfg.getParameter<bool>("signalOnlyCP"),
174  cfg.getParameter<bool>("intimeOnlyCP"),
175  cfg.getParameter<bool>("chargedOnlyCP"),
176  cfg.getParameter<bool>("stableOnlyCP"),
177  cfg.getParameter<bool>("notConvertedOnlyCP"),
178  cfg.getParameter<std::vector<int> >("pdgIdCP"),
179  cfg.getParameter<double>("minPhiCP"),
180  cfg.getParameter<double>("maxPhiCP"));
181  }
182  };
183 
184  } // namespace modules
185 } // namespace reco
186 
187 #endif
CaloParticleSelector(double ptMin, double ptMax, double minRapidity, double maxRapidity, double lip, double tip, int minHit, unsigned int maxSimClusters, bool signalOnly, bool intimeOnly, bool chargedOnly, bool stableOnly, bool notConvertedOnly, const std::vector< int > &pdgId=std::vector< int >(), double minPhi=-3.2, double maxPhi=3.2)
int event() const
get the contents of the subdetector field (should be protected?)
tuple cfg
Definition: looper.py:296
static CaloParticleSelector make(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
bool operator()(const CaloParticle &cp, std::vector< SimVertex > const &simVertices) const
list pdgids
Definition: ntuple.py:97
constexpr float ptMin
EncodedEventId eventId() const
Signal source, crossing number.
Definition: CaloParticle.h:54
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
Definition: CaloParticle.h:79
int status() const
Status word.
Definition: CaloParticle.h:155
const std::vector< SimTrack > & g4Tracks() const
Definition: CaloParticle.h:74
genp_iterator genParticle_begin() const
iterators
Definition: CaloParticle.h:63
const math::XYZTLorentzVectorF & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
Definition: CaloParticle.h:85
const SimClusterRefVector & simClusters() const
Definition: CaloParticle.h:72
int bunchCrossing() const
get the detector field from this detid
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define M_PI
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int pdgId() const
PDG ID.
Definition: CaloParticle.h:43
static CaloParticleSelector make(const edm::ParameterSet &cfg)
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
std::vector< int > pdgId_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > XYZTLorentzVectorF
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:22
genp_iterator genParticle_end() const
Definition: CaloParticle.h:64