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