CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes | Static Private Attributes
PedeReader Class Reference

#include <PedeReader.h>

Public Types

typedef PedeLabelerBase::RunNumber RunNumber
 
typedef PedeLabelerBase::RunRange RunRange
 

Public Member Functions

AlignmentParameterscheckAliParams (Alignable *alignable, bool createUserVars) const
 
 PedeReader (const edm::ParameterSet &config, const PedeSteerer &steerer, const PedeLabelerBase &labels, const RunRange &runrange)
 
bool read (std::vector< Alignable * > &alignables, bool setUserVars)
 
template<class T >
bool readIfSameLine (std::ifstream &aStream, T &outValue) const
 
bool setCalibrationParameter (IntegratedCalibrationBase *calib, unsigned int paramNum, unsigned int bufLength, const float *buf) const
 Set pede results stored in 'buf' to parameter 'paramNum' of IntegratedCalibrationBase. More...
 
AlignablesetParameter (unsigned int paramLabel, unsigned int bufLength, const float *buf, bool setUserVars) const
 
 ~PedeReader ()
 non virtual destructor: do not inherit from this class More...
 

Private Attributes

const PedeLabelerBasemyLabels
 
std::ifstream myPedeResult
 
const RunRange myRunRange
 
const PedeSteerermySteerer
 

Static Private Attributes

static const unsigned int myMaxNumValPerParam = 5
 

Detailed Description

read in result from pede text file

Author
: Gero Flucke date : November 2006
Revision:
1.4
Date:
2011/02/16 13:11:57

(last update by

Author:
mussgill

)

Definition at line 33 of file PedeReader.h.

Member Typedef Documentation

Definition at line 37 of file PedeReader.h.

Definition at line 38 of file PedeReader.h.

Constructor & Destructor Documentation

PedeReader::PedeReader ( const edm::ParameterSet config,
const PedeSteerer steerer,
const PedeLabelerBase labels,
const RunRange runrange 
)

Definition at line 33 of file PedeReader.cc.

References PedeSteerer::directory(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), recoMuon::in, myPedeResult, and AlCaHLTBitMon_QueryRunRegistry::string.

