Skip to content

Commit

Permalink
Merge pull request #29785 from vargasa/x1l
Browse files Browse the repository at this point in the history
DD4hep: Fix test on SimTracker/TrackerMaterialAnalysis
  • Loading branch information
cmsbuild committed May 9, 2020
2 parents b051dab + bb53ae4 commit d8aa8d5
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
#include <TLine.h>
#include <TText.h>
#include <TColor.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TFrame.h>
#include <TLegend.h>
#include <TLegendEntry.h>

#include "DD4hep_MaterialAccountingGroup.h"
#include "DD4hep_TrackingMaterialPlotter.h"

class DD4hep_ListGroups : public edm::one::EDAnalyzer<> {
public:
Expand All @@ -52,21 +58,143 @@ class DD4hep_ListGroups : public edm::one::EDAnalyzer<> {
std::vector<DD4hep_MaterialAccountingGroup *> m_groups;
void fillColor();
void fillGradient();
void fillMaterialDifferences();
void produceAndSaveSummaryPlot(cms::DDCompactView cpv);
std::vector<std::pair<std::shared_ptr<TLine>, std::shared_ptr<TText>>> overlayEtaReferences();
std::map<std::string, std::pair<float, float>> m_diff;
std::map<std::string, std::pair<float, float>> m_values;
};

#include "DD4hep_ListGroupsMaterialDifference.h"

DD4hep_ListGroups::DD4hep_ListGroups(const edm::ParameterSet &iConfig)
: m_tag(iConfig.getParameter<edm::ESInputTag>("DDDetector")) {
m_saveSummaryPlot = iConfig.getUntrackedParameter<bool>("SaveSummaryPlot");
m_plots.clear();
m_groups.clear();
TColor::InitializeColors();
fillColor();
fillMaterialDifferences();
fillGradient();
}

DD4hep_ListGroups::~DD4hep_ListGroups() {}

void DD4hep_ListGroups::produceAndSaveSummaryPlot(cms::DDCompactView cpv) {
const double scale = 10.;

static int markerStyles[10] = {kFullCircle,
kFullSquare,
kFullTriangleUp,
kFullTriangleDown,
kOpenCircle,
kOpenSquare,
kOpenTriangleUp,
kOpenDiamond,
kOpenCross,
kFullStar};

for (auto n : m_group_names) {
m_groups.push_back(new DD4hep_MaterialAccountingGroup(n.data(), cpv));
}

std::unique_ptr<TCanvas> canvas(
new TCanvas("Grouping_rz", "Grouping - RZ view", (int)(600 * scale * 1.25), (int)(120 * scale * 1.50)));
canvas->GetFrame()->SetFillColor(kWhite);
gStyle->SetOptStat(0);

unsigned int color_index = 1;

std::unique_ptr<TLegend> leg(new TLegend(0.1, 0.1, 0.23, 0.34));
leg->SetHeader("Tracker Material Grouping");
leg->SetTextFont(42);
leg->SetTextSize(0.008);
leg->SetNColumns(3);
std::unique_ptr<TProfile2D> radlen(
new TProfile2D("OverallRadLen", "OverallRadLen", 600., -300., 300, 120., 0., 120.));
std::unique_ptr<TProfile2D> eneloss(
new TProfile2D("OverallEnergyLoss", "OverallEnergyLoss", 600., -300., 300, 120., 0., 120.));
std::unique_ptr<TProfile2D> radlen_diff(
new TProfile2D("OverallDifferencesRadLen", "OverallDifferencesRadLen", 600., -300., 300, 120., 0., 120.));
std::unique_ptr<TProfile2D> eneloss_diff(
new TProfile2D("OverallDifferencesEnergyLoss", "OverallDifferencesEnergyLoss", 600., -300., 300, 120., 0., 120.));

for (auto g : m_groups) {
m_plots.push_back(
new TH2F(g->name().c_str(), g->name().c_str(), 6000., -300., 300, 1200., 0., 120.)); // 10x10 points per cm2
TH2F &current = *m_plots.back();
current.SetMarkerColor(m_color[color_index]);
current.SetMarkerStyle(markerStyles[color_index % 10]);
current.SetMarkerSize(0.8);
current.SetLineWidth(1);
for (auto element : g->elements()) {
current.Fill(element.z(), element.perp());
radlen->Fill(element.z(), element.perp(), m_values[g->name()].first);
eneloss->Fill(element.z(), element.perp(), m_values[g->name()].second);
radlen_diff->Fill(element.z(), element.perp(), m_diff[g->name()].first);
eneloss_diff->Fill(element.z(), element.perp(), m_diff[g->name()].second);
}

if (color_index == 1)
current.Draw();
else
current.Draw("SAME");

leg->AddEntry(&current, g->name().c_str(), "lp")->SetTextColor(m_color[color_index]);
color_index++;

color_index = color_index % m_color.size();
}
leg->Draw();
canvas->SaveAs("Grouping.png");

std::vector<std::pair<std::shared_ptr<TLine>, std::shared_ptr<TText>>> lines = overlayEtaReferences();

canvas->Clear();
radlen->SetMinimum(0);
radlen->SetMaximum(0.25);
radlen->Draw("COLZ");
for (auto line : lines) {
line.first->SetLineWidth(5);
line.first->Draw();
line.second->Draw();
}
canvas->SaveAs("RadLenValues.png");

canvas->Clear();
eneloss->SetMinimum(0.00001);
eneloss->SetMaximum(0.0005);
eneloss->Draw("COLZ");
for (auto line : lines) {
line.first->SetLineWidth(5);
line.first->Draw();
line.second->Draw();
}
canvas->SaveAs("EnergyLossValues.png");

canvas->Clear();
gStyle->SetPalette(m_gradient.size(), &m_gradient.front());
gStyle->SetNumberContours(m_gradient.size());
radlen_diff->SetMinimum(-100);
radlen_diff->SetMaximum(100);
radlen_diff->Draw("COLZ");
for (auto line : lines) {
line.first->SetLineWidth(5);
line.first->Draw();
line.second->Draw();
}
canvas->SaveAs("RadLenChanges.png");

canvas->Clear();
eneloss_diff->SetMinimum(-100);
eneloss_diff->SetMaximum(100);
eneloss_diff->Draw("COLZ");
for (auto line : lines) {
line.first->SetLineWidth(5);
line.first->Draw();
line.second->Draw();
}
canvas->SaveAs("EnergyLossChanges.png");
}

void DD4hep_ListGroups::fillColor(void) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file will be replaced with that created automatically when running
// python dumpFullXML.py -p -c
#ifndef DD4HEP_SIMTRACKER_TRACKERMATERIALANALYSIS_LISTGROUPS_MATERIALDIFFERENCE_H
#define DD4HEP_SIMTRACKER_TRACKERMATERIALANALYSIS_LISTGROUPS_MATERIALDIFFERENCE_H

void DD4hep_ListGroups::fillMaterialDifferences() {}

#endif // DD4HEP_SIMTRACKER_TRACKERMATERIALANALYSIS_LISTGROUPS_MATERIALDIFFERENCE_H
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def checkEnvironment():

def getTrackerRecoMaterialCopy(filename):
tracker_reco_material = os.path.join(os.environ['CMSSW_BASE'],
'src/Geometry/TrackerRecoData/data/PhaseI/pixfwd/trackerRecoMaterial.xml')
'src/Geometry/TrackerRecoData/data/PhaseI/trackerRecoMaterial.xml')
if not os.path.exists(tracker_reco_material):
tracker_reco_material = os.path.join(os.environ['CMSSW_RELEASE_BASE'],
'src/Geometry/TrackerRecoData/data/PhaseI/pixfwd/trackerRecoMaterial.xml')
'src/Geometry/TrackerRecoData/data/PhaseI/trackerRecoMaterial.xml')
if not os.path.exists(tracker_reco_material):
print('Something is wrong with the CMSSW installation. The file %s is missing. Quitting.\n' % tracker_reco_material)
sys.exit(TRACKER_MATERIAL_FILE_MISSING)
Expand Down

0 comments on commit d8aa8d5

Please sign in to comment.