CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
DD4hep_MaterialAccountingGroup Class Reference

#include <DD4hep_MaterialAccountingGroup.h>

Public Member Functions

bool addDetector (const MaterialAccountingDetector &detector)
 
MaterialAccountingStep average (void) const
 
double averageEnergyLoss (void) const
 
double averageLength (void) const
 
double averageRadiationLengths (void) const
 
 DD4hep_MaterialAccountingGroup (const DD4hep_MaterialAccountingGroup &layer)=delete
 
 DD4hep_MaterialAccountingGroup (const std::string &name, const cms::DDCompactView &geometry)
 
const std::vector< GlobalPoint > & elements (void) const
 
void endOfTrack (void)
 
std::pair< double, double > getBoundingR () const
 
std::pair< double, double > getBoundingZ () const
 
std::string info (void) const
 
bool isInside (const MaterialAccountingDetector &detector) const
 
const std::string & name (void) const
 
DD4hep_MaterialAccountingGroupoperator= (const DD4hep_MaterialAccountingGroup &layer)=delete
 
void savePlots (void)
 
double sigmaEnergyLoss (void) const
 
double sigmaLength (void) const
 
double sigmaRadiationLengths (void) const
 
unsigned int tracks (void) const
 
 ~DD4hep_MaterialAccountingGroup (void)
 

Private Member Functions

void savePlot (std::shared_ptr< TH1F > &plot, const std::string &name)
 
void savePlot (std::shared_ptr< TProfile > &plot, float average, const std::string &name)
 

Private Attributes

MaterialAccountingStep m_accounting
 
BoundingBox m_boundingbox
 
MaterialAccountingStep m_buffer
 
bool m_counted
 
std::shared_ptr< TH1F > m_dedx_spectrum
 
std::shared_ptr< TProfile > m_dedx_vs_eta
 
std::shared_ptr< TProfile > m_dedx_vs_r
 
std::shared_ptr< TProfile > m_dedx_vs_z
 
std::vector< GlobalPointm_elements
 
MaterialAccountingStep m_errors
 
std::unique_ptr< TFile > m_file
 
std::string m_name
 
std::shared_ptr< TH1F > m_radlen_spectrum
 
std::shared_ptr< TProfile > m_radlen_vs_eta
 
std::shared_ptr< TProfile > m_radlen_vs_r
 
std::shared_ptr< TProfile > m_radlen_vs_z
 
unsigned int m_tracks
 

Static Private Attributes

static constexpr double s_tolerance = 0.01
 

Detailed Description

Definition at line 23 of file DD4hep_MaterialAccountingGroup.h.

Constructor & Destructor Documentation

◆ DD4hep_MaterialAccountingGroup() [1/2]

DD4hep_MaterialAccountingGroup::DD4hep_MaterialAccountingGroup ( const DD4hep_MaterialAccountingGroup layer)
delete

◆ DD4hep_MaterialAccountingGroup() [2/2]

DD4hep_MaterialAccountingGroup::DD4hep_MaterialAccountingGroup ( const std::string &  name,
const cms::DDCompactView geometry 
)

Definition at line 23 of file DD4hep_MaterialAccountingGroup.cc.

References class-composition::children, ALCARECOTkAlBeamHalo_cff::filter, runTauDisplay::gp, BoundingBox::grow(), mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, m_boundingbox, m_dedx_spectrum, m_dedx_vs_eta, m_dedx_vs_r, m_dedx_vs_z, m_elements, m_name, m_radlen_spectrum, m_radlen_vs_eta, m_radlen_vs_r, m_radlen_vs_z, name(), castor_dqm_sourceclient_file_cfg::path, perp(), BoundingBox::range_r(), BoundingBox::range_z(), s_tolerance, and z.

