CMS 3D CMS Logo

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