CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions
RPAlignmentCorrectionsMethods Class Reference

#include <RPAlignmentCorrectionsMethods.h>

Public Member Functions

 RPAlignmentCorrectionsMethods ()
 

Static Public Member Functions

static RPAlignmentCorrectionsData getCorrectionsData (xercesc::DOMNode *)
 
static RPAlignmentCorrectionsData getCorrectionsDataFromFile (const edm::FileInPath &fileName)
 
static void writeXML (const RPAlignmentCorrectionData &data, FILE *f, bool precise, bool wrErrors, bool wrSh_r, bool wrSh_xy, bool wrSh_z, bool wrRot_z)
 
static void writeXMLBlock (const RPAlignmentCorrectionsData &, FILE *, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
 writes a block of corrections into a file More...
 
static void writeXMLFile (const RPAlignmentCorrectionsData &, const std::string &fileName, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
 writes corrections into a single XML file More...
 

Detailed Description

Definition at line 38 of file RPAlignmentCorrectionsMethods.h.

Constructor & Destructor Documentation

RPAlignmentCorrectionsMethods::RPAlignmentCorrectionsMethods ( )
inline

Member Function Documentation

RPAlignmentCorrectionsData RPAlignmentCorrectionsMethods::getCorrectionsData ( xercesc::DOMNode *  )
static

Definition at line 49 of file RPAlignmentCorrectionsMethods.cc.

References a, RPAlignmentCorrectionsData::addRPCorrection(), RPAlignmentCorrectionsData::addSensorCorrection(), class-composition::children, MillePedeFileConverter_cfg::e, Exception, mps_fire::i, mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toDouble(), cms::xerces::toString(), and cms::xerces::toUInt().

Referenced by getCorrectionsDataFromFile(), RPAlignmentCorrectionsDataSequence::loadXMLFile(), and RPAlignmentCorrectionsMethods().

50 {
52 
53  DOMNodeList *children = root->getChildNodes();
54  for ( unsigned int i = 0; i < children->getLength(); i++ ) {
55  DOMNode *node = children->item( i );
56  if ( node->getNodeType() != DOMNode::ELEMENT_NODE ) continue;
57  const std::string node_name = cms::xerces::toString( node->getNodeName() );
58 
59  // check node type
60  unsigned char nodeType = 0;
61  if ( node_name == "det" ) nodeType = 1;
62  else if ( node_name == "rp" ) nodeType = 2;
63 
64  if ( nodeType == 0 )
65  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Unknown node `" << cms::xerces::toString( node->getNodeName() ) << "'.";
66 
67  // check children
68  if ( node->getChildNodes()->getLength() > 0 ) {
69  edm::LogProblem("RPAlignmentCorrectionsMethods") << "LoadXMLFile > Warning: tag `" <<
70  cms::xerces::toString( node->getNodeName() ) << "' has " << node->getChildNodes()->getLength() << " children nodes - they will be all ignored.";
71  }
72 
73  // default values
74  double sh_r = 0., sh_x = 0., sh_y = 0., sh_z = 0., rot_z = 0.;
75  double sh_r_e = 0., sh_x_e = 0., sh_y_e = 0., sh_z_e = 0., rot_z_e = 0.;
76  unsigned int id = 0;
77  bool idSet = false;
78 
79  // get attributes
80  DOMNamedNodeMap* attr = node->getAttributes();
81  for ( unsigned int j = 0; j < attr->getLength(); j++ ) {
82  DOMNode *a = attr->item( j );
83  const std::string node_name = cms::xerces::toString( a->getNodeName() );
84 
85  if ( node_name == "id" ) {
86  id = cms::xerces::toUInt( a->getNodeValue() );
87  idSet = true;
88  }
89  else if ( node_name == "sh_r" ) sh_r = cms::xerces::toDouble( a->getNodeValue() );
90  else if ( node_name == "sh_r_e" ) sh_r_e = cms::xerces::toDouble( a->getNodeValue() );
91  else if ( node_name == "sh_x" ) sh_x = cms::xerces::toDouble( a->getNodeValue() );
92  else if ( node_name == "sh_x_e" ) sh_x_e = cms::xerces::toDouble( a->getNodeValue() );
93  else if ( node_name == "sh_y" ) sh_y = cms::xerces::toDouble( a->getNodeValue() );
94  else if ( node_name == "sh_y_e" ) sh_y_e = cms::xerces::toDouble( a->getNodeValue() );
95  else if ( node_name == "sh_z" ) sh_z = cms::xerces::toDouble( a->getNodeValue() );
96  else if ( node_name == "sh_z_e" ) sh_z_e = cms::xerces::toDouble( a->getNodeValue() );
97  else if ( node_name == "rot_z" ) rot_z = cms::xerces::toDouble( a->getNodeValue() );
98  else if ( node_name == "rot_z_e" ) rot_z_e = cms::xerces::toDouble( a->getNodeValue() );
99  else
100  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: unknown attribute `"
101  << cms::xerces::toString( a->getNodeName() ) << "'.";
102  }
103 
104  // id must be set
105  if ( !idSet )
106  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Id not set for tag `" << cms::xerces::toString( node->getNodeName() ) << "'.";
107 
108  // build alignment
109  const RPAlignmentCorrectionData align_corr(
110  sh_r*1e-3, sh_r_e*1e-3,
111  sh_x*1e-3, sh_x_e*1e-3,
112  sh_y*1e-3, sh_y_e*1e-3,
113  sh_z*1e-3, sh_z_e*1e-3,
114  rot_z*1e-3, rot_z_e*1e-3
115  );
116 
117  // add the alignment to the right list
118  if ( nodeType == 1 ) result.addSensorCorrection( id, align_corr, true );
119  if ( nodeType == 2 ) result.addRPCorrection( id, align_corr, true );
120  }
121 
122  return result;
123 }
void addRPCorrection(unsigned int, const RPAlignmentCorrectionData &, bool sumErrors=true, bool addShR=true, bool addShZ=true, bool addRotZ=true)
double toDouble(XMLCh const *toTranscode)
std::string toString(XMLCh const *toTranscode)
unsigned int toUInt(XMLCh const *toTranscode)
Alignment correction or result of alignment procedure for a single RP sensor. Within the geometry des...
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
void addSensorCorrection(unsigned int, const RPAlignmentCorrectionData &, bool sumErrors=true, bool addShR=true, bool addShZ=true, bool addRotZ=true)
adds (merges) a RP correction on top of the current value
double a
Definition: hdecay.h:121
RPAlignmentCorrectionsData RPAlignmentCorrectionsMethods::getCorrectionsDataFromFile ( const edm::FileInPath fileName)
static

Definition at line 14 of file RPAlignmentCorrectionsMethods.cc.

References Exception, edm::FileInPath::fullPath(), getCorrectionsData(), and createfilelist::parser.

Referenced by RPAlignmentCorrectionsMethods().

15 {
16  edm::LogInfo("RPAlignmentCorrectionsMethods")
17  << "LoadXMLFile(" << fileName << ")";
18 
19  // load DOM tree first the file
20  XMLPlatformUtils::Initialize();
21 
22  auto parser = std::make_unique<XercesDOMParser>();
23  parser->setValidationScheme( XercesDOMParser::Val_Always );
24  parser->setDoNamespaces( true );
25  parser->parse( fileName.fullPath().c_str() );
26 
27  if ( !parser )
28  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fileName.fullPath() << "' (parser = NULL).";
29 
30  DOMDocument* xmlDoc = parser->getDocument();
31 
32  if ( !xmlDoc )
33  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fileName.fullPath() << "' (xmlDoc = NULL).";
34 
35  DOMElement* elementRoot = xmlDoc->getDocumentElement();
36  if ( !elementRoot )
37  throw cms::Exception("RPAlignmentCorrectionsMethods") << "File `" << fileName.fullPath() << "' is empty.";
38 
39  RPAlignmentCorrectionsData corr_data = getCorrectionsData( elementRoot );
40 
41  XMLPlatformUtils::Terminate();
42 
43  return corr_data;
44 }
static RPAlignmentCorrectionsData getCorrectionsData(xercesc::DOMNode *)
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
std::string fullPath() const
Definition: FileInPath.cc:197
void RPAlignmentCorrectionsMethods::writeXML ( const RPAlignmentCorrectionData data,
FILE *  f,
bool  precise,
bool  wrErrors,
bool  wrSh_r,
bool  wrSh_xy,
bool  wrSh_z,
bool  wrRot_z 
)
static

Definition at line 139 of file RPAlignmentCorrectionsMethods.cc.

References RPAlignmentCorrectionData::rot_z(), RPAlignmentCorrectionData::rot_z_e(), RPAlignmentCorrectionData::sh_r(), RPAlignmentCorrectionData::sh_r_e(), RPAlignmentCorrectionData::sh_x(), RPAlignmentCorrectionData::sh_x_e(), RPAlignmentCorrectionData::sh_y(), RPAlignmentCorrectionData::sh_y_e(), RPAlignmentCorrectionData::sh_z(), RPAlignmentCorrectionData::sh_z_e(), and WRITE.

Referenced by RPAlignmentCorrectionsMethods(), and writeXMLBlock().

141 {
142  if ( wrSh_r ) {
143  WRITE( data.sh_r, 2, 0.1 );
144  if (wrErrors) {
145  WRITE( data.sh_r_e, 2, 0.1 );
146  }
147  /*
148  fprintf(f, " sh_r=\"%+8.2f\"", data.sh_r()*1E3);
149  if (wrErrors)
150  if (fabs(data.sh_r_e())*1E3 < 0.1)
151  fprintf(f, " sh_r_e=\"%+8.1E\"", data.sh_r_e()*1E3);
152  else
153  fprintf(f, " sh_r_e=\"%+8.2f\"", data.sh_r_e()*1E3);
154  */
155  }
156 
157  if ( wrSh_xy ) {
158  WRITE( data.sh_x, 2, 0.1 );
159  WRITE( data.sh_y, 2, 0.1 );
160  if ( wrErrors ) {
161  WRITE( data.sh_x_e, 2, 0.1 );
162  WRITE( data.sh_y_e, 2, 0.1 );
163  }
164  /*
165  fprintf(f, " sh_x=\"%+8.2f\" sh_y=\"%+8.2f\"", data.sh_x()*1E3, data.sh_y()*1E3);
166  if (wrErrors) {
167  if (fabs(data.sh_x_e())*1E3 < 0.1)
168  fprintf(f, " sh_x_e=\"%+8.1E\"", data.sh_x_e()*1E3);
169  else
170  fprintf(f, " sh_x_e=\"%+8.2f\"", data.sh_x_e()*1E3);
171 
172  if (fabs(data.sh_y_e())*1E3 < 0.1)
173  fprintf(f, " sh_y_e=\"%+8.1E\"", data.sh_y_e()*1E3);
174  else
175  fprintf(f, " sh_y_e=\"%+8.2f\"", data.sh_y_e()*1E3);
176  }
177  */
178  }
179 
180  // TODO: add the other 2 rotations
181 
182  if ( wrRot_z ) {
183  WRITE( data.rot_z, 3, 0.01 );
184  if ( wrErrors ) {
185  WRITE( data.rot_z_e, 3, 0.01 );
186  }
187  /*
188  fprintf(f, " rot_z=\"%+8.3f\"", data.rot_z()*1E3);
189  if (wrErrors)
190  if (fabs(data.rot_z_e())*1E3 < 0.01)
191  fprintf(f, " rot_z_e=\"%+8.1E\"", data.rot_z_e()*1E3);
192  else
193  fprintf(f, " rot_z_e=\"%+8.3f\"", data.rot_z_e()*1E3);
194  */
195  }
196 
197  if ( wrSh_z ) {
198  WRITE( data.sh_z, 2, 0.1 );
199  if ( wrErrors ) {
200  WRITE( data.sh_z_e, 2, 0.1 );
201  }
202 
203  /*
204  fprintf(f, " sh_z=\"%+8.2f\"", data.sh_z()*1E3);
205  if (wrErrors)
206  if (fabs(data.sh_z_e())*1E3 < 0.1)
207  fprintf(f, " sh_z_e=\"%+8.1E\"", data.sh_z_e()*1E3);
208  else
209  fprintf(f, " sh_z_e=\"%+8.2f\"", data.sh_z_e()*1E3);
210  */
211  }
212 }
#define WRITE(q, dig, lim)
void RPAlignmentCorrectionsMethods::writeXMLBlock ( const RPAlignmentCorrectionsData data,
FILE *  rf,
bool  precise = false,
bool  wrErrors = true,
bool  wrSh_r = true,
bool  wrSh_xy = true,
bool  wrSh_z = true,
bool  wrRot_z = true 
)
static

writes a block of corrections into a file

Definition at line 241 of file RPAlignmentCorrectionsMethods.cc.

References RPAlignmentCorrectionsData::getRPMap(), RPAlignmentCorrectionsData::getSensorMap(), and writeXML().

Referenced by RPAlignmentCorrectionsMethods(), writeXMLFile(), and RPAlignmentCorrectionsDataSequence::writeXMLFile().

243 {
244  bool firstRP = true;
245  unsigned int prevRP = 0;
246  std::set<unsigned int> writtenRPs;
247 
250 
251  for ( const auto& it : sensors ) {
252  // start a RP block
253  unsigned int rp = it.first / 10;
254  if ( firstRP || prevRP != rp ) {
255  if ( !firstRP ) fprintf( rf, "\n" );
256  firstRP = false;
257 
258  const auto& rit = rps.find( rp );
259  if ( rit != rps.end() ) {
260  fprintf( rf, "\t<rp id=\"%4u\" ", rit->first );
261  writeXML( rit->second , rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z );
262  fprintf( rf, "/>\n" );
263  writtenRPs.insert( rp );
264  }
265  else fprintf( rf, "\t<!-- RP %3u -->\n", rp );
266  }
267  prevRP = rp;
268 
269  // write the correction
270  fprintf( rf, "\t<det id=\"%4u\"", it.first );
271  writeXML( it.second, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z );
272  fprintf( rf, "/>\n" );
273  }
274 
275  // write remaining RPs
276  for ( const auto& it : rps ) {
277  const auto& wit = writtenRPs.find( it.first );
278  if ( wit == writtenRPs.end() ) {
279  fprintf( rf, "\t<rp id=\"%4u\" ", it.first );
280  writeXML( it.second, rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z );
281  fprintf( rf, "/>\n" );
282  }
283  }
284 }
std::map< unsigned int, RPAlignmentCorrectionData > mapType
map: element id -> its alignment correction
const mapType & getRPMap() const
returns the map of RP alignment corrections
static void writeXML(const RPAlignmentCorrectionData &data, FILE *f, bool precise, bool wrErrors, bool wrSh_r, bool wrSh_xy, bool wrSh_z, bool wrRot_z)
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
void RPAlignmentCorrectionsMethods::writeXMLFile ( const RPAlignmentCorrectionsData data,
const std::string &  fileName,
bool  precise = false,
bool  wrErrors = true,
bool  wrSh_r = true,
bool  wrSh_xy = true,
bool  wrSh_z = true,
bool  wrRot_z = true 
)
static

writes corrections into a single XML file

Definition at line 221 of file RPAlignmentCorrectionsMethods.cc.

References Exception, and writeXMLBlock().

Referenced by RPAlignmentCorrectionsMethods().

223 {
224  FILE* rf = fopen( fileName.c_str(), "w" );
225  if ( !rf )
226  throw cms::Exception("RPAlignmentCorrections::writeXMLFile") << "Cannot open file `" << fileName << "' to save alignments.";
227 
228  fprintf( rf, "<!--\nShifts in um, rotations in mrad.\n\nFor more details see RPAlignmentCorrections::LoadXMLFile in\n" );
229  fprintf( rf, "Alignment/RPDataFormats/src/RPAlignmentCorrectionsSequence.cc\n-->\n\n" );
230  fprintf( rf, "<xml DocumentType=\"AlignmentDescription\">\n" );
231 
232  writeXMLBlock( data, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z );
233 
234  fprintf( rf, "</xml>\n" );
235  fclose( rf );
236 }
static void writeXMLBlock(const RPAlignmentCorrectionsData &, FILE *, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
writes a block of corrections into a file