File indexing completed on 2024-09-07 04:35:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <string>
0021 #include <iostream>
0022 #include <fstream>
0023
0024
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0030 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0031 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0032 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0033 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0034
0035 class SiStripDetInfoFileWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0036 public:
0037 explicit SiStripDetInfoFileWriter(const edm::ParameterSet&);
0038 ~SiStripDetInfoFileWriter() override;
0039
0040 private:
0041 void beginRun(const edm::Run&, const edm::EventSetup& iSetup) override;
0042 void analyze(const edm::Event&, const edm::EventSetup&) override {}
0043 void endRun(const edm::Run&, const edm::EventSetup& iSetup) override {}
0044
0045 private:
0046 std::ofstream outputFile_;
0047 std::string filePath_;
0048 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0049 };
0050
0051 using namespace cms;
0052 using namespace std;
0053
0054 SiStripDetInfoFileWriter::SiStripDetInfoFileWriter(const edm::ParameterSet& iConfig) {
0055 edm::LogInfo("SiStripDetInfoFileWriter::SiStripDetInfoFileWriter");
0056
0057 filePath_ = iConfig.getUntrackedParameter<std::string>("FilePath", std::string("SiStripDetInfo.dat"));
0058 tkGeomToken_ = esConsumes<edm::Transition::BeginRun>();
0059 }
0060
0061 SiStripDetInfoFileWriter::~SiStripDetInfoFileWriter() {
0062 edm::LogInfo("SiStripDetInfoFileWriter::~SiStripDetInfoFileWriter");
0063 }
0064
0065 void SiStripDetInfoFileWriter::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0066 outputFile_.open(filePath_.c_str());
0067
0068 if (outputFile_.is_open()) {
0069 const auto& dd = iSetup.getData(tkGeomToken_);
0070
0071 edm::LogInfo("SiStripDetInfoFileWriter::beginRun - got geometry ") << std::endl;
0072
0073 edm::LogInfo("SiStripDetInfoFileWriter") << " There are " << dd.detUnits().size() << " detectors" << std::endl;
0074
0075 for (const auto& it : dd.detUnits()) {
0076 const StripGeomDetUnit* mit = dynamic_cast<StripGeomDetUnit const*>(it);
0077
0078 if (mit != nullptr) {
0079 uint32_t detid = (mit->geographicalId()).rawId();
0080 double stripLength = mit->specificTopology().stripLength();
0081 unsigned short numberOfAPVs = mit->specificTopology().nstrips() / 128;
0082 float thickness = mit->specificSurface().bounds().thickness();
0083
0084 if (numberOfAPVs < 1 || numberOfAPVs > 6) {
0085 edm::LogError("SiStripDetInfoFileWriter")
0086 << " Problem with Number of strips in detector.. " << mit->specificTopology().nstrips()
0087 << "Will not write this entry to file" << endl;
0088 continue;
0089 }
0090
0091 outputFile_ << detid << " " << numberOfAPVs << " " << stripLength << " " << thickness << "\n";
0092 }
0093 }
0094 outputFile_.close();
0095 } else {
0096 edm::LogError("SiStripDetInfoFileWriter::beginRun - Unable to open file") << endl;
0097 return;
0098 }
0099 }
0100
0101 DEFINE_FWK_MODULE(SiStripDetInfoFileWriter);