test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RctDigiToRctText.cc
Go to the documentation of this file.
1 
2 #include "RctDigiToRctText.h"
3 #include <iomanip>
4 
5 using std::setw;
6 using std::setfill;
7 using std::hex;
8 using std::dec;
9 using std::endl;
10 
11 
13  m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
14  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
15  m_hexUpperCase(iConfig.getParameter<bool>("HexUpperCase")) {
16 
18  for (unsigned i=0; i<NUM_RCT_CRATES; i++){
19  std::stringstream fileStream;
20  fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i << ".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 }
35 
36 
39  for (unsigned i=0; i<NUM_RCT_CRATES; i++)
40  m_file[i].close();
41  fdebug.close();
42 }
43 
44 
45 void
47 
49  static int nevt = -1;
50  nevt++;
51 
55  iEvent.getByLabel(m_rctInputLabel, em);
56  iEvent.getByLabel(m_rctInputLabel, rgn);
57 
59  bool ldebug = false;
60  bool debug_NOTEMPTY[18]={0};
61  for(int i=0; i<18; i++) debug_NOTEMPTY[i]=false;
62  std::stringstream dstrm;
63 
64 
66 
67  unsigned long int CAND[18][8];
68  int n_iso [18]={0};
69  int n_niso[18]={0};
70  bool iso;
71  int id;
72 
73  for(L1CaloEmCollection::const_iterator iem=em->begin(); iem!=em->end(); iem++){
74 
75  int crate = iem->rctCrate();
76  iso = iem->isolated();
77  unsigned data = iem->raw();
78 
79  id = iso ? n_iso[crate]++ : 4 + n_niso[crate]++;
80 
81  CAND[crate][id] = data;
82 
84  if(crate>17 || id > 7)
85  throw cms::Exception("RctDigiToRctTextElectronIndexOutBounds")
86  << "out of bounds indices crate:" << crate << "id:" << id << std::endl;
87  if(ldebug&&data!=0)
88  debug_NOTEMPTY[crate] = true;
89  dstrm.str("");
90  dstrm << "electron "
91  << " bx:" << nevt
92  << " crate:" << crate
93  << " iso:" << iso
94  << " raw:" << data
95  << " \t cand:" << *iem;
96  if(debug_NOTEMPTY[crate]) fdebug << dstrm.str() << std::endl;
97  }
98 
99 
101 
102  unsigned short MIPbits [18][7][2] = {{{0}}};
103  unsigned short QIEbits [18][7][2] = {{{0}}};
104  unsigned short RC [18][7][2] = {{{0}}};
105  unsigned short RCof [18][7][2] = {{{0}}};
106  unsigned short RCtau [18][7][2] = {{{0}}};
107  unsigned short HF [18][4][2] = {{{0}}};
108 
109  for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
110 
111  int crate = irgn->rctCrate();
112  int card = irgn->rctCard();
113  int rgnidx= irgn->rctRegionIndex();
114 
115  dstrm.str("");
116  if (!irgn->id().isHf()){
117  RC [crate][card][rgnidx]=irgn->et();
118  RCof [crate][card][rgnidx]=irgn->overFlow();
119  RCtau [crate][card][rgnidx]=irgn->tauVeto();
120  MIPbits[crate][card][rgnidx]=irgn->mip();
121  QIEbits[crate][card][rgnidx]=irgn->quiet();
122  // debug info
123  dstrm << hex
124  << "Et=" << irgn->et()
125  << " OverFlow=" << irgn->overFlow()
126  << " tauVeto=" << irgn->tauVeto()
127  << " mip=" << irgn->mip()
128  << " quiet=" << irgn->quiet()
129  << " Card=" << irgn->rctCard()
130  << " Region=" << irgn->rctRegionIndex()
131  << " Crate=" << irgn->rctCrate()
132  << dec;
133  if(ldebug) LogDebug("Regions") << dstrm.str();
134  } else {
135  HF [crate][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->et();
136  // debug info
137  dstrm << hex
138  << "Et=" << irgn->et()
139  << " FGrain=" << irgn->fineGrain()
140  << " Eta=" << irgn->id().rctEta()
141  << " Phi=" << irgn->id().rctPhi()
142  << " Crate=" << irgn->rctCrate()
143  << dec;
144  if(ldebug) LogDebug("HFRegions") << dstrm.str();
145  }
146 
147 
148  if(ldebug &&irgn->et()!=0) debug_NOTEMPTY[crate] = true; //debug
149  if(debug_NOTEMPTY[crate]) {
150  fdebug << "region"
151  << " bx:" << nevt
152  << " crate:" << crate
153  << "\t";
154  fdebug << dstrm.str() << std::endl;
155  }
156  }
157 
158 
159  std::stringstream sstrm;
160  if(m_hexUpperCase)
161  sstrm << std::uppercase;
162  else
163  sstrm.unsetf(std::ios::uppercase);
164 
165 
167 
168  for (unsigned crate=0; crate<NUM_RCT_CRATES; crate++){
169 
170  sstrm.str("");
171  sstrm << "Crossing " << nevt << std::endl;
172 
173  for(int j=0; j<8; j++) {
174  sstrm << setw(3) << setfill('0') << hex << (CAND[crate][j] & 0x3ff);
175  if(j<7) sstrm << " ";
176  }
177  sstrm << setfill(' ') << dec;
178  m_file[crate] << sstrm.str() << std::endl;
179 
180  // debug
181  if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl;
182  if(ldebug) LogDebug("Electrons") << sstrm.str() << std::endl;
183 
184  }
185 
186 
188 
189  for (unsigned crate=0; crate<NUM_RCT_CRATES; crate++){
190 
192  sstrm.str("");
193  for (int card=0; card<7; card++){
194  for (int j=0; j<2; j++){
195  sstrm << " " << MIPbits[crate][card][j];
196  }
197  }
198  m_file[crate] << sstrm.str() << std::endl;
199  if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl; //debug
200 
202  sstrm.str("");
203  for (int card=0; card<7; card++){
204  for (int j=0; j<2; j++){
205  sstrm << " " << QIEbits[crate][card][j];
206  }
207  }
208  m_file[crate] << sstrm.str() << std::endl;
209  if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl; //debug
210 
212  sstrm.str("");
213  for (int card=0; card<7; card++){
214  for (int j=0; j<2; j++){
215  unsigned long int tmp;
216  unsigned et = RC [crate][card][j];
217  unsigned ovf = RCof [crate][card][j];
218  unsigned tau = RCtau[crate][card][j];
219  //ovf = ovf || (et>=0x400);
220  tmp = ((tau & 0x1) << 11) | ((ovf &0x1)<<10) | ((et & 0x3ff));
221  sstrm << " " << setw(3) << setfill('0') << hex << tmp;
222 
223  }
224  }
225  m_file[crate] << sstrm.str() << std::endl;
226  if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl << std::endl; //debug
227 
228 
230  sstrm.str("");
231  for (int ip=0; ip<2; ip++){
232  for (int ie=0; ie<4; ie++){
233  unsigned et = HF[crate][ie][ip] & 0xff;
234  sstrm << " " << setw(2) << setfill('0') << hex << et;
235  }
236  }
237  m_file[crate] << sstrm.str() << std::endl;
238  if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl; //debug
239  sstrm << setfill(' ') << dec;
240 
241  }// end crate loop
242 
243 
245  for (unsigned i=0; i<NUM_RCT_CRATES; i++)
246  m_file[i] << std::flush;
247 
248  fdebug << std::flush;
249 
250 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
static const unsigned NUM_RCT_CRATES
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool m_hexUpperCase
write upper case hex words
edm::InputTag m_rctInputLabel
label for RCT digis
int iEvent
Definition: GenABIO.cc:230
int j
Definition: DBlmapReader.cc:9
std::ofstream m_file[NUM_RCT_CRATES]
handles for output files
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
tuple out
Definition: dbtoconf.py:99
RctDigiToRctText(const edm::ParameterSet &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::string m_textFileName
basename for output files
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::ofstream fdebug
handle for debug file