CMS 3D CMS Logo

CocoaAnalyzer Class Reference

#include <Alignment/CocoaApplication/interface/CocoaAnalyzer.h>

Inheritance diagram for CocoaAnalyzer:

edm::EDAnalyzer

List of all members.

Public Member Functions

virtual void analyze (const edm::Event &e, const edm::EventSetup &c)
virtual void beginJob (const edm::EventSetup &c)
 CocoaAnalyzer (int i)
 CocoaAnalyzer (edm::ParameterSet const &p)
virtual ~CocoaAnalyzer ()

Private Member Functions

bool CorrectOaParam (OpticalAlignParam *oaParamXML, OpticalAlignParam oaParamDB)
void CorrectOptAlignments (std::vector< OpticalAlignInfo > &oaListCalib)
bool DumpCocoaResults ()
OpticalAlignInfoFindOpticalAlignInfoXML (OpticalAlignInfo oaInfo)
double GetEntryError (const Entry *entry)
OpticalAlignInfo GetOptAlignInfoFromOptO (OpticalObject *opto)
double myFetchDbl (const DDsvalues_type &dvst, const std::string &spName, const size_t &vecInd)
std::string myFetchString (const DDsvalues_type &dvst, const std::string &spName, const size_t &vecInd)
std::vector< OpticalAlignInfoReadCalibrationDB (const edm::EventSetup &evts)
void ReadXMLFile (const edm::EventSetup &evts)
void RunCocoa ()

Private Attributes

OpticalAlignMeasurements measList_
OpticalAlignments oaList_
std::string theCocoaDaqRootFileName


Detailed Description

Definition at line 42 of file CocoaAnalyzer.h.


Constructor & Destructor Documentation

CocoaAnalyzer::CocoaAnalyzer ( edm::ParameterSet const &  p  )  [explicit]

Definition at line 31 of file CocoaAnalyzer.cc.

References edm::ParameterSet::getParameter(), and theCocoaDaqRootFileName.

00032 {
00033   theCocoaDaqRootFileName = pset.getParameter< std::string >("cocoaDaqRootFile");
00034 }

CocoaAnalyzer::CocoaAnalyzer ( int  i  )  [inline, explicit]

Definition at line 47 of file CocoaAnalyzer.h.

00047 { }

virtual CocoaAnalyzer::~CocoaAnalyzer (  )  [inline, virtual]

Definition at line 48 of file CocoaAnalyzer.h.

00048 { }


Member Function Documentation

void CocoaAnalyzer::analyze ( const edm::Event e,
const edm::EventSetup c 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 548 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), edm::Event::getByLabel(), edm::Event::id(), and oaList_.

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   // just a quick dump of the private OpticalAlignments object
00558   std::cout << oaList_ << std::endl;
00559  
00560   // STEP 2:
00561   // Get calibrated OpticalAlignments.  In this case I'm using
00562   // some sqlite database examples that are generated using
00563   // testOptAlignWriter.cc
00564   // from CondFormats/OptAlignObjects/test/
00565 
00566 //   edm::ESHandle<OpticalAlignments> oaESHandle;
00567 //   context.get<OpticalAlignmentsRcd>().get(oaESHandle);
00568 
00569 //   // This assumes they ALL come in together.  This may not be
00570 //   // the "real" case.  One could envision different objects coming
00571 //   // in and we would get by label each one (type).
00572 
00573 //   std::cout << "========== eventSetup data changes with IOV =========" << std::endl;
00574 //   std::cout << *oaESHandle << std::endl;
00575 //   //============== COCOA WORK!
00576 //   //  calibrated values should be used to "correct" the ones read in during beginJob
00577 //   //==============
00578   
00579 //   // 
00580 //   // to see how to iterate over the OpticalAlignments, please
00581 //   // refer to the << operator of OpticalAlignments, OpticalAlignInfo
00582 //   // and OpticalAlignParam.
00583 //   //     const OpticalAlignments* myoa=oa.product();
00584   
00585 //   // STEP 3:
00586 //   // This retrieves the Measurements
00587 //   // for each event, a new set of measurements is available.
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   //============== COCOA WORK!
00596   //  Each set of optical alignment measurements can be used
00597   //  in whatever type of analysis COCOA does. 
00598   //==============
00599 
00600 } //end of ::analyze()

