9 #include <fmt/printf.h>
32 if (strcasecmp(splitmode.c_str(),
"NearestLayer") == 0) {
34 }
else if (strcasecmp(splitmode.c_str(),
"InnerLayer") == 0) {
36 }
else if (strcasecmp(splitmode.c_str(),
"OuterLayer") == 0) {
41 <<
"Invalid SplitMode \"" << splitmode
42 <<
"\". Acceptable values are \"NearestLayer\", \"InnerLayer\", \"OuterLayer\".";
53 if (m_saveSummaryPlot) {
55 m_plotter = std::make_unique<DD4hep_TrackingMaterialPlotter>(550., 300., 10);
56 }
else if (m_isHFNose) {
57 m_plotter = std::make_unique<DD4hep_TrackingMaterialPlotter>(1200., 350., 10);
59 m_plotter = std::make_unique<DD4hep_TrackingMaterialPlotter>(300., 120., 10);
72 edm::LogVerbatim(
"TrackerMaterialAnalysis") <<
"TrackingMaterialAnalyser" << std::endl;
73 for (
unsigned int i = 0;
i <
m_groups.size(); ++
i) {
75 edm::LogVerbatim(
"TrackerMaterialAnalysis") <<
"TrackingMaterialAnalyser" << layer.
name() << std::endl;
77 <<
"TrackingMaterialAnalyser" << fmt::sprintf(
"\tnumber of hits: %9d", layer.
tracks())
80 <<
"TrackingMaterialAnalyser"
84 << fmt::sprintf(
"\tnormalized radiation lengths: %9.3f ± %9.3f",
89 <<
"TrackingMaterialAnalyser"
90 << fmt::sprintf(
"\tnormalized energy loss: %6.5fe-03 ± %6.5fe-03 GeV",
94 parameters << fmt::sprintf(
"%-20s\t%7d\t%5.1f ± %5.1f cm\t%6.4f ± %6.4f \t%6.4fe-03 ± %6.4fe-03 GeV",
105 edm::LogVerbatim(
"TrackerMaterialAnalysis") <<
"TrackingMaterialAnalyser" << std::endl;
112 std::ofstream xml(name);
113 xml <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl;
114 xml <<
"<Groups>" << std::endl;
115 for (
unsigned int i = 0;
i <
m_groups.size(); ++
i) {
117 xml <<
" <Group name=\"" << layer.
name() <<
"\">\n"
119 <<
" <Parameter name=\"TrackerXi\" value=\"" << layer.
averageEnergyLoss() <<
"\"/>\n"
123 xml <<
"</Groups>" << std::endl;
128 for (
unsigned int i = 0;
i <
m_groups.size(); ++
i) {
146 m_plotter->normalize();
167 <<
"TrackingMaterialAnalyser: List of the tracker groups: " << std::endl;
168 for (
unsigned int i = 0; i <
m_groups.size(); ++
i)
170 << i <<
" TrackingMaterialAnalyser:\t" <<
m_groups[
i]->info() << std::endl;
175 for (std::vector<MaterialAccountingTrack>::const_iterator
t = h_tracks->begin(),
end = h_tracks->end();
t !=
end;
195 for (
unsigned int i = 0;
i < track.
detectors().size(); ++
i)
198 for (
unsigned int i = 0;
i <
group.size(); ++
i)
200 edm::LogVerbatim(
"TrackerMaterialAnalysis") <<
"TrackingMaterialAnalyser:\n"
201 <<
"For detector i: " <<
i <<
" index: " <<
group[
i]
205 <<
", " <<
m_groups[
group[
i] - 1]->getBoundingZ().second << std::endl;
212 for (
unsigned int i = 1;
i < track.
steps().size(); ++
i)
215 const double TOLERANCE = 0.0001;
220 limits[0] = track.
detectors()[0].m_curvilinearIn - TOLERANCE;
222 limits[0] = -TOLERANCE;
243 limits[
i] = track.
detectors()[
i].m_curvilinearIn - TOLERANCE;
250 limits[
i] = track.
detectors()[
i - 1].m_curvilinearOut + TOLERANCE;
266 while (end < limits[0]) {
268 end = begin + step.
length();
277 unsigned int index = 0;
278 while (i < track.
steps().size()) {
281 end = begin + step.
length();
295 if (begin < limits[index]
or end > limits[index + 2]) {
298 <<
"TrackingMaterialAnalyser::split(): ERROR: internal logic error, expected " << limits[
index] <<
" < "
299 << begin <<
" < " << limits[index + 1] << std::endl;
303 if (limits[index] <= begin and end <= limits[index + 1]) {
310 double fraction = (limits[index + 1] -
begin) / (end - begin);
312 std::pair<MaterialAccountingStep, MaterialAccountingStep>
parts = step.
split(fraction);
319 m_plotter->plotSegmentUnassigned(parts.first);
321 if (index + 1 < detectors)
325 m_plotter->plotSegmentUnassigned(parts.second);
328 track.
detectors()[
index].account(parts.first, begin, limits[index + 1]);
330 if (index < detectors)
331 track.
detectors()[
index].account(parts.second, limits[index + 1], end);
338 for (
unsigned int i = 0;
i < track.
detectors().size(); ++
i)
362 <<
"TrackingMaterialAnalyser::findLayer(...): ERROR: detector does not belong to any DetLayer" << std::endl;
364 <<
"TrackingMaterialAnalyser::findLayer(...): detector position: " << std::fixed
365 <<
" (r: " << std::setprecision(1) << std::setw(5) << detector.
position().
perp()
366 <<
", z: " << std::setprecision(1) << std::setw(6) << detector.
position().
z()
367 <<
", phi: " << std::setprecision(3) << std::setw(6) << detector.
position().
phi() <<
")" << std::endl;
371 edm::LogError(
"TrackerMaterialAnalysis") <<
"TrackingMaterialAnalyser::findLayer(...): ERROR: detector belongs to "
372 << inside <<
" DetLayers" << std::endl;
374 <<
"TrackingMaterialAnalyser::findLayer(...): detector position: " << std::fixed
375 <<
" (r: " << std::setprecision(1) << std::setw(5) << detector.
position().
perp()
376 <<
", z: " << std::setprecision(1) << std::setw(6) << detector.
position().
z()
377 <<
", phi: " << std::setprecision(3) << std::setw(6) << detector.
position().
phi() <<
")" << std::endl;
Log< level::Info, true > LogVerbatim
void analyze(const edm::Event &, const edm::EventSetup &) override
void split(MaterialAccountingTrack &track)
const std::vector< MaterialAccountingDetector > & detectors() const
double sigmaRadiationLengths(void) const
std::unique_ptr< DD4hep_TrackingMaterialPlotter > m_plotter
const std::vector< MaterialAccountingStep > & steps() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > m_dddToken
DD4hep_TrackingMaterialAnalyser(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Geom::Phi< T > phi() const
double length(void) const
bool m_skipBeforeFirstDetector
std::vector< DD4hep_MaterialAccountingGroup * > m_groups
double sigmaLength(void) const
bool m_skipAfterLastDetector
Log< level::Error, false > LogError
edm::EDGetTokenT< std::vector< MaterialAccountingTrack > > m_materialToken
constexpr std::array< uint8_t, layerIndexSize > layer
double averageEnergyLoss(void) const
int findLayer(const MaterialAccountingDetector &detector)
void saveParameters(const char *name)
const std::string & name(void) const
std::vector< std::string > m_groupNames
~DD4hep_TrackingMaterialAnalyser() override
double sigmaEnergyLoss(void) const
double averageRadiationLengths(void) const
unsigned int tracks(void) const
T getParameter(std::string const &) const
std::pair< MaterialAccountingStep, MaterialAccountingStep > split(double fraction) const
split the step (0..1) in (0..f) + (f..1) using linear interpolation
const GlobalPoint & position() const
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
double averageLength(void) const
void saveXml(const char *name)
const MaterialAccountingStep & summary() const