00001 #include "FWCore/Framework/interface/ESHandle.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "CondCore/DBCommon/interface/Exception.h"
00004 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00005
00006 #include "../interface/CocoaAnalyzer.h"
00007 #include "DetectorDescription/Core/interface/DDSpecifics.h"
00008 #include "DetectorDescription/Base/interface/Ptr.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "CondFormats/OptAlignObjects/interface/OAQuality.h"
00011 #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurementInfo.h"
00012 #include "CondFormats/DataRecord/interface/OpticalAlignmentsRcd.h"
00013 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00014
00015 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00016 #include "DetectorDescription/Core/interface/DDValuePair.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include <list>
00020 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00021 #include <assert.h>
00022 #include "Alignment/CocoaModel/interface/Model.h"
00023 #include "Alignment/CocoaFit/interface/Fit.h"
00024 #include "Alignment/CocoaModel/interface/Entry.h"
00025 #include "Alignment/CocoaUtilities/interface/ALIFileOut.h"
00026 #include "Alignment/CocoaModel/interface/CocoaDaqReaderRoot.h"
00027 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00028 #include "DetectorDescription/Core/interface/DDCompactView.h"
00029
00030
00031 CocoaAnalyzer::CocoaAnalyzer(edm::ParameterSet const& pset)
00032 {
00033 theCocoaDaqRootFileName = pset.getParameter< std::string >("cocoaDaqRootFile");
00034 }
00035
00036
00037 void CocoaAnalyzer::beginJob( const edm::EventSetup& evts )
00038 {
00039 ReadXMLFile( evts );
00040
00041 std::vector<OpticalAlignInfo> oaListCalib = ReadCalibrationDB( evts );
00042
00043 CorrectOptAlignments( oaListCalib );
00044
00045 new CocoaDaqReaderRoot( theCocoaDaqRootFileName );
00046
00047
00048
00049
00050
00051
00052
00053
00054 RunCocoa();
00055
00056
00057
00058 DumpCocoaResults();
00059 }
00060
00061
00062 void CocoaAnalyzer::ReadXMLFile( const edm::EventSetup& evts )
00063 {
00064
00065 ALIUtils::setDebugVerbosity( 5 );
00066
00067
00068
00069
00070 edm::ESHandle<DDCompactView> cpv;
00071 evts.get<IdealGeometryRecord>().get(cpv);
00072
00073 if(ALIUtils::debug >= 3) {
00074 std::cout << " CocoaAnalyzer ROOT " << cpv->root() << std::endl;
00075 }
00076
00077
00078 const DDLogicalPart lv = cpv->root();
00079
00080 OpticalAlignInfo oaInfo;
00081 oaInfo.ID_ = 0;
00082
00083 oaInfo.name_ = lv.name();
00084 int icol = oaInfo.name_.find(":");
00085 oaInfo.name_ = oaInfo.name_.substr(icol+1,oaInfo.name_.length());
00086 oaInfo.parentName_ = "";
00087 oaInfo.x_.quality_ = 0;
00088 oaInfo.x_.value_ = 0.;
00089 oaInfo.x_.error_ = 0.;
00090 oaInfo.x_.quality_ = 0;
00091 oaInfo.y_.value_ = 0.;
00092 oaInfo.y_.error_ = 0.;
00093 oaInfo.y_.quality_ = 0;
00094 oaInfo.z_.value_ = 0.;
00095 oaInfo.z_.error_ = 0.;
00096 oaInfo.z_.quality_ = 0;
00097 oaInfo.angx_.value_ = 0.;
00098 oaInfo.angx_.error_ = 0.;
00099 oaInfo.angx_.quality_ = 0;
00100 oaInfo.angy_.value_ = 0.;
00101 oaInfo.angy_.error_ = 0.;
00102 oaInfo.angy_.quality_ = 0;
00103 oaInfo.angz_.value_ = 0.;
00104 oaInfo.angz_.error_ = 0.;
00105 oaInfo.angz_.quality_ = 0;
00106
00107 oaInfo.type_ = "system";
00108
00109 oaList_.opticalAlignments_.push_back(oaInfo);
00110 oaInfo.clear();
00111
00112
00113
00114
00115
00116 std::string attribute = "COCOA";
00117 std::string value = "COCOA";
00118 DDValue val(attribute, value, 0.0);
00119
00120
00121 DDSpecificsFilter filter;
00122 filter.setCriteria(val,
00123 DDSpecificsFilter::matches,
00124 DDSpecificsFilter::AND,
00125 true,
00126 true
00127 );
00128 DDFilteredView fv(*cpv);
00129 fv.addFilter(filter);
00130 bool doCOCOA = fv.firstChild();
00131
00132
00133 int nObjects=0;
00134 OpticalAlignParam oaParam;
00135 OpticalAlignMeasurementInfo oaMeas;
00136
00137 while ( doCOCOA ){
00138 ++nObjects;
00139 oaInfo.ID_ = nObjects;
00140 const DDsvalues_type params(fv.mergedSpecifics());
00141
00142 const DDLogicalPart lv = fv.logicalPart();
00143 if(ALIUtils::debug >= 4) {
00144 std::cout << " CocoaAnalyzer: reading object " << lv.name() << std::endl;
00145 }
00146
00147 std::vector<DDExpandedNode> history = fv.geoHistory();
00148 oaInfo.parentName_ = "";
00149 size_t ii;
00150 for(ii = 0; ii < history.size()-1;ii++ ) {
00151 if( ii != 0 ) oaInfo.parentName_ += "/";
00152 std::string name = history[ii].logicalPart().name();
00153 icol = name.find(":");
00154 name = name.substr(icol+1,name.length());
00155 oaInfo.parentName_ += name;
00156
00157
00158
00159 }
00160
00161
00162 std::string name = history[ii].logicalPart().name();
00163
00164 int icol = name.find(":");
00165 name = name.substr(icol+1,name.length());
00166 oaInfo.name_ = oaInfo.parentName_ + "/" + name;
00167 std::cout << " @@@@@@@@@@@@@@@@ NAme built " << oaInfo.name_ << " parent " << oaInfo.parentName_ << " short " << name << std::endl;
00168
00169
00170 oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0));
00171 DDTranslation transl = (fv.translation());
00172 DDRotationMatrix rot = (fv.rotation());
00173 DDExpandedNode parent = fv.geoHistory()[ fv.geoHistory().size()-2 ];
00174 DDTranslation parentTransl = parent.absTranslation();
00175 DDRotationMatrix parentRot = parent.absRotation();
00176 transl = parentRot.Inverse()*(transl - parentTransl );
00177 rot = parentRot.Inverse()*rot;
00178 rot = rot.Inverse();
00179
00180
00181
00182
00183
00184 oaInfo.x_.name_ = "X";
00185 oaInfo.x_.dim_type_ = "centre";
00186 oaInfo.x_.value_ = transl.x();
00187 oaInfo.x_.error_ = myFetchDbl(params, "centre_X_sigma", 0);
00188 oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0));
00189
00190 oaInfo.y_.name_ = "Y";
00191 oaInfo.y_.dim_type_ = "centre";
00192 oaInfo.y_.value_ = transl.y();
00193 oaInfo.y_.error_ = myFetchDbl(params, "centre_Y_sigma", 0);
00194 oaInfo.y_.quality_ = int (myFetchDbl(params, "centre_Y_quality", 0));
00195
00196 oaInfo.z_.name_ = "Z";
00197 oaInfo.z_.dim_type_ = "centre";
00198 oaInfo.z_.value_ = transl.z();
00199 oaInfo.z_.error_ = myFetchDbl(params, "centre_Z_sigma", 0);
00200 oaInfo.z_.quality_ = int (myFetchDbl(params, "centre_Z_quality", 0));
00201
00202
00203
00204 double xx,xy,xz,yx,yy,yz,zx,zy,zz;
00205 rot.GetComponents (xx, xy, xz,
00206 yx, yy, yz,
00207 zx, zy, zz);
00208 Hep3Vector colX(xx,xy,xz);
00209 Hep3Vector colY(yx,yy,yz);
00210 Hep3Vector colZ(zx,zy,zz);
00211 CLHEP::HepRotation rotclhep( colX, colY, colZ );
00212 std::vector<double> angles = ALIUtils::getRotationAnglesFromMatrix( rotclhep,0., 0., 0. );
00213
00214 oaInfo.angx_.name_ = "X";
00215 oaInfo.angx_.dim_type_ = "angles";
00216
00217 oaInfo.angx_.value_ = myFetchDbl(params, "angles_X_value", 0);
00218 oaInfo.angx_.error_ = myFetchDbl(params, "angles_X_sigma", 0);
00219 oaInfo.angx_.quality_ = int (myFetchDbl(params, "angles_X_quality", 0));
00220
00221 oaInfo.angy_.name_ = "Y";
00222 oaInfo.angy_.dim_type_ = "angles";
00223
00224 oaInfo.angy_.value_ = myFetchDbl(params, "angles_Y_value", 0);
00225 oaInfo.angy_.error_ = myFetchDbl(params, "angles_Y_sigma", 0);
00226 oaInfo.angy_.quality_ = int (myFetchDbl(params, "angles_Y_quality", 0));
00227
00228 oaInfo.angz_.name_ = "Z";
00229 oaInfo.angz_.dim_type_ = "angles";
00230
00231 oaInfo.angz_.value_ = myFetchDbl(params, "angles_Z_value", 0);
00232 oaInfo.angz_.error_ = myFetchDbl(params, "angles_Z_sigma", 0);
00233 oaInfo.angz_.quality_ = int (myFetchDbl(params, "angles_Z_quality", 0));
00234
00235 oaInfo.type_ = myFetchString(params, "cocoa_type", 0);
00236
00237 if(ALIUtils::debug >= 4) {
00238 std::cout << "CocoaAnalyzer OBJECT " << oaInfo.name_ << " pos/angle read " << std::endl;
00239 }
00240
00241 if( fabs( oaInfo.angx_.value_ - angles[0] ) > 1.E-9 ||
00242 fabs( oaInfo.angy_.value_ - angles[1] ) > 1.E-9 ||
00243 fabs( oaInfo.angz_.value_ - angles[2] ) > 1.E-9 ) {
00244 std::cerr << " WRONG ANGLE IN OBJECT " << oaInfo.name_<<
00245 oaInfo.angx_.value_ << " =? " << angles[0] <<
00246 oaInfo.angy_.value_ << " =? " << angles[1] <<
00247 oaInfo.angz_.value_ << " =? " << angles[2] << std::endl;
00248 }
00249
00250
00251 const std::vector<const DDsvalues_type *> params2(fv.specifics());
00252 std::vector<const DDsvalues_type *>::const_iterator spit = params2.begin();
00253 std::vector<const DDsvalues_type *>::const_iterator endspit = params2.end();
00254
00255 std::vector<std::string> names, dims;
00256 std::vector<double> values, errors, quality;
00257
00258 std::vector<std::string> measNames;
00259 std::vector<std::string> measTypes;
00260 std::map<std::string, std::vector<std::string> > measObjectNames;
00261 std::map<std::string, std::vector<std::string> > measParamNames;
00262 std::map<std::string, std::vector<double> > measParamValues;
00263 std::map<std::string, std::vector<double> > measParamSigmas;
00264 std::map<std::string, std::vector<double> > measIsSimulatedValue;
00265
00266 for ( ; spit != endspit; ++spit ) {
00267 DDsvalues_type::const_iterator sit = (**spit).begin();
00268 DDsvalues_type::const_iterator endsit = (**spit).end();
00269 for ( ; sit != endsit; ++sit ) {
00270 if (sit->second.name() == "extra_entry") {
00271 names = sit->second.strings();
00272 } else if (sit->second.name() == "dimType") {
00273 dims = sit->second.strings();
00274 } else if (sit->second.name() == "value") {
00275 values = sit->second.doubles();
00276 } else if (sit->second.name() == "sigma") {
00277 errors = sit->second.doubles();
00278 } else if (sit->second.name() == "quality") {
00279 quality = sit->second.doubles();
00280
00281 } else if (sit->second.name() == "meas_name") {
00282
00283 measNames = sit->second.strings();
00284 } else if (sit->second.name() == "meas_type") {
00285
00286 measTypes = sit->second.strings();
00287 }
00288
00289 }
00290 }
00291
00292
00293
00294
00295
00296 std::vector<std::string>::iterator vsite;
00297 for ( spit = params2.begin(); spit != params2.end(); ++spit ) {
00298
00299 DDsvalues_type::const_iterator sit = (**spit).begin();
00300 DDsvalues_type::const_iterator endsit = (**spit).end();
00301 for ( ; sit != endsit; ++sit ) {
00302 for( vsite = measNames.begin(); vsite != measNames.end(); vsite++ ){
00303
00304 if (sit->second.name() == "meas_object_name_"+(*vsite)) {
00305 measObjectNames[*vsite] = sit->second.strings();
00306 }else if (sit->second.name() == "meas_value_name_"+(*vsite)) {
00307 measParamNames[*vsite] = sit->second.strings();
00308 }else if (sit->second.name() == "meas_value_"+(*vsite)) {
00309 measParamValues[*vsite] = sit->second.doubles();
00310 }else if (sit->second.name() == "meas_sigma_"+(*vsite)) {
00311 measParamSigmas[*vsite] = sit->second.doubles();
00312 }else if (sit->second.name() == "meas_is_simulated_value_"+(*vsite)) {
00313 measIsSimulatedValue[*vsite] = sit->second.doubles();
00314 std::cout << *vsite << " setting issimu " << measIsSimulatedValue[*vsite][0] << std::endl;
00315 }
00316 if(ALIUtils::debug >= 4) {
00317 std::cout << "CocoaAnalyser: looped measObjectNames " << "meas_object_name_"+(*vsite) << " n obj " << measObjectNames[*vsite].size() << std::endl;
00318 }
00319
00320 }
00321
00322 }
00323 }
00324
00325 if(ALIUtils::debug >= 4) {
00326 std::cout << " CocoaAnalyzer: Fill extra entries with read parameters " << std::endl;
00327 }
00328
00329 if ( names.size() == dims.size() && dims.size() == values.size()
00330 && values.size() == errors.size() && errors.size() == quality.size() ) {
00331 for ( size_t ind = 0; ind < names.size(); ++ind ) {
00332 oaParam.value_ = values[ind];
00333 oaParam.error_ = errors[ind];
00334 oaParam.quality_ = int (quality[ind]);
00335 oaParam.name_ = names[ind];
00336 oaParam.dim_type_ = dims[ind];
00337 oaInfo.extraEntries_.push_back (oaParam);
00338 oaParam.clear();
00339 }
00340
00341
00342
00343 oaList_.opticalAlignments_.push_back(oaInfo);
00344 } else {
00345 std::cout << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do"
00346 << " not match! Did not add " << nObjects << " item to OpticalAlignments."
00347 << std::endl;
00348 }
00349
00350 if(ALIUtils::debug >= 4) {
00351 std::cout << " CocoaAnalyzer: Fill measurements with read parameters " << std::endl;
00352 }
00353
00354 if ( measNames.size() == measTypes.size() ) {
00355 for ( size_t ind = 0; ind < measNames.size(); ++ind ) {
00356 oaMeas.ID_ = ind;
00357 oaMeas.name_ = measNames[ind];
00358 oaMeas.type_ = measTypes[ind];
00359 oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_];
00360 if( measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size() ) {
00361 for( size_t ind2 = 0; ind2 < measParamNames[oaMeas.name_].size(); ind2++ ){
00362 oaParam.name_ = measParamNames[oaMeas.name_][ind2];
00363 oaParam.value_ = measParamValues[oaMeas.name_][ind2];
00364 oaParam.error_ = measParamSigmas[oaMeas.name_][ind2];
00365 if( oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" || oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM" ) {
00366 oaParam.dim_type_ = "length";
00367 } else if( oaMeas.type_ == "TILTMETER" ) {
00368 oaParam.dim_type_ = "angle";
00369 } else {
00370 std::cerr << "CocoaAnalyzer::ReadXMLFile. Invalid measurement type: " << oaMeas.type_ << std::endl;
00371 std::exception();
00372 }
00373
00374 oaMeas.values_.push_back( oaParam );
00375 oaMeas.isSimulatedValue_.push_back( measIsSimulatedValue[oaMeas.name_][ind2] );
00376 std::cout << oaMeas.name_ << " copying issimu " << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size()-1] << " = " << measIsSimulatedValue[oaMeas.name_][ind2] << std::endl;
00377
00378 oaParam.clear();
00379 }
00380 } else {
00381 std::cout << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do"
00382 << " not match! for measurement " << oaMeas.name_ << " !Did not fill parameters for this measurement " << std::endl;
00383 }
00384 measList_.oaMeasurements_.push_back (oaMeas);
00385 if(ALIUtils::debug >= 5) {
00386 std::cout << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read " << oaMeas << std::endl;
00387 }
00388 oaMeas.clear();
00389 }
00390
00391 } else {
00392 std::cout << "WARNING FOR NOW: sizes of measurements (names, types do"
00393 << " not match! Did not add " << nObjects << " item to XXXMeasurements"
00394 << std::endl;
00395 }
00396
00397
00398
00399
00400
00401
00402 oaInfo.clear();
00403 doCOCOA = fv.next();
00404 }
00405 if(ALIUtils::debug >= 3) {
00406 std::cout << "Finished making " << nObjects+1 << " OpticalAlignInfo objects" << " and " << measList_.oaMeasurements_.size() << " OpticalAlignMeasurementInfo objects " << std::endl;
00407 }
00408 if(ALIUtils::debug >= 5) {
00409 std::cout << " @@@@@@ OpticalAlignments " << oaList_ << std::endl;
00410 std::cout << " @@@@@@ OpticalMeasurements " << measList_ << std::endl;
00411 }
00412
00413 }
00414
00415
00416 std::vector<OpticalAlignInfo> CocoaAnalyzer::ReadCalibrationDB( const edm::EventSetup& evts )
00417 {
00418 using namespace edm::eventsetup;
00419 edm::ESHandle<OpticalAlignments> pObjs;
00420 evts.get<OpticalAlignmentsRcd>().get(pObjs);
00421 const OpticalAlignments* dbObj = pObjs.product();
00422 std::vector<OpticalAlignInfo>::const_iterator it;
00423 for( it=dbObj->opticalAlignments_.begin();it!=dbObj->opticalAlignments_.end(); ++it ){
00424 std::cout<<"@@@@@ OpticalAlignInfo READ "<< *it << std::endl;
00425 }
00426
00427 return dbObj->opticalAlignments_;
00428 }
00429
00430
00431
00432 void CocoaAnalyzer::CorrectOptAlignments( std::vector<OpticalAlignInfo>& oaListCalib )
00433 {
00434 std::vector<OpticalAlignInfo>::const_iterator it;
00435 for( it=oaListCalib.begin();it!=oaListCalib.end(); ++it ){
00436 OpticalAlignInfo oaInfoDB = *it;
00437 OpticalAlignInfo* oaInfoXML = FindOpticalAlignInfoXML( oaInfoDB );
00438 std::cout << " oaInfoXML found " << *oaInfoXML << std::endl;
00439 if( oaInfoXML == 0 ) {
00440 std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: OpticalAlignInfo read from DB is not present in XML "<< *it << std::endl;
00441 } else {
00442
00443 std::cout << " correcting info " << std::endl;
00444 CorrectOaParam( &oaInfoXML->x_, oaInfoDB.x_ );
00445 CorrectOaParam( &oaInfoXML->y_, oaInfoDB.y_ );
00446 CorrectOaParam( &oaInfoXML->z_, oaInfoDB.z_ );
00447 CorrectOaParam( &oaInfoXML->angx_, oaInfoDB.angx_ );
00448 CorrectOaParam( &oaInfoXML->angy_, oaInfoDB.angy_ );
00449 CorrectOaParam( &oaInfoXML->angz_, oaInfoDB.angz_ );
00450 std::vector<OpticalAlignParam>::iterator itoap1, itoap2;
00451 std::vector<OpticalAlignParam> extraEntDB = oaInfoDB.extraEntries_;
00452 std::vector<OpticalAlignParam>* extraEntXML = &(oaInfoXML->extraEntries_);
00453 for( itoap1 = extraEntDB.begin(); itoap1 != extraEntDB.end(); itoap1++ ){
00454 bool pFound = false;
00455
00456 std::string oaName = (*itoap1).name_.substr( 1, (*itoap1).name_.size()-2 );
00457 for( itoap2 = extraEntXML->begin(); itoap2 != extraEntXML->end(); itoap2++ ){
00458 if( oaName == (*itoap2).name_ ) {
00459 CorrectOaParam( &(*itoap2), *itoap1 );
00460 pFound = true;
00461 break;
00462 }
00463 }
00464 if( !pFound ) {
00465 std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: extra enty read from DB is not present in XML "<< *itoap1 << " in object " << *it << std::endl;
00466 }
00467
00468 }
00469 std::cout << " oaInfoXML corrected " << *oaInfoXML << std::endl;
00470 std::cout << " all oaInfo " << oaList_ << std::endl;
00471
00472 }
00473 }
00474
00475 }
00476
00477
00478
00479 OpticalAlignInfo* CocoaAnalyzer::FindOpticalAlignInfoXML( OpticalAlignInfo oaInfo )
00480 {
00481 OpticalAlignInfo* oaInfoXML = 0;
00482 std::vector<OpticalAlignInfo>::iterator it;
00483 for( it=oaList_.opticalAlignments_.begin();it!=oaList_.opticalAlignments_.end(); ++it ){
00484 std::string oaName = oaInfo.name_.substr( 1, oaInfo.name_.size()-2 );
00485 std::cout << "findoaixml " << (*it).name_ << " =? " << oaName << std::endl;
00486 if( (*it).name_ == oaName ) {
00487 oaInfoXML = &(*it);
00488 break;
00489 }
00490 }
00491
00492 return oaInfoXML;
00493 }
00494
00495
00496
00497 bool CocoaAnalyzer::CorrectOaParam( OpticalAlignParam* oaParamXML, OpticalAlignParam oaParamDB )
00498 {
00499 std::cout << " CorrectOaParam " << std::endl;
00500 std::cout << " CorrectOaParam al " << oaParamDB.value_ << std::endl;
00501 if( oaParamDB.value_ == -9.999E9 ) return false;
00502
00503 oaParamXML->value_ = oaParamDB.value_;
00504
00505 return true;
00506
00507 }
00508
00509
00510
00511
00512
00513
00514 void CocoaAnalyzer::RunCocoa()
00515 {
00516
00517
00518
00519
00520 Model& model = Model::getInstance();
00521
00522 model.BuildSystemDescriptionFromOA( oaList_ );
00523
00524 if(ALIUtils::debug >= 3) {
00525 std::cout << "RunCocoa: geometry built " << std::endl;
00526 }
00527
00528 model.BuildMeasurementsFromOA( measList_ );
00529
00530 if(ALIUtils::debug >= 3) {
00531 std::cout << "RunCocoa: measurements built " << std::endl;
00532 }
00533
00534 Fit::getInstance();
00535
00536 Fit::startFit();
00537
00538 if(ALIUtils::debug >= 0) std::cout << "............ program ended OK" << std::endl;
00539 if( ALIUtils::report >=1 ) {
00540 ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() );
00541 fileout << "............ program ended OK" << std::endl;
00542 }
00543
00544 }
00545
00546
00547
00548 void CocoaAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context)
00549 {
00550 return;
00551
00552
00553 using namespace edm::eventsetup;
00554 std::cout <<" I AM IN RUN NUMBER "<<e.id().run() <<std::endl;
00555 std::cout <<" ---EVENT NUMBER "<<e.id().event() <<std::endl;
00556
00557
00558 std::cout << oaList_ << std::endl;
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588 edm::Handle<OpticalAlignMeasurements> measHandle;
00589 e.getByLabel("OptAlignGeneratedSource", measHandle);
00590
00591
00592 std::cout << "========== event data product changes with every event =========" << std::endl;
00593 std::cout << *measHandle << std::endl;
00594
00595
00596
00597
00598
00599
00600 }
00601
00602
00603
00604
00605
00606
00607
00608 double CocoaAnalyzer:: myFetchDbl(const DDsvalues_type& dvst,
00609 const std::string& spName,
00610 const size_t& vecInd ) {
00611 DDValue val(spName, 0.0);
00612 if (DDfetch(&dvst,val)) {
00613 if ( val.doubles().size() > vecInd ) {
00614
00615 return val.doubles()[vecInd];
00616 } else {
00617 std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl;
00618 }
00619 }
00620 return 0.0;
00621 }
00622
00623
00624 std::string CocoaAnalyzer:: myFetchString(const DDsvalues_type& dvst,
00625 const std::string& spName,
00626 const size_t& vecInd ) {
00627 DDValue val(spName, 0.0);
00628 if (DDfetch(&dvst,val)) {
00629 if ( val.strings().size() > vecInd ) {
00630
00631 return val.strings()[vecInd];
00632 } else {
00633 std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl;
00634 }
00635 }
00636 return "";
00637 }
00638
00639
00640
00641
00642 bool CocoaAnalyzer::DumpCocoaResults()
00643 {
00644
00645 OpticalAlignments* myobj=new OpticalAlignments;
00646
00647 static std::vector< OpticalObject* > optolist = Model::OptOList();
00648 static std::vector< OpticalObject* >::const_iterator ite;
00649 for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00650 if( (*ite)->type() == "system" ) continue;
00651 OpticalAlignInfo data = GetOptAlignInfoFromOptO( *ite );
00652 myobj->opticalAlignments_.push_back(data);
00653 std::cout << "@@@@ OPTALIGNINFO WRITTEN TO DB "
00654 << data
00655 << std::endl; }
00656
00657 edm::Service<cond::service::PoolDBOutputService> mydbservice;
00658 if( mydbservice.isAvailable() ){
00659 mydbservice->createNewIOV<OpticalAlignments>(myobj,
00660 mydbservice->endOfTime(),
00661 "OpticalAlignmentsRcd");
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671 }
00672
00673
00674
00675 return TRUE;
00676 }
00677
00678
00679
00680 OpticalAlignInfo CocoaAnalyzer::GetOptAlignInfoFromOptO( OpticalObject* opto )
00681 {
00682 std::cout << " CocoaAnalyzer::GetOptAlignInfoFromOptO " << opto->name() << std::endl;
00683 OpticalAlignInfo data;
00684 data.ID_=opto->cmsSwID();
00685 data.type_=opto->type();
00686 data.name_=opto->name();
00687
00688
00689 Hep3Vector centreLocal = opto->centreGlob() - opto->parent()->centreGlob();
00690 CLHEP::HepRotation parentRmGlobInv = inverseOf( opto->parent()->rmGlob() );
00691 centreLocal = parentRmGlobInv * centreLocal;
00692
00693 const std::vector< Entry* > theCoordinateEntryVector = opto->CoordinateEntryList();
00694 std::cout << " CocoaAnalyzer::GetOptAlignInfoFromOptO starting coord " <<std::endl;
00695
00696 data.x_.value_= centreLocal.x() / 100.;
00697 std::cout << " matrix " << Fit::GetAtWAMatrix() << std::endl;
00698 std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[0]->fitPos() << std::endl;
00699 data.x_.error_= GetEntryError( theCoordinateEntryVector[0] ) / 100.;
00700
00701 data.y_.value_= centreLocal.y() / 100.;
00702 std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[1]->fitPos() << std::endl;
00703 data.y_.error_= GetEntryError( theCoordinateEntryVector[1] ) / 100.;
00704
00705 data.z_.value_= centreLocal.z() / 100.;
00706 std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[2]->fitPos() << std::endl;
00707 data.z_.error_= GetEntryError( theCoordinateEntryVector[2] ) / 100.;
00708
00709
00710 std::vector<double> anglocal = opto->getLocalRotationAngles( theCoordinateEntryVector );
00711
00712 data.angx_.value_= anglocal[0] *180./M_PI;
00713 std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[3]->fitPos() << std::endl;
00714 data.angx_.error_= GetEntryError( theCoordinateEntryVector[3] ) * 180./M_PI;
00715
00716 data.angy_.value_= anglocal[1] * 180./M_PI;
00717 std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[4]->fitPos() << std::endl;
00718 data.angy_.error_= GetEntryError( theCoordinateEntryVector[4] ) * 180./M_PI;
00719
00720 data.angz_.value_= anglocal[2] *180./M_PI;
00721 std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[5]->fitPos() << std::endl;
00722 data.angz_.error_= GetEntryError( theCoordinateEntryVector[5] ) * 180./M_PI;
00723
00724
00725 const std::vector< Entry* > theExtraEntryVector = opto->ExtraEntryList(); std::cout << " CocoaAnalyzer::GetOptAlignInfoFromOptO starting entry " << std::endl;
00726
00727 std::vector< Entry* >::const_iterator ite;
00728 for( ite = theExtraEntryVector.begin(); ite != theExtraEntryVector.end(); ite++ ) {
00729 OpticalAlignParam extraEntry;
00730 extraEntry.name_ = (*ite)->name();
00731 extraEntry.dim_type_ = (*ite)->type();
00732 extraEntry.value_ = (*ite)->value();
00733 extraEntry.error_ = (*ite)->sigma();
00734 extraEntry.quality_ = (*ite)->quality();
00735 data.extraEntries_.push_back( extraEntry );
00736 std::cout << " CocoaAnalyzer::GetOptAlignInfoFromOptO done extra entry " << extraEntry.name_ << std::endl;
00737
00738 }
00739
00740 return data;
00741 }
00742
00743
00744 double CocoaAnalyzer::GetEntryError( const Entry* entry )
00745 {
00746 if( entry->quality() > 0 ) {
00747 return sqrt(Fit::GetAtWAMatrix()->Mat()->me[entry->fitPos()][entry->fitPos()]) / 100.;
00748 } else {
00749 return entry->sigma();
00750 }
00751 }
00752