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
 
AlignablesetParameter (unsigned int paramLabel, unsigned int bufLength, 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 32 of file PedeReader.h.

Member Typedef Documentation

Definition at line 36 of file PedeReader.h.

Definition at line 37 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 31 of file PedeReader.cc.

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

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

non virtual destructor: do not inherit from this class

Definition at line 42 of file PedeReader.h.

42 {}

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

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

Referenced by setParameter().

208 {
209  // first check that we have parameters
210  AlignmentParameters *params = alignable->alignmentParameters();
211  if (!params) {
212  throw cms::Exception("BadConfig") << "PedeReader::checkAliParams"
213  << "Alignable without parameters.";
214 
215  }
216 
217  // now check that we have user parameters of correct type if requested:
218  if (createUserVars && !dynamic_cast<MillePedeVariables*>(params->userVariables())) {
219  edm::LogInfo("Alignment") << "@SUB=PedeReader::checkAliParams"
220  << "Add user variables for alignable with label "
221  << myLabels.alignableLabel(alignable);
222  params->setUserVariables(new MillePedeVariables(params->size(), myLabels.alignableLabel(alignable)));
223  }
224 
225  return params;
226 }
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:62
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 Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), MillePedeAlignmentAlgorithm::readFromPede(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

51 {
52  alignables.clear();
53  myPedeResult.seekg(0, std::ios::beg); // back to start
54  bool isAllOk = true;
55 
56  std::map<Alignable*,Alignable*> uniqueList; // Probably should use a std::set here...
57 
58  edm::LogInfo("Alignment") << "@SUB=PedeReader::read"
59  << "will read parameters for run range "
60  << myRunRange.first << " - " << myRunRange.second;
61 
62  // loop on lines of text file
63  unsigned int nParam = 0;
64  while (myPedeResult.good() && !myPedeResult.eof()) {
65  // read label
66  unsigned int paramLabel = 0;
67  if (!this->readIfSameLine<unsigned int>(myPedeResult, paramLabel)) continue; // empty line?
68 
69  // read up to maximal number of pede result per parameter
70  float buffer[myMaxNumValPerParam] = {0.};
71  unsigned int bufferPos = 0;
72  for ( ; bufferPos < myMaxNumValPerParam; ++bufferPos) {
73  if (!this->readIfSameLine<float>(myPedeResult, buffer[bufferPos])) break;
74  }
75 
76  const RunRange & runRange = myLabels.runRangeFromLabel(paramLabel);
77  if (!(runRange.first<=myRunRange.first && myRunRange.second<=runRange.second)) continue;
78 
79  Alignable *alignable = this->setParameter(paramLabel, bufferPos, buffer, setUserVars);
80  if (!alignable) {
81  isAllOk = false; // or error?
82  continue;
83  }
84  uniqueList[alignable] = alignable;
85  ++nParam;
86  }
87 
88  // add Alignables to output
89  for ( std::map<Alignable*,Alignable*>::const_iterator iAli = uniqueList.begin();
90  iAli != uniqueList.end(); ++iAli) {
91  alignables.push_back((*iAli).first);
92  }
93 
94  edm::LogInfo("Alignment") << "@SUB=PedeReader::read" << nParam << " parameters for "
95  << alignables.size() << " alignables";
96 
97  return isAllOk && nParam; // nParam == 0: empty or bad file
98 }
virtual const RunRange & runRangeFromLabel(unsigned int label) const
std::ifstream myPedeResult
Definition: PedeReader.h:60
PedeLabelerBase::RunRange RunRange
Definition: PedeReader.h:37
static const unsigned int myMaxNumValPerParam
Definition: PedeReader.h:65
Alignable * setParameter(unsigned int paramLabel, unsigned int bufLength, float *buf, bool setUserVars) const
Definition: PedeReader.cc:134
const PedeLabelerBase & myLabels
Definition: PedeReader.h:62
const RunRange myRunRange
Definition: PedeReader.h:63
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 103 of file PedeReader.cc.

104 {
105 
106  while (true) {
107  const int aChar = aStream.get();
108  if (!aStream.good()) return false;
109 
110  switch(aChar) {
111  case ' ':
112  case '\t':
113  continue; // to next character
114  case '\n':
115  return false; // end of line
116  default:
117  aStream.unget();
118  aStream >> outValue;
119  if (aStream.fail()) {// not correct type 'T' (!aStream.good() is true also in case of EOF)
120  aStream.clear();
121  while (aStream.good() && aStream.get() != '\n'); // forward to end of line
122  return false;
123  } else {
124  return true;
125  }
126  } // switch
127  } // while
128 
129  edm::LogError("Alignment") << "@SUB=PedeReader::readIfSameLine" << "Should never come here!";
130  return false;
131 }
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 electronTools.AddElectronUserIsolation::__call__(), photonTools.AddPhotonUserIsolation::__call__(), metTools.AddTcMET::__call__(), muonTools.AddMuonUserIsolation::__call__(), HiCoreTools.RestrictInputToAOD::__call__(), editorTools.UserCodeTool::__call__(), coreTools.RestrictInputToAOD::__call__(), trackTools.MakeAODTrackCandidates::__call__(), cmsswVersionTools.Run52xOn51xTrigger::__call__(), editorTools.ChangeSource::__call__(), metTools.AddPfMET::__call__(), HiCoreTools.RemoveMCMatching::__call__(), coreTools.RunOnData::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), cmsswVersionTools.PickRelValInputFiles::__call__(), coreTools.RemoveMCMatching::__call__(), HiCoreTools.RemoveAllPATObjectsBut::__call__(), jetTools.RunBTagging::__call__(), HiCoreTools.RemoveSpecificPATObjects::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), coreTools.RemoveAllPATObjectsBut::__call__(), trackTools.MakeTrackCandidates::__call__(), coreTools.RemoveSpecificPATObjects::__call__(), HiCoreTools.RemoveCleaning::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), HiCoreTools.AddCleaning::__call__(), coreTools.RemoveCleaning::__call__(), tauTools.AddTauCollection::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), coreTools.AddCleaning::__call__(), jetTools.AddJetCollection::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), trigTools.RemoveCleaningFromTriggerMatching::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), jetTools.SwitchJetCorrLevels::__call__(), metUncertaintyTools.RunMEtUncertainties::__call__(), and read().

