CMS 3D CMS Logo

HtrXmlPatternTool.cc
Go to the documentation of this file.
1 #include "HtrXmlPatternTool.h"
3 #include "HtrXmlPatternSet.h"
4 #include "HtrXmlPatternWriter.h"
5 #include "TFile.h"
6 #include "TH1.h"
7 #include <iostream>
8 #include <fstream>
9 #include "boost/filesystem/operations.hpp"
10 
12  m_params = params;
13 
14  //slotsOn array index corresponds to physical number (e.g., slotsOn[1] for slot 1)
15  int slotsOn[ChannelPattern::NUM_SLOTS];
16  int cratesOn[ChannelPattern::NUM_CRATES];
17 
18  //turn off all slots
19  for (int i = 0; i < ChannelPattern::NUM_SLOTS; i++)
20  slotsOn[i] = 0;
21  //turn on slots 2,3,4,5,6,7,8
22  for (int i = 2; i < 9; i++)
23  slotsOn[i] = 1;
24  //turn on slots 13,14,15,16,17,18
25  for (int i = 13; i < 19; i++)
26  slotsOn[i] = 1;
27 
28  //turn on all crates
29  for (int i = 0; i < ChannelPattern::NUM_CRATES; i++)
30  cratesOn[i] = 1;
31  //turn off two unused crates
32  cratesOn[8] = 0;
33  cratesOn[16] = 0;
34 
35  m_patternSet = new HtrXmlPatternSet(cratesOn, slotsOn);
37 }
38 
40 
43  HalfHtrData* hd = nullptr;
44  ChannelPattern* cp = nullptr;
45 
46  if (cd) {
47  hd = cd->getHalfHtrData(HEID.htrSlot(), HEID.htrTopBottom());
48  if (hd) {
49  hd->setSpigot(HEID.spigot());
50  hd->setDCC(HEID.dccid());
51 
52  cp = hd->getPattern(HEID.htrChanId());
53  if (cp)
54  cp->Fill(m_params, data);
55  else if (m_params->m_show_errors)
56  std::cerr << "Bad (crate,slot,channel): (" << HEID.readoutVMECrateId() << "," << HEID.htrSlot() << ","
57  << HEID.htrChanId() << ")" << std::endl;
58  } else if (m_params->m_show_errors)
59  std::cerr << "Bad (crate,slot): (" << HEID.readoutVMECrateId() << "," << HEID.htrSlot() << ")" << std::endl;
60  } else if (m_params->m_show_errors)
61  std::cerr << "Bad (crate): (" << HEID.readoutVMECrateId() << ")" << std::endl;
62 }
63 
66  HalfHtrData* hd = nullptr;
67  ChannelPattern* cp = nullptr;
68 
69  if (cd) {
70  hd = cd->getHalfHtrData(HEID.htrSlot(), HEID.htrTopBottom());
71  if (hd) {
72  hd->setSpigot(HEID.spigot());
73  hd->setDCC(HEID.dccid());
74 
75  cp = hd->getPattern(HEID.htrChanId());
76  if (cp)
77  cp->Fill(m_params, data);
78  else if (m_params->m_show_errors)
79  std::cerr << "Bad (crate,slot,channel): (" << HEID.readoutVMECrateId() << "," << HEID.htrSlot() << ","
80  << HEID.htrChanId() << ")" << std::endl;
81  } else if (m_params->m_show_errors)
82  std::cerr << "Bad (crate,slot): (" << HEID.readoutVMECrateId() << "," << HEID.htrSlot() << ")" << std::endl;
83  } else if (m_params->m_show_errors)
84  std::cerr << "Bad (crate): (" << HEID.readoutVMECrateId() << ")" << std::endl;
85 }
86 
89  HalfHtrData* hd = nullptr;
90  ChannelPattern* cp = nullptr;
91 
92  if (cd) {
93  hd = cd->getHalfHtrData(HEID.htrSlot(), HEID.htrTopBottom());
94  if (hd) {
95  hd->setSpigot(HEID.spigot());
96  hd->setDCC(HEID.dccid());
97 
98  cp = hd->getPattern(HEID.htrChanId());
99  if (cp)
100  cp->Fill(m_params, data);
101  else if (m_params->m_show_errors)
102  std::cerr << "Bad (crate,slot,channel): (" << HEID.readoutVMECrateId() << "," << HEID.htrSlot() << ","
103  << HEID.htrChanId() << ")" << std::endl;
104  } else if (m_params->m_show_errors)
105  std::cerr << "Bad (crate,slot): (" << HEID.readoutVMECrateId() << "," << HEID.htrSlot() << ")" << std::endl;
106  } else if (m_params->m_show_errors)
107  std::cerr << "Bad (crate): (" << HEID.readoutVMECrateId() << ")" << std::endl;
108 }
109 
110 void HtrXmlPatternTool::prepareDirs() { boost::filesystem::create_directory(m_params->m_output_directory); }
111 
113  std::cout << "Writing XML..." << std::endl;
114  std::ofstream* of = nullptr;
115 
116  if (m_params->m_XML_file_mode == 1) {
118  of = new std::ofstream(name.c_str(), std::ios_base::out | std::ios_base::trunc);
119  if (!of->good()) {
120  std::cerr << "XML output file " << name << " is bad." << std::endl;
121  return;
122  }
123  (*of) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
124  (*of) << "<CFGBrickSet name='" << m_params->m_file_tag << "'>" << std::endl;
125  }
126 
127  for (int crate = 0; crate < ChannelPattern::NUM_CRATES; crate++) {
128  CrateData* cd = m_patternSet->getCrate(crate);
129  if (cd == nullptr)
130  continue;
131 
132  if (m_params->m_XML_file_mode == 2) {
134  char cr_name[256];
135  snprintf(cr_name, 256, "_crate_%d.xml", crate);
136  name += cr_name;
137  of = new std::ofstream(name.c_str(), std::ios_base::out | std::ios_base::trunc);
138  if (!of->good()) {
139  std::cerr << "XML output file " << name << " is bad." << std::endl;
140  delete of;
141  return;
142  }
143  (*of) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
144  (*of) << "<CFGBrickSet name='" << m_params->m_file_tag << "'>" << std::endl;
145  }
146 
147  for (int slot = 0; slot < ChannelPattern::NUM_SLOTS; slot++) {
148  for (int tb = 0; tb <= 1; tb++) {
149  HalfHtrData* hd = cd->getHalfHtrData(slot, tb);
150  if (hd == nullptr)
151  continue;
152  for (int fiber = 1; fiber <= 8; fiber++) {
153  if (m_params->m_XML_file_mode == 3) {
155  char cr_name[256];
156  snprintf(cr_name, 256, "_crate_%d_slot_%d_tb_%d_fiber_%d.xml", crate, slot, tb, fiber);
157  name += cr_name;
158  of = new std::ofstream(name.c_str(), std::ios_base::out | std::ios_base::trunc);
159  if (!of->good()) {
160  std::cerr << "XML output file " << name << " is bad." << std::endl;
161  delete of;
162  return;
163  }
164  (*of) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
165  }
166  m_xmlWriter.writePattern(hd, fiber, *of, 1);
167  if (m_params->m_XML_file_mode == 3) {
168  of->close();
169  delete of;
170  of = nullptr;
171  }
172 
173  } //end fiber loop
174  } // end tb loop
175  } //end slot loop
176 
177  if (m_params->m_XML_file_mode == 2) {
178  (*of) << "</CFGBrickSet>" << std::endl;
179  of->close();
180  delete of;
181  of = nullptr;
182  }
183 
184  } //end crate loop
185 
186  if (m_params->m_XML_file_mode == 1) {
187  (*of) << "</CFGBrickSet>" << std::endl;
188  of->close();
189  delete of;
190  of = nullptr;
191  }
192 }
193 
195  std::cout << "Writing root file..." << std::endl;
197  TFile of(name.c_str(), "RECREATE");
198  if (of.IsZombie()) {
199  std::cerr << "root output file " << name << " is bad." << std::endl;
200  return;
201  }
202 
203  of.mkdir("adc");
204 
205  for (int crate = 0; crate < ChannelPattern::NUM_CRATES; crate++) {
206  CrateData* cd = m_patternSet->getCrate(crate);
207  if (cd == nullptr)
208  continue;
209  for (int slot = 0; slot < ChannelPattern::NUM_SLOTS; slot++) {
210  for (int tb = 0; tb <= 1; tb++) {
211  HalfHtrData* hd = cd->getHalfHtrData(slot, tb);
212  if (hd == nullptr)
213  continue;
214  for (int chan = 1; chan <= 24; chan++) {
216  char hname[128];
217  sprintf(hname, "Exact fC Cr%d,%d%s-%d", crate, slot, ((tb == 1) ? ("t") : ("b")), chan);
218  TH1* hp = new TH1F(hname, hname, ChannelPattern::SAMPLES, -0.5, ChannelPattern::SAMPLES - 0.5);
219  hp->SetDirectory(nullptr);
220  sprintf(hname, "Quantized fC Cr%d,%d%s-%d", crate, slot, ((tb == 1) ? ("t") : ("b")), chan);
221  TH1* hq = new TH1F(hname, hname, ChannelPattern::SAMPLES, -0.5, ChannelPattern::SAMPLES - 0.5);
222  hp->SetDirectory(nullptr);
223  sprintf(hname, "Encoded fC Cr%d,%d%s-%d", crate, slot, ((tb == 1) ? ("t") : ("b")), chan);
224  TH1* ha = new TH1F(hname, hname, ChannelPattern::SAMPLES, -0.5, ChannelPattern::SAMPLES - 0.5);
225  ha->SetDirectory(nullptr);
226  for (int i = 0; i < ChannelPattern::SAMPLES; i++) {
227  hp->Fill(i * 1.0, (*cp)[i]);
228  hq->Fill(i * 1.0, cp->getQuantized(i));
229  ha->Fill(i * 1.0, cp->getCoded(i));
230  }
231  //of.cd("perfect"); hp->Write();
232  //of.cd("quantized"); hq->Write();
233  of.cd("adc");
234  ha->Write();
235  delete hp;
236  delete hq;
237  delete ha;
238  }
239  }
240  }
241  }
242  of.Close();
243 }
HtrXmlPatternToolParameters::m_show_errors
bool m_show_errors
Definition: HtrXmlPatternToolParameters.h:12
HalfHtrData::setDCC
void setDCC(int dcc)
Definition: HtrXmlPatternSet.h:54
mps_fire.i
i
Definition: mps_fire.py:355
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
ChannelPattern
Definition: HtrXmlPatternSet.h:8
HcalElectronicsId::readoutVMECrateId
constexpr int readoutVMECrateId() const
get the readout VME crate number
Definition: HcalElectronicsId.h:105
HtrXmlPatternTool::createHists
void createHists()
Definition: HtrXmlPatternTool.cc:194
HtrXmlPatternToolParameters::m_file_tag
std::string m_file_tag
Definition: HtrXmlPatternToolParameters.h:17
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
HtrXmlPatternTool::m_params
HtrXmlPatternToolParameters * m_params
Definition: HtrXmlPatternTool.h:23
HalfHtrData
Definition: HtrXmlPatternSet.h:44
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HtrXmlPatternToolParameters.h
HcalElectronicsId::htrSlot
constexpr int htrSlot() const
get the htr slot
Definition: HcalElectronicsId.h:97
HtrXmlPatternTool::writeXML
void writeXML()
Definition: HtrXmlPatternTool.cc:112
HtrXmlPatternTool::m_xmlWriter
HtrXmlPatternWriter m_xmlWriter
Definition: HtrXmlPatternTool.h:24
HalfHtrData::getPattern
ChannelPattern * getPattern(int chan)
Definition: HtrXmlPatternSet.h:47
HtrXmlPatternSet
Definition: HtrXmlPatternSet.h:72
trackingPlots.hp
hp
Definition: trackingPlots.py:1246
ChannelPattern::SAMPLES
static const int SAMPLES
Definition: HtrXmlPatternSet.h:10
HtrXmlPatternToolParameters::m_output_directory
std::string m_output_directory
Definition: HtrXmlPatternToolParameters.h:19
HtrXmlPatternToolParameters::m_XML_file_mode
int m_XML_file_mode
Definition: HtrXmlPatternToolParameters.h:16
CrateData
Definition: HtrXmlPatternSet.h:62
ChannelPattern::NUM_CRATES
static const int NUM_CRATES
Definition: HtrXmlPatternSet.h:11
HcalElectronicsId
Readout chain identification for Hcal.
Definition: HcalElectronicsId.h:32
HtrXmlPatternTool::prepareDirs
void prepareDirs()
Definition: HtrXmlPatternTool.cc:110
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HtrXmlPatternTool::HtrXmlPatternTool
HtrXmlPatternTool(HtrXmlPatternToolParameters *m_params)
Definition: HtrXmlPatternTool.cc:11
HtrXmlPatternSet.h
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
HtrXmlPatternTool.h
HcalElectronicsId::htrTopBottom
constexpr int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
Definition: HcalElectronicsId.h:103
HtrXmlPatternTool::Fill
void Fill(const HcalElectronicsId HEID, HBHEDigiCollection::const_iterator data)
Definition: HtrXmlPatternTool.cc:41
HtrXmlPatternWriter.h
HtrXmlPatternTool::m_patternSet
HtrXmlPatternSet * m_patternSet
Definition: HtrXmlPatternTool.h:22
HalfHtrData::setSpigot
void setSpigot(int spigot)
Definition: HtrXmlPatternSet.h:53
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
ChannelPattern::NUM_SLOTS
static const int NUM_SLOTS
Definition: HtrXmlPatternSet.h:13
HtrXmlPatternTool::~HtrXmlPatternTool
~HtrXmlPatternTool()
Definition: HtrXmlPatternTool.cc:39
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
hippyaddtobaddatafiles.cd
def cd(newdir)
Definition: hippyaddtobaddatafiles.py:40
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HcalElectronicsId::spigot
constexpr int spigot() const
get the spigot (input number on DCC, AMC card number for uTCA)
Definition: HcalElectronicsId.h:93
HcalElectronicsId::dccid
constexpr int dccid() const
get the (Hcal local) DCC id for VME, crate number for uTCA
Definition: HcalElectronicsId.h:95
HtrXmlPatternSet::getCrate
CrateData * getCrate(int crate)
Definition: HtrXmlPatternSet.cc:295
HtrXmlPatternWriter::writePattern
void writePattern(HalfHtrData *spigotData, int fiber, std::ostream &os, int level=0)
Definition: HtrXmlPatternWriter.cc:22
HcalElectronicsId::htrChanId
constexpr int htrChanId() const
get the HTR channel id (1-24)
Definition: HcalElectronicsId.h:87
CommonMethods.cp
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
Definition: CommonMethods.py:192
pileupReCalc_HLTpaths.trunc
trunc
Definition: pileupReCalc_HLTpaths.py:144
HtrXmlPatternToolParameters
Definition: HtrXmlPatternToolParameters.h:6
HtrXmlPatternWriter::setTagName
void setTagName(std::string tn)
Definition: HtrXmlPatternWriter.h:10