File indexing completed on 2024-04-06 12:28:30
0001 #ifndef RecoTracker_PixelSeeding_CACut_h
0002 #define RecoTracker_PixelSeeding_CACut_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "RecoTracker/PixelSeeding/interface/CAGraph.h"
0015
0016 class CACut {
0017 public:
0018 explicit CACut(const double defaultCut, const std::vector<edm::ParameterSet> &tripletCuts)
0019 : useCACuts_(true), foundAllLayerIds_(false), defaultCut_(defaultCut) {
0020 if (tripletCuts.size() == 1 && tripletCuts[0].getParameter<double>("cut") == -1.) {
0021 useCACuts_ = false;
0022 LogDebug("Configuration") << "No CACut VPSet. Using default cut value of " << defaultCut
0023 << " for all layer triplets";
0024 return;
0025 }
0026
0027 valuesByTripletNames_.reserve(tripletCuts.size());
0028 valuesByLayerIds_.reserve(tripletCuts.size());
0029
0030 setCutValuesByTripletNames(tripletCuts);
0031 }
0032
0033 void setCutValuesByTripletNames(const std::vector<edm::ParameterSet> &tripletCuts) {
0034 for (const auto &thisTriplet : tripletCuts) {
0035 valuesByTripletNames_.emplace_back();
0036 auto &thisCACut = valuesByTripletNames_.back();
0037
0038 thisCACut.tripletName_ = thisTriplet.getParameter<std::string>("seedingLayers");
0039 thisCACut.cutValue_ = thisTriplet.getParameter<double>("cut");
0040 }
0041 }
0042
0043 void setCutValuesByLayerIds(CAGraph &caLayers) {
0044 if (!useCACuts_ || foundAllLayerIds_)
0045 return;
0046
0047 foundAllLayerIds_ = true;
0048 valuesByLayerIds_.clear();
0049
0050 for (const auto &thisTriplet : valuesByTripletNames_) {
0051 valuesByLayerIds_.emplace_back();
0052 auto &thisCACut = valuesByLayerIds_.back();
0053
0054
0055 std::string layersToSet = thisTriplet.tripletName_;
0056 for (int thisLayer = 0; thisLayer < 3; thisLayer++) {
0057
0058 std::size_t layerPos = layersToSet.find('+');
0059 if ((thisLayer < 2 && layerPos == std::string::npos) || (thisLayer == 2 && layerPos != std::string::npos)) {
0060 throw cms::Exception("Configuration")
0061 << "Please enter a valid triplet name in the CACuts parameter set; e.g. 'BPix1+BPix2+BPix3'";
0062 }
0063
0064 std::string layerName = layersToSet.substr(0, layerPos);
0065 layersToSet = layersToSet.substr(layerPos + 1);
0066
0067
0068 thisCACut.layerIds_.emplace_back(caLayers.getLayerId(layerName));
0069 if (thisCACut.layerIds_.back() == -1) {
0070 foundAllLayerIds_ = false;
0071 edm::LogWarning("Configuration") << "Layer name '" << layerName
0072 << "' not found in the CAGraph. Please check CACuts parameter set if this "
0073 "warning is present for all events";
0074 }
0075 }
0076
0077
0078 thisCACut.cutValue_ = thisTriplet.cutValue_;
0079 thisCACut.hasValueByInnerLayerId_ = false;
0080 }
0081
0082 setCutValuesByInnerLayerIds();
0083 }
0084
0085 void setCutValuesByInnerLayerIds() {
0086 for (auto &thisTriplet : valuesByLayerIds_) {
0087 if (thisTriplet.hasValueByInnerLayerId_)
0088 continue;
0089 auto it = std::find(thisTriplet.layerIds_.begin(), thisTriplet.layerIds_.end(), -1);
0090 if (it != thisTriplet.layerIds_.end())
0091 continue;
0092
0093 bool foundOuterDoublet = false;
0094
0095 for (auto &thisOuterDoublet : valuesByInnerLayerIds_) {
0096 if (thisOuterDoublet.outerDoubletIds_[0] == thisTriplet.layerIds_[1] &&
0097 thisOuterDoublet.outerDoubletIds_[1] == thisTriplet.layerIds_[2]) {
0098 thisOuterDoublet.innerLayerIds_.emplace_back(thisTriplet.layerIds_[0]);
0099 thisOuterDoublet.cutValues_.emplace_back(thisTriplet.cutValue_);
0100 foundOuterDoublet = true;
0101 break;
0102 }
0103 }
0104
0105 if (!foundOuterDoublet) {
0106 valuesByInnerLayerIds_.emplace_back(defaultCut_);
0107 auto &newOuterDoublet = valuesByInnerLayerIds_.back();
0108
0109 newOuterDoublet.outerDoubletIds_.emplace_back(thisTriplet.layerIds_[1]);
0110 newOuterDoublet.outerDoubletIds_.emplace_back(thisTriplet.layerIds_[2]);
0111 newOuterDoublet.innerLayerIds_.emplace_back(thisTriplet.layerIds_[0]);
0112 newOuterDoublet.cutValues_.emplace_back(thisTriplet.cutValue_);
0113 }
0114
0115 thisTriplet.hasValueByInnerLayerId_ = true;
0116 }
0117 }
0118
0119 struct CAValuesByInnerLayerIds {
0120 explicit CAValuesByInnerLayerIds(float cut) : defaultCut_(cut) {}
0121
0122 float at(int layerId) const {
0123 for (size_t thisLayer = 0; thisLayer < innerLayerIds_.size(); thisLayer++) {
0124 if (innerLayerIds_.at(thisLayer) == layerId)
0125 return cutValues_.at(thisLayer);
0126 }
0127
0128 return defaultCut_;
0129 }
0130
0131 std::vector<int> outerDoubletIds_;
0132 std::vector<int> innerLayerIds_;
0133 std::vector<float> cutValues_;
0134
0135 private:
0136 double defaultCut_;
0137 };
0138
0139 CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const {
0140 for (const auto &thisCut : valuesByInnerLayerIds_) {
0141 if (thisCut.outerDoubletIds_[0] == layerIds1 && thisCut.outerDoubletIds_[1] == layerIds2) {
0142 return thisCut;
0143 }
0144 }
0145
0146 CAValuesByInnerLayerIds emptyCutsByInnerLayer(defaultCut_);
0147 return emptyCutsByInnerLayer;
0148 }
0149
0150 private:
0151 struct CAValueByTripletName {
0152 std::string tripletName_;
0153 float cutValue_;
0154 };
0155
0156 struct CAValueByLayerIds {
0157 std::vector<int> layerIds_;
0158 float cutValue_;
0159 bool hasValueByInnerLayerId_;
0160 };
0161
0162 private:
0163 std::vector<CAValueByTripletName> valuesByTripletNames_;
0164 std::vector<CAValueByLayerIds> valuesByLayerIds_;
0165 std::vector<CAValuesByInnerLayerIds> valuesByInnerLayerIds_;
0166 bool useCACuts_;
0167 bool foundAllLayerIds_;
0168 const float defaultCut_;
0169 };
0170
0171 #endif