35  : mySteerer(steerer), myLabels(labels), myRunRange(runrange)
36 {
37  std::string pedeResultFile(config.getUntrackedParameter<std::string>("fileDir"));
38  if (pedeResultFile.empty()) pedeResultFile = steerer.directory(); // includes final '/'
39  else if (pedeResultFile.find_last_of('/') != pedeResultFile.size() - 1) {
40  pedeResultFile += '/'; // directory may need '/'
41  }
42 
43  pedeResultFile += config.getParameter<std::string>("readFile");
44  myPedeResult.open(pedeResultFile.c_str(), std::ios::in);
45  if (!myPedeResult.is_open()) {
46  edm::LogError("Alignment") << "@SUB=PedeReader"
47  << "Problem opening pede output file " << pedeResultFile;
48  }
49 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const PedeSteerer & mySteerer
Definition: PedeReader.h:68
std::ifstream myPedeResult
Definition: PedeReader.h:67
const std::string & directory() const
directory from constructor input, &#39;/&#39; is attached if needed
Definition: PedeSteerer.h:66
const PedeLabelerBase & myLabels
Definition: PedeReader.h:69
const RunRange myRunRange
Definition: PedeReader.h:70
PedeReader::~PedeReader ( )
inline

non virtual destructor: do not inherit from this class

Definition at line 43 of file PedeReader.h.

43 {}

Member Function Documentation

AlignmentParameters * PedeReader::checkAliParams ( Alignable alignable,
bool  createUserVars 
) const

returns parameters of alignable (creates if not yet existing, but MillePedeVariables are only created if createUserVars == true)

Definition at line 261 of file PedeReader.cc.

References PedeLabelerBase::alignableLabel(), Alignable::alignmentParameters(), Exception, myLabels, AlignmentParameters::setUserVariables(), AlignmentParameters::size(), and AlignmentParameters::userVariables().

Referenced by setParameter().

262 {
263  // first check that we have parameters
264  AlignmentParameters *params = alignable->alignmentParameters();
265  if (!params) {
266  throw cms::Exception("BadConfig") << "PedeReader::checkAliParams: "
267  << "Alignable without parameters.";
268 
269  }
270 
271  // now check that we have user parameters of correct type if requested:
272  if (createUserVars && !dynamic_cast<MillePedeVariables*>(params->userVariables())) {
273  edm::LogInfo("Alignment") << "@SUB=PedeReader::checkAliParams"
274  << "Add user variables for alignable with label "
275  << myLabels.alignableLabel(alignable);
276  params->setUserVariables(new MillePedeVariables(params->size(), myLabels.alignableLabel(alignable)));
277  }
278 
279  return params;
280 }
virtual unsigned int alignableLabel(Alignable *alignable) const =0
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
int size(void) const
Get number of parameters.
const PedeLabelerBase & myLabels
Definition: PedeReader.h:69
bool PedeReader::read ( std::vector< Alignable * > &  alignables,
bool  setUserVars 
)

Read pede output into AlignmentParameters attached to 'alignables' (if they fit to the run range). If (setUserVars == true) also care about MillePedeVariables. Also treats parameters belonging to a IntegratedCalibrationBase.

Definition at line 52 of file PedeReader.cc.

References PedeLabelerBase::calibrationParamFromLabel(), myLabels, myMaxNumValPerParam, myPedeResult, myRunRange, dbtoconf::out, PedeLabelerBase::runRangeFromLabel(), setCalibrationParameter(), and setParameter().

Referenced by Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), MillePedeAlignmentAlgorithm::readFromPede(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

53 {
54  alignables.clear();
55  myPedeResult.seekg(0, std::ios::beg); // back to start
56  bool isAllOk = true;
57 
58  std::set<Alignable*> uniqueList;
59 
60  edm::LogInfo("Alignment") << "@SUB=PedeReader::read"
61  << "will read parameters for run range "
62  << myRunRange.first << " - " << myRunRange.second;
63 
64  // loop on lines of text file
65  unsigned int nParam = 0, nParamCalib = 0, nParamUnknown = 0;
66  while (myPedeResult.good() && !myPedeResult.eof()) {
67  // read label
68  unsigned int paramLabel = 0;
69  if (!this->readIfSameLine<unsigned int>(myPedeResult, paramLabel)) continue; // empty line?
70 
71  // read up to maximal number of pede result per parameter
72  float buffer[myMaxNumValPerParam] = {0.};
73  unsigned int bufferPos = 0;
74  for ( ; bufferPos < myMaxNumValPerParam; ++bufferPos) {
75  if (!this->readIfSameLine<float>(myPedeResult, buffer[bufferPos])) break;
76  }
77 
78  // First check whether parameter is from any calibration (to be done before RunRange check:
79  // run dependence for them is not handled here, but probably inside the calibration).
80  // Double setting by calling read(..) twice for different RunRanges shouldn't harm.
81  std::pair<IntegratedCalibrationBase*, unsigned int> calibParam
82  = myLabels.calibrationParamFromLabel(paramLabel);
83  if (calibParam.first) { // label belongs to a calibration
84  if (this->setCalibrationParameter(calibParam.first, calibParam.second, bufferPos, buffer)) {
85  ++nParamCalib;
86  } else {
87  edm::LogError("Alignment") << "@SUB=PedeReader::read" << "Problems setting results of "
88  << "parameter " << calibParam.second << " to calibration '"
89  << calibParam.first->name() << "' ("<< calibParam.first << ").";
90  isAllOk = false;
91  }
92  continue; // does not belong to any Alignable, so go to next line of file
93  }
94  // Now treat Alignables if paramLabel fits to run range, otherwise skip line:
95  const RunRange & runRange = myLabels.runRangeFromLabel(paramLabel);
96  if (!(runRange.first<=myRunRange.first && myRunRange.second<=runRange.second)) continue;
97 
98  Alignable *alignable = this->setParameter(paramLabel, bufferPos, buffer, setUserVars);
99  if (!alignable) {
100  // OK, e.g. for PedeReaderInputs: calibration parameters, but not yet known to labeler
101  ++nParamUnknown;
102  continue;
103  }
104  uniqueList.insert(alignable);
105  ++nParam;
106  }
107 
108  // add Alignables to output
109  alignables.insert(alignables.end(), uniqueList.begin(), uniqueList.end());
110 
111  std::stringstream out; // "@SUB=PedeReader::read" cannot yet go to 'out' for proper format
112  out << nParam << " parameters for " << alignables.size() << " alignables and " << nParamCalib
113  << " for calibrations, " << nParamUnknown << " parameters are unknown.\n";
114  if (nParamUnknown) {
115  edm::LogWarning("Alignment") << "@SUB=PedeReader::read" << out.str();
116  } else {
117  edm::LogInfo("Alignment") << "@SUB=PedeReader::read" << out.str();
118  }
119 
120  return isAllOk && (nParam + nParamCalib); // nParam+nParamCalib == 0: empty or bad file
121 }
virtual const RunRange & runRangeFromLabel(unsigned int label) const
std::ifstream myPedeResult
Definition: PedeReader.h:67
std::pair< RunNumber, RunNumber > RunRange
Alignable * setParameter(unsigned int paramLabel, unsigned int bufLength, const float *buf, bool setUserVars) const
Definition: PedeReader.cc:157
tuple out
Definition: dbtoconf.py:99
static const unsigned int myMaxNumValPerParam
Definition: PedeReader.h:72
virtual std::pair< IntegratedCalibrationBase *, unsigned int > calibrationParamFromLabel(unsigned int label) const
bool setCalibrationParameter(IntegratedCalibrationBase *calib, unsigned int paramNum, unsigned int bufLength, const float *buf) const
Set pede results stored in &#39;buf&#39; to parameter &#39;paramNum&#39; of IntegratedCalibrationBase.
Definition: PedeReader.cc:231
const PedeLabelerBase & myLabels
Definition: PedeReader.h:69
const RunRange myRunRange
Definition: PedeReader.h:70
template<class T >
bool PedeReader::readIfSameLine ( std::ifstream &  aStream,
T outValue 
) const

true if 'outValue' could be read via operator >> from the current line (!) of aStream, false otherwise

Definition at line 126 of file PedeReader.cc.

127 {
128 
129  while (true) {
130  const int aChar = aStream.get();
131  if (!aStream.good()) return false;
132 
133  switch(aChar) {
134  case ' ':
135  case '\t':
136  continue; // to next character
137  case '\n':
138  return false; // end of line
139  default:
140  aStream.unget();
141  aStream >> outValue;
142  if (aStream.fail()) {// not correct type 'T' (!aStream.good() is true also in case of EOF)
143  aStream.clear();
144  while (aStream.good() && aStream.get() != '\n'); // forward to end of line
145  return false;
146  } else {
147  return true;
148  }
149  } // switch
150  } // while
151 
152  edm::LogError("Alignment") << "@SUB=PedeReader::readIfSameLine" << "Should never come here!";
153  return false;
154 }
bool PedeReader::setCalibrationParameter ( IntegratedCalibrationBase calib,
unsigned int  paramNum,
unsigned int  bufLength,
const float *  buf 
) const

Set pede results stored in 'buf' to parameter 'paramNum' of IntegratedCalibrationBase.

Definition at line 231 of file PedeReader.cc.

References mySteerer, IntegratedCalibrationBase::name(), PedeSteerer::parameterSign(), IntegratedCalibrationBase::setParameter(), and IntegratedCalibrationBase::setParameterError().

Referenced by read().

233 {
234  if (!calib || !buf) return false;
235 
236  // FIXME: Should we attach MillePedeVariables to IntegratedCalibrationBase to store
237  // 'other' results beyond value and error?
238  switch (bufLength) {
239  case 5: // buf[4]: global correlation - not treated yet FIXME // no break;
240  case 4: // uncertainty
241  calib->setParameterError(paramNum, buf[3]); // no break;
242  case 3: // buf[2]: difference to start value - not treated yet // no break;
243  case 2:
244  if (bufLength == 2 && buf[1] >= 0.) { // buf[1]: pre-sigma, < 0 means fixed
245  edm::LogWarning("Alignment") << "@SUB=PedeReader::setCalibrationParameter"
246  << "Param " << paramNum << " of calibration '"
247  << calib->name() << "' without result!";
248  }
249  return calib->setParameter(paramNum, buf[0] * mySteerer.parameterSign());
250  case 0:
251  case 1:
252  default:
253  edm::LogError("Alignment") << "@SUB=PedeReader::setCalibrationParameter"
254  << "Expect 2 to 5 values, got " << bufLength << ".";
255  return false;
256  }
257 
258 }
const PedeSteerer & mySteerer
Definition: PedeReader.h:68
virtual bool setParameter(unsigned int index, double value)=0
const std::string & name() const
name of this calibration
virtual bool setParameterError(unsigned int index, double value)=0
int parameterSign() const
results from pede (and start values for pede) might need a sign flip
Definition: PedeSteerer.h:64
Alignable * PedeReader::setParameter ( unsigned int  paramLabel,
unsigned int  bufLength,
const float *  buf,
bool  setUserVars 
) const

Set pede results stored in 'buf' to AlignmentParameters and (if setUserVars == true) to MillePedeVariables, return corresponding Alignable.

Definition at line 157 of file PedeReader.cc.

References PedeLabelerBase::alignableFromLabel(), PedeLabelerBase::alignableLabel(), checkAliParams(), AlignmentParameters::clone(), PedeSteerer::cmsToPedeFactor(), AlignmentParameters::covariance(), MillePedeVariables::diffBefore(), MillePedeVariables::globalCor(), MillePedeVariables::isFixed(), MillePedeVariables::isValid(), MillePedeVariables::label(), PedeLabelerBase::lasBeamIdFromLabel(), myLabels, mySteerer, MillePedeVariables::parameter(), AlignmentParameters::parameters(), PedeSteerer::parameterSign(), PedeLabelerBase::paramNumFromLabel(), MillePedeVariables::preSigma(), Alignable::setAlignmentParameters(), MillePedeVariables::setAllDefault(), AlignmentParameters::setValid(), MillePedeVariables::sigma(), and AlignmentParameters::userVariables().

Referenced by editorTools.UserCodeTool::__call__(), HiCoreTools.RestrictInputToAOD::__call__(), coreTools.RunOnData::__call__(), trackTools.MakeAODTrackCandidates::__call__(), runJetUncertainties.RunJetUncertainties::__call__(), metTools.AddMETCollection::__call__(), editorTools.ChangeSource::__call__(), HiCoreTools.RemoveMCMatching::__call__(), cmsswVersionTools.PickRelValInputFiles::__call__(), coreTools.RemoveMCMatching::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__call__(), jetTools.AddJetCollection::__call__(), HiCoreTools.RemoveAllPATObjectsBut::__call__(), HiCoreTools.RemoveSpecificPATObjects::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), trackTools.MakeTrackCandidates::__call__(), tauTools.AddTauCollection::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), HiCoreTools.RemoveCleaning::__call__(), HiCoreTools.AddCleaning::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::jetConfiguration(), and read().

