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