void CocoaAnalyzer::beginJob ( const edm::EventSetup c  )  [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 37 of file CocoaAnalyzer.cc.

References CorrectOptAlignments(), DumpCocoaResults(), ReadCalibrationDB(), ReadXMLFile(), RunCocoa(), and theCocoaDaqRootFileName.

00038 {
00039   ReadXMLFile( evts );
00040 
00041   std::vector<OpticalAlignInfo> oaListCalib = ReadCalibrationDB( evts );
00042 
00043   CorrectOptAlignments( oaListCalib );
00044 
00045   new CocoaDaqReaderRoot( theCocoaDaqRootFileName );
00046  
00047   /*-
00048   int nEvents = daqReader->GetNEvents();
00049   for( int ii = 0; ii < nEvents; ii++) {
00050     if( ! daqReader->ReadEvent( ii ) ) break;
00051   }
00052   */ 
00053 
00054   RunCocoa();
00055 
00056   //  std::cout << "!!!! NOT  DumpCocoaResults() " << std::endl;  
00057 
00058   DumpCocoaResults();  
00059 }

bool CocoaAnalyzer::CorrectOaParam ( OpticalAlignParam oaParamXML,
OpticalAlignParam  oaParamDB 
) [private]

Definition at line 497 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and OpticalAlignParam::value_.

Referenced by CorrectOptAlignments().

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 }

void CocoaAnalyzer::CorrectOptAlignments ( std::vector< OpticalAlignInfo > &  oaListCalib  )  [private]

Definition at line 432 of file CocoaAnalyzer.cc.

References OpticalAlignInfo::angx_, OpticalAlignInfo::angy_, OpticalAlignInfo::angz_, TestMuL1L2Filter_cff::cerr, CorrectOaParam(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), OpticalAlignInfo::extraEntries_, FindOpticalAlignInfoXML(), it, oaList_, OpticalAlignInfo::x_, OpticalAlignInfo::y_, and OpticalAlignInfo::z_.

Referenced by beginJob().

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       //------ Correct info       
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         //----- Look fot the extra parameter in XML oaInfo that has the same name
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 }

bool CocoaAnalyzer::DumpCocoaResults (  )  [private]

Definition at line 642 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, data, lat::endl(), GetOptAlignInfoFromOptO(), edm::Service< T >::isAvailable(), OpticalAlignments::opticalAlignments_, Model::OptOList(), and TRUE.

Referenced by beginJob().

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        /*? compilation error??
00663     }catch(const cond::Exception& er){
00664       std::cout<<er.what()<<std::endl;
00665     }catch(const std::exception& er){
00666       std::cout<<"caught std::exception "<<er.what()<<std::endl;
00667     }catch(...){
00668       std::cout<<"Funny error"<<std::endl;
00669     }
00670        */
00671   }
00672 
00673   //? gives unreadable error???  std::cout << "@@@@ OPTICALALIGNMENTS WRITTEN TO DB " << *myobj << std::endl;
00674 
00675   return TRUE;
00676 }

OpticalAlignInfo * CocoaAnalyzer::FindOpticalAlignInfoXML ( OpticalAlignInfo  oaInfo  )  [private]

Definition at line 479 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), it, OpticalAlignInfo::name_, oaList_, and OpticalAlignments::opticalAlignments_.

Referenced by CorrectOptAlignments().

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 }

double CocoaAnalyzer::GetEntryError ( const Entry entry  )  [private]

Definition at line 744 of file CocoaAnalyzer.cc.

References Entry::fitPos(), Fit::GetAtWAMatrix(), me, Entry::quality(), Entry::sigma(), and funct::sqrt().

Referenced by GetOptAlignInfoFromOptO().

00745 {
00746   if( entry->quality() > 0 ) {
00747     return sqrt(Fit::GetAtWAMatrix()->Mat()->me[entry->fitPos()][entry->fitPos()]) / 100.;
00748   } else { //entry not fitted, return original error
00749     return entry->sigma();
00750   }
00751 }

OpticalAlignInfo CocoaAnalyzer::GetOptAlignInfoFromOptO ( OpticalObject opto  )  [private]

