test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ListGroups.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 #include <map>
4 #include <iostream>
5 #include <iomanip>
6 
7 #include "boost/format.hpp"
8 
17 
24 
25 // ROOT
26 #include <TROOT.h>
27 #include <TProfile2D.h>
28 #include <TColor.h>
29 #include <TStyle.h>
30 #include <TCanvas.h>
31 #include <TFrame.h>
32 #include <TText.h>
33 #include <TLegend.h>
34 #include <TLegendEntry.h>
35 #include <TLine.h>
36 
39 
40 static
42  std::vector<const DDsvalues_type *> result;
43  view.specificsV(result);
44  for (std::vector<const DDsvalues_type *>::iterator it = result.begin(); it != result.end(); ++it) {
45  DDValue parameter(name);
46  if (DDfetch(*it, parameter)) {
47  if (parameter.strings().size() == 1) {
48  value = parameter.strings().front();
49  return true;
50  } else {
51  throw cms::Exception("Configuration")<< " ERROR: multiple " << name << " tags encountered";
52  return false;
53  }
54  }
55  }
56  return false;
57 }
58 
59 static inline
60 double dddGetDouble(const std::string & s, DDFilteredView const & view) {
62  if (dddGetStringRaw(view, s, value))
63  return double(::atof(value.c_str()));
64  else
65  return NAN;
66 }
67 
68 static inline
71  if (dddGetStringRaw(view, s, value))
72  return value;
73  else
74  return std::string();
75 }
76 
77 static inline
78 std::ostream & operator<<(std::ostream & out, const math::XYZVector & v) {
79  out << std::fixed << std::setprecision(3);
80  return out << "(" << v.rho() << ", " << v.z() << ", " << v.phi() << ")";
81 }
82 
84 {
85 public:
87  virtual ~ListGroups();
88 
89 private:
90  void analyze(const edm::Event &, const edm::EventSetup &) override;
91  void beginJob() override {}
92  void endJob() override;
93  void fillColor();
95  void fillGradient();
96  std::vector<std::pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > > overlayEtaReferences();
99  std::vector<TH2F *> m_plots;
100  std::set<std::string> m_group_names;
101  std::vector<MaterialAccountingGroup *> m_groups;
102  std::vector<unsigned int> m_color;
103  std::vector<int> m_gradient;
104 
105  // The following maps are automatically filled by the script
106  // dumpFullXML, when run with -c,--compare flag, and are injected in
107  // this code via the header ListGroupsMaterialDifference.h, which is
108  // included below. The first value of the pair in m_diff represents
109  // the relative difference ((new - old)/old * 100, in %) of
110  // radiation length, while the second referes to the energy loss (in
111  // GeV/cm) changes. The values in m_values are ordered in the very
112  // same way, ie. they contain the new values for radiation length
113  // and energy loss, respectively.
114  std::map<std::string, std::pair<float, float> > m_diff;
115  std::map<std::string, std::pair<float, float> > m_values;
116 };
117 
119  m_saveSummaryPlot = iPSet.getUntrackedParameter<bool>("SaveSummaryPlot");
120  m_plots.clear();
121  m_groups.clear();
122  TColor::InitializeColors();
123  fillColor();
125  fillGradient();
126 }
127 
129  for (auto plot : m_plots)
130  delete plot;
131 
132  if (m_groups.size())
133  for (auto g : m_groups)
134  delete g;
135 }
136 
138 
140 {
141  m_gradient.reserve(200);
142  unsigned int steps = 100;
143  // if no index was given, find the highest used one and start from that plus one
144  unsigned int index = ((TObjArray*) gROOT->GetListOfColors())->GetLast() + 1;
145 
146  float r1, g1, b1, r2, g2, b2;
147  static_cast<TColor *>(gROOT->GetListOfColors()->At(kBlue + 1))->GetRGB(r1, g1, b1);
148  static_cast<TColor *>(gROOT->GetListOfColors()->At(kAzure + 10))->GetRGB(r2, g2, b2);
149  float delta_r = (r2 - r1) / (steps - 1);
150  float delta_g = (g2 - g1) / (steps - 1);
151  float delta_b = (b2 - b1) / (steps - 1);
152 
153  m_gradient.push_back(kBlue + 4); // Underflow lowest bin
154  unsigned int ii = 0;
155  for (unsigned int i = 0; i < steps; ++i, ++ii) {
156  new TColor(static_cast<Int_t>(index + ii), r1 + delta_r * i, g1 + delta_g * i, b1 + delta_b * i);
157  m_gradient.push_back(index + ii);
158  }
159 
160  m_gradient.push_back(kWhite); // 0 level perfectly white
161 
162  static_cast<TColor *>(gROOT->GetListOfColors()->At(kOrange))->GetRGB(r1, g1, b1);
163  static_cast<TColor *>(gROOT->GetListOfColors()->At(kOrange + 7))->GetRGB(r2, g2, b2);
164  delta_r = (r2 - r1) / (steps - 1);
165  delta_g = (g2 - g1) / (steps - 1);
166  delta_b = (b2 - b1) / (steps - 1);
167  for (unsigned int i = 0; i < steps; ++i, ++ii) {
168  new TColor(static_cast<Int_t>(index + ii), r1 + delta_r * i, g1 + delta_g * i, b1 + delta_b * i);
169  m_gradient.push_back(index + ii);
170  }
171  m_gradient.push_back(kRed); // Overflow highest bin
172 }
173 
175 {
176  m_color.push_back(kBlack); // unassigned
177 
178  m_color.push_back(kAzure); // PixelBarrelLayer0
179  m_color.push_back(kAzure + 1) ; // Layer1_Z0
180  m_color.push_back(kAzure + 2) ; // Layer1_Z10
181  m_color.push_back(kAzure + 3) ; // Layer2_Z0
182  m_color.push_back(kAzure + 10); // Layer2_Z15
183 
184  m_color.push_back(kGreen); // EndCapDisk1_R0
185  m_color.push_back(kGreen + 2); // EndcapDisk1_R11
186  m_color.push_back(kGreen + 4); // EndcapDisk1_R7
187  m_color.push_back(kSpring + 9); // EndcapDisk2_R0
188  m_color.push_back(kSpring + 4); // EndcapDisk2_R7
189 
190  m_color.push_back(kRed); // TECDisk0_R20
191  m_color.push_back(kRed + 2); // TECDisk0_R40
192  m_color.push_back(kRed - 7); // TECDisk0_R50
193  m_color.push_back(kRed - 5); // TECDisk0_R60
194  m_color.push_back(kRed - 10); // TECDisk0_R90
195  m_color.push_back(kRed - 3); // TECDisk1_R20
196  m_color.push_back(kPink - 2); // TECDisk2_R20
197  m_color.push_back(kPink + 9); // TECDisk3
198  m_color.push_back(kMagenta - 2); // TECDisk4_R33
199  m_color.push_back(kMagenta - 4); // TECDisk5_R33
200  m_color.push_back(kRed); // TECDisk6
201  m_color.push_back(kMagenta - 9); // TECDisk7_R40
202  m_color.push_back(kViolet); // TECDisk8
203 
204  m_color.push_back(kOrange + 9); // TIBLayer0_Z0
205  m_color.push_back(kOrange + 7); // TIBLayer0_Z20
206  m_color.push_back(kOrange - 2); // TIBLayer1_Z0
207  m_color.push_back(kOrange - 3); // TIBLayer1_Z30
208  m_color.push_back(kOrange + 4); // TIBLayer2_Z0
209  m_color.push_back(kOrange - 7); // TIBLayer2_Z40
210  m_color.push_back(kOrange); // TIBLayer3_Z0
211  m_color.push_back(kOrange + 10); // TIBLayer3_Z50
212 
213  m_color.push_back(kViolet + 10); // TIDDisk1_R0
214  m_color.push_back(kViolet + 6); // TIDDisk1_R30
215  m_color.push_back(kViolet - 7); // TIDDisk2_R25
216  m_color.push_back(kViolet - 1); // TIDDisk2_R30
217  m_color.push_back(kViolet + 9); // TIDDisk2_R40
218  m_color.push_back(kViolet); // TIDDisk3_R24
219 
220  m_color.push_back(kAzure ); // TOBLayer0_Z0
221  m_color.push_back(kAzure + 8); // TOBLayer0_Z20
222  m_color.push_back(kAzure + 2); // TOBLayer0_Z70
223  m_color.push_back(kCyan + 1); // TOBLayer1_Z0
224  m_color.push_back(kCyan - 9); // TOBLayer1_Z20
225  m_color.push_back(kCyan + 3); // TOBLayer1_Z80
226  m_color.push_back(kAzure ); // TOBLayer2_Z0
227  m_color.push_back(kAzure + 8); // TOBLayer2_Z25
228  m_color.push_back(kAzure + 2); // TOBLayer2_Z80
229  m_color.push_back(kCyan + 1); // TOBLayer3_Z0
230  m_color.push_back(kCyan - 9); // TOBLayer3_Z25
231  m_color.push_back(kCyan + 3); // TOBLayer3_Z80
232  m_color.push_back(kAzure ); // TOBLayer4_Z0
233  m_color.push_back(kAzure + 8); // TOBLayer4_Z25
234  m_color.push_back(kAzure + 2); // TOBLayer4_Z80
235  m_color.push_back(kCyan + 1); // TOBLayer5_Z0
236  m_color.push_back(kCyan - 9); // TOBLayer5_Z25
237  m_color.push_back(kCyan + 3); // TOBLayer5_Z80
238 }
239 
240 std::vector<std::pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > >
242  std::vector<std::pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > > lines;
243 
244  lines.reserve(40);
245  std::pair<float, float> deltaZ(293, 298);
246  std::pair<float, float> deltaR(115, 118);
247  float text_size = 0.033;
248 
249  for (float eta = 0.; eta <= 3.8; eta += 0.2) {
250  float theta = 2. * atan (exp(-eta));
251  if (eta >= 1.8) {
252  lines.push_back(
253  std::make_pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > (
254  std::make_shared<TLine>(
255  deltaZ.first, deltaZ.first * tan(theta), deltaZ.second, deltaZ.second * tan(theta)),
256  std::make_shared<TText>(
257  deltaZ.first, deltaZ.first * tan(theta), str(boost::format("%2.1f") % eta).c_str())));
258  lines.back().second->SetTextFont(42);
259  lines.back().second->SetTextSize(text_size);
260  lines.back().second->SetTextAlign(33);
261  lines.push_back(
262  std::make_pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > (
263  std::make_shared<TLine>(
264  -deltaZ.first, deltaZ.first * tan(theta), -deltaZ.second, deltaZ.second * tan(theta)),
265  std::make_shared<TText>(
266  -deltaZ.first, deltaZ.first * tan(theta), str(boost::format("-%2.1f") % eta).c_str())));
267  lines.back().second->SetTextFont(42);
268  lines.back().second->SetTextSize(text_size);
269  lines.back().second->SetTextAlign(13);
270  } else {
271  lines.push_back(
272  std::make_pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > (
273  std::make_shared<TLine>(
274  deltaR.first / tan(theta), deltaR.first, deltaR.second / tan(theta), deltaR.second),
275  std::make_shared<TText>(
276  deltaR.first / tan(theta), deltaR.first, str(boost::format("%2.1f") % eta).c_str())));
277  lines.back().second->SetTextFont(42);
278  lines.back().second->SetTextSize(text_size);
279  lines.back().second->SetTextAlign(23);
280  if (eta != 0) {
281  lines.push_back(
282  std::make_pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > (
283  std::make_shared<TLine>(
284  - deltaR.first / tan(theta), deltaR.first, - deltaR.second / tan(theta), deltaR.second),
285  std::make_shared<TText>(
286  - deltaR.first / tan(theta), deltaR.first, str(boost::format("-%2.1f") % eta).c_str())));
287  lines.back().second->SetTextFont(42);
288  lines.back().second->SetTextSize(text_size);
289  lines.back().second->SetTextAlign(23);
290  }
291  }
292  }
293  return lines;
294 }
295 
296 
298  const double scale = 10.;
299  std::vector<TText *> nukem_text;
300 
302  setup.get<IdealGeometryRecord>().get( hDdd );
303 
304  for (auto n : m_group_names) {
305  m_groups.push_back( new MaterialAccountingGroup(n, *hDdd) );
306  };
307 
308  std::unique_ptr<TCanvas> canvas(
309  new TCanvas("Grouping_rz", "Grouping - RZ view",
310  (int) (600 * scale * 1.25), (int) (120 * scale * 1.50)));
311  canvas->GetFrame()->SetFillColor(kWhite);
312  gStyle->SetOptStat(0);
313 
314  unsigned int color_index = 1;
315  // Setup the legend
316  std::unique_ptr<TLegend> leg(new TLegend(0.1,0.1,0.23,0.34));
317  leg->SetHeader("Tracker Material Grouping");
318  leg->SetTextFont(42);
319  leg->SetTextSize(0.008);
320  leg->SetNColumns(3);
321  std::unique_ptr<TProfile2D> radlen(
322  new TProfile2D( "OverallRadLen", "OverallRadLen",
323  600., -300., 300, 120., 0., 120.));
324  std::unique_ptr<TProfile2D> eneloss(
325  new TProfile2D( "OverallEnergyLoss", "OverallEnergyLoss",
326  600., -300., 300, 120., 0., 120.));
327  std::unique_ptr<TProfile2D> radlen_diff(
328  new TProfile2D( "OverallDifferencesRadLen", "OverallDifferencesRadLen",
329  600., -300., 300, 120., 0., 120.));
330  std::unique_ptr<TProfile2D> eneloss_diff(
331  new TProfile2D( "OverallDifferencesEnergyLoss", "OverallDifferencesEnergyLoss",
332  600., -300., 300, 120., 0., 120.));
333 
334  for (auto g : m_groups) {
335  m_plots.push_back(
336  new TH2F( g->name().c_str(), g->name().c_str(),
337  6000., -300., 300, 1200., 0., 120.)); // 10x10 points per cm2
338  TH2F &current = *m_plots.back();
339  current.SetMarkerColor(m_color[color_index]);
340  current.SetMarkerStyle( color_index%2 == 0 ? kFullCircle : kOpenCircle);
341  current.SetMarkerSize(0.8);
342  for (auto element : g->elements()) {
343  current.Fill(element.z(), element.perp());
344  radlen->Fill(element.z(), element.perp(), m_values[g->name()].first);
345  eneloss->Fill(element.z(), element.perp(), m_values[g->name()].second);
346  radlen_diff->Fill(element.z(), element.perp(), m_diff[g->name()].first);
347  eneloss_diff->Fill(element.z(), element.perp(), m_diff[g->name()].second);
348  }
349 
350  if (color_index == 1)
351  current.Draw();
352  else
353  current.Draw("SAME");
354 
355  leg->AddEntry(&current , g->name().c_str(), "lp")->SetTextColor(m_color[color_index]);
356  color_index++;
357 
358  // Loop over the same chromatic scale in case the number of
359  // allocated colors is not big enough.
360  color_index = color_index%m_color.size();
361  }
362  leg->Draw();
363  canvas->SaveAs("Grouping.png");
364 
365  std::vector<std::pair<std::shared_ptr<TLine>, std::shared_ptr<TText> > > lines = overlayEtaReferences();
366 
367  canvas->Clear();
368  radlen->SetMinimum(0);
369  radlen->SetMaximum(0.25);
370  radlen->Draw("COLZ");
371  for (auto line : lines) {
372  line.first->SetLineWidth(5);
373  line.first->Draw();
374  line.second->Draw();
375  }
376  canvas->SaveAs("RadLenValues.png");
377 
378  canvas->Clear();
379  eneloss->SetMinimum(0.00001);
380  eneloss->SetMaximum(0.0005);
381  eneloss->Draw("COLZ");
382  for (auto line : lines) {
383  line.first->SetLineWidth(5);
384  line.first->Draw();
385  line.second->Draw();
386  }
387  canvas->SaveAs("EnergyLossValues.png");
388 
389  canvas->Clear();
390  gStyle->SetPalette( m_gradient.size(), & m_gradient.front() );
391  gStyle->SetNumberContours( m_gradient.size() );
392  radlen_diff->SetMinimum(-100);
393  radlen_diff->SetMaximum(100);
394  radlen_diff->Draw("COLZ");
395  for (auto line : lines) {
396  line.first->SetLineWidth(5);
397  line.first->Draw();
398  line.second->Draw();
399  }
400  canvas->SaveAs("RadLenChanges.png");
401 
402  canvas->Clear();
403  eneloss_diff->SetMinimum(-100);
404  eneloss_diff->SetMaximum(100);
405  eneloss_diff->Draw("COLZ");
406  for (auto line : lines) {
407  line.first->SetLineWidth(5);
408  line.first->Draw();
409  line.second->Draw();
410  }
411  canvas->SaveAs("EnergyLossChanges.png");
412 
413  for (auto g : nukem_text)
414  delete g;
415 
416 }
417 
418 
419 void
422  setup.get<IdealGeometryRecord>().get( hDdd );
423  DDFilteredView fv(*hDdd);
424 
426  filter.setCriteria(DDValue("TrackingMaterialGroup", ""), DDCompOp::not_equals);
427  fv.addFilter(filter);
428 
429  while (fv.next()) {
430  // print the group name and full hierarchy of all items
431  std::cout << dddGetString("TrackingMaterialGroup", fv) << '\t';
432  m_group_names.insert(dddGetString("TrackingMaterialGroup", fv));
433 
434  // start from 2 to skip the leading /OCMS[0]/CMSE[1] part
435  const DDGeoHistory & history = fv.geoHistory();
436  std::cout << '/';
437  for (unsigned int h = 2; h < history.size(); ++h)
438  std::cout << '/' << history[h].logicalPart().name().name() << '[' << history[h].copyno() << ']';
439 
440  // DD3Vector and DDTranslation are the same type as math::XYZVector
441  math::XYZVector position = fv.translation() / 10.; // mm -> cm
442  std::cout << "\t" << position << std::endl;
443  };
444  std::cout << std::endl;
445 
446  if (m_saveSummaryPlot)
448 }
449 
450 void
452 }
453 
454 //-------------------------------------------------------------------------
455 // define as a plugin
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void endJob() override
Definition: ListGroups.cc:451
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void fillColor()
Definition: ListGroups.cc:174
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ListGroups.cc:420
virtual ~ListGroups()
Definition: ListGroups.cc:128
Geom::Theta< T > theta() const
string format
Some error handling for the usage.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
int ii
Definition: cuy.py:588
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
std::vector< TH2F * > m_plots
Definition: ListGroups.cc:99
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:80
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 g
Definition: Activities.doc:4
tuple result
Definition: mps_fire.py:84
def canvas
Definition: svgfig.py:481
void beginJob() override
Definition: ListGroups.cc:91
std::vector< unsigned int > m_color
Definition: ListGroups.cc:102
std::vector< std::pair< std::shared_ptr< TLine >, std::shared_ptr< TText > > > overlayEtaReferences()
Definition: ListGroups.cc:241
void produceAndSaveSummaryPlot(const edm::EventSetup &)
Definition: ListGroups.cc:297
bool next()
set current node to the next node in the filtered tree
def plot
Definition: bigModule.py:19
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:249
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static double dddGetDouble(const std::string &s, DDFilteredView const &view)
Definition: ListGroups.cc:60
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:62
std::map< std::string, std::pair< float, float > > m_diff
Definition: ListGroups.cc:114
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
bool m_saveSummaryPlot
Definition: ListGroups.cc:98
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:56
void fillGradient()
Definition: ListGroups.cc:139
std::set< std::string > m_group_names
Definition: ListGroups.cc:100
std::vector< MaterialAccountingGroup * > m_groups
Definition: ListGroups.cc:101
static int position[264][3]
Definition: ReadPGInfo.cc:509
ListGroups(const edm::ParameterSet &)
Definition: ListGroups.cc:118
std::vector< int > m_gradient
Definition: ListGroups.cc:103
void specificsV(std::vector< const DDsvalues_type * > &result) const
User specific data attached to the current node.
tuple cout
Definition: gather_cfg.py:145
static bool dddGetStringRaw(const DDFilteredView &view, const std::string &name, std::string &value)
Definition: ListGroups.cc:41
const DDTranslation & translation() const
The absolute translation of the current node.
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:245
std::map< std::string, std::pair< float, float > > m_values
Definition: ListGroups.cc:115
static std::string dddGetString(const std::string &s, DDFilteredView const &view)
Definition: ListGroups.cc:69
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:32