Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-22 06:26:42

0001 // -*- C++ -*-
0002 //
0003 // Package:    TestIdealGeometry
0004 // Class:      TestIdealGeometry
0005 //
0006 //
0007 // Description: Module to test the SurveyConverter software
0008 //
0009 //
0010 // Original Author:  Roberto Covarelli
0011 //         Created:  March 16, 2006
0012 //
0013 
0014 // system include files
0015 #include "TTree.h"
0016 #include "TFile.h"
0017 // #include "TRotMatrix.h"
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 
0027 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0030 /* #include "CondFormats/Alignment/interface/Alignments.h"
0031 #include "CondFormats/Alignment/interface/AlignTransform.h"
0032 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0033 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0034 #include "CondFormats/Alignment/interface/AlignTransformError.h"
0035 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"*/
0036 
0037 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0038 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0039 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0040 
0041 #include "Alignment/SurveyAnalysis/interface/SurveyDataReader.h"
0042 //
0043 //
0044 // class declaration
0045 //
0046 using namespace std;
0047 
0048 class TestIdealGeometry : public edm::one::EDAnalyzer<> {
0049   typedef SurveyDataReader::MapType MapType;
0050   typedef SurveyDataReader::PairType PairType;
0051   typedef SurveyDataReader::MapTypeOr MapTypeOr;
0052   typedef SurveyDataReader::PairTypeOr PairTypeOr;
0053 
0054 public:
0055   explicit TestIdealGeometry(const edm::ParameterSet&);
0056   ~TestIdealGeometry();
0057 
0058   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0059 
0060 private:
0061   // ----------member data ---------------------------
0062   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0063   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0064   TTree* theTree;
0065   TFile* theFile;
0066   edm::ParameterSet theParameterSet;
0067   float dx_, dy_, dz_;
0068   float dtx_, dty_, dtz_;
0069   float dkx_, dky_, dkz_;
0070   float dnx_, dny_, dnz_;
0071   int Id_;
0072   // TRotMatrix* rot_;
0073   static const int NFILES = 2;
0074 };
0075 
0076 //
0077 // constructors and destructor
0078 //
0079 TestIdealGeometry::TestIdealGeometry(const edm::ParameterSet& iConfig)
0080     : tTopoToken_(esConsumes()), tkGeomToken_(esConsumes()), theParameterSet(iConfig) {
0081   // Open root file and define tree
0082   std::string fileName = theParameterSet.getUntrackedParameter<std::string>("fileName", "testideal.root");
0083   theFile = new TFile(fileName.c_str(), "RECREATE");
0084   theTree = new TTree("theTree", "Detector units positions");
0085 
0086   theTree->Branch("Id", &Id_, "Id/I");
0087   theTree->Branch("dx", &dx_, "dx/F");
0088   theTree->Branch("dy", &dy_, "dy/F");
0089   theTree->Branch("dz", &dz_, "dz/F");
0090   theTree->Branch("dtx", &dtx_, "dtx/F");
0091   theTree->Branch("dty", &dty_, "dty/F");
0092   theTree->Branch("dtz", &dtz_, "dtz/F");
0093   theTree->Branch("dkx", &dkx_, "dkx/F");
0094   theTree->Branch("dky", &dky_, "dky/F");
0095   theTree->Branch("dkz", &dkz_, "dkz/F");
0096   theTree->Branch("dnx", &dnx_, "dnx/F");
0097   theTree->Branch("dny", &dny_, "dny/F");
0098   theTree->Branch("dnz", &dnz_, "dnz/F");
0099 }
0100 
0101 TestIdealGeometry::~TestIdealGeometry() {
0102   theTree->Write();
0103   theFile->Close();
0104 }
0105 
0106 void TestIdealGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0107   //Retrieve tracker topology from geometry
0108   const TrackerTopology* const tTopo = &iSetup.getData(tTopoToken_);
0109   edm::LogInfo("TrackerAlignment") << "Starting!";
0110 
0111   //
0112   // Read in the survey information from the text files
0113   //
0114   edm::ParameterSet textFiles = theParameterSet.getParameter<edm::ParameterSet>("textFileNames");
0115   std::string textFileNames[NFILES];
0116   std::string fileType[NFILES];
0117   textFileNames[0] = textFiles.getUntrackedParameter<std::string>("forTIB", "NONE");
0118   fileType[0] = "TIB";
0119   textFileNames[1] = textFiles.getUntrackedParameter<std::string>("forTID", "NONE");
0120   fileType[1] = "TID";
0121 
0122   SurveyDataReader dataReader;
0123   for (int ii = 0; ii < NFILES; ii++) {
0124     if (textFileNames[ii] == "NONE")
0125       throw cms::Exception("BadConfig") << fileType[ii] << " input file not found in configuration";
0126     dataReader.readFile(textFileNames[ii], fileType[ii], tTopo);
0127   }
0128 
0129   edm::LogInfo("TrackerAlignment") << "Files read";
0130 
0131   const MapTypeOr& theSurveyMap = dataReader.surveyMap();
0132 
0133   edm::LogInfo("TrackerAlignment") << "Map written";
0134 
0135   //
0136   // Retrieve tracker geometry from event setup
0137   //
0138   const TrackerGeometry* trackerGeometry = &iSetup.getData(tkGeomToken_);
0139 
0140   // Retrieve alignment[Error]s from DBase
0141   // edm::ESHandle<Alignments> alignments;
0142   // iSetup.get<TrackerAlignmentRcd>().get( alignments );
0143   // edm::ESHandle<AlignmentErrorsExtended> alignmentErrors;
0144   // iSetup.get<TrackerAlignmentErrorExtendedRcd>().get( alignmentErrors );
0145 
0146   int countDet = 0;
0147 
0148   // Now loop on detector units, and store difference position and orientation w.r.t. survey
0149   for (auto iGeomDet = trackerGeometry->dets().begin(); iGeomDet != trackerGeometry->dets().end(); iGeomDet++)
0150   // for (auto iGeomDet = alignments->m_align.begin();
0151   //    iGeomDet != alignments->m_align.end(); iGeomDet++ )
0152   {
0153     if (countDet == 0) {  // Enter only once for double-sided dets
0154 
0155       countDet++;
0156       unsigned int comparisonVect[6] = {0, 0, 0, 0, 0, 0};
0157 
0158       if (((*iGeomDet)->geographicalId()).subdetId() == int(StripSubdetector::TIB)) {
0159         comparisonVect[0] = int(StripSubdetector::TIB);
0160 
0161         comparisonVect[1] = tTopo->tibLayer((*iGeomDet)->geographicalId());
0162         if (comparisonVect[1] < 3)
0163           countDet = countDet + 2;
0164         std::vector<unsigned int> theString = tTopo->tibStringInfo((*iGeomDet)->geographicalId());
0165         comparisonVect[2] = theString[0];
0166         comparisonVect[3] = theString[1];
0167         comparisonVect[4] = theString[2];
0168         comparisonVect[5] = tTopo->tibModule((*iGeomDet)->geographicalId());
0169 
0170       } else if (((*iGeomDet)->geographicalId()).subdetId() == int(StripSubdetector::TID)) {
0171         comparisonVect[0] = int(StripSubdetector::TID);
0172 
0173         comparisonVect[1] = tTopo->tidSide((*iGeomDet)->geographicalId());
0174         comparisonVect[2] = tTopo->tidWheel((*iGeomDet)->geographicalId());
0175         comparisonVect[3] = tTopo->tidRing((*iGeomDet)->geographicalId());
0176         if (comparisonVect[3] < 3)
0177           countDet = countDet + 2;
0178         std::vector<unsigned int> theModule = tTopo->tidModuleInfo((*iGeomDet)->geographicalId());
0179         comparisonVect[4] = theModule[0];
0180         comparisonVect[5] = theModule[1];
0181       }
0182 
0183       for (MapTypeOr::const_iterator it = theSurveyMap.begin(); it != theSurveyMap.end(); it++) {
0184         std::vector<int> locPos = (it)->first;
0185         align::Scalars align_params = (it)->second;
0186 
0187         if (locPos[0] == int(comparisonVect[0]) && locPos[1] == int(comparisonVect[1]) &&
0188             locPos[2] == int(comparisonVect[2]) && locPos[3] == int(comparisonVect[3]) &&
0189             locPos[4] == int(comparisonVect[4]) && locPos[5] == int(comparisonVect[5])) {
0190           Id_ = (*iGeomDet)->geographicalId().rawId();
0191           cout << "DetId = " << Id_ << " " << endl;
0192           cout << "DetId decodified = " << comparisonVect[0] << " " << comparisonVect[1] << " " << comparisonVect[2]
0193                << " " << comparisonVect[3] << " " << comparisonVect[4] << " " << comparisonVect[5] << endl;
0194           dx_ = (*iGeomDet)->position().x() - align_params[0];
0195           cout << "X pos : TRACKER_GEOM = " << std::fixed << std::setprecision(2) << (*iGeomDet)->position().x()
0196                << " / IDEAL RICCARDO = " << align_params[0] << endl;
0197           dy_ = (*iGeomDet)->position().y() - align_params[1];
0198           cout << "Y pos : TRACKER_GEOM = " << std::fixed << std::setprecision(2) << (*iGeomDet)->position().y()
0199                << " / IDEAL RICCARDO = " << align_params[1] << endl;
0200           dz_ = (*iGeomDet)->position().z() - align_params[2];
0201           cout << "Z pos : TRACKER_GEOM = " << std::fixed << std::setprecision(2) << (*iGeomDet)->position().z()
0202                << " / IDEAL RICCARDO = " << align_params[2] << endl;
0203           dtx_ = (*iGeomDet)->rotation().xx() - align_params[6];
0204           cout << "Trans vect X : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().xx()
0205                << " / IDEAL RICCARDO = " << align_params[6] << endl;
0206           dty_ = (*iGeomDet)->rotation().xy() - align_params[7];
0207           cout << "Trans vect Y : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().xy()
0208                << " / IDEAL RICCARDO = " << align_params[7] << endl;
0209           dtz_ = (*iGeomDet)->rotation().xz() - align_params[8];
0210           cout << "Trans vect Z : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().xz()
0211                << " / IDEAL RICCARDO = " << align_params[8] << endl;
0212           dkx_ = (*iGeomDet)->rotation().yx() - align_params[9];
0213           cout << "Long vect X : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().yx()
0214                << " / IDEAL RICCARDO = " << align_params[9] << endl;
0215           dky_ = (*iGeomDet)->rotation().yy() - align_params[10];
0216           cout << "Long vect Y : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().yy()
0217                << " / IDEAL RICCARDO = " << align_params[10] << endl;
0218           dkz_ = (*iGeomDet)->rotation().yz() - align_params[11];
0219           cout << "Long vect Z : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().yz()
0220                << " / IDEAL RICCARDO = " << align_params[11] << endl;
0221           dnx_ = (*iGeomDet)->rotation().zx() - align_params[3];
0222           cout << "Norm vect X : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().zx()
0223                << " / IDEAL RICCARDO = " << align_params[3] << endl;
0224           dny_ = (*iGeomDet)->rotation().zy() - align_params[4];
0225           cout << "Norm vect Y : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().zy()
0226                << " / IDEAL RICCARDO = " << align_params[4] << endl;
0227           dnz_ = (*iGeomDet)->rotation().zz() - align_params[5];
0228           cout << "Norm vect Z : TRACKER_GEOM = " << std::fixed << std::setprecision(3) << (*iGeomDet)->rotation().zz()
0229                << " / IDEAL RICCARDO = " << align_params[5] << endl;
0230           theTree->Fill();
0231         }
0232       }
0233     }
0234     countDet--;
0235   }
0236 
0237   edm::LogInfo("TrackerAlignment") << "Done!";
0238 }
0239 
0240 //define this as a plug-in
0241 DEFINE_FWK_MODULE(TestIdealGeometry);