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 std::string &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 26 of file RPAlignmentCorrectionsMethods.h.

Constructor & Destructor Documentation

RPAlignmentCorrectionsMethods::RPAlignmentCorrectionsMethods ( )
inline

Member Function Documentation

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

Definition at line 88 of file RPAlignmentCorrectionsMethods.cc.

References a, RPAlignmentCorrectionsData::AddRPCorrection(), RPAlignmentCorrectionsData::AddSensorCorrection(), class-composition::children, Exception, i, j, gen::n, and mps_fire::result.

Referenced by RPAlignmentCorrectionsDataSequence::LoadXMLFile().

89 {
91 
92  DOMNodeList *children = root->getChildNodes();
93  for (unsigned int i = 0; i < children->getLength(); i++)
94  {
95  DOMNode *n = children->item(i);
96  if (n->getNodeType() != DOMNode::ELEMENT_NODE)
97  continue;
98 
99  // check node type
100  unsigned char nodeType = 0;
101  if (!strcmp(XMLString::transcode(n->getNodeName()), "det")) nodeType = 1;
102  if (!strcmp(XMLString::transcode(n->getNodeName()), "rp")) nodeType = 2;
103 
104  if (!nodeType)
105  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Unknown node `" << XMLString::transcode(n->getNodeName()) << "'.";
106 
107  // check children
108  if (n->getChildNodes()->getLength() > 0)
109  {
110  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: tag `" <<
111  XMLString::transcode(n->getNodeName()) << "' has " << n->getChildNodes()->getLength() <<
112  " children nodes - they will be all ignored.";
113  }
114 
115  // default values
116  double sh_r = 0., sh_x = 0., sh_y = 0., sh_z = 0., rot_z = 0.;
117  double sh_r_e = 0., sh_x_e = 0., sh_y_e = 0., sh_z_e = 0., rot_z_e = 0.;
118  unsigned int decId = 0;
119  bool idSet = false;
120 
121  // get attributes
122  DOMNamedNodeMap* attr = n->getAttributes();
123  for (unsigned int j = 0; j < attr->getLength(); j++)
124  {
125  DOMNode *a = attr->item(j);
126 
127  //printf("\t%s\n", XMLString::transcode(a->getNodeName()));
128 
129  if (!strcmp(XMLString::transcode(a->getNodeName()), "id"))
130  {
131  decId = atoi(XMLString::transcode(a->getNodeValue()));
132  idSet = true;
133  } else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_r"))
134  sh_r = atof(XMLString::transcode(a->getNodeValue()));
135  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_r_e"))
136  sh_r_e = atof(XMLString::transcode(a->getNodeValue()));
137  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_x"))
138  sh_x = atof(XMLString::transcode(a->getNodeValue()));
139  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_x_e"))
140  sh_x_e = atof(XMLString::transcode(a->getNodeValue()));
141  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_y"))
142  sh_y = atof(XMLString::transcode(a->getNodeValue()));
143  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_y_e"))
144  sh_y_e = atof(XMLString::transcode(a->getNodeValue()));
145  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_z"))
146  sh_z = atof(XMLString::transcode(a->getNodeValue()));
147  else if (!strcmp(XMLString::transcode(a->getNodeName()), "sh_z_e"))
148  sh_z_e = atof(XMLString::transcode(a->getNodeValue()));
149  else if (!strcmp(XMLString::transcode(a->getNodeName()), "rot_z"))
150  rot_z = atof(XMLString::transcode(a->getNodeValue()));
151  else if (!strcmp(XMLString::transcode(a->getNodeName()), "rot_z_e"))
152  rot_z_e = atof(XMLString::transcode(a->getNodeValue()));
153  else
154  edm::LogProblem("RPAlignmentCorrectionsMethods") << ">> RPAlignmentCorrectionsMethods::LoadXMLFile > Warning: unknown attribute `"
155  << XMLString::transcode(a->getNodeName()) << "'.";
156  }
157 
158  // id must be set
159  if (!idSet)
160  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Id not set for tag `" << XMLString::transcode(n->getNodeName()) << "'.";
161 
162  // build alignment
163  RPAlignmentCorrectionData a(sh_r*1E-3, sh_r_e*1E-3, sh_x*1E-3, sh_x_e*1E-3, sh_y*1E-3, sh_y_e*1E-3,
164  sh_z*1E-3, sh_z_e*1E-3, rot_z*1E-3, rot_z_e*1E-3);
165 
166  // add the alignment to the right list
167  if (nodeType == 1)
168  {
169  const unsigned int arm = decId / 1000;
170  const unsigned int st = (decId / 100) % 10;
171  const unsigned int rp = (decId / 10) % 10;
172  const unsigned int det = decId % 10;
173  result.AddSensorCorrection(TotemRPDetId(arm, st, rp, det), a, true);
174  }
175 
176  if (nodeType == 2)
177  {
178  const unsigned int arm = (decId / 100) % 10;
179  const unsigned int st = (decId / 10) % 10;
180  const unsigned int rp = decId % 10;
181  result.AddRPCorrection(TotemRPDetId(arm, st, rp), a, true);
182  }
183  }
184 
185  return result;
186 }
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
int i
Definition: DBlmapReader.cc:9
void AddRPCorrection(unsigned int, const RPAlignmentCorrectionData &, bool sumErrors=true, bool addShR=true, bool addShZ=true, bool addRotZ=true)
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
int j
Definition: DBlmapReader.cc:9
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...
double a
Definition: hdecay.h:121
RPAlignmentCorrectionsData RPAlignmentCorrectionsMethods::GetCorrectionsDataFromFile ( const std::string &  fileName)
static

Definition at line 35 of file RPAlignmentCorrectionsMethods.cc.

References edmIntegrityCheck::d, Exception, python.rootplot.argparse::message, createfilelist::parser, fetchall_from_DQM_v2::release, and AlCaHLTBitMon_QueryRunRegistry::string.

36 {
37  printf(">> RPAlignmentCorrectionsMethods::LoadXMLFile(%s)\n", fileName.c_str());
38 
39  // prepend CMSSW src dir
40  char *cmsswPath = getenv("CMSSW_BASE");
41  size_t start = fileName.find_first_not_of(" ");
42  string fn = fileName.substr(start);
43  if (cmsswPath && fn[0] != '/' && fn.find("./") != 0)
44  fn = string(cmsswPath) + string("/src/") + fn;
45 
46  // load DOM tree first the file
47  try {
48  XMLPlatformUtils::Initialize();
49  }
50  catch (const XMLException& toCatch) {
51  char* message = XMLString::transcode(toCatch.getMessage());
52  throw cms::Exception("RPAlignmentCorrectionsMethods") << "An XMLException caught with message: " << message << ".\n";
53  XMLString::release(&message);
54  }
55 
56  XercesDOMParser* parser = new XercesDOMParser();
57  parser->setValidationScheme(XercesDOMParser::Val_Always);
58  parser->setDoNamespaces(true);
59 
60  try {
61  parser->parse(fn.c_str());
62  }
63  catch (...) {
64  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fn << "' (exception)." << endl;
65  }
66 
67  if (!parser)
68  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fn << "' (parser = NULL)." << endl;
69 
70  DOMDocument* xmlDoc = parser->getDocument();
71 
72  if (!xmlDoc)
73  throw cms::Exception("RPAlignmentCorrectionsMethods") << "Cannot parse file `" << fn << "' (xmlDoc = NULL)." << endl;
74 
75  DOMElement* elementRoot = xmlDoc->getDocumentElement();
76  if (!elementRoot)
77  throw cms::Exception("RPAlignmentCorrectionsMethods") << "File `" << fn << "' is empty." << endl;
78 
80 
81  XMLPlatformUtils::Terminate();
82 
83  return d;
84 }
Definition: start.py:1
static RPAlignmentCorrectionsData GetCorrectionsData(xercesc::DOMNode *)
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
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 197 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.

