CMS 3D CMS Logo

HtrXmlPattern.cc
Go to the documentation of this file.
4 
7 
8 #include "HtrXmlPatternTool.h"
10 
11 // system include files
12 #include <memory>
13 
14 // default include files
17 
20 
23 
25 public:
26  explicit HtrXmlPattern(const edm::ParameterSet&);
27  ~HtrXmlPattern() override;
28 
29 private:
30  void analyze(const edm::Event&, const edm::EventSetup&) override;
31  void endJob() override;
32  virtual void do_hand_fill(const HcalElectronicsMap*);
38  bool m_filled;
40 
42 };
43 
45  m_filled = false;
46  m_fill_by_hand = iConfig.getUntrackedParameter<bool>("fill_by_hand");
47  m_hand_pattern_number = iConfig.getUntrackedParameter<int>("hand_pattern_number");
48  m_sets_to_show = iConfig.getUntrackedParameter<int>("sets_to_show");
49  m_write_root_file = iConfig.getUntrackedParameter<bool>("write_root_file");
50 
52  m_toolparameters->m_show_errors = iConfig.getUntrackedParameter<bool>("show_errors");
53  m_toolparameters->m_presamples_per_event = iConfig.getUntrackedParameter<int>("presamples_per_event");
54  m_toolparameters->m_samples_per_event = iConfig.getUntrackedParameter<int>("samples_per_event");
55 
56  m_toolparameters->m_XML_file_mode = iConfig.getUntrackedParameter<int>("XML_file_mode");
59 
61  while (out_dir.find_last_of('/') == out_dir.length() - 1)
62  out_dir.erase(out_dir.find_last_of('/'));
64 
66 }
67 
69  delete m_tool;
70  delete m_toolparameters;
71 }
72 
73 // ------------ method called to for each event ------------
75  using namespace std;
76 
77  if (m_filled)
78  return;
79 
80  // Get the HCAL Electronics Map from the Event setup
81  const auto pSetup = iSetup.getHandle(m_hcalElectronicsMapToken);
82  const HcalElectronicsMap* readoutMap = pSetup->getHcalMapping();
83 
84  if (m_fill_by_hand) {
85  do_hand_fill(readoutMap);
86  m_filled = true;
87  return;
88  }
89 
90  std::vector<edm::Handle<HBHEDigiCollection> > hbhe;
91  std::vector<edm::Handle<HODigiCollection> > ho;
92  std::vector<edm::Handle<HFDigiCollection> > hf;
93  std::vector<edm::Handle<ZDCDigiCollection> > zdc;
94  std::vector<edm::Handle<HcalCalibDigiCollection> > hc;
95  std::vector<edm::Handle<HcalTrigPrimDigiCollection> > htp;
96  std::vector<edm::Handle<HcalHistogramDigiCollection> > hh;
97 
98  iEvent.getManyByType(hbhe);
99  if (hbhe.empty()) {
100  edm::LogPrint("HtrXmlPattern") << "No HB/HE Digis.";
101  } else {
102  std::vector<edm::Handle<HBHEDigiCollection> >::iterator i;
103  for (i = hbhe.begin(); i != hbhe.end(); i++) {
104  const HBHEDigiCollection& c = *(*i);
105 
106  int count = 0;
107  for (HBHEDigiCollection::const_iterator j = c.begin(); j != c.end(); j++) {
108  const HcalElectronicsId HEID = readoutMap->lookup(j->id());
109  m_tool->Fill(HEID, j);
110 
111  if (count++ < m_sets_to_show || m_sets_to_show < 0) {
112  edm::LogPrint("HtrXmlPattern") << *j;
113  edm::LogPrint("HtrXmlPattern") << HEID;
114  edm::LogPrint("HtrXmlPattern") << "count: " << count;
115  }
116  }
117  if (m_sets_to_show != 0)
118  edm::LogPrint("HtrXmlPattern") << "HB/HE count: " << count;
119  }
120  }
121 
122  iEvent.getManyByType(hf);
123  if (hf.empty()) {
124  edm::LogPrint("HtrXmlPattern") << "No HF Digis.";
125  } else {
126  std::vector<edm::Handle<HFDigiCollection> >::iterator i;
127  for (i = hf.begin(); i != hf.end(); i++) {
128  const HFDigiCollection& c = *(*i);
129 
130  int count = 0;
131  for (HFDigiCollection::const_iterator j = c.begin(); j != c.end(); j++) {
132  const HcalElectronicsId HEID = readoutMap->lookup(j->id());
133  m_tool->Fill(HEID, j);
134 
135  if (count++ < m_sets_to_show || m_sets_to_show < 0) {
136  edm::LogPrint("HtrXmlPattern") << *j;
137  edm::LogPrint("HtrXmlPattern") << HEID;
138  edm::LogPrint("HtrXmlPattern") << "count: " << count;
139  }
140  }
141  if (m_sets_to_show != 0)
142  edm::LogPrint("HtrXmlPattern") << "HF count: " << count;
143  }
144  }
145 
146  iEvent.getManyByType(ho);
147  if (ho.empty()) {
148  edm::LogPrint("HtrXmlPattern") << "No HO Digis.";
149  } else {
150  std::vector<edm::Handle<HODigiCollection> >::iterator i;
151  for (i = ho.begin(); i != ho.end(); i++) {
152  const HODigiCollection& c = *(*i);
153 
154  int count = 0;
155  for (HODigiCollection::const_iterator j = c.begin(); j != c.end(); j++) {
156  const HcalElectronicsId HEID = readoutMap->lookup(j->id());
157  m_tool->Fill(HEID, j);
158 
159  if (count++ < m_sets_to_show || m_sets_to_show < 0) {
160  edm::LogPrint("HtrXmlPattern") << *j;
161  edm::LogPrint("HtrXmlPattern") << HEID;
162  edm::LogPrint("HtrXmlPattern") << "count: " << count;
163  }
164  }
165  if (m_sets_to_show != 0)
166  edm::LogPrint("HtrXmlPattern") << "HO count: " << count;
167  }
168  }
169 
170  edm::LogPrint("HtrXmlPattern");
171 }
172 
175 
176  for (int iCrate = 0; iCrate < ChannelPattern::NUM_CRATES; iCrate++) {
177  CrateData* cd = hxps->getCrate(iCrate);
178  if (!cd)
179  continue;
180  for (int iSlot = 0; iSlot < ChannelPattern::NUM_SLOTS; iSlot++) {
181  for (int iTb = 0; iTb < 2; iTb++) {
182  HalfHtrData* hhd = cd->getHalfHtrData(iSlot, iTb);
183  if (!hhd)
184  continue;
185  for (int iChannel = 1; iChannel < 25; iChannel++) {
186  ChannelPattern* cp = hhd->getPattern(iChannel);
187  if (!cp)
188  continue;
189  cp->Fill_by_hand(emap, m_hand_pattern_number);
190  }
191  }
192  }
193  }
194 }
195 
196 // ------------ method called once each job just after ending the event loop ------------
198  bool modeg0 = m_toolparameters->m_XML_file_mode > 0;
199  if (modeg0 || m_write_root_file)
200  m_tool->prepareDirs();
201  if (modeg0)
202  m_tool->writeXML();
203  if (m_write_root_file)
204  m_tool->createHists();
205 }
206 
const edm::ESGetToken< HcalDbService, HcalDbRecord > m_hcalElectronicsMapToken
HtrXmlPatternToolParameters * m_toolparameters
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
auto const & hh
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
std::vector< T >::const_iterator const_iterator
~HtrXmlPattern() override
void endJob() override
HtrXmlPattern(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
static const int NUM_CRATES
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
ChannelPattern * getPattern(int chan)
int m_hand_pattern_number
bool m_write_root_file
static const int NUM_SLOTS
Log< level::Warning, true > LogPrint
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
void Fill(const HcalElectronicsId HEID, HBHEDigiCollection::const_iterator data)
HtrXmlPatternSet * GetPatternSet()
CrateData * getCrate(int crate)
virtual void do_hand_fill(const HcalElectronicsMap *)
Readout chain identification for Hcal.
HtrXmlPatternTool * m_tool