Definition at line 680 of file CocoaAnalyzer.cc.

References OpticalAlignInfo::angx_, OpticalAlignInfo::angy_, OpticalAlignInfo::angz_, OpticalObject::centreGlob(), OpticalObject::cmsSwID(), OpticalObject::CoordinateEntryList(), GenMuonPlsPt100GeV_cfg::cout, data, OpticalAlignParam::dim_type_, lat::endl(), OpticalAlignParam::error_, OpticalAlignInfo::extraEntries_, OpticalObject::ExtraEntryList(), Fit::GetAtWAMatrix(), GetEntryError(), OpticalObject::getLocalRotationAngles(), OpticalAlignInfo::ID_, MatrixMeschach::Mat(), OpticalObject::name(), OpticalAlignInfo::name_, OpticalAlignParam::name_, OpticalObject::parent(), OpticalAlignParam::quality_, OpticalObject::rmGlob(), OpticalObject::type(), OpticalAlignInfo::type_, OpticalAlignParam::value_, OpticalAlignInfo::x_, OpticalAlignInfo::y_, and OpticalAlignInfo::z_.

Referenced by DumpCocoaResults().

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   //----- Centre in local coordinates
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.; // in cm
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.; // in cm
00700 
00701   data.y_.value_= centreLocal.y() / 100.; // in cm
00702   std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat()  << " " << theCoordinateEntryVector[1]->fitPos() << std::endl;
00703   data.y_.error_= GetEntryError( theCoordinateEntryVector[1] ) / 100.; // in cm
00704 
00705   data.z_.value_= centreLocal.z() / 100.; // in cm
00706   std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat()  << " " << theCoordinateEntryVector[2]->fitPos() << std::endl;
00707   data.z_.error_= GetEntryError( theCoordinateEntryVector[2] ) / 100.; // in cm
00708 
00709   //----- angles in local coordinates
00710   std::vector<double> anglocal = opto->getLocalRotationAngles( theCoordinateEntryVector );
00711 
00712   data.angx_.value_= anglocal[0] *180./M_PI; // in deg
00713   std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[3]->fitPos() << std::endl;
00714   data.angx_.error_= GetEntryError( theCoordinateEntryVector[3] ) * 180./M_PI; // in deg;
00715 
00716   data.angy_.value_= anglocal[1] * 180./M_PI; // in deg
00717   std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[4]->fitPos() << std::endl;
00718   data.angy_.error_= GetEntryError( theCoordinateEntryVector[4] ) * 180./M_PI; // in deg;;
00719 
00720   data.angz_.value_= anglocal[2] *180./M_PI; // in deg
00721   std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[5]->fitPos() << std::endl;
00722   data.angz_.error_= GetEntryError( theCoordinateEntryVector[5] ) * 180./M_PI; // in deg;
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 }

double CocoaAnalyzer::myFetchDbl ( const DDsvalues_type dvst,
const std::string &  spName,
const size_t &  vecInd 
) [private]

Definition at line 608 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, DDfetch(), DDValue::doubles(), and lat::endl().

Referenced by ReadXMLFile().

