File indexing completed on 2023-03-17 10:46:24
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0010 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0011 #include "CondCore/CondDB/interface/Time.h"
0012 #include "CondCore/SiStripPlugins/interface/SiStripPayloadInspectorHelper.h"
0013 #include "CondCore/Utilities/interface/PayloadInspector.h"
0014 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0015 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0016 #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
0017 #include "DQM/TrackerRemapper/interface/SiStripTkMaps.h"
0018 #include "SiStripCondObjectRepresent.h"
0019
0020 #include <memory>
0021 #include <sstream>
0022
0023
0024 #include "TH2F.h"
0025 #include "TLegend.h"
0026 #include "TCanvas.h"
0027 #include "TLine.h"
0028 #include "TStyle.h"
0029 #include "TLatex.h"
0030 #include "TPave.h"
0031 #include "TPaveStats.h"
0032 #include "TGaxis.h"
0033
0034 namespace {
0035
0036 using namespace cond::payloadInspector;
0037
0038 class SiStripLorentzAngleContainer
0039 : public SiStripCondObjectRepresent::SiStripDataContainer<SiStripLorentzAngle, float> {
0040 public:
0041 SiStripLorentzAngleContainer(const std::shared_ptr<SiStripLorentzAngle> &payload,
0042 const SiStripPI::MetaData &metadata,
0043 const std::string &tagName)
0044 : SiStripCondObjectRepresent::SiStripDataContainer<SiStripLorentzAngle, float>(payload, metadata, tagName) {
0045 payloadType_ = "SiStripLorentzAngle";
0046 setGranularity(SiStripCondObjectRepresent::PERMODULE);
0047 }
0048
0049 void storeAllValues() override {
0050 auto LAMap_ = payload_->getLorentzAngles();
0051 for (const auto &element : LAMap_) {
0052 SiStripCondData_.fillByPushBack(element.first, element.second);
0053 }
0054 }
0055 };
0056
0057
0058
0059
0060 class SiStripLorentzAngleTest : public PlotImage<SiStripLorentzAngle, SINGLE_IOV> {
0061 public:
0062 SiStripLorentzAngleTest() : PlotImage<SiStripLorentzAngle, SINGLE_IOV>("SiStrip LorentzAngle values") {}
0063
0064 bool fill() override {
0065 auto tag = PlotBase::getTag<0>();
0066 auto iov = tag.iovs.front();
0067 auto tagname = tag.name;
0068 std::shared_ptr<SiStripLorentzAngle> payload = fetchPayload(std::get<1>(iov));
0069 if (payload.get()) {
0070 SiStripLorentzAngleContainer *objContainer = new SiStripLorentzAngleContainer(payload, iov, tagname);
0071
0072
0073 TCanvas canvas("Partion summary", "partition summary", 1200, 1000);
0074 objContainer->fillSummary(canvas);
0075
0076 std::string fileName(m_imageFileName);
0077 canvas.SaveAs(fileName.c_str());
0078
0079 }
0080 return true;
0081 }
0082 };
0083
0084 class SiStripLorentzAngleByPartition : public PlotImage<SiStripLorentzAngle, SINGLE_IOV> {
0085 public:
0086 SiStripLorentzAngleByPartition()
0087 : PlotImage<SiStripLorentzAngle, SINGLE_IOV>("SiStrip LorentzAngle By Partition") {}
0088
0089 bool fill() override {
0090 auto tag = PlotBase::getTag<0>();
0091 auto iov = tag.iovs.front();
0092 auto tagname = tag.name;
0093 std::shared_ptr<SiStripLorentzAngle> payload = fetchPayload(std::get<1>(iov));
0094 if (payload.get()) {
0095 SiStripLorentzAngleContainer *objContainer = new SiStripLorentzAngleContainer(payload, iov, tagname);
0096 objContainer->printAll();
0097
0098 TCanvas canvas("Partition summary", "partition summary", 1400, 1000);
0099 objContainer->fillByPartition(canvas, 100, 0., 0.05);
0100
0101 std::string fileName(m_imageFileName);
0102 canvas.SaveAs(fileName.c_str());
0103 }
0104 return true;
0105 }
0106 };
0107
0108 class SiStripLorentzAngleCompareByRegion : public PlotImage<SiStripLorentzAngle, MULTI_IOV, 2> {
0109 public:
0110 SiStripLorentzAngleCompareByRegion()
0111 : PlotImage<SiStripLorentzAngle, MULTI_IOV, 2>("SiStrip LorentzAngle By Partition") {}
0112
0113 bool fill() override {
0114
0115 auto theIOVs = PlotBase::getTag<0>().iovs;
0116 auto tagname1 = PlotBase::getTag<0>().name;
0117 auto tag2iovs = PlotBase::getTag<1>().iovs;
0118 auto tagname2 = PlotBase::getTag<1>().name;
0119 SiStripPI::MetaData firstiov = theIOVs.front();
0120 SiStripPI::MetaData lastiov = tag2iovs.front();
0121
0122 std::shared_ptr<SiStripLorentzAngle> last_payload = fetchPayload(std::get<1>(lastiov));
0123 std::shared_ptr<SiStripLorentzAngle> first_payload = fetchPayload(std::get<1>(firstiov));
0124
0125 SiStripLorentzAngleContainer *l_objContainer = new SiStripLorentzAngleContainer(last_payload, lastiov, tagname1);
0126 SiStripLorentzAngleContainer *f_objContainer =
0127 new SiStripLorentzAngleContainer(first_payload, firstiov, tagname2);
0128
0129 l_objContainer->compare(f_objContainer);
0130
0131
0132
0133 TCanvas canvas("Partition summary", "partition summary", 1400, 1000);
0134 l_objContainer->fillSummary(canvas);
0135
0136 std::string fileName(m_imageFileName);
0137 canvas.SaveAs(fileName.c_str());
0138
0139 return true;
0140 }
0141 };
0142
0143
0144
0145
0146
0147
0148 class SiStripLorentzAngleValue : public Histogram1D<SiStripLorentzAngle, SINGLE_IOV> {
0149 public:
0150 SiStripLorentzAngleValue()
0151 : Histogram1D<SiStripLorentzAngle, SINGLE_IOV>(
0152 "SiStrip LorentzAngle values", "SiStrip LorentzAngle values", 100, 0.0, 0.05) {}
0153
0154 bool fill() override {
0155 auto tag = PlotBase::getTag<0>();
0156 for (auto const &iov : tag.iovs) {
0157 std::shared_ptr<SiStripLorentzAngle> payload = Base::fetchPayload(std::get<1>(iov));
0158 if (payload.get()) {
0159 std::map<uint32_t, float> LAMap_ = payload->getLorentzAngles();
0160
0161 for (const auto &element : LAMap_) {
0162 fillWithValue(element.second);
0163 }
0164 }
0165 }
0166 return true;
0167 }
0168 };
0169
0170
0171
0172
0173 class SiStripLorentzAngle_TrackerMap : public PlotImage<SiStripLorentzAngle, SINGLE_IOV> {
0174 public:
0175 SiStripLorentzAngle_TrackerMap()
0176 : PlotImage<SiStripLorentzAngle, SINGLE_IOV>("Tracker Map SiStrip Lorentz Angle") {}
0177
0178 bool fill() override {
0179 auto tag = PlotBase::getTag<0>();
0180 auto iov = tag.iovs.front();
0181 std::shared_ptr<SiStripLorentzAngle> payload = fetchPayload(std::get<1>(iov));
0182
0183 std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("SiStripLorentzAngle");
0184 tmap->setPalette(1);
0185 std::string titleMap = "TrackerMap of SiStrip Lorentz Angle per module, payload : " + std::get<1>(iov);
0186 tmap->setTitle(titleMap);
0187
0188 std::map<uint32_t, float> LAMap_ = payload->getLorentzAngles();
0189
0190 for (const auto &element : LAMap_) {
0191 tmap->fill(element.first, element.second);
0192 }
0193
0194 std::pair<float, float> extrema = tmap->getAutomaticRange();
0195
0196 std::string fileName(m_imageFileName);
0197
0198
0199 if (extrema.first != extrema.second) {
0200 tmap->save(true, 0, 0, fileName);
0201 } else {
0202 tmap->save(true, extrema.first * 0.95, extrema.first * 1.05, fileName);
0203 }
0204
0205 return true;
0206 }
0207 };
0208
0209
0210
0211
0212 class SiStripLorentzAngleTkMap : public PlotImage<SiStripLorentzAngle, SINGLE_IOV> {
0213 public:
0214 SiStripLorentzAngleTkMap() : PlotImage<SiStripLorentzAngle, SINGLE_IOV>("Tracker Map SiStrip Lorentz Angle") {}
0215
0216 bool fill() override {
0217
0218 gStyle->SetPalette(1);
0219
0220 auto tag = PlotBase::getTag<0>();
0221 auto iov = tag.iovs.front();
0222 auto tagname = PlotBase::getTag<0>().name;
0223
0224 std::shared_ptr<SiStripLorentzAngle> payload = fetchPayload(std::get<1>(iov));
0225
0226 auto theIOVsince = std::to_string(std::get<0>(iov));
0227 std::string titleMap = "SiStrip Lorentz Angle Map, Run: " + theIOVsince + " (tag:#color[2]{" + tagname + "})";
0228
0229 SiStripTkMaps myMap("COLZA L");
0230 myMap.bookMap(titleMap, "SiStrip #mu_{H}=(tan#theta_{L}/B) [1/T]");
0231
0232 std::map<uint32_t, float> LAMap_ = payload->getLorentzAngles();
0233
0234 for (const auto &element : LAMap_) {
0235 myMap.fill(element.first, element.second);
0236 }
0237
0238 std::string fileName(m_imageFileName);
0239 TCanvas canvas("LA map", "LA map");
0240 myMap.drawMap(canvas, "");
0241 canvas.SaveAs(fileName.c_str());
0242
0243 #ifdef MMDEBUG
0244 canvas.SaveAs("test.root");
0245 #endif
0246 return true;
0247 }
0248 };
0249
0250
0251
0252
0253
0254 class SiStripLorentzAngleByRegion : public PlotImage<SiStripLorentzAngle, SINGLE_IOV> {
0255 public:
0256 SiStripLorentzAngleByRegion()
0257 : PlotImage<SiStripLorentzAngle, SINGLE_IOV>("SiStripLorentzAngle By Region"),
0258 m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0259 edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
0260
0261 bool fill() override {
0262 auto tag = PlotBase::getTag<0>();
0263 auto iov = tag.iovs.front();
0264 std::shared_ptr<SiStripLorentzAngle> payload = fetchPayload(std::get<1>(iov));
0265
0266 SiStripDetSummary summaryLA{&m_trackerTopo};
0267
0268 std::map<uint32_t, float> LAMap_ = payload->getLorentzAngles();
0269
0270 for (const auto &element : LAMap_) {
0271 summaryLA.add(element.first, element.second);
0272 }
0273
0274 std::map<unsigned int, SiStripDetSummary::Values> map = summaryLA.getCounts();
0275
0276
0277 TCanvas canvas("Partion summary", "partition summary", 1200, 1000);
0278 canvas.cd();
0279 auto h1 = std::make_unique<TH1F>("byRegion",
0280 "SiStrip LA average by partition;; average SiStrip Lorentz Angle [rad]",
0281 map.size(),
0282 0.,
0283 map.size());
0284 h1->SetStats(false);
0285 canvas.SetBottomMargin(0.18);
0286 canvas.SetLeftMargin(0.17);
0287 canvas.SetRightMargin(0.05);
0288 canvas.Modified();
0289
0290 std::vector<int> boundaries;
0291 unsigned int iBin = 0;
0292
0293 std::string detector;
0294 std::string currentDetector;
0295
0296 for (const auto &element : map) {
0297 iBin++;
0298 int count = element.second.count;
0299 double mean = (element.second.mean) / count;
0300
0301 if (currentDetector.empty())
0302 currentDetector = "TIB";
0303
0304 switch ((element.first) / 1000) {
0305 case 1:
0306 detector = "TIB";
0307 break;
0308 case 2:
0309 detector = "TOB";
0310 break;
0311 case 3:
0312 detector = "TEC";
0313 break;
0314 case 4:
0315 detector = "TID";
0316 break;
0317 }
0318
0319 h1->SetBinContent(iBin, mean);
0320 h1->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
0321 h1->GetXaxis()->LabelsOption("v");
0322
0323 if (detector != currentDetector) {
0324 boundaries.push_back(iBin);
0325 currentDetector = detector;
0326 }
0327 }
0328
0329 h1->GetYaxis()->SetRangeUser(0., h1->GetMaximum() * 1.30);
0330 h1->SetMarkerStyle(20);
0331 h1->SetMarkerSize(1);
0332 h1->Draw("HIST");
0333 h1->Draw("Psame");
0334
0335 canvas.Update();
0336
0337 TLine l[boundaries.size()];
0338 unsigned int i = 0;
0339 for (const auto &line : boundaries) {
0340 l[i] = TLine(h1->GetBinLowEdge(line), canvas.GetUymin(), h1->GetBinLowEdge(line), canvas.GetUymax());
0341 l[i].SetLineWidth(1);
0342 l[i].SetLineStyle(9);
0343 l[i].SetLineColor(2);
0344 l[i].Draw("same");
0345 i++;
0346 }
0347
0348 TLegend legend = TLegend(0.52, 0.82, 0.95, 0.9);
0349 legend.SetHeader((std::get<1>(iov)).c_str(), "C");
0350 legend.AddEntry(h1.get(), ("IOV: " + std::to_string(std::get<0>(iov))).c_str(), "PL");
0351 legend.SetTextSize(0.025);
0352 legend.Draw("same");
0353
0354 std::string fileName(m_imageFileName);
0355 canvas.SaveAs(fileName.c_str());
0356
0357 return true;
0358 }
0359
0360 private:
0361 TrackerTopology m_trackerTopo;
0362 };
0363
0364
0365
0366
0367
0368 template <int ntags, IOVMultiplicity nIOVs>
0369 class SiStripLorentzAngleComparatorByRegionBase : public PlotImage<SiStripLorentzAngle, nIOVs, ntags> {
0370 public:
0371 SiStripLorentzAngleComparatorByRegionBase()
0372 : PlotImage<SiStripLorentzAngle, nIOVs, ntags>("SiStripLorentzAngle By Region Comparison"),
0373 m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0374 edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
0375
0376 bool fill() override {
0377
0378 auto theIOVs = PlotBase::getTag<0>().iovs;
0379 auto tagname1 = PlotBase::getTag<0>().name;
0380 std::string tagname2 = "";
0381 auto firstiov = theIOVs.front();
0382 SiStripPI::MetaData lastiov;
0383
0384
0385 assert(this->m_plotAnnotations.ntags < 3);
0386
0387 if (this->m_plotAnnotations.ntags == 2) {
0388 auto tag2iovs = PlotBase::getTag<1>().iovs;
0389 tagname2 = PlotBase::getTag<1>().name;
0390 lastiov = tag2iovs.front();
0391 } else {
0392 lastiov = theIOVs.back();
0393 }
0394
0395 std::shared_ptr<SiStripLorentzAngle> f_payload = this->fetchPayload(std::get<1>(firstiov));
0396 std::shared_ptr<SiStripLorentzAngle> l_payload = this->fetchPayload(std::get<1>(lastiov));
0397
0398 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0399 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0400
0401
0402 TCanvas canvas("Partion summary", "partition summary", 1200, 1000);
0403 canvas.cd();
0404 canvas.SetBottomMargin(0.18);
0405 canvas.SetLeftMargin(0.13);
0406 canvas.SetRightMargin(0.03);
0407 canvas.SetTopMargin(0.05);
0408 canvas.Modified();
0409
0410 std::vector<int> boundaries;
0411 std::shared_ptr<TH1F> h_first;
0412 std::shared_ptr<TH1F> h_last;
0413
0414 fillTheHistogram(f_payload, h_first, boundaries, 0);
0415 fillTheHistogram(l_payload, h_last, boundaries, 1);
0416
0417 canvas.cd();
0418 h_first->Draw("HIST");
0419 h_last->Draw("Psame");
0420
0421 canvas.Update();
0422
0423 TLine l[boundaries.size()];
0424 unsigned int i = 0;
0425 for (const auto &line : boundaries) {
0426 l[i] = TLine(h_first->GetBinLowEdge(line), canvas.GetUymin(), h_first->GetBinLowEdge(line), canvas.GetUymax());
0427 l[i].SetLineWidth(1);
0428 l[i].SetLineStyle(9);
0429 l[i].SetLineColor(2);
0430 l[i].Draw("same");
0431 i++;
0432 }
0433
0434 auto ltx = TLatex();
0435 ltx.SetTextFont(62);
0436 ltx.SetTextSize(0.045);
0437 ltx.SetTextAlign(11);
0438
0439 std::unique_ptr<TLegend> legend = std::make_unique<TLegend>(0.50, 0.25, 0.80, 0.35);
0440 if (this->m_plotAnnotations.ntags == 2) {
0441 legend->AddEntry(h_last.get(), ("#color[2]{" + tagname2 + "}").c_str(), "P");
0442 legend->AddEntry(h_first.get(), ("#color[4]{" + tagname1 + "}").c_str(), "L");
0443 legend->SetTextSize(0.024);
0444 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
0445 1 - gPad->GetTopMargin() + 0.01,
0446 ("IOV : #color[4]{" + std::to_string(std::get<0>(firstiov)) + "} vs #color[2]{" +
0447 std::to_string(std::get<0>(lastiov)) + "}")
0448 .c_str());
0449 } else {
0450 legend->AddEntry(h_last.get(), ("IOV: #color[2]{" + lastIOVsince + "}").c_str(), "P");
0451 legend->AddEntry(h_first.get(), ("IOV: #color[4]{" + firstIOVsince + "}").c_str(), "L");
0452 legend->SetTextSize(0.040);
0453 ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, ("Tag: " + tagname1).c_str());
0454
0455 legend->SetLineColor(kBlack);
0456 }
0457 legend->Draw("same");
0458
0459 std::string fileName(this->m_imageFileName);
0460 canvas.SaveAs(fileName.c_str());
0461
0462 return true;
0463 }
0464
0465 private:
0466 TrackerTopology m_trackerTopo;
0467
0468 void fillTheHistogram(const std::shared_ptr<SiStripLorentzAngle> &payload,
0469 std::shared_ptr<TH1F> &hist,
0470 std::vector<int> &boundaries,
0471 unsigned int index = 0) {
0472 SiStripDetSummary summaryLA{&m_trackerTopo};
0473 auto LAMap_ = payload->getLorentzAngles();
0474 for (const auto &element : LAMap_) {
0475 summaryLA.add(element.first, element.second);
0476 }
0477
0478 auto map = summaryLA.getCounts();
0479 hist = std::make_shared<TH1F>(
0480 (Form("byRegion_%i", index)), ";; average SiStrip Lorentz Angle #mu_{H} [1/T]", map.size(), 0., map.size());
0481
0482 hist->SetStats(false);
0483 if (index == 0) {
0484 hist->SetLineColor(kBlue);
0485 hist->SetMarkerColor(kBlue);
0486 hist->SetLineWidth(2);
0487 hist->SetMarkerStyle(kFourSquaresX);
0488 } else {
0489 hist->SetMarkerStyle(kFourSquaresX);
0490 hist->SetLineColor(kRed);
0491 hist->SetMarkerColor(kRed);
0492 }
0493 unsigned int iBin = 0;
0494
0495 std::string detector;
0496 std::string currentDetector;
0497
0498 for (const auto &element : map) {
0499 iBin++;
0500 int count = element.second.count;
0501 double mean = (element.second.mean) / count;
0502
0503 if (currentDetector.empty())
0504 currentDetector = "TIB";
0505
0506 switch ((element.first) / 1000) {
0507 case 1:
0508 detector = "TIB";
0509 break;
0510 case 2:
0511 detector = "TOB";
0512 break;
0513 case 3:
0514 detector = "TEC";
0515 break;
0516 case 4:
0517 detector = "TID";
0518 break;
0519 }
0520
0521 hist->SetBinContent(iBin, mean);
0522 hist->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
0523 hist->GetXaxis()->LabelsOption("v");
0524
0525 if (detector != currentDetector) {
0526 if (index == 0) {
0527 boundaries.push_back(iBin);
0528 }
0529 currentDetector = detector;
0530 }
0531 }
0532
0533 hist->GetYaxis()->SetTitleSize(0.04);
0534 hist->GetYaxis()->SetTitleOffset(1.55);
0535 hist->GetYaxis()->CenterTitle(true);
0536 hist->GetYaxis()->SetRangeUser(0., hist->GetMaximum() * 1.30);
0537 hist->SetMarkerSize(2);
0538 }
0539 };
0540
0541 using SiStripLorentzAngleByRegionCompareSingleTag = SiStripLorentzAngleComparatorByRegionBase<1, MULTI_IOV>;
0542 using SiStripLorentzAngleByRegionCompareTwoTags = SiStripLorentzAngleComparatorByRegionBase<2, SINGLE_IOV>;
0543
0544 }
0545
0546 PAYLOAD_INSPECTOR_MODULE(SiStripLorentzAngle) {
0547 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleTest);
0548 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleByPartition);
0549 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleValue);
0550 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleTkMap);
0551 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngle_TrackerMap);
0552 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleByRegion);
0553 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleCompareByRegion);
0554 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleByRegionCompareSingleTag);
0555 PAYLOAD_INSPECTOR_CLASS(SiStripLorentzAngleByRegionCompareTwoTags);
0556 }