25  : m_name(name),
26  m_elements(),
27  m_boundingbox(),
28  m_accounting(),
29  m_errors(),
30  m_tracks(0),
31  m_counted(false),
32  m_file(nullptr) {
33  cms::DDFilter filter("TrackingMaterialGroup", {name.data(), name.size()});
35  bool firstChild = fv.firstChild();
36 
37  edm::LogVerbatim("TrackingMaterialAnalysis") << "Elements within: " << name;
38 
39  for (const auto& j : fv.specpars()) {
40  for (const auto& k : j.second->paths) {
41  if (firstChild) {
42  std::vector<std::vector<cms::Node*>> children = fv.children(k);
43  for (auto const& path : children) {
44  cms::Translation trans = fv.translation(path) / dd4hep::cm;
45  GlobalPoint gp = GlobalPoint(trans.x(), trans.y(), trans.z());
46  m_elements.emplace_back(gp);
47  edm::LogVerbatim("TrackerMaterialAnalysis")
48  << "MaterialAccountingGroup:\t"
49  << "Adding element at (r,z) " << gp.perp() << "," << gp.z() << std::endl;
50  }
51  }
52  }
53  }
54 
55  for (unsigned int i = 0; i < m_elements.size(); ++i) {
57  }
58 
60 
61  edm::LogVerbatim("TrackerMaterialAnalysis")
62  << "MaterialAccountingGroup:\t"
63  << "Final BBox r_range: " << m_boundingbox.range_r().first << ", " << m_boundingbox.range_r().second << std::endl
64  << "Final BBox z_range: " << m_boundingbox.range_z().first << ", " << m_boundingbox.range_z().second << std::endl;
65 
66  m_dedx_spectrum = std::make_shared<TH1F>((m_name + "_dedx_spectrum").c_str(), "Energy loss spectrum", 1000, 0., 1.);
68  std::make_shared<TH1F>((m_name + "_radlen_spectrum").c_str(), "Radiation lengths spectrum", 1000, 0., 1.);
69  m_dedx_vs_eta = std::make_shared<TProfile>((m_name + "_dedx_vs_eta").c_str(), "Energy loss vs. eta", 600, -3., 3.);
70  m_dedx_vs_z = std::make_shared<TProfile>((m_name + "_dedx_vs_z").c_str(), "Energy loss vs. Z", 6000, -300., 300.);
71  m_dedx_vs_r = std::make_shared<TProfile>((m_name + "_dedx_vs_r").c_str(), "Energy loss vs. R", 1200, 0., 120.);
73  std::make_shared<TProfile>((m_name + "_radlen_vs_eta").c_str(), "Radiation lengths vs. eta", 600, -3., 3.);
75  std::make_shared<TProfile>((m_name + "_radlen_vs_z").c_str(), "Radiation lengths vs. Z", 6000, -300., 300.);
77  std::make_shared<TProfile>((m_name + "_radlen_vs_r").c_str(), "Radiation lengths vs. R", 1200, 0., 120.);
78 
79  m_dedx_spectrum->SetDirectory(nullptr);
80  m_radlen_spectrum->SetDirectory(nullptr);
81  m_dedx_vs_eta->SetDirectory(nullptr);
82  m_dedx_vs_z->SetDirectory(nullptr);
83  m_dedx_vs_r->SetDirectory(nullptr);
84  m_radlen_vs_eta->SetDirectory(nullptr);
85  m_radlen_vs_z->SetDirectory(nullptr);
86  m_radlen_vs_r->SetDirectory(nullptr);
87 }
Log< level::Info, true > LogVerbatim
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
const std::string & name(void) const
std::pair< double, double > range_z() const
Definition: BoundingBox.h:29
T perp() const
Magnitude of transverse component.
void grow(const double &r, const double &z)
Definition: BoundingBox.cc:3
std::pair< double, double > range_r() const
Definition: BoundingBox.h:27
std::shared_ptr< TProfile > m_radlen_vs_eta
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation

◆ ~DD4hep_MaterialAccountingGroup()

DD4hep_MaterialAccountingGroup::~DD4hep_MaterialAccountingGroup ( void  )

Member Function Documentation

◆ addDetector()

bool DD4hep_MaterialAccountingGroup::addDetector ( const MaterialAccountingDetector detector)

Definition at line 119 of file DD4hep_MaterialAccountingGroup.cc.

References hgcalTestNeighbor_cfi::detector, isInside(), m_buffer, and m_counted.

119  {
120  if (!isInside(detector))
121  return false;
122 
123  m_buffer += detector.material();
124  m_counted = true;
125 
126  return true;
127 }
bool isInside(const MaterialAccountingDetector &detector) const

◆ average()

MaterialAccountingStep DD4hep_MaterialAccountingGroup::average ( void  ) const

◆ averageEnergyLoss()

double DD4hep_MaterialAccountingGroup::averageEnergyLoss ( void  ) const

◆ averageLength()

double DD4hep_MaterialAccountingGroup::averageLength ( void  ) const

Definition at line 214 of file DD4hep_MaterialAccountingGroup.cc.

References MaterialAccountingStep::length(), m_accounting, and m_tracks.

Referenced by sigmaLength().

214  {
215  return m_tracks ? m_accounting.length() / m_tracks : 0.;
216 }

◆ averageRadiationLengths()

double DD4hep_MaterialAccountingGroup::averageRadiationLengths ( void  ) const

◆ elements()

const std::vector<GlobalPoint>& DD4hep_MaterialAccountingGroup::elements ( void  ) const
inline

