CMS 3D CMS Logo

EcalWeightXtalGroups_PayloadInspector.cc
Go to the documentation of this file.
6 
7 // the data format of the condition to be inspected
9 
10 #include "TH2F.h"
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 #include "TLine.h"
14 #include "TLatex.h"
15 
16 #include <string>
17 
18 namespace {
19 
20  enum {kEBChannels = 61200, kEEChannels = 14648, kSides = 2, kRMS = 5, TEMPLATESAMPLES = 12};
21  enum {MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360}; // barrel lower and upper bounds on eta and phi
22  enum {IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100}; // endcaps lower and upper bounds on x and y
23 
24  /*****************************************************
25  2d plot of Ecal WeightXtal Groups of 1 IOV
26  *****************************************************/
27  class EcalWeightXtalGroupsPlot : public cond::payloadInspector::PlotImage<EcalWeightXtalGroups> {
28 
29  public:
30  EcalWeightXtalGroupsPlot() : cond::payloadInspector::PlotImage<EcalWeightXtalGroups>("Ecal Weight Xtal Groups - map ") {
31  setSingleIov(true);
32  }
33 
34  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
35  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
36  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
37  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
38 
39  auto iov = iovs.front();
40  std::shared_ptr<EcalWeightXtalGroups> payload = fetchPayload( std::get<1>(iov) );
41  unsigned int run = std::get<0>(iov);
42 
43  if( payload.get() ){
44 
45  if (payload->barrelItems().empty())
46  return false;
47 
48  for(int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
49  uint32_t rawid = EBDetId::unhashIndex(cellid);
50 
51  std::vector<EcalXtalGroupId>::const_iterator value_ptr = payload->find(rawid);
52  // unsigned int id()
53  if (value_ptr == payload->end())
54  continue; // cell absent from payload
55 
56  unsigned int weight = (unsigned int)((*value_ptr).id());
57  Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
58  Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
59 
60 
61 
62  if(eta > 0.)
63  eta = eta - 0.5; // 0.5 to 84.5
64  else
65  eta = eta + 0.5; // -84.5 to -0.5
66 
67  barrel->Fill(phi, eta, weight);
68  }// loop over cellid
69 
70  if (payload->endcapItems().empty())
71  return false;
72 
73  // looping over the EE channels
74  for(int iz = -1; iz < 2; iz = iz + 2) // -1 or +1
75  for(int iy = IY_MIN; iy < IY_MAX+IY_MIN; iy++)
76  for(int ix = IX_MIN; ix < IX_MAX+IX_MIN; ix++)
77  if(EEDetId::validDetId(ix, iy, iz)) {
78  EEDetId myEEId = EEDetId(ix, iy, iz, EEDetId::XYMODE);
79  uint32_t rawid = myEEId.rawId();
80 
81  std::vector<EcalXtalGroupId>::const_iterator value_ptr = payload->find(rawid);
82 
83  if (value_ptr == payload->end())
84  continue; // cell absent from payload
85 
86  unsigned int weight = (unsigned int)((*value_ptr).id());
87 
88  if(iz == 1)
89  endc_p->Fill(ix, iy, weight);
90  else
91  endc_m->Fill(ix, iy, weight);
92  } // validDetId
93  } // payload
94 
95  gStyle->SetPalette(1);
96  gStyle->SetOptStat(0);
97  TCanvas canvas("CC map","CC map", 1600, 450);
98  TLatex t1;
99  t1.SetNDC();
100  t1.SetTextAlign(26);
101  t1.SetTextSize(0.05);
102  t1.DrawLatex(0.5, 0.96, Form("Ecal Weight Xtal Groups, IOV %i", run));
103 
104  float xmi[3] = {0.0 , 0.24, 0.76};
105  float xma[3] = {0.24, 0.76, 1.00};
106  TPad** pad = new TPad*;
107  for (int obj = 0; obj < 3; obj++) {
108  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
109  pad[obj]->Draw();
110  }
111  // EcalDrawMaps ICMap;
112  pad[0]->cd();
113  // ICMap.DrawEE(endc_m, 0., 2.);
114  DrawEE(endc_m, 0., 2.5);
115  pad[1]->cd();
116  // ICMap.DrawEB(barrel, 0., 2.);
117  DrawEB(barrel, 0., 2.5);
118  pad[2]->cd();
119  // ICMap.DrawEE(endc_p, 0., 2.);
120  DrawEE(endc_p, 0., 2.5);
121 
122  std::string ImageName(m_imageFileName);
123  canvas.SaveAs(ImageName.c_str());
124  return true;
125  }// fill method
126  };
127 
128 
129 }
130 
131 // Register the classes as boost python plugin
133  PAYLOAD_INSPECTOR_CLASS(EcalWeightXtalGroupsPlot);
134 }
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
static const int XYMODE
Definition: EEDetId.h:339
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
Definition: weight.py:1
static const int kSides
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
static const int MIN_HASH
Definition: EBDetId.h:156
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:481