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