67 unsigned int derivatives(std::vector<ValuesIndexPair> &outDerivInds,
110 const std::map<unsigned int, TreeStruct> &treeInfo,
111 const char *treeName)
const;
139 saveToDB_(
cfg.getParameter<
bool>(
"saveToDB")),
140 recordNameDBwrite_(
cfg.getParameter<
std::
string>(
"recordNameDBwrite")),
141 outFileName_(
cfg.getParameter<
std::
string>(
"treeFile")),
143 lorentzAngleLabel_(
cfg.getParameter<
std::
string>(
"lorentzAngleLabel")),
144 moduleGroupSelCfg_(
cfg.getParameter<
edm::
ParameterSet>(
"LorentzAngleModuleGroups")) {}
174 if (lorentzAngleRcd.validityInterval().first().eventID().run() >
firstRun &&
180 <<
") in an IOV (" <<
firstRun <<
") that was already cached.\n"
181 <<
"The following record in your input database tag has an IOV "
182 <<
"boundary that does not match your IOV definition:\n"
183 <<
" - SiPixelLorentzAngleRcd '" << lorentzAngleRcd.key().name() <<
"' (since "
184 << lorentzAngleRcd.validityInterval().first().eventID().run() <<
")\n";
198 outDerivInds.clear();
209 const double dZ =
hit.det()->surface().bounds().thickness();
213 const double xDerivative = bFieldLocal.
y() * dZ * -0.5;
214 const double yDerivative = bFieldLocal.x() * dZ * 0.5;
215 if (xDerivative || yDerivative) {
216 const Values derivs{xDerivative, yDerivative};
221 edm::LogWarning(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::derivatives2"
222 <<
"Hit without GeomDet, skip!";
225 return outDerivInds.size();
270 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration"
271 <<
"Created with name " << this->
name() <<
"',\n"
278 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration"
286 std::ostringstream
out;
287 out <<
"Parameter results\n";
288 for (
unsigned int iPar = 0; iPar <
parameters_.size(); ++iPar) {
291 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob" <<
out.str();
293 std::map<unsigned int, TreeStruct> treeInfo;
297 std::vector<const SiPixelLorentzAngle *>
inputs{};
304 (treeName +
"input_" + std::to_string(firstRunOfIOV)).c_str());
306 if (
inputs.back()->getLorentzAngles().empty()) {
307 edm::LogError(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob"
308 <<
"Input Lorentz angle map is empty, skip writing output!";
313 const unsigned int nonZeroParamsOrErrors =
321 for (
const auto &iterIdValue :
inputs[iIOV]->getLorentzAngles()) {
323 const auto detId = iterIdValue.first;
327 auto value = iterIdValue.second + static_cast<float>(param);
333 if (
saveToDB_ || nonZeroParamsOrErrors != 0) {
334 this->
writeTree(&
output, treeInfo, (treeName + Form(
"result_%lld", firstRunOfIOV)).c_str());
342 edm::LogError(
"BadConfig") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob"
343 <<
"No PoolDBOutputService available, but saveToDB true!";
356 const std::string treeName{this->
name() +
"_input_" + std::to_string(resolvedRun)};
367 if (!la.getLorentzAngles().empty() &&
370 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
371 <<
"Different input values from tree " << treeName <<
" in file " << iFile <<
".";
380 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
381 <<
"No input, create an empty one!";
383 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
398 const std::map<unsigned int, TreeStruct> &treeInfo,
399 const char *treeName)
const {
405 edm::LogError(
"BadConfig") <<
"@SUB=SiPixelLorentzAngleCalibration::writeTree"
410 TTree *
tree =
new TTree(treeName, treeName);
414 tree->Branch(
"detId", &
id,
"detId/i");
415 tree->Branch(
"value", &
value,
"value/F");
422 id = iterIdValue->first;
423 value = iterIdValue->second;
425 auto treeStructIter = treeInfo.find(
id);
426 if (treeStructIter != treeInfo.end()) {
427 treeStruct = treeStructIter->second;
443 TFile *
file =
nullptr;
444 FILE *testFile = fopen(
fileName,
"r");
450 TTree *
tree =
nullptr;
458 tree->SetBranchAddress(
"detId", &
id);
461 const Long64_t nEntries =
tree->GetEntries();
462 for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) {
463 tree->GetEntry(iEntry);
467 edm::LogWarning(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::createFromTree"
468 <<
"Could not get TTree '" << treeName <<
"' from file '" <<
fileName
469 << (
file ?
"'." :
"' (file does not exist).");