TestAnalyzer

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
// -*- C++ -*-
//
// Package:    TestAnalyzer
// Class:      TestAnalyzer
//
//
// Description: Module to test the Alignment software
//
//
// Original Author:  Frederic Ronga
//         Created:  March 16, 2006
//

// system include files
#include <string>
#include <TTree.h>
#include <TFile.h>
#include <TRotMatrix.h>

// user include files
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "Geometry/CommonDetUnit/interface/GeomDet.h"

#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"

//
//
// class declaration
//

class TestAnalyzer : public edm::one::EDAnalyzer<> {
public:
  explicit TestAnalyzer(const edm::ParameterSet&);
  ~TestAnalyzer();

  virtual void analyze(const edm::Event&, const edm::EventSetup&);

private:
  // ----------member data ---------------------------
  const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
  TTree* theTree;
  TFile* theFile;
  float x_, y_, z_, phi_, theta_, length_, thick_, width_;
  int Id_;
  TRotMatrix* rot_;
};

//
// constructors and destructor
//
TestAnalyzer::TestAnalyzer(const edm::ParameterSet& iConfig) : tkGeomToken_(esConsumes()) {
  // Open root file and define tree
  std::string fileName = iConfig.getUntrackedParameter<std::string>("fileName", "test.root");
  theFile = new TFile(fileName.c_str(), "RECREATE");
  theTree = new TTree("theTree", "Detector units positions");

  theTree->Branch("Id", &Id_, "Id/I");
  theTree->Branch("x", &x_, "x/F");
  theTree->Branch("y", &y_, "y/F");
  theTree->Branch("z", &z_, "z/F");
  theTree->Branch("phi", &phi_, "phi/F");
  theTree->Branch("theta", &theta_, "theta/F");
  theTree->Branch("length", &length_, "length/F");
  theTree->Branch("width", &width_, "width/F");
  theTree->Branch("thick", &thick_, "thick/F");
  rot_ = 0;
  theTree->Branch("rot", "TRotMatrix", &rot_);
}

TestAnalyzer::~TestAnalyzer() {
  theTree->Write();
  theFile->Close();
}

void TestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
  edm::LogInfo("TrackerAlignment") << "Starting!";

  //
  // Retrieve tracker geometry from event setup
  //
  const TrackerGeometry* trackerGeometry = &iSetup.getData(tkGeomToken_);

  // Now loop on detector units, and store position and orientation
  for (auto iGeomDet = trackerGeometry->dets().begin(); iGeomDet != trackerGeometry->dets().end(); iGeomDet++) {
    Id_ = (*iGeomDet)->geographicalId().rawId();
    x_ = (*iGeomDet)->position().x();
    y_ = (*iGeomDet)->position().y();
    z_ = (*iGeomDet)->position().z();
    phi_ = (*iGeomDet)->surface().normalVector().phi();
    theta_ = (*iGeomDet)->surface().normalVector().theta();
    length_ = (*iGeomDet)->surface().bounds().length();
    width_ = (*iGeomDet)->surface().bounds().width();
    thick_ = (*iGeomDet)->surface().bounds().thickness();

    double matrix[9] = {(*iGeomDet)->rotation().xx(),
                        (*iGeomDet)->rotation().xy(),
                        (*iGeomDet)->rotation().xz(),
                        (*iGeomDet)->rotation().yx(),
                        (*iGeomDet)->rotation().yy(),
                        (*iGeomDet)->rotation().yz(),
                        (*iGeomDet)->rotation().zx(),
                        (*iGeomDet)->rotation().zy(),
                        (*iGeomDet)->rotation().zz()};
    rot_ = new TRotMatrix("rot", "rot", matrix);

    theTree->Fill();
  }

  edm::LogInfo("TrackerAlignment") << "Done!";
}

//define this as a plug-in
DEFINE_FWK_MODULE(TestAnalyzer);