#include <PedeReader.h>
Public Types | |
typedef PedeLabelerBase::RunNumber | RunNumber |
typedef PedeLabelerBase::RunRange | RunRange |
Public Member Functions | |
AlignmentParameters * | checkAliParams (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 |
Alignable * | setParameter (unsigned int paramLabel, unsigned int bufLength, float *buf, bool setUserVars) const |
~PedeReader () | |
non virtual destructor: do not inherit from this class | |
Private Attributes | |
const PedeLabelerBase & | myLabels |
std::ifstream | myPedeResult |
const RunRange | myRunRange |
const PedeSteerer & | mySteerer |
Static Private Attributes | |
static const unsigned int | myMaxNumValPerParam = 5 |
read in result from pede text file
(last update by
)
Definition at line 32 of file PedeReader.h.
Definition at line 36 of file PedeReader.h.
Definition at line 37 of file PedeReader.h.
PedeReader::PedeReader | ( | const edm::ParameterSet & | config, |
const PedeSteerer & | steerer, | ||
const PedeLabelerBase & | labels, | ||
const RunRange & | runrange | ||
) |
Definition at line 31 of file PedeReader.cc.
References PedeSteerer::directory(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), recoMuon::in, and myPedeResult.
: mySteerer(steerer), myLabels(labels), myRunRange(runrange) { std::string pedeResultFile(config.getUntrackedParameter<std::string>("fileDir")); if (pedeResultFile.empty()) pedeResultFile = steerer.directory(); // includes final '/' else if (pedeResultFile.find_last_of('/') != pedeResultFile.size() - 1) { pedeResultFile += '/'; // directory may need '/' } pedeResultFile += config.getParameter<std::string>("readFile"); myPedeResult.open(pedeResultFile.c_str(), std::ios::in); if (!myPedeResult.is_open()) { edm::LogError("Alignment") << "@SUB=PedeReader" << "Problem opening pede output file " << pedeResultFile; } }
PedeReader::~PedeReader | ( | ) | [inline] |
non virtual destructor: do not inherit from this class
Definition at line 42 of file PedeReader.h.
{}
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 207 of file PedeReader.cc.
References PedeLabelerBase::alignableLabel(), Alignable::alignmentParameters(), Exception, myLabels, AlignmentParameters::setUserVariables(), AlignmentParameters::size(), and AlignmentParameters::userVariables().
Referenced by setParameter().
{ // first check that we have parameters AlignmentParameters *params = alignable->alignmentParameters(); if (!params) { throw cms::Exception("BadConfig") << "PedeReader::checkAliParams" << "Alignable without parameters."; } // now check that we have user parameters of correct type if requested: if (createUserVars && !dynamic_cast<MillePedeVariables*>(params->userVariables())) { edm::LogInfo("Alignment") << "@SUB=PedeReader::checkAliParams" << "Add user variables for alignable with label " << myLabels.alignableLabel(alignable); params->setUserVariables(new MillePedeVariables(params->size(), myLabels.alignableLabel(alignable))); } return params; }
bool PedeReader::read | ( | std::vector< Alignable * > & | alignables, |
bool | setUserVars | ||
) |
Read pede output into AlignmentParameters attached to 'alignables', if (setUserVars == true) also care about MillePedeVariables.
Definition at line 50 of file PedeReader.cc.
References myLabels, myMaxNumValPerParam, myPedeResult, myRunRange, PedeLabelerBase::runRangeFromLabel(), and setParameter().
Referenced by MillePedeAlignmentAlgorithm::readFromPede().
{ alignables.clear(); myPedeResult.seekg(0, std::ios::beg); // back to start bool isAllOk = true; std::map<Alignable*,Alignable*> uniqueList; // Probably should use a std::set here... edm::LogInfo("Alignment") << "@SUB=PedeReader::read" << "will read parameters for run range " << myRunRange.first << " - " << myRunRange.second; // loop on lines of text file unsigned int nParam = 0; while (myPedeResult.good() && !myPedeResult.eof()) { // read label unsigned int paramLabel = 0; if (!this->readIfSameLine<unsigned int>(myPedeResult, paramLabel)) continue; // empty line? // read up to maximal number of pede result per parameter float buffer[myMaxNumValPerParam] = {0.}; unsigned int bufferPos = 0; for ( ; bufferPos < myMaxNumValPerParam; ++bufferPos) { if (!this->readIfSameLine<float>(myPedeResult, buffer[bufferPos])) break; } const RunRange & runRange = myLabels.runRangeFromLabel(paramLabel); if (!(runRange.first<=myRunRange.first && myRunRange.second<=runRange.second)) continue; Alignable *alignable = this->setParameter(paramLabel, bufferPos, buffer, setUserVars); if (!alignable) { isAllOk = false; // or error? continue; } uniqueList[alignable] = alignable; ++nParam; } // add Alignables to output for ( std::map<Alignable*,Alignable*>::const_iterator iAli = uniqueList.begin(); iAli != uniqueList.end(); ++iAli) { alignables.push_back((*iAli).first); } edm::LogInfo("Alignment") << "@SUB=PedeReader::read" << nParam << " parameters for " << alignables.size() << " alignables"; return isAllOk && nParam; // nParam == 0: empty or bad file }
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 103 of file PedeReader.cc.
{ while (true) { const int aChar = aStream.get(); if (!aStream.good()) return false; switch(aChar) { case ' ': case '\t': continue; // to next character case '\n': return false; // end of line default: aStream.unget(); aStream >> outValue; if (aStream.fail()) {// not correct type 'T' (!aStream.good() is true also in case of EOF) aStream.clear(); while (aStream.good() && aStream.get() != '\n'); // forward to end of line return false; } else { return true; } } // switch } // while edm::LogError("Alignment") << "@SUB=PedeReader::readIfSameLine" << "Should never come here!"; return false; }
Alignable * PedeReader::setParameter | ( | unsigned int | paramLabel, |
unsigned int | bufLength, | ||
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 134 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 read().
{ Alignable *alignable = myLabels.alignableFromLabel(paramLabel); const unsigned int paramNum = myLabels.paramNumFromLabel(paramLabel); const double cmsToPede = mySteerer.cmsToPedeFactor(paramNum); if (alignable) { AlignmentParameters *params = this->checkAliParams(alignable, setUserVars); MillePedeVariables *userParams = // static cast ensured by previous checkAliParams (setUserVars ? static_cast<MillePedeVariables*>(params->userVariables()) : 0); // if (userParams && userParams->label() != myLabels.alignableLabelFromLabel(paramLabel)) { if (userParams && userParams->label() != myLabels.alignableLabel(alignable)) { edm::LogError("Alignment") << "@SUB=PedeReader::setParameter" << "Label mismatch: paramLabel " << paramLabel << " for alignableLabel " << userParams->label(); } AlgebraicVector parVec(params->parameters()); AlgebraicSymMatrix covMat(params->covariance()); if (userParams) userParams->setAllDefault(paramNum); switch (bufLength) { case 5: // global correlation if (userParams) userParams->globalCor()[paramNum] = buf[4]; // no break case 4: // uncertainty if (userParams) userParams->sigma()[paramNum] = buf[3] / cmsToPede; covMat[paramNum][paramNum] = buf[3]*buf[3] / (cmsToPede*cmsToPede); // no break; case 3: // difference to start value if (userParams) userParams->diffBefore()[paramNum] = buf[2] / cmsToPede; // no break case 2: params->setValid(true); parVec[paramNum] = buf[0] / cmsToPede * mySteerer.parameterSign(); // parameter if (userParams) { userParams->parameter()[paramNum] = parVec[paramNum]; // duplicate in millepede parameters userParams->preSigma()[paramNum] = buf[1]; // presigma given, probably means fixed if (!userParams->isFixed(paramNum)) { userParams->preSigma()[paramNum] /= cmsToPede; if (bufLength == 2) { edm::LogWarning("Alignment") << "@SUB=PedeReader::setParameter" << "Param " << paramLabel << " (from " << typeid(*alignable).name() << ") without result!"; userParams->isValid()[paramNum] = false; params->setValid(false); } } } break; case 0: case 1: default: edm::LogError("Alignment") << "@SUB=PedeReader::setParameter" << "Expect 2 to 5 values, got " << bufLength << " for label " << paramLabel; break; } alignable->setAlignmentParameters(params->clone(parVec, covMat));//transferred mem. responsib. } else { unsigned int lasBeamId = myLabels.lasBeamIdFromLabel(paramLabel); edm::LogError("Alignment") << "@SUB=PedeReader::setParameter" << "No alignable for paramLabel " << paramLabel << ", probably LasBeam with Id " << lasBeamId << ",\nparam " << paramNum << ": " << buf[0] / cmsToPede * mySteerer.parameterSign() << " += " << (bufLength >= 4 ? buf[3] / cmsToPede : -99.); } return alignable; }
const PedeLabelerBase& PedeReader::myLabels [private] |
Definition at line 62 of file PedeReader.h.
Referenced by checkAliParams(), read(), and setParameter().
const unsigned int PedeReader::myMaxNumValPerParam = 5 [static, private] |
Definition at line 65 of file PedeReader.h.
Referenced by read().
std::ifstream PedeReader::myPedeResult [private] |
Definition at line 60 of file PedeReader.h.
Referenced by PedeReader(), and read().
const RunRange PedeReader::myRunRange [private] |
Definition at line 63 of file PedeReader.h.
Referenced by read().
const PedeSteerer& PedeReader::mySteerer [private] |
Definition at line 61 of file PedeReader.h.
Referenced by setParameter().