CMS 3D CMS Logo

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 35 of file PedeReader.cc.

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

37  : mySteerer(steerer), myLabels(labels), myRunRange(runrange)
38 {
39  std::string pedeResultFile(config.getUntrackedParameter<std::string>("fileDir"));
40  if (pedeResultFile.empty()) pedeResultFile = steerer.directory(); // includes final '/'
41  else if (pedeResultFile.find_last_of('/') != pedeResultFile.size() - 1) {
42  pedeResultFile += '/'; // directory may need '/'
43  }
44 
45  pedeResultFile += config.getParameter<std::string>("readFile");
46  myPedeResult.open(pedeResultFile.c_str(), std::ios::in);
47  if (!myPedeResult.is_open()) {
48  edm::LogError("Alignment") << "@SUB=PedeReader"
49  << "Problem opening pede output file " << pedeResultFile;
50  }
51 }
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:67
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 263 of file PedeReader.cc.

References PedeLabelerBase::alignableLabel(), Alignable::alignableObjectId(), PedeLabelerBase::alignableTracker(), Alignable::alignmentParameters(), Exception, myLabels, AlignableTracker::objectIdProvider(), AlignmentParameters::setUserVariables(), AlignmentParameters::size(), AlignableObjectId::typeToName(), and AlignmentParameters::userVariables().

Referenced by setParameter().

264 {
265  // first check that we have parameters
266  AlignmentParameters *params = alignable->alignmentParameters();
267  if (!params) {
268  throw cms::Exception("BadConfig") << "PedeReader::checkAliParams: "
269  << "Alignable without parameters.";
270 
271  }
272 
273  // now check that we have user parameters of correct type if requested:
274  if (createUserVars && !dynamic_cast<MillePedeVariables*>(params->userVariables())) {
275  edm::LogInfo("Alignment") << "@SUB=PedeReader::checkAliParams"
276  << "Add user variables for alignable with label "
277  << myLabels.alignableLabel(alignable);
278  params->setUserVariables(new MillePedeVariables(params->size(),
279  myLabels.alignableLabel(alignable),
281  }
282 
283  return params;
284 }
std::string typeToName(align::StructureType type) const
Convert type to name.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
const AlignableTracker * alignableTracker() const
const AlignableObjectId & objectIdProvider() const
Return tracker alignable object ID provider derived from the tracker&#39;s geometry.
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
int size(void) const
Get number of parameters.
virtual unsigned int alignableLabel(Alignable *alignable) const =0
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 54 of file PedeReader.cc.

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

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

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

129 {
130 
131  while (true) {
132  const int aChar = aStream.get();
133  if (!aStream.good()) return false;
134 
135  switch(aChar) {
136  case ' ':
137  case '\t':
138  continue; // to next character
139  case '\n':
140  return false; // end of line
141  default:
142  aStream.unget();
143  aStream >> outValue;
144  if (aStream.fail()) {// not correct type 'T' (!aStream.good() is true also in case of EOF)
145  aStream.clear();
146  while (aStream.good() && aStream.get() != '\n'); // forward to end of line
147  return false;
148  } else {
149  return true;
150  }
151  } // switch
152  } // while
153 
154  edm::LogError("Alignment") << "@SUB=PedeReader::readIfSameLine" << "Should never come here!";
155  return false;
156 }
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 233 of file PedeReader.cc.

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

Referenced by read().

235 {
236  if (!calib || !buf) return false;
237 
238  // FIXME: Should we attach MillePedeVariables to IntegratedCalibrationBase to store
239  // 'other' results beyond value and error?
240  switch (bufLength) {
241  case 5: // buf[4]: global correlation - not treated yet FIXME // no break;
242  case 4: // uncertainty
243  calib->setParameterError(paramNum, buf[3]); // no break;
244  case 3: // buf[2]: difference to start value - not treated yet // no break;
245  case 2:
246  if (bufLength == 2 && buf[1] >= 0.) { // buf[1]: pre-sigma, < 0 means fixed
247  edm::LogWarning("Alignment") << "@SUB=PedeReader::setCalibrationParameter"
248  << "Param " << paramNum << " of calibration '"
249  << calib->name() << "' without result!";
250  }
251  return calib->setParameter(paramNum, buf[0] * mySteerer.parameterSign());
252  case 0:
253  case 1:
254  default:
255  edm::LogError("Alignment") << "@SUB=PedeReader::setCalibrationParameter"
256  << "Expect 2 to 5 values, got " << bufLength << ".";
257  return false;
258  }
259 
260 }
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:65
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 159 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__(), trigTools.SwitchOnTrigger::__call__(), trackTools.MakePATTrackCandidates::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__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.AddJetCollection::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.UpdateJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::jetConfiguration(), and read().

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

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().