CMS 3D CMS Logo

RctDigiToRctText.cc
Go to the documentation of this file.
1 
2 #include "RctDigiToRctText.h"
3 #include <iomanip>
4 
5 using std::dec;
6 using std::endl;
7 using std::hex;
8 using std::setfill;
9 using std::setw;
10 
12  : m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
13  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
14  m_hexUpperCase(iConfig.getParameter<bool>("HexUpperCase")) {
15 
17  for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
18  std::stringstream fileStream;
19  fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i
20  << ".txt";
21  std::string fileName(fileStream.str());
22  m_file[i].open(fileName.c_str(), std::ios::out);
23 
24  if (!m_file[i].good()) {
25  throw cms::Exception("RctDigiToRctTextTextFileOpenError")
26  << "RctDigiToRctText::RctDigiToRctText : "
27  << " couldn't create the file " << fileName << std::endl;
28  }
29  }
30 
32  fdebug.open("rctdigitorcttext_debug.txt", std::ios::out);
33 }
34 
37  for (unsigned i = 0; i < NUM_RCT_CRATES; i++)
38  m_file[i].close();
39  fdebug.close();
40 }
41 
43  const edm::EventSetup &iSetup) {
44 
46  static int nevt = -1;
47  nevt++;
48 
52  iEvent.getByLabel(m_rctInputLabel, em);
53  iEvent.getByLabel(m_rctInputLabel, rgn);
54 
56  bool ldebug = false;
57  bool debug_NOTEMPTY[18] = {false};
58  for (int i = 0; i < 18; i++)
59  debug_NOTEMPTY[i] = false;
60  std::stringstream dstrm;
61 
63 
64  unsigned long int CAND[18][8];
65  int n_iso[18] = {0};
66  int n_niso[18] = {0};
67  bool iso;
68  int id;
69 
70  for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end();
71  iem++) {
72 
73  int crate = iem->rctCrate();
74  iso = iem->isolated();
75  unsigned data = iem->raw();
76 
77  id = iso ? n_iso[crate]++ : 4 + n_niso[crate]++;
78 
79  CAND[crate][id] = data;
80 
82  if (crate > 17 || id > 7)
83  throw cms::Exception("RctDigiToRctTextElectronIndexOutBounds")
84  << "out of bounds indices crate:" << crate << "id:" << id
85  << std::endl;
86  if (ldebug && data != 0)
87  debug_NOTEMPTY[crate] = true;
88  dstrm.str("");
89  dstrm << "electron "
90  << " bx:" << nevt << " crate:" << crate << " iso:" << iso
91  << " raw:" << data << " \t cand:" << *iem;
92  if (debug_NOTEMPTY[crate])
93  fdebug << dstrm.str() << std::endl;
94  }
95 
97 
98  unsigned short MIPbits[18][7][2] = {{{0}}};
99  unsigned short QIEbits[18][7][2] = {{{0}}};
100  unsigned short RC[18][7][2] = {{{0}}};
101  unsigned short RCof[18][7][2] = {{{0}}};
102  unsigned short RCtau[18][7][2] = {{{0}}};
103  unsigned short HF[18][4][2] = {{{0}}};
104 
105  for (L1CaloRegionCollection::const_iterator irgn = rgn->begin();
106  irgn != rgn->end(); irgn++) {
107 
108  int crate = irgn->rctCrate();
109  int card = irgn->rctCard();
110  int rgnidx = irgn->rctRegionIndex();
111 
112  dstrm.str("");
113  if (!irgn->id().isHf()) {
114  RC[crate][card][rgnidx] = irgn->et();
115  RCof[crate][card][rgnidx] = irgn->overFlow();
116  RCtau[crate][card][rgnidx] = irgn->tauVeto();
117  MIPbits[crate][card][rgnidx] = irgn->mip();
118  QIEbits[crate][card][rgnidx] = irgn->quiet();
119  // debug info
120  dstrm << hex << "Et=" << irgn->et() << " OverFlow=" << irgn->overFlow()
121  << " tauVeto=" << irgn->tauVeto() << " mip=" << irgn->mip()
122  << " quiet=" << irgn->quiet() << " Card=" << irgn->rctCard()
123  << " Region=" << irgn->rctRegionIndex()
124  << " Crate=" << irgn->rctCrate() << dec;
125  if (ldebug)
126  LogDebug("Regions") << dstrm.str();
127  } else {
128  HF[crate][irgn->id().rctEta() - 7][irgn->id().rctPhi()] = irgn->et();
129  // debug info
130  dstrm << hex << "Et=" << irgn->et() << " FGrain=" << irgn->fineGrain()
131  << " Eta=" << irgn->id().rctEta() << " Phi=" << irgn->id().rctPhi()
132  << " Crate=" << irgn->rctCrate() << dec;
133  if (ldebug)
134  LogDebug("HFRegions") << dstrm.str();
135  }
136 
137  if (ldebug && irgn->et() != 0)
138  debug_NOTEMPTY[crate] = true; // debug
139  if (debug_NOTEMPTY[crate]) {
140  fdebug << "region"
141  << " bx:" << nevt << " crate:" << crate << "\t";
142  fdebug << dstrm.str() << std::endl;
143  }
144  }
145 
146  std::stringstream sstrm;
147  if (m_hexUpperCase)
148  sstrm << std::uppercase;
149  else
150  sstrm.unsetf(std::ios::uppercase);
151 
153 
154  for (unsigned crate = 0; crate < NUM_RCT_CRATES; crate++) {
155 
156  sstrm.str("");
157  sstrm << "Crossing " << nevt << std::endl;
158 
159  for (int j = 0; j < 8; j++) {
160  sstrm << setw(3) << setfill('0') << hex << (CAND[crate][j] & 0x3ff);
161  if (j < 7)
162  sstrm << " ";
163  }
164  sstrm << setfill(' ') << dec;
165  m_file[crate] << sstrm.str() << std::endl;
166 
167  // debug
168  if (debug_NOTEMPTY[crate])
169  fdebug << sstrm.str() << std::endl;
170  if (ldebug)
171  LogDebug("Electrons") << sstrm.str() << std::endl;
172  }
173 
175 
176  for (unsigned crate = 0; crate < NUM_RCT_CRATES; crate++) {
177 
179  sstrm.str("");
180  for (int card = 0; card < 7; card++) {
181  for (int j = 0; j < 2; j++) {
182  sstrm << " " << MIPbits[crate][card][j];
183  }
184  }
185  m_file[crate] << sstrm.str() << std::endl;
186  if (debug_NOTEMPTY[crate])
187  fdebug << sstrm.str() << std::endl; // debug
188 
190  sstrm.str("");
191  for (int card = 0; card < 7; card++) {
192  for (int j = 0; j < 2; j++) {
193  sstrm << " " << QIEbits[crate][card][j];
194  }
195  }
196  m_file[crate] << sstrm.str() << std::endl;
197  if (debug_NOTEMPTY[crate])
198  fdebug << sstrm.str() << std::endl; // debug
199 
201  sstrm.str("");
202  for (int card = 0; card < 7; card++) {
203  for (int j = 0; j < 2; j++) {
204  unsigned long int tmp;
205  unsigned et = RC[crate][card][j];
206  unsigned ovf = RCof[crate][card][j];
207  unsigned tau = RCtau[crate][card][j];
208  // ovf = ovf || (et>=0x400);
209  tmp = ((tau & 0x1) << 11) | ((ovf & 0x1) << 10) | ((et & 0x3ff));
210  sstrm << " " << setw(3) << setfill('0') << hex << tmp;
211  }
212  }
213  m_file[crate] << sstrm.str() << std::endl;
214  if (debug_NOTEMPTY[crate])
215  fdebug << sstrm.str() << std::endl << std::endl; // debug
216 
218  sstrm.str("");
219  for (int ip = 0; ip < 2; ip++) {
220  for (int ie = 0; ie < 4; ie++) {
221  unsigned et = HF[crate][ie][ip] & 0xff;
222  sstrm << " " << setw(2) << setfill('0') << hex << et;
223  }
224  }
225  m_file[crate] << sstrm.str() << std::endl;
226  if (debug_NOTEMPTY[crate])
227  fdebug << sstrm.str() << std::endl; // debug
228  sstrm << setfill(' ') << dec;
229 
230  } // end crate loop
231 
233  for (unsigned i = 0; i < NUM_RCT_CRATES; i++)
234  m_file[i] << std::flush;
235 
236  fdebug << std::flush;
237 }
#define LogDebug(id)
static const unsigned NUM_RCT_CRATES
bool m_hexUpperCase
write upper case hex words
edm::InputTag m_rctInputLabel
label for RCT digis
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
std::ofstream m_file[NUM_RCT_CRATES]
handles for output files
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
~RctDigiToRctText() override
RctDigiToRctText(const edm::ParameterSet &)
et
define resolution functions of each parameter
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::string m_textFileName
basename for output files
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::ofstream fdebug
handle for debug file