CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(0),
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),
55  theAlignableMuon(0),
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 
74 //__________________________________________________________________________________________________
76 {
77  AlignmentParameterSelector selector(0);
78  std::vector<std::string> selsTypes(pSet.getParameter<std::vector<std::string> >("parameterTypes"));
79 
80  for (unsigned int i = 0; i < selsTypes.size(); ++i) {
81  std::vector<std::string> selSetType(selector.decompose(selsTypes[i], ','));
82  if (selSetType.size() != 2) {
83  throw cms::Exception("BadConfig") << "AlignmentParameterBuilder"
84  << "parameterTypes should contain 2 comma separated strings"
85  << ", but found '" << selsTypes[i] << "'.";
86  }
87  this->addSelections(pSet.getParameter<edm::ParameterSet>(selSetType[0]),
89  }
90 }
91 
92 //__________________________________________________________________________________________________
94  ParametersType parType)
95 {
96 
97  const unsigned int oldAliSize = theAlignables.size();
98 
100  const unsigned int addedSets = selector.addSelections(pSet);
101 
102  const align::Alignables &alignables = selector.selectedAlignables();
103  const std::vector<std::vector<char> > &paramSels = selector.selectedParameters();
104 
105  align::Alignables::const_iterator iAli = alignables.begin();
106  std::vector<std::vector<char> >::const_iterator iParamSel = paramSels.begin();
107  unsigned int nHigherLevel = 0;
108 
109  while (iAli != alignables.end() && iParamSel != paramSels.end()) {
110  std::vector<bool> boolParSel;
111  std::vector<char> parSel(*iParamSel); // copy, since decodeParamSel may manipulate
112  bool charSelIsGeneral = this->decodeParamSel(parSel, boolParSel);
113  if (this->add(*iAli, parType, boolParSel)) ++nHigherLevel;
114  if (charSelIsGeneral) this->addFullParamSel((*iAli)->alignmentParameters(), parSel);
115 
116  ++iAli;
117  ++iParamSel;
118  }
119 
120  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterBuilder::addSelections"
121  << " Added " << addedSets << " set(s) of alignables with "
122  << theAlignables.size() - oldAliSize << " alignables in total,"
123  << " of which " << nHigherLevel << " are higher level "
124  << "(using " << parametersTypeName(parType) << "AlignmentParameters).";
125 
126  return addedSets;
127 }
128 
129 //__________________________________________________________________________________________________
131  ParametersType parType,
132  const std::vector<bool> &sel)
133 {
134  AlignmentParameters *paras = AlignmentParametersFactory::createParameters(alignable, parType, sel);
135  alignable->setAlignmentParameters(paras);
136  theAlignables.push_back(alignable);
137 
138  const int aliTypeId = alignable->alignableObjectId();
139  const bool isHigherLevel = (aliTypeId != align::AlignableDet
140  && aliTypeId != align::AlignableDetUnit);
141  return isHigherLevel;
142 }
143 
144 
145 //__________________________________________________________________________________________________
146 unsigned int AlignmentParameterBuilder::add(const align::Alignables &alignables,
147  ParametersType parType, const std::vector<bool> &sel)
148 {
149 
150  unsigned int nHigherLevel = 0;
151 
152  for (align::Alignables::const_iterator iAli = alignables.begin();
153  iAli != alignables.end(); ++iAli) {
154  if (this->add(*iAli, parType, sel)) ++nHigherLevel;
155  }
156 
157  return nHigherLevel;
158 }
159 
160 
161 //__________________________________________________________________________________________________
163 {
164 
165  if (n<1 || n>3) {
166  edm::LogError("BadArgument") << " n = " << n << " is not in [1,3]";
167  return;
168  }
169 
170  align::Alignables theNewAlignables;
171  int i=0;
172  int imax = theAlignables.size();
173  for ( align::Alignables::const_iterator ia=theAlignables.begin();
174  ia!=theAlignables.end(); ia++ )
175  {
176  i++;
177  if ( n==1 && i>1 )
178  theNewAlignables.push_back(*ia);
179  else if ( n==2 && i>1 && i<imax )
180  theNewAlignables.push_back(*ia);
181  else if ( n==3 && i>2 && i<imax)
182  theNewAlignables.push_back(*ia);
183  }
184 
185  theAlignables = theNewAlignables;
186 
187  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterBuilder::fixAlignables"
188  << "removing " << n << " alignables, so that "
189  << theAlignables.size() << " alignables left";
190 }
191 
192 //__________________________________________________________________________________________________
193 bool AlignmentParameterBuilder::decodeParamSel(std::vector<char> &paramSelChar,
194  std::vector<bool> &result) const
195 {
196  result.clear();
197  // remove all spaces from paramSelChar - useful to group the parameters if they are many
198  paramSelChar.erase(std::remove(paramSelChar.begin(), paramSelChar.end(), ' '),
199  paramSelChar.end());
200 
201  bool anyNon01 = false;
202 
203  for (unsigned int pos = 0; pos < paramSelChar.size(); ++pos) {
204 
205  switch (paramSelChar[pos]) {
206  default:
207  anyNon01 = true;
208  // no break;
209  case '1':
210  result.push_back(true);
211  break;
212  case '0':
213  result.push_back(false);
214  break;
215  }
216  }
217 
218  return anyNon01;
219 }
220 
221 //__________________________________________________________________________________________________
223  const std::vector<char> &fullSel) const
224 {
225  if (!aliParams) return false;
226 
227  aliParams->setUserVariables(new SelectionUserVariables(fullSel));
228 
229  return true;
230 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
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 &amp;typeString) ...
bool decodeParamSel(std::vector< char > &paramSelChar, std::vector< bool > &result) const
ParametersType
enums for all available AlignmentParameters
AlignableExtras * theAlignableExtras
extra Alignables
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:81
bool addFullParamSel(AlignmentParameters *aliPar, const std::vector< char > &fullSel) const
add SelectionUserVariables corresponding to fullSel
tuple result
Definition: query.py:137
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;.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
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.
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
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:36
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.