21 const std::shared_ptr<const PedeLabelerBase>&
pedeLabeler,
22 const std::shared_ptr<const AlignPCLThresholds>& theThresholds) :
23 pedeLabeler_(pedeLabeler),
24 theThresholds_(theThresholds),
25 millePedeLogFile_(config.getParameter<
std::
string>(
"millePedeLogFile")),
26 millePedeResFile_(config.getParameter<
std::
string>(
"millePedeResFile"))
32 readMillePedeLogFile();
33 readMillePedeResultFile();
38 return (updateDB_&&!vetoUpdateDB_);
51 logFile.open(millePedeLogFile_.c_str());
53 if (logFile.is_open()) {
54 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede log-file";
57 while (getline(logFile, line)) {
60 if (line.find(Nrec_string) != std::string::npos) {
61 std::istringstream iss(line);
63 iss >> trash >> trash >> Nrec_;
65 if (Nrec_ < theThresholds_->getNrecords() ) {
66 edm::LogInfo(
"MillePedeFileReader")<<
"Number of records used "<<theThresholds_->getNrecords()<<std::endl;
73 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede log-file.";
85 std::map<std::string,std::array<float, 6 > > cutoffs_;
86 std::map<std::string,std::array<float, 6 > > significances_;
87 std::map<std::string,std::array<float, 6 > > thresholds_;
88 std::map<std::string,std::array<float, 6 > > errors_;
90 std::vector<std::string> alignables_ = theThresholds_->getAlignableList();
91 for (
auto &ali : alignables_){
92 cutoffs_[ali] = theThresholds_->getCut(ali);
93 significances_[ali] = theThresholds_->getSigCut(ali);
94 thresholds_[ali] = theThresholds_->getMaxMoveCut(ali);
95 errors_[ali] = theThresholds_->getMaxErrorCut(ali);
99 vetoUpdateDB_ =
false;
100 std::ifstream resFile;
101 resFile.open(millePedeResFile_.c_str());
103 if (resFile.is_open()) {
104 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede result-file";
107 getline(resFile, line);
109 while (getline(resFile, line)) {
110 std::istringstream iss(line);
112 std::vector<std::string> tokens;
114 while (iss >> token) {
115 tokens.push_back(token);
118 if (tokens.size() > 4 ) {
120 auto alignableLabel = std::stoul(tokens[0]);
121 auto alignableIndex = alignableLabel % 10 - 1;
122 const auto alignable = pedeLabeler_->alignableFromLabel(alignableLabel);
124 double ObsMove = std::stof(tokens[3]) * multiplier_[alignableIndex];
125 double ObsErr = std::stof(tokens[4]) * multiplier_[alignableIndex];
127 auto det = getHLS(alignable);
128 int detIndex =
static_cast<int>(det);
132 if (det != PclHLS::NotInPCL) {
135 Xobs_[detIndex] = ObsMove;
136 XobsErr_[detIndex] = ObsErr;
139 Yobs_[detIndex] = ObsMove;
140 YobsErr_[detIndex] = ObsErr;
143 Zobs_[detIndex] = ObsMove;
144 ZobsErr_[detIndex] = ObsErr;
147 tXobs_[detIndex] = ObsMove;
148 tXobsErr_[detIndex] = ObsErr;
151 tYobs_[detIndex] = ObsMove;
152 tYobsErr_[detIndex] = ObsErr;
155 tZobs_[detIndex] = ObsMove;
156 tZobsErr_[detIndex] = ObsErr;
159 edm::LogError(
"MillePedeFileReader") <<
"Currently not able to handle DOF " << coord
167 edm::LogVerbatim(
"MillePedeFileReader")<<
" alignableLabel: "<< alignableLabel <<
" with alignableIndex "<<alignableIndex <<
" detIndex"<< detIndex <<
"\n" 168 <<
" i.e. detLabel: "<< detLabel <<
" ("<< coord <<
")\n" 169 <<
" has movement: "<< ObsMove <<
" +/- "<< ObsErr <<
"\n" 170 <<
" cutoff (cutoffs_["<< detLabel <<
"]["<< coord <<
"]): "<< cutoffs_[detLabel][alignableIndex] <<
"\n" 171 <<
" significance (significances_["<< detLabel <<
"]["<< coord <<
"]): "<< significances_[detLabel][alignableIndex] <<
"\n" 172 <<
" error thresolds (errors_["<< detLabel <<
"]["<< coord <<
"]): "<< errors_[detLabel][alignableIndex] <<
"\n" 173 <<
" max movement (thresholds_["<< detLabel <<
"]["<< coord <<
"]): "<< thresholds_[detLabel][alignableIndex] <<
"\n" 174 <<
"============="<< std::endl;
176 if (
std::abs(ObsMove) > thresholds_[detLabel][alignableIndex]) {
178 <<
" Exceeding maximum thresholds for movement: "<<
std::abs(ObsMove)<<
" for"<< detLabel <<
"("<<coord<<
")" ;
179 vetoUpdateDB_ =
true;
182 }
else if (
std::abs(ObsMove) > cutoffs_[detLabel][alignableIndex]) {
184 if (
std::abs(ObsErr) > errors_[detLabel][alignableIndex]) {
186 <<
" Exceeding maximum thresholds for error: "<<
std::abs(ObsErr)<<
" for"<< detLabel <<
"("<<coord<<
")" ;
187 vetoUpdateDB_ =
true;
190 if (
std::abs(ObsMove/ObsErr) < significances_[detLabel][alignableIndex]) {
195 edm::LogInfo(
"MillePedeFileReader")<<
"This correction: "<<ObsMove<<
"+/-" <<ObsErr<<
" for "<< detLabel <<
"("<<coord<<
") will trigger a new Tracker Alignment payload!";
200 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede result-file.";
210 if (!alignable)
return PclHLS::NotInPCL;
212 const auto& tns = pedeLabeler_->alignableTracker()->trackerNameSpace();
216 switch (tns.tpb().halfBarrelNumber(alignable->
id())) {
217 case 1:
return PclHLS::TPBHalfBarrelXminus;
218 case 2:
return PclHLS::TPBHalfBarrelXplus;
221 <<
"@SUB=MillePedeFileReader::getHLS\n" 222 <<
"Found a pixel half-barrel number that should not exist: " 223 << tns.tpb().halfBarrelNumber(alignable->
id());
226 switch (tns.tpe().endcapNumber(alignable->
id())) {
228 switch (tns.tpe().halfCylinderNumber(alignable->
id())) {
229 case 1:
return PclHLS::TPEHalfCylinderXminusZminus;
230 case 2:
return PclHLS::TPEHalfCylinderXplusZminus;
233 <<
"@SUB=MillePedeFileReader::getHLS\n" 234 <<
"Found a pixel half-cylinder number that should not exist: " 235 << tns.tpe().halfCylinderNumber(alignable->
id());
238 switch (tns.tpe().halfCylinderNumber(alignable->
id())) {
239 case 1:
return PclHLS::TPEHalfCylinderXminusZplus;
240 case 2:
return PclHLS::TPEHalfCylinderXplusZplus;
243 <<
"@SUB=MillePedeFileReader::getHLS\n" 244 <<
"Found a pixel half-cylinder number that should not exist: " 245 << tns.tpe().halfCylinderNumber(alignable->
id());
249 <<
"@SUB=MillePedeFileReader::getHLS\n" 250 <<
"Found a pixel endcap number that should not exist: " 251 << tns.tpe().endcapNumber(alignable->
id());
253 default:
return PclHLS::NotInPCL;
269 <<
"@SUB=MillePedeFileReader::getStringFromHLS\n" 270 <<
"Found an alignable structure not possible to map in the default AlignPCLThresholds partitions";
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
PclHLS getHLS(const Alignable *)
void readMillePedeLogFile()
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void readMillePedeResultFile()
Abs< T >::type abs(const T &t)
MillePedeFileReader(const edm::ParameterSet &, const std::shared_ptr< const PedeLabelerBase > &, const std::shared_ptr< const AlignPCLThresholds > &)
std::string getStringFromHLS(PclHLS HLS)
static std::array< double, 6 > multiplier_