CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Alignment/OfflineValidation/plugins/TrackerGeometryCompare.cc

Go to the documentation of this file.
00001 #include "CondFormats/Alignment/interface/Alignments.h"
00002 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00003 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h" 
00004 #include "CondFormats/Alignment/interface/Definitions.h" 
00005 #include "CLHEP/Vector/RotationInterfaces.h" 
00006 #include "CondFormats/Alignment/interface/AlignmentSorter.h"
00007 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyRcd.h"
00008 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyErrorRcd.h"
00009 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00010 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00011 #include "FWCore/Framework/interface/MakerMacros.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Framework/interface/ESTransientHandle.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
00018 #include "Geometry/CommonTopologies/interface/SurfaceDeformationFactory.h"
00019 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
00020 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00021 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00022 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h" 
00023 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00024 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00025 #include "Alignment/CommonAlignment/interface/Utilities.h"
00026 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00027 #include "Alignment/CommonAlignment/interface/Alignable.h"
00028 #include "DataFormats/DetId/interface/DetId.h"
00029 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00030 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00031 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00032 
00033 //#include "Alignment/OfflineValidation/interface/ComparisonUtilities.h"
00034 //#include "Alignment/CommonAlignment/interface/AlignTools.h"
00035 
00036 //#include "Alignment/OfflineValidation/plugins/TrackerGeometryCompare.h"
00037 #include "TrackerGeometryCompare.h"
00038 #include "TFile.h" 
00039 #include "CLHEP/Vector/ThreeVector.h"
00040 
00041 // Database
00042 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00043 #include "FWCore/ServiceRegistry/interface/Service.h"
00044 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00045 //#include "Geometry/Records/interface/PGeometricDetRcd.h"
00046 
00047 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00048 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00049 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00050 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00051 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00052 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00053 
00054 #include <iostream>
00055 #include <fstream>
00056 #include <sstream> 
00057 
00058 TrackerGeometryCompare::TrackerGeometryCompare(const edm::ParameterSet& cfg) :
00059   m_params( cfg ),      
00060   referenceTracker(0),
00061   dummyTracker(0),
00062   currentTracker(0),
00063   theSurveyIndex(0),
00064   theSurveyValues(0),
00065   theSurveyErrors(0),
00066   _commonTrackerLevel(align::invalid),
00067   _inputRootFile1(0),
00068   _inputRootFile2(0),
00069   _inputTree01(0),
00070   _inputTree02(0),
00071   _inputTree11(0),
00072   _inputTree12(0),
00073   m_nBins(10000),
00074   m_rangeLow(-.1),
00075   m_rangeHigh(.1), 
00076   firstEvent_(true),
00077   m_vtkmap(13)   
00078 {
00079         
00080         //input is ROOT
00081         _inputFilename1 = cfg.getUntrackedParameter< std::string > ("inputROOTFile1");
00082         _inputFilename2 = cfg.getUntrackedParameter< std::string > ("inputROOTFile2");
00083         _inputTreenameAlign = cfg.getUntrackedParameter< std::string > ("treeNameAlign");
00084         _inputTreenameDeform = cfg.getUntrackedParameter< std::string > ("treeNameDeform"); 
00085         
00086         //output file
00087         _filename = cfg.getUntrackedParameter< std::string > ("outputFile");
00088         
00089         _writeToDB = cfg.getUntrackedParameter< bool > ("writeToDB" );
00090         
00091         const std::vector<std::string>& levels = cfg.getUntrackedParameter< std::vector<std::string> > ("levels");
00092         
00093         _weightBy = cfg.getUntrackedParameter< std::string > ("weightBy");
00094         _setCommonTrackerSystem = cfg.getUntrackedParameter< std::string > ("setCommonTrackerSystem");
00095         _detIdFlag = cfg.getUntrackedParameter< bool > ("detIdFlag");
00096         _detIdFlagFile = cfg.getUntrackedParameter< std::string > ("detIdFlagFile");
00097         _weightById  = cfg.getUntrackedParameter< bool > ("weightById");
00098         _weightByIdFile = cfg.getUntrackedParameter< std::string > ("weightByIdFile");
00099         
00100         //setting the levels being used in the geometry comparator
00101         //DM_534?? AlignableObjectId dummy; 
00102         edm::LogInfo("TrackerGeometryCompare") << "levels: " << levels.size();
00103         for (unsigned int l = 0; l < levels.size(); ++l){
00104                 m_theLevels.push_back(AlignableObjectId::stringToId(levels[l])) ; //DM_61X?? 
00105                 //DM_534?? m_theLevels.push_back( dummy.nameToType(levels[l])); 
00106                 edm::LogInfo("TrackerGeometryCompare") << "level: " << levels[l];
00107                 edm::LogInfo("TrackerGeometryCompare") << "structure type: " << AlignableObjectId::stringToId(levels[l]) ; 
00108                 //DM_534?? edm::LogInfo("TrackerGeometryCompare") << "structure type: " << dummy.typeToName(m_theLevels.at(l)); 
00109         }
00110         
00111                 
00112         // if want to use, make id cut list
00113         if (_detIdFlag){
00114         ifstream fin;
00115         fin.open( _detIdFlagFile.c_str() );
00116         
00117         while (!fin.eof() && fin.good() ){
00118                         
00119                         uint32_t id;
00120                         fin >> id;
00121                         _detIdFlagVector.push_back(id);
00122         }
00123         fin.close();
00124         }               
00125         
00126         // turn weightByIdFile into weightByIdVector
00127         if (_weightById){
00128                 std::ifstream inFile;
00129                 inFile.open( _weightByIdFile.c_str() );
00130                 int ctr = 0;
00131                 while ( !inFile.eof() ){
00132                         ctr++;
00133                         unsigned int listId;
00134                         inFile >> listId;
00135                         inFile.ignore(256, '\n');
00136                         
00137                         _weightByIdVector.push_back( listId );
00138                 }
00139                 inFile.close();
00140         }
00141         
00142         //root configuration
00143         _theFile = new TFile(_filename.c_str(),"RECREATE");
00144         _alignTree = new TTree("alignTree","alignTree");//,"id:level:mid:mlevel:sublevel:x:y:z:r:phi:a:b:c:dx:dy:dz:dr:dphi:da:db:dc");
00145         _alignTree->Branch("id", &_id, "id/I");
00146         _alignTree->Branch("level", &_level, "level/I");
00147         _alignTree->Branch("mid", &_mid, "mid/I");
00148         _alignTree->Branch("mlevel", &_mlevel, "mlevel/I");
00149         _alignTree->Branch("sublevel", &_sublevel, "sublevel/I");
00150         _alignTree->Branch("x", &_xVal, "x/F");
00151         _alignTree->Branch("y", &_yVal, "y/F");
00152         _alignTree->Branch("z", &_zVal, "z/F");
00153         _alignTree->Branch("r", &_rVal, "r/F");
00154         _alignTree->Branch("phi", &_phiVal, "phi/F");
00155         _alignTree->Branch("eta", &_etaVal, "eta/F");
00156         _alignTree->Branch("alpha", &_alphaVal, "alpha/F");
00157         _alignTree->Branch("beta", &_betaVal, "beta/F");
00158         _alignTree->Branch("gamma", &_gammaVal, "gamma/F");
00159         _alignTree->Branch("dx", &_dxVal, "dx/F");
00160         _alignTree->Branch("dy", &_dyVal, "dy/F");
00161         _alignTree->Branch("dz", &_dzVal, "dz/F");
00162         _alignTree->Branch("dr", &_drVal, "dr/F");
00163         _alignTree->Branch("dphi", &_dphiVal, "dphi/F");
00164         _alignTree->Branch("dalpha", &_dalphaVal, "dalpha/F");
00165         _alignTree->Branch("dbeta", &_dbetaVal, "dbeta/F");
00166         _alignTree->Branch("dgamma", &_dgammaVal, "dgamma/F");
00167         _alignTree->Branch("du", &_duVal, "du/F");
00168         _alignTree->Branch("dv", &_dvVal, "dv/F");
00169         _alignTree->Branch("dw", &_dwVal, "dw/F");
00170         _alignTree->Branch("da", &_daVal, "da/F");
00171         _alignTree->Branch("db", &_dbVal, "db/F");
00172         _alignTree->Branch("dg", &_dgVal, "dg/F");
00173         _alignTree->Branch("useDetId", &_useDetId, "useDetId/I");
00174         _alignTree->Branch("detDim", &_detDim, "detDim/I");     
00175         _alignTree->Branch("surW", &_surWidth, "surW/F");
00176         _alignTree->Branch("surL", &_surLength, "surL/F");
00177         _alignTree->Branch("surRot", &_surRot, "surRot[9]/D");
00178         _alignTree->Branch("identifiers", &_identifiers, "identifiers[6]/I");
00179         _alignTree->Branch("type", &_type, "type/I");
00180         _alignTree->Branch("surfDeform", &_surfDeform, "surfDeform[13]/D"); 
00181 
00182         for (std::vector<TrackerMap>::iterator it = m_vtkmap.begin(); it != m_vtkmap.end(); ++it) {
00183           it->setPalette(1) ;
00184           it->addPixel(true) ;
00185         }
00186 
00187         edm::Service<TFileService> fs;
00188         TFileDirectory subDir_All = fs->mkdir( "AllSubdetectors" );
00189         TFileDirectory subDir_PXB = fs->mkdir( "PixelBarrel" );
00190         TFileDirectory subDir_PXF = fs->mkdir( "PixelEndcap" );
00191         for (int ii = 0; ii < 13; ++ii) { 
00192           std::stringstream histname0 ;
00193           histname0 << "SurfDeform_Par_" << ii ; 
00194           m_h1[histname0.str()] = subDir_All.make<TH1D>((histname0.str()).c_str(),(histname0.str()).c_str(),m_nBins,m_rangeLow,m_rangeHigh); 
00195         
00196           std::stringstream histname1 ;
00197           histname1 << "SurfDeform_PixelBarrel_Par_" << ii ; 
00198           m_h1[histname1.str()] = subDir_PXB.make<TH1D>((histname1.str()).c_str(),(histname1.str()).c_str(),m_nBins,m_rangeLow,m_rangeHigh); 
00199         
00200           std::stringstream histname2 ;
00201           histname2 << "SurfDeform_PixelEndcap_Par_" << ii ; 
00202           m_h1[histname2.str()] = subDir_PXF.make<TH1D>((histname2.str()).c_str(),(histname2.str()).c_str(),m_nBins,m_rangeLow,m_rangeHigh); 
00203         }
00204         
00205 }
00206 
00207 void TrackerGeometryCompare::beginJob(){
00208   firstEvent_ = true;
00209 }
00210 
00211 void TrackerGeometryCompare::endJob(){
00212 
00213   int iname(0) ;
00214   for (std::vector<TrackerMap>::iterator it = m_vtkmap.begin(); it != m_vtkmap.end(); ++it) {
00215     std::stringstream mapname ;
00216     mapname << "TkMap_Pix_SurfDeform" << iname << ".png" ; 
00217     it->save(true,0,0,mapname.str());
00218     mapname.str( std::string() ); 
00219     mapname.clear() ; 
00220     mapname << "TkMap_Pix_SurfDeform" << iname << ".pdf" ; 
00221     it->save(true,0,0,mapname.str());
00222     ++iname ; 
00223   }
00224 
00225   _theFile->cd();
00226   _alignTree->Write();
00227   _theFile->Close();
00228         
00229 }
00230 
00231 void TrackerGeometryCompare::analyze(const edm::Event&, const edm::EventSetup& iSetup){
00232 
00233   if (firstEvent_) {
00234 
00235         //upload the ROOT geometries
00236         createROOTGeometry(iSetup);
00237 
00238         //set common tracker system first
00239         // if setting the tracker common system
00240         if (_setCommonTrackerSystem != "NONE"){
00241                 setCommonTrackerSystem();
00242         }
00243         
00244         //compare the goemetries
00245         compareGeometries(referenceTracker,currentTracker);
00246         compareSurfaceDeformations(_inputTree11, _inputTree12); 
00247         
00248         //write out ntuple
00249         //might be better to do within output module
00250         
00251         if (_writeToDB){
00252                 Alignments* myAlignments = currentTracker->alignments();
00253                 AlignmentErrors* myAlignmentErrors = currentTracker->alignmentErrors();
00254                 
00255                 // 2. Store alignment[Error]s to DB
00256                 edm::Service<cond::service::PoolDBOutputService> poolDbService;
00257                 // Call service
00258                 if( !poolDbService.isAvailable() ) // Die if not available
00259                         throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00260                 
00261                 poolDbService->writeOne<Alignments>(&(*myAlignments), poolDbService->beginOfTime(), "TrackerAlignmentRcd");
00262                 poolDbService->writeOne<AlignmentErrors>(&(*myAlignmentErrors), poolDbService->beginOfTime(), "TrackerAlignmentErrorRcd");
00263                 
00264         }               
00265 
00266         firstEvent_ = false;
00267   }
00268 }
00269 
00270 void TrackerGeometryCompare::createROOTGeometry(const edm::EventSetup& iSetup){
00271         
00272         int inputRawId1, inputRawId2;
00273         double inputX1, inputY1, inputZ1, inputX2, inputY2, inputZ2;
00274         double inputAlpha1, inputBeta1, inputGamma1, inputAlpha2, inputBeta2, inputGamma2;
00275                 
00276         //declare alignments
00277         Alignments* alignments1 = new Alignments();
00278         AlignmentErrors* alignmentErrors1 = new AlignmentErrors();      
00279         if (_inputFilename1 != "IDEAL"){
00280                 _inputRootFile1 = new TFile(_inputFilename1.c_str());
00281                 TTree* _inputTree01 = (TTree*) _inputRootFile1->Get(_inputTreenameAlign.c_str());
00282                 _inputTree01->SetBranchAddress("rawid", &inputRawId1);
00283                 _inputTree01->SetBranchAddress("x", &inputX1);
00284                 _inputTree01->SetBranchAddress("y", &inputY1);
00285                 _inputTree01->SetBranchAddress("z", &inputZ1);
00286                 _inputTree01->SetBranchAddress("alpha", &inputAlpha1);
00287                 _inputTree01->SetBranchAddress("beta", &inputBeta1);
00288                 _inputTree01->SetBranchAddress("gamma", &inputGamma1);
00289 
00290                 int nEntries1 = _inputTree01->GetEntries();
00291                 //fill alignments
00292                 for (int i = 0; i < nEntries1; ++i){
00293                         
00294                         _inputTree01->GetEntry(i);
00295                         CLHEP::Hep3Vector translation1(inputX1, inputY1, inputZ1);
00296                         CLHEP::HepEulerAngles eulerangles1(inputAlpha1,inputBeta1,inputGamma1);
00297                         uint32_t detid1 = inputRawId1;
00298                         AlignTransform transform1(translation1, eulerangles1, detid1);
00299                         alignments1->m_align.push_back(transform1);
00300                         
00301                         //dummy errors
00302                         CLHEP::HepSymMatrix clhepSymMatrix(3,0);
00303                         AlignTransformError transformError(clhepSymMatrix, detid1);
00304                         alignmentErrors1->m_alignError.push_back(transformError);
00305                 }               
00306                 
00307                 // to get the right order
00308                 std::sort( alignments1->m_align.begin(), alignments1->m_align.end(), lessAlignmentDetId<AlignTransform>() );
00309                 std::sort( alignmentErrors1->m_alignError.begin(), alignmentErrors1->m_alignError.end(), lessAlignmentDetId<AlignTransformError>() );
00310         }
00311         //------------------
00312         Alignments* alignments2 = new Alignments();
00313         AlignmentErrors* alignmentErrors2 = new AlignmentErrors();
00314         if (_inputFilename2 != "IDEAL"){        
00315                 _inputRootFile2 = new TFile(_inputFilename2.c_str());
00316                 TTree* _inputTree02 = (TTree*) _inputRootFile2->Get(_inputTreenameAlign.c_str());
00317                 _inputTree02->SetBranchAddress("rawid", &inputRawId2);
00318                 _inputTree02->SetBranchAddress("x", &inputX2);
00319                 _inputTree02->SetBranchAddress("y", &inputY2);
00320                 _inputTree02->SetBranchAddress("z", &inputZ2);
00321                 _inputTree02->SetBranchAddress("alpha", &inputAlpha2);
00322                 _inputTree02->SetBranchAddress("beta", &inputBeta2);
00323                 _inputTree02->SetBranchAddress("gamma", &inputGamma2);
00324                 
00325                 int nEntries2 = _inputTree02->GetEntries();
00326                 //fill alignments
00327                 for (int i = 0; i < nEntries2; ++i){
00328                         
00329                         _inputTree02->GetEntry(i);
00330                         CLHEP::Hep3Vector translation2(inputX2, inputY2, inputZ2);
00331                         CLHEP::HepEulerAngles eulerangles2(inputAlpha2,inputBeta2,inputGamma2);
00332                         uint32_t detid2 = inputRawId2;
00333                         AlignTransform transform2(translation2, eulerangles2, detid2);
00334                         alignments2->m_align.push_back(transform2);
00335                         
00336                         //dummy errors
00337                         CLHEP::HepSymMatrix clhepSymMatrix(3,0);
00338                         AlignTransformError transformError(clhepSymMatrix, detid2);
00339                         alignmentErrors2->m_alignError.push_back(transformError); 
00340                 }                       
00341                 
00342                 //to get the right order
00343                 std::sort( alignments2->m_align.begin(), alignments2->m_align.end(), lessAlignmentDetId<AlignTransform>() );
00344                 std::sort( alignmentErrors2->m_alignError.begin(), alignmentErrors2->m_alignError.end(), lessAlignmentDetId<AlignTransformError>() );
00345         }
00346         
00347         //accessing the initial geometry
00348         edm::ESTransientHandle<DDCompactView> cpv;
00349         iSetup.get<IdealGeometryRecord>().get(cpv);
00350         edm::ESHandle<GeometricDet> theGeometricDet;
00351         iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
00352         TrackerGeomBuilderFromGeometricDet trackerBuilder;
00353         
00354         edm::ESHandle<Alignments> globalPositionRcd;
00355         iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
00356         
00357         //reference tracker
00358         TrackerGeometry* theRefTracker = trackerBuilder.build(&*theGeometricDet, m_params); 
00359         if (_inputFilename1 != "IDEAL"){
00360                 GeometryAligner aligner1;
00361                 aligner1.applyAlignments<TrackerGeometry>( &(*theRefTracker), &(*alignments1), &(*alignmentErrors1),
00362                                                                                                   align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
00363         }
00364         referenceTracker = new AlignableTracker(&(*theRefTracker));
00365         //referenceTracker->setSurfaceDeformation(surfDef1, true) ; 
00366 
00367         int inputRawid1;
00368         int inputRawid2;
00369         int inputDtype1, inputDtype2 ; 
00370         std::vector<double> inputDpar1;
00371         std::vector<double> inputDpar2 ; 
00372         std::vector<double>* p_inputDpar1 = &inputDpar1; 
00373         std::vector<double>* p_inputDpar2 = &inputDpar2; 
00374 
00375         const std::vector<Alignable*> comp1 = referenceTracker->deepComponents(); 
00376 
00377         SurfaceDeformation * surfDef1; 
00378         if (_inputFilename1 != "IDEAL"){
00379           TTree* _inputTree11 = (TTree*) _inputRootFile1->Get(_inputTreenameDeform.c_str());
00380           _inputTree11->SetBranchAddress("irawid", &inputRawid1);
00381           _inputTree11->SetBranchAddress("dtype", &inputDtype1);
00382           _inputTree11->SetBranchAddress("dpar", &p_inputDpar1);
00383 
00384           unsigned int nEntries11 = _inputTree11->GetEntries();
00385           edm::LogInfo("TrackerGeometryCompare") << " nentries11 = " << nEntries11 << std::endl ; 
00386           for (unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
00387             _inputTree11->GetEntry(iEntry) ; 
00388 
00389             surfDef1 = SurfaceDeformationFactory::create( inputDtype1, inputDpar1);
00390 
00391             if (int(comp1[iEntry]->id()) == inputRawid1) {
00392               comp1[iEntry]->setSurfaceDeformation(surfDef1, true) ; 
00393             }
00394 
00395           }
00396         }
00397                 
00398         //currernt tracker
00399         TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet,m_params); 
00400         if (_inputFilename2 != "IDEAL"){
00401                 GeometryAligner aligner2;
00402                 aligner2.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments2), &(*alignmentErrors2),
00403                                                                                                   align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
00404         }
00405         currentTracker = new AlignableTracker(&(*theCurTracker));
00406         
00407         const std::vector<Alignable*> comp2 = currentTracker->deepComponents(); 
00408 
00409         SurfaceDeformation * surfDef2 ; 
00410         if (_inputFilename2 != "IDEAL"){ 
00411           TTree* _inputTree12 = (TTree*) _inputRootFile2->Get(_inputTreenameDeform.c_str());
00412           _inputTree12->SetBranchAddress("irawid", &inputRawid2);
00413           _inputTree12->SetBranchAddress("dtype", &inputDtype2);
00414           _inputTree12->SetBranchAddress("dpar",  &p_inputDpar2);
00415 
00416           unsigned int nEntries12 = _inputTree12->GetEntries();
00417           edm::LogInfo("TrackerGeometryCompare") << " nentries12 = " << nEntries12 << std::endl ; 
00418           for (unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
00419             _inputTree12->GetEntry(iEntry) ; 
00420             
00421             surfDef2 = SurfaceDeformationFactory::create( inputDtype2, inputDpar2);
00422 
00423             if (int(comp2[iEntry]->id()) == inputRawid2) {
00424               comp2[iEntry]->setSurfaceDeformation(surfDef2, true) ; 
00425             }
00426 
00427           }
00428         }
00429                 
00430         delete alignments1;
00431         delete alignmentErrors1;
00432         delete alignments2;
00433         delete alignmentErrors2;
00434 
00435 }
00436 
00437 void TrackerGeometryCompare::compareSurfaceDeformations(TTree* refTree, TTree* curTree) {
00438         
00439   if (_inputFilename1 != "IDEAL" && _inputFilename2 != "IDEAL") {
00440              
00441     int inputRawid1;
00442     int inputRawid2;
00443     int inputSubdetid1, inputSubdetid2 ; 
00444     int inputDtype1, inputDtype2 ; 
00445     std::vector<double> inputDpar1;
00446     std::vector<double> inputDpar2 ; 
00447     std::vector<double>* p_inputDpar1 = &inputDpar1; 
00448     std::vector<double>* p_inputDpar2 = &inputDpar2; 
00449   
00450     TTree* refTree = (TTree*) _inputRootFile1->Get(_inputTreenameDeform.c_str());
00451     refTree->SetBranchAddress("irawid", &inputRawid1);
00452     refTree->SetBranchAddress("subdetid", &inputSubdetid1);
00453     refTree->SetBranchAddress("dtype", &inputDtype1);
00454     refTree->SetBranchAddress("dpar", &p_inputDpar1);
00455   
00456     TTree* curTree = (TTree*) _inputRootFile2->Get(_inputTreenameDeform.c_str());
00457     curTree->SetBranchAddress("irawid", &inputRawid2);
00458     curTree->SetBranchAddress("subdetid", &inputSubdetid2);
00459     curTree->SetBranchAddress("dtype", &inputDtype2);
00460     curTree->SetBranchAddress("dpar",  &p_inputDpar2);
00461   
00462     unsigned int nEntries11 = refTree->GetEntries();
00463     unsigned int nEntries12 = curTree->GetEntries();
00464 
00465     if (nEntries11 != nEntries12) {
00466       edm::LogError("TrackerGeometryCompare")   << " Surface deformation parameters in two geometries differ!\n" ;
00467       return ; 
00468     }
00469     
00470     for (unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
00471       refTree->GetEntry(iEntry) ;
00472       curTree->GetEntry(iEntry) ;
00473       for (int ii = 0; ii < 13; ++ii) { _surfDeform[ii] = -1.0 ; } 
00474       for (int npar = 0; npar < int(inputDpar2.size()); ++npar ) {
00475             if (inputRawid1 == inputRawid2) {
00476         _surfDeform[npar] = inputDpar2.at(npar) - inputDpar1.at(npar) ; 
00477         std::stringstream histname0 ;
00478         histname0 << "SurfDeform_Par_" << npar ;  
00479         if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname0.str()]->Fill(_surfDeform[npar]) ; 
00480         if (inputSubdetid1 == 1 && inputSubdetid2 == 1) {
00481           std::stringstream histname1 ;
00482           histname1 << "SurfDeform_PixelBarrel_Par_" << npar ;  
00483           if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname1.str()]->Fill(_surfDeform[npar]) ; 
00484         }
00485         if (inputSubdetid1 == 2 && inputSubdetid2 == 2) {
00486           std::stringstream histname2 ;
00487           histname2 << "SurfDeform_PixelEndcap_Par_" << npar ;  
00488           if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname2.str()]->Fill(_surfDeform[npar]) ; 
00489         }
00490         (m_vtkmap.at(npar)).fill_current_val(inputRawid1,_surfDeform[npar]) ; 
00491             }
00492       }
00493     }
00494   
00495   } else if ( _inputFilename1 == "IDEAL" && _inputFilename2 != "IDEAL" ) {
00496              
00497     int inputRawid2;
00498     int inputSubdetid2 ; 
00499     int inputDtype2 ; 
00500     std::vector<double> inputDpar2 ; 
00501     std::vector<double>* p_inputDpar2 = &inputDpar2; 
00502   
00503     TTree* curTree = (TTree*) _inputRootFile2->Get(_inputTreenameDeform.c_str());
00504     curTree->SetBranchAddress("irawid", &inputRawid2);
00505     curTree->SetBranchAddress("subdetid", &inputSubdetid2);
00506     curTree->SetBranchAddress("dtype", &inputDtype2);
00507     curTree->SetBranchAddress("dpar",  &p_inputDpar2);
00508   
00509     unsigned int nEntries12 = curTree->GetEntries();
00510     
00511     for (unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
00512       curTree->GetEntry(iEntry) ;
00513       for (int ii = 0; ii < 12; ++ii) { _surfDeform[ii] = -1.0 ; } 
00514       for (int npar = 0; npar < int(inputDpar2.size()); ++npar ) {
00515         _surfDeform[npar] = inputDpar2.at(npar) ; 
00516         std::stringstream histname0 ;
00517         histname0 << "SurfDeform_Par_" << npar ;  
00518         if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname0.str()]->Fill(_surfDeform[npar]) ; 
00519         if (inputSubdetid2 == 1) {
00520           std::stringstream histname1 ;
00521           histname1 << "SurfDeform_PixelBarrel_Par_" << npar ;  
00522           if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname1.str()]->Fill(_surfDeform[npar]) ; 
00523         }
00524         if (inputSubdetid2 == 2) {
00525           std::stringstream histname2 ;
00526           histname2 << "SurfDeform_PixelEndcap_Par_" << npar ;  
00527           if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname2.str()]->Fill(_surfDeform[npar]) ; 
00528         }
00529         (m_vtkmap.at(npar)).fill_current_val(inputRawid2,_surfDeform[npar]) ; 
00530       }
00531     }
00532   
00533   } else if ( _inputFilename1 != "IDEAL" && _inputFilename2 == "IDEAL" ) {
00534              
00535     int inputRawid1;
00536     int inputSubdetid1 ; 
00537     int inputDtype1 ; 
00538     std::vector<double> inputDpar1;
00539     std::vector<double>* p_inputDpar1 = &inputDpar1; 
00540   
00541     TTree* refTree = (TTree*) _inputRootFile1->Get(_inputTreenameDeform.c_str());
00542     refTree->SetBranchAddress("irawid", &inputRawid1);
00543     refTree->SetBranchAddress("subdetid", &inputSubdetid1);
00544     refTree->SetBranchAddress("dtype", &inputDtype1);
00545     refTree->SetBranchAddress("dpar", &p_inputDpar1);
00546   
00547     unsigned int nEntries11 = refTree->GetEntries();
00548     
00549     for (unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
00550       refTree->GetEntry(iEntry) ;
00551       for (int ii = 0; ii < 12; ++ii) { _surfDeform[ii] = -1.0 ; } 
00552       for (int npar = 0; npar < int(inputDpar1.size()); ++npar ) {
00553         _surfDeform[npar] = - inputDpar1.at(npar) ; 
00554         std::stringstream histname0 ;
00555         histname0 << "SurfDeform_Par_" << npar ;  
00556         if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname0.str()]->Fill(_surfDeform[npar]) ; 
00557         if (inputSubdetid1 == 1) {
00558           std::stringstream histname1 ;
00559           histname1 << "SurfDeform_PixelBarrel_Par_" << npar ;  
00560           if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname1.str()]->Fill(_surfDeform[npar]) ; 
00561         }
00562         if (inputSubdetid1 == 2) {
00563           std::stringstream histname2 ;
00564           histname2 << "SurfDeform_PixelEndcap_Par_" << npar ;  
00565           if ( TMath::Abs(_surfDeform[npar]) > (m_rangeHigh - m_rangeLow)/(10.*m_nBins) ) m_h1[histname2.str()]->Fill(_surfDeform[npar]) ; 
00566         }
00567         (m_vtkmap.at(npar)).fill_current_val(inputRawid1,_surfDeform[npar]) ; 
00568       }
00569     }
00570   
00571   } else if ( _inputFilename1 == "IDEAL" && _inputFilename2 == "IDEAL" ) {
00572 
00573           edm::LogInfo("TrackerGeometryCompare") << ">>>> Comparing IDEAL with IDEAL: nothing to do! <<<<\n" ; 
00574           
00575   }
00576 
00577   return ;      
00578 }
00579 
00580 void TrackerGeometryCompare::compareGeometries(Alignable* refAli, Alignable* curAli){
00581 
00582         using namespace align ; 
00583         
00584         const std::vector<Alignable*>& refComp = refAli->components();
00585         const std::vector<Alignable*>& curComp = curAli->components();
00586         
00587         unsigned int nComp = refComp.size();
00588         //only perform for designate levels
00589         bool useLevel = false;
00590         for (unsigned int i = 0; i < m_theLevels.size(); ++i){
00591                 if (refAli->alignableObjectId() == m_theLevels[i]) useLevel = true;
00592         }
00593         
00594         //another added level for difference between det and detunit
00595         //if ((refAli->alignableObjectId()==2)&&(nComp == 1)) useLevel = false;
00596         
00597         //coordinate matching, etc etc
00598         if (useLevel){
00599                 DetId detid(refAli->id());
00600 
00601                 CLHEP::Hep3Vector Rtotal, Wtotal, lRtotal, lWtotal;
00602                 Rtotal.set(0.,0.,0.); 
00603                 Wtotal.set(0.,0.,0.);
00604                 lRtotal.set(0.,0.,0.); 
00605                 lWtotal.set(0.,0.,0.);
00606 
00607                 for (int i = 0; i < 100; i++){
00608                         AlgebraicVector diff = align::diffAlignables(refAli,curAli, _weightBy, _weightById, _weightByIdVector);
00609                         CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
00610                         Rtotal+=dR;
00611                         CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
00612                         CLHEP::HepRotation rot(Wtotal.unit(),Wtotal.mag());
00613                         CLHEP::HepRotation drot(dW.unit(),dW.mag());
00614                         rot*=drot;
00615                         Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
00616                         // local coordinates
00617                         lRtotal.set(diff[6],diff[7],diff[8]);
00618                         lWtotal.set(diff[9],diff[10],diff[11]);
00619                         
00620                         align::moveAlignable(curAli, diff);
00621                         float tolerance = 1e-7;
00622                         AlgebraicVector check = align::diffAlignables(refAli,curAli, _weightBy, _weightById, _weightByIdVector);
00623                         align::GlobalVector checkR(check[0],check[1],check[2]);
00624                         align::GlobalVector checkW(check[3],check[4],check[5]);
00625                         if ((checkR.mag() > tolerance)||(checkW.mag() > tolerance)){
00626                                 edm::LogInfo("TrackerGeometryCompare") << "Tolerance Exceeded!(alObjId: " << refAli->alignableObjectId()
00627                                 << ", rawId: " << refAli->geomDetId().rawId()
00628                                 << ", subdetId: "<< detid.subdetId() << "): " << diff;
00629                                 throw cms::Exception("Tolerance in TrackerGeometryCompare exceeded");
00630                         }
00631                         else{
00632                                 break;
00633                         }
00634                 }
00635 
00636                 AlgebraicVector TRtot(12);
00637                 // global 
00638                 TRtot(1) = Rtotal.x(); TRtot(2) = Rtotal.y(); TRtot(3) = Rtotal.z();
00639                 TRtot(4) = Wtotal.x(); TRtot(5) = Wtotal.y(); TRtot(6) = Wtotal.z();
00640                 // local
00641                 TRtot(7) = lRtotal.x(); TRtot(8) = lRtotal.y(); TRtot(9) = lRtotal.z();
00642                 TRtot(10) = lWtotal.x(); TRtot(11) = lWtotal.y(); TRtot(12) = lWtotal.z();
00643 
00644                 fillTree(refAli, TRtot);
00645         }
00646 
00647         // another added level for difference between det and detunit
00648         for (unsigned int i = 0; i < nComp; ++i) 
00649           compareGeometries(refComp[i],curComp[i]);     
00650 
00651 }
00652 
00653 void TrackerGeometryCompare::setCommonTrackerSystem(){
00654 
00655         edm::LogInfo("TrackerGeometryCompare") << "Setting Common Tracker System....";
00656         
00657         // DM_534??AlignableObjectId dummy;
00658         // DM_534??_commonTrackerLevel = dummy.nameToType(_setCommonTrackerSystem);
00659         _commonTrackerLevel = AlignableObjectId::stringToId(_setCommonTrackerSystem); // DM_61X?? 
00660                 
00661         diffCommonTrackerSystem(referenceTracker, currentTracker);
00662         
00663         align::EulerAngles dOmega(3); dOmega[0] = _TrackerCommonR.x() ; dOmega[1] = _TrackerCommonR.y(); dOmega[2] = _TrackerCommonR.z();
00664         align::RotationType rot = align::toMatrix( dOmega );
00665         align::GlobalVector theR = _TrackerCommonT;
00666         
00667         std::cout << "what we get from overlaying the pixels..." << theR << ", " << rot << std::endl;
00668         
00669         //transform to the Tracker System
00670         align::PositionType trackerCM = currentTracker->globalPosition();
00671         align::GlobalVector cmDiff( trackerCM.x()-_TrackerCommonCM.x(), trackerCM.y()-_TrackerCommonCM.y(), trackerCM.z()-_TrackerCommonCM.z() );
00672         
00673         std::cout << "Pixel CM: " << _TrackerCommonCM << ", tracker CM: " << trackerCM << std::endl;
00674         
00675         //adjust translational difference factoring in different rotational CM
00676         //needed because rotateInGlobalFrame is about CM of alignable, not Tracker
00677         align::GlobalVector::BasicVectorType lpvgf = cmDiff.basicVector();
00678         align::GlobalVector moveV( rot.multiplyInverse(lpvgf) - lpvgf);
00679         align::GlobalVector theRprime(theR + moveV);
00680         
00681         AlgebraicVector TrackerCommonTR(6);
00682         TrackerCommonTR(1) = theRprime.x(); TrackerCommonTR(2) = theRprime.y(); TrackerCommonTR(3) = theRprime.z();
00683         TrackerCommonTR(4) = _TrackerCommonR.x(); TrackerCommonTR(5) = _TrackerCommonR.y(); TrackerCommonTR(6) = _TrackerCommonR.z();
00684         
00685         std::cout << "and after the transformation: " << TrackerCommonTR << std::endl;
00686         
00687         align::moveAlignable(currentTracker, TrackerCommonTR );
00688         
00689 }
00690 
00691 void TrackerGeometryCompare::diffCommonTrackerSystem(Alignable *refAli, Alignable *curAli){
00692         
00693         const std::vector<Alignable*>& refComp = refAli->components();
00694         const std::vector<Alignable*>& curComp = curAli->components();
00695         
00696         unsigned int nComp = refComp.size();
00697         //only perform for designate levels
00698         bool useLevel = false;
00699         if (refAli->alignableObjectId() == _commonTrackerLevel) useLevel = true;
00700         
00701         //useLevel = false;
00702         if (useLevel){
00703                 CLHEP::Hep3Vector Rtotal, Wtotal;
00704                 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
00705                 
00706                 AlgebraicVector diff = align::diffAlignables(refAli,curAli, _weightBy, _weightById, _weightByIdVector);
00707                 CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
00708                 Rtotal+=dR;
00709                 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
00710                 CLHEP::HepRotation rot(Wtotal.unit(),Wtotal.mag());
00711                 CLHEP::HepRotation drot(dW.unit(),dW.mag());
00712                 rot*=drot;
00713                 Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
00714                 /*
00715                  //std::cout << "a";
00716                  //if (refAli->alignableObjectId() == 1) std::cout << "DIFF: " << diff << std::endl;
00717                  align::moveAlignable(curAli, diff);
00718                  float tolerance = 1e-7;
00719                  AlgebraicVector check = align::diffAlignables(refAli,curAli, _weightBy, _weightById, _weightByIdVector);
00720                  align::GlobalVector checkR(check[0],check[1],check[2]);
00721                  align::GlobalVector checkW(check[3],check[4],check[5]);
00722                  DetId detid(refAli->id());
00723                  if ((checkR.mag() > tolerance)||(checkW.mag() > tolerance)){
00724                  edm::LogInfo("TrackerGeometryCompare") << "Tolerance Exceeded!(alObjId: " << refAli->alignableObjectId()
00725                  << ", rawId: " << refAli->geomDetId().rawId()
00726                  << ", subdetId: "<< detid.subdetId() << "): " << diff;
00727                  }
00728                  else{
00729                  break;
00730                  }
00731                  }
00732                  */
00733                 
00734                 //_TrackerCommonT.set(Rtotal.x(), Rtotal.y(), Rtotal.z());
00735                 _TrackerCommonT = align::GlobalVector(Rtotal.x(), Rtotal.y(), Rtotal.z());
00736                 _TrackerCommonR = align::GlobalVector(Wtotal.x(), Wtotal.y(), Wtotal.z());
00737                 _TrackerCommonCM = curAli->globalPosition();
00738                 //_TrackerCommonTR(1) = Rtotal.x(); _TrackerCommonTR(2) = Rtotal.y(); _TrackerCommonTR(3) = Rtotal.z();
00739                 //_TrackerCommonTR(4) = Wtotal.x(); _TrackerCommonTR(5) = Wtotal.y(); _TrackerCommonTR(6) = Wtotal.z();
00740                 
00741                 
00742         }
00743         else{
00744                 for (unsigned int i = 0; i < nComp; ++i) diffCommonTrackerSystem(refComp[i],curComp[i]);
00745         }
00746         
00747         
00748 }
00749 
00750 void TrackerGeometryCompare::fillTree(Alignable *refAli, AlgebraicVector diff){
00751         
00752         _id = refAli->id();
00753         _level = refAli->alignableObjectId();
00754         //need if ali has no mother
00755         if (refAli->mother()){
00756                 _mid = refAli->mother()->geomDetId().rawId();
00757                 _mlevel = refAli->mother()->alignableObjectId();
00758         }
00759         else{
00760                 _mid = -1;
00761                 _mlevel = -1;
00762         }
00763         DetId detid(_id);
00764         _sublevel = detid.subdetId();
00765         fillIdentifiers( _sublevel, _id );
00766         _xVal = refAli->globalPosition().x();
00767         _yVal = refAli->globalPosition().y();
00768         _zVal = refAli->globalPosition().z();
00769         align::GlobalVector vec(_xVal,_yVal,_zVal);
00770         _rVal = vec.perp();
00771         _phiVal = vec.phi();
00772         _etaVal = vec.eta();
00773         align::RotationType rot = refAli->globalRotation();
00774         align::EulerAngles eulerAngles = align::toAngles(rot);
00775         _alphaVal = eulerAngles[0];
00776         _betaVal = eulerAngles[1];
00777         _gammaVal = eulerAngles[2];
00778         // global
00779         _dxVal = diff[0];
00780         _dyVal = diff[1];
00781         _dzVal = diff[2];
00782         // local
00783         _duVal = diff[6];
00784         _dvVal = diff[7];
00785         _dwVal = diff[8];
00786         //...TODO...
00787         align::GlobalVector g(_dxVal, _dyVal, _dzVal);
00788         //getting dR and dPhi
00789         align::GlobalVector vRef(_xVal,_yVal,_zVal);
00790         align::GlobalVector vCur(_xVal + _dxVal, _yVal + _dyVal, _zVal + _dzVal);
00791         _drVal = vCur.perp() - vRef.perp();
00792         _dphiVal = vCur.phi() - vRef.phi();
00793         // global
00794         _dalphaVal = diff[3];
00795         _dbetaVal = diff[4];
00796         _dgammaVal = diff[5];
00797         // local
00798         _daVal = diff[9];
00799         _dbVal = diff[10];
00800         _dgVal = diff[11];
00801         
00802         //detIdFlag
00803         if (refAli->alignableObjectId() == align::AlignableDetUnit){
00804                 if (_detIdFlag){
00805                         if ((passIdCut(refAli->id()))||(passIdCut(refAli->mother()->id()))){
00806                                 _useDetId = 1;
00807                         }
00808                         else{
00809                                 _useDetId = 0;
00810                         }
00811                 }
00812         }
00813         // det module dimension
00814         if (refAli->alignableObjectId() == align::AlignableDetUnit){
00815                 if (refAli->mother()->alignableObjectId() != align::AlignableDet) _detDim = 1;
00816                 else if (refAli->mother()->alignableObjectId() == align::AlignableDet) _detDim = 2;
00817         }
00818         else _detDim = 0;
00819         
00820         _surWidth = refAli->surface().width();
00821         _surLength = refAli->surface().length();
00822         align::RotationType rt = refAli->globalRotation();
00823         _surRot[0] = rt.xx(); _surRot[1] = rt.xy(); _surRot[2] = rt.xz();
00824         _surRot[3] = rt.yx(); _surRot[4] = rt.yy(); _surRot[5] = rt.yz();
00825         _surRot[6] = rt.zx(); _surRot[7] = rt.zy(); _surRot[8] = rt.zz();
00826         
00827         //Fill
00828         _alignTree->Fill();
00829         
00830 }
00831 
00832 void TrackerGeometryCompare::surveyToTracker(AlignableTracker* ali, Alignments* alignVals, AlignmentErrors* alignErrors){
00833         
00834         //getting the right alignables for the alignment record
00835         std::vector<Alignable*> detPB = ali->pixelHalfBarrelGeomDets();
00836         std::vector<Alignable*> detPEC = ali->pixelEndcapGeomDets();
00837         std::vector<Alignable*> detTIB = ali->innerBarrelGeomDets();
00838         std::vector<Alignable*> detTID = ali->TIDGeomDets();
00839         std::vector<Alignable*> detTOB = ali->outerBarrelGeomDets();
00840         std::vector<Alignable*> detTEC = ali->endcapGeomDets();
00841         
00842         std::vector<Alignable*> allGeomDets;
00843         std::copy(detPB.begin(), detPB.end(), std::back_inserter(allGeomDets));
00844         std::copy(detPEC.begin(), detPEC.end(), std::back_inserter(allGeomDets));
00845         std::copy(detTIB.begin(), detTIB.end(), std::back_inserter(allGeomDets));
00846         std::copy(detTID.begin(), detTID.end(), std::back_inserter(allGeomDets));
00847         std::copy(detTOB.begin(), detTOB.end(), std::back_inserter(allGeomDets));
00848         std::copy(detTEC.begin(), detTEC.end(), std::back_inserter(allGeomDets));
00849         
00850         std::vector<Alignable*> rcdAlis;
00851         for (std::vector<Alignable*>::iterator i = allGeomDets.begin(); i!= allGeomDets.end(); i++){
00852                 if ((*i)->components().size() == 1){
00853                         rcdAlis.push_back((*i));
00854                 }
00855                 else if ((*i)->components().size() > 1){
00856                         rcdAlis.push_back((*i));
00857                         std::vector<Alignable*> comp = (*i)->components();
00858                         for (std::vector<Alignable*>::iterator j = comp.begin(); j != comp.end(); j++){
00859                                 rcdAlis.push_back((*j));
00860                         }
00861                 }
00862         }
00863         
00864         //turning them into alignments
00865         for(std::vector<Alignable*>::iterator k = rcdAlis.begin(); k != rcdAlis.end(); k++){
00866                 
00867                 const SurveyDet* surveyInfo = (*k)->survey();
00868                 align::PositionType pos(surveyInfo->position());
00869                 align::RotationType rot(surveyInfo->rotation());
00870                 CLHEP::Hep3Vector clhepVector(pos.x(),pos.y(),pos.z());
00871                 CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3(rot.xx(),rot.xy(),rot.xz(),rot.yx(),rot.yy(),rot.yz(),rot.zx(),rot.zy(),rot.zz()));
00872                 AlignTransform transform(clhepVector, clhepRotation, (*k)->id());
00873                 AlignTransformError transformError(CLHEP::HepSymMatrix(3,1), (*k)->id());
00874                 alignVals->m_align.push_back(transform);
00875                 alignErrors->m_alignError.push_back(transformError);
00876         }
00877         
00878         //to get the right order
00879         std::sort( alignVals->m_align.begin(), alignVals->m_align.end(), lessAlignmentDetId<AlignTransform>() );
00880         std::sort( alignErrors->m_alignError.begin(), alignErrors->m_alignError.end(), lessAlignmentDetId<AlignTransformError>() );
00881         
00882 }
00883 
00884 void TrackerGeometryCompare::addSurveyInfo(Alignable* ali){
00885         
00886         const std::vector<Alignable*>& comp = ali->components();
00887         
00888         unsigned int nComp = comp.size();
00889         
00890         for (unsigned int i = 0; i < nComp; ++i) addSurveyInfo(comp[i]);
00891         
00892         const SurveyError& error = theSurveyErrors->m_surveyErrors[theSurveyIndex];
00893         
00894         if ( ali->geomDetId().rawId() != error.rawId() ||
00895                 ali->alignableObjectId() != error.structureType() )
00896         {
00897                 throw cms::Exception("DatabaseError")
00898                 << "Error reading survey info from DB. Mismatched id!";
00899         }
00900         
00901         const CLHEP::Hep3Vector&  pos = theSurveyValues->m_align[theSurveyIndex].translation();
00902         const CLHEP::HepRotation& rot = theSurveyValues->m_align[theSurveyIndex].rotation();
00903         
00904         AlignableSurface surf( align::PositionType( pos.x(), pos.y(), pos.z() ),
00905                                                   align::RotationType( rot.xx(), rot.xy(), rot.xz(),
00906                                                                                           rot.yx(), rot.yy(), rot.yz(),
00907                                                                                           rot.zx(), rot.zy(), rot.zz() ) );
00908         
00909         surf.setWidth( ali->surface().width() );
00910         surf.setLength( ali->surface().length() );
00911         
00912         ali->setSurvey( new SurveyDet( surf, error.matrix() ) );
00913         
00914         ++theSurveyIndex;
00915         
00916 }
00917 
00918 bool TrackerGeometryCompare::passIdCut( uint32_t id ){
00919         
00920         bool pass = false;
00921         int nEntries = _detIdFlagVector.size();
00922         
00923         for (int i = 0; i < nEntries; i++){
00924                 if (_detIdFlagVector[i] == id) pass = true;
00925         }
00926         
00927         return pass;
00928         
00929 }
00930 
00931 void TrackerGeometryCompare::fillIdentifiers( int subdetlevel, int rawid ){
00932         
00933         
00934         switch( subdetlevel ){
00935                         
00936                 case 1:
00937                 {
00938                         PXBDetId pxbid( rawid );
00939                         _identifiers[0] = pxbid.module();
00940                         _identifiers[1] = pxbid.ladder();
00941                         _identifiers[2] = pxbid.layer();
00942                         _identifiers[3] = 999;
00943                         _identifiers[4] = 999;
00944                         _identifiers[5] = 999;
00945                         break;
00946                 }
00947                 case 2:
00948                 {
00949                         PXFDetId pxfid( rawid );
00950                         _identifiers[0] = pxfid.module();
00951                         _identifiers[1] = pxfid.panel();
00952                         _identifiers[2] = pxfid.blade();
00953                         _identifiers[3] = pxfid.disk();
00954                         _identifiers[4] = pxfid.side();
00955                         _identifiers[5] = 999;
00956                         break;
00957                 }
00958                 case 3:
00959                 {
00960                         TIBDetId tibid( rawid );
00961                         _identifiers[0] = tibid.module();
00962                         _identifiers[1] = tibid.string()[0];
00963                         _identifiers[2] = tibid.string()[1];
00964                         _identifiers[3] = tibid.string()[2];
00965                         _identifiers[4] = tibid.layer();
00966                         _identifiers[5] = 999;
00967                         break;
00968                 }
00969                 case 4: 
00970                 {
00971                         TIDDetId tidid( rawid );
00972                         _identifiers[0] = tidid.module()[0];
00973                         _identifiers[1] = tidid.module()[1];
00974                         _identifiers[2] = tidid.ring();
00975                         _identifiers[3] = tidid.wheel();
00976                         _identifiers[4] = tidid.side();
00977                         _identifiers[5] = 999;
00978                         break;
00979                 }
00980                 case 5: 
00981                 {
00982                         TOBDetId tobid( rawid );
00983                         _identifiers[0] = tobid.module();
00984                         _identifiers[1] = tobid.rod()[0];
00985                         _identifiers[2] = tobid.rod()[1];
00986                         _identifiers[3] = tobid.layer();
00987                         _identifiers[4] = 999;
00988                         _identifiers[5] = 999;
00989                         break;
00990                 }
00991                 case 6: 
00992                 {
00993                         TECDetId tecid( rawid );
00994                         _identifiers[0] = tecid.module();
00995                         _identifiers[1] = tecid.ring();
00996                         _identifiers[2] = tecid.petal()[0];
00997                         _identifiers[3] = tecid.petal()[1];
00998                         _identifiers[4] = tecid.wheel();
00999                         _identifiers[5] = tecid.side();
01000                         break;
01001                 }
01002                 default:
01003                 {
01004                         std::cout << "Error: bad subdetid!!" << std::endl;
01005                         break;
01006                 }
01007                         
01008         }
01009 }
01010 
01011 
01012 DEFINE_FWK_MODULE(TrackerGeometryCompare);