199 {
200  if (wrSh_r) {
201  WRITE(data.sh_r, 2, 0.1);
202  if (wrErrors) {
203  WRITE(data.sh_r_e, 2, 0.1);
204  }
205  /*
206  fprintf(f, " sh_r=\"%+8.2f\"", data.sh_r()*1E3);
207  if (wrErrors)
208  if (fabs(data.sh_r_e())*1E3 < 0.1)
209  fprintf(f, " sh_r_e=\"%+8.1E\"", data.sh_r_e()*1E3);
210  else
211  fprintf(f, " sh_r_e=\"%+8.2f\"", data.sh_r_e()*1E3);
212  */
213  }
214 
215  if (wrSh_xy) {
216  WRITE(data.sh_x, 2, 0.1);
217  WRITE(data.sh_y, 2, 0.1);
218  if (wrErrors) {
219  WRITE(data.sh_x_e, 2, 0.1);
220  WRITE(data.sh_y_e, 2, 0.1);
221  }
222  /*
223  fprintf(f, " sh_x=\"%+8.2f\" sh_y=\"%+8.2f\"", data.sh_x()*1E3, data.sh_y()*1E3);
224  if (wrErrors) {
225  if (fabs(data.sh_x_e())*1E3 < 0.1)
226  fprintf(f, " sh_x_e=\"%+8.1E\"", data.sh_x_e()*1E3);
227  else
228  fprintf(f, " sh_x_e=\"%+8.2f\"", data.sh_x_e()*1E3);
229 
230  if (fabs(data.sh_y_e())*1E3 < 0.1)
231  fprintf(f, " sh_y_e=\"%+8.1E\"", data.sh_y_e()*1E3);
232  else
233  fprintf(f, " sh_y_e=\"%+8.2f\"", data.sh_y_e()*1E3);
234  }
235  */
236  }
237 
238  // TODO: add the other 2 rotations
239 
240  if (wrRot_z) {
241  WRITE(data.rot_z, 3, 0.01);
242  if (wrErrors) {
243  WRITE(data.rot_z_e, 3, 0.01);
244  }
245  /*
246  fprintf(f, " rot_z=\"%+8.3f\"", data.rot_z()*1E3);
247  if (wrErrors)
248  if (fabs(data.rot_z_e())*1E3 < 0.01)
249  fprintf(f, " rot_z_e=\"%+8.1E\"", data.rot_z_e()*1E3);
250  else
251  fprintf(f, " rot_z_e=\"%+8.3f\"", data.rot_z_e()*1E3);
252  */
253  }
254 
255  if (wrSh_z) {
256  WRITE(data.sh_z, 2, 0.1);
257  if (wrErrors) {
258  WRITE(data.sh_z_e, 2, 0.1);
259  }
260 
261  /*
262  fprintf(f, " sh_z=\"%+8.2f\"", data.sh_z()*1E3);
263  if (wrErrors)
264  if (fabs(data.sh_z_e())*1E3 < 0.1)
265  fprintf(f, " sh_z_e=\"%+8.1E\"", data.sh_z_e()*1E3);
266  else
267  fprintf(f, " sh_z_e=\"%+8.2f\"", data.sh_z_e()*1E3);
268  */
269  }
270 }
#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 297 of file RPAlignmentCorrectionsMethods.cc.

