00001
00002
00003
00004
00005
00006
00007 #include <map>
00008 #include <fstream>
00009
00010 #include "Alignment/CocoaAnalysis/interface/FittedEntriesManager.h"
00011 #include "Alignment/CocoaAnalysis/interface/FittedEntriesSet.h"
00012 #include <iostream>
00013 #include <iomanip>
00014 #include "Alignment/CocoaModel/interface/Model.h"
00015 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00016 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00017
00018 FittedEntriesManager* FittedEntriesManager::instance = 0;
00019
00020
00021
00022
00023 FittedEntriesManager* FittedEntriesManager::getInstance()
00024 {
00025 if(!instance) {
00026 instance = new FittedEntriesManager;
00027 }
00028 return instance;
00029 }
00030
00031
00032
00033
00034 void FittedEntriesManager::AddFittedEntriesSet( FittedEntriesSet* fents)
00035 {
00036 theFittedEntriesSets.push_back( fents );
00037
00038 }
00039
00040
00041
00042
00043
00044
00045 void FittedEntriesManager::MakeHistos()
00046 {
00047
00048
00049
00050
00051
00052
00053
00054 if( ALIUtils::debug >= 5) std::cout << "No sets2 " << theFittedEntriesSets.size() << " No ent " << ( ( *(theFittedEntriesSets.begin()) )->FittedEntries() ).size() << std::endl;
00055 std::ofstream fout;
00056 std::ofstream fout2;
00057 fout.open( "fittedEntries.out" );
00058 fout2.open( "longFittedEntries.out" );
00059
00060 ALIUtils::dumpDimensions( fout );
00061 ALIUtils::dumpDimensions( fout2 );
00062
00063 AddFittedEntriesSet( new FittedEntriesSet( theFittedEntriesSets ) );
00064
00065
00066 std::vector< FittedEntriesSet* >::const_iterator vfescite;
00067 std::vector< FittedEntry* >::const_iterator vfecite;
00068 ALIint jj = 1;
00069 for( vfescite = theFittedEntriesSets.begin(); vfescite != theFittedEntriesSets.end(); vfescite++) {
00070
00071 if( vfescite == theFittedEntriesSets.begin() ) {
00072
00073 fout << " ";
00074 ALIint ii = 0;
00075 for( vfecite = ((*vfescite)->FittedEntries()).begin(); vfecite != ((*vfescite)->FittedEntries()).end(); vfecite++) {
00076 ALIstring filename = createFileName( (*vfecite)->getOptOName(), (*vfecite)->getEntryName() );
00077 fout << ii << ": " << std::setw(13) << filename << " ";;
00078 if(ALIUtils::debug >= 3) std::cout << ii << ": " << std::setw(13) << filename << " = " << (*vfecite)->getName() << std::endl;
00079 if( ALIUtils::debug >= 3) std::cout << filename << " ";
00080 if( ALIUtils::debug >= 3) std::cout << "OPENING FITTED ENTRIES file " << filename << std::endl;
00081 ii++;
00082 }
00083
00084 fout << std::endl;
00085 if( ALIUtils::debug >= 3) std::cout << std::endl;
00086 }
00087
00088 fout << jj << " ";
00089 fout2 << jj << " ";
00090
00091 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00092 if( gomgr->GlobalOptions()["DumpDateInFittedEntries"] >= 1 ) {
00093 fout << (*vfescite)->getDate() << " " << (*vfescite)->getTime() << " ";
00094 fout2 << (*vfescite)->getDate() << " " << (*vfescite)->getTime() << " ";
00095 }
00096
00097 ALIint ii = 0;
00098 for( vfecite = ((*vfescite)->FittedEntries()).begin(); vfecite != ((*vfescite)->FittedEntries()).end(); vfecite++) {
00099
00100
00101 fout << std::setprecision(8) << std::setw(10) << (*vfecite)->getValue() << " " << (*vfecite)->getSigma() << " ";
00102
00103
00104 if( ALIUtils::debug >= 3) std::cout << " FITTEDENTRY:" << std::setprecision(5) << std::setw(8) << (*vfecite)->getValue() << " +- " << (*vfecite)->getSigma() << std::endl;
00105
00106 ALIstring filename = createFileName( (*vfecite)->getOptOName(), (*vfecite)->getEntryName() );
00107 fout2 << std::setprecision(8) << std::setw(10) << filename<< " " << (*vfecite)->getValue() << " " << (*vfecite)->getSigma() << " ";
00108 ii++;
00109 }
00110
00111 fout << std::endl;
00112 fout2 << std::endl;
00113 if( ALIUtils::debug >= 3) std::cout << std::endl;
00114 jj++;
00115 }
00116 fout.close();
00117 fout2.close();
00118
00119 GetDifferentBetweenLasers();
00120
00121 }
00122
00123 #include "Alignment/CocoaModel/interface/LightRay.h"
00124 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00125
00126
00127 void FittedEntriesManager::GetDifferentBetweenLasers()
00128 {
00129
00130 std::vector< OpticalObject* > optoList = Model::OptOList();
00131 std::vector< OpticalObject* >::const_iterator ite;
00132 std::map< ALIstring, LightRay* > lrays;
00133
00134 for( ite = optoList.begin(); ite != optoList.end(); ite++ ){
00135 if( (*ite)->type() == "laser" ){
00136 LightRay* lightray = new LightRay;
00137 lightray->startLightRay( *ite );
00138 lrays[(*ite)->parent()->name()] = lightray;
00139 }
00140 }
00141
00142 std::map< ALIstring, LightRay* >::const_iterator lite1, lite2;
00143 for( lite1 = lrays.begin(); lite1 != lrays.end(); lite1++ ){
00144 lite2 = lite1; lite2++;
00145 for( ; lite2 != lrays.end(); lite2++ ){
00146 if( lite1 == lite2 ) continue;
00147 Hep3Vector dirdiff = ((*lite1).second->direction() - (*lite2).second->direction());
00148 if(ALIUtils::debug >= 0) {
00149 std::cout << "LASER DIFF " << (*lite1).first << " & " << (*lite2).first << " " << dirdiff.mag()*180./M_PI << "o " << dirdiff.mag() << " rad " << dirdiff << std::endl;
00150
00151 (*lite1).second->dumpData(ALIstring(" laser ") + (*lite1).first );
00152 (*lite2).second->dumpData(ALIstring(" laser ") + (*lite2).first );
00153 }
00154 }
00155
00156 }
00157
00158 }
00159
00160
00161
00162
00163
00164 ALIstring FittedEntriesManager::createFileName( const ALIstring& optoName, const ALIstring& entryName)
00165 {
00166
00167 ALIstring filename;
00168
00169
00170
00171
00172
00173
00174
00175
00176 filename = optoName.substr( 2, optoName.size() );
00177 ALIint slash = -1;
00178 for(;;){
00179 slash = filename.find('/', slash+1);
00180 if( slash == -1 ) break;
00181 filename[slash] = '.';
00182 }
00183
00184
00185 ALIint space = entryName.rfind(' ');
00186 filename.append(".");
00187 ALIstring en = entryName;
00188 if( space != -1) en[space] = '_';
00189
00190
00191
00192 filename.append( en);
00193 if( ALIUtils::debug >= 3) std::cout << "filename " << filename << std::endl;
00194
00195 return filename;
00196
00197 }
00198
00199
00200
00201
00202
00203
00204
00205 void FittedEntriesManager::dumpEntriesSubstraction( std::ofstream& fout, FittedEntriesSet& fes, ALIint order1, ALIint order2 )
00206 {
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 FittedEntry* fe1 = *((fes.FittedEntries()).begin() + order1);
00223 FittedEntry* fe2 = *((fes.FittedEntries()).begin() + order2);
00224
00225 ALIdouble val1 = fe1->getValue();
00226 ALIdouble val2 = fe2->getValue();
00227 ALIdouble sig1 = fe1->getSigma();
00228 ALIdouble sig2 = fe2->getSigma();
00229 ALIdouble val = val1 - val2;
00230 ALIdouble sig = sqrt( sig1*sig1 + sig2*sig2);
00231
00232 fout << std::setprecision(6) <<std::setw(8) << val << " +- " << sig << " ";
00233 if( ALIUtils::debug >= 3) std::cout << " FITTEDENTRY:" << std::setprecision(5) << std::setw(8) << val << " +- " << sig << std::endl;
00234
00235
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278