CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: RctTextToRctDigi.cc,v 1.4 2007/08/06 11:38:41 nuno Exp $
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 RC4mip0 RC4mip1
20 // RC5mip0 RC5mip1 RC6mip0 RC6mip1 (14)
21 // Line 4: RC0qt0 RCqt1 RC1qt0 RC1qt1 RC2qt0 RC2qt1 RC3qt0 RC3qt1 RC4qt0 RC4qt1
22 // RC5qt0 RC5qt1 RC6qt0 RC6qt1 (14)
23 // Line 5: RC0reg0 RC0reg1 RC1reg0 RC1reg1 RC2reg0 RC2reg1 RC3reg0 RC3reg1 RC4reg0 RC4reg1
24 // RC5reg0 RC5reg1 RC6reg0 RC6reg1 (14)
25 // Line 6: HF0eta0 HF0eta1 HF0eta2 HF0eta3 HF1eta0 HF1eta1 HF1eta2 HF1eta3 (8)
26 //
27 // NOTE: CMS IN 2004/009 specifies that cable four provides 8 Quiet (fineGrain) bits for the HF. These are not
28 // detailed in the fileformat above, and are not currently dealt with in any way. Set to true.
29 //
30 
31 #include "RctTextToRctDigi.h"
32 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
34 #include <iomanip>
35 
36 using namespace edm;
37 using namespace std;
38 
39 // Set constant
40 const static unsigned NUM_RCT_CRATES = 18;
41 
43  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
44  m_fileEventOffset(iConfig.getParameter<int>("FileEventOffset")),
45  m_nevt(0)
46 {
47  // Produces collections
48  produces<L1CaloEmCollection>();
49  produces<L1CaloRegionCollection>();
50 
51  // Open the input files
52  for (unsigned i=0; i<NUM_RCT_CRATES; i++){
53  std::stringstream fileStream;
54  fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i << ".txt";
55  std::string fileName(fileStream.str());
56  m_file[i].open(fileName.c_str(),std::ios::in);
57 
58  if(!m_file[i].good())
59  {
60  //throw cms::Exception("RctTextToRctDigiTextFileOpenError")
61  LogDebug("RctTextToRctDigi")
62  << "RctTextToRctDigi::RctTextToRctDigi : "
63  << " couldn't open the file " << fileName << "...skipping!" << std::endl;
64  }
65  }
66 }
67 
69 {
70  // Close the input files
71  for (unsigned i=0; i<NUM_RCT_CRATES; i++){
72  m_file[i].close();
73  }
74 }
75 
78  std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
79  std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
80  for (unsigned i=0; i<NUM_RCT_CRATES; i++){
81  for (unsigned j=0; j<4; j++) {
82  em->push_back(L1CaloEmCand(0, i, true));
83  em->push_back(L1CaloEmCand(0, i, false));
84  }
85  for (unsigned j=0; j<14; j++)
86  rgn->push_back(L1CaloRegion(0,false,false,false,false,i,j/2,j%2));
87  for (unsigned j=0; j<8; j++)
88  rgn->push_back(L1CaloRegion(0,true,i,j));
89  }
90  iEvent.put(em);
91  iEvent.put(rgn);
92 }
93 
95 void RctTextToRctDigi::bxSynchro(int &bx,int crate) {
96  std::string tmp;
97  // bypass bx input until correct bx is reached
98  while(bx<m_nevt+m_fileEventOffset) {
99  for (int j=0; j<6; j++){
100  getline(m_file[crate],tmp);
101  }
102  m_file[crate] >> tmp >> bx;
103  if(tmp!="Crossing")
104  throw cms::Exception("RctTextToRctDigiTextFileReadError")
105  << "RctTextToRctDigi::bxSynchro : "
106  << " something screwy happened Crossing!=" << tmp << std::endl;
107  }
108 }
109 
110 // ------------ method called to produce the data ------------
112 {
113 
114  // Skip event if required
115  if (m_nevt < m_fileEventOffset){
116  //string tmp;
117  //for (int i=0; i<6; i++){
118  // getline(m_file[i],tmp);
119  //}
120  putEmptyDigi(iEvent);
121  m_nevt++;
122  return;
123  }
124 
125  // New collections
126  std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
127  std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
128 
129  // Loop over RCT crates
130  for (unsigned i=0; i<NUM_RCT_CRATES; i++){
131 
132  if(!m_file[i].good()) {
133  continue;
134  }
135 
136  // Check we're not at the end of the file
137  if(m_file[i].eof())
138  {
139  //throw cms::Exception("RctTextToRctDigiTextFileReadError")
140  LogDebug("RctTextToRctDigi")
141  << "RctTextToRctDigi::produce : "
142  << " unexpected end of file " << m_textFileName << i
143  << " adding empty collection for event !"
144  << std::endl;
145  putEmptyDigi(iEvent);
146  continue;
147  }
148 
149  // Check we're at the start of an event
150  std::string tmp;
151  m_file[i]>> tmp;
152  if(tmp!="Crossing")
153  {
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 << " + " << m_fileEventOffset
172  << 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,0));
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,0));
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 = uLongBuffer & 0x3ff; // put the first 10 bits of rawData into the Et
208  uLongBuffer >>= 10; // shift the remaining bits down to remove the 10 bits of Et
209 
210  bool overFlow = ((uLongBuffer & 0x1) != 0); //LSB is now overflow bit
211  bool tauVeto = (((uLongBuffer & 0x2) >> 1) != 0); //2nd bit is tauveto
212 
213  rgn->push_back(L1CaloRegion(et,overFlow,tauVeto,mipBitBuffer[j],qBitBuffer[j],i,j/2,j%2));
214  }
215 
216  // HF
217  for (unsigned j=0; j<8; j++){
218  m_file[i] >> uLongBuffer;
219 
220  unsigned et = uLongBuffer & 0xff; // put the first 8 bits into the Et
221 
222  rgn->push_back(L1CaloRegion(et,true,i,j));
223  }
224 
225  dec(m_file[i]);
226  }
227 
228  iEvent.put(em);
229  iEvent.put(rgn);
230 
231  m_nevt++;
232 }
233 
234 
235 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< L1CaloEmCand > L1CaloEmCollection
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:243
RctTextToRctDigi(const edm::ParameterSet &)
static const unsigned NUM_RCT_CRATES
int m_nevt
Event counter.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
int j
Definition: DBlmapReader.cc:9
int m_fileEventOffset
Number of events to be offset wrt input.
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual void produce(edm::Event &, const edm::EventSetup &)
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:22
std::vector< L1CaloRegion > L1CaloRegionCollection
std::ifstream m_file[18]
file handle