File indexing completed on 2024-04-06 12:27:09
0001
0002
0003
0004
0005
0006 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedLayerFinder.h"
0007
0008 using namespace std;
0009 using namespace edm;
0010
0011 RPCSeedLayerFinder::RPCSeedLayerFinder() {
0012
0013 LayersinRPC.clear();
0014 isConfigured = false;
0015 isInputset = false;
0016 isOutputset = false;
0017 }
0018
0019 RPCSeedLayerFinder::~RPCSeedLayerFinder() {}
0020
0021 void RPCSeedLayerFinder::configure(const edm::ParameterSet& iConfig) {
0022
0023 isCosmic = iConfig.getParameter<bool>("isCosmic");
0024 isMixBarrelwithEndcap = iConfig.getParameter<bool>("isMixBarrelwithEndcap");
0025 RangeofLayersinBarrel = iConfig.getParameter<std::vector<unsigned int> >("RangeofLayersinBarrel");
0026 RangeofLayersinEndcap = iConfig.getParameter<std::vector<unsigned int> >("RangeofLayersinEndcap");
0027 isSpecialLayers = iConfig.getParameter<bool>("isSpecialLayers");
0028 LayersinBarrel = iConfig.getParameter<std::vector<unsigned int> >("LayersinBarrel");
0029 LayersinEndcap = iConfig.getParameter<std::vector<unsigned int> >("LayersinEndcap");
0030 constrainedLayersinBarrel = iConfig.getParameter<std::vector<unsigned int> >("constrainedLayersinBarrel");
0031
0032
0033 isConfigured = true;
0034 }
0035
0036 void RPCSeedLayerFinder::setInput(MuonRecHitContainer (&recHitsRPC)[RPCLayerNumber]) {
0037 for (unsigned int i = 0; i < RPCLayerNumber; i++)
0038 recHitsinLayers[i] = recHitsRPC[i].size();
0039
0040
0041 isInputset = true;
0042 }
0043
0044 void RPCSeedLayerFinder::unsetInput() { isInputset = false; }
0045
0046 void RPCSeedLayerFinder::setOutput(RPCSeedrecHitFinder* Ref = nullptr, RPCCosmicSeedrecHitFinder* CosmicRef = nullptr) {
0047 RPCrecHitFinderRef = Ref;
0048 RPCCosmicrecHitFinderRef = CosmicRef;
0049 isOutputset = true;
0050 }
0051
0052 void RPCSeedLayerFinder::fill() {
0053
0054 if (isConfigured == false || isInputset == false || isOutputset == false) {
0055 cout << "RPCSeedLayerFinder needs to be configured and set IO before running RPCSeedLayerFinder::fillLayers()"
0056 << endl;
0057 return;
0058 }
0059
0060
0061 LayersinRPC.clear();
0062
0063
0064 if (isCosmic == true) {
0065 if (RPCCosmicrecHitFinderRef != nullptr)
0066 fillCosmicLayers();
0067 else
0068 cout << "RPCCosmicrecHitFinderRef not set" << endl;
0069 } else {
0070 if (RPCrecHitFinderRef != nullptr)
0071 fillLayers();
0072 else
0073 cout << "RPCrecHitFinderRef not set" << endl;
0074 }
0075 }
0076
0077 void RPCSeedLayerFinder::fillLayers() {
0078 if (isSpecialLayers == false && isMixBarrelwithEndcap == false) {
0079 for (std::vector<unsigned int>::iterator NumberofLayersinBarrel = RangeofLayersinBarrel.begin();
0080 NumberofLayersinBarrel != RangeofLayersinBarrel.end();
0081 NumberofLayersinBarrel++) {
0082
0083 unsigned int NumberofLayers = *NumberofLayersinBarrel;
0084 if (NumberofLayers < 1 || NumberofLayers > BarrelLayerNumber)
0085 continue;
0086 int type = 0;
0087 LayersinRPC.clear();
0088 SpecialLayers(-1, NumberofLayers, type);
0089 LayersinRPC.clear();
0090 }
0091
0092 for (std::vector<unsigned int>::iterator NumberofLayersinEndcap = RangeofLayersinEndcap.begin();
0093 NumberofLayersinEndcap != RangeofLayersinEndcap.end();
0094 NumberofLayersinEndcap++) {
0095 unsigned int NumberofLayers = *NumberofLayersinEndcap;
0096 if (NumberofLayers < 1 || NumberofLayers > EachEndcapLayerNumber)
0097 continue;
0098 int type = 1;
0099
0100 LayersinRPC.clear();
0101 SpecialLayers(BarrelLayerNumber - 1, NumberofLayers, type);
0102 LayersinRPC.clear();
0103
0104 LayersinRPC.clear();
0105 SpecialLayers(BarrelLayerNumber + EachEndcapLayerNumber - 1, NumberofLayers, type);
0106 LayersinRPC.clear();
0107 }
0108 }
0109
0110 if (isSpecialLayers == true && isMixBarrelwithEndcap == false) {
0111
0112 bool EnoughforBarrel = true;
0113 unsigned int i = 0;
0114 LayersinRPC.clear();
0115 for (std::vector<unsigned int>::iterator it = LayersinBarrel.begin(); it != LayersinBarrel.end(); it++, i++) {
0116 if ((*it) != 0 && i < BarrelLayerNumber) {
0117 if (recHitsinLayers[i] != 0)
0118 LayersinRPC.push_back(i);
0119 else {
0120 cout << "Not recHits in special Barrel layer " << i << endl;
0121 EnoughforBarrel = false;
0122 }
0123 }
0124 }
0125 if (EnoughforBarrel && (!LayersinRPC.empty())) {
0126
0127 RPCrecHitFinderRef->setLayers(LayersinRPC);
0128 RPCrecHitFinderRef->fillrecHits();
0129 }
0130 LayersinRPC.clear();
0131
0132
0133 bool EnoughforEndcap = true;
0134
0135
0136 i = BarrelLayerNumber;
0137 EnoughforEndcap = true;
0138 LayersinRPC.clear();
0139 for (std::vector<unsigned int>::iterator it = LayersinEndcap.begin(); it != LayersinEndcap.end(); it++, i++) {
0140 if ((*it) != 0 && i < (BarrelLayerNumber + EachEndcapLayerNumber)) {
0141 if (recHitsinLayers[i] != 0)
0142 LayersinRPC.push_back(i);
0143 else {
0144 cout << "Not recHits in special Endcap " << (i - BarrelLayerNumber) << endl;
0145 EnoughforEndcap = false;
0146 }
0147 }
0148 }
0149 if (EnoughforEndcap && (!LayersinRPC.empty())) {
0150
0151 RPCrecHitFinderRef->setLayers(LayersinRPC);
0152 RPCrecHitFinderRef->fillrecHits();
0153 }
0154 LayersinRPC.clear();
0155
0156
0157 i = BarrelLayerNumber;
0158 EnoughforEndcap = true;
0159 LayersinRPC.clear();
0160 for (std::vector<unsigned int>::iterator it = LayersinEndcap.begin(); it != LayersinEndcap.end(); it++, i++) {
0161 if ((*it) != 0 && i >= (BarrelLayerNumber + EachEndcapLayerNumber) &&
0162 i < (BarrelLayerNumber + EachEndcapLayerNumber * 2)) {
0163 if (recHitsinLayers[i] != 0)
0164 LayersinRPC.push_back(i);
0165 else {
0166 cout << "Not recHits in special Endcap " << i << endl;
0167 EnoughforEndcap = false;
0168 }
0169 }
0170 }
0171 if (EnoughforEndcap && (!LayersinRPC.empty())) {
0172
0173 RPCrecHitFinderRef->setLayers(LayersinRPC);
0174 RPCrecHitFinderRef->fillrecHits();
0175 }
0176 LayersinRPC.clear();
0177 }
0178
0179 if (isMixBarrelwithEndcap == true) {
0180 cout << " Mix is not ready for non-cosmic case" << endl;
0181 LayersinRPC.clear();
0182 }
0183 }
0184
0185 void RPCSeedLayerFinder::fillCosmicLayers() {
0186
0187 if (isSpecialLayers == true && isMixBarrelwithEndcap == false) {
0188
0189 unsigned int i = 0;
0190 LayersinRPC.clear();
0191 for (std::vector<unsigned int>::iterator it = LayersinBarrel.begin(); it != LayersinBarrel.end(); it++, i++) {
0192 if ((*it) != 0 && i < BarrelLayerNumber)
0193 if (recHitsinLayers[i] != 0)
0194 LayersinRPC.push_back(i);
0195 }
0196 if (!LayersinRPC.empty()) {
0197
0198 RPCCosmicrecHitFinderRef->setLayers(LayersinRPC);
0199 RPCCosmicrecHitFinderRef->fillrecHits();
0200 }
0201 LayersinRPC.clear();
0202
0203
0204
0205
0206 i = BarrelLayerNumber;
0207 LayersinRPC.clear();
0208 for (std::vector<unsigned int>::iterator it = LayersinEndcap.begin(); it != LayersinEndcap.end(); it++, i++) {
0209 if ((*it) != 0 && i < (BarrelLayerNumber + EachEndcapLayerNumber))
0210 if (recHitsinLayers[i] != 0)
0211 LayersinRPC.push_back(i);
0212 }
0213 if (!LayersinRPC.empty()) {
0214
0215 RPCCosmicrecHitFinderRef->setLayers(LayersinRPC);
0216 RPCCosmicrecHitFinderRef->fillrecHits();
0217 }
0218 LayersinRPC.clear();
0219
0220
0221 i = BarrelLayerNumber;
0222 LayersinRPC.clear();
0223 for (std::vector<unsigned int>::iterator it = LayersinEndcap.begin(); it != LayersinEndcap.end(); it++, i++) {
0224 if ((*it) != 0 && i >= (BarrelLayerNumber + EachEndcapLayerNumber) &&
0225 i < (BarrelLayerNumber + EachEndcapLayerNumber * 2))
0226 if (recHitsinLayers[i] != 0)
0227 LayersinRPC.push_back(i);
0228 }
0229 if (!LayersinRPC.empty()) {
0230
0231 RPCCosmicrecHitFinderRef->setLayers(LayersinRPC);
0232 RPCCosmicrecHitFinderRef->fillrecHits();
0233 }
0234 LayersinRPC.clear();
0235 }
0236
0237 if (isSpecialLayers == true && isMixBarrelwithEndcap == true) {
0238
0239 unsigned int i = 0;
0240 LayersinRPC.clear();
0241 for (std::vector<unsigned int>::iterator it = LayersinBarrel.begin(); it != LayersinBarrel.end(); it++, i++) {
0242 if ((*it) != 0 && i < BarrelLayerNumber)
0243 if (recHitsinLayers[i] != 0)
0244 LayersinRPC.push_back(i);
0245 }
0246 i = BarrelLayerNumber;
0247 for (std::vector<unsigned int>::iterator it = LayersinEndcap.begin(); it != LayersinEndcap.end(); it++, i++) {
0248 if ((*it) != 0 && i < (BarrelLayerNumber + EachEndcapLayerNumber * 2))
0249 if (recHitsinLayers[i] != 0)
0250 LayersinRPC.push_back(i);
0251 }
0252
0253 if (!LayersinRPC.empty()) {
0254
0255 RPCCosmicrecHitFinderRef->setLayers(LayersinRPC);
0256 RPCCosmicrecHitFinderRef->fillrecHits();
0257 }
0258 LayersinRPC.clear();
0259 }
0260
0261 if (isSpecialLayers == false) {
0262 cout << "Not ready for not SpecialLayers for Cosmic case" << endl;
0263 LayersinRPC.clear();
0264 }
0265 }
0266
0267 void RPCSeedLayerFinder::SpecialLayers(int last, unsigned int NumberofLayers, int type) {
0268
0269
0270
0271 if (type == 0) {
0272 if (NumberofLayers > BarrelLayerNumber) {
0273 cout << "NumberofLayers larger than max layers in barrel" << endl;
0274 return;
0275 }
0276 for (unsigned int i = (last + 1); i <= (BarrelLayerNumber - NumberofLayers + LayersinRPC.size()); i++) {
0277 if (recHitsinLayers[i] != 0) {
0278 LayersinRPC.push_back(i);
0279 last = i;
0280 if (LayersinRPC.size() < NumberofLayers)
0281 SpecialLayers(last, NumberofLayers, type);
0282 else {
0283 if (checkConstrain()) {
0284 cout << "Find special barrel layers: ";
0285 for (unsigned int k = 0; k < NumberofLayers; k++)
0286 cout << LayersinRPC[k] << " ";
0287 cout << endl;
0288
0289 RPCrecHitFinderRef->setLayers(LayersinRPC);
0290 RPCrecHitFinderRef->fillrecHits();
0291 } else
0292 cout << "The layers don't contain all layers in constrain" << endl;
0293 }
0294 LayersinRPC.pop_back();
0295 }
0296 }
0297 }
0298
0299
0300 if (type == 1) {
0301 if (NumberofLayers > EachEndcapLayerNumber) {
0302 cout << "NumberofLayers larger than max layers in endcap" << endl;
0303 return;
0304 }
0305 if (last < (BarrelLayerNumber + EachEndcapLayerNumber - 1) ||
0306 (last == (BarrelLayerNumber + EachEndcapLayerNumber - 1) && !LayersinRPC.empty())) {
0307
0308 for (unsigned int i = (last + 1);
0309 i <= (BarrelLayerNumber + EachEndcapLayerNumber - NumberofLayers + LayersinRPC.size());
0310 i++) {
0311 if (recHitsinLayers[i] != 0) {
0312 LayersinRPC.push_back(i);
0313 last = i;
0314 if (LayersinRPC.size() < NumberofLayers)
0315 SpecialLayers(last, NumberofLayers, type);
0316 else {
0317 cout << "Find special -Z endcap layers: ";
0318 for (unsigned int k = 0; k < NumberofLayers; k++)
0319 cout << LayersinRPC[k] << " ";
0320 cout << endl;
0321
0322 RPCrecHitFinderRef->setLayers(LayersinRPC);
0323 RPCrecHitFinderRef->fillrecHits();
0324 }
0325 LayersinRPC.pop_back();
0326 }
0327 }
0328 } else {
0329
0330 for (unsigned int i = (last + 1);
0331 i <= (BarrelLayerNumber + EachEndcapLayerNumber * 2 - NumberofLayers + LayersinRPC.size());
0332 i++) {
0333 if (recHitsinLayers[i] != 0) {
0334 LayersinRPC.push_back(i);
0335 last = i;
0336 if (LayersinRPC.size() < NumberofLayers)
0337 SpecialLayers(last, NumberofLayers, type);
0338 else {
0339 cout << "Find special +Z endcap layers: ";
0340 for (unsigned int k = 0; k < NumberofLayers; k++)
0341 cout << LayersinRPC[k] << " ";
0342 cout << endl;
0343
0344 RPCrecHitFinderRef->setLayers(LayersinRPC);
0345 RPCrecHitFinderRef->fillrecHits();
0346 }
0347 LayersinRPC.pop_back();
0348 }
0349 }
0350 }
0351 }
0352 }
0353
0354 bool RPCSeedLayerFinder::checkConstrain() {
0355 bool pass = true;
0356 std::vector<unsigned int> fitConstrain = constrainedLayersinBarrel;
0357 for (unsigned int i = 0; i < LayersinRPC.size(); i++)
0358 fitConstrain[LayersinRPC[i]] = 0;
0359 for (unsigned int i = 0; i < BarrelLayerNumber; i++)
0360 if (fitConstrain[i] != 0)
0361 pass = false;
0362 return pass;
0363 }