CMS 3D CMS Logo

AlignmentParameterBuilder.cc
Go to the documentation of this file.
1 
8 // This class's header should be first:
10 
14 
17 
19 
22 
23 #include <algorithm>
24 
25 using namespace AlignmentParametersFactory;
26 
27 //__________________________________________________________________________________________________
29  AlignableExtras *alignableExtras)
30  : theAlignables(),
31  theAlignableTracker(alignableTracker),
32  theAlignableMuon(nullptr),
33  theAlignableExtras(alignableExtras) {}
34 
35 //__________________________________________________________________________________________________
37  AlignableMuon *alignableMuon,
38  AlignableExtras *alignableExtras)
39  : theAlignables(),
40  theAlignableTracker(alignableTracker),
41  theAlignableMuon(alignableMuon),
42  theAlignableExtras(alignableExtras) {}
43 
44 //__________________________________________________________________________________________________
46  AlignableExtras *alignableExtras,
47  const edm::ParameterSet &pSet)
48  : theAlignables(),
49  theAlignableTracker(alignableTracker),
50  theAlignableMuon(nullptr),
51  theAlignableExtras(alignableExtras) {
52  this->addAllSelections(pSet);
53 }
54 
55 //__________________________________________________________________________________________________
57  AlignableMuon *alignableMuon,
58  AlignableExtras *alignableExtras,
59  const edm::ParameterSet &pSet)
60  : theAlignables(),
61  theAlignableTracker(alignableTracker),
62  theAlignableMuon(alignableMuon),
63  theAlignableExtras(alignableExtras) {
64  this->addAllSelections(pSet);
65 }
66 
68 
69 //__________________________________________________________________________________________________
72  std::vector<std::string> selsTypes(pSet.getParameter<std::vector<std::string> >("parameterTypes"));
73 
74  for (unsigned int i = 0; i < selsTypes.size(); ++i) {
75  std::vector<std::string> selSetType(selector.decompose(selsTypes[i], ','));
76  if (selSetType.size() != 2) {
77  throw cms::Exception("BadConfig") << "AlignmentParameterBuilder"
78  << "parameterTypes should contain 2 comma separated strings"
79  << ", but found '" << selsTypes[i] << "'.";
80  }
81  this->addSelections(pSet.getParameter<edm::ParameterSet>(selSetType[0]),
83  }
84 }
85 
86 //__________________________________________________________________________________________________
88  const unsigned int oldAliSize = theAlignables.size();
89 
91  const unsigned int addedSets = selector.addSelections(pSet);
92 
93  const align::Alignables &alignables = selector.selectedAlignables();
94  const std::vector<std::vector<char> > &paramSels = selector.selectedParameters();
95 
96  align::Alignables::const_iterator iAli = alignables.begin();
97  std::vector<std::vector<char> >::const_iterator iParamSel = paramSels.begin();
98  unsigned int nHigherLevel = 0;
99 
100  while (iAli != alignables.end() && iParamSel != paramSels.end()) {
101  std::vector<bool> boolParSel;
102  std::vector<char> parSel(*iParamSel); // copy, since decodeParamSel may manipulate
103  bool charSelIsGeneral = this->decodeParamSel(parSel, boolParSel);
104  if (this->add(*iAli, parType, boolParSel))
105  ++nHigherLevel;
106  if (charSelIsGeneral)
107  this->addFullParamSel((*iAli)->alignmentParameters(), parSel);
108 
109  ++iAli;
110  ++iParamSel;
111  }
112 
113  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterBuilder::addSelections"
114  << " Added " << addedSets << " set(s) of alignables with "
115  << theAlignables.size() - oldAliSize << " alignables in total,"
116  << " of which " << nHigherLevel << " are higher level "
117  << "(using " << parametersTypeName(parType) << "AlignmentParameters).";
118 
119  return addedSets;
120 }
121 
122 //__________________________________________________________________________________________________
123 bool AlignmentParameterBuilder::add(Alignable *alignable, ParametersType parType, const std::vector<bool> &sel) {
125  alignable->setAlignmentParameters(paras);
126  theAlignables.push_back(alignable);
127 
128  const int aliTypeId = alignable->alignableObjectId();
129  const bool isHigherLevel = (aliTypeId != align::AlignableDet && aliTypeId != align::AlignableDetUnit);
130  return isHigherLevel;
131 }
132 
133 //__________________________________________________________________________________________________
134 unsigned int AlignmentParameterBuilder::add(const align::Alignables &alignables,
135  ParametersType parType,
136  const std::vector<bool> &sel) {
137  unsigned int nHigherLevel = 0;
138 
139  for (align::Alignables::const_iterator iAli = alignables.begin(); iAli != alignables.end(); ++iAli) {
140  if (this->add(*iAli, parType, sel))
141  ++nHigherLevel;
142  }
143 
144  return nHigherLevel;
145 }
146 
147 //__________________________________________________________________________________________________
149  if (n < 1 || n > 3) {
150  edm::LogError("BadArgument") << " n = " << n << " is not in [1,3]";
151  return;
152  }
153 
154  align::Alignables theNewAlignables;
155  int i = 0;
156  int imax = theAlignables.size();
157  for (align::Alignables::const_iterator ia = theAlignables.begin(); ia != theAlignables.end(); ++ia) {
158  i++;
159  if (n == 1 && i > 1)
160  theNewAlignables.push_back(*ia);
161  else if (n == 2 && i > 1 && i < imax)
162  theNewAlignables.push_back(*ia);
163  else if (n == 3 && i > 2 && i < imax)
164  theNewAlignables.push_back(*ia);
165  }
166 
167  theAlignables = theNewAlignables;
168 
169  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterBuilder::fixAlignables"
170  << "removing " << n << " alignables, so that " << theAlignables.size()
171  << " alignables left";
172 }
173 
174 //__________________________________________________________________________________________________
175 bool AlignmentParameterBuilder::decodeParamSel(std::vector<char> &paramSelChar, std::vector<bool> &result) const {
176  result.clear();
177  // remove all spaces from paramSelChar - useful to group the parameters if they are many
178  paramSelChar.erase(std::remove(paramSelChar.begin(), paramSelChar.end(), ' '), paramSelChar.end());
179 
180  bool anyNon01 = false;
181 
182  for (unsigned int pos = 0; pos < paramSelChar.size(); ++pos) {
183  switch (paramSelChar[pos]) {
184  default:
185  anyNon01 = true;
186  [[fallthrough]];
187  case '1':
188  result.push_back(true);
189  break;
190  case '0':
191  result.push_back(false);
192  break;
193  }
194  }
195 
196  return anyNon01;
197 }
198 
199 //__________________________________________________________________________________________________
201  const std::vector<char> &fullSel) const {
202  if (!aliParams)
203  return false;
204 
205  aliParams->setUserVariables(new SelectionUserVariables(fullSel));
206 
207  return true;
208 }
AlignmentParameterBuilder(AlignableTracker *alignableTracker, AlignableExtras *alignableExtras)
Constructor from tracker only.
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
unsigned int addSelections(const edm::ParameterSet &pset, AlignmentParametersFactory::ParametersType parType)
bool decodeParamSel(std::vector< char > &paramSelChar, std::vector< bool > &result) const
const AlignableTracker * alignableTracker() const
Alignable tracker.
std::string parametersTypeName(ParametersType parType)
Log< level::Error, false > LogError
bool addFullParamSel(AlignmentParameters *aliPar, const std::vector< char > &fullSel) const
add SelectionUserVariables corresponding to fullSel
ParametersType
enums for all available AlignmentParameters
AlignableExtras * theAlignableExtras
extra Alignables
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void fixAlignables(int n)
Remove n Alignables from list.
const align::Alignables & alignables() const
Get list of alignables for which AlignmentParameters are built.
AlignableMuon * theAlignableMuon
Alignable muon.
AlignmentParameters * createParameters(Alignable *ali, ParametersType parType, const std::vector< bool > &sel)
unsigned int add(const align::Alignables &alignables, AlignmentParametersFactory::ParametersType parType, const std::vector< bool > &sel)
Add arbitrary selection of Alignables, return number of higher level Alignables.
Log< level::Info, false > LogInfo
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:234
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
align::Alignables theAlignables
Vector of alignables.
ParametersType parametersType(const std::string &typeString)
convert string to ParametersType - exception if not known
Constructor of the full muon geometry.
Definition: AlignableMuon.h:38
AlignableTracker * theAlignableTracker
Alignable tracker.
void addAllSelections(const edm::ParameterSet &pSet)
master initialisation method, PSet must have form as constructor wants it