136 {
137  Alignable *alignable = myLabels.alignableFromLabel(paramLabel);
138  const unsigned int paramNum = myLabels.paramNumFromLabel(paramLabel);
139  const double cmsToPede = mySteerer.cmsToPedeFactor(paramNum);
140  if (alignable) {
141  AlignmentParameters *params = this->checkAliParams(alignable, setUserVars);
142  MillePedeVariables *userParams = // static cast ensured by previous checkAliParams
143  (setUserVars ? static_cast<MillePedeVariables*>(params->userVariables()) : 0);
144  // if (userParams && userParams->label() != myLabels.alignableLabelFromLabel(paramLabel)) {
145  if (userParams && userParams->label() != myLabels.alignableLabel(alignable)) {
146  edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
147  << "Label mismatch: paramLabel " << paramLabel
148  << " for alignableLabel " << userParams->label();
149  }
150 
151  AlgebraicVector parVec(params->parameters());
152  AlgebraicSymMatrix covMat(params->covariance());
153 
154  if (userParams) userParams->setAllDefault(paramNum);
155 
156  switch (bufLength) {
157  case 5: // global correlation
158  if (userParams) userParams->globalCor()[paramNum] = buf[4]; // no break
159  case 4: // uncertainty
160  if (userParams) userParams->sigma()[paramNum] = buf[3] / cmsToPede;
161  covMat[paramNum][paramNum] = buf[3]*buf[3] / (cmsToPede*cmsToPede);
162  // no break;
163  case 3: // difference to start value
164  if (userParams) userParams->diffBefore()[paramNum] = buf[2] / cmsToPede;
165  // no break
166  case 2:
167  params->setValid(true);
168  parVec[paramNum] = buf[0] / cmsToPede * mySteerer.parameterSign(); // parameter
169  if (userParams) {
170  userParams->parameter()[paramNum] = parVec[paramNum]; // duplicate in millepede parameters
171  userParams->preSigma()[paramNum] = buf[1]; // presigma given, probably means fixed
172  if (!userParams->isFixed(paramNum)) {
173  userParams->preSigma()[paramNum] /= cmsToPede;
174  if (bufLength == 2) {
175  edm::LogWarning("Alignment") << "@SUB=PedeReader::setParameter"
176  << "Param " << paramLabel << " (from "
177  << typeid(*alignable).name() << ") without result!";
178  userParams->isValid()[paramNum] = false;
179  params->setValid(false);
180  }
181  }
182  }
183  break;
184  case 0:
185  case 1:
186  default:
187  edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
188  << "Expect 2 to 5 values, got " << bufLength
189  << " for label " << paramLabel;
190  break;
191  }
192  alignable->setAlignmentParameters(params->clone(parVec, covMat));//transferred mem. responsib.
193  } else {
194  unsigned int lasBeamId = myLabels.lasBeamIdFromLabel(paramLabel);
195  edm::LogError("Alignment") << "@SUB=PedeReader::setParameter"
196  << "No alignable for paramLabel " << paramLabel
197  << ", probably LasBeam with Id " << lasBeamId
198  << ",\nparam " << paramNum << ": "
199  << buf[0] / cmsToPede * mySteerer.parameterSign()
200  << " += " << (bufLength >= 4 ? buf[3] / cmsToPede : -99.);
201  }
202 
203  return alignable;
204 }
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:207
bool isFixed(unsigned int nParam) const
true if parameter is fixed
const PedeSteerer & mySteerer
Definition: PedeReader.h:61
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:135
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:62
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:63
virtual unsigned int lasBeamIdFromLabel(unsigned int label) const =0

Member Data Documentation

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
staticprivate

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