Definition at line 75 of file DD4hep_MaterialAccountingGroup.h.

References m_elements.

75 { return m_elements; }

◆ endOfTrack()

void DD4hep_MaterialAccountingGroup::endOfTrack ( void  )

Definition at line 129 of file DD4hep_MaterialAccountingGroup.cc.

References average(), MaterialAccountingStep::energyLoss(), MaterialAccountingStep::in(), m_accounting, m_buffer, m_counted, m_dedx_spectrum, m_dedx_vs_eta, m_dedx_vs_r, m_dedx_vs_z, m_errors, m_radlen_spectrum, m_radlen_vs_eta, m_radlen_vs_r, m_radlen_vs_z, m_tracks, MaterialAccountingStep::out(), MaterialAccountingStep::radiationLengths(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

129  {
130  if (m_counted) {
133  ++m_tracks;
134 
135  GlobalPoint average((m_buffer.in().x() + m_buffer.out().x()) / 2.,
136  (m_buffer.in().y() + m_buffer.out().y()) / 2.,
137  (m_buffer.in().z() + m_buffer.out().z()) / 2.);
140  m_dedx_vs_eta->Fill(average.eta(), m_buffer.energyLoss(), 1.);
141  m_dedx_vs_z->Fill(average.z(), m_buffer.energyLoss(), 1.);
142  m_dedx_vs_r->Fill(average.perp(), m_buffer.energyLoss(), 1.);
143  m_radlen_vs_eta->Fill(average.eta(), m_buffer.radiationLengths(), 1.);
145  m_radlen_vs_r->Fill(average.perp(), m_buffer.radiationLengths(), 1.);
146  }
147  m_counted = false;
149 }
T z() const
Definition: PV3DBase.h:61
const GlobalPoint & in(void) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
MaterialAccountingStep average(void) const
std::shared_ptr< TProfile > m_radlen_vs_eta
const GlobalPoint & out(void) const
double radiationLengths(void) const
double energyLoss(void) const

◆ getBoundingR()

std::pair<double, double> DD4hep_MaterialAccountingGroup::getBoundingR ( ) const
inline

Definition at line 61 of file DD4hep_MaterialAccountingGroup.h.

References m_boundingbox, and BoundingBox::range_r().

61 { return m_boundingbox.range_r(); };
std::pair< double, double > range_r() const
Definition: BoundingBox.h:27

◆ getBoundingZ()

std::pair<double, double> DD4hep_MaterialAccountingGroup::getBoundingZ ( ) const
inline

Definition at line 62 of file DD4hep_MaterialAccountingGroup.h.

References m_boundingbox, and BoundingBox::range_z().

62 { return m_boundingbox.range_z(); };
std::pair< double, double > range_z() const
Definition: BoundingBox.h:29

◆ info()

std::string DD4hep_MaterialAccountingGroup::info ( void  ) const

Definition at line 198 of file DD4hep_MaterialAccountingGroup.cc.

References alignBH_cfg::fixed, m_boundingbox, m_elements, m_name, MillePedeFileConverter_cfg::out, BoundingBox::range_r(), and BoundingBox::range_z().

198  {
199  std::stringstream out;
200  out << std::setw(48) << std::left << m_name << std::right << std::fixed;
201 
202  out << "BBox: " << std::setprecision(1) << std::setw(6) << m_boundingbox.range_z().first << " < Z < "
203  << std::setprecision(1) << std::setw(6) << m_boundingbox.range_z().second;
204  out << ", " << std::setprecision(1) << std::setw(5) << m_boundingbox.range_r().first << " < R < "
205  << std::setprecision(1) << std::setw(5) << m_boundingbox.range_r().second;
206  out << " Elements: " << std::setw(6) << m_elements.size();
207  return out.str();
208 }
std::pair< double, double > range_z() const
Definition: BoundingBox.h:29
std::pair< double, double > range_r() const
Definition: BoundingBox.h:27

◆ isInside()

bool DD4hep_MaterialAccountingGroup::isInside ( const MaterialAccountingDetector detector) const

Definition at line 89 of file DD4hep_MaterialAccountingGroup.cc.

References hgcalTestNeighbor_cfi::detector, mps_fire::i, BoundingBox::inside(), m_boundingbox, m_elements, mag(), position, BoundingBox::range_r(), BoundingBox::range_z(), and s_tolerance.

Referenced by addDetector().

89  {
90  const GlobalPoint& position = detector.position();
91 
92  edm::LogVerbatim("MaterialAccountingGroup")
93  << "Testing position: (x, y, z, r) = " << position.x() << ", " << position.y() << ", " << position.z() << ", "
94  << position.perp() << std::endl;
95 
96  if (not m_boundingbox.inside(position.perp(), position.z())) {
97  edm::LogVerbatim("MaterialAccountingGroup")
98  << "r outside of: (" << m_boundingbox.range_r().first << ", " << m_boundingbox.range_r().second
99  << "), Z ouside of: (" << m_boundingbox.range_z().first << ", " << m_boundingbox.range_z().second << ")"
100  << std::endl;
101  return false;
102  } else {
103  edm::LogVerbatim("MaterialAccountingGroup")
104  << "r within: (" << m_boundingbox.range_r().first << ", " << m_boundingbox.range_r().second << "), Z within: ("
105  << m_boundingbox.range_z().first << ", " << m_boundingbox.range_z().second << ")" << std::endl;
106 
107  for (unsigned int i = 0; i < m_elements.size(); ++i) {
108  edm::LogVerbatim("MaterialAccountingGroup")
109  << "Closest testing agains(x, y, z, r): (" << m_elements[i].x() << ", " << m_elements[i].y() << ", "
110  << m_elements[i].z() << ", " << m_elements[i].perp() << ") --> " << (position - m_elements[i]).mag()
111  << " vs tolerance: " << s_tolerance << std::endl;
112  if ((position - m_elements[i]).mag2() < (s_tolerance * s_tolerance))
113  return true;
114  }
115  return false;
116  }
117 }
Log< level::Info, true > LogVerbatim
std::pair< double, double > range_z() const
Definition: BoundingBox.h:29
bool inside(const double &r, const double &z) const
Definition: BoundingBox.h:23
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::pair< double, double > range_r() const
Definition: BoundingBox.h:27
static int position[264][3]
Definition: ReadPGInfo.cc:289

◆ name()

const std::string& DD4hep_MaterialAccountingGroup::name ( void  ) const
inline

◆ operator=()

DD4hep_MaterialAccountingGroup& DD4hep_MaterialAccountingGroup::operator= ( const DD4hep_MaterialAccountingGroup layer)
delete

◆ savePlot() [1/2]

void DD4hep_MaterialAccountingGroup::savePlot ( std::shared_ptr< TH1F > &  plot,
const std::string &  name 
)
private

Definition at line 165 of file DD4hep_MaterialAccountingGroup.cc.

References svgfig::canvas(), m_file, name(), and plotFactory::plot.

Referenced by savePlots().

165  {
166  TCanvas canvas(name.c_str(), plot->GetTitle(), 1280, 1024);
167  plot->SetFillColor(15); // grey
168  plot->SetLineColor(1); // black
169  plot->Draw("c e");
170  canvas.GetFrame()->SetFillColor(kWhite);
171  canvas.Draw();
172  canvas.SaveAs((name + ".png").c_str(), "");
173  plot->SetDirectory(m_file.get());
174 }
const std::string & name(void) const
def canvas(sub, attr)
Definition: svgfig.py:482

◆ savePlot() [2/2]

void DD4hep_MaterialAccountingGroup::savePlot ( std::shared_ptr< TProfile > &  plot,
float  average,
const std::string &  name 
)
private

Definition at line 176 of file DD4hep_MaterialAccountingGroup.cc.

References svgfig::canvas(), mps_splice::line, m_file, name(), and plotFactory::plot.

176  {
177  std::unique_ptr<TH1F> line = std::make_unique<TH1F>(
178  (name + "_par").c_str(), "Parametrization", 1, plot->GetXaxis()->GetXmin(), plot->GetXaxis()->GetXmax());
179 
180  line->SetBinContent(1, average);
181 
182  TCanvas canvas(name.c_str(), plot->GetTitle(), 1280, 1024);
183  plot->SetFillColor(15); // grey
184  plot->SetLineColor(1); // black
185  plot->SetLineWidth(2);
186  plot->Draw("c e6");
187  line->SetLineColor(2); // red
188  line->SetLineWidth(2);
189  line->Draw("same");
190  canvas.GetFrame()->SetFillColor(kWhite);
191  canvas.Draw();
192  canvas.SaveAs((name + ".png").c_str(), "");
193  plot->SetDirectory(m_file.get());
194  line->SetDirectory(m_file.get());
195  line->Write();
196 }
const std::string & name(void) const
def canvas(sub, attr)
Definition: svgfig.py:482

◆ savePlots()

void DD4hep_MaterialAccountingGroup::savePlots ( void  )

Definition at line 151 of file DD4hep_MaterialAccountingGroup.cc.

References averageEnergyLoss(), averageRadiationLengths(), m_dedx_spectrum, m_dedx_vs_eta, m_dedx_vs_r, m_dedx_vs_z, m_file, m_name, m_radlen_spectrum, m_radlen_vs_eta, m_radlen_vs_r, m_radlen_vs_z, and savePlot().

151  {
152  m_file = std::make_unique<TFile>((m_name + ".root").c_str(), "RECREATE");
153  savePlot(m_dedx_spectrum, m_name + "_dedx_spectrum");
154  savePlot(m_radlen_spectrum, m_name + "_radlen_spectrum");
155  savePlot(m_dedx_vs_eta, averageEnergyLoss(), m_name + "_dedx_vs_eta");
156  savePlot(m_dedx_vs_z, averageEnergyLoss(), m_name + "_dedx_vs_z");
157  savePlot(m_dedx_vs_r, averageEnergyLoss(), m_name + "_dedx_vs_r");
158  savePlot(m_radlen_vs_eta, averageRadiationLengths(), m_name + "_radlen_vs_eta");
161  m_file->Write();
162  m_file->Close();
163 }
std::shared_ptr< TProfile > m_radlen_vs_eta
void savePlot(std::shared_ptr< TH1F > &plot, const std::string &name)

◆ sigmaEnergyLoss()

double DD4hep_MaterialAccountingGroup::sigmaEnergyLoss ( void  ) const

◆ sigmaLength()

double DD4hep_MaterialAccountingGroup::sigmaLength ( void  ) const

◆ sigmaRadiationLengths()

double DD4hep_MaterialAccountingGroup::sigmaRadiationLengths ( void  ) const

◆ tracks()

unsigned int DD4hep_MaterialAccountingGroup::tracks ( void  ) const
inline

Definition at line 70 of file DD4hep_MaterialAccountingGroup.h.

References m_tracks.

Member Data Documentation

◆ m_accounting

MaterialAccountingStep DD4hep_MaterialAccountingGroup::m_accounting
private

◆ m_boundingbox

BoundingBox DD4hep_MaterialAccountingGroup::m_boundingbox
private

◆ m_buffer

MaterialAccountingStep DD4hep_MaterialAccountingGroup::m_buffer
private

Definition at line 39 of file DD4hep_MaterialAccountingGroup.h.

Referenced by addDetector(), and endOfTrack().

◆ m_counted

bool DD4hep_MaterialAccountingGroup::m_counted
private

Definition at line 38 of file DD4hep_MaterialAccountingGroup.h.

Referenced by addDetector(), and endOfTrack().

◆ m_dedx_spectrum

std::shared_ptr<TH1F> DD4hep_MaterialAccountingGroup::m_dedx_spectrum
private

◆ m_dedx_vs_eta

std::shared_ptr<TProfile> DD4hep_MaterialAccountingGroup::m_dedx_vs_eta
private

◆ m_dedx_vs_r

std::shared_ptr<TProfile> DD4hep_MaterialAccountingGroup::m_dedx_vs_r
private

◆ m_dedx_vs_z

std::shared_ptr<TProfile> DD4hep_MaterialAccountingGroup::m_dedx_vs_z
private

◆ m_elements

std::vector<GlobalPoint> DD4hep_MaterialAccountingGroup::m_elements
private

◆ m_errors

MaterialAccountingStep DD4hep_MaterialAccountingGroup::m_errors
private

◆ m_file

std::unique_ptr<TFile> DD4hep_MaterialAccountingGroup::m_file
private

Definition at line 50 of file DD4hep_MaterialAccountingGroup.h.

Referenced by savePlot(), and savePlots().

◆ m_name

std::string DD4hep_MaterialAccountingGroup::m_name
private

◆ m_radlen_spectrum

std::shared_ptr<TH1F> DD4hep_MaterialAccountingGroup::m_radlen_spectrum
private

◆ m_radlen_vs_eta

std::shared_ptr<TProfile> DD4hep_MaterialAccountingGroup::m_radlen_vs_eta
private

◆ m_radlen_vs_r

std::shared_ptr<TProfile> DD4hep_MaterialAccountingGroup::m_radlen_vs_r
private

◆ m_radlen_vs_z

std::shared_ptr<TProfile> DD4hep_MaterialAccountingGroup::m_radlen_vs_z
private

◆ m_tracks

unsigned int DD4hep_MaterialAccountingGroup::m_tracks
private

◆ s_tolerance

constexpr double DD4hep_MaterialAccountingGroup::s_tolerance = 0.01
staticprivate

Definition at line 52 of file DD4hep_MaterialAccountingGroup.h.

Referenced by DD4hep_MaterialAccountingGroup(), and isInside().