Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:38:37

0001 //   COCOA class implementation file

0002 //Id:  FittedEntriesSet.cc

0003 //CAT: Model

0004 //

0005 //   History: v1.0

0006 //   Pedro Arce

0007 
0008 #include <fstream>
0009 #include <map>
0010 #include "Alignment/CocoaFit/interface/FittedEntriesSet.h"
0011 #include "Alignment/CocoaModel/interface/Model.h"
0012 #include "Alignment/CocoaModel/interface/Measurement.h"
0013 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0014 #include "Alignment/CocoaModel/interface/Entry.h"
0015 
0016 #ifdef MAT_MESCHACH
0017 #include "Alignment/CocoaFit/interface/MatrixMeschach.h"
0018 #endif
0019 //

0020 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0021 FittedEntriesSet::FittedEntriesSet(MatrixMeschach* AtWAMatrix) {
0022   //- theTime = Model::MeasurementsTime();

0023   theDate = Measurement::getCurrentDate();
0024   theTime = Measurement::getCurrentTime();
0025 
0026   theMinEntryQuality = 2;
0027   theEntriesErrorMatrix = AtWAMatrix;
0028 
0029   Fill();
0030 }
0031 
0032 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0033 FittedEntriesSet::FittedEntriesSet(const std::vector<ALIstring>& wl) {
0034   //- theTime = Model::MeasurementsTime();

0035   theDate = wl[0];
0036   theTime = "99:99";
0037 
0038   theMinEntryQuality = 2;
0039   theEntriesErrorMatrix = (MatrixMeschach*)nullptr;
0040 
0041   FillEntriesFromFile(wl);
0042 }
0043 
0044 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0045 FittedEntriesSet::FittedEntriesSet(const std::vector<FittedEntriesSet*>& vSets) {
0046   theDate = "99/99/99";
0047   theTime = "99:99";
0048 
0049   theMinEntryQuality = 2;
0050   theEntriesErrorMatrix = (MatrixMeschach*)nullptr;
0051 
0052   FillEntriesAveragingSets(vSets);
0053 }
0054 
0055 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0056 void FittedEntriesSet::Fill() {
0057   FillEntries();
0058   FillCorrelations();
0059 }
0060 
0061 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0062 void FittedEntriesSet::FillEntries() {
0063   //---------- Store Fitted Entries

0064   //----- Iterate over entry list

0065   std::vector<Entry*>::const_iterator vecite;
0066   for (vecite = Model::EntryList().begin(); vecite != Model::EntryList().end(); ++vecite) {
0067     //--- Only for good quality parameters (='unk')

0068     if ((*vecite)->quality() >= theMinEntryQuality) {
0069       //      ALIdouble dimv =  (*vecite)->ValueDimensionFactor();

0070       //  ALIdouble dims =  (*vecite)->SigmaDimensionFactor();

0071       ALIint ipos = (*vecite)->fitPos();
0072       FittedEntry* fe = new FittedEntry((*vecite), ipos, sqrt(theEntriesErrorMatrix->Mat()->me[ipos][ipos]));
0073       //-      std::cout << fe << "IN fit FE " << fe->theValue<< " " << fe->Sigma()<< " "  << sqrt(theEntriesErrorMatrix->Mat()->me[NoEnt][NoEnt]) / dims<< std::endl;

0074       theFittedEntries.push_back(fe);
0075     }
0076   }
0077 }
0078 
0079 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0080 void FittedEntriesSet::FillCorrelations() {
0081   //------ Count the number of entries that will be in the set

0082   ALIuint nent = 0;
0083   std::vector<Entry*>::const_iterator vecite;
0084   for (vecite = Model::EntryList().begin(); vecite != Model::EntryList().end(); ++vecite) {
0085     if ((*vecite)->quality() > theMinEntryQuality) {
0086       nent++;
0087     }
0088   }
0089 
0090   CreateCorrelationMatrix(nent);
0091   //---------- Store correlations

0092   ALIuint ii;
0093   for (ii = 0; ii < nent; ii++) {
0094     for (ALIuint jj = ii + 1; jj < nent; jj++) {
0095       ALIdouble corr = theEntriesErrorMatrix->Mat()->me[ii][jj];
0096       if (corr != 0) {
0097         corr /= (sqrt(theEntriesErrorMatrix->Mat()->me[ii][ii]) / sqrt(theEntriesErrorMatrix->Mat()->me[jj][jj]));
0098         theCorrelationMatrix[ii][jj] = corr;
0099       }
0100     }
0101   }
0102 }
0103 
0104 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0105 void FittedEntriesSet::CreateCorrelationMatrix(const ALIuint nent) {
0106   std::vector<ALIdouble> vd(nent, 0.);
0107   std::vector<std::vector<ALIdouble> > vvd(nent, vd);
0108   theCorrelationMatrix = vvd;
0109 }
0110 
0111 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0112 void FittedEntriesSet::FillEntriesFromFile(const std::vector<ALIstring>& wl) {
0113   ALIuint siz = wl.size();
0114   for (ALIuint ii = 1; ii < siz; ii += 3) {
0115     FittedEntry* fe = new FittedEntry(wl[ii], ALIUtils::getFloat(wl[ii + 1]), ALIUtils::getFloat(wl[ii + 2]));
0116     theFittedEntries.push_back(fe);
0117   }
0118 }
0119 
0120 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0121 void FittedEntriesSet::FillEntriesAveragingSets(const std::vector<FittedEntriesSet*>& vSets) {
0122   std::vector<FittedEntry*> vFEntry;
0123   ALIuint nEntry = vSets[0]->FittedEntries().size();
0124   //  ALIuint setssiz = vSets.size();

0125   for (ALIuint ii = 0; ii < nEntry; ii++) {  // loop to FittedEntry's

0126     if (ALIUtils::debug >= 5)
0127       std::cout << "FillEntriesAveragingSets entry " << ii << std::endl;
0128     vFEntry.clear();
0129     for (ALIuint jj = 0; jj < vSets.size(); jj++) {  // look for FittedEntry ii in each Sets

0130       if (ALIUtils::debug >= 5)
0131         std::cout << "FillEntriesAveragingSets set " << jj << std::endl;
0132       //----- Check all have the same number of entries

0133       if (vSets[jj]->FittedEntries().size() != nEntry) {
0134         std::cerr << "!!! FATAL ERROR FittedEntriesSet::FillEntriesAveragingSets  set number " << jj
0135                   << " has different number of entries = " << vSets[jj]->FittedEntries().size()
0136                   << " than first set = " << nEntry << std::endl;
0137         exit(1);
0138       }
0139 
0140       vFEntry.push_back(vSets[jj]->FittedEntries()[ii]);
0141     }
0142     FittedEntry* fe = new FittedEntry(vFEntry);
0143     if (ALIUtils::debug >= 5)
0144       std::cout << "FillEntriesAveragingSets new fentry " << fe->getValue() << " " << fe->getSigma() << std::endl;
0145     theFittedEntries.push_back(fe);
0146   }
0147 }
0148 
0149 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

0150 void FittedEntriesSet::SetOptOEntries() {
0151   if (ALIUtils::debug >= 5)
0152     std::cout << "  FittedEntriesSet::SetOptOEntries " << theFittedEntries.size() << std::endl;
0153 
0154   std::vector<FittedEntry*>::const_iterator ite;
0155   for (ite = theFittedEntries.begin(); ite != theFittedEntries.end(); ++ite) {
0156     FittedEntry* fe = (*ite);
0157     OpticalObject* opto = Model::getOptOByName(fe->getOptOName());
0158     Entry* entry = Model::getEntryByName(fe->getOptOName(), fe->getEntryName());
0159     entry->setValue(fe->getValue());
0160     entry->setSigma(fe->getSigma());
0161 
0162     if (ALIUtils::debug >= 5)
0163       std::cout << "  FittedEntriesSet::SetOptOEntries() " << opto->name() << " " << entry->name() << std::endl;
0164     opto->setGlobalCoordinates();
0165     opto->setOriginalEntryValues();
0166   }
0167 }