00610                                                              {
00611   DDValue val(spName, 0.0);
00612   if (DDfetch(&dvst,val)) {
00613     if ( val.doubles().size() > vecInd ) {
00614       //          std::cout << "about to return: " << val.doubles()[vecInd] << std::endl;
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 }

std::string CocoaAnalyzer::myFetchString ( const DDsvalues_type dvst,
const std::string &  spName,
const size_t &  vecInd 
) [private]

Definition at line 624 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, DDfetch(), lat::endl(), and DDValue::strings().

Referenced by ReadXMLFile().

00626                                                              {
00627   DDValue val(spName, 0.0);
00628   if (DDfetch(&dvst,val)) {
00629     if ( val.strings().size() > vecInd ) {
00630       //          std::cout << "about to return: " << val.doubles()[vecInd] << std::endl;
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 }

std::vector< OpticalAlignInfo > CocoaAnalyzer::ReadCalibrationDB ( const edm::EventSetup evts  )  [private]

Definition at line 416 of file CocoaAnalyzer.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), edm::EventSetup::get(), it, OpticalAlignments::opticalAlignments_, and edm::ESHandle< T >::product().

Referenced by beginJob().

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 }

void CocoaAnalyzer::ReadXMLFile ( const edm::EventSetup evts  )  [private]

Definition at line 62 of file CocoaAnalyzer.cc.

References DDExpandedNode::absRotation(), DDExpandedNode::absTranslation(), DDFilteredView::addFilter(), DDSpecificsFilter::AND, OpticalAlignInfo::angx_, OpticalAlignInfo::angy_, OpticalAlignInfo::angz_, TestMuL1L2Filter_cff::cerr, OpticalAlignInfo::clear(), OpticalAlignParam::clear(), OpticalAlignMeasurementInfo::clear(), GenMuonPlsPt100GeV_cfg::cout, ALIUtils::debug, OpticalAlignParam::dim_type_, lat::endl(), OpticalAlignParam::error_, HLT_VtxMuL3::errors, exception, OpticalAlignInfo::extraEntries_, filter, DDFilteredView::firstChild(), DDFilteredView::geoHistory(), edm::EventSetup::get(), ALIUtils::getRotationAnglesFromMatrix(), icol, OpticalAlignInfo::ID_, OpticalAlignMeasurementInfo::ID_, int, OpticalAlignMeasurementInfo::isSimulatedValue_, DDFilteredView::logicalPart(), lv, DDSpecificsFilter::matches, measList_, OpticalAlignMeasurementInfo::measObjectNames_, DDFilteredView::mergedSpecifics(), myFetchDbl(), myFetchString(), name, DDBase< N, C >::name(), OpticalAlignInfo::name_, OpticalAlignParam::name_, OpticalAlignMeasurementInfo::name_, names, DDFilteredView::next(), oaList_, OpticalAlignMeasurements::oaMeasurements_, OpticalAlignments::opticalAlignments_, params, dbtoconf::parent, OpticalAlignInfo::parentName_, OpticalAlignParam::quality_, rot, DDFilteredView::rotation(), DDSpecificsFilter::setCriteria(), ALIUtils::setDebugVerbosity(), DDFilteredView::specifics(), DDFilteredView::translation(), OpticalAlignInfo::type_, OpticalAlignMeasurementInfo::type_, value, OpticalAlignParam::value_, values, OpticalAlignMeasurementInfo::values_, OpticalAlignInfo::x_, OpticalAlignInfo::y_, and OpticalAlignInfo::z_.

Referenced by beginJob().

00063 {
00064 
00065   ALIUtils::setDebugVerbosity( 5 );
00066 
00067   // STEP ONE:  Initial COCOA objects will be built from a DDL geometry
00068   // description.  
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   //Build OpticalAlignInfo "system"
00078   const DDLogicalPart lv = cpv->root();
00079   
00080   OpticalAlignInfo oaInfo;
00081   oaInfo.ID_ = 0;
00082   //--- substract file name to object name
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   // Example of traversing the whole optical alignment geometry.
00113   // At each node we get specpars as variables and use them in 
00114   // constructing COCOA objects. 
00115   //  It stores these objects in a private data member, opt
00116   std::string attribute = "COCOA"; 
00117   std::string value     = "COCOA";
00118   DDValue val(attribute, value, 0.0);
00119   
00120           // get all parts labelled with COCOA using a SpecPar
00121   DDSpecificsFilter filter;
00122   filter.setCriteria(val,  // name & value of a variable 
00123                      DDSpecificsFilter::matches,
00124                      DDSpecificsFilter::AND, 
00125                      true, // compare strings otherwise doubles
00126                      true  // use merged-specifics or simple-specifics
00127                      );
00128   DDFilteredView fv(*cpv);
00129   fv.addFilter(filter);
00130   bool doCOCOA = fv.firstChild();
00131   
00132   // Loop on parts
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  //    oaInfo.parentName_ = (fv.geoHistory()[fv.geoHistory().size()-2]).logicalPart().name();
00157 //    icol = oaInfo.parentName_.find(":");
00158  //   oaInfo.parentName_ = oaInfo.parentName_.substr(icol+1,oaInfo.parentName_.length());
00159     }
00160 
00161     //--- build object name (= parent name + object name)
00162     std::string name = history[ii].logicalPart().name();
00163     //--- substract file name to object name
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     //----- Read centre and angles
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(); //DDL uses opposite convention than COCOA
00179     /*    if(ALIUtils::debug >= 4) {
00180       ALIUtils::dumprm( rot, "local rotation ");
00181       ALIUtils::dump3v( transl, "local translation");
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   //---- DDD convention is to use the inverse matrix, COCOA is the direct one!!!
00203     //---- convert it to CLHEP::Matrix
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     //-    oaInfo.angx_.value_ = angles[0];
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     //-    oaInfo.angy_.value_ = angles[1];
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     //    oaInfo.angz_.value_ = angles[2];
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     //----- Read extra entries and measurements
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     //--- extra entries variables
00255     std::vector<std::string> names, dims;
00256     std::vector<double> values, errors, quality;
00257     //--- measurements variables
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           //-     std::cout << " meas_name found " << std::endl;
00283           measNames = sit->second.strings();
00284         } else if (sit->second.name() == "meas_type") {
00285           //- std::cout << " meas_type found " << std::endl;
00286           measTypes = sit->second.strings();
00287         }
00288         
00289       }
00290     }
00291 
00292     //---- loop again to look for the measurement object names, that have the meas name in the SpecPar title 
00293     //    <Parameter name="meas_object_name_SENSOR2D:OCMS/sens2" value="OCMS/laser1"  eval="false" /> 
00294     //   <Parameter name="meas_object_name_SENSOR2D:OCMS/sens2" value="OCMS/sens2"  eval="false" /> 
00295 
00296     std::vector<std::string>::iterator vsite;
00297     for ( spit = params2.begin(); spit != params2.end(); ++spit ) {
00298       //-  std::cout << "loop vector DDsvalues " << std::endl;
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           //- std::cout << "looping measObjectNames " << *vsite << std::endl;
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(); // this is not in OptAlignParam info
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     //--- Fill extra entries with read parameters    
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       //t      std::cout << names.size() << " OBJECT " << oaInfo.name_ << " extra entries read " << oaInfo << std::endl;
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     //--- Fill measurements with read parameters    
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             //-           std::cout << ind2 << " adding meas value " << oaParam << std::endl;
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 //       std::cout << "sizes are values=" << values.size();
00398 //       std::cout << "  sigma(errors)=" << errors.size();
00399 //       std::cout << "  quality=" << quality.size();
00400 //       std::cout << "  names=" << names.size();
00401 //       std::cout << "  dimType=" << dims.size() << std::endl;
00402     oaInfo.clear();
00403     doCOCOA = fv.next(); // go to next part
00404   } // while (doCOCOA)
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 }

void CocoaAnalyzer::RunCocoa (  )  [private]

Definition at line 514 of file CocoaAnalyzer.cc.

References Model::BuildMeasurementsFromOA(), Model::BuildSystemDescriptionFromOA(), GenMuonPlsPt100GeV_cfg::cout, ALIUtils::debug, lat::endl(), Fit::getInstance(), ALIFileOut::getInstance(), Model::getInstance(), measList_, oaList_, ALIUtils::report, Model::ReportFName(), and Fit::startFit().

Referenced by beginJob().

00515 {
00516   //-ALIFileIn fin;
00517   //-  GlobalOptionMgr::getInstance()->setGlobalOption("debug_verbose",5, fin );
00518 
00519   //---------- Build the Model out of the system description text file
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 } // end of ::beginJob


Member Data Documentation

OpticalAlignMeasurements CocoaAnalyzer::measList_ [private]

Definition at line 78 of file CocoaAnalyzer.h.

Referenced by ReadXMLFile(), and RunCocoa().

OpticalAlignments CocoaAnalyzer::oaList_ [private]

Definition at line 77 of file CocoaAnalyzer.h.

Referenced by analyze(), CorrectOptAlignments(), FindOpticalAlignInfoXML(), ReadXMLFile(), and RunCocoa().

std::string CocoaAnalyzer::theCocoaDaqRootFileName [private]

Definition at line 79 of file CocoaAnalyzer.h.

Referenced by beginJob(), and CocoaAnalyzer().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:16:25 2009 for CMSSW by  doxygen 1.5.4