Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:00

0001 //   COCOA class header file

0002 //Id:  Model.h

0003 //CAT: Model

0004 //

0005 //   Utility class that steers the reading of the system description file

0006 //              and contains the static data

0007 //

0008 //   History: v1.0

0009 //   Pedro Arce

0010 
0011 #ifndef MODEL_H
0012 #define MODEL_H
0013 
0014 #include <vector>
0015 #include <map>
0016 //#include <multimap.h>

0017 
0018 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
0019 class Entry;
0020 //#include "Alignment/CocoaModel/interface/Entry.h"  //temporal

0021 class OpticalObject;
0022 //#include "Alignment/CocoaModel/interface/OpticalObject.h"

0023 class Measurement;
0024 class ALIFileIn;
0025 class FittedEntriesReader;
0026 
0027 class OpticalAlignments;
0028 class OpticalAlignMeasurements;
0029 
0030 #include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h"
0031 
0032 enum sectionType {
0033   sectGlobalOptions,
0034   sectParameters,
0035   sectSystemTreeDescription,
0036   sectSystemTreeData,
0037   sectMeasurements,
0038   sectReportOut
0039 };
0040 
0041 enum cocoaStatus {
0042   COCOA_Init,
0043   COCOA_ReadingModel,
0044   COCOA_InitFit,
0045   COCOA_FirstIterationInEvent,
0046   COCOA_NextIterationInEvent,
0047   COCOA_FitOK,
0048   COCOA_FitImproving,
0049   COCOA_FitCannotImprove,
0050   COCOA_FitChi2Worsened,
0051   COCOA_FitMatrixNonInversable
0052 };
0053 
0054 class Model {
0055 public:
0056   //---------- Constructor / destructor

0057   Model();
0058   ~Model(){};
0059 
0060   ///---------- Gets the only instance of this class

0061   static Model& getInstance();
0062 
0063   static cocoaStatus getCocoaStatus() { return theCocoaStatus; }
0064   static void setCocoaStatus(const cocoaStatus cs) { theCocoaStatus = cs; }
0065   static std::string printCocoaStatus(const cocoaStatus cs);
0066 
0067   ///---------- Read the different sections of the SDF and act accordingly

0068   static void readSystemDescription();
0069 
0070   //----------- Build OpticalObjects's from info in XML file

0071   void BuildSystemDescriptionFromOA(OpticalAlignments& optAlig);
0072   OpticalAlignInfo FindOptAlignInfoByType(const ALIstring& type);
0073   //----------- Build Measurements's from info in XML file

0074   void BuildMeasurementsFromOA(OpticalAlignMeasurements& measList);
0075 
0076   /// ACCESS STATIC DATA MEMBERS

0077 
0078   //  static std::map< ALIstring, ALIdouble, std::less<ALIstring> >& Parameters() {

0079   //     return theParameters;

0080   //  }

0081 
0082   static std::vector<std::vector<ALIstring> >& OptODictionary() { return theOptODictionary; }
0083 
0084   static std::vector<OpticalObject*>& OptOList() { return theOptOList; }
0085 
0086   static std::vector<Entry*>& EntryList() { return theEntryVector; }
0087 
0088   static std::vector<Measurement*>& MeasurementList() { return theMeasurementVector; }
0089 
0090   static Measurement* getMeasurementByName(const ALIstring& name, ALIbool exists = true);
0091 
0092   /// the name of the System Description File

0093   static ALIstring& SDFName() { return theSDFName; }
0094 
0095   /// the name of the Measurements File

0096   static ALIstring& MeasFName() { return theMeasFName; }
0097 
0098   /// the name of the report File

0099   static ALIstring& ReportFName() { return theReportFName; }
0100 
0101   /// the name of the File for storing the matrices

0102   static ALIstring& MatricesFName() { return theMatricesFName; }
0103 
0104   ///************ ACCESS INFO FROM STATIC DATA

0105 
0106   ///----- Search a string in theParameters and return 1 if found

0107   static int getParameterValue(const ALIstring& sstr, ALIdouble& val);
0108 
0109   ///-----  Find an OptO name in theOptOList and return a pointer to it

0110   static OpticalObject* getOptOByName(const ALIstring& opto_name);
0111 
0112   ///-----  Find the first OptO of type 'opto_type' in theOptOList and return a pointer to it

0113   static OpticalObject* getOptOByType(const ALIstring& type);
0114 
0115   ///-----  Search an Entry name in the Entry* list and return a pointer to it

0116   static Entry* getEntryByName(const ALIstring& opto_name, const ALIstring& entry_name);
0117 
0118   ///-----  Search an Entry from the full entry path

0119   /// (first substract the name of the OptO and then look in the Entry* list)

0120   static Entry* getEntryByName(const ALIstring& opto_entry_name) {
0121     ALIint slash_pos = opto_entry_name.rfind('/');
0122     ALIint length = opto_entry_name.length();
0123     ALIstring opto_name = opto_entry_name.substr(0, slash_pos);
0124     ALIstring entry_name = opto_entry_name.substr(slash_pos + 1, length);
0125     Entry* entry = getEntryByName(opto_name, entry_name);
0126     return entry;
0127   }
0128 
0129   ///----- Get from theOptODictionary the list of component OptO types

0130   static ALIbool getComponentOptOTypes(const ALIstring& opto_type, std::vector<ALIstring>& vcomponents);
0131 
0132   ///----- Get from theOptOList the list of pointers to component OptOs

0133   static ALIbool getComponentOptOs(const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents);
0134 
0135   static struct tm& MeasurementsTime() { return theMeasurementsTime; }
0136 
0137   static std::vector<OpticalAlignInfo> getOpticalAlignments() { return theOpticalAlignments; }
0138 
0139   ///*****************  SET DATA MEMBERS

0140   static void addEntryToList(Entry* entry) {
0141     theEntryVector.push_back(entry);
0142     //-     std::cout << entry << entry->OptOCurrent()->name() << "ADDENTRY " << entry->name() << " " << EntryList().size() << std::endl;

0143   }
0144 
0145   static void addMeasurementToList(Measurement* measadd) {
0146     theMeasurementVector.push_back(measadd);
0147     //   std::cout << "ADD MEASUREMENT" << theMeasurementVector.size() << std::endl ;

0148   }
0149 
0150   //----- Set the name of the System Description File

0151   static void setSDFName(const ALIstring& name) { theSDFName = name; }
0152   //----- Set the name of the report File

0153   static void setReportFName(const ALIstring& name) { theReportFName = name; }
0154   //----- Set the name of the matrices File

0155   static void setMatricesFName(const ALIstring& name) { theMatricesFName = name; }
0156 
0157   static void setMeasurementsTime(struct tm& tim) { theMeasurementsTime = tim; }
0158 
0159   static ALIbool readMeasurementsFromFile(ALIstring only1Date = ALIstring(""), ALIstring only1Time = ALIstring(""));
0160 
0161   ///********** private METHODS

0162 private:
0163   /// Reorder the list of OptOs in a hierarchical structure (tree-like)

0164   static void reorderOptODictionary(const ALIstring& ssearch, std::vector<std::vector<ALIstring> >& OptODictionary2);
0165 
0166   /// Read Measurements (to be implemented for reading from an external file the DATA of the measurements)

0167   //  static void readMeasurements( ALIFileIn& filein );

0168 
0169   /// Build for each measuremnt its link to the OptO that take part in it

0170   static void buildMeasurementsLinksToOptOs();
0171 
0172   static void SetValueDisplacementsFromReportOut();
0173 
0174   ///********** private DATA MEMBERS

0175   /// Only instance of Model

0176   static Model* theInstance;
0177 
0178   /// parameters

0179   //-  static std::map< ALIstring, ALIdouble, std::less<ALIstring> > theParameters;

0180 
0181   /// std::vector of OptOs with components (in tree structure)

0182   static std::vector<std::vector<ALIstring> > theOptODictionary;
0183 
0184   /// map of OptO*/type of parent OptO, for navigation down the tree structure

0185   //-  static multimap< ALIstring, OpticalObject*, std::less<ALIstring> > theOptOtree;

0186   /// map of OptO*/name of OptO for quick search based on name

0187   //  static map< ALIstring, OpticalObject*, std::less<ALIstring> > theOptOList;

0188   static std::vector<OpticalObject*> theOptOList;
0189 
0190   /// std::vector of all Entries

0191   static std::vector<Entry*> theEntryVector;
0192 
0193   /// std::vector of all Measurements

0194   static std::vector<Measurement*> theMeasurementVector;
0195 
0196   /// the name of the System Description File

0197   static ALIstring theSDFName;
0198   /// the name of the Measurements File

0199   static ALIstring theMeasFName;
0200   /// the name of the report File

0201   static ALIstring theReportFName;
0202   /// the name of the File for storing the matrices

0203   static ALIstring theMatricesFName;
0204 
0205   ///**************** FOR COPYING AN OPTO

0206 public:
0207   //----- Steers the storing of the components of OptO named 'optoname'

0208   static ALIbool createCopyComponentList(const ALIstring& optoname);
0209   //----- Get next object to copy from the stored list of components and copy it

0210   static OpticalObject* nextOptOToCopy();
0211 
0212 private:
0213   //----- Stores the components of opto

0214   static ALIbool fillCopyComponentList(const OpticalObject* opto);
0215   //----- List of components of an OptO to copy

0216   static std::vector<OpticalObject*> theOptOsToCopyList;
0217   //----- Iterator of the list of components of an OptO to copy

0218   static std::vector<OpticalObject*>::const_iterator theOptOsToCopyListIterator;
0219 
0220   ///*************** FOR RANGE STUDIES

0221 public:
0222   static ALIint Ncmslinkrange;
0223   static std::vector<ALIdouble> CMSLinkRangeDetValue;
0224 
0225   ///*************** FOR CMS LINK SYSTEM (to fit it part by part)

0226 public:
0227   void CMSLinkFit(ALIint cmslink);
0228 
0229 private:
0230   void CMSLinkCleanModel();
0231   static void CMSLinkDeleteOptOs();
0232   static void CMSLinkSaveParamFittedSigma(ALIint cmslink);
0233   static void CMSLinkSaveParamFittedValueDisplacement(ALIint cmslink);
0234   static void CMSLinkRecoverParamFittedSigma(ALIint cmslink);
0235   static void CMSLinkRecoverParamFittedValueDisplacement(ALIint cmslink);
0236 
0237   static ALIint CMSLinkIteration;
0238 
0239   //----- METHODS FOR FITTING IN SEVERAL STEPS

0240   static void deleteOptO(const ALIstring& opto_name);
0241   static void deleteOptO(OpticalObject* opto);
0242 
0243   static void saveParamFittedSigma(const ALIstring& opto_name, const ALIstring& entry_name);
0244 
0245   static void saveParamFittedCorrelation(const ALIstring& opto_name1,
0246                                          const ALIstring& entry_name1,
0247                                          const ALIstring& opto_name2,
0248                                          const ALIstring& entry_name2);
0249 
0250   static void recoverParamFittedSigma(const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position);
0251 
0252 public:
0253   static ALIdouble getParamFittedSigmaVectorItem(const ALIuint position);
0254   static FittedEntriesReader* getFittedEntriesReader() { return theFittedEntriesReader; }
0255 
0256 private:
0257   static void cleanParamFittedSigmaVector() {
0258     ALIuint pfsv_size = theParamFittedSigmaVector.size();
0259     for (ALIuint ii = 0; ii < pfsv_size; ii++) {
0260       theParamFittedSigmaVector.pop_back();
0261     }
0262   }
0263 
0264   static void cleanParamFittedValueDisplacementMap() {
0265     theParamFittedValueDisplacementMap.erase(theParamFittedValueDisplacementMap.begin(),
0266                                              theParamFittedValueDisplacementMap.end());
0267   }
0268 
0269   static void copyMeasurements(const std::vector<ALIstring>& wl);
0270 
0271 private:
0272   static cocoaStatus theCocoaStatus;
0273 
0274   static std::vector<ALIdouble> theParamFittedSigmaVector;
0275 
0276   static std::map<ALIstring, ALIdouble, std::less<ALIstring> > theParamFittedValueDisplacementMap;
0277 
0278   static struct tm theMeasurementsTime;
0279 
0280   static FittedEntriesReader* theFittedEntriesReader;
0281 
0282   static std::vector<OpticalAlignInfo> theOpticalAlignments;
0283 };
0284 
0285 #endif