00001
00009 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterSelector.h"
00010 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00011 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
00012 #include "Alignment/TrackerAlignment/interface/TrackerAlignableId.h"
00013
00014 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00015
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018
00019
00020 AlignmentParameterSelector::AlignmentParameterSelector(AlignableTracker *aliTracker, AlignableMuon* aliMuon) :
00021 theTracker(aliTracker), theMuon(aliMuon), theSelectedAlignables(),
00022 theRangesEta(), theRangesPhi(), theRangesR(), theRangesX(), theRangesY(), theRangesZ()
00023 {
00024 this->setSpecials("");
00025 }
00026
00027
00028 void AlignmentParameterSelector::clear()
00029 {
00030 theSelectedAlignables.clear();
00031 theSelectedParameters.clear();
00032 this->clearGeometryCuts();
00033 }
00034
00035
00036 void AlignmentParameterSelector::clearGeometryCuts()
00037 {
00038 theRangesEta.clear();
00039 theRangesPhi.clear();
00040 theRangesR.clear();
00041 theRangesX.clear();
00042 theRangesY.clear();
00043 theRangesZ.clear();
00044 }
00045
00046
00047 unsigned int AlignmentParameterSelector::addSelections(const edm::ParameterSet &pSet)
00048 {
00049
00050 const std::vector<std::string> selections
00051 = pSet.getParameter<std::vector<std::string> >("alignParams");
00052
00053 unsigned int addedSets = 0;
00054
00055 for (unsigned int iSel = 0; iSel < selections.size(); ++iSel) {
00056
00057 std::vector<std::string> decompSel(this->decompose(selections[iSel], ','));
00058 if (decompSel.empty()) continue;
00059
00060 if (decompSel.size() < 2) {
00061 throw cms::Exception("BadConfig") << "@SUB=AlignmentParameterSelector::addSelections"
00062 << selections[iSel]<<" from alignableParamSelector: "
00063 << " should have at least 2 ','-separated parts";
00064 } else if (decompSel.size() > 2) {
00065 const edm::ParameterSet geoSel(pSet.getParameter<edm::ParameterSet>(decompSel[2].c_str()));
00066 this->addSelection(decompSel[0], this->convertParamSel(decompSel[1]), geoSel);
00067 } else {
00068 this->clearGeometryCuts();
00069 this->addSelection(decompSel[0], this->convertParamSel(decompSel[1]));
00070 }
00071
00072 ++addedSets;
00073 }
00074
00075 return addedSets;
00076 }
00077
00078
00079 void AlignmentParameterSelector::setGeometryCuts(const edm::ParameterSet &pSet)
00080 {
00081
00082 theRangesEta = pSet.getParameter<std::vector<double> >("etaRanges");
00083 theRangesPhi = pSet.getParameter<std::vector<double> >("phiRanges");
00084 theRangesR = pSet.getParameter<std::vector<double> >("rRanges" );
00085 theRangesX = pSet.getParameter<std::vector<double> >("xRanges" );
00086 theRangesY = pSet.getParameter<std::vector<double> >("yRanges" );
00087 theRangesZ = pSet.getParameter<std::vector<double> >("zRanges" );
00088 }
00089
00090
00091 unsigned int AlignmentParameterSelector::addSelection(const std::string &name,
00092 const std::vector<char> ¶mSel,
00093 const edm::ParameterSet &pSet)
00094 {
00095 this->setGeometryCuts(pSet);
00096 return this->addSelection(name, paramSel);
00097 }
00098
00099
00100 unsigned int AlignmentParameterSelector::addSelection(const std::string &nameInput,
00101 const std::vector<char> ¶mSel)
00102 {
00103 const std::string name(this->setSpecials(nameInput));
00104
00105 unsigned int numAli = 0;
00106
00108
00110 if (name.find("Tracker") == 0) {
00111 if (!theTracker) {
00112 throw cms::Exception("BadConfig") << "[TrackerAlignmentSelector::addSelection] "
00113 << "Configuration requires access to AlignableTracker"
00114 << " (for " << name << ") that is not initialized";
00115 }
00116 const std::string substructName(name, 7);
00117 numAli += this->add(theTracker->subStructures(substructName), paramSel);
00118 }
00120
00122 else if (name == "AllDets") numAli += this->addAllDets(paramSel);
00123 else if (name == "AllRods") numAli += this->addAllRods(paramSel);
00124 else if (name == "AllLayers") numAli += this->addAllLayers(paramSel);
00125 else if (name == "AllComponents") numAli += this->add(theTracker->components(), paramSel);
00126 else if (name == "AllAlignables") numAli += this->addAllAlignables(paramSel);
00127
00128
00129
00130 else if (name == "BarrelRods") numAli += this->add(theTracker->barrelRods(), paramSel);
00131 else if (name == "BarrelDets") numAli += this->add(theTracker->barrelGeomDets(), paramSel);
00132 else if (name == "BarrelLayers") numAli += this->add(theTracker->barrelLayers(), paramSel);
00133 else if (name == "TOBDets") numAli += this->add(theTracker->outerBarrelGeomDets(), paramSel);
00134 else if (name == "TOBRods") numAli += this->add(theTracker->outerBarrelRods(), paramSel);
00135 else if (name == "TOBLayers") numAli += this->add(theTracker->outerBarrelLayers(), paramSel);
00136 else if (name == "TOBHalfBarrels") numAli += this->add(theTracker->outerHalfBarrels(), paramSel);
00137 else if (name == "TIBDets") numAli += this->add(theTracker->innerBarrelGeomDets(), paramSel);
00138 else if (name == "TIBRods") numAli += this->add(theTracker->innerBarrelRods(), paramSel);
00139 else if (name == "TIBLayers") numAli += this->add(theTracker->innerBarrelLayers(), paramSel);
00140 else if (name == "TIBHalfBarrels") numAli += this->add(theTracker->innerHalfBarrels(), paramSel);
00141
00142
00143
00144 else if (name == "PixelHalfBarrelDets") {
00145 numAli += this->add(theTracker->pixelHalfBarrelGeomDets(), paramSel);
00146 } else if (name == "PixelHalfBarrelLadders") {
00147 numAli += this->add(theTracker->pixelHalfBarrelLadders(), paramSel);
00148 } else if (name == "PixelHalfBarrelLayers") {
00149 numAli += this->add(theTracker->pixelHalfBarrelLayers(), paramSel);
00150 } else if (name == "PixelHalfBarrels") {
00151 numAli += this->add(theTracker->pixelHalfBarrels(), paramSel);
00152 }
00153
00154
00155
00156 else if (name == "PXECDets") numAli += this->add(theTracker->pixelEndcapGeomDets(), paramSel);
00157 else if (name == "PXECPetals") numAli += this->add(theTracker->pixelEndcapPetals(), paramSel);
00158 else if (name == "PXECLayers") numAli += this->add(theTracker->pixelEndcapLayers(), paramSel);
00159 else if (name == "PXEndCaps") numAli += this->add(theTracker->pixelEndCaps(), paramSel);
00160
00161
00162
00163 else if (name == "PixelDets") {
00164 numAli += this->add(theTracker->pixelHalfBarrelGeomDets(), paramSel);
00165 numAli += this->add(theTracker->pixelEndcapGeomDets(), paramSel);
00166 } else if (name == "PixelRods") {
00167 numAli += this->add(theTracker->pixelHalfBarrelLadders(), paramSel);
00168 numAli += this->add(theTracker->pixelEndcapPetals(), paramSel);
00169 } else if (name == "PixelLayers") {
00170 numAli += this->add(theTracker->pixelHalfBarrelLayers(), paramSel);
00171 numAli += this->add(theTracker->pixelEndcapLayers(), paramSel);
00172 }
00173
00174
00175
00176 else if (name == "TIDs") numAli += this->add(theTracker->TIDs(), paramSel);
00177 else if (name == "TIDLayers") numAli += this->add(theTracker->TIDLayers(), paramSel);
00178 else if (name == "TIDRings") numAli += this->add(theTracker->TIDRings(), paramSel);
00179 else if (name == "TIDDets") numAli += this->add(theTracker->TIDGeomDets(), paramSel);
00180
00181
00182
00183 else if (name == "TECDets") numAli += this->add(theTracker->endcapGeomDets(), paramSel);
00184 else if (name == "TECPetals") numAli += this->add(theTracker->endcapPetals(), paramSel);
00185 else if (name == "TECLayers") numAli += this->add(theTracker->endcapLayers(), paramSel);
00186 else if (name == "TECs") numAli += this->add(theTracker->endCaps(), paramSel);
00187
00188
00189
00190 else if (name == "EndcapDets") {
00191 numAli += this->add(theTracker->TIDGeomDets(), paramSel);
00192 numAli += this->add(theTracker->endcapGeomDets(), paramSel);
00193 } else if (name == "EndcapPetals") {
00194 numAli += this->add(theTracker->TIDRings(), paramSel);
00195 numAli += this->add(theTracker->endcapPetals(), paramSel);
00196 } else if (name == "EndcapLayers") {
00197 numAli += this->add(theTracker->TIDLayers(), paramSel);
00198 numAli += this->add(theTracker->endcapLayers(), paramSel);
00199 }
00200
00201
00202
00203 else if (name == "StripDets") {
00204 numAli += this->add(theTracker->barrelGeomDets(), paramSel);
00205 numAli += this->add(theTracker->TIDGeomDets(), paramSel);
00206 numAli += this->add(theTracker->endcapGeomDets(), paramSel);
00207 } else if (name == "StripRods") {
00208 numAli += this->add(theTracker->barrelRods(), paramSel);
00209 numAli += this->add(theTracker->TIDRings(), paramSel);
00210 numAli += this->add(theTracker->endcapPetals(), paramSel);
00211 } else if (name == "StripLayers") {
00212 numAli += this->add(theTracker->barrelLayers(), paramSel);
00213 numAli += this->add(theTracker->TIDLayers(), paramSel);
00214 numAli += this->add(theTracker->endcapLayers(), paramSel);
00215 }
00217
00219
00220 else if (name.find("Muon") != std::string::npos) {
00221 if (!theMuon) {
00222 throw cms::Exception("BadConfig") << "[TrackerAlignmentSelector::addSelection] "
00223 << "Configuration requires access to AlignableMuon"
00224 << " which is not initialized";
00225 }
00226 else if (name == "MuonDTLayers") add(theMuon->DTLayers(), paramSel);
00227 else if (name == "MuonDTSuperLayers") add(theMuon->DTSuperLayers(), paramSel);
00228 else if (name == "MuonDTChambers") add(theMuon->DTChambers(), paramSel);
00229 else if (name == "MuonDTStations") add(theMuon->DTStations(), paramSel);
00230 else if (name == "MuonDTWheels") add(theMuon->DTWheels(), paramSel);
00231 else if (name == "MuonBarrel") add(theMuon->DTBarrel(), paramSel);
00232 else if (name == "MuonCSCLayers") add(theMuon->CSCLayers(), paramSel);
00233 else if (name == "MuonCSCRings") add(theMuon->CSCRings(), paramSel);
00234 else if (name == "MuonCSCChambers") add(theMuon->CSCChambers(), paramSel);
00235 else if (name == "MuonCSCStations") add(theMuon->CSCStations(), paramSel);
00236 else if (name == "MuonEndcaps") add(theMuon->CSCEndcaps(), paramSel);
00237
00239
00241 else {
00242 throw cms::Exception("BadConfig") <<"[AlignmentParameterSelector::addSelection]"
00243 << ": Selection '" << name << "' invalid!";
00244 }
00245 }
00246 else {
00247 throw cms::Exception("BadConfig") <<"[AlignmentParameterSelector::addSelection]"
00248 << ": Selection '" << name << "' invalid!";
00249 }
00250
00251 this->setSpecials("");
00252
00253 return numAli;
00254 }
00255
00256
00257 unsigned int AlignmentParameterSelector::add(const align::Alignables &alignables,
00258 const std::vector<char> ¶mSel)
00259 {
00260 unsigned int numAli = 0;
00261
00262
00263 for (align::Alignables::const_iterator iAli = alignables.begin();
00264 iAli != alignables.end(); ++iAli) {
00265
00266 if (!this->layerDeselected(*iAli)
00267 && !this->detUnitDeselected(*iAli)
00268 && !this->outsideRanges(*iAli)) {
00269
00270 theSelectedAlignables.push_back(*iAli);
00271 theSelectedParameters.push_back(paramSel);
00272 ++numAli;
00273 }
00274 }
00275
00276 return numAli;
00277 }
00278
00279
00280 bool AlignmentParameterSelector::layerDeselected(const Alignable *ali) const
00281 {
00282 if (theOnlySS || theOnlyDS || theSelLayers) {
00283 TrackerAlignableId idProvider;
00284 std::pair<int,int> typeLayer = idProvider.typeAndLayerFromDetId(ali->id());
00285 int type = typeLayer.first;
00286 int layer = typeLayer.second;
00287
00288
00289 if (theOnlySS
00290 && (std::abs(type) == SiStripDetId::TIB || std::abs(type) == SiStripDetId::TOB)
00291 && layer <= 2) {
00292 return true;
00293 }
00294 if (theOnlyDS
00295 && (std::abs(type) == SiStripDetId::TIB || std::abs(type) == SiStripDetId::TOB)
00296 && layer > 2) {
00297 return true;
00298 }
00299
00300
00301 if (theSelLayers && (layer < theMinLayer || layer > theMaxLayer)) {
00302 return true;
00303 }
00304 }
00305
00306 return false;
00307 }
00308
00309
00310 bool AlignmentParameterSelector::detUnitDeselected(const Alignable *ali) const
00311 {
00312
00313 if (theRphiOrStereoDetUnit != Both && ali->alignableObjectId() == align::AlignableDetUnit) {
00314 const SiStripDetId detId(ali->geomDetId());
00315 if (detId.det() == DetId::Tracker
00316 && (detId.subdetId() == SiStripDetId::TIB || detId.subdetId() == SiStripDetId::TID ||
00317 detId.subdetId() == SiStripDetId::TOB || detId.subdetId() == SiStripDetId::TEC)) {
00318
00319 if ((theRphiOrStereoDetUnit == Stereo && !detId.stereo())
00320 || (theRphiOrStereoDetUnit == Rphi && detId.stereo())) {
00321 return true;
00322 }
00323 }
00324 }
00325
00326 return false;
00327 }
00328
00329
00330 bool AlignmentParameterSelector::outsideRanges(const Alignable *alignable) const
00331 {
00332
00333 const align::PositionType& position(alignable->globalPosition());
00334
00335 if (!theRangesEta.empty() && !this->insideRanges((position.eta()), theRangesEta)) return true;
00336 if (!theRangesPhi.empty() && !this->insideRanges((position.phi()), theRangesPhi,true))return true;
00337 if (!theRangesR.empty() && !this->insideRanges((position.perp()),theRangesR)) return true;
00338 if (!theRangesX.empty() && !this->insideRanges((position.x()), theRangesX)) return true;
00339 if (!theRangesY.empty() && !this->insideRanges((position.y()), theRangesY)) return true;
00340 if (!theRangesZ.empty() && !this->insideRanges((position.z()), theRangesZ)) return true;
00341
00342 return false;
00343 }
00344
00345
00346 bool AlignmentParameterSelector::insideRanges(double value, const std::vector<double> &ranges,
00347 bool isPhi) const
00348 {
00349
00350
00351 if (ranges.size()%2 != 0) {
00352 cms::Exception("BadConfig") << "@SUB=AlignmentParameterSelector::insideRanges"
00353 << " need even number of entries in ranges instead of "
00354 << ranges.size();
00355 return false;
00356 }
00357
00358 for (unsigned int i = 0; i < ranges.size(); i += 2) {
00359 if (isPhi) {
00360 Geom::Phi<double> rangePhi1(ranges[i]);
00361 Geom::Phi<double> rangePhi2(ranges[i+1]);
00362 Geom::Phi<double> valuePhi(value);
00363 if (rangePhi1 <= valuePhi && valuePhi < rangePhi2) {
00364 return true;
00365 }
00366 if (rangePhi2 < rangePhi1 && (rangePhi1 <= valuePhi || valuePhi < rangePhi2)) {
00367 return true;
00368 }
00369 } else if (ranges[i] <= value && value < ranges[i+1]) {
00370 return true;
00371 }
00372 }
00373
00374 return false;
00375 }
00376
00377
00378 std::vector<std::string>
00379 AlignmentParameterSelector::decompose(const std::string &s, std::string::value_type delimiter) const
00380 {
00381
00382 std::vector<std::string> result;
00383
00384 std::string::size_type previousPos = 0;
00385 while (true) {
00386 const std::string::size_type delimiterPos = s.find(delimiter, previousPos);
00387 if (delimiterPos == std::string::npos) {
00388 result.push_back(s.substr(previousPos));
00389 break;
00390 }
00391 result.push_back(s.substr(previousPos, delimiterPos - previousPos));
00392 previousPos = delimiterPos + 1;
00393 }
00394
00395 return result;
00396 }
00397
00398
00399 std::vector<char> AlignmentParameterSelector::convertParamSel(const std::string &selString) const
00400 {
00401
00402
00403
00404
00405
00406
00407 std::vector<char> result(selString.size());
00408
00409 for (std::string::size_type pos = 0; pos < selString.size(); ++pos) {
00410 result[pos] = selString[pos];
00411 }
00412
00413 return result;
00414 }
00415
00416
00417
00418 std::string AlignmentParameterSelector::setSpecials(const std::string &name)
00419 {
00420
00421
00422 std::string newName(name);
00423
00424 const std::string::size_type ss = newName.rfind("SS");
00425 if (ss != std::string::npos) {
00426 newName.erase(ss, 2);
00427 theOnlySS = true;
00428 } else {
00429 theOnlySS = false;
00430 }
00431
00432 const std::string::size_type ds = newName.rfind("DS");
00433 if (ds != std::string::npos) {
00434 newName.erase(ds, 2);
00435 theOnlyDS = true;
00436 } else {
00437 theOnlyDS = false;
00438 }
00439
00440 const std::string::size_type size = newName.size();
00441 const std::string::size_type layers = newName.rfind("Layers");
00442 if (layers != std::string::npos && size - layers - 2 == 6
00443 && isdigit(newName[size-1]) && isdigit(newName[size-2])) {
00444 theSelLayers = true;
00445 theMinLayer = newName[size-2] - '0';
00446 theMaxLayer = newName[size-1] - '0';
00447 newName.erase(layers);
00448 } else {
00449 theSelLayers = false;
00450 theMinLayer = -1;
00451 theMaxLayer = 99999;
00452 }
00453
00454 theRphiOrStereoDetUnit = Both;
00455 if (newName.rfind("Unit") != std::string::npos) {
00456 const std::string::size_type uRph = newName.rfind("UnitRphi");
00457 if (uRph != std::string::npos) {
00458 newName.erase(uRph + 4, 4);
00459 theRphiOrStereoDetUnit = Rphi;
00460 }
00461 const std::string::size_type uSte = newName.rfind("UnitStereo");
00462 if (uSte != std::string::npos) {
00463 newName.erase(uSte + 4, 6);
00464 theRphiOrStereoDetUnit = Stereo;
00465 }
00466 }
00467
00468 if (newName != name) {
00469 LogDebug("Alignment") << "@SUB=AlignmentParameterSelector::setSpecials"
00470 << name << " becomes " << newName << ", makes theOnlySS " << theOnlySS
00471 << ", theOnlyDS " << theOnlyDS << ", theSelLayers " << theSelLayers
00472 << ", theMinLayer " << theMinLayer << ", theMaxLayer " << theMaxLayer
00473 << ", theRphiOrStereoDetUnit " << theRphiOrStereoDetUnit;
00474 }
00475
00476 return newName;
00477 }
00478
00479
00480 unsigned int AlignmentParameterSelector::addAllDets(const std::vector<char> ¶mSel)
00481 {
00482 unsigned int numAli = 0;
00483
00484 numAli += this->add(theTracker->barrelGeomDets(), paramSel);
00485 numAli += this->add(theTracker->endcapGeomDets(), paramSel);
00486 numAli += this->add(theTracker->TIDGeomDets(), paramSel);
00487 numAli += this->add(theTracker->pixelHalfBarrelGeomDets(), paramSel);
00488 numAli += this->add(theTracker->pixelEndcapGeomDets(), paramSel);
00489
00490 return numAli;
00491 }
00492
00493
00494 unsigned int AlignmentParameterSelector::addAllRods(const std::vector<char> ¶mSel)
00495 {
00496 unsigned int numAli = 0;
00497
00498 numAli += this->add(theTracker->barrelRods(), paramSel);
00499 numAli += this->add(theTracker->pixelHalfBarrelLadders(), paramSel);
00500 numAli += this->add(theTracker->endcapPetals(), paramSel);
00501 numAli += this->add(theTracker->TIDRings(), paramSel);
00502 numAli += this->add(theTracker->pixelEndcapPetals(), paramSel);
00503
00504 return numAli;
00505 }
00506
00507
00508 unsigned int AlignmentParameterSelector::addAllLayers(const std::vector<char> ¶mSel)
00509 {
00510 unsigned int numAli = 0;
00511
00512 numAli += this->add(theTracker->barrelLayers(), paramSel);
00513 numAli += this->add(theTracker->pixelHalfBarrelLayers(), paramSel);
00514 numAli += this->add(theTracker->endcapLayers(), paramSel);
00515 numAli += this->add(theTracker->TIDLayers(), paramSel);
00516 numAli += this->add(theTracker->pixelEndcapLayers(), paramSel);
00517
00518 return numAli;
00519 }
00520
00521
00522 unsigned int AlignmentParameterSelector::addAllAlignables(const std::vector<char> ¶mSel)
00523 {
00524 unsigned int numAli = 0;
00525
00526 numAli += this->addAllDets(paramSel);
00527 numAli += this->addAllRods(paramSel);
00528 numAli += this->addAllLayers(paramSel);
00529 numAli += this->add(theTracker->components(), paramSel);
00530
00531 return numAli;
00532 }