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 }
36 
37 //__________________________________________________________________________________________________
39  AlignableMuon* alignableMuon,
40  AlignableExtras* alignableExtras) :
41  theAlignables(),
42  theAlignableTracker(alignableTracker),
43  theAlignableMuon(alignableMuon),
44  theAlignableExtras(alignableExtras)
45 {
46 }
47 
48 
49 //__________________________________________________________________________________________________
51  AlignableExtras* alignableExtras,
52  const edm::ParameterSet &pSet) :
53  theAlignables(),
54  theAlignableTracker(alignableTracker),
56  theAlignableExtras(alignableExtras)
57 {
58  this->addAllSelections(pSet);
59 }
60 
61 //__________________________________________________________________________________________________
63  AlignableMuon* alignableMuon,
64  AlignableExtras* alignableExtras,
65  const edm::ParameterSet &pSet) :
66  theAlignables(),
67  theAlignableTracker(alignableTracker),
68  theAlignableMuon(alignableMuon),
69  theAlignableExtras(alignableExtras)
70 {
71  this->addAllSelections(pSet);
72 }
73 
75 {
76  return theAlignableTracker;
77 }
78 
79 //__________________________________________________________________________________________________
81 {
82  AlignmentParameterSelector selector(nullptr);
83  std::vector<std::string> selsTypes(pSet.getParameter<std::vector<std::string> >("parameterTypes"));
84 
85  for (unsigned int i = 0; i < selsTypes.size(); ++i) {
86  std::vector<std::string> selSetType(selector.decompose(selsTypes[i], ','));
87  if (selSetType.size() != 2) {
88  throw cms::Exception("BadConfig") << "AlignmentParameterBuilder"
89  << "parameterTypes should contain 2 comma separated strings"
90  << ", but found '" << selsTypes[i] << "'.";
91  }
92  this->addSelections(pSet.getParameter<edm::ParameterSet>(selSetType[0]),
94  }
95 }
96 
97 //__________________________________________________________________________________________________
99  ParametersType parType)
100 {
101 
102  const unsigned int oldAliSize = theAlignables.size();
103 
105  const unsigned int addedSets = selector.addSelections(pSet);
106 
107  const align::Alignables &alignables = selector.selectedAlignables();
108  const std::vector<std::vector<char> > &paramSels = selector.selectedParameters();
109 
110  align::Alignables::const_iterator iAli = alignables.begin();
111  std::vector<std::vector<char> >::const_iterator iParamSel = paramSels.begin();
112  unsigned int nHigherLevel = 0;
113 
114  while (iAli != alignables.end() && iParamSel != paramSels.end()) {
115  std::vector<bool> boolParSel;
116  std::vector<char> parSel(*iParamSel); // copy, since decodeParamSel may manipulate
117  bool charSelIsGeneral = this->decodeParamSel(parSel, boolParSel);
118  if (this->add(*iAli, parType, boolParSel)) ++nHigherLevel;
119  if (charSelIsGeneral) this->addFullParamSel((*iAli)->alignmentParameters(), parSel);
120 
121  ++iAli;
122  ++iParamSel;
123  }
124 
125  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterBuilder::addSelections"
126  << " Added " << addedSets << " set(s) of alignables with "
127  << theAlignables.size() - oldAliSize << " alignables in total,"
128  << " of which " << nHigherLevel << " are higher level "
129  << "(using " << parametersTypeName(parType) << "AlignmentParameters).";
130 
131  return addedSets;
132 }
133 
134 //__________________________________________________________________________________________________
136  ParametersType parType,
137  const std::vector<bool> &sel)
138 {
139  AlignmentParameters *paras = AlignmentParametersFactory::createParameters(alignable, parType, sel);
140  alignable->setAlignmentParameters(paras);
141  theAlignables.push_back(alignable);
142 
143  const int aliTypeId = alignable->alignableObjectId();
144  const bool isHigherLevel = (aliTypeId != align::AlignableDet
145  && aliTypeId != align::AlignableDetUnit);
146  return isHigherLevel;
147 }
148 
149 
150 //__________________________________________________________________________________________________
152  ParametersType parType, const std::vector<bool> &sel)
153 {
154 
155  unsigned int nHigherLevel = 0;
156 
157  for (align::Alignables::const_iterator iAli = alignables.begin();
158  iAli != alignables.end(); ++iAli) {
159  if (this->add(*iAli, parType, sel)) ++nHigherLevel;
160  }
161 
162  return nHigherLevel;
163 }
164 
165 
166 //__________________________________________________________________________________________________
168 {
169 
170  if (n<1 || n>3) {
171  edm::LogError("BadArgument") << " n = " << n << " is not in [1,3]";
172  return;
173  }
174 
175  align::Alignables theNewAlignables;
176  int i=0;
177  int imax = theAlignables.size();
178  for ( align::Alignables::const_iterator ia=theAlignables.begin();
179  ia!=theAlignables.end(); ++ia )
180  {
181  i++;
182  if ( n==1 && i>1 )
183  theNewAlignables.push_back(*ia);
184  else if ( n==2 && i>1 && i<imax )
185  theNewAlignables.push_back(*ia);
186  else if ( n==3 && i>2 && i<imax)
187  theNewAlignables.push_back(*ia);
188  }
189 
190  theAlignables = theNewAlignables;
191 
192  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterBuilder::fixAlignables"
193  << "removing " << n << " alignables, so that "
194  << theAlignables.size() << " alignables left";
195 }
196 
197 //__________________________________________________________________________________________________
198 bool AlignmentParameterBuilder::decodeParamSel(std::vector<char> &paramSelChar,
199  std::vector<bool> &result) const
200 {
201  result.clear();
202  // remove all spaces from paramSelChar - useful to group the parameters if they are many
203  paramSelChar.erase(std::remove(paramSelChar.begin(), paramSelChar.end(), ' '),
204  paramSelChar.end());
205 
206  bool anyNon01 = false;
207 
208  for (unsigned int pos = 0; pos < paramSelChar.size(); ++pos) {
209 
210  switch (paramSelChar[pos]) {
211  default:
212  anyNon01 = true;
213  // no break;
214  case '1':
215  result.push_back(true);
216  break;
217  case '0':
218  result.push_back(false);
219  break;
220  }
221  }
222 
223  return anyNon01;
224 }
225 
226 //__________________________________________________________________________________________________
228  const std::vector<char> &fullSel) const
229 {
230  if (!aliParams) return false;
231 
232  aliParams->setUserVariables(new SelectionUserVariables(fullSel));
233 
234  return true;
235 }
T getParameter(std::string const &) const
AlignmentParameterBuilder(AlignableTracker *alignableTracker, AlignableExtras *alignableExtras)
Constructor from tracker only.
unsigned int addSelections(const edm::ParameterSet &pset, AlignmentParametersFactory::ParametersType parType)
std::string parametersTypeName(ParametersType parType)
convert ParametersType to string understood by parametersType(string &typeString) ...
#define nullptr
const AlignableTracker * alignableTracker() const
Alignable tracker.
bool decodeParamSel(std::vector< char > &paramSelChar, std::vector< bool > &result) const
ParametersType
enums for all available AlignmentParameters
AlignableExtras * theAlignableExtras
extra Alignables
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:128
bool addFullParamSel(AlignmentParameters *aliPar, const std::vector< char > &fullSel) const
add SelectionUserVariables corresponding to fullSel
std::vector< std::string > decompose(const std::string &s, std::string::value_type delimiter) const
Decomposing input string &#39;s&#39; into parts separated by &#39;delimiter&#39;.
void fixAlignables(int n)
Remove n Alignables from list.
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.
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:212
std::vector< Alignable * > Alignables
Definition: Utilities.h:32
unsigned int addSelections(const edm::ParameterSet &pSet)
align::Alignables theAlignables
Vector of alignables.
ParametersType parametersType(const std::string &typeString)
convert string to ParametersType - exception if not known
const std::vector< std::vector< char > > & selectedParameters() const
vector of selection &#39;strings&#39; for alignables, parallel to selectedAlignables()
Constructor of the full muon geometry.
Definition: AlignableMuon.h:37
AlignableTracker * theAlignableTracker
Alignable tracker.
void addAllSelections(const edm::ParameterSet &pSet)
master initialisation method, PSet must have form as constructor wants it
const align::Alignables & alignables() const
Get list of alignables for which AlignmentParameters are built.