CMS 3D CMS Logo

L1TStage2CaloLayer2Comp.cc
Go to the documentation of this file.
1 #ifndef L1Trigger_L1TCalorimeter_L1TStage2CaloLayer2Comp
2 #define L1Trigger_L1TCalorimeter_L1TStage2CaloLayer2Comp
3 
5 
9 
14 
18 
20 
23 
26 
33 
34 // classes required for storage of objects into a separate edm file
36 
37 // classes required for sorting of jets
42 
43 
44 namespace l1t {
45  bool operator > ( const l1t::Jet& a, l1t::Jet& b ) {
46  return a.hwPt() > b.hwPt();
47  }
48  bool operator > ( const l1t::EGamma& a, l1t::EGamma& b ) {
49  return a.hwPt() > b.hwPt();
50  }
51  bool operator > ( const l1t::Tau& a, l1t::Tau& b ) {
52  return a.hwPt() > b.hwPt();
53  }
54 }
55 
56 
57 #include "TH1F.h"
58 #include "TH2F.h"
59 
60 
68 
69 public:
84 
85 
86 protected:
87 
100  void produce (edm::Event&, const edm::EventSetup&) override;
101 
102 private:
103 
126  bool compareJets(const edm::Handle<l1t::JetBxCollection> & dataCol,
127  const edm::Handle<l1t::JetBxCollection> & emulCol);
128 
153  bool compareEGs(const edm::Handle<l1t::EGammaBxCollection> & dataCol,
154  const edm::Handle<l1t::EGammaBxCollection> & emulCol);
155 
180  bool compareTaus(const edm::Handle<l1t::TauBxCollection> & dataCol,
181  const edm::Handle<l1t::TauBxCollection> & emulCol);
182 
202  bool compareSums(const edm::Handle<l1t::EtSumBxCollection> & dataCol,
203  const edm::Handle<l1t::EtSumBxCollection> & emulCol);
204 
205  void accuSort(std::vector<l1t::Jet> *jets);
206  void accuSort(std::vector<l1t::Tau> *taus);
207  void accuSort(std::vector<l1t::EGamma> *egs);
208  void accuSort(std::vector<l1t::L1Candidate> & jets);
209 
210  void dumpEventToFile();
211  void dumpEventToEDM(edm::Event &e);
212 
213  // collections to hold entities reconstructed from data and emulation
224 
225  // define collections to hold lists of objects in event
236 
237  const unsigned int currBx = 0;
238 
239  bool dumpTowers = false;
240  bool dumpWholeEvent = false;
241 };
242 
244  : calol2JetCollectionData(consumes <l1t::JetBxCollection>(
245  ps.getParameter<edm::InputTag>(
246  "calol2JetCollectionData"))),
247  calol2JetCollectionEmul(consumes <l1t::JetBxCollection>(
248  ps.getParameter<edm::InputTag>(
249  "calol2JetCollectionEmul"))),
250  calol2EGammaCollectionData(consumes <l1t::EGammaBxCollection>(
251  ps.getParameter<edm::InputTag>(
252  "calol2EGammaCollectionData"))),
253  calol2EGammaCollectionEmul(consumes <l1t::EGammaBxCollection>(
254  ps.getParameter<edm::InputTag>(
255  "calol2EGammaCollectionEmul"))),
256  calol2TauCollectionData(consumes <l1t::TauBxCollection>(
257  ps.getParameter<edm::InputTag>(
258  "calol2TauCollectionData"))),
259  calol2TauCollectionEmul(consumes <l1t::TauBxCollection>(
260  ps.getParameter<edm::InputTag>(
261  "calol2TauCollectionEmul"))),
262  calol2EtSumCollectionData(consumes <l1t::EtSumBxCollection>(
263  ps.getParameter<edm::InputTag>(
264  "calol2EtSumCollectionData"))),
265  calol2EtSumCollectionEmul(consumes <l1t::EtSumBxCollection>(
266  ps.getParameter<edm::InputTag>(
267  "calol2EtSumCollectionEmul"))),
268  calol2CaloTowerCollectionData(consumes <l1t::CaloTowerBxCollection>(
269  ps.getParameter<edm::InputTag>(
270  "calol2CaloTowerCollectionData"))),
271  calol2CaloTowerCollectionEmul(consumes <l1t::CaloTowerBxCollection>(
272  ps.getParameter<edm::InputTag>(
273  "calol2CaloTowerCollectionEmul")))
274 {
275  produces<l1t::JetBxCollection> ("dataJet").setBranchAlias("dataJets");
276  produces<l1t::JetBxCollection> ("emulJet").setBranchAlias("emulJets");
277  produces<l1t::EGammaBxCollection> ("dataEg").setBranchAlias("dataEgs");
278  produces<l1t::EGammaBxCollection> ("emulEg").setBranchAlias("emulEgs");
279  produces<l1t::TauBxCollection> ("dataTau").setBranchAlias("dataTaus");
280  produces<l1t::TauBxCollection> ("emulTau").setBranchAlias("emulTaus");
281  produces<l1t::EtSumBxCollection> ("dataEtSum").setBranchAlias("dataEtSums");
282  produces<l1t::EtSumBxCollection> ("emulEtSum").setBranchAlias("emulEtSums");
283  produces<l1t::CaloTowerBxCollection> ("dataCaloTower").setBranchAlias("dataCaloTowers");
284  produces<l1t::CaloTowerBxCollection> ("emulCaloTower").setBranchAlias("emulCaloTowers");
285 
286  dumpTowers = ps.getParameter<bool>("dumpTowers");
287  dumpWholeEvent = ps.getParameter<bool>("dumpWholeEvent");
288 }
289 
291  edm::Event& e,
292  const edm::EventSetup & c) {
293 
294  bool eventGood = true;
295 
296  // map event contents to above collections
307 
308  edm::LogProblem("l1tcalol2ebec")
309  << "Processing event " << e.id() << std::endl;
310 
311  if(caloTowerDataCol->size()==0){
312  edm::LogProblem("l1tcalol2ebec")
313  << "Empty caloTowers. Skipping event " << std::endl;
314  return;
315  }
316 
318  eventGood = false;
319  }
320 
321  if (!compareEGs(egDataCol, egEmulCol)) {
322  eventGood = false;
323  }
324 
326  eventGood = false;
327  }
328 
330  eventGood = false;
331  }
332 
333  if (!eventGood) {
334 
335  if (dumpWholeEvent) {
336  // store all contents of event to log file
337  dumpEventToFile();
338  }
339 
340  // store all contents of event to edm file:
341  dumpEventToEDM(e);
342 
343  edm::LogProblem("l1tcalol2ebec")
344  << "Bad event! " << std::endl;
345 
346  }
347 }
348 
349 // comparison method for jets
351  const edm::Handle<l1t::JetBxCollection> & dataCol,
352  const edm::Handle<l1t::JetBxCollection> & emulCol)
353 {
354  bool eventGood = true;
355 
356  std::vector<l1t::Jet> *jets = new std::vector<l1t::Jet>;
357  std::vector<l1t::Jet>::iterator dataIt;
360 
361  if (dataCol->size(currBx) > 0) {
362  // sort data jets
363  while (true) {
364 
365  jets->emplace_back(*dataBxIt);
366 
367  dataBxIt++;
368  if (dataBxIt == dataCol->end(currBx))
369  break;
370  }
371 
372  accuSort(jets);
373  dataIt = jets->begin();
374  }
375 
376  // process jets
377  if (jets->size() != emulCol->size(currBx)) {
378  edm::LogProblem("l1tcalol2ebec")
379  << "Jet collection size difference: "
380  << "data = " << jets->size()
381  << " emul = " << emulCol->size(currBx)
382  << std::endl;
383  return false;
384  }
385 
386  if (dataIt != jets->end() ||
387  emulBxIt != emulCol->end(currBx)) {
388 
389  int nPos=0;
390  int nNeg=0;
391 
392  while(true) {
393 
394  bool posGood = true;
395  bool etGood = true;
396 
397  // object pt mismatch
398  if (dataIt->hwPt() != emulBxIt->hwPt()) {
399  etGood = false;
400  eventGood = false;
401  }
402 
403  // object position mismatch (phi)
404  if (dataIt->hwPhi() != emulBxIt->hwPhi()){
405  posGood = false;
406  }
407 
408  // object position mismatch (eta)
409  if (dataIt->hwEta() != emulBxIt->hwEta()) {
410  posGood = false;
411  }
412 
413  //bypass sorting bug
414  if(etGood && !posGood){
415  l1t::JetBxCollection::const_iterator emulItCheckSort;
416  l1t::JetBxCollection::const_iterator dataItCheckSort;
417  for(emulItCheckSort = emulCol->begin(currBx) ; emulItCheckSort != emulCol->end(currBx) ; ++emulItCheckSort) {
418  for (dataItCheckSort = jets->begin(); dataItCheckSort != jets->end(); ++dataItCheckSort){
419 
420  if(dataItCheckSort->hwEta() > 0) ++nPos;
421  if(dataItCheckSort->hwEta() < 0) ++nNeg;
422 
423  if(dataIt->hwPt() == emulItCheckSort->hwPt()
424  && dataIt->hwPhi() == emulItCheckSort->hwPhi()
425  && dataIt->hwEta() == emulItCheckSort->hwEta())
426  posGood = true;
427  }
428  }
429  }
430 
431  if(etGood && dataIt->hwEta() > 0 && ((distance(dataIt, jets->end())-nNeg) < 5))
432  posGood = true;
433  if(etGood && dataIt->hwEta() < 0 && (distance(dataIt, jets->end()) < 5))
434  posGood = true;
435 
436  if(!posGood) eventGood = false;
437 
438  // if both position and energy agree, object is good
439  if (!etGood || !posGood) {
440  edm::LogProblem("l1tcalol2ebec")
441  << "Jet Problem (data emul): "
442  << "\tEt = " << dataIt->hwPt() << " " << emulBxIt->hwPt()
443  << "\teta = " << dataIt->hwEta() << " " << emulBxIt->hwEta()
444  << "\tphi = " << dataIt->hwPhi() << " " << emulBxIt->hwPhi()
445  << std::endl;
446  }
447 
448  // increment position of pointers
449  ++dataIt;
450  ++emulBxIt;
451 
452  if (dataIt == jets->end() ||
453  emulBxIt == emulCol->end(currBx))
454  break;
455  }
456  } else {
457  if (!jets->empty() || emulCol->size(currBx) != 0)
458  return false;
459  }
460 
461  // return a boolean that states whether the jet data in the event are in
462  // agreement
463  return eventGood;
464 }
465 
466 // comparison method for e/gammas
468  const edm::Handle<l1t::EGammaBxCollection> & dataCol,
469  const edm::Handle<l1t::EGammaBxCollection> & emulCol)
470 {
471  bool eventGood = true;
472 
473  std::vector<l1t::EGamma> *egs = new std::vector<l1t::EGamma>;
474  std::vector<l1t::EGamma>::iterator dataIt;
477 
478  if (dataCol->size(currBx) > 0) {
479  // sort data egs
480  while (true) {
481 
482  egs->emplace_back(*dataBxIt);
483 
484  dataBxIt++;
485  if (dataBxIt == dataCol->end(currBx))
486  break;
487  }
488  accuSort(egs);
489  dataIt = egs->begin();
490  }
491 
492  // check length of collections
493  if (egs->size() != emulCol->size(currBx)) {
494  edm::LogProblem("l1tcalol2ebec")
495  << "EG collection size difference: "
496  << "data = " << egs->size()
497  << " emul = " << emulCol->size(currBx)
498  << std::endl;
499  return false;
500  }
501 
502  // processing continues only of length of data collections is the same
503  if (dataIt != egs->end() ||
504  emulBxIt != emulCol->end(currBx)) {
505 
506  int nPos=0;
507  int nNeg=0;
508 
509  while(true) {
510 
511  bool posGood = true;
512  bool etGood = true;
513 
514  // object pt mismatch
515  if (dataIt->hwPt() != emulBxIt->hwPt()) {
516  etGood = false;
517  eventGood = false;
518  }
519 
520  // object position mismatch (phi)
521  if (dataIt->hwPhi() != emulBxIt->hwPhi()) {
522  posGood = false;
523  }
524 
525  // object position mismatch (eta)
526  if (dataIt->hwEta() != emulBxIt->hwEta()) {
527  posGood = false;
528  }
529 
530  //bypass sorting bug
531  if(etGood && !posGood){
534  for(emulItCheckSort = emulCol->begin(currBx); emulItCheckSort != emulCol->end(currBx); ++emulItCheckSort) {
535  for (dataItCheckSort = egs->begin(); dataItCheckSort != egs->end(); ++dataItCheckSort){
536 
537  if(dataItCheckSort->hwEta() > 0) ++nPos;
538  if(dataItCheckSort->hwEta() < 0) ++nNeg;
539 
540  if(dataIt->hwPt() == emulItCheckSort->hwPt()
541  && dataIt->hwPhi() == emulItCheckSort->hwPhi()
542  && dataIt->hwEta() == emulItCheckSort->hwEta())
543  posGood = true;
544  }
545  }
546  }
547 
548  if(etGood && dataIt->hwEta() > 0 && ((distance(dataIt, egs->end())-nNeg) < 5))
549  posGood = true;
550  if(etGood && dataIt->hwEta() < 0 && (distance(dataIt, egs->end()) < 5))
551  posGood = true;
552 
553  if(!posGood) eventGood = false;
554 
555  // if both position and energy agree, object is good
556  if (!posGood || !etGood) {
557  edm::LogProblem("l1tcalol2ebec")
558  << "EG Problem (data emul): "
559  << "\tEt = " << dataIt->hwPt() << " " << emulBxIt->hwPt()
560  << "\teta = " << dataIt->hwEta() << " " << emulBxIt->hwEta()
561  << "\tphi = " << dataIt->hwPhi() << " " << emulBxIt->hwPhi()
562  << std::endl;
563  }
564 
565  // increment position of pointers
566  ++dataIt;
567  ++emulBxIt;
568 
569  if (dataIt == egs->end() ||
570  emulBxIt == emulCol->end(currBx))
571  break;
572  }
573  } else {
574  if (!egs->empty() || emulCol->size(currBx) != 0)
575  return false;
576  }
577 
578  // return a boolean that states whether the eg data in the event are in
579  // agreement
580  return eventGood;
581 }
582 
583 // comparison method for taus
585  const edm::Handle<l1t::TauBxCollection> & dataCol,
586  const edm::Handle<l1t::TauBxCollection> & emulCol)
587 {
588  bool eventGood = true;
589 
590  std::vector<l1t::Tau> *taus = new std::vector<l1t::Tau>;
591  std::vector<l1t::Tau>::iterator dataIt;
594 
595  if (dataCol->size(currBx) > 0) {
596  // sort data taus
597  while (true) {
598 
599  taus->emplace_back(*dataBxIt);
600 
601  dataBxIt++;
602  if (dataBxIt == dataCol->end(currBx))
603  break;
604  }
605  accuSort(taus);
606  dataIt = taus->begin();
607  }
608 
609  // check length of collections
610  if (taus->size() != emulCol->size(currBx)) {
611  edm::LogProblem("l1tcalol2ebec")
612  << "Tau collection size difference: "
613  << "data = " << taus->size()
614  << " emul = " << emulCol->size(currBx)
615  << std::endl;
616  return false;
617  }
618 
619  // processing continues only of length of data collections is the same
620  if (dataIt != taus->end() ||
621  emulBxIt != emulCol->end(currBx)) {
622 
623  int nPos=0;
624  int nNeg=0;
625 
626  while(true) {
627 
628  bool posGood = true;
629  bool etGood = true;
630 
631  // object Et mismatch
632  if (dataIt->hwPt() != emulBxIt->hwPt()) {
633  etGood = false;
634  eventGood = false;
635  }
636 
637  // object position mismatch (phi)
638  if (dataIt->hwPhi() != emulBxIt->hwPhi()) {
639  posGood = false;
640  }
641 
642  // object position mismatch (eta)
643  if (dataIt->hwEta() != emulBxIt->hwEta()) {
644  posGood = false;
645  }
646 
647  //bypass sorting bug
648  if(etGood && !posGood){
649  l1t::TauBxCollection::const_iterator emulItCheckSort;
650  l1t::TauBxCollection::const_iterator dataItCheckSort;
651  for(emulItCheckSort = emulCol->begin(currBx); emulItCheckSort != emulCol->end(currBx); ++emulItCheckSort) {
652  for (dataItCheckSort = taus->begin(); dataItCheckSort != taus->end(); ++dataItCheckSort){
653 
654  if(dataItCheckSort->hwEta() > 0) ++nPos;
655  if(dataItCheckSort->hwEta() < 0) ++nNeg;
656 
657  if(dataIt->hwPt() == emulItCheckSort->hwPt()
658  && dataIt->hwPhi() == emulItCheckSort->hwPhi()
659  && dataIt->hwEta() == emulItCheckSort->hwEta())
660  posGood = true;
661  }
662  }
663  }
664 
665  if(etGood && dataIt->hwEta() > 0 && ((distance(dataIt, taus->end())-nNeg) < 5))
666  posGood = true;
667  if(etGood && dataIt->hwEta() < 0 && (distance(dataIt, taus->end()) < 5))
668  posGood = true;
669 
670  if(!posGood) eventGood = false;
671 
672  // if both position and energy agree, object is good
673  if (!posGood || !etGood) {
674  edm::LogProblem("l1tcalol2ebec")
675  << "Tau Problem (data emul): "
676  << "\tEt = " << dataIt->hwPt() << " " << emulBxIt->hwPt()
677  << "\teta = " << dataIt->hwEta() << " " << emulBxIt->hwEta()
678  << "\tphi = " << dataIt->hwPhi() << " " << emulBxIt->hwPhi()
679  << std::endl;
680  }
681 
682  // increment position of pointers
683  ++dataIt;
684  ++emulBxIt;
685 
686  if (dataIt == taus->end() ||
687  emulBxIt == emulCol->end(currBx))
688  break;
689  }
690  } else {
691  if (!taus->empty() || emulCol->size(currBx) != 0)
692  return false;
693  }
694 
695  // return a boolean that states whether the tau data in the event are in
696  // agreement
697  return eventGood;
698 }
699 
700 // comparison method for sums
702  const edm::Handle<l1t::EtSumBxCollection> & dataCol,
703  const edm::Handle<l1t::EtSumBxCollection> & emulCol)
704 {
705  bool eventGood = true;
706 
707  double dataEt = 0;
708  double emulEt = 0;
709 
710  // if either data or emulator collections are empty, or they have different
711  // size, mark the event as bad (this should never occur in normal running)
712  if ((dataCol->isEmpty(currBx)) || (emulCol->isEmpty(currBx)) ||
713  (dataCol->size(currBx) != emulCol->size(currBx))) {
714  edm::LogProblem("l1tcalol2ebec")
715  << "EtSum collection size difference: "
716  << "data = " << dataCol->size(currBx)
717  << " emul = " << emulCol->size(currBx)
718  << std::endl;
719 
720  return false;
721  }
722 
723  l1t::EtSum dataSum;
724  l1t::EtSum emulSum;
725  for (unsigned int i = 0; i < emulCol->size(currBx); i++) {
726 
727  emulSum = emulCol->at(currBx, i);
729 
730  if (emulSum.getType() != dataSum.getType()) {
731  edm::LogProblem("l1tcalol2ebec")
732  << "EtSum type problem (data emul): "
733  << dataSum.getType() << " " << emulSum.getType()
734  << std::endl;
735  }
736 
737  dataEt = dataSum.hwPt();
738  emulEt = emulSum.hwPt();
739 
740  if (dataEt != emulEt) {
741  eventGood = false;
742  edm::LogProblem("l1tcalol2ebec")
743  << "EtSum problem (data emul):\tType = " << emulSum.getType()
744  << "\tEt = " << dataEt << " " << emulEt
745  << std::endl;
746  }
747  }
748 
749  // return a boolean that states whether the sum data in the event are in
750  // agreement
751  return eventGood;
752 }
753 
754 // sort for jets
755 void L1TStage2CaloLayer2Comp::accuSort(std::vector<l1t::Jet> *jets){
756 
758  l1t::Jet tempJet (emptyP4, 0, 0, 0, 0);
759  std::vector< std::vector<l1t::Jet> > jetEtaPos( 41 , std::vector<l1t::Jet>(18, tempJet));
760  std::vector< std::vector<l1t::Jet> > jetEtaNeg( 41 , std::vector<l1t::Jet>(18, tempJet));
761 
762  for (unsigned int iJet = 0; iJet < jets->size(); iJet++) {
763  if (jets->at(iJet).hwEta() > 0) jetEtaPos.at(jets->at(iJet).hwEta()-1).at((jets->at(iJet).hwPhi()-1)/4) = jets->at(iJet);
764  else jetEtaNeg.at(-(jets->at(iJet).hwEta()+1)).at((jets->at(iJet).hwPhi()-1)/4) = jets->at(iJet);
765  }
766 
767  AccumulatingSort <l1t::Jet> etaPosSorter(7);
768  AccumulatingSort <l1t::Jet> etaNegSorter(7);
769  std::vector<l1t::Jet> accumEtaPos;
770  std::vector<l1t::Jet> accumEtaNeg;
771 
772  for( int ieta = 0 ; ieta < 41 ; ++ieta) {
773  // eta +
774  std::vector<l1t::Jet>::iterator start_, end_;
775  start_ = jetEtaPos.at(ieta).begin();
776  end_ = jetEtaPos.at(ieta).end();
777  BitonicSort<l1t::Jet>(down, start_, end_);
778  etaPosSorter.Merge( jetEtaPos.at(ieta) , accumEtaPos );
779 
780  // eta -
781  start_ = jetEtaNeg.at(ieta).begin();
782  end_ = jetEtaNeg.at(ieta).end();
783  BitonicSort<l1t::Jet>(down, start_, end_);
784  etaNegSorter.Merge( jetEtaNeg.at(ieta) , accumEtaNeg );
785 
786  }
787 
788  //check for 6 & 7th jets with same et and eta. Keep jet with larger phi
789  if(accumEtaPos.at(6).hwPt()==accumEtaPos.at(5).hwPt() && accumEtaPos.at(6).hwEta()==accumEtaPos.at(5).hwEta()
790  && accumEtaPos.at(6).hwPhi() > accumEtaPos.at(5).hwPhi()){
791  accumEtaPos.at(5)=accumEtaPos.at(6);
792  }
793  if(accumEtaNeg.at(6).hwPt()==accumEtaNeg.at(5).hwPt() && accumEtaNeg.at(6).hwEta()==accumEtaNeg.at(5).hwEta()
794  && accumEtaNeg.at(6).hwPhi() > accumEtaNeg.at(5).hwPhi()){
795  accumEtaNeg.at(5)=accumEtaNeg.at(6);
796  }
797 
798  //truncate
799  accumEtaPos.resize(6);
800  accumEtaNeg.resize(6);
801 
802  // put all 12 candidates in the original jet vector, removing zero energy ones
803  jets->clear();
804  for (l1t::Jet accjet : accumEtaPos) {
805  if (accjet.hwPt() > 0) jets->push_back(accjet);
806  }
807  for (l1t::Jet accjet : accumEtaNeg) {
808  if (accjet.hwPt() > 0) jets->push_back(accjet);
809  }
810 }
811 
812 // sort for eg
813 void L1TStage2CaloLayer2Comp::accuSort(std::vector<l1t::EGamma> *egs){
814 
816  l1t::EGamma tempEGamma (emptyP4, 0, 0, 0, 0);
817  std::vector< std::vector<l1t::EGamma> > jetEtaPos( 41 , std::vector<l1t::EGamma>(18, tempEGamma));
818  std::vector< std::vector<l1t::EGamma> > jetEtaNeg( 41 , std::vector<l1t::EGamma>(18, tempEGamma));
819 
820  for (unsigned int iEGamma = 0; iEGamma < egs->size(); iEGamma++) {
821  if (egs->at(iEGamma).hwEta() > 0) jetEtaPos.at(egs->at(iEGamma).hwEta()-1).at((egs->at(iEGamma).hwPhi()-1)/4) = egs->at(iEGamma);
822  else jetEtaNeg.at(-(egs->at(iEGamma).hwEta()+1)).at((egs->at(iEGamma).hwPhi()-1)/4) = egs->at(iEGamma);
823  }
824 
825  AccumulatingSort <l1t::EGamma> etaPosSorter(7);
826  AccumulatingSort <l1t::EGamma> etaNegSorter(7);
827  std::vector<l1t::EGamma> accumEtaPos;
828  std::vector<l1t::EGamma> accumEtaNeg;
829 
830  for( int ieta = 0 ; ieta < 41 ; ++ieta) {
831  // eta +
832  std::vector<l1t::EGamma>::iterator start_, end_;
833  start_ = jetEtaPos.at(ieta).begin();
834  end_ = jetEtaPos.at(ieta).end();
835  BitonicSort<l1t::EGamma>(down, start_, end_);
836  etaPosSorter.Merge( jetEtaPos.at(ieta) , accumEtaPos );
837 
838  // eta -
839  start_ = jetEtaNeg.at(ieta).begin();
840  end_ = jetEtaNeg.at(ieta).end();
841  BitonicSort<l1t::EGamma>(down, start_, end_);
842  etaNegSorter.Merge( jetEtaNeg.at(ieta) , accumEtaNeg );
843 
844  }
845 
846  //check for 6 & 7th egs with same et and eta. Keep jet with larger phi
847  if(accumEtaPos.at(6).hwPt()==accumEtaPos.at(5).hwPt() && accumEtaPos.at(6).hwEta()==accumEtaPos.at(5).hwEta()
848  && accumEtaPos.at(6).hwPhi() > accumEtaPos.at(5).hwPhi()){
849  accumEtaPos.at(5)=accumEtaPos.at(6);
850  }
851  if(accumEtaNeg.at(6).hwPt()==accumEtaNeg.at(5).hwPt() && accumEtaNeg.at(6).hwEta()==accumEtaNeg.at(5).hwEta()
852  && accumEtaNeg.at(6).hwPhi() > accumEtaNeg.at(5).hwPhi()){
853  accumEtaNeg.at(5)=accumEtaNeg.at(6);
854  }
855 
856  //truncate
857  accumEtaPos.resize(6);
858  accumEtaNeg.resize(6);
859 
860  // put all 12 candidates in the original jet vector, removing zero energy ones
861  egs->clear();
862  for (l1t::EGamma accjet : accumEtaPos) {
863  if (accjet.hwPt() > 0) egs->push_back(accjet);
864  }
865  for (l1t::EGamma accjet : accumEtaNeg) {
866  if (accjet.hwPt() > 0) egs->push_back(accjet);
867  }
868 }
869 
870 
871 // sort for tau
872 void L1TStage2CaloLayer2Comp::accuSort(std::vector<l1t::Tau> *taus){
873 
875  l1t::Tau tempTau (emptyP4, 0, 0, 0, 0);
876  std::vector< std::vector<l1t::Tau> > jetEtaPos( 41 , std::vector<l1t::Tau>(18, tempTau));
877  std::vector< std::vector<l1t::Tau> > jetEtaNeg( 41 , std::vector<l1t::Tau>(18, tempTau));
878 
879  for (unsigned int iTau = 0; iTau < taus->size(); iTau++) {
880  if (taus->at(iTau).hwEta() > 0) jetEtaPos.at(taus->at(iTau).hwEta()-1).at((taus->at(iTau).hwPhi()-1)/4) = taus->at(iTau);
881  else jetEtaNeg.at(-(taus->at(iTau).hwEta()+1)).at((taus->at(iTau).hwPhi()-1)/4) = taus->at(iTau);
882  }
883 
884  AccumulatingSort <l1t::Tau> etaPosSorter(7);
885  AccumulatingSort <l1t::Tau> etaNegSorter(7);
886  std::vector<l1t::Tau> accumEtaPos;
887  std::vector<l1t::Tau> accumEtaNeg;
888 
889  for( int ieta = 0 ; ieta < 41 ; ++ieta) {
890  // eta +
891  std::vector<l1t::Tau>::iterator start_, end_;
892  start_ = jetEtaPos.at(ieta).begin();
893  end_ = jetEtaPos.at(ieta).end();
894  BitonicSort<l1t::Tau>(down, start_, end_);
895  etaPosSorter.Merge( jetEtaPos.at(ieta) , accumEtaPos );
896 
897  // eta -
898  start_ = jetEtaNeg.at(ieta).begin();
899  end_ = jetEtaNeg.at(ieta).end();
900  BitonicSort<l1t::Tau>(down, start_, end_);
901  etaNegSorter.Merge( jetEtaNeg.at(ieta) , accumEtaNeg );
902 
903  }
904 
905  //check for 6 & 7th taus with same et and eta. Keep jet with larger phi
906  if(accumEtaPos.at(6).hwPt()==accumEtaPos.at(5).hwPt() && accumEtaPos.at(6).hwEta()==accumEtaPos.at(5).hwEta()
907  && accumEtaPos.at(6).hwPhi() > accumEtaPos.at(5).hwPhi()){
908  accumEtaPos.at(5)=accumEtaPos.at(6);
909  }
910  if(accumEtaNeg.at(6).hwPt()==accumEtaNeg.at(5).hwPt() && accumEtaNeg.at(6).hwEta()==accumEtaNeg.at(5).hwEta()
911  && accumEtaNeg.at(6).hwPhi() > accumEtaNeg.at(5).hwPhi()){
912  accumEtaNeg.at(5)=accumEtaNeg.at(6);
913  }
914 
915  //truncate
916  accumEtaPos.resize(6);
917  accumEtaNeg.resize(6);
918 
919  // put all 12 candidates in the original jet vector, removing zero energy ones
920  taus->clear();
921  for (l1t::Tau accjet : accumEtaPos) {
922  if (accjet.hwPt() > 0) taus->push_back(accjet);
923  }
924  for (l1t::Tau accjet : accumEtaNeg) {
925  if (accjet.hwPt() > 0) taus->push_back(accjet);
926  }
927 }
928 
930 {
931  edm::LogProblem("l1tcalol2ebec")
932  << "==== Problems found, dumping full event contents ====" << std::endl;
933 
934  edm::LogProblem("l1tcalol2ebec")
935  << "==== Event contents in data: ====" << std::endl;
936 
937  if (dumpTowers) {
938  edm::LogProblem("l1tcalol2ebec")
939  << "==== Towers: ====" << std::endl;
940 
941  for (auto tower = caloTowerDataCol->begin(currBx); tower != caloTowerDataCol->end(currBx); ++tower)
942  edm::LogProblem("l1tcalol2ebec")
943  << "Tower: Et = " << tower->hwPt() << ", "
944  << "eta = " << tower->hwEta() << ", "
945  << "phi = " << tower->hwPhi() << std::endl;
946  }
947 
948  edm::LogProblem("l1tcalol2ebec")
949  << "==== Jets: ====" << std::endl;
950  for (auto jet = jetDataCol->begin(currBx); jet != jetDataCol->end(currBx); ++jet)
951  edm::LogProblem("l1tcalol2ebec")
952  << "Jet: Et = " << jet->hwPt() << ", "
953  << "eta = " << jet->hwEta() << ", "
954  << "phi = " << jet->hwPhi() << std::endl;
955 
956  edm::LogProblem("l1tcalol2ebec")
957  << "==== EGs: ====" << std::endl;
958  for (auto eg = egDataCol->begin(currBx); eg != egDataCol->end(currBx); ++eg)
959  edm::LogProblem("l1tcalol2ebec")
960  << "EG: Et = " << eg->hwPt() << ", "
961  << "eta = " << eg->hwEta() << ", "
962  << "phi = " << eg->hwPhi() << std::endl;
963 
964  edm::LogProblem("l1tcalol2ebec")
965  << "==== Taus: ====" << std::endl;
966  for (auto tau = tauDataCol->begin(currBx); tau != tauDataCol->end(currBx); ++tau)
967  edm::LogProblem("l1tcalol2ebec")
968  << "Tau: Et = " << tau->hwPt() << ", "
969  << "eta = " << tau->hwEta() << ", "
970  << "phi = " << tau->hwPhi() << std::endl;
971 
972  edm::LogProblem("l1tcalol2ebec")
973  << "==== Sums: ====" << std::endl;
974  for (auto sum = sumDataCol->begin(currBx); sum != sumDataCol->end(currBx); ++sum)
975  edm::LogProblem("l1tcalol2ebec")
976  << "Sum: type = " << sum->getType() << " "
977  << "Et = " << sum->hwPt() << ", "
978  << "eta = " << sum->hwEta() << ", "
979  << "phi = " << sum->hwPhi() << std::endl;
980 
981  edm::LogProblem("l1tcalol2ebec")
982  << "==== Event contents in emul: ====" << std::endl;
983 
984  if (dumpTowers) {
985  edm::LogProblem("l1tcalol2ebec")
986  << "==== Towers: ====" << std::endl;
987 
988  for (auto tower = caloTowerEmulCol->begin(currBx); tower != caloTowerEmulCol->end(currBx); ++tower)
989  edm::LogProblem("l1tcalol2ebec")
990  << "Tower: Et = " << tower->hwPt() << ", "
991  << "eta = " << tower->hwEta() << ", "
992  << "phi = " << tower->hwPhi() << std::endl;
993  }
994 
995  edm::LogProblem("l1tcalol2ebec")
996  << "==== Jets: ====" << std::endl;
997  for (auto jet = jetEmulCol->begin(currBx); jet != jetEmulCol->end(currBx); ++jet)
998  edm::LogProblem("l1tcalol2ebec")
999  << "Jet: Et = " << jet->hwPt() << ", "
1000  << "eta = " << jet->hwEta() << ", "
1001  << "phi = " << jet->hwPhi() << std::endl;
1002 
1003  edm::LogProblem("l1tcalol2ebec")
1004  << "==== EGs: ====" << std::endl;
1005  for (auto eg = egEmulCol->begin(currBx); eg != egEmulCol->end(currBx); ++eg)
1006  edm::LogProblem("l1tcalol2ebec")
1007  << "EG: Et = " << eg->hwPt() << ", "
1008  << "eta = " << eg->hwEta() << ", "
1009  << "phi = " << eg->hwPhi() << std::endl;
1010 
1011  edm::LogProblem("l1tcalol2ebec")
1012  << "==== Taus: ====" << std::endl;
1013  for (auto tau = tauEmulCol->begin(currBx); tau != tauEmulCol->end(currBx); ++tau)
1014  edm::LogProblem("l1tcalol2ebec")
1015  << "Tau: Et = " << tau->hwPt() << ", "
1016  << "eta = " << tau->hwEta() << ", "
1017  << "phi = " << tau->hwPhi() << std::endl;
1018 
1019  edm::LogProblem("l1tcalol2ebec")
1020  << "==== Sums: ====" << std::endl;
1021  for (auto sum = sumEmulCol->begin(currBx); sum != sumEmulCol->end(currBx); ++sum)
1022  edm::LogProblem("l1tcalol2ebec")
1023  << "Sum: type = " << sum->getType() << " "
1024  << "Et = " << sum->hwPt() << ", "
1025  << "eta = " << sum->hwEta() << ", "
1026  << "phi = " << sum->hwPhi() << std::endl;
1027 
1028 }
1029 
1030 
1032 {
1033  // store all jets to an edm file
1034  std::unique_ptr<l1t::JetBxCollection> mpjets_data (new l1t::JetBxCollection(0, currBx, currBx));
1035  std::unique_ptr<l1t::JetBxCollection> mpjets_emul (new l1t::JetBxCollection(0, currBx, currBx));
1036 
1037  for (auto jet = jetDataCol->begin(currBx); jet != jetDataCol->end(currBx); ++jet)
1038  mpjets_data->push_back(0, (*jet));
1039  for (auto jet = jetEmulCol->begin(currBx); jet != jetEmulCol->end(currBx); ++jet)
1040  mpjets_emul->push_back(0, (*jet));
1041 
1042  e.put(std::move(mpjets_data), "dataJet");
1043  e.put(std::move(mpjets_emul), "emulJet");
1044 
1045  // store all egs to an edm file
1046  std::unique_ptr<l1t::EGammaBxCollection> mpEGammas_data (new l1t::EGammaBxCollection(0, currBx, currBx));
1047  std::unique_ptr<l1t::EGammaBxCollection> mpEGammas_emul (new l1t::EGammaBxCollection(0, currBx, currBx));
1048 
1049  for (auto eg = egDataCol->begin(currBx); eg != egDataCol->end(currBx); ++eg)
1050  mpEGammas_data->push_back(0, (*eg));
1051  for (auto eg = egEmulCol->begin(currBx); eg != egEmulCol->end(currBx); ++eg)
1052  mpEGammas_emul->push_back(0, (*eg));
1053 
1054  e.put(std::move(mpEGammas_data), "dataEg");
1055  e.put(std::move(mpEGammas_emul), "emulEg");
1056 
1057  // store all taus to an edm file
1058  std::unique_ptr<l1t::TauBxCollection> mptaus_data (new l1t::TauBxCollection(0, currBx, currBx));
1059  std::unique_ptr<l1t::TauBxCollection> mptaus_emul (new l1t::TauBxCollection(0, currBx, currBx));
1060 
1061  for (auto tau = tauDataCol->begin(currBx); tau != tauDataCol->end(currBx); ++tau)
1062  mptaus_data->push_back(0, (*tau));
1063  for (auto tau = tauEmulCol->begin(currBx); tau != tauEmulCol->end(currBx); ++tau)
1064  mptaus_emul->push_back(0, (*tau));
1065 
1066  e.put(std::move(mptaus_data), "dataTau");
1067  e.put(std::move(mptaus_emul), "emulTau");
1068 
1069  // store all sums to an edm file
1070  std::unique_ptr<l1t::EtSumBxCollection> mpsums_data (new l1t::EtSumBxCollection(0, currBx, currBx));
1071  std::unique_ptr<l1t::EtSumBxCollection> mpsums_emul (new l1t::EtSumBxCollection(0, currBx, currBx));
1072 
1073  for (auto sum = sumDataCol->begin(currBx); sum != sumDataCol->end(currBx); ++sum)
1074  mpsums_data->push_back(0, (*sum));
1075  for (auto sum = sumEmulCol->begin(currBx); sum != sumEmulCol->end(currBx); ++sum)
1076  mpsums_emul->push_back(0, (*sum));
1077 
1078  e.put(std::move(mpsums_data), "dataEtSum");
1079  e.put(std::move(mpsums_emul), "emulEtSum");
1080 
1081  // store calorimeter towers
1082  std::unique_ptr<l1t::CaloTowerBxCollection> mptowers_data (new l1t::CaloTowerBxCollection(0, currBx, currBx));
1083  std::unique_ptr<l1t::CaloTowerBxCollection> mptowers_emul (new l1t::CaloTowerBxCollection(0, currBx, currBx));
1084 
1085  for (auto tower = caloTowerDataCol->begin(currBx); tower != caloTowerDataCol->end(currBx); ++tower)
1086  mptowers_data->push_back(0, (*tower));
1087  for (auto tower = caloTowerEmulCol->begin(currBx); tower != caloTowerEmulCol->end(currBx); ++tower)
1088  mptowers_emul->push_back(0, (*tower));
1089 
1090  e.put(std::move(mptowers_data), "dataCaloTower");
1091  e.put(std::move(mptowers_emul), "emulCaloTower");
1092 }
1093 
1095 
1096 #endif
void accuSort(std::vector< l1t::Jet > *jets)
BXVector< EGamma > EGammaBxCollection
Definition: EGamma.h:11
edm::Handle< l1t::EGammaBxCollection > egDataCol
const_iterator end(int bx) const
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
unsigned size(int bx) const
bool compareSums(const edm::Handle< l1t::EtSumBxCollection > &dataCol, const edm::Handle< l1t::EtSumBxCollection > &emulCol)
edm::Handle< l1t::EtSumBxCollection > sumDataCol
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static const int emul_to_data_sum_index_map[31]
Definition: CaloTools.h:124
void Merge(const std::vector< T > &aInput, std::vector< T > &aOutput)
Definition: Tau.h:21
bool compareJets(const edm::Handle< l1t::JetBxCollection > &dataCol, const edm::Handle< l1t::JetBxCollection > &emulCol)
edm::Handle< l1t::EtSumBxCollection > sumEmulCol
edm::EDGetToken calol2EGammaCollectionEmul
bool isEmpty(int bx) const
delete x;
Definition: CaloConfig.h:22
BXVector< Tau > TauBxCollection
Definition: Tau.h:11
edm::Handle< l1t::JetBxCollection > jetDataCol
edm::Handle< l1t::TauBxCollection > tauDataCol
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
Definition: Jet.h:21
BXVector< EtSum > EtSumBxCollection
Definition: EtSum.h:11
edm::Handle< l1t::CaloTowerBxCollection > caloTowerEmulCol
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetToken calol2EGammaCollectionData
compareCands< edm::Handle< L1GctJetCandCollection > > compareJets
vector< PseudoJet > jets
edm::Handle< l1t::EGammaBxCollection > egEmulCol
bool compareEGs(const edm::Handle< l1t::EGammaBxCollection > &dataCol, const edm::Handle< l1t::EGammaBxCollection > &emulCol)
edm::EDGetToken calol2CaloTowerCollectionData
BXVector< Jet > JetBxCollection
Definition: Jet.h:11
int hwPt() const
Definition: L1Candidate.h:48
BXVector< CaloTower > CaloTowerBxCollection
Definition: CaloTower.h:10
L1TStage2CaloLayer2Comp(const edm::ParameterSet &ps)
double b
Definition: hdecay.h:120
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
double a
Definition: hdecay.h:121
edm::EDGetToken calol2CaloTowerCollectionEmul
bool operator>(const l1t::Jet &a, l1t::Jet &b)
edm::Handle< l1t::TauBxCollection > tauEmulCol
EtSumType getType() const
Definition: EtSum.cc:37
edm::Handle< l1t::CaloTowerBxCollection > caloTowerDataCol
const_iterator begin(int bx) const
edm::Handle< l1t::JetBxCollection > jetEmulCol
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:20
bool compareTaus(const edm::Handle< l1t::TauBxCollection > &dataCol, const edm::Handle< l1t::TauBxCollection > &emulCol)
const T & at(int bx, unsigned i) const