File indexing completed on 2024-04-06 11:57:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <string>
0016 #include <TTree.h>
0017 #include <TFile.h>
0018 #include <TRotMatrix.h>
0019
0020
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029
0030 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0031
0032 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0033 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0034
0035
0036
0037
0038
0039
0040 class TestAnalyzer : public edm::one::EDAnalyzer<> {
0041 public:
0042 explicit TestAnalyzer(const edm::ParameterSet&);
0043 ~TestAnalyzer();
0044
0045 virtual void analyze(const edm::Event&, const edm::EventSetup&);
0046
0047 private:
0048
0049 const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0050 TTree* theTree;
0051 TFile* theFile;
0052 float x_, y_, z_, phi_, theta_, length_, thick_, width_;
0053 int Id_;
0054 TRotMatrix* rot_;
0055 };
0056
0057
0058
0059
0060 TestAnalyzer::TestAnalyzer(const edm::ParameterSet& iConfig) : tkGeomToken_(esConsumes()) {
0061
0062 std::string fileName = iConfig.getUntrackedParameter<std::string>("fileName", "test.root");
0063 theFile = new TFile(fileName.c_str(), "RECREATE");
0064 theTree = new TTree("theTree", "Detector units positions");
0065
0066 theTree->Branch("Id", &Id_, "Id/I");
0067 theTree->Branch("x", &x_, "x/F");
0068 theTree->Branch("y", &y_, "y/F");
0069 theTree->Branch("z", &z_, "z/F");
0070 theTree->Branch("phi", &phi_, "phi/F");
0071 theTree->Branch("theta", &theta_, "theta/F");
0072 theTree->Branch("length", &length_, "length/F");
0073 theTree->Branch("width", &width_, "width/F");
0074 theTree->Branch("thick", &thick_, "thick/F");
0075 rot_ = 0;
0076 theTree->Branch("rot", "TRotMatrix", &rot_);
0077 }
0078
0079 TestAnalyzer::~TestAnalyzer() {
0080 theTree->Write();
0081 theFile->Close();
0082 }
0083
0084 void TestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0085 edm::LogInfo("TrackerAlignment") << "Starting!";
0086
0087
0088
0089
0090 const TrackerGeometry* trackerGeometry = &iSetup.getData(tkGeomToken_);
0091
0092
0093 for (auto iGeomDet = trackerGeometry->dets().begin(); iGeomDet != trackerGeometry->dets().end(); iGeomDet++) {
0094 Id_ = (*iGeomDet)->geographicalId().rawId();
0095 x_ = (*iGeomDet)->position().x();
0096 y_ = (*iGeomDet)->position().y();
0097 z_ = (*iGeomDet)->position().z();
0098 phi_ = (*iGeomDet)->surface().normalVector().phi();
0099 theta_ = (*iGeomDet)->surface().normalVector().theta();
0100 length_ = (*iGeomDet)->surface().bounds().length();
0101 width_ = (*iGeomDet)->surface().bounds().width();
0102 thick_ = (*iGeomDet)->surface().bounds().thickness();
0103
0104 double matrix[9] = {(*iGeomDet)->rotation().xx(),
0105 (*iGeomDet)->rotation().xy(),
0106 (*iGeomDet)->rotation().xz(),
0107 (*iGeomDet)->rotation().yx(),
0108 (*iGeomDet)->rotation().yy(),
0109 (*iGeomDet)->rotation().yz(),
0110 (*iGeomDet)->rotation().zx(),
0111 (*iGeomDet)->rotation().zy(),
0112 (*iGeomDet)->rotation().zz()};
0113 rot_ = new TRotMatrix("rot", "rot", matrix);
0114
0115 theTree->Fill();
0116 }
0117
0118 edm::LogInfo("TrackerAlignment") << "Done!";
0119 }
0120
0121
0122 DEFINE_FWK_MODULE(TestAnalyzer);