CMS 3D CMS Logo

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  const std::vector<int>& pdgId = std::vector<int>(),
26  double minPhi = -3.2,
27  double maxPhi = 3.2)
28  : ptMin2_(ptMin * ptMin),
29  ptMax2_(ptMax * ptMax),
32  lip_(lip),
33  tip2_(tip * tip),
34  meanPhi_((minPhi + maxPhi) / 2.),
35  rangePhi_((maxPhi - minPhi) / 2.),
36  minHit_(minHit),
37  maxSimClusters_(maxSimClusters),
42  pdgId_(pdgId) {
43  if (minPhi >= maxPhi) {
44  throw cms::Exception("Configuration")
45  << "CaloParticleSelector: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi
46  << "). The range is constructed from minPhi to maxPhi around their average.";
47  }
48  if (minPhi >= M_PI) {
49  throw cms::Exception("Configuration")
50  << "CaloParticleSelector: minPhi (" << minPhi
51  << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
52  }
53  if (maxPhi <= -M_PI) {
54  throw cms::Exception("Configuration")
55  << "CaloParticleSelector: maxPhi (" << maxPhi
56  << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
57  }
58  }
59 
60  // Operator() performs the selection: e.g. if (cPSelector(cp)) {...}
61  // For the moment there shouldn't be any SimTracks from different crossings in the CaloParticle.
62  bool operator()(const CaloParticle& cp, std::vector<SimVertex> const& simVertices) const {
63  // signal only means no PU particles
64  if (signalOnly_ && !(cp.eventId().bunchCrossing() == 0 && cp.eventId().event() == 0))
65  return false;
66  // intime only means no OOT PU particles
67  if (intimeOnly_ && !(cp.eventId().bunchCrossing() == 0))
68  return false;
69 
70  if (cp.simClusters().size() > maxSimClusters_)
71  return false;
72 
73  auto pdgid = cp.pdgId();
74  if (!pdgId_.empty()) {
75  bool testId = false;
76  for (auto id : pdgId_) {
77  if (id == pdgid) {
78  testId = true;
79  break;
80  }
81  }
82  if (!testId)
83  return false;
84  }
85 
86  if (chargedOnly_ && cp.charge() == 0)
87  return false; //select only if charge!=0
88 
89  // select only stable particles
90  if (stableOnly_) {
91  for (CaloParticle::genp_iterator j = cp.genParticle_begin(); j != cp.genParticle_end(); ++j) {
92  if (j->get() == nullptr || j->get()->status() != 1) {
93  return false;
94  }
95  }
96 
97  // test for remaining unstabled due to lack of genparticle pointer
98  std::vector<int> pdgids{11, 13, 211, 321, 2212, 3112, 3222, 3312, 3334};
99  if (cp.status() == -99 && (!std::binary_search(pdgids.begin(), pdgids.end(), std::abs(pdgid)))) {
100  return false;
101  }
102  }
103 
104  auto etaOk = [&](const CaloParticle& p) -> bool {
105  float eta = etaFromXYZ(p.px(), p.py(), p.pz());
106  return (eta >= minRapidity_) & (eta <= maxRapidity_);
107  };
108  auto phiOk = [&](const CaloParticle& p) {
109  float dphi = deltaPhi(atan2f(p.py(), p.px()), meanPhi_);
110  return dphi >= -rangePhi_ && dphi <= rangePhi_;
111  };
112  auto ptOk = [&](const CaloParticle& p) {
113  double pt2 = cp.p4().perp2();
114  return pt2 >= ptMin2_ && pt2 <= ptMax2_;
115  };
116 
117  return (ptOk(cp) && etaOk(cp) && phiOk(cp));
118  }
119 
120 private:
121  double ptMin2_;
122  double ptMax2_;
125  double lip_;
126  double tip2_;
127  float meanPhi_;
128  float rangePhi_;
129  int minHit_;
130  unsigned int maxSimClusters_;
135  std::vector<int> pdgId_;
136 };
137 
140 
141 namespace reco {
142  namespace modules {
143 
144  template <>
147 
149  return CaloParticleSelector(cfg.getParameter<double>("ptMinCP"),
150  cfg.getParameter<double>("ptMaxCP"),
151  cfg.getParameter<double>("minRapidityCP"),
152  cfg.getParameter<double>("maxRapidityCP"),
153  cfg.getParameter<double>("lip"),
154  cfg.getParameter<double>("tip"),
155  cfg.getParameter<int>("minHitCP"),
156  cfg.getParameter<int>("maxSimClustersCP"),
157  cfg.getParameter<bool>("signalOnlyCP"),
158  cfg.getParameter<bool>("intimeOnlyCP"),
159  cfg.getParameter<bool>("chargedOnlyCP"),
160  cfg.getParameter<bool>("stableOnlyCP"),
161  cfg.getParameter<std::vector<int> >("pdgIdCP"),
162  cfg.getParameter<double>("minPhiCP"),
163  cfg.getParameter<double>("maxPhiCP"));
164  }
165  };
166 
167  } // namespace modules
168 } // namespace reco
169 
170 #endif
trackingParticleSelector_cfi.signalOnly
signalOnly
Definition: trackingParticleSelector_cfi.py:9
HLT_2018_cff.pt2
pt2
Definition: HLT_2018_cff.py:8552
qcdUeDQM_cfi.minRapidity
minRapidity
Definition: qcdUeDQM_cfi.py:24
reco::modules::ParameterAdapter< CaloParticleSelector >::make
static CaloParticleSelector make(const edm::ParameterSet &cfg)
Definition: CaloParticleSelector.h:148
modules
Definition: ZHLTMatchFilter.cc:17
qcdUeDQM_cfi.maxRapidity
maxRapidity
Definition: qcdUeDQM_cfi.py:27
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ptMin
constexpr float ptMin
Definition: PhotonIDValueMapProducer.cc:153
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
CaloParticleSelector::meanPhi_
float meanPhi_
Definition: CaloParticleSelector.h:127
CaloParticleSelector::intimeOnly_
bool intimeOnly_
Definition: CaloParticleSelector.h:132
CaloParticleSelector::rangePhi_
float rangePhi_
Definition: CaloParticleSelector.h:128
qcdUeDQM_cfi.lip
lip
Definition: qcdUeDQM_cfi.py:25
HLT_2018_cff.minPhi
minPhi
Definition: HLT_2018_cff.py:51486
GenParticle.h
CaloParticleSelector::chargedOnly_
bool chargedOnly_
Definition: CaloParticleSelector.h:133
CaloParticleSelector
Definition: CaloParticleSelector.h:10
AlignmentTrackSelector_cfi.ptMax
ptMax
Definition: AlignmentTrackSelector_cfi.py:12
HLT_2018_cff.maxPhi
maxPhi
Definition: HLT_2018_cff.py:51498
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
PVValHelper::eta
Definition: PVValidationHelpers.h:69
CaloParticleSelector::operator()
bool operator()(const CaloParticle &cp, std::vector< SimVertex > const &simVertices) const
Definition: CaloParticleSelector.h:62
SimVertex.h
CaloParticleSelector::minRapidity_
float minRapidity_
Definition: CaloParticleSelector.h:123
qcdUeDQM_cfi.tip
tip
Definition: qcdUeDQM_cfi.py:23
reco::modules::ParameterAdapter< CaloParticleSelector >::make
static CaloParticleSelector make(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Definition: CaloParticleSelector.h:146
trackingParticleSelector_cfi.intimeOnly
intimeOnly
Definition: trackingParticleSelector_cfi.py:10
edm::ParameterSet
Definition: ParameterSet.h:36
CaloParticle
Definition: CaloParticle.h:16
genCandidates_cfi.stableOnly
stableOnly
Definition: genCandidates_cfi.py:6
CaloParticle.h
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
CaloParticleSelector::tip2_
double tip2_
Definition: CaloParticleSelector.h:126
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
qcdUeDQM_cfi.minHit
minHit
Definition: qcdUeDQM_cfi.py:33
CaloParticleSelector::lip_
double lip_
Definition: CaloParticleSelector.h:125
looper.cfg
cfg
Definition: looper.py:297
PtEtaPhiMass.h
CaloParticleSelector::maxRapidity_
float maxRapidity_
Definition: CaloParticleSelector.h:124
Exception
Definition: hltDiff.cc:246
edm::RefVectorIterator
Definition: EDProductfwd.h:33
CaloParticleSelector::CaloParticleSelector
CaloParticleSelector()
Definition: CaloParticleSelector.h:12
cosmictrackingParticleSelector_cfi.chargedOnly
chargedOnly
Definition: cosmictrackingParticleSelector_cfi.py:5
CaloParticleSelector::maxSimClusters_
unsigned int maxSimClusters_
Definition: CaloParticleSelector.h:130
CaloParticleSelector::signalOnly_
bool signalOnly_
Definition: CaloParticleSelector.h:131
ParameterAdapter.h
ConsumesCollector.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGCalValidator_cfi.simVertices
simVertices
Definition: HGCalValidator_cfi.py:43
ntuple.pdgids
pdgids
Definition: ntuple.py:98
CaloParticleSelector::stableOnly_
bool stableOnly_
Definition: CaloParticleSelector.h:134
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
CaloParticleSelector::ptMin2_
double ptMin2_
Definition: CaloParticleSelector.h:121
CaloParticleSelector::ptMax2_
double ptMax2_
Definition: CaloParticleSelector.h:122
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:30
CommonMethods.cp
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
Definition: CommonMethods.py:192
CaloParticleSelector::minHit_
int minHit_
Definition: CaloParticleSelector.h:129
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
CaloParticleSelector::CaloParticleSelector
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, const std::vector< int > &pdgId=std::vector< int >(), double minPhi=-3.2, double maxPhi=3.2)
Definition: CaloParticleSelector.h:13
reco::modules::ParameterAdapter
Definition: ParameterAdapter.h:12
deltaPhi.h
CaloParticleSelector::pdgId_
std::vector< int > pdgId_
Definition: CaloParticleSelector.h:135