160 {
161  Alignable *alignable = myLabels.alignableFromLabel(paramLabel);
162  const unsigned int paramNum = myLabels.paramNumFromLabel(paramLabel);
163  const double cmsToPede = mySteerer.cmsToPedeFactor(paramNum);
164  if (alignable) {
165  AlignmentParameters *params = this->checkAliParams(alignable, setUserVars);
166  MillePedeVariables *userParams = // static cast ensured by previous checkAliParams
167  (setUserVars ? static_cast<MillePedeVariables*>(params->userVariables()) : 0);
168  // if (userParams && userParams->label() != myLabels.alignableLabelFromLabel(paramLabel)) {
169  if (userParams && userParams->label() != myLabels.alignableLabel(alignable)) {
170  edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
171  << "Label mismatch: paramLabel " << paramLabel
172  << " for alignableLabel " << userParams->label();
173  }
174 
175  AlgebraicVector parVec(params->parameters());
176  AlgebraicSymMatrix covMat(params->covariance());
177 
178  if (userParams) userParams->setAllDefault(paramNum);
179 
180  switch (bufLength) {
181  case 5: // global correlation
182  if (userParams) userParams->globalCor()[paramNum] = buf[4]; // no break
183  case 4: // uncertainty
184  if (userParams) userParams->sigma()[paramNum] = buf[3] / cmsToPede;
185  covMat[paramNum][paramNum] = buf[3]*buf[3] / (cmsToPede*cmsToPede);
186  // no break;
187  case 3: // difference to start value
188  if (userParams) userParams->diffBefore()[paramNum] = buf[2] / cmsToPede;
189  // no break
190  case 2:
191  params->setValid(true);
192  parVec[paramNum] = buf[0] / cmsToPede * mySteerer.parameterSign(); // parameter
193  if (userParams) {
194  userParams->parameter()[paramNum] = parVec[paramNum]; // duplicate in millepede parameters
195  userParams->preSigma()[paramNum] = buf[1]; // presigma given, probably means fixed
196  if (!userParams->isFixed(paramNum)) {
197  userParams->preSigma()[paramNum] /= cmsToPede;
198  if (bufLength == 2) {
199  edm::LogWarning("Alignment") << "@SUB=PedeReader::setParameter"
200  << "Param " << paramLabel << " (from "
201  << typeid(*alignable).name() << ") without result!";
202  userParams->isValid()[paramNum] = false;
203  params->setValid(false);
204  }
205  }
206  }
207  break;
208  case 0:
209  case 1:
210  default:
211  edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
212  << "Expect 2 to 5 values, got " << bufLength
213  << " for label " << paramLabel;
214  break;
215  }
216  alignable->setAlignmentParameters(params->clone(parVec, covMat));//transferred mem. responsib.
217  } else {
218  unsigned int lasBeamId = myLabels.lasBeamIdFromLabel(paramLabel);
219  edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
220  << "No alignable for paramLabel " << paramLabel
221  << ", probably LasBeam with Id " << lasBeamId
222  << ",\nparam " << paramNum << ": "
223  << buf[0] / cmsToPede * mySteerer.parameterSign()
224  << " += " << (bufLength >= 4 ? buf[3] / cmsToPede : -99.);
225  }
226 
227  return alignable;
228 }
unsigned int label() const
get alignable label as used by pede
const std::vector< float > & globalCor() const
get global correlation array
virtual Alignable * alignableFromLabel(unsigned int label) const =0
AlignmentParameters * checkAliParams(Alignable *alignable, bool createUserVars) const
Definition: PedeReader.cc:261
bool isFixed(unsigned int nParam) const
true if parameter is fixed
const PedeSteerer & mySteerer
Definition: PedeReader.h:68
virtual unsigned int alignableLabel(Alignable *alignable) const =0
const std::vector< float > & parameter() const
get array of parameters
virtual unsigned int paramNumFromLabel(unsigned int paramLabel) const =0
parameter number, 0 &lt;= .. &lt; theMaxNumParam, belonging to unique parameter label
const AlgebraicVector & parameters(void) const
Get alignment parameters.
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:81
void setValid(bool v)
Set validity flag.
const std::vector< float > & preSigma() const
get array of presigmas (&lt;= 0: means fixed)
const std::vector< float > & sigma() const
get array of sigmas
const std::vector< float > & diffBefore() const
get array of differences to start value
CLHEP::HepVector AlgebraicVector
virtual AlignmentParameters * clone(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
Enforce clone methods in derived classes.
double cmsToPedeFactor(unsigned int parNum) const
Definition: PedeSteerer.cc:139
const std::vector< bool > & isValid() const
get valid flag array
CLHEP::HepSymMatrix AlgebraicSymMatrix
const AlgebraicSymMatrix & covariance(void) const
Get parameter covariance matrix.
const PedeLabelerBase & myLabels
Definition: PedeReader.h:69
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
int parameterSign() const
results from pede (and start values for pede) might need a sign flip
Definition: PedeSteerer.h:64
virtual unsigned int lasBeamIdFromLabel(unsigned int label) const =0

Member Data Documentation

const PedeLabelerBase& PedeReader::myLabels
private

Definition at line 69 of file PedeReader.h.

Referenced by checkAliParams(), read(), and setParameter().

const unsigned int PedeReader::myMaxNumValPerParam = 5
staticprivate

Definition at line 72 of file PedeReader.h.

Referenced by read().

std::ifstream PedeReader::myPedeResult
private

Definition at line 67 of file PedeReader.h.

Referenced by PedeReader(), and read().

const RunRange PedeReader::myRunRange
private

Definition at line 70 of file PedeReader.h.

Referenced by read().

const PedeSteerer& PedeReader::mySteerer
private

Definition at line 68 of file PedeReader.h.

Referenced by setCalibrationParameter(), and setParameter().