Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:23

0001 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
0002 #include "Alignment/CocoaModel/interface/EntryMgr.h"
0003 #include "Alignment/CocoaModel/interface/EntryData.h"
0004 
0005 void printDiffErrors( std::vector<EntryData*>& entries1, std::vector<EntryData*>& entries2 );
0006 void printDiffValues( std::vector<EntryData*>& entries1, std::vector<EntryData*>& entries2 );
0007 EntryData* findEntryUnk( EntryData* entry1, std::vector<EntryData*> entries2 );
0008 
0009 int main( int argc, char** argv )
0010 {
0011 
0012   if( argc < 3 ) {
0013     std::cerr << "!!ERROR: Must supply at least two arguments: old_file new_file (diffValues_Yes)" << std::endl;
0014     exit(1);
0015   }
0016 
0017   ALIFileIn& fin1 = ALIFileIn::getInstance(argv[1]);
0018   std::cout << " file 1 opened " << argv[1] << std::endl;
0019   ALIFileIn& fin2 = ALIFileIn::getInstance(argv[2]);
0020   std::cout << " file 2 opened " << argv[2] << std::endl;
0021   
0022   EntryMgr* entrymgr = EntryMgr::getInstance();   
0023   std::vector<ALIstring> wordlist;
0024   while (!fin1.eof()) {
0025     if( !fin1.getWordsInLine(wordlist) ) break;  //----- Read line
0026     entrymgr->readEntryFromReportOut( wordlist );
0027 //    std::cout << "N entries1 " << entrymgr->numberOfEntries() << std::endl;
0028   }
0029   std::cout << "TOTAL N entries1 " << entrymgr->numberOfEntries() << std::endl;
0030 
0031   std::vector<EntryData*> entries1 = entrymgr->getEntryData();
0032   entrymgr->clearEntryData();
0033 
0034   while (!fin2.eof()) {
0035     if( !fin2.getWordsInLine(wordlist) ) break;  //----- Read line
0036     entrymgr->readEntryFromReportOut( wordlist );
0037     //    std::cout << "N entries2 " << entrymgr->numberOfEntries() << std::endl;
0038   }
0039   std::cout << "TOTAL N entries2 " << entrymgr->numberOfEntries() << std::endl;
0040 
0041   std::vector<EntryData*> entries2 = entrymgr->getEntryData();
0042   entrymgr->clearEntryData();
0043 
0044   std::cout << " argc " << argc << " " << argv[3] << "ZZ" << std::endl;
0045   bool bVal = 0;
0046   if( argc == 4 ) {
0047     if( atof(argv[3]) == 1 ) {
0048       bVal = 1;
0049     }
0050   }
0051   std::cout << " argc " << argc << " " << argv[3] << "ZZ" << std::endl;
0052   if( bVal ){
0053     printDiffValues( entries1, entries2 );
0054   } else {
0055     printDiffErrors( entries1, entries2 );
0056   }
0057 }
0058 
0059 
0060 //-----------------------------------------------------------------
0061 void printDiffErrors( std::vector<EntryData*>& entries1, std::vector<EntryData*>& entries2 )
0062 {
0063   std::vector<EntryData*>::const_iterator ite1;
0064   for( ite1 = entries1.begin(); ite1 != entries1.end(); ++ite1 ) {
0065     EntryData* entry1 = *ite1;
0066     if( (entry1)->quality() == 2 ) {
0067       EntryData* entry2 = findEntryUnk( entry1, entries2 );
0068       if( entry2 == 0 ) { 
0069     std::cerr << " !!! WARNING Entry not found in second file " << *entry1 << std::endl;
0070       } else {
0071     double sigmadiff;
0072     double sigma1 = entry1->sigma();
0073     double sigma2 = entry2->sigma();
0074     if( sigma1 < sigma2 ){
0075       sigmadiff = sqrt( sigma2*sigma2 - sigma1*sigma1 );
0076     } else {
0077       sigmadiff = -sqrt( -sigma2*sigma2 + sigma1*sigma1 );
0078     }
0079     std::cout << " ENTRY DIFF_ERROR: " << sigmadiff << "  " << entry1->longOptOName() << " " << entry1->entryName() << " " << entry1->valueOriginal()+entry1->valueDisplacement() << "  +-(1) " << sigma1 << "  +-(2) " << sigma2 << std::endl;
0080       }
0081     }
0082   }
0083 
0084 }
0085 
0086 //-----------------------------------------------------------------
0087 void printDiffValues( std::vector<EntryData*>& entries1, std::vector<EntryData*>& entries2 )
0088 {
0089   std::vector<EntryData*>::const_iterator ite1;
0090   for( ite1 = entries1.begin(); ite1 != entries1.end(); ++ite1 ) {
0091     EntryData* entry1 = *ite1;
0092     if( (entry1)->quality() == 2 ) {
0093       EntryData* entry2 = findEntryUnk( entry1, entries2 );
0094       if( entry2 == 0 ) { 
0095     std::cerr << " !!! WARNING Entry not found in second file " << *entry1 << std::endl;
0096       } else {
0097     double val1 = entry1->valueOriginal() + entry1->valueDisplacement();
0098     double val2 = entry2->valueOriginal() + entry2->valueDisplacement();
0099     std::cout << " ENTRY DIFF: " << val2 - val1 << "  " << entry1->longOptOName() << " " << entry1->entryName() << "  VAL(1) " << val1  << "  VAL(2) " << val2 << std::endl;
0100       }
0101     }
0102   }
0103 
0104 }
0105 
0106 //-----------------------------------------------------------------
0107 EntryData* findEntryUnk( EntryData* entry1, std::vector<EntryData*> entries2 )
0108 {
0109 
0110   std::vector<EntryData*>::const_iterator ite2;
0111   for( ite2 = entries2.begin(); ite2 != entries2.end(); ++ite2 ) {
0112     EntryData* entry2 = *ite2;
0113     if( entry2->longOptOName() == entry1->longOptOName() 
0114     && entry2->entryName() == entry1->entryName() ){
0115       return entry2;
0116     }
0117   }
0118 
0119   return 0;
0120 
0121 }