CMS 3D CMS Logo

RctTextToRctDigi.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RctTextToRctDigi
4 // Class: RctTextToRctDigi
5 //
12 //
13 // Original Author: Alex Tapper
14 // Created: Fri Mar 9 19:11:51 CET 2007
15 
16 // Rct Input File Format
17 // Line 1: Crossing no as "Crossing x" (2)
18 // Line 2: isoe0 isoe1 isoe2 isoe3 nonIsoe0 nonIsoe1 nonIso2 nonIso3 (8)
19 // Line 3: RC0mip0 RC0mip1 RC1mip0 RC1mip1 RC2mip0 RC2mip1 RC3mip0 RC3mip1
20 // RC4mip0 RC4mip1
21 // RC5mip0 RC5mip1 RC6mip0 RC6mip1 (14)
22 // Line 4: RC0qt0 RCqt1 RC1qt0 RC1qt1 RC2qt0 RC2qt1 RC3qt0 RC3qt1 RC4qt0 RC4qt1
23 // RC5qt0 RC5qt1 RC6qt0 RC6qt1 (14)
24 // Line 5: RC0reg0 RC0reg1 RC1reg0 RC1reg1 RC2reg0 RC2reg1 RC3reg0 RC3reg1
25 // RC4reg0 RC4reg1
26 // RC5reg0 RC5reg1 RC6reg0 RC6reg1 (14)
27 // Line 6: HF0eta0 HF0eta1 HF0eta2 HF0eta3 HF1eta0 HF1eta1 HF1eta2 HF1eta3 (8)
28 //
29 // NOTE: CMS IN 2004/009 specifies that cable four provides 8 Quiet (fineGrain)
30 // bits for the HF. These are not
31 // detailed in the fileformat above, and are not currently dealt with in
32 // any way. Set to true.
33 //
34 
36 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
37 #include "RctTextToRctDigi.h"
38 #include <iomanip>
39 
40 using namespace edm;
41 using namespace std;
42 
43 // Set constant
44 const static unsigned NUM_RCT_CRATES = 18;
45 
47  : m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
48  m_fileEventOffset(iConfig.getParameter<int>("FileEventOffset")),
49  m_nevt(0) {
50  // Produces collections
51  produces<L1CaloEmCollection>();
52  produces<L1CaloRegionCollection>();
53 
54  // Open the input files
55  for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
56  std::stringstream fileStream;
57  fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i
58  << ".txt";
59  std::string fileName(fileStream.str());
60  m_file[i].open(fileName.c_str(), std::ios::in);
61 
62  if (!m_file[i].good()) {
63  // throw cms::Exception("RctTextToRctDigiTextFileOpenError")
64  LogDebug("RctTextToRctDigi") << "RctTextToRctDigi::RctTextToRctDigi : "
65  << " couldn't open the file " << fileName
66  << "...skipping!" << std::endl;
67  }
68  }
69 }
70 
72  // Close the input files
73  for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
74  m_file[i].close();
75  }
76 }
77 
80  std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
81  std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
82  for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
83  for (unsigned j = 0; j < 4; j++) {
84  em->push_back(L1CaloEmCand(0, i, true));
85  em->push_back(L1CaloEmCand(0, i, false));
86  }
87  for (unsigned j = 0; j < 14; j++)
88  rgn->push_back(
89  L1CaloRegion(0, false, false, false, false, i, j / 2, j % 2));
90  for (unsigned j = 0; j < 8; j++)
91  rgn->push_back(L1CaloRegion(0, true, i, j));
92  }
93  iEvent.put(std::move(em));
94  iEvent.put(std::move(rgn));
95 }
96 
98 void RctTextToRctDigi::bxSynchro(int &bx, int crate) {
100  // bypass bx input until correct bx is reached
101  while (bx < m_nevt + m_fileEventOffset) {
102  for (int j = 0; j < 6; j++) {
103  getline(m_file[crate], tmp);
104  }
105  m_file[crate] >> tmp >> bx;
106  if (tmp != "Crossing")
107  throw cms::Exception("RctTextToRctDigiTextFileReadError")
108  << "RctTextToRctDigi::bxSynchro : "
109  << " something screwy happened Crossing!=" << tmp << std::endl;
110  }
111 }
112 
113 // ------------ method called to produce the data ------------
115  const edm::EventSetup &iSetup) {
116 
117  // Skip event if required
118  if (m_nevt < m_fileEventOffset) {
119  // string tmp;
120  // for (int i=0; i<6; i++){
121  // getline(m_file[i],tmp);
122  //}
123  putEmptyDigi(iEvent);
124  m_nevt++;
125  return;
126  }
127 
128  // New collections
129  std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
130  std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
131 
132  // Loop over RCT crates
133  for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
134 
135  if (!m_file[i].good()) {
136  continue;
137  }
138 
139  // Check we're not at the end of the file
140  if (m_file[i].eof()) {
141  // throw cms::Exception("RctTextToRctDigiTextFileReadError")
142  LogDebug("RctTextToRctDigi")
143  << "RctTextToRctDigi::produce : "
144  << " unexpected end of file " << m_textFileName << i
145  << " adding empty collection for event !" << std::endl;
146  putEmptyDigi(iEvent);
147  continue;
148  }
149 
150  // Check we're at the start of an event
152  m_file[i] >> tmp;
153  if (tmp != "Crossing") {
154  throw cms::Exception("RctTextToRctDigiTextFileReadError")
155  << "RctTextToRctDigi::produce : "
156  << " something screwy happened Crossing!=" << tmp << std::endl;
157  }
158 
159  // Read BX number
160  dec(m_file[i]);
161  int BXNum;
162  m_file[i] >> BXNum;
163 
165  bxSynchro(BXNum, i);
166 
167  if (BXNum != m_nevt + m_fileEventOffset)
168  throw cms::Exception("RctTextToRctDigiTextSyncError")
169  << "RctTextToRctDigi::produce : "
170  << " something screwy happened "
171  << "evt:" << m_nevt << " != bx:" << BXNum << " + "
172  << m_fileEventOffset << std::endl;
173 
174  // Buffers
175  unsigned long int uLongBuffer;
176  bool mipBitBuffer[14], qBitBuffer[14];
177 
178  // All in hex from now on
179  hex(m_file[i]);
180 
181  // Isolated electrons
182  for (unsigned j = 0; j < 4; j++) {
183  m_file[i] >> uLongBuffer;
184  em->push_back(L1CaloEmCand(uLongBuffer, i, true, j, BXNum, false));
185  }
186 
187  // Non-isolated electrons
188  for (unsigned j = 0; j < 4; j++) {
189  m_file[i] >> uLongBuffer;
190  em->push_back(L1CaloEmCand(uLongBuffer, i, false, j, BXNum, false));
191  }
192 
193  // MIP bits
194  for (unsigned j = 0; j < 14; j++) {
195  m_file[i] >> mipBitBuffer[j];
196  }
197 
198  // Quiet bits
199  for (unsigned j = 0; j < 14; j++) {
200  m_file[i] >> qBitBuffer[j];
201  }
202 
203  // Barrel and endcap regions
204  for (unsigned j = 0; j < 14; j++) {
205  m_file[i] >> uLongBuffer;
206 
207  unsigned et =
208  uLongBuffer & 0x3ff; // put the first 10 bits of rawData into the Et
209  uLongBuffer >>=
210  10; // shift the remaining bits down to remove the 10 bits of Et
211 
212  bool overFlow = ((uLongBuffer & 0x1) != 0); // LSB is now overflow bit
213  bool tauVeto = (((uLongBuffer & 0x2) >> 1) != 0); // 2nd bit is tauveto
214 
215  rgn->push_back(L1CaloRegion(et, overFlow, tauVeto, mipBitBuffer[j],
216  qBitBuffer[j], i, j / 2, j % 2));
217  }
218 
219  // HF
220  for (unsigned j = 0; j < 8; j++) {
221  m_file[i] >> uLongBuffer;
222 
223  unsigned et = uLongBuffer & 0xff; // put the first 8 bits into the Et
224 
225  rgn->push_back(L1CaloRegion(et, true, i, j));
226  }
227 
228  dec(m_file[i]);
229  }
230 
231  iEvent.put(std::move(em));
232  iEvent.put(std::move(rgn));
233 
234  m_nevt++;
235 }
#define LogDebug(id)
std::vector< L1CaloEmCand > L1CaloEmCollection
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void bxSynchro(int &, int)
Synchronize bunch crossing.
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:18
void putEmptyDigi(edm::Event &)
Create empty digi collection.
std::string m_textFileName
Name out input file.
int iEvent
Definition: GenABIO.cc:224
RctTextToRctDigi(const edm::ParameterSet &)
static const unsigned NUM_RCT_CRATES
int m_nevt
Event counter.
~RctTextToRctDigi() override
int m_fileEventOffset
Number of events to be offset wrt input.
et
define resolution functions of each parameter
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:22
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< L1CaloRegion > L1CaloRegionCollection
std::ifstream m_file[18]
file handle
def move(src, dest)
Definition: eostools.py:511