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 //__________________________________________________________________________________________________
71  AlignmentParameterSelector selector(nullptr);
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 
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::addFullParamSel
bool addFullParamSel(AlignmentParameters *aliPar, const std::vector< char > &fullSel) const
add SelectionUserVariables corresponding to fullSel
Definition: AlignmentParameterBuilder.cc:200
AlignmentParametersFactory::createParameters
AlignmentParameters * createParameters(Alignable *ali, ParametersType parType, const std::vector< bool > &sel)
Definition: AlignmentParametersFactory.cc:83
AlignmentParametersFactory.h
mps_fire.i
i
Definition: mps_fire.py:428
AlignmentParametersFactory::parametersTypeName
std::string parametersTypeName(ParametersType parType)
Definition: AlignmentParametersFactory.cc:63
AlignmentParameterSelector::decompose
std::vector< std::string > decompose(const std::string &s, std::string::value_type delimiter) const
Decomposing input string 's' into parts separated by 'delimiter'.
Definition: AlignmentParameterSelector.cc:776
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
Alignable::setAlignmentParameters
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
AlignmentParameterBuilder::fixAlignables
void fixAlignables(int n)
Remove n Alignables from list.
Definition: AlignmentParameterBuilder.cc:148
AlignmentParametersFactory::ParametersType
ParametersType
enums for all available AlignmentParameters
Definition: AlignmentParametersFactory.h:21
AlignmentParameterSelector.h
Alignable
Definition: Alignable.h:27
pos
Definition: PixelAliasList.h:18
SelectionUserVariables
Definition: SelectionUserVariables.h:22
AlignmentParametersFactory
AlignmentParameterBuilder::addAllSelections
void addAllSelections(const edm::ParameterSet &pSet)
master initialisation method, PSet must have form as constructor wants it
Definition: AlignmentParameterBuilder.cc:70
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
AlignmentParameterSelector::selectedAlignables
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
Definition: AlignmentParameterSelector.h:37
AlignmentParameters
Definition: AlignmentParameters.h:35
AlignmentParameterBuilder::theAlignables
align::Alignables theAlignables
Vector of alignables.
Definition: AlignmentParameterBuilder.h:87
AlignmentParameterSelector::selectedParameters
const std::vector< std::vector< char > > & selectedParameters() const
vector of selection 'strings' for alignables, parallel to selectedAlignables()
Definition: AlignmentParameterSelector.h:39
AlignmentParameters.h
AlignmentParameterBuilder.h
AlignmentParameterBuilder::theAlignableTracker
AlignableTracker * theAlignableTracker
Alignable tracker.
Definition: AlignmentParameterBuilder.h:90
AlignmentParameterBuilder::AlignmentParameterBuilder
AlignmentParameterBuilder(AlignableTracker *alignableTracker, AlignableExtras *alignableExtras)
Constructor from tracker only.
Definition: AlignmentParameterBuilder.cc:28
Alignable::alignableObjectId
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignableTracker
Definition: AlignableTracker.h:17
AlignmentParameterBuilder::addSelections
unsigned int addSelections(const edm::ParameterSet &pset, AlignmentParametersFactory::ParametersType parType)
Definition: AlignmentParameterBuilder.cc:87
AlignableExtras
Definition: AlignableExtras.h:19
AlignmentParameterBuilder::alignables
const align::Alignables & alignables() const
Get list of alignables for which AlignmentParameters are built.
Definition: AlignmentParameterBuilder.h:68
align::AlignableDetUnit
Definition: StructureType.h:19
edm::ParameterSet
Definition: ParameterSet.h:47
SelectionUserVariables.h
AlignableMuon
Constructor of the full muon geometry.
Definition: AlignableMuon.h:38
AlignmentParameterBuilder::theAlignableMuon
AlignableMuon * theAlignableMuon
Alignable muon.
Definition: AlignmentParameterBuilder.h:93
AlignmentParameterBuilder::decodeParamSel
bool decodeParamSel(std::vector< char > &paramSelChar, std::vector< bool > &result) const
Definition: AlignmentParameterBuilder.cc:175
AlignmentParameterBuilder::alignableTracker
const AlignableTracker * alignableTracker() const
Alignable tracker.
Definition: AlignmentParameterBuilder.cc:67
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
align::AlignableDet
Definition: StructureType.h:20
align::Alignables
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
AlignmentParameterSelector::addSelections
unsigned int addSelections(const edm::ParameterSet &pSet)
Definition: AlignmentParameterSelector.cc:67
Exception
Definition: hltDiff.cc:245
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219
Alignable.h
AlignmentParameterBuilder::theAlignableExtras
AlignableExtras * theAlignableExtras
extra Alignables
Definition: AlignmentParameterBuilder.h:96
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
AlignmentParameterBuilder::add
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.
Definition: AlignmentParameterBuilder.cc:134
AlignmentParametersFactory::parametersType
ParametersType parametersType(const std::string &typeString)
convert string to ParametersType - exception if not known
Definition: AlignmentParametersFactory.cc:22
AlignmentParameterSelector
Definition: AlignmentParameterSelector.h:26
AlignmentParameters::setUserVariables
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
Definition: AlignmentParameters.cc:94