CMS 3D CMS Logo

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