CMS 3D CMS Logo

GctFibreAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: GctFibreAnalyzer
4 // Class: GctFibreAnalyzer
5 //
11 //
12 // Original Author: Alex Tapper
13 // Created: Thu Jul 12 14:21:06 CEST 2007
14 //
15 //
16 
18 #include "FWCore/Utilities/interface/Exception.h" // Exceptions
19 
20 // Include file
22 
23 // Data format
25 
27  m_fibreSource(iConfig.getUntrackedParameter<edm::InputTag>("FibreSource")),
28  m_doLogicalID(iConfig.getUntrackedParameter<bool>("doLogicalID")),
29  m_doCounter(iConfig.getUntrackedParameter<bool>("doCounter")),
30  m_numZeroEvents(0),
31  m_numInconsistentPayloadEvents(0),
32  m_numConsistentEvents(0)
33 {
34 }
35 
37 {
38  edm::LogInfo("Zero Fibreword events") << "Total number of events with zero fibrewords: " << m_numZeroEvents;
39  edm::LogInfo("Inconsistent Payload events") << "Total number of events with inconsistent payloads: " << m_numInconsistentPayloadEvents;
40  if(m_doCounter){edm::LogInfo("Successful events") << "Total number of Successful events: " << m_numConsistentEvents;}
41 }
42 
44 {
45  using namespace edm;
46 
48  iEvent.getByLabel(m_fibreSource,fibre);
49 
50  bool bc0= false;
51  int flag_for_zeroes = 0;
52  int flag_for_inconsistent_events = 0;
53  unsigned int flag_for_consistency = 0;
54  int flag_for_consistent_events = 0;
55 
56  for (L1GctFibreCollection::const_iterator f=fibre->begin(); f!=fibre->end(); f++){
57 
58  if (f->data()!=0)
59  {
60  if(m_doCounter)
61  {
62  if(f==fibre->begin()) {flag_for_consistency = f->data();}
63  else if(flag_for_consistency == f->data()){flag_for_consistent_events++;}
64  }
65 
66  // Check for corrupt fibre data
67  if (!CheckFibreWord(*f)){
68  edm::LogInfo("GCT fibre data error") << "Missing phase bit (clock) in fibre data " << (*f);
69  }
70 
71  // Check for BC0
72  if (CheckForBC0(*f) && (f==fibre->begin())) {
73  bc0=true;
74  }
75 
76  // Check for mismatch between fibres
77  if ((bc0 && !CheckForBC0(*f)) ||
78  (!bc0 && CheckForBC0(*f))){
79  edm::LogInfo("GCT fibre data error") << "BC0 mismatch in fibre data " << (*f);
80  }
81 
82  // Check logical ID pattern
84 
85  // Check counter pattern
86  if (m_doCounter) CheckCounter(*f);
87 
88  flag_for_zeroes = 1;
89  }
90  else
91  {
92  //this basically checks that all the data is 0s by the time it gets to the last iteration
93  if(flag_for_zeroes == 0 && f==(fibre->end()-1)) {m_numZeroEvents++;}
94  //if the zero flag is set to 1 and it managed to find its way into here then something is wrong!
95  if(flag_for_zeroes == 1) {flag_for_inconsistent_events++;}
96  }
97 
98  }
99  //check for inconsistent events i.e. those with one(or more) zeroes, and the rest data
100  if(flag_for_inconsistent_events != 0) {m_numInconsistentPayloadEvents++;}
101  //check for consistent events with the counter
102  if(m_doCounter && flag_for_consistent_events != 0) {m_numConsistentEvents++;}
103 }
104 
106 {
107  // Check for BC0 on this event
108  if (fibre.data() & 0x8000){
109  return true;
110  } else {
111  return false;
112  }
113 }
114 
116 {
117  // Check that the phase or clock bit (MSB bit on cycle 1) is set as it should be
118  if (fibre.data() & 0x80000000){
119  return true;
120  } else {
121  return false;
122  }
123 }
124 
126 {
127  // Remove MSB from both cycles
128  int cycle0Data, cycle1Data;
129 
130  cycle0Data = fibre.data() & 0x7FFF;
131  cycle1Data = (fibre.data() >> 16) & 0x7FFF;
132 
133  // Check to see if fibre numbers are consistent
134  if ((cycle0Data+1)!=cycle1Data){
135  edm::LogInfo("GCT fibre data error") << "Fibre data not incrementing in cycles 0 and 1 "
136  << " Cycle 0 data=" << cycle0Data
137  << " Cycle 1 data=" << cycle1Data
138  << " " << fibre;
139  }
140 
141  // For now just write out the data
142  edm::LogInfo("GCT fibre counter data") << " Fibre data: cycle0=" << cycle0Data
143  << " cycle1=" << cycle1Data
144  << " " << fibre;
145 }
146 
148 {
149  //added by Jad Marrouche, May 08
150 
151  unsigned ref_jf_link[] = {1,2,3,4,1,2,3,4};
152  //this array lists the link number ordering we expect from the 3 JFs in positive eta
153  //below, we modify indices 2 and 3 from 3,4 to 1,2 to represent negative eta
154 
155  unsigned ref_eta0_link[] = {3,4,3,4,3,4};
156  //this array lists the link number ordering we expect from the ETA0
157 
158  unsigned ref_jf_type[] = {2,2,3,3,1,1,1,1};
159  //this array lists the SC_type ordering we expect for the JFs
160 
161  unsigned ref_eta0_type[] = {2,2,2,2,2,2};
162  //this array lists the SC_type ordering we expect for the ETA0 (for consistency)
163 
164  int eta_region, rct_phi_region, leaf_phi_region, jf_type, elec_type, local_source_card_id, source_card_id_read, source_card_id_expected;
165 
166  // Check that data in cycle 0 and cycle 1 are equal
167  if ((fibre.data()&0x7FFF)!=((fibre.data()&0x7FFF0000)>>16)){
168  edm::LogInfo("GCT fibre data error") << "Fibre data different on cycles 0 and 1 " << fibre;
169  }
170 
171  //fibre.block() gives 0x90c etc
172  //fibre.index() runs from 0 to 6/8
173 
174  if((fibre.block() >> 10) & 0x1 )
175  {
176  eta_region = 0; //negative eta region
177  ref_jf_link[2] = 1; //modify indices to represent neg_eta fibre mapping
178  ref_jf_link[3] = 2;
179  }
180  else eta_region = 1; //positive eta region
181 
182  if(((fibre.block() >> 8) & 0x7) == 0 || ((fibre.block() >> 8) & 0x7) == 4) //i.e. electron leaf cards
183  {
184 
185  if((fibre.block() & 0xFF)==0x04) elec_type=1;
186  else if((fibre.block() & 0xFF)==0x84) elec_type=0;
187  else throw cms::Exception("Unknown GCT fibre data block ") << fibre.block(); //else something screwed up
188 
189  rct_phi_region = (fibre.index() / 3) + (4*elec_type);
190 
191  local_source_card_id = (4*eta_region);
192 
193  source_card_id_expected = (8 * rct_phi_region) + local_source_card_id;
194 
195  source_card_id_read = (fibre.data() >> 8) & 0x7F;
196 
197  if(source_card_id_expected != source_card_id_read )
198  {
199  edm::LogInfo("GCT fibre data error") << "Electron Source Card IDs do not match "
200  << "Expected ID = " << source_card_id_expected
201  << " ID read from data = " << source_card_id_read
202  << " " << fibre; //screwed up
203  }
204 
205  if( (fibre.data() & 0xFF) != (unsigned int)(2 + fibre.index()%3))
206  {
207  edm::LogInfo("GCT fibre data error") << "Electron Fibres do not match "
208  << "Expected Fibre = " << (2 + fibre.index()%3)
209  << " Fibre read from data = " << (fibre.data() & 0xFF)
210  << " " << fibre; //screwed up
211  }
212 
213 
214  }
215  else //i.e. jet leaf cards
216  {
217  //the reason we use these values for eta_region is so it is easy to add 4 to the local source card ID
218  //remember that 0x9.. 0xA.. and 0xB.. are +ve eta block headers
219  //whereas 0xD.., 0xE.. and 0xF.. are -ve eta
220  //can distinguish between them using the above mask and shift
221 
222  if((fibre.block() & 0xFF)==0x04) jf_type=1; //JF2
223  else if((fibre.block() & 0xFF)==0x0C) jf_type=2; //JF3
224  else if((fibre.block() & 0xFF)==0x84) jf_type=-1; //ETA0
225  else if((fibre.block() & 0xFF)==0x8C) jf_type=0; //JF1
226  else throw cms::Exception("Unknown GCT fibre data block ") << fibre.block(); //else something screwed up
227 
228  //edm::LogInfo("JF Type Info") << "JF TYPE = " << jf_type << " block = " << fibre; //INFO ONLY
229 
230  leaf_phi_region = ((fibre.block() >> 8) & 0x7)-1; //0,1,2,3,4,5 for leaf cards
231  if(eta_region == 0) leaf_phi_region--; //need to do this because block index goes 9.. A.. B.. D.. E.. F.. - 8 and C are reserved for electron leafs which are dealt with above
232  if(leaf_phi_region <0 || leaf_phi_region >5) throw cms::Exception("Unknown Leaf Card ") << fibre.block();
233  //throw exception if number is outside 0-5 which means something screwed up
234  //if(leaf_phi_region <0 || leaf_phi_region >5) edm::LogInfo("GCT fibre data error") << "Unknown leaf card " << fibre;
235  //write to logger if number is outside 0-5 which means something screwed up
236 
237  if(jf_type == -1)
238  {
239  //in this case fibre.index() runs from 0-5
240  //JF1 comes first, followed by JF2 and JF3
241 
242  if(fibre.index() <=5 ) //the compiler warning is because fibre.index() is unsigned int and hence is always >=0
243  {
244  rct_phi_region = ( (8 + ((leaf_phi_region%3)*3) + (fibre.index() / 2) ) % 9);
245  //fibre.index()/2 will give 0 for 0,1 1 for 2,3 and 2 for 4,5
246 
247  //local_source_card_id = ref_eta0_type[ fibre.index() ] + (4 * (1 % eta_region));
248  //take the ones complement of the eta_region because this is the shared part (i.e. other eta0 region)
249  //this is done by (1 % eta_region) since 1%0 = 1 and 1%1=0
250  //FLAWED - since 1%0 is a floating point exception you idiot!
251 
252  local_source_card_id = ref_eta0_type[ fibre.index() ] + (4 + (eta_region * -4));
253  //this gives what you want - adds 4 when eta_region = 0 (neg) and adds 0 when eta_region = 1 (pos)
254 
255  source_card_id_expected = (8 * rct_phi_region) + local_source_card_id;
256  //from GCT_refdoc_v2_2.pdf
257 
258  source_card_id_read = (fibre.data() >> 8) & 0x7F;
259 
260  if(source_card_id_expected != source_card_id_read )
261  {
262  edm::LogInfo("GCT fibre data error") << "ETA0 Source Card IDs do not match "
263  << "Expected ID = " << source_card_id_expected
264  << " ID read from data = " << source_card_id_read
265  << " " << fibre; //screwed up
266  }
267 
268  if( (fibre.data() & 0xFF) != ref_eta0_link[fibre.index()])
269  {
270  edm::LogInfo("GCT fibre data error") << "ETA0 Fibres do not match "
271  << "Expected Fibre = " << ref_eta0_link[fibre.index()]
272  << " Fibre read from data = " << (fibre.data() & 0xFF)
273  << " " << fibre; //screwed up
274  }
275  }
276  else edm::LogInfo("GCT fibre data error") << "ETA0 Fibre index out of bounds " << fibre;
277  //edm::LogInfo("Fibre Index Info") << "ETA0 Fibre index = " << fibre.index();
278  }
279 
280 
281  if(jf_type >=0)
282  {
283  if(fibre.index() <=7 )
284  {
285  rct_phi_region = ( (8 + ((leaf_phi_region%3)*3) + jf_type ) % 9); //see table below
286 
287  /*
288  Leaf Card | RCT crate | Jet Finder
289  ___________________________________________
290  LC3 | LC0 | 17 | 8 | JF1
291  | | 9 | 0 | JF2
292  | | 10 | 1 | JF3
293  ___________________________________________
294  LC4 | LC1 | 11 | 2 | JF1
295  | | 12 | 3 | JF2
296  | | 13 | 4 | JF3
297  ___________________________________________
298  LC5 | LC2 | 14 | 5 | JF1
299  | | 15 | 6 | JF2
300  | | 16 | 7 | JF3
301  ___________________________________________
302  The phase results in the 17/8 being at the top
303  This can be adjusted as necessary by changing
304  the number 8 added before modulo 9 operation
305  */
306 
307  local_source_card_id = ref_jf_type[ fibre.index() ] + (4 * eta_region);
308 
309  //since the SC sharing scheme renumbers SC 7 as SC3:
310  if(local_source_card_id == 7) local_source_card_id = 3;
311  //there is probably a more elegant way to do this
312 
313  source_card_id_expected = (8 * rct_phi_region) + local_source_card_id;
314 
315  source_card_id_read = (fibre.data() >> 8) & 0x7F;
316 
317  if(source_card_id_expected != source_card_id_read )
318  {
319  edm::LogInfo("GCT fibre data error") << "Source Card IDs do not match "
320  << "Expected ID = " << source_card_id_expected
321  << " ID read from data = " << source_card_id_read
322  << " " << fibre; //screwed up
323  }
324 
325  if( (fibre.data() & 0xFF) != ref_jf_link[fibre.index()])
326  {
327  edm::LogInfo("GCT fibre data error") << "Fibres do not match "
328  << "Expected Fibre = " << ref_jf_link[fibre.index()]
329  << " Fibre read from data = " << (fibre.data() & 0xFF)
330  << " " << fibre; //screwed up
331  }
332  }
333  else edm::LogInfo("GCT fibre data error") << "Fibre index out of bounds " << fibre;
334  }
335 
336  }
337 
338 
339 }
Global Calorimeter Trigger SC -> CC fibre data word.
uint16_t index() const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
unsigned int m_numConsistentEvents
bool CheckFibreWord(const L1GctFibreWord fibre)
int iEvent
Definition: GenABIO.cc:230
unsigned int m_numZeroEvents
double f[11][100]
void CheckLogicalID(const L1GctFibreWord fibre)
uint32_t data() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:464
uint16_t block() const
edm::InputTag m_fibreSource
bool CheckForBC0(const L1GctFibreWord fibre)
GctFibreAnalyzer(const edm::ParameterSet &)
HLT enums.
void CheckCounter(const L1GctFibreWord fibre)
unsigned int m_numInconsistentPayloadEvents