References RPAlignmentCorrectionsData::GetRPMap(), and RPAlignmentCorrectionsData::GetSensorMap().

Referenced by RPAlignmentCorrectionsDataSequence::WriteXMLFile().

299 {
300  bool firstRP = true;
301  unsigned int prevRP = 0;
302  set<unsigned int> writtenRPs;
303 
306 
307  for (RPAlignmentCorrectionsData::mapType::const_iterator it = sensors.begin(); it != sensors.end(); ++it) {
308  // start a RP block
309  unsigned int rp = it->first / 10;
310  if (firstRP || prevRP != rp) {
311  if (!firstRP)
312  fprintf(rf, "\n");
313  firstRP = false;
314 
315  RPAlignmentCorrectionsData::mapType::const_iterator rit = rps.find(rp);
316  if (rit != rps.end()) {
317  fprintf(rf, "\t<rp id=\"%4u\" ", rit->first);
318  WriteXML( rit->second , rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z );
319  fprintf(rf, "/>\n");
320  writtenRPs.insert(rp);
321  } else
322  fprintf(rf, "\t<!-- RP %3u -->\n", rp);
323  }
324  prevRP = rp;
325 
326  // write the correction
327  fprintf(rf, "\t<det id=\"%4u\"", it->first);
328  WriteXML(it->second, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z);
329  fprintf(rf, "/>\n");
330  }
331 
332  // write remaining RPs
333  for (RPAlignmentCorrectionsData::mapType::const_iterator it = rps.begin(); it != rps.end(); ++it) {
334  set<unsigned int>::iterator wit = writtenRPs.find(it->first);
335  if (wit == writtenRPs.end()) {
336  fprintf(rf, "\t<rp id=\"%4u\" ", it->first);
337  WriteXML(it->second, rf, precise, wrErrors, false, wrSh_xy, wrSh_z, wrRot_z);
338  fprintf(rf, "/>\n");
339  }
340  }
341 }
std::map< unsigned int, RPAlignmentCorrectionData > mapType
map: element id -> its alignment correction
const mapType & GetSensorMap() const
returns the map of sensor alignment corrections
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)
void RPAlignmentCorrectionsMethods::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 
)
static

writes corrections into a single XML file

Definition at line 277 of file RPAlignmentCorrectionsMethods.cc.

References Exception.

279 {
280  FILE *rf = fopen(fileName.c_str(), "w");
281  if (!rf)
282  throw cms::Exception("RPAlignmentCorrections::WriteXMLFile") << "Cannot open file `" << fileName
283  << "' to save alignments." << endl;
284 
285  fprintf(rf, "<!--\nShifts in um, rotations in mrad.\n\nFor more details see RPAlignmentCorrections::LoadXMLFile in\n");
286  fprintf(rf, "Alignment/RPDataFormats/src/RPAlignmentCorrectionsSequence.cc\n-->\n\n");
287  fprintf(rf, "<xml DocumentType=\"AlignmentDescription\">\n");
288 
289  WriteXMLBlock(data, rf, precise, wrErrors, wrSh_r, wrSh_xy, wrSh_z, wrRot_z);
290 
291  fprintf(rf, "</xml>\n");
292  fclose(rf);
293 }
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82