CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCDigiValidator.cc
Go to the documentation of this file.
1 
4 // Original Author: Lindsey Gray
5 // Created: Tue Jul 28 18:04:11 CEST 2009
6 
7 #include <memory>
8 #include <string>
9 #include <map>
10 #include <vector>
11 #include <algorithm>
12 #include <iostream>
13 
24 
36 
38 
39 class CSCWireDigi;
40 class CSCStripDigi;
41 class CSCComparatorDigi;
42 class CSCCLCTDigi;
43 class CSCALCTDigi;
45 class CSCDetId;
46 class CSCChamberMap;
47 
49 public:
50  explicit CSCDigiValidator(const edm::ParameterSet&);
51  ~CSCDigiValidator() override;
52 
53 private:
54  void beginJob() override;
55  bool filter(edm::Event&, const edm::EventSetup&) override;
56  void endJob() override;
57 
58  std::vector<CSCWireDigi> sanitizeWireDigis(std::vector<CSCWireDigi>::const_iterator,
59  std::vector<CSCWireDigi>::const_iterator);
60  std::vector<CSCStripDigi> relabelStripDigis(const CSCChamberMap*,
61  CSCDetId,
62  std::vector<CSCStripDigi>::const_iterator,
63  std::vector<CSCStripDigi>::const_iterator);
64  std::vector<CSCStripDigi> sanitizeStripDigis(std::vector<CSCStripDigi>::const_iterator,
65  std::vector<CSCStripDigi>::const_iterator);
66  std::vector<CSCStripDigi> zeroSupStripDigis(std::vector<CSCStripDigi>::const_iterator,
67  std::vector<CSCStripDigi>::const_iterator);
68  std::vector<CSCComparatorDigi> relabelCompDigis(const CSCChamberMap* m,
69  CSCDetId _id,
70  std::vector<CSCComparatorDigi>::const_iterator b,
71  std::vector<CSCComparatorDigi>::const_iterator e);
72  std::vector<CSCComparatorDigi> zeroSupCompDigis(std::vector<CSCComparatorDigi>::const_iterator,
73  std::vector<CSCComparatorDigi>::const_iterator);
74 
75  // ----------member data ---------------------------
78 
87 
97 };
98 
100  wd1_token = consumes<CSCWireDigiCollection>(iConfig.getParameter<edm::InputTag>("inputWire"));
101  wd2_token = consumes<CSCWireDigiCollection>(iConfig.getParameter<edm::InputTag>("repackWire"));
102  sd1_token = consumes<CSCStripDigiCollection>(iConfig.getParameter<edm::InputTag>("inputStrip"));
103  sd2_token = consumes<CSCStripDigiCollection>(iConfig.getParameter<edm::InputTag>("inputStrip"));
104  cd1_token = consumes<CSCComparatorDigiCollection>(iConfig.getParameter<edm::InputTag>("inputComp"));
105  cd2_token = consumes<CSCComparatorDigiCollection>(iConfig.getParameter<edm::InputTag>("RepackComp"));
106  al1_token = consumes<CSCALCTDigiCollection>(iConfig.getParameter<edm::InputTag>("inputALCT"));
107  al2_token = consumes<CSCALCTDigiCollection>(iConfig.getParameter<edm::InputTag>("repackALCT"));
108  cl1_token = consumes<CSCCLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("inputCLCT"));
109  cl2_token = consumes<CSCCLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("repackCLCT"));
110  co1_token = consumes<CSCCorrelatedLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("inputCorrLCT"));
111  co2_token = consumes<CSCCorrelatedLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("repackCorrLCT"));
112  tr1_token = consumes<L1CSCTrackCollection>(iConfig.getParameter<edm::InputTag>("inputCSCTF"));
113  tr2_token = consumes<L1CSCTrackCollection>(iConfig.getParameter<edm::InputTag>("repackCSCTF"));
114  ts1_token = consumes<CSCTriggerContainer<csctf::TrackStub> >(iConfig.getParameter<edm::InputTag>("inputCSCTFStubs"));
115  ts2_token = consumes<CSCTriggerContainer<csctf::TrackStub> >(iConfig.getParameter<edm::InputTag>("repackCSCTFStubs"));
116  cham_token = esConsumes<CSCChamberMap, CSCChamberMapRcd>();
117 }
118 
120 
122  bool _err = false;
123  using namespace edm;
124 
125  typedef std::map<CSCDetId, std::pair<std::vector<CSCWireDigi>, std::vector<CSCWireDigi> > > matchingDetWireCollection;
126  typedef std::map<CSCDetId, std::pair<std::vector<CSCStripDigi>, std::vector<CSCStripDigi> > >
127  matchingDetStripCollection;
128  typedef std::map<CSCDetId, std::pair<std::vector<CSCComparatorDigi>, std::vector<CSCComparatorDigi> > >
129  matchingDetComparatorCollection;
130  typedef std::map<CSCDetId, std::pair<std::vector<CSCCLCTDigi>, std::vector<CSCCLCTDigi> > > matchingDetCLCTCollection;
131  typedef std::map<CSCDetId, std::pair<std::vector<CSCALCTDigi>, std::vector<CSCALCTDigi> > > matchingDetALCTCollection;
132  typedef std::map<CSCDetId, std::pair<std::vector<CSCCorrelatedLCTDigi>, std::vector<CSCCorrelatedLCTDigi> > >
133  matchingDetLCTCollection;
134 
136  const CSCChamberMap* theMapping = hcham.product();
137 
141  Handle<CSCCLCTDigiCollection> _clct, _sclct;
142  Handle<CSCALCTDigiCollection> _alct, _salct;
144  Handle<L1CSCTrackCollection> _trk, _strk;
146 
147  // get wire digis before and after unpacking
148  iEvent.getByToken(wd1_token, _swi);
149  iEvent.getByToken(wd2_token, _wi);
150 
151  //get strip digis before and after unpacking
152  iEvent.getByToken(sd1_token, _sst);
153  iEvent.getByToken(sd2_token, _st);
154 
155  //get comparator digis before and after unpacking
156  iEvent.getByToken(co1_token, _scmp);
157  iEvent.getByToken(co2_token, _cmp);
158 
159  //get clcts
160  iEvent.getByToken(cl1_token, _sclct);
161  iEvent.getByToken(cl2_token, _clct);
162 
163  //get alcts
164  iEvent.getByToken(al1_token, _salct);
165  iEvent.getByToken(al2_token, _alct);
166 
167  //get corr lcts
168  iEvent.getByToken(co1_token, _slct);
169  iEvent.getByToken(co2_token, _lct);
170 
171  //get l1 tracks
172  iEvent.getByToken(tr1_token, _strk);
173  iEvent.getByToken(tr2_token, _trk);
174 
175  //get DT stubs for L1 Tracks
176  iEvent.getByToken(ts1_token, _sdt);
177  iEvent.getByToken(ts2_token, _dt);
178 
179  CSCWireDigiCollection::DigiRangeIterator wi = _wi->begin(), swi = _swi->begin();
180  CSCStripDigiCollection::DigiRangeIterator st = _st->begin(), sst = _sst->begin();
181  CSCComparatorDigiCollection::DigiRangeIterator cmp = _cmp->begin(), scmp = _scmp->begin();
182  CSCCLCTDigiCollection::DigiRangeIterator clct = _clct->begin(), sclct = _sclct->begin();
183  CSCALCTDigiCollection::DigiRangeIterator alct = _alct->begin(), salct = _salct->begin();
184  CSCCorrelatedLCTDigiCollection::DigiRangeIterator lct = _lct->begin(), slct = _slct->begin();
185  L1CSCTrackCollection::const_iterator trk = _trk->begin(), strk = _strk->begin();
186 
187  //per detID, create lists of various digi types
188  matchingDetWireCollection wires;
189  matchingDetStripCollection strips;
190  matchingDetComparatorCollection comps;
191  matchingDetCLCTCollection clcts;
192  matchingDetALCTCollection alcts;
193  matchingDetLCTCollection lcts, trackstubs;
195 
196  //wires
197  for (; wi != _wi->end(); ++wi) {
198  CSCWireDigiCollection::const_iterator b = (*wi).second.first, e = (*wi).second.second;
199  std::vector<CSCWireDigi>::iterator beg = wires[(*wi).first].first.end();
200  wires[(*wi).first].first.insert(beg, b, e);
201  }
202  for (; swi != _swi->end(); ++swi) {
203  CSCWireDigiCollection::const_iterator b = (*swi).second.first, e = (*swi).second.second;
204  //convert sim ring 4(ME1/a) to ring 1
205  CSCDetId _id = (*swi).first;
206  if ((*swi).first.ring() == 4)
207  _id = CSCDetId((*swi).first.endcap(), (*swi).first.station(), 1, (*swi).first.chamber(), (*swi).first.layer());
208 
209  std::vector<CSCWireDigi>::iterator beg = wires[_id].second.end();
210 
211  wires[_id].second.insert(beg, b, e);
212  // automatically combine wire digis after each insertion
213  wires[_id].second = sanitizeWireDigis(wires[_id].second.begin(), wires[_id].second.end());
214  }
215 
216  //strips
217  for (; st != _st->end(); ++st) {
218  CSCStripDigiCollection::const_iterator b = (*st).second.first, e = (*st).second.second;
219  std::vector<CSCStripDigi>::iterator beg = strips[(*st).first].first.end();
220 
221  //need to remove strips with no active ADCs
222  std::vector<CSCStripDigi> zs = zeroSupStripDigis(b, e);
223 
224  strips[(*st).first].first.insert(beg, zs.begin(), zs.end());
225  }
226  for (; sst != _sst->end(); ++sst) {
227  CSCStripDigiCollection::const_iterator b = (*sst).second.first, e = (*sst).second.second;
228  // conversion of ring 4->1 not necessary here
229  CSCDetId _id = (*sst).first;
230  //if((*sst).first.ring() == 4)
231  // _id = CSCDetId((*sst).first.endcap(),(*sst).first.station(),
232  // 1, (*sst).first.chamber(),(*sst).first.layer());
233 
234  std::vector<CSCStripDigi>::iterator beg = strips[_id].second.end();
235 
236  std::vector<CSCStripDigi> relab = relabelStripDigis(theMapping, (*sst).first, b, e);
237 
238  strips[_id].second.insert(beg, relab.begin(), relab.end());
239  //strips[_id].second.insert(beg,b,e);
240  }
241 
242  //comparators
243  for (; cmp != _cmp->end(); ++cmp) {
244  CSCComparatorDigiCollection::const_iterator b = (*cmp).second.first, e = (*cmp).second.second;
245  std::vector<CSCComparatorDigi>::iterator beg = comps[(*cmp).first].first.end();
246 
247  comps[(*cmp).first].first.insert(beg, b, e);
248  }
249  for (; scmp != _scmp->end(); ++scmp) {
250  CSCComparatorDigiCollection::const_iterator b = (*scmp).second.first, e = (*scmp).second.second;
251  // convert sim ring 4 (ME1/a) to ring 1
252  CSCDetId _id = (*scmp).first;
253  if ((*scmp).first.ring() == 4)
254  _id =
255  CSCDetId((*scmp).first.endcap(), (*scmp).first.station(), 1, (*scmp).first.chamber(), (*scmp).first.layer());
256 
257  std::vector<CSCComparatorDigi>::iterator beg = comps[_id].second.begin();
258 
259  if ((*scmp).first.ring() == 4)
260  beg = comps[_id].second.end();
261 
262  std::vector<CSCComparatorDigi> zs = zeroSupCompDigis(b, e);
263 
264  std::vector<CSCComparatorDigi> relab = relabelCompDigis(theMapping, (*scmp).first, zs.begin(), zs.end());
265 
266  comps[_id].second.insert(beg, relab.begin(), relab.end());
267  }
268 
269  //CLCTs
270  for (; clct != _clct->end(); ++clct) {
271  CSCCLCTDigiCollection::const_iterator b = (*clct).second.first, e = (*clct).second.second;
272  std::vector<CSCCLCTDigi>::iterator beg = clcts[(*clct).first].first.end();
273 
274  clcts[(*clct).first].first.insert(beg, b, e);
275  }
276  for (; sclct != _sclct->end(); ++sclct) {
277  CSCCLCTDigiCollection::const_iterator b = (*sclct).second.first, e = (*sclct).second.second;
278  // convert sim ring 4 (ME1/a) to ring 1
279  CSCDetId _id = (*sclct).first;
280  if ((*sclct).first.ring() == 4)
281  _id = CSCDetId(
282  (*sclct).first.endcap(), (*sclct).first.station(), 1, (*sclct).first.chamber(), (*sclct).first.layer());
283 
284  std::vector<CSCCLCTDigi>::iterator beg = clcts[_id].second.begin();
285 
286  if ((*sclct).first.ring() == 4)
287  beg = clcts[_id].second.end();
288 
289  clcts[_id].second.insert(beg, b, e);
290  }
291 
292  //ALCTs
293  for (; alct != _alct->end(); ++alct) {
294  CSCALCTDigiCollection::const_iterator b = (*alct).second.first, e = (*alct).second.second;
295  std::vector<CSCALCTDigi>::iterator beg = alcts[(*alct).first].first.end();
296 
297  alcts[(*alct).first].first.insert(beg, b, e);
298  }
299  for (; salct != _salct->end(); ++salct) {
300  CSCALCTDigiCollection::const_iterator b = (*salct).second.first, e = (*salct).second.second;
301  // convert sim ring 4 (ME1/a) to ring 1
302  CSCDetId _id = (*salct).first;
303  if ((*salct).first.ring() == 4)
304  _id = CSCDetId(
305  (*salct).first.endcap(), (*salct).first.station(), 1, (*salct).first.chamber(), (*salct).first.layer());
306 
307  std::vector<CSCALCTDigi>::iterator beg = alcts[_id].second.begin();
308 
309  if ((*salct).first.ring() == 4)
310  beg = alcts[_id].second.end();
311 
312  alcts[_id].second.insert(beg, b, e);
313  }
314 
315  // Correlated LCTs
316  for (; lct != _lct->end(); ++lct) {
317  CSCCorrelatedLCTDigiCollection::const_iterator b = (*lct).second.first, e = (*lct).second.second;
318  std::vector<CSCCorrelatedLCTDigi>::iterator beg = lcts[(*lct).first].first.end();
319 
320  lcts[(*lct).first].first.insert(beg, b, e);
321  }
322  for (; slct != _slct->end(); ++slct) {
323  CSCCorrelatedLCTDigiCollection::const_iterator b = (*slct).second.first, e = (*slct).second.second;
324  // convert sim ring 4 (ME1/a) to ring 1
325  CSCDetId _id = (*slct).first;
326  if ((*slct).first.ring() == 4)
327  _id =
328  CSCDetId((*slct).first.endcap(), (*slct).first.station(), 1, (*slct).first.chamber(), (*slct).first.layer());
329 
330  std::vector<CSCCorrelatedLCTDigi>::iterator beg = lcts[_id].second.begin();
331 
332  if ((*slct).first.ring() == 4)
333  beg = lcts[_id].second.end();
334 
335  lcts[_id].second.insert(beg, b, e);
336  }
337  // remove attached LCT digis from tracks, should be put into their own collection and checked separately
338  for (; trk != _trk->end(); ++trk) {
339  tracks.push_back(trk->first);
340  }
341  for (; strk != _strk->end(); ++strk) {
342  simtracks.push_back(strk->first);
343  }
344 
345  //now loop through each set and process if there are differences!
346  matchingDetWireCollection::const_iterator w;
347  matchingDetStripCollection::const_iterator s;
348  matchingDetComparatorCollection::const_iterator c;
349  matchingDetCLCTCollection::const_iterator cl;
350  matchingDetALCTCollection::const_iterator al;
351  matchingDetLCTCollection::const_iterator lc;
352 
353  for (w = wires.begin(); w != wires.end(); ++w) {
354  if (w->second.first.size() != w->second.second.size()) {
355  std::cout << "Major error! # of wire digis in detID: " << w->first << " is not equal between sim and unpacked!"
356  << std::endl;
357  //eventually do more in this case!
358 
359  std::vector<CSCWireDigi> a = w->second.second;
360  std::vector<CSCWireDigi> b = w->second.first;
361  std::cout << "SIM OUTPUT:" << std::endl;
362  for (std::vector<CSCWireDigi>::const_iterator i = a.begin(); i != a.end(); ++i)
363  i->print();
364  std::cout << "UNPACKER OUTPUT:" << std::endl;
365  for (std::vector<CSCWireDigi>::const_iterator i = b.begin(); i != b.end(); ++i)
366  i->print();
367  }
368  int max = std::min(w->second.first.size(), w->second.second.size());
369  std::vector<CSCWireDigi> cv = w->second.first;
370  std::vector<CSCWireDigi> sv = w->second.second;
371  for (int i = 0; i < max; ++i) {
372  if (sv[i].getWireGroup() != cv[i].getWireGroup()) {
373  std::cout << "In detId: " << w->first << std::endl;
374  std::cout << "Wire Groups do not match: " << sv[i].getWireGroup() << " != " << cv[i].getWireGroup()
375  << std::endl;
376  }
377  if (sv[i].getTimeBin() != cv[i].getTimeBin()) {
378  std::cout << "In detId: " << w->first << std::endl;
379  std::cout << "First Time Bins do not match: " << sv[i].getTimeBin() << " != " << cv[i].getTimeBin()
380  << std::endl;
381  }
382  if (sv[i].getTimeBinWord() != cv[i].getTimeBinWord()) {
383  std::cout << "In detId: " << w->first << std::endl;
384  std::cout << "Time Bin Words do not match: " << sv[i].getTimeBinWord() << " != " << cv[i].getTimeBinWord()
385  << std::endl;
386  }
387  }
388  }
389  for (s = strips.begin(); s != strips.end(); ++s) {
390  if (s->second.first.size() != s->second.second.size()) {
391  std::cout << "Major error! # of strip digis in detID: " << s->first << " is not equal between sim and unpacked!"
392  << std::endl;
393  //eventually do more in this case!
394 
395  std::vector<CSCStripDigi> a = s->second.second;
396  std::vector<CSCStripDigi> b = s->second.first;
397  std::cout << "SIM OUTPUT:" << std::endl;
398  for (std::vector<CSCStripDigi>::const_iterator i = a.begin(); i != a.end(); ++i)
399  i->print();
400  std::cout << "UNPACKER OUTPUT:" << std::endl;
401  for (std::vector<CSCStripDigi>::const_iterator i = b.begin(); i != b.end(); ++i)
402  i->print();
403  }
404  int max = std::min(s->second.first.size(), s->second.second.size());
405  std::vector<CSCStripDigi> cv = s->second.first;
406  std::vector<CSCStripDigi> sv = s->second.second;
407  for (int i = 0; i < max; ++i) {
408  bool me1a = s->first.station() == 1 && s->first.ring() == 4;
409  bool me1b = s->first.station() == 1 && s->first.ring() == 1;
410  bool zplus = s->first.endcap() == 1;
411  int k = i;
412 
413  if (me1a && zplus)
414  k = max - i - 1;
415  if (me1b && !zplus)
416  k = max - i - 1;
417 
418  if (sv[k].getStrip() != cv[i].getStrip()) {
419  std::cout << "In detId: " << s->first << std::endl;
420  std::cout << "Strips do not match: " << sv[k].getStrip() << " != " << cv[i].getStrip() << std::endl;
421  }
422  if (sv[k].getADCCounts().size() != cv[i].getADCCounts().size()) {
423  std::cout << "In detId: " << s->first << std::endl;
424  std::cout << "ADC Readouts not of equal size!" << std::endl;
425  std::cout << sv[k].getADCCounts().size() << ' ' << cv[i].getADCCounts().size() << std::endl;
426  } else {
427  std::vector<int> sADC = sv[k].getADCCounts();
428  std::vector<int> uADC = cv[i].getADCCounts();
429 
430  for (unsigned iadc = 0; iadc < sADC.size(); ++iadc)
431  if (sADC[iadc] != uADC[iadc]) {
432  std::cout << "In detId: " << s->first << std::endl;
433  std::cout << "ADC counts not equal at index: " << iadc << std::endl
434  << std::hex << sADC[iadc] << " != " << uADC[iadc] << std::dec << std::endl;
435  }
436  }
437  if (sv[k].getADCOverflow().size() != cv[i].getADCOverflow().size()) {
438  std::cout << "In detId: " << s->first << std::endl;
439  std::cout << "ADC Overflows not of equal size!" << std::endl;
440  std::cout << sv[k].getADCOverflow().size() << ' ' << cv[i].getADCOverflow().size() << std::endl;
441  } else {
442  std::vector<uint16_t> sADC = sv[k].getADCOverflow();
443  std::vector<uint16_t> uADC = cv[i].getADCOverflow();
444 
445  for (unsigned iadc = 0; iadc < sADC.size(); ++iadc)
446  if (sADC[iadc] != uADC[iadc]) {
447  std::cout << "In detId: " << s->first << std::endl;
448  std::cout << "ADC overflows not equal at index: " << iadc << std::endl
449  << std::hex << sADC[iadc] << " != " << uADC[iadc] << std::dec << std::endl;
450  }
451  }
452  if (sv[k].getOverlappedSample().size() != cv[i].getOverlappedSample().size()) {
453  std::cout << "In detId: " << s->first << std::endl;
454  std::cout << "Overlapped Samples not of equal size!" << std::endl;
455  std::cout << sv[k].getOverlappedSample().size() << ' ' << cv[i].getOverlappedSample().size() << std::endl;
456  } else {
457  std::vector<uint16_t> sADC = sv[k].getOverlappedSample();
458  std::vector<uint16_t> uADC = cv[i].getOverlappedSample();
459 
460  for (unsigned iadc = 0; iadc < sADC.size(); ++iadc)
461  if (sADC[iadc] != uADC[iadc]) {
462  std::cout << "In detId: " << s->first << std::endl;
463  std::cout << "Overlapped Samples not equal at index: " << iadc << std::endl
464  << std::hex << sADC[iadc] << " != " << uADC[iadc] << std::dec << std::endl;
465  }
466  }
467  if (sv[k].getErrorstat().size() != cv[i].getErrorstat().size()) {
468  std::cout << "In detId: " << s->first << std::endl;
469  std::cout << "Errorstat not of equal size!" << std::endl;
470  std::cout << sv[k].getErrorstat().size() << ' ' << cv[i].getErrorstat().size() << std::endl;
471  } else {
472  std::vector<uint16_t> sADC = sv[k].getErrorstat();
473  std::vector<uint16_t> uADC = cv[i].getErrorstat();
474 
475  for (unsigned iadc = 0; iadc < sADC.size(); ++iadc)
476  if (sADC[iadc] != uADC[iadc]) {
477  std::cout << "In detId: " << s->first << std::endl;
478  std::cout << "Errorstat not equal at index: " << iadc << std::endl
479  << std::hex << sADC[iadc] << " != " << uADC[iadc] << std::dec << std::endl;
480  }
481  }
482  if (sv[k].pedestal() != cv[i].pedestal()) {
483  std::cout << "In detId: " << s->first << std::endl;
484  std::cout << "Pedestals not equal: " << sv[k].pedestal() << " != " << cv[i].pedestal() << std::endl;
485  }
486  if (sv[k].amplitude() != cv[i].amplitude()) {
487  std::cout << "In detId: " << s->first << std::endl;
488  std::cout << "Amplitudes not equal: " << sv[k].amplitude() << " != " << cv[i].amplitude() << std::endl;
489  }
490  }
491  }
492  for (c = comps.begin(); c != comps.end(); ++c) {
493  if (c->second.first.size() != c->second.second.size()) {
494  std::cout << "Major error! # of comparator digis in detID: " << c->first
495  << " is not equal between sim and unpacked!" << std::endl;
496  //eventually do more in this case!
497 
498  std::vector<CSCComparatorDigi> a = c->second.second;
499  std::vector<CSCComparatorDigi> b = c->second.first;
500  std::cout << "SIM OUTPUT:" << std::endl;
501  for (std::vector<CSCComparatorDigi>::const_iterator i = a.begin(); i != a.end(); ++i)
502  i->print();
503  std::cout << "UNPACKER OUTPUT:" << std::endl;
504  for (std::vector<CSCComparatorDigi>::const_iterator i = b.begin(); i != b.end(); ++i)
505  i->print();
506  }
507  int max = std::min(c->second.first.size(), c->second.second.size());
508  std::vector<CSCComparatorDigi> cv = c->second.first;
509  std::vector<CSCComparatorDigi> sv = c->second.second;
510  for (int i = 0; i < max; ++i) {
511  if (sv[i].getStrip() != cv[i].getStrip()) {
512  std::cout << "In detId: " << s->first << std::endl;
513  std::cout << "Comparator strips do not match: " << sv[i].getStrip() << " != " << cv[i].getStrip() << std::endl;
514  }
515  if (sv[i].getComparator() != cv[i].getComparator()) {
516  std::cout << "In detId: " << c->first << std::endl;
517  std::cout << "Comparators do not match: " << sv[i].getComparator() << " != " << cv[i].getComparator()
518  << std::endl;
519  }
520  if (sv[i].getTimeBinWord() != cv[i].getTimeBinWord()) {
521  std::cout << "In detId: " << c->first << std::endl;
522  std::cout << "Comparator time bins words do not match: " << sv[i].getTimeBinWord()
523  << " != " << cv[i].getTimeBinWord() << std::endl;
524  }
525  }
526  }
527  for (cl = clcts.begin(); cl != clcts.end(); ++cl) {
528  if (cl->second.first.size() != cl->second.second.size()) {
529  std::cout << "Major error! # of CLCT digis in detID: " << cl->first << " is not equal between sim and unpacked!"
530  << std::endl;
531  //eventually do more in this case!
532 
533  std::vector<CSCCLCTDigi> a = cl->second.second;
534  std::vector<CSCCLCTDigi> b = cl->second.first;
535  std::cout << "SIM OUTPUT:" << std::endl;
536  for (std::vector<CSCCLCTDigi>::const_iterator i = a.begin(); i != a.end(); ++i)
537  i->print();
538  std::cout << "UNPACKER OUTPUT:" << std::endl;
539  for (std::vector<CSCCLCTDigi>::const_iterator i = b.begin(); i != b.end(); ++i)
540  i->print();
541  }
542  int max = std::min(cl->second.first.size(), cl->second.second.size());
543  std::vector<CSCCLCTDigi> cv = cl->second.first;
544  std::vector<CSCCLCTDigi> sv = cl->second.second;
545  for (int i = 0; i < max; ++i) {
546  if (cv[i].getKeyStrip() != sv[i].getKeyStrip()) {
547  std::cout << "In detId: " << cl->first << std::endl;
548  std::cout << "CLCT key strips do not match: " << sv[i].getKeyStrip() << " != " << cv[i].getKeyStrip()
549  << std::endl;
550  }
551  if (cv[i].getStrip() != sv[i].getStrip()) {
552  std::cout << "In detId: " << cl->first << std::endl;
553  std::cout << "CLCT strips do not match: " << sv[i].getStrip() << " != " << cv[i].getStrip() << std::endl;
554  }
555  if (cv[i].isValid() != sv[i].isValid()) {
556  std::cout << "In detId: " << cl->first << std::endl;
557  std::cout << "CLCT Valid bits do not match: " << sv[i].isValid() << " != " << cv[i].isValid() << std::endl;
558  }
559  if (cv[i].getQuality() != sv[i].getQuality()) {
560  std::cout << "In detId: " << cl->first << std::endl;
561  std::cout << "CLCT qualities do not match: " << sv[i].getQuality() << " != " << cv[i].getQuality() << std::endl;
562  }
563  if (cv[i].getPattern() != sv[i].getPattern()) {
564  std::cout << "In detId: " << cl->first << std::endl;
565  std::cout << "CLCT patterns do not match: " << sv[i].getPattern() << " != " << cv[i].getPattern() << std::endl;
566  }
567  if (cv[i].getStripType() != sv[i].getStripType()) {
568  std::cout << "In detId: " << cl->first << std::endl;
569  std::cout << "CLCT strip types do not match: " << sv[i].getStripType() << " != " << cv[i].getStripType()
570  << std::endl;
571  }
572  if (cv[i].getBend() != sv[i].getBend()) {
573  std::cout << "In detId: " << cl->first << std::endl;
574  std::cout << "CLCT bends do not match: " << sv[i].getBend() << " != " << cv[i].getBend() << std::endl;
575  }
576  if (cv[i].getCFEB() != sv[i].getCFEB()) {
577  std::cout << "In detId: " << cl->first << std::endl;
578  std::cout << "CLCT CFEBs do not match: " << sv[i].getCFEB() << " != " << cv[i].getCFEB() << std::endl;
579  }
580  if (((short)cv[i].getBX()) != ((short)sv[i].getBX()) - 4) {
581  std::cout << "In detId: " << cl->first << std::endl;
582  std::cout << "CLCT BX do not match: " << sv[i].getBX() - 4 << " != " << cv[i].getBX() << std::endl;
583  }
584  if (cv[i].getFullBX() != sv[i].getFullBX()) {
585  std::cout << "In detId: " << cl->first << std::endl;
586  std::cout << "CLCT Full BX do not match: " << sv[i].getFullBX() << " != " << cv[i].getFullBX() << std::endl;
587  }
588  if (cv[i].getTrknmb() != sv[i].getTrknmb()) {
589  std::cout << "In detId: " << cl->first << std::endl;
590  std::cout << "CLCT Track numbers do not match: " << sv[i].getTrknmb() << " != " << cv[i].getTrknmb()
591  << std::endl;
592  }
593  }
594  }
595  for (al = alcts.begin(); al != alcts.end(); ++al) {
596  if (al->second.first.size() != al->second.second.size()) {
597  std::cout << "Major error! # of ALCT digis in detID: " << al->first << " is not equal between sim and unpacked!"
598  << std::endl;
599  //eventually do more in this case!
600 
601  std::vector<CSCALCTDigi> a = al->second.second;
602  std::vector<CSCALCTDigi> b = al->second.first;
603  std::cout << "SIM OUTPUT:" << std::endl;
604  for (std::vector<CSCALCTDigi>::const_iterator i = a.begin(); i != a.end(); ++i)
605  i->print();
606  std::cout << "UNPACKER OUTPUT:" << std::endl;
607  for (std::vector<CSCALCTDigi>::const_iterator i = b.begin(); i != b.end(); ++i)
608  i->print();
609  }
610  int max = std::min(al->second.first.size(), al->second.second.size());
611  std::vector<CSCALCTDigi> cv = al->second.first;
612  std::vector<CSCALCTDigi> sv = al->second.second;
613  for (int i = 0; i < max; ++i) {
614  if (cv[i].getKeyWG() != sv[i].getKeyWG()) {
615  std::cout << "In detId: " << al->first << std::endl;
616  std::cout << "ALCT key wire groups do not match: " << sv[i].getKeyWG() << " != " << cv[i].getKeyWG()
617  << std::endl;
618  }
619  if (cv[i].isValid() != sv[i].isValid()) {
620  std::cout << "In detId: " << al->first << std::endl;
621  std::cout << "ALCT Valid bits do not match: " << sv[i].isValid() << " != " << cv[i].isValid() << std::endl;
622  }
623  if (cv[i].getQuality() != sv[i].getQuality()) {
624  std::cout << "In detId: " << al->first << std::endl;
625  std::cout << "ALCT qualities do not match: " << sv[i].getQuality() << " != " << cv[i].getQuality() << std::endl;
626  }
627  if (cv[i].getAccelerator() != sv[i].getAccelerator()) {
628  std::cout << "In detId: " << al->first << std::endl;
629  std::cout << "ALCT accelerator bits do not match: " << sv[i].getAccelerator()
630  << " != " << cv[i].getAccelerator() << std::endl;
631  }
632  if (cv[i].getCollisionB() != sv[i].getCollisionB()) {
633  std::cout << "In detId: " << al->first << std::endl;
634  std::cout << "ALCT CollisionB flags do not match: " << sv[i].getCollisionB() << " != " << cv[i].getCollisionB()
635  << std::endl;
636  }
637  if ((cv[i].getBX()) != (sv[i].getBX())) {
638  std::cout << "In detId: " << al->first << std::endl;
639  std::cout << "ALCT BX do not match: " << sv[i].getBX() << " != " << cv[i].getBX() << std::endl;
640  }
641  if (cv[i].getFullBX() != sv[i].getFullBX()) {
642  std::cout << "In detId: " << cl->first << std::endl;
643  std::cout << "ALCT Full BX do not match: " << sv[i].getFullBX() << " != " << cv[i].getFullBX() << std::endl;
644  }
645  }
646  }
647  for (lc = lcts.begin(); lc != lcts.end(); ++lc) {
648  if (lc->second.first.size() != lc->second.second.size()) {
649  std::cout << "Major error! # of Correlated LCT digis in detID: " << lc->first
650  << " is not equal between sim and unpacked!" << std::endl;
651  //eventually do more in this case!
652 
653  std::vector<CSCCorrelatedLCTDigi> a = lc->second.second;
654  std::vector<CSCCorrelatedLCTDigi> b = lc->second.first;
655  std::cout << "SIM OUTPUT:" << std::endl;
656  for (std::vector<CSCCorrelatedLCTDigi>::const_iterator i = a.begin(); i != a.end(); ++i)
657  i->print();
658  std::cout << "UNPACKER OUTPUT:" << std::endl;
659  for (std::vector<CSCCorrelatedLCTDigi>::const_iterator i = b.begin(); i != b.end(); ++i)
660  i->print();
661  }
662  int max = std::min(lc->second.first.size(), lc->second.second.size());
663  std::vector<CSCCorrelatedLCTDigi> cv = lc->second.first;
664  std::vector<CSCCorrelatedLCTDigi> sv = lc->second.second;
665  for (int i = 0; i < max; ++i) {
666  if (cv[i].getStrip() != sv[i].getStrip()) {
667  std::cout << "In detId: " << lc->first << std::endl;
668  std::cout << "Correlated LCT strips do not match: " << sv[i].getStrip() << " != " << cv[i].getStrip()
669  << std::endl;
670  }
671  if (cv[i].getKeyWG() != sv[i].getKeyWG()) {
672  std::cout << "In detId: " << lc->first << std::endl;
673  std::cout << "Correlated LCT key wire groups do not match: " << sv[i].getKeyWG() << " != " << cv[i].getKeyWG()
674  << std::endl;
675  }
676  if (cv[i].isValid() != sv[i].isValid()) {
677  std::cout << "In detId: " << lc->first << std::endl;
678  std::cout << "Correlated LCT Valid bits do not match: " << sv[i].isValid() << " != " << cv[i].isValid()
679  << std::endl;
680  }
681  if (cv[i].getQuality() != sv[i].getQuality()) {
682  std::cout << "In detId: " << lc->first << std::endl;
683  std::cout << "Correlated LCT qualities do not match: " << sv[i].getQuality() << " != " << cv[i].getQuality()
684  << std::endl;
685  }
686  if (cv[i].getPattern() != sv[i].getPattern()) {
687  std::cout << "In detId: " << lc->first << std::endl;
688  std::cout << "Correlated LCT ALCT patterns do not match: " << sv[i].getPattern() << " != " << cv[i].getPattern()
689  << std::endl;
690  }
691  if (cv[i].getCLCTPattern() != sv[i].getCLCTPattern()) {
692  std::cout << "In detId: " << lc->first << std::endl;
693  std::cout << "Correlated LCT CLCT patterns do not match: " << sv[i].getCLCTPattern()
694  << " != " << cv[i].getCLCTPattern() << std::endl;
695  }
696  if (cv[i].getStripType() != sv[i].getStripType()) {
697  std::cout << "In detId: " << lc->first << std::endl;
698  std::cout << "Correlated LCT strip types do not match: " << sv[i].getStripType()
699  << " != " << cv[i].getStripType() << std::endl;
700  }
701  if (cv[i].getBend() != sv[i].getBend()) {
702  std::cout << "In detId: " << lc->first << std::endl;
703  std::cout << "Correlated LCT bends do not match: " << sv[i].getBend() << " != " << cv[i].getBend() << std::endl;
704  }
705  if (cv[i].getMPCLink() != sv[i].getMPCLink()) {
706  std::cout << "In detId: " << lc->first << std::endl;
707  std::cout << "Correlated LCT MPC Links do not match: " << sv[i].getMPCLink() << " != " << cv[i].getMPCLink()
708  << std::endl;
709  }
710  if ((cv[i].getBX()) != (sv[i].getBX() - 6)) {
711  std::cout << "In detId: " << lc->first << std::endl;
712  std::cout << "Correlated LCT BX do not match: " << sv[i].getBX() - 6 << " != " << cv[i].getBX() << std::endl;
713  }
714  if (cv[i].getCSCID() != sv[i].getCSCID()) {
715  std::cout << "In detId: " << lc->first << std::endl;
716  std::cout << "Correlated LCT CSCIDs do not match: " << sv[i].getCSCID() << " != " << cv[i].getCSCID()
717  << std::endl;
718  }
719  if (cv[i].getBX0() != sv[i].getBX0()) {
720  std::cout << "In detId: " << lc->first << std::endl;
721  std::cout << "Correlated LCT BX0s do not match: " << sv[i].getBX0() << " != " << cv[i].getBX0() << std::endl;
722  }
723  if (cv[i].getSyncErr() != sv[i].getSyncErr()) {
724  std::cout << "In detId: " << lc->first << std::endl;
725  std::cout << "Correlated LCT SyncErrs do not match: " << sv[i].getSyncErr() << " != " << cv[i].getSyncErr()
726  << std::endl;
727  }
728  if (cv[i].getTrknmb() != sv[i].getTrknmb()) {
729  std::cout << "In detId: " << lc->first << std::endl;
730  std::cout << "Correlated LCT Track numbers do not match: " << sv[i].getTrknmb() << " != " << cv[i].getTrknmb()
731  << std::endl;
732  }
733  }
734  }
735  if (tracks.get().size() != simtracks.get().size()) {
736  std::cout << "Major error! # of L1 Tracks is not equal between sim and unpacked!" << std::endl;
737  std::vector<csc::L1Track> a = simtracks.get();
738  std::vector<csc::L1Track> b = tracks.get();
739  std::cout << "SIM OUTPUT:" << std::endl;
740  for (std::vector<csc::L1Track>::const_iterator i = a.begin(); i != a.end(); ++i)
741  i->print();
742  std::cout << "UNPACKER OUTPUT:" << std::endl;
743  for (std::vector<csc::L1Track>::const_iterator i = b.begin(); i != b.end(); ++i)
744  i->print();
745  }
746 
747  return _err;
748 }
749 
750 // this function takes the sim wire digis and combines wire digis from the same wire
751 // into one wire digi, as in the data.
752 // returns a vector of the combined wire digis
753 std::vector<CSCWireDigi> CSCDigiValidator::sanitizeWireDigis(std::vector<CSCWireDigi>::const_iterator b,
754  std::vector<CSCWireDigi>::const_iterator e) {
755  typedef std::map<int, std::vector<CSCWireDigi> > wire2digi;
756 
757  std::vector<CSCWireDigi> _r; // the resulting vector of wire digis
758  wire2digi _wr2digis; // map of wires to a set of digis
759 
760  for (std::vector<CSCWireDigi>::const_iterator i = b; i != e; ++i)
761  _wr2digis[i->getWireGroup()].push_back(*i);
762 
763  for (wire2digi::const_iterator i = _wr2digis.begin(); i != _wr2digis.end(); ++i) {
764  int wire = i->first;
765  unsigned tbin = 0x0;
766 
767  for (std::vector<CSCWireDigi>::const_iterator d = i->second.begin(); d != i->second.end(); ++d) {
768  std::vector<int> binson = d->getTimeBinsOn();
769  for (std::vector<int>::const_iterator t = binson.begin(); t != binson.end(); ++t)
770  tbin |= 1 << (*t);
771  }
772 
773  _r.push_back(CSCWireDigi(wire, tbin));
774  }
775 
776  return _r;
777 }
778 
779 std::vector<CSCStripDigi> CSCDigiValidator::relabelStripDigis(const CSCChamberMap* m,
780  CSCDetId _id,
781  std::vector<CSCStripDigi>::const_iterator b,
782  std::vector<CSCStripDigi>::const_iterator e) {
783  std::vector<CSCStripDigi> _r; // the vector of strip digis with appropriate strip #'s
784 
785  //bool me1a = _id.station()==1 && _id.ring()==4;
786  //bool zplus = _id.endcap()==1;
787  //bool me1b = _id.station()==1 && _id.ring()==1;
788 
789  for (std::vector<CSCStripDigi>::const_iterator i = b; i != e; ++i) {
790  int strip = i->getStrip();
791 
792  //if(me1a&&zplus) strip=17-strip;
793  //if(me1b&&!zplus) strip=(65-strip-1)%(m->dmb(_id)*16) + 1;
794  //if(me1a) strip+=64;
795 
796  _r.push_back(
797  CSCStripDigi(strip, i->getADCCounts(), i->getADCOverflow(), i->getOverlappedSample(), i->getErrorstat()));
798  }
799  return _r;
800 }
801 
802 std::vector<CSCComparatorDigi> CSCDigiValidator::relabelCompDigis(const CSCChamberMap* m,
803  CSCDetId _id,
804  std::vector<CSCComparatorDigi>::const_iterator b,
805  std::vector<CSCComparatorDigi>::const_iterator e) {
806  std::vector<CSCComparatorDigi> _r; // the vector of comp digis with appropriate strip #'s
807 
808  bool me1a = _id.station() == 1 && _id.ring() == 4;
809  //bool zplus = _id.endcap()==1;
810  //bool me1b = _id.station()==1 && _id.ring()==1;
811 
812  for (std::vector<CSCComparatorDigi>::const_iterator i = b; i != e; ++i) {
813  int strip = i->getStrip();
814 
815  // if(me1a&&zplus) strip=17-strip;
816  // if(me1b&&!zplus) strip=65-strip;
817  if (me1a)
818  strip += 64;
819 
820  _r.push_back(CSCComparatorDigi(strip, i->getComparator(), i->getTimeBinWord()));
821  }
822  return _r;
823 }
824 
825 std::vector<CSCStripDigi> CSCDigiValidator::sanitizeStripDigis(std::vector<CSCStripDigi>::const_iterator b,
826  std::vector<CSCStripDigi>::const_iterator e) {
827  std::vector<CSCStripDigi> _r; // vector of digis in proper order
828 
829  return _r;
830 }
831 
832 std::vector<CSCStripDigi> CSCDigiValidator::zeroSupStripDigis(std::vector<CSCStripDigi>::const_iterator b,
833  std::vector<CSCStripDigi>::const_iterator e) {
834  std::vector<CSCStripDigi> _r; // zero-suppressed strip digis
835  std::vector<int> counts;
836 
837  for (std::vector<CSCStripDigi>::const_iterator i = b; i != e; ++i) {
838  bool nonzero = false;
839  counts = i->getADCCounts();
840  for (std::vector<int>::const_iterator a = counts.begin(); a != counts.end(); ++a)
841  if ((*a) != 0)
842  nonzero = true;
843 
844  if (nonzero)
845  _r.push_back(*i);
846  }
847 
848  return _r;
849 }
850 
851 // remove comparator digis on or after the 10th time bin, for now, will be configurable later.
852 std::vector<CSCComparatorDigi> CSCDigiValidator::zeroSupCompDigis(std::vector<CSCComparatorDigi>::const_iterator b,
853  std::vector<CSCComparatorDigi>::const_iterator e) {
854  std::vector<CSCComparatorDigi> _r;
855 
856  for (std::vector<CSCComparatorDigi>::const_iterator i = b; i != e; ++i) {
857  bool present = false;
858 
859  if (i->getTimeBin() < 10)
860  present = true;
861 
862  if (present)
863  _r.push_back(*i);
864  }
865 
866  return _r;
867 }
868 
870 
872 
edm::InputTag strip2
edm::InputTag csctfstubs2
edm::InputTag alct2
edm::EDGetTokenT< CSCComparatorDigiCollection > cd1_token
~CSCDigiValidator() override
const edm::EventSetup & c
std::vector< CSCStripDigi > sanitizeStripDigis(std::vector< CSCStripDigi >::const_iterator, std::vector< CSCStripDigi >::const_iterator)
std::vector< CSCComparatorDigi > zeroSupCompDigis(std::vector< CSCComparatorDigi >::const_iterator, std::vector< CSCComparatorDigi >::const_iterator)
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
const double w
Definition: UKUtility.cc:23
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< CSCComparatorDigi > relabelCompDigis(const CSCChamberMap *m, CSCDetId _id, std::vector< CSCComparatorDigi >::const_iterator b, std::vector< CSCComparatorDigi >::const_iterator e)
edm::EDGetTokenT< CSCStripDigiCollection > sd1_token
void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< CSCCLCTDigiCollection > cl1_token
edm::EDGetTokenT< CSCCLCTDigiCollection > cl2_token
edm::EDGetTokenT< CSCALCTDigiCollection > al1_token
edm::InputTag wire2
void beginJob() override
auto const & tracks
cannot be loose
edm::InputTag csctfstubs1
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > co2_token
edm::EDGetTokenT< CSCALCTDigiCollection > al2_token
tuple cl
Definition: haddnano.py:49
edm::InputTag wire1
U second(std::pair< T, U > const &p)
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< L1CSCTrackCollection > tr1_token
edm::InputTag comp1
tuple strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
edm::InputTag alct1
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT< CSCTriggerContainer< csctf::TrackStub > > ts1_token
edm::EDGetTokenT< CSCWireDigiCollection > wd1_token
edm::EDGetTokenT< CSCStripDigiCollection > sd2_token
dictionary cv
Definition: cuy.py:363
edm::InputTag comp2
edm::EDGetTokenT< CSCWireDigiCollection > wd2_token
edm::ESGetToken< CSCChamberMap, CSCChamberMapRcd > cham_token
edm::InputTag strip1
int ring() const
Definition: CSCDetId.h:68
CSCDigiValidator(const edm::ParameterSet &)
edm::EDGetTokenT< CSCTriggerContainer< csctf::TrackStub > > ts2_token
bool filter(edm::Event &, const edm::EventSetup &) override
edm::InputTag clct2
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double b
Definition: hdecay.h:118
std::vector< DigiType >::const_iterator const_iterator
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > co1_token
edm::EDGetTokenT< CSCComparatorDigiCollection > cd2_token
edm::InputTag lct1
edm::EDGetTokenT< L1CSCTrackCollection > tr2_token
std::vector< CSCStripDigi > zeroSupStripDigis(std::vector< CSCStripDigi >::const_iterator, std::vector< CSCStripDigi >::const_iterator)
double a
Definition: hdecay.h:119
int station() const
Definition: CSCDetId.h:79
tuple cout
Definition: gather_cfg.py:144
edm::InputTag clct1
tuple wires
Definition: DigiDM_cff.py:33
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
edm::InputTag csctf2
std::vector< CSCWireDigi > sanitizeWireDigis(std::vector< CSCWireDigi >::const_iterator, std::vector< CSCWireDigi >::const_iterator)
tuple size
Write out results.
std::vector< CSCStripDigi > relabelStripDigis(const CSCChamberMap *, CSCDetId, std::vector< CSCStripDigi >::const_iterator, std::vector< CSCStripDigi >::const_iterator)
edm::InputTag lct2
edm::InputTag csctf1