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 << ".txt";
58  std::string fileName(fileStream.str());
59  m_file[i].open(fileName.c_str(), std::ios::in);
60 
61  if (!m_file[i].good()) {
62  // throw cms::Exception("RctTextToRctDigiTextFileOpenError")
63  LogDebug("RctTextToRctDigi") << "RctTextToRctDigi::RctTextToRctDigi : "
64  << " couldn't open the file " << fileName << "...skipping!" << std::endl;
65  }
66  }
67 }
68 
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::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
79  std::unique_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(std::move(em));
91  iEvent.put(std::move(rgn));
92 }
93 
95 void RctTextToRctDigi::bxSynchro(int &bx, int crate) {
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  // Skip event if required
113  if (m_nevt < m_fileEventOffset) {
114  // string tmp;
115  // for (int i=0; i<6; i++){
116  // getline(m_file[i],tmp);
117  //}
119  m_nevt++;
120  return;
121  }
122 
123  // New collections
124  std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
125  std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
126 
127  // Loop over RCT crates
128  for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
129  if (!m_file[i].good()) {
130  continue;
131  }
132 
133  // Check we're not at the end of the file
134  if (m_file[i].eof()) {
135  // throw cms::Exception("RctTextToRctDigiTextFileReadError")
136  LogDebug("RctTextToRctDigi") << "RctTextToRctDigi::produce : "
137  << " unexpected end of file " << m_textFileName << i
138  << " adding empty collection for event !" << std::endl;
140  continue;
141  }
142 
143  // Check we're at the start of an event
145  m_file[i] >> tmp;
146  if (tmp != "Crossing") {
147  throw cms::Exception("RctTextToRctDigiTextFileReadError")
148  << "RctTextToRctDigi::produce : "
149  << " something screwy happened Crossing!=" << tmp << std::endl;
150  }
151 
152  // Read BX number
153  dec(m_file[i]);
154  int BXNum;
155  m_file[i] >> BXNum;
156 
158  bxSynchro(BXNum, i);
159 
160  if (BXNum != m_nevt + m_fileEventOffset)
161  throw cms::Exception("RctTextToRctDigiTextSyncError")
162  << "RctTextToRctDigi::produce : "
163  << " something screwy happened "
164  << "evt:" << m_nevt << " != bx:" << BXNum << " + " << m_fileEventOffset << std::endl;
165 
166  // Buffers
167  unsigned long int uLongBuffer;
168  bool mipBitBuffer[14], qBitBuffer[14];
169 
170  // All in hex from now on
171  hex(m_file[i]);
172 
173  // Isolated electrons
174  for (unsigned j = 0; j < 4; j++) {
175  m_file[i] >> uLongBuffer;
176  em->push_back(L1CaloEmCand(uLongBuffer, i, true, j, BXNum, false));
177  }
178 
179  // Non-isolated electrons
180  for (unsigned j = 0; j < 4; j++) {
181  m_file[i] >> uLongBuffer;
182  em->push_back(L1CaloEmCand(uLongBuffer, i, false, j, BXNum, false));
183  }
184 
185  // MIP bits
186  for (unsigned j = 0; j < 14; j++) {
187  m_file[i] >> mipBitBuffer[j];
188  }
189 
190  // Quiet bits
191  for (unsigned j = 0; j < 14; j++) {
192  m_file[i] >> qBitBuffer[j];
193  }
194 
195  // Barrel and endcap regions
196  for (unsigned j = 0; j < 14; j++) {
197  m_file[i] >> uLongBuffer;
198 
199  unsigned et = uLongBuffer & 0x3ff; // put the first 10 bits of rawData into the Et
200  uLongBuffer >>= 10; // shift the remaining bits down to remove the 10 bits of Et
201 
202  bool overFlow = ((uLongBuffer & 0x1) != 0); // LSB is now overflow bit
203  bool tauVeto = (((uLongBuffer & 0x2) >> 1) != 0); // 2nd bit is tauveto
204 
205  rgn->push_back(L1CaloRegion(et, overFlow, tauVeto, mipBitBuffer[j], qBitBuffer[j], i, j / 2, j % 2));
206  }
207 
208  // HF
209  for (unsigned j = 0; j < 8; j++) {
210  m_file[i] >> uLongBuffer;
211 
212  unsigned et = uLongBuffer & 0xff; // put the first 8 bits into the Et
213 
214  rgn->push_back(L1CaloRegion(et, true, i, j));
215  }
216 
217  dec(m_file[i]);
218  }
219 
220  iEvent.put(std::move(em));
221  iEvent.put(std::move(rgn));
222 
223  m_nevt++;
224 }
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
RctTextToRctDigi.h
L1CaloRegion
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
NUM_RCT_CRATES
const static unsigned NUM_RCT_CRATES
Definition: RctTextToRctDigi.cc:44
edm
HLT enums.
Definition: AlignableModifier.h:19
RctTextToRctDigi::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: RctTextToRctDigi.cc:111
RctTextToRctDigi::m_textFileName
std::string m_textFileName
Name out input file.
Definition: RctTextToRctDigi.h:54
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
RctTextToRctDigi::RctTextToRctDigi
RctTextToRctDigi(const edm::ParameterSet &)
Definition: RctTextToRctDigi.cc:46
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
L1CaloEmCollection
std::vector< L1CaloEmCand > L1CaloEmCollection
Definition: L1CaloCollections.h:10
Service.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
RctTextToRctDigi::m_fileEventOffset
int m_fileEventOffset
Number of events to be offset wrt input.
Definition: RctTextToRctDigi.h:57
recoMuon::in
Definition: RecoMuonEnumerators.h:6
RctTextToRctDigi::m_nevt
int m_nevt
Event counter.
Definition: RctTextToRctDigi.h:60
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
RctTextToRctDigi::putEmptyDigi
void putEmptyDigi(edm::Event &)
Create empty digi collection.
Definition: RctTextToRctDigi.cc:77
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
edm::EventSetup
Definition: EventSetup.h:57
RctTextToRctDigi::bxSynchro
void bxSynchro(int &, int)
Synchronize bunch crossing.
Definition: RctTextToRctDigi.cc:95
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
L1CaloRegionCollection
std::vector< L1CaloRegion > L1CaloRegionCollection
Definition: L1CaloCollections.h:11
RctTextToRctDigi::m_file
std::ifstream m_file[18]
file handle
Definition: RctTextToRctDigi.h:63
Exception
Definition: hltDiff.cc:246
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
L1CaloEmCand
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:17
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
RctTextToRctDigi::~RctTextToRctDigi
~RctTextToRctDigi() override
Definition: RctTextToRctDigi.cc:69