Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-21 02:53:37

0001 // **************** Validation Macro *******************
0002 // * This macro compares the new and reference files   *
0003 // * map detid,x,y,z with navtype                      *
0004 // * for each navtype checks if detid,x,y,z correspond *
0005 // *   written by rranieri 22 Feb 2007                 *
0006 // *****************************************************
0007 
0008 // include files
0009 #include <iostream>
0010 #include <iomanip>
0011 #include <map>
0012 
0013 //
0014 Double_t tolerance = 0.0001; // 0.1 um is enough!
0015 //
0016 
0017 // maps to compare detid-navtype
0018 std::map< std::string , Int_t > theNewMapNavTypeToDetId;
0019 std::map< std::string , Int_t > theReferenceMapNavTypeToDetId;
0020 //
0021 // maps to compare position-navtype
0022 std::map< std::string , Double_t > theNewMapNavTypeToGlobalPosition_X;
0023 std::map< std::string , Double_t > theNewMapNavTypeToGlobalPosition_Y;
0024 std::map< std::string , Double_t > theNewMapNavTypeToGlobalPosition_Z;
0025 //
0026 std::map< std::string , Double_t > theReferenceMapNavTypeToGlobalPosition_X;
0027 std::map< std::string , Double_t > theReferenceMapNavTypeToGlobalPosition_Y;
0028 std::map< std::string , Double_t > theReferenceMapNavTypeToGlobalPosition_Z;
0029 //
0030 
0031 // Main
0032 TrackerNumberingComparison( TString newFileName , TString referenceFileName , TString outputFileName) {
0033   // open files
0034   std::ifstream theNewFile;
0035   theNewFile.open(newFileName);
0036   std::ifstream theReferenceFile;
0037   theReferenceFile.open(referenceFileName);
0038   // output file
0039   std::ofstream theOutputFile;
0040   theOutputFile.open(outputFileName);
0041   theOutputFile 
0042     << std::setprecision(4)
0043     << std::fixed;
0044   //
0045   
0046   // filling the maps
0047   Int_t detid;
0048   detid = 0;
0049   std::string navType;
0050   Double_t x,y,z;
0051   x=y=z=0.0000;
0052   //
0053   //  std::cout << " Reading " << newFileName << " ..." << std::endl;
0054   while(!theNewFile.eof()) {
0055     //
0056     theNewFile >> detid
0057            >> navType
0058            >> x >> y >> z;
0059     //
0060     //    std::std::cout << "New: load " << detid  << " " << navType << std::endl;
0061     //
0062     theNewMapNavTypeToDetId[navType] = detid;
0063     theNewMapNavTypeToGlobalPosition_X[navType] = x;
0064     theNewMapNavTypeToGlobalPosition_Y[navType] = y;
0065     theNewMapNavTypeToGlobalPosition_Z[navType] = z;
0066     //
0067   }
0068   //  std::cout << " ... done" << std::endl;
0069   //
0070   //  std::cout << " Reading " << referenceFileName << " ..." << std::endl;
0071   while(!theReferenceFile.eof()) {
0072     //
0073     theReferenceFile >> detid
0074            >> navType
0075            >> x >> y >> z;
0076     //
0077     //    std::std::cout << "Reference: load " << detid  << " " << navType << std::endl;
0078     //
0079     theReferenceMapNavTypeToDetId[navType] = detid;
0080     theReferenceMapNavTypeToGlobalPosition_X[navType] = x;
0081     theReferenceMapNavTypeToGlobalPosition_Y[navType] = y;
0082     theReferenceMapNavTypeToGlobalPosition_Z[navType] = z;
0083     //
0084   }
0085   //  std::cout << " ... done" << std::endl;
0086   //  
0087   
0088   // Compare the two maps
0089   // size
0090   //  std::cout << " Size of the maps: " << std::endl;
0091   //  std::cout << " Reference = " << theReferenceMapNavTypeToDetId.size() << std::endl;
0092   //  std::cout << "     New   = " << theNewMapNavTypeToDetId.size()       << std::endl;
0093   if(theNewMapNavTypeToDetId.size() != theReferenceMapNavTypeToDetId.size()) {
0094     theOutputFile << "ERROR: The size of the two detid-navtype maps is different" << std::endl;
0095     theOutputFile << " Reference = " << theReferenceMapNavTypeToDetId.size()      << std::endl;
0096     theOutputFile << "     New   = " << theNewMapNavTypeToDetId.size()            << std::endl;
0097   }
0098   if(theNewMapNavTypeToGlobalPosition_X.size() != theReferenceMapNavTypeToGlobalPosition_X.size()) {
0099     theOutputFile << "ERROR: The size of the two X-navtype maps is different"  << std::endl;
0100     theOutputFile << " Reference = " << theReferenceMapNavTypeToGlobalPosition_X.size() << std::endl;
0101     theOutputFile << "     New   = " << theNewMapNavTypeToGlobalPosition_X.size()       << std::endl;
0102   }
0103   if(theNewMapNavTypeToGlobalPosition_Y.size() != theReferenceMapNavTypeToGlobalPosition_Y.size()) {
0104     theOutputFile << "ERROR: The size of the two Y-navtype maps is different"  << std::endl;
0105     theOutputFile << " Reference = " << theReferenceMapNavTypeToGlobalPosition_Y.size() << std::endl;
0106     theOutputFile << "     New   = " << theNewMapNavTypeToGlobalPosition_Y.size()       << std::endl;
0107   }
0108   if(theNewMapNavTypeToGlobalPosition_Z.size() != theReferenceMapNavTypeToGlobalPosition_Z.size()) {
0109     theOutputFile << "ERROR: The size of the two Z-navtype maps is different"  << std::endl;
0110     theOutputFile << " Reference = " << theReferenceMapNavTypeToGlobalPosition_Z.size() << std::endl;
0111     theOutputFile << "     New   = " << theNewMapNavTypeToGlobalPosition_Z.size()       << std::endl;
0112   }
0113   // compare the detid-navtype maps
0114   for( std::map< std::string , Int_t >::iterator iMap = theReferenceMapNavTypeToDetId.begin();
0115        iMap != theReferenceMapNavTypeToDetId.end(); iMap++ ) {
0116     //    std::cout << " reference: " << " detid " << (*iMap).second << " navtype " << (*iMap).first << std::endl;
0117     //    std::cout << "   new:     " << " detid " << theNewMapNavTypeToDetId[(*iMap).first] << " navtype " << (*iMap).first << std::endl;
0118     Int_t referenceDetId = (*iMap).second;
0119     std::string navType  = (*iMap).first;
0120     Int_t newDetId       = theNewMapNavTypeToDetId[navType];
0121     if( referenceDetId != newDetId ) {
0122       theOutputFile << "ERROR: The detid's associated to the same navtype do not correspond"   << std::endl;
0123       theOutputFile << " reference: " << " detid " << referenceDetId << " navtype " << navType << std::endl;
0124       theOutputFile << "   new:     " << " detid " << newDetId       << " navtype " << navType << std::endl;
0125     }
0126   }
0127   //
0128   // compare the position-navtype maps
0129   for( std::map< std::string , Int_t >::iterator iMap = theReferenceMapNavTypeToDetId.begin();
0130        iMap != theReferenceMapNavTypeToDetId.end(); iMap++ ) {
0131     //
0132     std::string navType = (*iMap).first;
0133     //
0134     Double_t referenceX = theReferenceMapNavTypeToGlobalPosition_X[navType];
0135     Double_t referenceY = theReferenceMapNavTypeToGlobalPosition_Y[navType];
0136     Double_t referenceZ = theReferenceMapNavTypeToGlobalPosition_Z[navType];
0137     Double_t newX       = theNewMapNavTypeToGlobalPosition_X[navType];
0138     Double_t newY       = theNewMapNavTypeToGlobalPosition_Y[navType];
0139     Double_t newZ       = theNewMapNavTypeToGlobalPosition_Z[navType];
0140     //
0141     /*    std::cout << " reference: "
0142       << " x = "     << referenceX
0143       << " y = "     << referenceY
0144       << " z = "     << referenceZ
0145       << " navtype " << navType
0146       << std::endl;
0147       std::cout << "   new:     "
0148       << " x = "     << newX
0149       << " y = "     << newY
0150       << " z = "     << newZ
0151       << " navtype " << navType
0152       << std::endl;
0153     */
0154     //
0155     if( fabs(referenceX-newX) > tolerance
0156     ||
0157     fabs(referenceY-newY) > tolerance
0158     ||
0159     fabs(referenceZ-newZ) > tolerance ) {
0160       theOutputFile << "ERROR: The positions associated to the same navtype do not correspond" << std::endl;
0161       theOutputFile 
0162     << " reference: "
0163     << " x = "     << referenceX
0164     << " y = "     << referenceY
0165     << " z = "     << referenceZ
0166     << " navtype " << navType
0167     << std::endl;
0168       theOutputFile
0169     << "   new:     "
0170     << " x = "     << newX
0171     << " y = "     << newY
0172     << " z = "     << newZ
0173     << " navtype " << navType
0174     << std::endl;
0175     }
0176     //
0177   }
0178   //
0179 }