CMS 3D CMS Logo

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