File indexing completed on 2024-04-06 11:55:59
0001
0002
0003
0004
0005
0006
0007 #include <map>
0008 #include <fstream>
0009 #include <iostream>
0010 #include <iomanip>
0011
0012 #include "Alignment/CocoaFit/interface/FittedEntriesManager.h"
0013 #include "Alignment/CocoaModel/interface/Model.h"
0014 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0015 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0016
0017 FittedEntriesManager* FittedEntriesManager::instance = nullptr;
0018
0019
0020
0021
0022 FittedEntriesManager* FittedEntriesManager::getInstance() {
0023 if (!instance) {
0024 instance = new FittedEntriesManager;
0025 }
0026 return instance;
0027 }
0028
0029
0030
0031
0032 void FittedEntriesManager::AddFittedEntriesSet(FittedEntriesSet* fents) { theFittedEntriesSets.push_back(fents); }
0033
0034
0035
0036
0037
0038 void FittedEntriesManager::MakeHistos() {
0039
0040
0041
0042
0043
0044
0045 if (ALIUtils::debug >= 5)
0046 std::cout << "No sets2 " << theFittedEntriesSets.size() << " No ent "
0047 << ((*(theFittedEntriesSets.begin()))->FittedEntries()).size() << std::endl;
0048 std::ofstream fout;
0049 std::ofstream fout2;
0050 fout.open("fittedEntries.out");
0051 fout2.open("longFittedEntries.out");
0052
0053 ALIUtils::dumpDimensions(fout);
0054 ALIUtils::dumpDimensions(fout2);
0055
0056 AddFittedEntriesSet(new FittedEntriesSet(theFittedEntriesSets));
0057
0058
0059 std::vector<FittedEntriesSet*>::const_iterator vfescite;
0060 std::vector<FittedEntry*>::const_iterator vfecite;
0061 ALIint jj = 1;
0062 for (vfescite = theFittedEntriesSets.begin(); vfescite != theFittedEntriesSets.end(); ++vfescite) {
0063
0064 if (vfescite == theFittedEntriesSets.begin()) {
0065
0066 fout << " ";
0067 ALIint ii = 0;
0068 for (vfecite = ((*vfescite)->FittedEntries()).begin(); vfecite != ((*vfescite)->FittedEntries()).end();
0069 ++vfecite) {
0070 ALIstring filename = createFileName((*vfecite)->getOptOName(), (*vfecite)->getEntryName());
0071 fout << ii << ": " << std::setw(13) << filename << " ";
0072 ;
0073 if (ALIUtils::debug >= 3)
0074 std::cout << ii << ": " << std::setw(13) << filename << " = " << (*vfecite)->getName() << std::endl;
0075 if (ALIUtils::debug >= 3)
0076 std::cout << filename << " ";
0077 if (ALIUtils::debug >= 3)
0078 std::cout << "OPENING FITTED ENTRIES file " << filename << std::endl;
0079 ii++;
0080 }
0081
0082 fout << std::endl;
0083 if (ALIUtils::debug >= 3)
0084 std::cout << std::endl;
0085 }
0086
0087 fout << jj << " ";
0088 fout2 << jj << " ";
0089
0090 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0091 if (gomgr->GlobalOptions()["DumpDateInFittedEntries"] >= 1) {
0092 fout << (*vfescite)->getDate() << " " << (*vfescite)->getTime() << " ";
0093 fout2 << (*vfescite)->getDate() << " " << (*vfescite)->getTime() << " ";
0094 }
0095
0096
0097 for (vfecite = ((*vfescite)->FittedEntries()).begin(); vfecite != ((*vfescite)->FittedEntries()).end(); ++vfecite) {
0098
0099
0100 fout << std::setprecision(8) << std::setw(10) << (*vfecite)->getValue() << " " << (*vfecite)->getSigma() << " ";
0101
0102
0103 if (ALIUtils::debug >= 3)
0104 std::cout << " FITTEDENTRY:" << std::setprecision(5) << std::setw(8) << (*vfecite)->getValue() << " +- "
0105 << (*vfecite)->getSigma() << std::endl;
0106
0107 ALIstring filename = createFileName((*vfecite)->getOptOName(), (*vfecite)->getEntryName());
0108 fout2 << std::setprecision(8) << std::setw(10) << filename << " " << (*vfecite)->getValue() << " "
0109 << (*vfecite)->getSigma() << " ";
0110
0111 }
0112
0113 fout << std::endl;
0114 fout2 << std::endl;
0115 if (ALIUtils::debug >= 3)
0116 std::cout << std::endl;
0117 jj++;
0118 }
0119 fout.close();
0120 fout2.close();
0121
0122 GetDifferentBetweenLasers();
0123 }
0124
0125 #include "Alignment/CocoaModel/interface/LightRay.h"
0126 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0127
0128
0129 void FittedEntriesManager::GetDifferentBetweenLasers() {
0130 std::vector<OpticalObject*> optoList = Model::OptOList();
0131 std::vector<OpticalObject*>::const_iterator ite;
0132 std::map<ALIstring, LightRay*> lrays;
0133
0134 for (ite = optoList.begin(); ite != optoList.end(); ++ite) {
0135 if ((*ite)->type() == "laser") {
0136 LightRay* lightray = new LightRay;
0137 lightray->startLightRay(*ite);
0138 lrays[(*ite)->parent()->name()] = lightray;
0139 }
0140 }
0141
0142 std::map<ALIstring, LightRay*>::const_iterator lite1, lite2;
0143 for (lite1 = lrays.begin(); lite1 != lrays.end(); ++lite1) {
0144 lite2 = lite1;
0145 ++lite2;
0146 for (; lite2 != lrays.end(); ++lite2) {
0147 if (lite1 == lite2)
0148 continue;
0149 CLHEP::Hep3Vector dirdiff = ((*lite1).second->direction() - (*lite2).second->direction());
0150 if (ALIUtils::debug >= 0) {
0151 std::cout << "LASER DIFF " << (*lite1).first << " & " << (*lite2).first << " " << dirdiff.mag() * 180. / M_PI
0152 << "o " << dirdiff.mag() << " rad " << dirdiff << std::endl;
0153
0154 (*lite1).second->dumpData(ALIstring(" laser ") + (*lite1).first);
0155 (*lite2).second->dumpData(ALIstring(" laser ") + (*lite2).first);
0156 }
0157 }
0158 }
0159 }
0160
0161
0162
0163
0164 ALIstring FittedEntriesManager::createFileName(const ALIstring& optoName, const ALIstring& entryName) {
0165
0166 ALIstring filename;
0167
0168
0169
0170
0171
0172
0173
0174
0175 filename = optoName.substr(2, optoName.size());
0176 ALIint slash = -1;
0177 for (;;) {
0178 slash = filename.find('/', slash + 1);
0179 if (slash == -1)
0180 break;
0181 filename[slash] = '.';
0182 }
0183
0184
0185 ALIint space = entryName.rfind(' ');
0186 filename.append(".");
0187 ALIstring en = entryName;
0188 if (space != -1)
0189 en[space] = '_';
0190
0191
0192
0193 filename.append(en);
0194 if (ALIUtils::debug >= 3)
0195 std::cout << "filename " << filename << std::endl;
0196
0197 return filename;
0198 }
0199
0200
0201
0202
0203
0204 void FittedEntriesManager::dumpEntriesSubstraction(std::ofstream& fout,
0205 FittedEntriesSet& fes,
0206 ALIint order1,
0207 ALIint order2) {
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222 FittedEntry* fe1 = *((fes.FittedEntries()).begin() + order1);
0223 FittedEntry* fe2 = *((fes.FittedEntries()).begin() + order2);
0224
0225 ALIdouble val1 = fe1->getValue();
0226 ALIdouble val2 = fe2->getValue();
0227 ALIdouble sig1 = fe1->getSigma();
0228 ALIdouble sig2 = fe2->getSigma();
0229 ALIdouble val = val1 - val2;
0230 ALIdouble sig = sqrt(sig1 * sig1 + sig2 * sig2);
0231
0232 fout << std::setprecision(6) << std::setw(8) << val << " +- " << sig << " ";
0233 if (ALIUtils::debug >= 3)
0234 std::cout << " FITTEDENTRY:" << std::setprecision(5) << std::setw(8) << val << " +- " << sig << std::endl;
0235 }
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275