CMS 3D CMS Logo

CACut.h
Go to the documentation of this file.
1 #ifndef RecoPixelVertexing_PixelTriplets_interface_CACut_h
2 #define RecoPixelVertexing_PixelTriplets_interface_CACut_h
3 // -*- C++ -*-
4 // //
5 // // Package: RecoTracker/PixelSeeding
6 // // Class: CACut
7 // //
8 // // Original Author: Karla Josefina Pena Rodriguez
9 // // Created: Wed, 14 Feb 2019 10:30:00 GMT
10 // //
11 
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
std::vector< CAValueByLayerIds > valuesByLayerIds_
Definition: CACut.h:164
void setCutValuesByLayerIds(CAGraph &caLayers)
Definition: CACut.h:43
bool useCACuts_
Definition: CACut.h:166
bool hasValueByInnerLayerId_
Definition: CACut.h:159
bool foundAllLayerIds_
Definition: CACut.h:167
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Definition: CACut.h:16
int getLayerId(const std::string &layerName)
Definition: CAGraph.h:51
std::vector< int > outerDoubletIds_
Definition: CACut.h:131
void setCutValuesByInnerLayerIds()
Definition: CACut.h:85
std::vector< float > cutValues_
Definition: CACut.h:133
std::string tripletName_
Definition: CACut.h:152
CACut(const double defaultCut, const std::vector< edm::ParameterSet > &tripletCuts)
Definition: CACut.h:18
const float defaultCut_
Definition: CACut.h:168
std::vector< CAValueByTripletName > valuesByTripletNames_
Definition: CACut.h:163
CAValuesByInnerLayerIds(float cut)
Definition: CACut.h:120
std::vector< int > innerLayerIds_
Definition: CACut.h:132
std::vector< CAValuesByInnerLayerIds > valuesByInnerLayerIds_
Definition: CACut.h:165
Log< level::Warning, false > LogWarning
CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const
Definition: CACut.h:139
float at(int layerId) const
Definition: CACut.h:122
std::vector< int > layerIds_
Definition: CACut.h:157
void setCutValuesByTripletNames(const std::vector< edm::ParameterSet > &tripletCuts)
Definition: CACut.h:33
#define LogDebug(id)