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();
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 std::ifstream resFile;
100 resFile.open(millePedeResFile_.c_str());
102 if (resFile.is_open()) {
103 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede result-file";
106 getline(resFile, line);
108 while (getline(resFile, line)) {
109 std::istringstream iss(line);
111 std::vector<std::string> tokens;
113 while (iss >> token) {
114 tokens.push_back(token);
117 if (tokens.size() > 4 ) {
119 auto alignableLabel = std::stoul(tokens[0]);
120 auto alignableIndex = alignableLabel % 10 - 1;
121 const auto alignable = pedeLabeler_->alignableFromLabel(alignableLabel);
123 double ObsMove = std::stof(tokens[3]) * multiplier_[alignableIndex];
124 double ObsErr = std::stof(tokens[4]) * multiplier_[alignableIndex];
126 auto det = getHLS(alignable);
127 int detIndex =
static_cast<int>(det);
131 if (det != PclHLS::NotInPCL) {
134 Xobs_[detIndex] = ObsMove;
135 XobsErr_[detIndex] = ObsErr;
138 Yobs_[detIndex] = ObsMove;
139 YobsErr_[detIndex] = ObsErr;
142 Zobs_[detIndex] = ObsMove;
143 ZobsErr_[detIndex] = ObsErr;
146 tXobs_[detIndex] = ObsMove;
147 tXobsErr_[detIndex] = ObsErr;
150 tYobs_[detIndex] = ObsMove;
151 tYobsErr_[detIndex] = ObsErr;
154 tZobs_[detIndex] = ObsMove;
155 tZobsErr_[detIndex] = ObsErr;
158 edm::LogError(
"MillePedeFileReader") <<
"Currently not able to handle DOF " << coord
166 edm::LogVerbatim(
"MillePedeFileReader")<<
" alignableLabel: "<< alignableLabel <<
" with alignableIndex "<<alignableIndex <<
" detIndex"<< detIndex <<
"\n" 167 <<
" i.e. detLabel: "<< detLabel <<
" ("<< coord <<
")\n" 168 <<
" has movement: "<< ObsMove <<
" +/- "<< ObsErr <<
"\n" 169 <<
" cutoff (cutoffs_["<< detLabel <<
"]["<< coord <<
"]): "<< cutoffs_[detLabel][alignableIndex] <<
"\n" 170 <<
" significance (significances_["<< detLabel <<
"]["<< coord <<
"]): "<< significances_[detLabel][alignableIndex] <<
"\n" 171 <<
" error thresolds (errors_["<< detLabel <<
"]["<< coord <<
"]): "<< errors_[detLabel][alignableIndex] <<
"\n" 172 <<
" max movement (thresholds_["<< detLabel <<
"]["<< coord <<
"]): "<< thresholds_[detLabel][alignableIndex] <<
"\n" 173 <<
"============="<< std::endl;
175 if (
std::abs(ObsMove) > thresholds_[detLabel][alignableIndex]) {
177 <<
" Exceeding maximum thresholds for movement: "<<
std::abs(ObsMove)<<
" for"<< detLabel <<
"("<<coord<<
")" ;
181 }
else if (
std::abs(ObsMove) > cutoffs_[detLabel][alignableIndex]) {
183 if (
std::abs(ObsErr) > errors_[detLabel][alignableIndex]) {
185 <<
" Exceeding maximum thresholds for error: "<<
std::abs(ObsErr)<<
" for"<< detLabel <<
"("<<coord<<
")" ;
189 if (
std::abs(ObsMove/ObsErr) < significances_[detLabel][alignableIndex]) {
194 edm::LogInfo(
"MillePedeFileReader")<<
"This correction: "<<ObsMove<<
"+/-" <<ObsErr<<
" for "<< detLabel <<
"("<<coord<<
") will trigger a new Tracker Alignment payload!";
199 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede result-file.";
209 if (!alignable)
return PclHLS::NotInPCL;
211 const auto& tns = pedeLabeler_->alignableTracker()->trackerNameSpace();
215 switch (tns.tpb().halfBarrelNumber(alignable->
id())) {
216 case 1:
return PclHLS::TPBHalfBarrelXminus;
217 case 2:
return PclHLS::TPBHalfBarrelXplus;
220 <<
"@SUB=MillePedeFileReader::getHLS\n" 221 <<
"Found a pixel half-barrel number that should not exist: " 222 << tns.tpb().halfBarrelNumber(alignable->
id());
225 switch (tns.tpe().endcapNumber(alignable->
id())) {
227 switch (tns.tpe().halfCylinderNumber(alignable->
id())) {
228 case 1:
return PclHLS::TPEHalfCylinderXminusZminus;
229 case 2:
return PclHLS::TPEHalfCylinderXplusZminus;
232 <<
"@SUB=MillePedeFileReader::getHLS\n" 233 <<
"Found a pixel half-cylinder number that should not exist: " 234 << tns.tpe().halfCylinderNumber(alignable->
id());
237 switch (tns.tpe().halfCylinderNumber(alignable->
id())) {
238 case 1:
return PclHLS::TPEHalfCylinderXminusZplus;
239 case 2:
return PclHLS::TPEHalfCylinderXplusZplus;
242 <<
"@SUB=MillePedeFileReader::getHLS\n" 243 <<
"Found a pixel half-cylinder number that should not exist: " 244 << tns.tpe().halfCylinderNumber(alignable->
id());
248 <<
"@SUB=MillePedeFileReader::getHLS\n" 249 <<
"Found a pixel endcap number that should not exist: " 250 << tns.tpe().endcapNumber(alignable->
id());
252 default:
return PclHLS::NotInPCL;
268 <<
"@SUB=MillePedeFileReader::getStringFromHLS\n" 269 <<
"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_