File indexing completed on 2024-04-06 12:08:39
0001
0002 #include <cmath>
0003 #include <iostream>
0004 #include <memory>
0005 #include <sstream>
0006 #include <vector>
0007
0008
0009 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0010 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0011 #include "DQMServices/Core/interface/DQMStore.h"
0012 #include "DataFormats/TrackerCommon/interface/SiStripSubStructure.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/ParameterSet/interface/FileInPath.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0021 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0022 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0023
0024
0025 #include "TPostScript.h"
0026 #include "TCanvas.h"
0027
0028
0029 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
0030
0031
0032
0033
0034
0035
0036 class testTkHistoMap : public DQMOneEDAnalyzer<> {
0037 public:
0038 explicit testTkHistoMap(const edm::ParameterSet&);
0039 ~testTkHistoMap() override = default;
0040
0041 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override {}
0042 void analyze(const edm::Event&, const edm::EventSetup&) override;
0043
0044 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045
0046 void endJob(void) override;
0047
0048 private:
0049 void read(const TkDetMap* tkDetMap);
0050 void create(const TkDetMap* tkDetMap);
0051
0052 const edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tTopoToken;
0053 const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeoToken;
0054
0055 const bool readFromFile_;
0056 const edm::FileInPath fp_;
0057 std::unique_ptr<TkHistoMap> tkhistoID, tkhisto, tkhistoBis, tkhistoZ, tkhistoPhi, tkhistoR, tkhistoCheck;
0058 };
0059
0060 void testTkHistoMap::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0061 edm::ParameterSetDescription desc;
0062 desc.add<bool>("readFromFile", false)->setComment("read the map from ROOT file");
0063 desc.add<edm::FileInPath>("inputFile", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))
0064 ->setComment("source of the tkhisto map values");
0065 descriptions.add("testglobalrunsummary", desc);
0066 }
0067
0068
0069 testTkHistoMap::testTkHistoMap(const edm::ParameterSet& iConfig)
0070 : tTopoToken(esConsumes()),
0071 tkGeoToken(esConsumes()),
0072 readFromFile_(iConfig.getParameter<bool>("readFromFile")),
0073 fp_(iConfig.getParameter<edm::FileInPath>("inputFile")) {}
0074
0075 void testTkHistoMap::create(const TkDetMap* tkDetMap) {
0076 tkhistoID = std::make_unique<TkHistoMap>(tkDetMap, "detIdV", "detIdV", -1);
0077 tkhisto = std::make_unique<TkHistoMap>(tkDetMap, "detId", "detId", -1);
0078 tkhistoBis = std::make_unique<TkHistoMap>(
0079 tkDetMap,
0080 "detIdBis",
0081 "detIdBis",
0082 0,
0083 1);
0084 tkhistoZ = std::make_unique<TkHistoMap>(tkDetMap, "Zmap", "Zmap");
0085 tkhistoPhi = std::make_unique<TkHistoMap>(tkDetMap, "Phi", "Phi");
0086 tkhistoR = std::make_unique<TkHistoMap>(
0087 tkDetMap,
0088 "Rmap",
0089 "Rmap",
0090 -99.);
0091 tkhistoCheck = std::make_unique<TkHistoMap>(tkDetMap, "check", "check");
0092 }
0093
0094
0095 void testTkHistoMap::read(const TkDetMap* tkDetMap) {
0096 edm::Service<DQMStore>().operator->()->open("test.root");
0097
0098 tkhistoID = std::make_unique<TkHistoMap>(tkDetMap);
0099 tkhisto = std::make_unique<TkHistoMap>(tkDetMap);
0100 tkhistoBis = std::make_unique<TkHistoMap>(tkDetMap);
0101 tkhistoZ = std::make_unique<TkHistoMap>(tkDetMap);
0102 tkhistoPhi = std::make_unique<TkHistoMap>(tkDetMap);
0103 tkhistoR = std::make_unique<TkHistoMap>(tkDetMap);
0104 tkhistoCheck = std::make_unique<TkHistoMap>(tkDetMap);
0105
0106 tkhistoID->loadTkHistoMap("detIdV", "detIdV");
0107 tkhisto->loadTkHistoMap("detId", "detId");
0108 tkhistoBis->loadTkHistoMap("detIdBis", "detIdBis", true);
0109 tkhistoZ->loadTkHistoMap("Zmap", "Zmap");
0110 tkhistoPhi->loadTkHistoMap("Phi", "Phi");
0111 tkhistoR->loadTkHistoMap("Rmap", "Rmap");
0112 tkhistoCheck->loadTkHistoMap("check", "check");
0113 }
0114
0115 void testTkHistoMap::endJob(void) {
0116
0117 size_t ilayer = 1;
0118 std::string histoTitle = tkhisto->getMap(ilayer)->getTitle();
0119 uint32_t detB = tkhisto->getDetId(ilayer, 5, 5);
0120 uint32_t detA = tkhisto->getDetId(histoTitle, 5, 5);
0121 if (detA == 0 || detA != detB)
0122 edm::LogError("testTkHistoMap") << " for layer " << ilayer << " the extracted detid in a bin is wrong " << detA
0123 << " " << detB << std::endl;
0124
0125
0126 TCanvas C("c", "c");
0127 C.Divide(3, 3);
0128 C.Update();
0129 TPostScript ps("test.ps", 121);
0130 ps.NewPage();
0131 for (size_t ilayer = 1; ilayer < 34; ++ilayer) {
0132 C.cd(1);
0133 tkhisto->getMap(ilayer)->getTProfile2D()->Draw("TEXT");
0134 C.cd(2);
0135 tkhistoZ->getMap(ilayer)->getTProfile2D()->Draw("BOXCOL");
0136 C.cd(3);
0137 tkhistoPhi->getMap(ilayer)->getTProfile2D()->Draw("BOXCOL");
0138 C.cd(4);
0139 tkhistoR->getMap(ilayer)->getTProfile2D()->Draw("BOXCOL");
0140 C.cd(5);
0141 tkhistoCheck->getMap(ilayer)->getTProfile2D()->Draw("BOXCOL");
0142 C.cd(6);
0143 tkhistoBis->getMap(ilayer)->getTProfile2D()->Draw("BOXCOL");
0144 C.Update();
0145 ps.NewPage();
0146 }
0147 ps.Close();
0148
0149 if (!readFromFile_)
0150 edm::Service<DQMStore>().operator->()->save("test.root");
0151
0152 tkhisto->saveAsCanvas("test.canvas.root", "LEGO", "RECREATE");
0153 tkhistoBis->saveAsCanvas("test.canvas.root", "LEGO", "RECREATE");
0154 tkhistoZ->saveAsCanvas("test.canvas.root", "LEGO", "UPDATE");
0155 tkhistoPhi->saveAsCanvas("test.canvas.root", "LEGO", "UPDATE");
0156 tkhistoR->saveAsCanvas("test.canvas.root", "LEGO", "UPDATE");
0157 tkhistoCheck->saveAsCanvas("test.canvas.root", "LEGO", "UPDATE");
0158
0159
0160 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0161 TrackerMap tkmap, tkmapZ, tkmapPhi, tkmapR;
0162
0163 tkmap.setPalette(1);
0164 tkmapZ.setPalette(2);
0165 tkmapPhi.setPalette(2);
0166 tkmapR.setPalette(2);
0167
0168 tkhisto->dumpInTkMap(&tkmap);
0169 tkhistoZ->dumpInTkMap(&tkmapZ);
0170 tkhistoPhi->dumpInTkMap(&tkmapPhi);
0171 tkhistoR->dumpInTkMap(&tkmapR);
0172
0173 tkmap.save(true, 0, 0, "testTkMap.png");
0174 tkmapZ.save(true, 0, 0, "testTkMapZ.png");
0175 tkmapPhi.save(true, 0, 0, "testTkMapPhi.png");
0176 tkmapR.save(true, 0, 0, "testTkMapR.png");
0177 }
0178
0179
0180
0181
0182
0183
0184 void testTkHistoMap::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0185 const TkDetMap* tkDetMap = &iSetup.getData(tTopoToken);
0186 if (!readFromFile_) {
0187 create(tkDetMap);
0188 } else {
0189 read(tkDetMap);
0190 }
0191
0192 if (readFromFile_)
0193 return;
0194
0195 const TrackerGeometry* tkgeom = &iSetup.getData(tkGeoToken);
0196
0197 float value;
0198 LocalPoint localPos(0., 0., 0.);
0199 GlobalPoint globalPos;
0200
0201 tkhisto->fillFromAscii(fp_.fullPath());
0202 tkhistoBis->fillFromAscii(fp_.fullPath());
0203
0204 for (const auto det : tkgeom->detUnits()) {
0205 const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(det);
0206 if (stripDet != nullptr) {
0207 globalPos = stripDet->surface().toGlobal(localPos);
0208 const DetId id = stripDet->geographicalId();
0209
0210 value = id % 1000000;
0211
0212 tkhistoID->fill(id, value);
0213
0214 tkhistoZ->fill(id, globalPos.z());
0215 tkhistoPhi->fill(id, globalPos.phi());
0216 tkhistoR->fill(id, globalPos.perp());
0217 tkhistoCheck->add(id, 1.);
0218 tkhistoCheck->add(id, 1.);
0219
0220 edm::LogInfo("testTkHistoMap") << "detid " << id.rawId() << " pos z " << globalPos.z() << " phi "
0221 << globalPos.phi() << " r " << globalPos.perp() << std::endl;
0222
0223 if (value != tkhistoID->getValue(id))
0224 edm::LogError("testTkHistoMap") << " input value " << value << " differs from read value "
0225 << tkhistoID->getValue(id) << std::endl;
0226
0227
0228
0229
0230
0231
0232
0233
0234 }
0235 }
0236 }
0237
0238
0239 DEFINE_FWK_MODULE(testTkHistoMap);