CMS 3D CMS Logo

CACut.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // //
3 // // Package: RecoPixelVertexing/PixelTriplets
4 // // Class: CACut
5 // //
6 // // Original Author: Karla Josefina Pena Rodriguez
7 // // Created: Wed, 14 Feb 2019 10:30:00 GMT
8 // //
9 
10 #ifndef RecoPixelVertexing_PixelTriplets_src_CACut_h
11 #define RecoPixelVertexing_PixelTriplets_src_CACut_h
12 
14 #include "CAGraph.h"
15 
16 class CACut {
17 public:
18  explicit CACut(const double defaultCut, const std::vector<edm::ParameterSet> &tripletCuts)
20  if (tripletCuts.size() == 1 && tripletCuts[0].getParameter<double>("cut") == -1.) {
21  useCACuts_ = false;
22  LogDebug("Configuration") << "No CACut VPSet. Using default cut value of " << defaultCut
23  << " for all layer triplets";
24  return;
25  }
26 
27  valuesByTripletNames_.reserve(tripletCuts.size());
28  valuesByLayerIds_.reserve(tripletCuts.size());
29 
30  setCutValuesByTripletNames(tripletCuts);
31  }
32 
33  void setCutValuesByTripletNames(const std::vector<edm::ParameterSet> &tripletCuts) {
34  for (const auto &thisTriplet : tripletCuts) {
35  valuesByTripletNames_.emplace_back();
36  auto &thisCACut = valuesByTripletNames_.back();
37 
38  thisCACut.tripletName_ = thisTriplet.getParameter<std::string>("seedingLayers");
39  thisCACut.cutValue_ = thisTriplet.getParameter<double>("cut");
40  }
41  }
42 
43  void setCutValuesByLayerIds(CAGraph &caLayers) {
45  return;
46 
47  foundAllLayerIds_ = true;
48  valuesByLayerIds_.clear();
49 
50  for (const auto &thisTriplet : valuesByTripletNames_) {
51  valuesByLayerIds_.emplace_back();
52  auto &thisCACut = valuesByLayerIds_.back();
53 
54  // Triplet name, e.g. 'BPix1+BPix2+BPix3'
55  std::string layersToSet = thisTriplet.tripletName_;
56  for (int thisLayer = 0; thisLayer < 3; thisLayer++) {
57  // Get layer name
58  std::size_t layerPos = layersToSet.find("+");
59  if ((thisLayer < 2 && layerPos == std::string::npos) || (thisLayer == 2 && layerPos != std::string::npos)) {
60  throw cms::Exception("Configuration")
61  << "Please enter a valid triplet name in the CACuts parameter set; e.g. 'BPix1+BPix2+BPix3'";
62  }
63 
64  std::string layerName = layersToSet.substr(0, layerPos);
65  layersToSet = layersToSet.substr(layerPos + 1);
66 
67  // Get layer ID
68  thisCACut.layerIds_.emplace_back(caLayers.getLayerId(layerName));
69  if (thisCACut.layerIds_.back() == -1) {
70  foundAllLayerIds_ = false;
71  edm::LogWarning("Configuration") << "Layer name '" << layerName
72  << "' not found in the CAGraph. Please check CACuts parameter set if this "
73  "warning is present for all events";
74  }
75  }
76 
77  // Cut
78  thisCACut.cutValue_ = thisTriplet.cutValue_;
79  thisCACut.hasValueByInnerLayerId_ = false;
80  }
81 
83  }
84 
86  for (auto &thisTriplet : valuesByLayerIds_) {
87  if (thisTriplet.hasValueByInnerLayerId_)
88  continue;
89  auto it = std::find(thisTriplet.layerIds_.begin(), thisTriplet.layerIds_.end(), -1);
90  if (it != thisTriplet.layerIds_.end())
91  continue;
92 
93  bool foundOuterDoublet = false;
94 
95  for (auto &thisOuterDoublet : valuesByInnerLayerIds_) {
96  if (thisOuterDoublet.outerDoubletIds_[0] == thisTriplet.layerIds_[1] &&
97  thisOuterDoublet.outerDoubletIds_[1] == thisTriplet.layerIds_[2]) {
98  thisOuterDoublet.innerLayerIds_.emplace_back(thisTriplet.layerIds_[0]);
99  thisOuterDoublet.cutValues_.emplace_back(thisTriplet.cutValue_);
100  foundOuterDoublet = true;
101  break;
102  }
103  }
104 
105  if (!foundOuterDoublet) {
106  valuesByInnerLayerIds_.emplace_back(defaultCut_);
107  auto &newOuterDoublet = valuesByInnerLayerIds_.back();
108 
109  newOuterDoublet.outerDoubletIds_.emplace_back(thisTriplet.layerIds_[1]);
110  newOuterDoublet.outerDoubletIds_.emplace_back(thisTriplet.layerIds_[2]);
111  newOuterDoublet.innerLayerIds_.emplace_back(thisTriplet.layerIds_[0]);
112  newOuterDoublet.cutValues_.emplace_back(thisTriplet.cutValue_);
113  }
114 
115  thisTriplet.hasValueByInnerLayerId_ = true;
116  }
117  }
118 
121 
122  float at(int layerId) const {
123  for (size_t thisLayer = 0; thisLayer < innerLayerIds_.size(); thisLayer++) {
124  if (innerLayerIds_.at(thisLayer) == layerId)
125  return cutValues_.at(thisLayer);
126  }
127 
128  return defaultCut_;
129  }
130 
131  std::vector<int> outerDoubletIds_;
132  std::vector<int> innerLayerIds_;
133  std::vector<float> cutValues_;
134 
135  private:
136  double defaultCut_;
137  };
138 
139  CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const {
140  for (const auto &thisCut : valuesByInnerLayerIds_) {
141  if (thisCut.outerDoubletIds_[0] == layerIds1 && thisCut.outerDoubletIds_[1] == layerIds2) {
142  return thisCut;
143  }
144  }
145 
146  CAValuesByInnerLayerIds emptyCutsByInnerLayer(defaultCut_);
147  return emptyCutsByInnerLayer;
148  }
149 
150 private:
153  float cutValue_;
154  };
155 
157  std::vector<int> layerIds_;
158  float cutValue_;
160  };
161 
162 private:
163  std::vector<CAValueByTripletName> valuesByTripletNames_;
164  std::vector<CAValueByLayerIds> valuesByLayerIds_;
165  std::vector<CAValuesByInnerLayerIds> valuesByInnerLayerIds_;
168  const float defaultCut_;
169 };
170 
171 #endif
CACut::foundAllLayerIds_
bool foundAllLayerIds_
Definition: CACut.h:167
CACut::CAValuesByInnerLayerIds::innerLayerIds_
std::vector< int > innerLayerIds_
Definition: CACut.h:132
funct::false
false
Definition: Factorize.h:29
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
CACut::valuesByLayerIds_
std::vector< CAValueByLayerIds > valuesByLayerIds_
Definition: CACut.h:164
CACut::setCutValuesByLayerIds
void setCutValuesByLayerIds(CAGraph &caLayers)
Definition: CACut.h:43
CACut::useCACuts_
bool useCACuts_
Definition: CACut.h:166
CACut::CAValueByLayerIds::hasValueByInnerLayerId_
bool hasValueByInnerLayerId_
Definition: CACut.h:159
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CACut::CAValueByTripletName::tripletName_
std::string tripletName_
Definition: CACut.h:152
CACut::CAValueByLayerIds::layerIds_
std::vector< int > layerIds_
Definition: CACut.h:157
CACut::CAValueByLayerIds::cutValue_
float cutValue_
Definition: CACut.h:158
CACut::CAValueByLayerIds
Definition: CACut.h:156
ParameterSetDescription.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
funct::true
true
Definition: Factorize.h:173
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
CACut::setCutValuesByInnerLayerIds
void setCutValuesByInnerLayerIds()
Definition: CACut.h:85
CACut::CAValueByTripletName::cutValue_
float cutValue_
Definition: CACut.h:153
CAGraph
Definition: CAGraph.h:50
CAGraph::getLayerId
int getLayerId(const std::string &layerName)
Definition: CAGraph.h:51
CACut::CAValuesByInnerLayerIds
Definition: CACut.h:119
CACut::CAValuesByInnerLayerIds::CAValuesByInnerLayerIds
CAValuesByInnerLayerIds(float cut)
Definition: CACut.h:120
CAGraph.h
CACut::valuesByInnerLayerIds_
std::vector< CAValuesByInnerLayerIds > valuesByInnerLayerIds_
Definition: CACut.h:165
CACut::CAValuesByInnerLayerIds::at
float at(int layerId) const
Definition: CACut.h:122
CACut::getCutsByInnerLayer
CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const
Definition: CACut.h:139
Exception
Definition: hltDiff.cc:245
CACut::CACut
CACut(const double defaultCut, const std::vector< edm::ParameterSet > &tripletCuts)
Definition: CACut.h:18
CACut
Definition: CACut.h:16
CACut::CAValuesByInnerLayerIds::cutValues_
std::vector< float > cutValues_
Definition: CACut.h:133
CACut::CAValuesByInnerLayerIds::defaultCut_
double defaultCut_
Definition: CACut.h:136
CACut::CAValuesByInnerLayerIds::outerDoubletIds_
std::vector< int > outerDoubletIds_
Definition: CACut.h:131
CACut::setCutValuesByTripletNames
void setCutValuesByTripletNames(const std::vector< edm::ParameterSet > &tripletCuts)
Definition: CACut.h:33
CACut::valuesByTripletNames_
std::vector< CAValueByTripletName > valuesByTripletNames_
Definition: CACut.h:163
phase1PixelTopology::layerName
constexpr char const * layerName[numberOfLayers]
Definition: phase1PixelTopology.h:37
CACut::CAValueByTripletName
Definition: CACut.h:151
CACut::defaultCut_
const float defaultCut_
Definition: CACut.h:168