Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:26

0001 #ifndef DEUTILS_H
0002 #define DEUTILS_H
0003 
0004 /*\class template DEutils
0005  *\description data|emulation auxiliary template
0006                collection operations struct
0007  *\author Nuno Leonardo (CERN)
0008  *\date 07.04
0009  */
0010 
0011 #include <iomanip>
0012 
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "L1Trigger/HardwareValidation/interface/DEtrait.h"
0015 
0016 template <typename T>
0017 struct DEutils {
0018   typedef typename T::size_type col_sz;
0019   typedef typename T::const_iterator col_cit;
0020   typedef typename T::iterator col_it;
0021   typedef DEtrait<T> de_trait;
0022   typedef typename de_trait::cand_type cand_type;
0023   typedef typename de_trait::coll_type coll_type;
0024 
0025 public:
0026   DEutils() {
0027     if (de_type() > 51)
0028       edm::LogError("L1ComparatorDeutilsCollType")  //throw cms::Exception("ERROR")
0029           << "DEutils::DEutils() :: "
0030           << "specialization is still missing for collection of type:" << de_type() << std::endl;
0031   }
0032   ~DEutils() {}
0033 
0034   inline int de_type() const { return de_trait::de_type(); }
0035   bool de_equal(const cand_type&, const cand_type&);
0036   bool de_equal_loc(const cand_type&, const cand_type&);
0037   bool de_nequal(const cand_type&, const cand_type&);
0038   bool de_nequal_loc(const cand_type&, const cand_type&);
0039   col_it de_find(col_it, col_it, const cand_type&);
0040   //col_it de_find_loc  ( col_it, col_it,  const cand_type&);
0041 
0042   std::string print(col_cit) const;
0043   bool is_empty(col_cit) const;
0044   std::string GetName(int i = 0) const;
0045 
0046   L1DataEmulDigi DEDigi(col_cit itd, col_cit itm, int ctype);
0047 };
0048 
0049 /// --- form de-digi ---
0050 
0051 template <typename T>
0052 L1DataEmulDigi DEutils<T>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0053   ///return empty digi by default
0054   return L1DataEmulDigi();
0055 }
0056 
0057 template <>
0058 inline L1DataEmulDigi DEutils<EcalTrigPrimDigiCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0059   int cid = de_type();
0060   int errt = aflag;
0061   //fill data if flagged, otherwise emulator
0062   double x1 = (aflag != 4) ? itd->id().iphi() : itm->id().iphi();
0063   double x2 = (aflag != 4) ? itd->id().ieta() : itm->id().ieta();
0064   L1DataEmulDigi digi(dedefs::ETP, cid, x1, x2, 0, errt);
0065   unsigned int dwS = (aflag == 4) ? 0 : itd->sample(itd->sampleOfInterest()).raw();
0066   unsigned int ewS = (aflag == 3) ? 0 : itm->sample(itm->sampleOfInterest()).raw();
0067   //dw1 &= 0x01ff; ew1 &= 0x01ff; //9-bit: fg(8),energy(7:0)
0068   unsigned int mask = 0x0eff;  //fg bit temporary(!) mask
0069   dwS &= mask;
0070   ewS &= mask;
0071   unsigned int dwI = (aflag == 4) ? 0 : itd->id().rawId();
0072   unsigned int ewI = (aflag == 3) ? 0 : itm->id().rawId();
0073   //dw2 &= 0xfe00ffff; ew2 &= 0xfe00ffff; //32-bit, reset unused (24:16)
0074   //merge id and sample words
0075   unsigned int dw = (dwI & 0xfe00ffff) | ((dwS & 0x000001ff) << 16);
0076   unsigned int ew = (ewI & 0xfe00ffff) | ((ewS & 0x000001ff) << 16);
0077   digi.setData(dw, ew);
0078   int de = (aflag == 4) ? 0 : itd->compressedEt();
0079   int ee = (aflag == 3) ? 0 : itm->compressedEt();
0080   digi.setRank((float)de, (float)ee);
0081   L1MonitorDigi dedata(dedefs::ETP, cid, itd->id().iphi(), itd->id().ieta(), 0, itd->compressedEt(), itd->id().rawId());
0082   L1MonitorDigi deemul(dedefs::ETP, cid, itm->id().iphi(), itm->id().ieta(), 0, itm->compressedEt(), itm->id().rawId());
0083   digi.setDEpair(dedata, deemul);
0084   return digi;
0085 }
0086 
0087 template <>
0088 inline L1DataEmulDigi DEutils<HcalTrigPrimDigiCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0089   int cid = de_type();
0090   int errt = aflag;
0091   double x1 = (aflag != 4) ? itd->id().iphi() : itm->id().iphi();
0092   double x2 = (aflag != 4) ? itd->id().ieta() : itm->id().ieta();
0093   L1DataEmulDigi digi(dedefs::HTP, cid, x1, x2, 0, errt);
0094   unsigned int dw = (aflag == 4) ? 0 : itd->t0().raw();
0095   unsigned int ew = (aflag == 3) ? 0 : itm->t0().raw();
0096   //16-bit; bits 10:9 not set(?);
0097   // bits 15:11 not accessible in emulator (slb/channel ids)
0098   unsigned int mask = 0x01ff;
0099   dw &= mask;
0100   ew &= mask;
0101   digi.setData(dw, ew);
0102   int de = (aflag == 4) ? 0 : itd->SOI_compressedEt();
0103   int ee = (aflag == 3) ? 0 : itm->SOI_compressedEt();
0104   digi.setRank((float)de, (float)ee);
0105   return digi;
0106 }
0107 
0108 template <>
0109 inline L1DataEmulDigi DEutils<L1CaloEmCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0110   int cid = de_type();
0111   int errt = aflag;
0112   double x1, x2, x3(0.);
0113   // global index ieta (0-21), iphi (0-17), card (0-6)
0114   x1 = (aflag != 4) ? itd->regionId().iphi() : itm->regionId().iphi();
0115   x2 = (aflag != 4) ? itd->regionId().ieta() : itm->regionId().ieta();
0116   x3 = (aflag != 4) ? itd->regionId().rctCard() : itm->regionId().rctCard();
0117   //alternative coordinates: rctCrate(), rctCard(), index()
0118   L1DataEmulDigi digi(dedefs::RCT, cid, x1, x2, x3, errt);
0119   unsigned int dw = itd->raw();
0120   unsigned int ew = itm->raw();
0121   dw &= 0x3ff;
0122   dw += (((itd->rctCrate()) & 0x1f) << 10);
0123   dw += (((itd->isolated() ? 1 : 0) & 0x1) << 15);
0124   dw += (((itd->index()) & 0x3) << 16);
0125   ew &= 0x3ff;
0126   ew += (((itm->rctCrate()) & 0x1f) << 10);
0127   ew += (((itm->isolated() ? 1 : 0) & 0x1) << 15);
0128   ew += (((itm->index()) & 0x3) << 16);
0129   dw = (aflag == 4) ? 0 : dw;
0130   ew = (aflag == 3) ? 0 : ew;
0131   /// bits: index(17:16) iso(15) crate(14:10)  +  card(9:7) region(6) rank (5:0)
0132   /// (rank & 0x3f) + ((region & 0x1)<<6) + ((card & 0x7)<<7)
0133   ///  + ((card & 0x1f)<<10) + ((0x1)<<15) + ((0x3)<<16)
0134   digi.setData(dw, ew);
0135   int de = (aflag == 4) ? 0 : itd->rank();
0136   int ee = (aflag == 3) ? 0 : itm->rank();
0137   digi.setRank((float)de, (float)ee);
0138   return digi;
0139 }
0140 
0141 template <>
0142 inline L1DataEmulDigi DEutils<L1CaloRegionCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0143   int cid = de_type();
0144   int errt = aflag;
0145   double x1, x2, x3(0.);
0146   x1 = (aflag != 4) ? itd->id().iphi() : itm->id().iphi();
0147   x2 = (aflag != 4) ? itd->id().ieta() : itm->id().ieta();
0148   x3 = (aflag != 4) ? itd->id().rctCard() : itm->id().rctCard();
0149   L1DataEmulDigi digi(dedefs::RCT, cid, x1, x2, x3, errt);
0150   unsigned int dw = itd->raw();
0151   unsigned int ew = itm->raw();
0152   unsigned int mask = 0x3fff;
0153   //mask (temporary) mip(12), quiet (13)
0154   mask = 0x0fff;
0155   dw &= mask;
0156   dw += (((itd->id().ieta()) & 0x1f) << 14);
0157   dw += (((itd->id().iphi()) & 0x1f) << 19);
0158   ew &= mask;
0159   ew += (((itm->id().ieta()) & 0x1f) << 14);
0160   ew += (((itm->id().iphi()) & 0x1f) << 19);
0161   dw = (aflag == 4) ? 0 : dw;
0162   ew = (aflag == 3) ? 0 : ew;
0163   /// bits: iphi(23:19), ieta(18:14) + quiet(13), mip(12), fg(11), ovf(10), et (9:0)
0164   digi.setData(dw, ew);
0165   int de = (aflag == 4) ? 0 : itd->et();
0166   int ee = (aflag == 3) ? 0 : itm->et();
0167   digi.setRank((float)de, (float)ee);
0168   return digi;
0169 }
0170 
0171 template <>
0172 inline L1DataEmulDigi DEutils<L1GctEmCandCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0173   int cid = de_type();
0174   int errt = aflag;
0175   //phi: 0..17; eta: 0..21
0176   // bring it to global coordinates
0177   double x1 = (aflag != 4) ? itd->regionId().iphi() : itm->regionId().iphi();
0178   double x2 = (aflag != 4) ? itd->regionId().ieta() : itm->regionId().ieta();
0179   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0180   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0181   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0182   dw &= 0x7fff;
0183   ew &= 0x7fff;  //15-bit
0184   digi.setData(dw, ew);
0185   int de = (aflag == 4) ? 0 : itd->rank();
0186   int ee = (aflag == 3) ? 0 : itm->rank();
0187   digi.setRank((float)de, (float)ee);
0188   return digi;
0189 }
0190 
0191 template <>
0192 inline L1DataEmulDigi DEutils<L1GctJetCandCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0193   int cid = de_type();
0194   int errt = aflag;
0195   //phi: 0..17; eta: -6..-0,+0..+6; eta sign:1(z-),0(z+)
0196   // bring it to global coordinates 0..21 below
0197   double x1 = (aflag != 4) ? itd->phiIndex() : itm->phiIndex();
0198   unsigned deta(0), eeta(0);
0199   if (!itd->isForward())
0200     deta = (itd->etaSign() == 1 ? 10 - (itd->etaIndex() & 0x7) : (itd->etaIndex() & 0x7) + 11);
0201   else
0202     deta = (itd->etaSign() == 1 ? 3 - (itd->etaIndex() & 0x7) : (itd->etaIndex() & 0x7) + 18);
0203   if (!itm->isForward())
0204     eeta = (itm->etaSign() == 1 ? 10 - (itm->etaIndex() & 0x7) : (itm->etaIndex() & 0x7) + 11);
0205   else
0206     eeta = (itm->etaSign() == 1 ? 3 - (itm->etaIndex() & 0x7) : (itm->etaIndex() & 0x7) + 18);
0207   double x2 = (aflag != 4) ? deta : eeta;
0208   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0209   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0210   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0211   dw &= 0x7fff;
0212   ew &= 0x7fff;  //15-bit
0213   digi.setData(dw, ew);
0214   int de = (aflag == 4) ? 0 : itd->rank();
0215   int ee = (aflag == 3) ? 0 : itm->rank();
0216   digi.setRank((float)de, (float)ee);
0217   return digi;
0218 }
0219 
0220 template <>
0221 inline L1DataEmulDigi DEutils<L1GctEtHadCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0222   int cid = de_type();
0223   int errt = aflag;
0224   double x1 = 0;
0225   double x2 = 0;  //no 'location' associated with candidates...
0226   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0227   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0228   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0229   dw &= 0x1fff;
0230   ew &= 0x1fff;  //13-bit
0231   digi.setData(dw, ew);
0232   int de = (aflag == 4) ? 0 : itd->et();
0233   int ee = (aflag == 3) ? 0 : itm->et();
0234   digi.setRank((float)de, (float)ee);
0235   return digi;
0236 }
0237 template <>
0238 inline L1DataEmulDigi DEutils<L1GctEtMissCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0239   int cid = de_type();
0240   int errt = aflag;
0241   double x1 = (aflag != 4) ? itd->phi() : itm->phi();
0242   double x2 = 0;  //no 'eta' associated with candidates...
0243   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0244   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0245   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0246   dw &= 0x8f1fff;
0247   ew &= 0x8f1fff;  //22-bit (bits 13,14,15 not set)
0248   digi.setData(dw, ew);
0249   int de = (aflag == 4) ? 0 : itd->et();
0250   int ee = (aflag == 3) ? 0 : itm->et();
0251   digi.setRank((float)de, (float)ee);
0252   return digi;
0253 }
0254 
0255 template <>
0256 inline L1DataEmulDigi DEutils<L1GctEtTotalCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0257   int cid = de_type();
0258   int errt = aflag;
0259   double x1 = 0;
0260   double x2 = 0;  //no 'location' associated with candidates...
0261   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0262   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0263   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0264   dw &= 0x1fff;
0265   ew &= 0x1fff;  //13-bit
0266   digi.setData(dw, ew);
0267   int de = (aflag == 4) ? 0 : itd->et();
0268   int ee = (aflag == 3) ? 0 : itm->et();
0269   digi.setRank((float)de, (float)ee);
0270   return digi;
0271 }
0272 template <>
0273 inline L1DataEmulDigi DEutils<L1GctHFBitCountsCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0274   int cid = de_type();
0275   int errt = aflag;
0276   double x1 = 0;
0277   double x2 = 0;  //no 'location' associated with candidates...
0278   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0279   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0280   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0281   digi.setData(dw, ew);
0282   int de = 0;
0283   int ee = 0;  //no 'rank' associated with candidates...
0284   digi.setRank((float)de, (float)ee);
0285   return digi;
0286 }
0287 template <>
0288 inline L1DataEmulDigi DEutils<L1GctHFRingEtSumsCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0289   int cid = de_type();
0290   int errt = aflag;
0291   double x1 = 0;
0292   double x2 = 0;  //no 'location' associated with candidates...
0293   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0294   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0295   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0296   digi.setData(dw, ew);
0297   int de = 0;
0298   int ee = 0;  //no 'rank' associated with candidates...
0299   digi.setRank((float)de, (float)ee);
0300   return digi;
0301 }
0302 template <>
0303 inline L1DataEmulDigi DEutils<L1GctHtMissCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0304   int cid = de_type();
0305   int errt = aflag;
0306   double x1 = (aflag != 4) ? itd->phi() : itm->phi();
0307   double x2 = 0;  //no 'eta' associated with candidates...
0308   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0309   unsigned int dw = (aflag == 4) ? 0 : itd->raw();
0310   unsigned int ew = (aflag == 3) ? 0 : itm->raw();
0311   dw &= 0x8f1fff;
0312   ew &= 0x8f1fff;  //22-bit (bits 13,14,15 not set)
0313   digi.setData(dw, ew);
0314   int de = (aflag == 4) ? 0 : itd->et();
0315   int ee = (aflag == 3) ? 0 : itm->et();
0316   digi.setRank((float)de, (float)ee);
0317   return digi;
0318 }
0319 
0320 template <>
0321 inline L1DataEmulDigi DEutils<L1GctJetCountsCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0322   int cid = de_type();
0323   int errt = aflag;
0324   double x1 = 0;
0325   double x2 = 0;  //no 'location' associated with candidates...
0326   L1DataEmulDigi digi(dedefs::GCT, cid, x1, x2, 0., errt);
0327   unsigned int dw = (aflag == 4) ? 0 : itd->raw0();  //raw0, raw1...
0328   unsigned int ew = (aflag == 3) ? 0 : itm->raw0();  //raw0, raw1...
0329   digi.setData(dw, ew);
0330   int de = 0;
0331   int ee = 0;  //no 'rank' associated with candidates...
0332   digi.setRank((float)de, (float)ee);
0333   return digi;
0334 }
0335 
0336 template <>
0337 inline L1DataEmulDigi DEutils<L1MuRegionalCandCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0338   int sid;
0339   switch (itd->type_idx()) {  // 0 DT, 1 bRPC, 2 CSC, 3 fRPC
0340     case 0:
0341       sid = dedefs::DTF;
0342       break;
0343     case 1:
0344       sid = dedefs::RPC;
0345       break;
0346     case 2:
0347       sid = dedefs::CTF;
0348       break;
0349     case 3:
0350       sid = dedefs::RPC;
0351       break;
0352     default:
0353       sid = -1;
0354   }
0355   int cid = de_type();
0356   int errt = aflag;
0357   //double x1 = (aflag!=4) ? itd->phiValue() : itm->phiValue();
0358   //double x2 = (aflag!=4) ? itd->etaValue() : itm->etaValue();
0359   double x1 = (aflag != 4) ? itd->phi_packed() : itm->phi_packed();
0360   double x2 = (aflag != 4) ? itd->eta_packed() : itm->eta_packed();
0361   L1DataEmulDigi digi(sid, cid, x1, x2, 0, errt);
0362   unsigned int dw = (aflag == 4) ? 0 : itd->getDataWord();
0363   unsigned int ew = (aflag == 3) ? 0 : itm->getDataWord();
0364   unsigned int mask = 0xffffffff;  //32-bit
0365   //RPC: mask bits 25-29 (including synch bits)
0366   // emulator doesn't set these bits (permanent masking)
0367   if (sid == dedefs::RPC)
0368     mask &= 0xc1ffffff;
0369   dw &= mask;
0370   ew &= mask;
0371   digi.setData(dw, ew);
0372   int de = (aflag == 4) ? 0 : itd->pt_packed();  //ptValue();
0373   int ee = (aflag == 3) ? 0 : itm->pt_packed();  //ptValue();
0374   digi.setRank((float)de, (float)ee);
0375   //note: phi,eta,pt 'values' not always set for all muon tf systems
0376   //(under discussion) need universal mechanism for setting up physical units
0377   if (false)  //check print
0378     std::cout << "L1DataEmulDigi DEutils<L1MuRegionalCandCollection>] dedigi info"
0379               //<< " phivalue:" << itd->phiValue()   << "," << itm->phiValue()
0380               //<< " etavalue:" << itd->etaValue()   << "," << itm->etaValue()
0381               << " phipackd:" << itd->phi_packed() << "," << itm->phi_packed() << " etapackd:" << itd->eta_packed()
0382               << "," << itm->eta_packed() << std::endl;
0383   return digi;
0384 }
0385 
0386 template <>
0387 inline L1DataEmulDigi DEutils<L1MuGMTCandCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0388   int cid = de_type();
0389   int errt = aflag;
0390   //double x1 = (aflag!=4) ? itd->phiValue() : itm->phiValue();
0391   //double x2 = (aflag!=4) ? itd->etaValue() : itm->etaValue();
0392   double x1 = (aflag != 4) ? itd->phiIndex() : itm->phiIndex();
0393   double x2 = (aflag != 4) ? itd->etaIndex() : itm->etaIndex();
0394   L1DataEmulDigi digi(dedefs::GMT, cid, x1, x2, 0, errt);
0395   unsigned int dw = (aflag == 4) ? 0 : itd->getDataWord();
0396   unsigned int ew = (aflag == 3) ? 0 : itm->getDataWord();
0397   unsigned int mask = 0x3ffffff;  //26-bit
0398   //mask bits 22 (isolation), 23 (mip) [not permanent!]
0399   mask &= (~(0x0c00000));
0400   dw &= mask;
0401   ew &= mask;
0402   digi.setData(dw, ew);
0403   int de = (aflag == 4) ? 0 : itd->ptIndex();  //ptValue();
0404   int ee = (aflag == 3) ? 0 : itm->ptIndex();  //ptValue();
0405   digi.setRank((float)de, (float)ee);
0406   if (false)  //check print
0407     std::cout << "l1dataemuldigi l1mugmtcandcoll type:"
0408               << cid
0409               //<< " eta:" << itd->etaValue() << ", " << itm->etaValue()
0410               //<< " phi:" << itd->phiValue() << ", " << itm->phiValue()
0411               << std::hex << " word d:" << dw << "e:" << ew << std::dec << std::endl;
0412   return digi;
0413 }
0414 
0415 template <>
0416 inline L1DataEmulDigi DEutils<L1MuDTChambPhDigiCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0417   int cid = de_type();
0418   int errt = aflag;
0419   double x1 = (aflag != 4) ? itd->scNum() : itm->scNum();
0420   double x2 = (aflag != 4) ? itd->whNum() : itm->whNum();
0421   double x3 = (aflag != 4) ? itd->stNum() : itm->stNum();
0422   L1DataEmulDigi digi(dedefs::DTP, cid, x1, x2, x3, errt);
0423   //other coordinate methods phi(), phiB()
0424   //note: no data word defined for candidate
0425   int dr = (aflag == 4) ? 0 : itd->code();
0426   int er = (aflag == 3) ? 0 : itm->code();
0427   digi.setRank((float)dr, (float)er);
0428   return digi;
0429 }
0430 
0431 template <>
0432 inline L1DataEmulDigi DEutils<L1MuDTChambThDigiCollection>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0433   int cid = de_type();
0434   int errt = aflag;
0435   double x1 = (aflag != 4) ? itd->scNum() : itm->scNum();
0436   double x2 = (aflag != 4) ? itd->whNum() : itm->whNum();
0437   double x3 = (aflag != 4) ? itd->stNum() : itm->stNum();
0438   L1DataEmulDigi digi(dedefs::DTP, cid, x1, x2, x3, errt);
0439   //note: no data word defined for candidate
0440   int dr(0), er(0);
0441   for (int i = 0; i < 7; i++) {
0442     if (itd->code(i) >= dr)
0443       dr = itd->quality(i);
0444     if (itm->code(i) >= er)
0445       er = itm->quality(i);
0446   }
0447   //alternatives: code() = quality() + positions()
0448   dr = (aflag == 4) ? 0 : dr;
0449   er = (aflag == 3) ? 0 : er;
0450   digi.setRank((float)dr, (float)er);
0451   return digi;
0452 }
0453 
0454 template <>
0455 inline L1DataEmulDigi DEutils<CSCCorrelatedLCTDigiCollection_>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0456   int cid = de_type();
0457   int errt = aflag;
0458   double x1 = (aflag != 4) ? itd->getStrip() : itm->getStrip();
0459   double x2 = (aflag != 4) ? itd->getKeyWG() : itm->getKeyWG();
0460   double x3 = (aflag != 4) ? itd->getTrknmb() : itm->getTrknmb();
0461   //multiple subsystem ctp,ctf
0462   L1DataEmulDigi digi(-1, cid, x1, x2, x3, errt);
0463   int dq = (aflag == 4) ? 0 : itd->getQuality();
0464   int eq = (aflag == 3) ? 0 : itm->getQuality();
0465   digi.setRank((float)dq, (float)eq);
0466   // Pack LCT digi members into 32-bit data words.
0467   static const int kValidBitWidth = 1;      // Reverse the order of the 1st
0468   static const int kQualityBitWidth = 4;    // frame to keep the valid bit
0469   static const int kPatternBitWidth = 4;    // first and quality second, as
0470   static const int kWireGroupBitWidth = 7;  // is done in ALCT and CLCT.
0471   static const int kHalfstripBitWidth = 8;
0472   static const int kBendBitWidth = 1;
0473   static const int kBxBitWidth = 1;
0474   // Use sync_err and bx0_local bits to store MPC link.
0475   static const int kMPCLinkBitWidth = 2;
0476   static const int kCSCIdBitWidth = 4;
0477   // While packing, check that the right number of bits is retained.
0478   unsigned shift = 0, dw = 0, ew = 0;
0479   dw = itd->isValid() & ((1 << kValidBitWidth) - 1);
0480   dw += (itd->getQuality() & ((1 << kQualityBitWidth) - 1)) << (shift += kValidBitWidth);
0481   dw += (itd->getPattern() & ((1 << kPatternBitWidth) - 1)) << (shift += kQualityBitWidth);
0482   dw += (itd->getKeyWG() & ((1 << kWireGroupBitWidth) - 1)) << (shift += kPatternBitWidth);
0483   dw += (itd->getStrip() & ((1 << kHalfstripBitWidth) - 1)) << (shift += kWireGroupBitWidth);
0484   dw += (itd->getBend() & ((1 << kBendBitWidth) - 1)) << (shift += kHalfstripBitWidth);
0485   dw += (itd->getBX() & ((1 << kBxBitWidth) - 1)) << (shift += kBendBitWidth);
0486   dw += (itd->getMPCLink() & ((1 << kMPCLinkBitWidth) - 1)) << (shift += kBxBitWidth);
0487   dw += (itd->getCSCID() & ((1 << kCSCIdBitWidth) - 1)) << (shift += kMPCLinkBitWidth);
0488   shift = 0;
0489   ew = itm->isValid() & ((1 << kValidBitWidth) - 1);
0490   ew += (itm->getQuality() & ((1 << kQualityBitWidth) - 1)) << (shift += kValidBitWidth);
0491   ew += (itm->getPattern() & ((1 << kPatternBitWidth) - 1)) << (shift += kQualityBitWidth);
0492   ew += (itm->getKeyWG() & ((1 << kWireGroupBitWidth) - 1)) << (shift += kPatternBitWidth);
0493   ew += (itm->getStrip() & ((1 << kHalfstripBitWidth) - 1)) << (shift += kWireGroupBitWidth);
0494   ew += (itm->getBend() & ((1 << kBendBitWidth) - 1)) << (shift += kHalfstripBitWidth);
0495   ew += (itm->getBX() & ((1 << kBxBitWidth) - 1)) << (shift += kBendBitWidth);
0496   ew += (itm->getMPCLink() & ((1 << kMPCLinkBitWidth) - 1)) << (shift += kBxBitWidth);
0497   ew += (itm->getCSCID() & ((1 << kCSCIdBitWidth) - 1)) << (shift += kMPCLinkBitWidth);
0498   digi.setData(dw, ew);
0499   return digi;
0500 }
0501 
0502 template <>
0503 inline L1DataEmulDigi DEutils<CSCALCTDigiCollection_>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0504   int cid = de_type();
0505   int errt = aflag;
0506   double x2 = (aflag != 4) ? itd->getKeyWG() : itm->getKeyWG();
0507   double x3 = (aflag != 4) ? itd->getTrknmb() : itm->getTrknmb();
0508   L1DataEmulDigi digi(dedefs::CTP, cid, 0, x2, x3, errt);
0509   int dq = (aflag == 4) ? 0 : itd->getQuality();
0510   int eq = (aflag == 3) ? 0 : itm->getQuality();
0511   digi.setRank((float)dq, (float)eq);
0512   // Pack anode digi members into 17-bit data words.
0513   static const int kValidBitWidth = 1;
0514   static const int kQualityBitWidth = 2;
0515   static const int kAccelBitWidth = 1;
0516   static const int kPatternBBitWidth = 1;
0517   static const int kWireGroupBitWidth = 7;
0518   static const int kBxBitWidth = 5;
0519   // While packing, check that the right number of bits is retained.
0520   unsigned shift = 0, dw = 0, ew = 0;
0521   dw = itd->isValid() & ((1 << kValidBitWidth) - 1);
0522   dw += (itd->getQuality() & ((1 << kQualityBitWidth) - 1)) << (shift += kValidBitWidth);
0523   dw += (itd->getAccelerator() & ((1 << kAccelBitWidth) - 1)) << (shift += kQualityBitWidth);
0524   dw += (itd->getCollisionB() & ((1 << kPatternBBitWidth) - 1)) << (shift += kAccelBitWidth);
0525   dw += (itd->getKeyWG() & ((1 << kWireGroupBitWidth) - 1)) << (shift += kPatternBBitWidth);
0526   dw += (itd->getBX() & ((1 << kBxBitWidth) - 1)) << (shift += kWireGroupBitWidth);
0527   shift = 0;
0528   ew = itm->isValid() & ((1 << kValidBitWidth) - 1);
0529   ew += (itm->getQuality() & ((1 << kQualityBitWidth) - 1)) << (shift += kValidBitWidth);
0530   ew += (itm->getAccelerator() & ((1 << kAccelBitWidth) - 1)) << (shift += kQualityBitWidth);
0531   ew += (itm->getCollisionB() & ((1 << kPatternBBitWidth) - 1)) << (shift += kAccelBitWidth);
0532   ew += (itm->getKeyWG() & ((1 << kWireGroupBitWidth) - 1)) << (shift += kPatternBBitWidth);
0533   ew += (itm->getBX() & ((1 << kBxBitWidth) - 1)) << (shift += kWireGroupBitWidth);
0534   digi.setData(dw, ew);
0535   return digi;
0536 }
0537 template <>
0538 inline L1DataEmulDigi DEutils<CSCCLCTDigiCollection_>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0539   int cid = de_type();
0540   int errt = aflag;
0541   double x1 = (aflag != 4) ? itd->getKeyStrip() : itm->getKeyStrip();
0542   double x3 = (aflag != 4) ? itd->getTrknmb() : itm->getTrknmb();
0543   L1DataEmulDigi digi(dedefs::CTP, cid, x1, 0, x3, errt);
0544   int dq = (aflag == 4) ? 0 : itd->getQuality();
0545   int eq = (aflag == 3) ? 0 : itm->getQuality();
0546   digi.setRank((float)dq, (float)eq);
0547   // Pack cathode digi members into 19-bit data words.
0548   static const int kValidBitWidth = 1;
0549   static const int kQualityBitWidth = 3;
0550   static const int kPatternBitWidth = 4;
0551   static const int kBendBitWidth = 1;
0552   static const int kHalfstripBitWidth = 5;
0553   static const int kCFEBBitWidth = 3;
0554   static const int kBxBitWidth = 2;
0555   // While packing, check that the right number of bits is retained.
0556   unsigned shift = 0, dw = 0, ew = 0;
0557   dw = itd->isValid() & ((1 << kValidBitWidth) - 1);
0558   dw += (itd->getQuality() & ((1 << kQualityBitWidth) - 1)) << (shift += kValidBitWidth);
0559   dw += (itd->getPattern() & ((1 << kPatternBitWidth) - 1)) << (shift += kQualityBitWidth);
0560   dw += (itd->getBend() & ((1 << kBendBitWidth) - 1)) << (shift += kPatternBitWidth);
0561   dw += (itd->getStrip() & ((1 << kHalfstripBitWidth) - 1)) << (shift += kBendBitWidth);
0562   dw += (itd->getCFEB() & ((1 << kCFEBBitWidth) - 1)) << (shift += kHalfstripBitWidth);
0563   dw += (itd->getBX() & ((1 << kBxBitWidth) - 1)) << (shift += kCFEBBitWidth);
0564   shift = 0;
0565   ew = itm->isValid() & ((1 << kValidBitWidth) - 1);
0566   ew += (itm->getQuality() & ((1 << kQualityBitWidth) - 1)) << (shift += kValidBitWidth);
0567   ew += (itm->getPattern() & ((1 << kPatternBitWidth) - 1)) << (shift += kQualityBitWidth);
0568   ew += (itm->getBend() & ((1 << kBendBitWidth) - 1)) << (shift += kPatternBitWidth);
0569   ew += (itm->getStrip() & ((1 << kHalfstripBitWidth) - 1)) << (shift += kBendBitWidth);
0570   ew += (itm->getCFEB() & ((1 << kCFEBBitWidth) - 1)) << (shift += kHalfstripBitWidth);
0571   ew += (itm->getBX() & ((1 << kBxBitWidth) - 1)) << (shift += kCFEBBitWidth);
0572   digi.setData(dw, ew);
0573   return digi;
0574 }
0575 
0576 template <>
0577 inline L1DataEmulDigi DEutils<L1CSCSPStatusDigiCollection_>::DEDigi(col_cit itd, col_cit itm, int aflag) {
0578   int cid = de_type();
0579   int errt = aflag;
0580   double x1;  //sector/slot
0581   x1 = (aflag != 4) ? itd->slot() : itm->slot();
0582   //sector-slot map to be in principle to be provided from event setup
0583   //int de_cscstatus_slot2sector[22] =
0584   // {0,0,0,0,0, 0,1,2,3,4, 5,6,0,0,0, 0,7,8,9,10,  11,12};
0585   //x1 = (aflag!=4) ? slot2sector[itd->slot()] : slot2sector[itm->slot()];
0586   L1DataEmulDigi digi(dedefs::CTF, cid, x1, 0, 0, errt);
0587   //note: no data word and rank defined for candidate
0588   return digi;
0589 }
0590 
0591 /// --- find candidate ---
0592 
0593 template <typename T>
0594 typename DEutils<T>::col_it DEutils<T>::de_find(col_it first, col_it last, const cand_type& value) {
0595   for (; first != last; first++)
0596     if (de_equal(*first, value))
0597       break;
0598   return first;
0599 }
0600 
0601 /*
0602 template <typename T> typename 
0603 DEutils<T>::col_it DEutils<T>::de_find_loc( col_it first, col_it last, const cand_type& value ) {
0604   for ( ;first!=last; first++) 
0605     if ( de_equal_loc(*first,value) ) break;
0606   return first;
0607 }
0608 */
0609 
0610 /// --- candidate match definition ---
0611 
0612 template <typename T>
0613 bool DEutils<T>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0614   //declare candidate matching by default
0615   return true;
0616 }
0617 template <typename T>
0618 bool DEutils<T>::de_nequal(const cand_type& lhs, const cand_type& rhs) {
0619   return !de_equal(lhs, rhs);
0620 }
0621 
0622 template <>
0623 inline bool DEutils<EcalTrigPrimDigiCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0624   bool val = true;
0625   unsigned int mask = 0x0fff;  //keep only ttf[11:9], fg [8], Et [7:0]
0626   mask &= 0x0eff;              //fg bit temporary(!) mask
0627   val &= ((lhs[lhs.sampleOfInterest()].raw() & mask) == (rhs[rhs.sampleOfInterest()].raw() & mask));
0628   val &= (lhs.id().rawId() == rhs.id().rawId());
0629   return val;
0630 }
0631 
0632 template <>
0633 inline bool DEutils<HcalTrigPrimDigiCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0634   bool val = true;
0635   unsigned int mask = 0x01ff;
0636   val &= ((lhs.t0().raw() & mask) == (rhs.t0().raw() & mask));
0637   val &= (lhs.id().rawId() == rhs.id().rawId());
0638   return val;
0639 }
0640 
0641 template <>
0642 inline bool DEutils<L1CaloEmCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0643   bool val = true;
0644   val &= (lhs.raw() == rhs.raw());
0645   val &= (lhs.rctCrate() == rhs.rctCrate());
0646   val &= (lhs.isolated() == rhs.isolated());
0647   val &= (lhs.index() == rhs.index());
0648   //val &= (lhs.bx()       == rhs.bx()      );
0649   return val;
0650 }
0651 
0652 template <>
0653 inline bool DEutils<L1CaloRegionCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0654   bool val = true;
0655   val &= (lhs.et() == rhs.et());
0656   val &= (lhs.rctCrate() == rhs.rctCrate());
0657   val &= (lhs.rctRegionIndex() == rhs.rctRegionIndex());
0658   val &= (lhs.id().isHf() == rhs.id().isHf());
0659   if (!lhs.id().isHf()) {
0660     val &= (lhs.overFlow() == rhs.overFlow());
0661     val &= (lhs.tauVeto() == rhs.tauVeto());
0662     //mask temporarily (!) mip and quiet bits
0663     //val &= (lhs.mip()       == rhs.mip()      );
0664     //val &= (lhs.quiet()     == rhs.quiet()    );
0665     val &= (lhs.rctCard() == rhs.rctCard());
0666   } else {
0667     val &= (lhs.fineGrain() == rhs.fineGrain());
0668   }
0669   return val;
0670 }
0671 
0672 template <>
0673 inline bool DEutils<L1GctEmCandCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0674   return lhs == rhs;
0675 }
0676 
0677 template <>
0678 inline bool DEutils<L1GctJetCandCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0679   return lhs == rhs;
0680 }
0681 
0682 template <>
0683 inline bool DEutils<L1GctEtHadCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0684   return lhs == rhs;
0685 }
0686 template <>
0687 inline bool DEutils<L1GctEtMissCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0688   return lhs == rhs;
0689 }
0690 template <>
0691 inline bool DEutils<L1GctEtTotalCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0692   return lhs == rhs;
0693 }
0694 template <>
0695 inline bool DEutils<L1GctHtMissCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0696   return lhs == rhs;
0697 }
0698 template <>
0699 inline bool DEutils<L1GctHFRingEtSumsCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0700   return lhs == rhs;
0701 }
0702 template <>
0703 inline bool DEutils<L1GctHFBitCountsCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0704   return lhs == rhs;
0705 }
0706 template <>
0707 inline bool DEutils<L1GctJetCountsCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0708   return lhs == rhs;
0709 }
0710 
0711 template <>
0712 inline bool DEutils<L1MuDTChambPhDigiCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0713   bool val = true;
0714   val &= (lhs.whNum() == rhs.whNum());
0715   val &= (lhs.scNum() == rhs.scNum());
0716   val &= (lhs.stNum() == rhs.stNum());
0717   //val &= (lhs.phi()   ==rhs.phi()   );
0718   //val &= (lhs.phiB()  ==rhs.phiB()  );
0719   val &= (lhs.code() == rhs.code());
0720   val &= (lhs.Ts2Tag() == rhs.Ts2Tag());
0721   //val &= (lhs.BxCnt() ==rhs.BxCnt() );
0722   //val &= (lhs.bxNum() ==rhs.bxNum() );
0723   return val;
0724 }
0725 
0726 template <>
0727 inline bool DEutils<L1MuDTChambThDigiCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0728   bool val = true;
0729   val &= (lhs.whNum() == rhs.whNum());
0730   val &= (lhs.scNum() == rhs.scNum());
0731   val &= (lhs.stNum() == rhs.stNum());
0732   //for(int i=0; i<7; i++) {
0733   //  val &= (lhs.code(i)    ==rhs.code(i)    );
0734   //  val &= (lhs.position(i)==rhs.position(i));
0735   //  val &= (lhs.quality(i) ==rhs.quality(i) );
0736   //}
0737   //val &= (lhs.bxNum() ==rhs.bxNum() );
0738   return val;
0739 }
0740 
0741 template <>
0742 inline bool DEutils<L1MuRegionalCandCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0743   bool val = true;
0744   val &= (lhs.type_idx() == rhs.type_idx());
0745   val &= (lhs.bx() == rhs.bx());
0746   if (!val)
0747     return val;
0748   unsigned int dw = lhs.getDataWord();
0749   unsigned int ew = rhs.getDataWord();
0750   unsigned int mask = 0xffffffff;  //32-bit
0751   //RPC: mask bits 25-29 (including synch bits)
0752   // emulator doesn't set these bits (permanent masking)
0753   // 0 DT, 1 bRPC, 2 CSC, 3 fRPC
0754   if (rhs.type_idx() == 1 || rhs.type_idx() == 3)
0755     mask &= 0xc1ffffff;
0756   dw &= mask;
0757   ew &= mask;
0758   val &= (dw == ew);
0759   //val &= (lhs.getDataWord() == rhs.getDataWord() );
0760   //check whether collections being compared refer to same system and bx!
0761   return val;
0762 }
0763 
0764 template <>
0765 inline bool DEutils<L1MuGMTCandCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0766   //return (lhs.getDataWord() == rhs.getDataWord() );
0767   //return lhs==rhs; //(dataword,bx..)
0768   bool val = true;
0769   unsigned int dw = rhs.getDataWord();
0770   unsigned int ew = lhs.getDataWord();
0771   unsigned int mask = 0x3ffffff;  //26-bit
0772   //mask bits 22 (isolation), 23 (mip) [not permanent!]
0773   mask &= (~(0x0c00000));
0774   dw &= mask;
0775   ew &= mask;
0776   val &= (dw == ew);
0777   return val;
0778 }
0779 
0780 template <>
0781 inline bool DEutils<CSCCorrelatedLCTDigiCollection_>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0782   // Exclude track number from comparison since it is only meaningful for
0783   // LCTs upstream of the MPC but not downstream (the latter ones are
0784   // unpacked by the CSC TF unpacker).
0785   bool val = true;
0786   val &= (lhs.isValid() == rhs.isValid());
0787   val &= (lhs.getQuality() == rhs.getQuality());
0788   val &= (lhs.getKeyWG() == rhs.getKeyWG());
0789   val &= (lhs.getStrip() == rhs.getStrip());
0790   val &= (lhs.getPattern() == rhs.getPattern());
0791   val &= (lhs.getBend() == rhs.getBend());
0792   val &= (lhs.getBX() == rhs.getBX());
0793   val &= (lhs.getMPCLink() == rhs.getMPCLink());
0794   val &= (lhs.getCSCID() == rhs.getCSCID());
0795   return val;
0796   //return lhs==rhs;
0797 }
0798 template <>
0799 inline bool DEutils<CSCALCTDigiCollection_>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0800   return lhs == rhs;
0801 }
0802 template <>
0803 inline bool DEutils<CSCCLCTDigiCollection_>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0804   return lhs == rhs;
0805 }
0806 template <>
0807 inline bool DEutils<L1CSCSPStatusDigiCollection_>::de_equal(const cand_type& lhs, const cand_type& rhs) {
0808   bool val = true;
0809   val &= (lhs.slot() == rhs.slot());
0810   val &= (lhs.BXN() == rhs.BXN());
0811   val &= (lhs.FMM() == rhs.FMM());
0812   val &= (lhs.SEs() == rhs.SEs());
0813   val &= (lhs.SMs() == rhs.SMs());
0814   val &= (lhs.BXs() == rhs.BXs());
0815   val &= (lhs.AFs() == rhs.AFs());
0816   val &= (lhs.VPs() == rhs.VPs());
0817   return val;
0818 }
0819 
0820 /// --- candidate location-match definition ---
0821 
0822 template <typename T>
0823 bool DEutils<T>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0824   //declare candidate matching by default
0825   return true;
0826 }
0827 template <typename T>
0828 bool DEutils<T>::de_nequal_loc(const cand_type& lhs, const cand_type& rhs) {
0829   return !de_equal_loc(lhs, rhs);
0830 }
0831 
0832 template <>
0833 inline bool DEutils<EcalTrigPrimDigiCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0834   bool val = true;
0835   val &= (lhs.id().zside() == rhs.id().zside());
0836   val &= (lhs.id().ietaAbs() == rhs.id().ietaAbs());
0837   val &= (lhs.id().iphi() == rhs.id().iphi());
0838   return val;
0839 }
0840 
0841 template <>
0842 inline bool DEutils<HcalTrigPrimDigiCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0843   bool val = true;
0844   val &= (lhs.id().zside() == rhs.id().zside());
0845   val &= (lhs.id().ietaAbs() == rhs.id().ietaAbs());
0846   val &= (lhs.id().iphi() == rhs.id().iphi());
0847   return val;
0848 }
0849 
0850 template <>
0851 inline bool DEutils<L1CaloEmCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0852   bool val = true;
0853   val &= (lhs.rctCrate() == rhs.rctCrate());
0854   val &= (lhs.rctCard() == rhs.rctCard());
0855   val &= (lhs.rctRegion() == rhs.rctRegion());
0856   return val;
0857 }
0858 
0859 template <>
0860 inline bool DEutils<L1CaloRegionCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0861   bool val = true;
0862   val &= (lhs.rctCrate() == rhs.rctCrate());
0863   val &= (lhs.id().isHf() == rhs.id().isHf());
0864   if (!lhs.id().isHf())
0865     val &= (lhs.rctCard() == rhs.rctCard());
0866   val &= (lhs.rctRegionIndex() == rhs.rctRegionIndex());
0867   return val;
0868 }
0869 
0870 template <>
0871 inline bool DEutils<L1GctEmCandCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0872   bool val = true;
0873   val &= (lhs.etaIndex() == rhs.etaIndex());
0874   val &= (lhs.phiIndex() == rhs.phiIndex());
0875   return val;
0876 }
0877 template <>
0878 inline bool DEutils<L1GctJetCandCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0879   bool val = true;
0880   val &= (lhs.etaIndex() == rhs.etaIndex());
0881   val &= (lhs.phiIndex() == rhs.phiIndex());
0882   return val;
0883 }
0884 
0885 template <>
0886 inline bool DEutils<L1GctEtHadCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0887   return true;  // no associated location defined
0888 }
0889 template <>
0890 inline bool DEutils<L1GctEtMissCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0891   bool val = true;
0892   val &= (lhs.phi() == rhs.phi());
0893   return val;
0894 }
0895 template <>
0896 inline bool DEutils<L1GctEtTotalCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0897   return true;  // no associated location defined
0898 }
0899 template <>
0900 inline bool DEutils<L1GctHtMissCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0901   bool val = true;
0902   val &= (lhs.phi() == rhs.phi());
0903   return val;
0904 }
0905 template <>
0906 inline bool DEutils<L1GctHFRingEtSumsCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0907   return true;  // no associated location defined
0908 }
0909 template <>
0910 inline bool DEutils<L1GctHFBitCountsCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0911   return true;  // no associated location defined
0912 }
0913 template <>
0914 inline bool DEutils<L1GctJetCountsCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0915   return true;  // no associated location defined
0916 }
0917 
0918 template <>
0919 inline bool DEutils<L1MuRegionalCandCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0920   bool val = true;
0921   val &= (lhs.phi_packed() == rhs.phi_packed());
0922   val &= (lhs.eta_packed() == rhs.eta_packed());
0923   //val &= (lhs.type_idx() == rhs.type_idx());
0924   //val &= (lhs.bx()       == rhs.bx());
0925   return val;
0926 }
0927 
0928 template <>
0929 inline bool DEutils<L1MuGMTCandCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0930   bool val = true;
0931   val &= (lhs.phiIndex() == rhs.phiIndex());
0932   val &= (lhs.etaIndex() == rhs.etaIndex());
0933   return val;
0934 }
0935 
0936 template <>
0937 inline bool DEutils<L1MuDTChambPhDigiCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0938   bool val = true;
0939   val &= (lhs.whNum() == rhs.whNum());
0940   val &= (lhs.scNum() == rhs.scNum());
0941   val &= (lhs.stNum() == rhs.stNum());
0942   //val &= (lhs.phi()   ==rhs.phi()   );
0943   //val &= (lhs.phiB()  ==rhs.phiB()  );
0944   //val &= (lhs.bxNum() ==rhs.bxNum() );
0945   return val;
0946 }
0947 
0948 template <>
0949 inline bool DEutils<L1MuDTChambThDigiCollection>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0950   bool val = true;
0951   val &= (lhs.whNum() == rhs.whNum());
0952   val &= (lhs.scNum() == rhs.scNum());
0953   val &= (lhs.stNum() == rhs.stNum());
0954   //val &= (lhs.bxNum() ==rhs.bxNum() );
0955   return val;
0956 }
0957 
0958 template <>
0959 inline bool DEutils<CSCCorrelatedLCTDigiCollection_>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0960   bool val = true;
0961   val &= (lhs.getCSCID() == rhs.getCSCID());
0962   val &= (lhs.getStrip() == rhs.getStrip());
0963   val &= (lhs.getKeyWG() == rhs.getKeyWG());
0964   return val;
0965 }
0966 
0967 template <>
0968 inline bool DEutils<CSCALCTDigiCollection_>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0969   bool val = true;
0970   val &= (lhs.getTrknmb() == rhs.getTrknmb());
0971   val &= (lhs.getKeyWG() == rhs.getKeyWG());
0972   return val;
0973 }
0974 template <>
0975 inline bool DEutils<CSCCLCTDigiCollection_>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0976   bool val = true;
0977   val &= (lhs.getTrknmb() == rhs.getTrknmb());
0978   val &= (lhs.getKeyStrip() == rhs.getKeyStrip());
0979   return val;
0980 }
0981 template <>
0982 inline bool DEutils<L1CSCSPStatusDigiCollection_>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
0983   bool val = true;
0984   val &= (lhs.slot() == rhs.slot());
0985   return val;
0986 }
0987 
0988 /// --- candidate emptiness definition ---
0989 
0990 template <typename T>
0991 bool DEutils<T>::is_empty(col_cit it) const {
0992   //declare candidate non-empty by default
0993   return false;
0994 }
0995 
0996 template <>
0997 inline bool DEutils<EcalTrigPrimDigiCollection>::is_empty(col_cit it) const {
0998   bool val = false;
0999   unsigned int raw = it->sample(it->sampleOfInterest()).raw();
1000   unsigned int mask = 0x0fff;
1001   mask = 0x0eff;  //fg bit temporary(!) mask
1002   raw &= mask;
1003   val |= (raw == 0);
1004   if (val)
1005     return val;
1006   unsigned int ttf = it->ttFlag();
1007   val |= ((ttf != 0x1) && (ttf != 0x3));  //compare only if ttf is 1 or 3
1008   return val;
1009   //  return ( it->size()==0 || it->sample(it->sampleOfInterest()).raw()==0);
1010 }
1011 
1012 template <>
1013 inline bool DEutils<HcalTrigPrimDigiCollection>::is_empty(col_cit it) const {
1014   unsigned int mask = 0x01ff;
1015   return (it->size() == 0 || ((it->t0().raw() & mask) == 0) || it->SOI_compressedEt() == 0);
1016 }
1017 
1018 template <>
1019 inline bool DEutils<L1CaloEmCollection>::is_empty(col_cit it) const {
1020   return ((it->rank()) == 0);
1021   //return it->empty();
1022 }
1023 
1024 template <>
1025 inline bool DEutils<L1CaloRegionCollection>::is_empty(col_cit it) const {
1026   return ((it->et()) == 0);
1027   //return it->empty();
1028 }
1029 
1030 template <>
1031 inline bool DEutils<L1GctEmCandCollection>::is_empty(col_cit it) const {
1032   return (it->empty());
1033 }
1034 
1035 template <>
1036 inline bool DEutils<L1GctJetCandCollection>::is_empty(col_cit it) const {
1037   return (it->empty());
1038 }
1039 
1040 template <>
1041 inline bool DEutils<L1GctEtHadCollection>::is_empty(col_cit it) const {
1042   return (it->empty());
1043 }
1044 template <>
1045 inline bool DEutils<L1GctEtMissCollection>::is_empty(col_cit it) const {
1046   return (it->empty());
1047 }
1048 template <>
1049 inline bool DEutils<L1GctEtTotalCollection>::is_empty(col_cit it) const {
1050   return (it->empty());
1051 }
1052 template <>
1053 inline bool DEutils<L1GctHtMissCollection>::is_empty(col_cit it) const {
1054   return (it->empty());
1055 }
1056 template <>
1057 inline bool DEutils<L1GctHFRingEtSumsCollection>::is_empty(col_cit it) const {
1058   return (it->empty());
1059 }
1060 template <>
1061 inline bool DEutils<L1GctHFBitCountsCollection>::is_empty(col_cit it) const {
1062   return (it->empty());
1063 }
1064 template <>
1065 inline bool DEutils<L1GctJetCountsCollection>::is_empty(col_cit it) const {
1066   return (it->empty());
1067 }
1068 
1069 template <>
1070 inline bool DEutils<L1MuDTChambPhDigiCollection>::is_empty(col_cit it) const {
1071   return (it->bxNum() != 0 || it->code() == 7);
1072   //return (it->qualityCode() == 7);
1073   //return  false;
1074 }
1075 template <>
1076 inline bool DEutils<L1MuDTChambThDigiCollection>::is_empty(col_cit it) const {
1077   return (it->whNum() == 0 && it->scNum() == 0 && it->stNum() == 0);  //tmp!
1078   //return  false;
1079 }
1080 
1081 template <>
1082 inline bool DEutils<L1MuRegionalCandCollection>::is_empty(col_cit it) const {
1083   //note: following call used to give trouble sometimes
1084 
1085   //restrict further processing to bx==0 for RPC
1086   if (it->type_idx() == 1 || it->type_idx() == 3)  //rpc
1087     if (it->bx() != 0)
1088       return true;
1089 
1090   return (it->empty());
1091   //virtual bool empty() const { return readDataField( PT_START, PT_LENGTH) == 0; }
1092   //return  (it->getDataWord()==0);
1093   //return  (it->pt_packed()==0);
1094 }
1095 
1096 template <>
1097 inline bool DEutils<L1MuGMTCandCollection>::is_empty(col_cit it) const {
1098   return (it->empty());
1099   //return (it->ptIndex()==0);
1100   //return  (it->getDataWord()==0);
1101 }
1102 
1103 template <>
1104 inline bool DEutils<CSCCorrelatedLCTDigiCollection_>::is_empty(col_cit it) const {
1105   return !(it->isValid());
1106 }
1107 template <>
1108 inline bool DEutils<CSCALCTDigiCollection_>::is_empty(col_cit it) const {
1109   return !(it->isValid());
1110 }
1111 template <>
1112 inline bool DEutils<CSCCLCTDigiCollection_>::is_empty(col_cit it) const {
1113   return !(it->isValid());
1114 }
1115 
1116 template <>
1117 inline bool DEutils<L1CSCSPStatusDigiCollection_>::is_empty(col_cit it) const {
1118   unsigned data = it->slot() | it->BXN() | it->FMM() | it->SEs() | it->SMs() | it->BXs() | it->AFs() | it->VPs();
1119   return data == 0;
1120 }
1121 
1122 /// --- print candidate ---
1123 
1124 template <typename T>
1125 std::string DEutils<T>::print(col_cit it) const {
1126   std::stringstream ss;
1127   ss << "[DEutils<T>::print()] specialization still missing for collection!";
1128   //ss << *it; // default
1129   ss << std::endl;
1130   return ss.str();
1131 }
1132 
1133 template <>
1134 inline std::string DEutils<EcalTrigPrimDigiCollection>::print(col_cit it) const {
1135   std::stringstream ss;
1136   ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->sample(it->sampleOfInterest()).raw()
1137      << std::setfill(' ') << std::dec << ", et:" << std::setw(3) << it->compressedEt() << ", fg:" << std::setw(1)
1138      << it->fineGrain() << ", ttf:" << std::setw(2) << it->ttFlag()
1139      << ", sdet:" << ((it->id().subDet() == EcalBarrel) ? ("Barrel") : ("Endcap"))
1140      << ", iz:" << ((it->id().zside() > 0) ? ("+") : ("-")) << ", ieta:" << std::setw(2) << it->id().ietaAbs()
1141      << ", iphi:" << std::setw(2)
1142      << it->id().iphi()
1143      //<< "\n\t: " << *it
1144      << std::endl;
1145   return ss.str();
1146 }
1147 
1148 template <>
1149 inline std::string DEutils<HcalTrigPrimDigiCollection>::print(col_cit it) const {
1150   std::stringstream ss;
1151   ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->t0().raw() << std::setfill(' ') << std::dec
1152      << ", et:" << std::setw(3) << it->SOI_compressedEt() << ", fg:" << std::setw(1) << it->SOI_fineGrain()
1153      << ", sdet:" << it->id().subdet() << ", iz:" << ((it->id().zside() > 0) ? ("+") : ("-"))
1154      << ", ieta:" << std::setw(2) << it->id().ietaAbs() << ", iphi:" << std::setw(2) << it->id().iphi() << std::endl;
1155   //ss << *it << std::endl;
1156   return ss.str();
1157 }
1158 
1159 template <>
1160 inline std::string DEutils<L1CaloEmCollection>::print(col_cit it) const {
1161   std::stringstream ss;
1162   ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->raw() << ", rank=0x" << std::setw(2) << std::hex
1163      << it->rank() << std::setfill(' ') << std::dec << ", region:" << std::setw(1) << it->rctRegion()
1164      << ", card:" << std::setw(1) << it->rctCard() << ", crate:" << std::setw(2) << it->rctCrate()
1165      << ", ieta:" << std::setw(2) << it->regionId().ieta()  //0..21
1166      << ", iphi:" << std::setw(2)
1167      << it->regionId().iphi()  //0..17
1168                                //<< ", eta:"   << std::setw(2) << it->regionId().rctEta() //0..10
1169                                //<< ", phi:"   << std::setw(2) << it->regionId().rctPhi() //0..1
1170      << ", iso:" << std::setw(1) << it->isolated() << ", index:" << std::setw(1) << it->index() << ", bx:" << it->bx()
1171      << std::endl;
1172   //ss << *it;
1173   return ss.str();
1174 }
1175 
1176 template <>
1177 inline std::string DEutils<L1CaloRegionCollection>::print(col_cit it) const {
1178   std::stringstream ss;
1179   ss << "L1CaloRegion:"
1180      << " et=" << it->et() << " o/f=" << it->overFlow() << " f/g=" << it->fineGrain() << " tau=" << it->tauVeto()
1181      << " rct(crate=" << it->rctCrate() << " card=" << it->rctCard() << " rgn=" << it->rctRegionIndex()
1182      << " eta=" << it->rctEta() << " phi=" << it->rctPhi() << ")\n\t\t"
1183      << "gct(eta=" << it->gctEta() << " phi=" << it->gctPhi() << ")" << std::hex << " cap_block=" << it->capBlock()
1184      << std::dec << " index=" << it->capIndex() << " bx=" << it->bx() << std::endl;
1185   //ss << *it; ///replace due to too long unformatted verbose
1186   //note: raw() data accessor missing in dataformats
1187   return ss.str();
1188 }
1189 
1190 template <>
1191 inline std::string DEutils<L1GctEmCandCollection>::print(col_cit it) const {
1192   std::stringstream ss;
1193   //get rct index
1194   //int ieta = (it->etaIndex()&0x7); ieta = it->etaSign() ? 10-ieta:11+ieta;
1195   ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->raw() << ", rank=0x" << std::setw(2) << std::hex
1196      << it->rank() << std::setfill(' ') << std::dec << ", etaSign:" << it->etaSign()
1197      << ", eta:" << (it->etaIndex() & 0x7)                        //0..6
1198      << ", phi:" << std::setw(2) << it->phiIndex()                //0..17
1199      << " (ieta:" << std::setw(2) << it->regionId().ieta()        //0..21
1200      << ",iphi:" << std::setw(2) << it->regionId().iphi() << ")"  //0..17
1201      << ", iso:" << it->isolated() << ", cap block:" << std::setw(3) << it->capBlock() << ", index:" << it->capIndex()
1202      << ", bx:" << it->bx() << std::endl;
1203   //<< " " << *it << std::dec << std::endl;
1204   return ss.str();
1205 }
1206 
1207 /*notes on rct/gct indices
1208  ieta: 0 .. 11 .. 21  ->  rctEta: 10 .. 0 .. 10   ie: ieta<11?10-ieta:ieta-11
1209  gct from rct  eta: rctEta&0x7 (7..0..7) | etaSign(==ieta<11)
1210  rct from gct  eta: +-(0..7) -> 3..18  ie: sign?10-eta:eta+11
1211  rct iphi = gct phi
1212 */
1213 
1214 template <>
1215 inline std::string DEutils<L1GctJetCandCollection>::print(col_cit it) const {
1216   std::stringstream ss;
1217   ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->raw() << " " << *it << std::dec << std::endl;
1218   return ss.str();
1219 }
1220 template <>
1221 inline std::string DEutils<L1GctEtHadCollection>::print(col_cit it) const {
1222   std::stringstream ss;
1223   ss << *it;
1224   return ss.str();
1225 }
1226 template <>
1227 inline std::string DEutils<L1GctEtMissCollection>::print(col_cit it) const {
1228   std::stringstream ss;
1229   ss << *it;
1230   return ss.str();
1231 }
1232 template <>
1233 inline std::string DEutils<L1GctEtTotalCollection>::print(col_cit it) const {
1234   std::stringstream ss;
1235   ss << *it;
1236   return ss.str();
1237 }
1238 template <>
1239 inline std::string DEutils<L1GctHtMissCollection>::print(col_cit it) const {
1240   std::stringstream ss;
1241   ss << *it;
1242   return ss.str();
1243 }
1244 template <>
1245 inline std::string DEutils<L1GctHFRingEtSumsCollection>::print(col_cit it) const {
1246   std::stringstream ss;
1247   ss << *it;
1248   return ss.str();
1249 }
1250 template <>
1251 inline std::string DEutils<L1GctHFBitCountsCollection>::print(col_cit it) const {
1252   std::stringstream ss;
1253   ss << *it;
1254   return ss.str();
1255 }
1256 template <>
1257 inline std::string DEutils<L1GctJetCountsCollection>::print(col_cit it) const {
1258   std::stringstream ss;
1259   ss << *it;
1260   return ss.str();
1261 }
1262 
1263 template <>
1264 inline std::string DEutils<L1MuDTChambPhDigiCollection>::print(col_cit it) const {
1265   std::stringstream ss;
1266   ss << ""
1267      << " bxNum:" << it->bxNum() << " whNum:" << it->whNum() << " scNum:" << it->scNum() << " stNum:" << it->stNum()
1268      << " phi:" << it->phi() << " phiB:" << it->phiB() << " code:" << it->code() << " Ts2Tag:" << it->Ts2Tag()
1269      << " BxCnt:" << it->BxCnt() << std::endl;
1270   //nb: operator << not implemented in base class L1MuDTChambPhDigi
1271   return ss.str();
1272 }
1273 
1274 template <>
1275 inline std::string DEutils<L1MuDTChambThDigiCollection>::print(col_cit it) const {
1276   std::stringstream ss;
1277   ss << ""
1278      << " bxNum:" << it->bxNum() << " whNum:" << it->whNum() << " scNum:" << it->scNum() << " stNum:" << it->stNum()
1279      << std::endl;
1280   //nb: operator << not implemented in base class L1MuDTChambThDigi
1281   return ss.str();
1282 }
1283 
1284 template <>
1285 inline std::string DEutils<L1MuRegionalCandCollection>::print(col_cit it) const {
1286   std::stringstream ss;
1287   //const float noval = -10; //L1MuRegionalCand::m_invalidValue;
1288   ss << std::setiosflags(std::ios::showpoint | std::ios::fixed | std::ios::right | std::ios::adjustfield);
1289   ss << std::hex << std::setfill('0') << " 0x" << std::setw(8) << it->getDataWord();
1290   //if(it->phiValue()==noval || it->etaValue()==noval || it->ptValue()==noval )
1291   ss << std::hex << std::setfill('0') << " pt:0x" << std::setw(2) << it->pt_packed() << " phi:0x" << std::setw(2)
1292      << it->phi_packed() << " eta:0x" << std::setw(2) << it->eta_packed();
1293   //else
1294   //  ss << std::dec << std::setfill(' ')
1295   //     << " pt:"   << std::setw(5) << std::setprecision(1) << it->ptValue() <<"[GeV]"
1296   //     << " phi:"  << std::setw(5) << std::setprecision(3) << it->phiValue()<<"[rad]"
1297   //     << " eta:"  << std::setw(6) << std::setprecision(3) << it->etaValue();
1298   ss << std::dec << std::setfill(' ') << " qua:" << std::setw(1) << it->quality() << " cha:" << std::setw(2)
1299      << it->chargeValue() << " chav:" << std::setw(1) << it->chargeValid() << " fh:" << std::setw(1) << it->isFineHalo()
1300      << " bx:" << std::setw(4) << it->bx() << " [id:" << std::setw(1) << it->type_idx()
1301      << "]"  // 0 DT, 1 bRPC, 2 CSC, 3 fRPC
1302      << std::endl;
1303   //ss << it->print()
1304   return ss.str();
1305 }
1306 
1307 template <>
1308 inline std::string DEutils<L1MuGMTCandCollection>::print(col_cit it) const {
1309   std::stringstream ss;
1310   ss << std::setiosflags(std::ios::showpoint | std::ios::fixed | std::ios::right | std::ios::adjustfield);
1311   //const float noval = -10; //L1MuGMTCand::m_invalidValue;
1312   ss << std::hex << std::setfill('0') << " 0x" << std::setw(7) << it->getDataWord();
1313   //if(it->phiValue()==noval || it->etaValue()==noval || it->ptValue()==noval)
1314   ss << std::hex << std::setfill('0') << " pt:0x" << std::setw(2) << it->ptIndex() << " eta:0x" << std::setw(2)
1315      << it->etaIndex() << " phi:0x" << std::setw(3) << it->phiIndex();
1316   //else
1317   //  ss << std::dec << std::setfill(' ')
1318   //     << " pt:"   << std::setw(5) << std::setprecision(1) << it->ptValue() <<"[GeV]"
1319   //     << " phi:"  << std::setw(5) << std::setprecision(3) << it->phiValue()<<"[rad]"
1320   //     << " eta:"  << std::setw(6) << std::setprecision(2) << it->etaValue();
1321   ss << std::dec << std::setfill(' ') << " cha:" << std::setw(2) << it->charge() << " qua:" << std::setw(3)
1322      << it->quality() << " iso:" << std::setw(1) << it->isol() << " mip:" << std::setw(1) << it->mip()
1323      << " bx:" << it->bx() << std::endl;
1324   //ss << it->print()
1325   return ss.str();
1326 }
1327 
1328 template <>
1329 inline std::string DEutils<CSCCorrelatedLCTDigiCollection_>::print(col_cit it) const {
1330   std::stringstream ss;
1331   ss
1332       //<< " lct#:"     << it->getTrknmb()
1333       //<< " val:"      << it->isValid()
1334       //<< " qua:"      << it->getQuality()
1335       //<< " strip:"    << it->getStrip()
1336       //<< " bend:"     << ((it->getBend() == 0) ? 'L' : 'R')
1337       //<< " patt:"     << it->getPattern()
1338       //<<"  key wire:" << it->getKeyWG()
1339       //<< " bx:"       << it->getBX()
1340       //<< " mpc-link:" << it->getMPCLink()
1341       //<< " csc id:"   << it->getCSCID()
1342       //<< std::endl;
1343       << *it;
1344   return ss.str();
1345 }
1346 
1347 template <>
1348 inline std::string DEutils<CSCALCTDigiCollection_>::print(col_cit it) const {
1349   std::stringstream ss;
1350   ss << *it << std::endl;
1351   return ss.str();
1352 }
1353 
1354 template <>
1355 inline std::string DEutils<CSCCLCTDigiCollection_>::print(col_cit it) const {
1356   std::stringstream ss;
1357   ss << *it << std::endl;
1358   return ss.str();
1359 }
1360 
1361 template <>
1362 inline std::string DEutils<L1CSCSPStatusDigiCollection_>::print(col_cit it) const {
1363   std::stringstream ss;
1364   ss << " slot:" << it->slot() << " bxn:" << it->BXN() << " fmm:" << it->FMM() << " ses:" << it->SEs()
1365      << " sms:" << it->SMs() << " bxs:" << it->BXs() << " afs:" << it->AFs() << " vps:" << it->VPs() << std::endl;
1366   return ss.str();
1367 }
1368 
1369 /// --- name candidate ---
1370 
1371 template <typename T>
1372 std::string DEutils<T>::GetName(int i) const {
1373   const int nlabel = 17;
1374   if (!(i < nlabel))
1375     return "un-defined";
1376   std::string str[nlabel] = {"un-registered"};
1377 
1378   switch (de_type()) {
1379     case dedefs::ECALtp:
1380       str[0] = "ECAL tp";
1381       str[1] = "EcalTrigPrimDigiCollection";
1382       str[2] = "EcalTriggerPrimitiveDigi";
1383       break;
1384     case dedefs::HCALtp:
1385       str[0] = "HCAL tp";
1386       str[1] = "HcalTrigPrimDigiCollection";
1387       str[2] = "HcalTriggerPrimitiveDigi";
1388       break;
1389     case dedefs::RCTem:
1390       str[0] = "RCT em";
1391       str[1] = "L1CaloEmCollection";
1392       str[2] = "L1CaloEmCand";
1393       break;
1394     case dedefs::RCTrgn:
1395       str[0] = "RCT region";
1396       str[1] = "L1CaloRegionCollection";
1397       str[2] = "L1CaloRegion";
1398       break;
1399     case dedefs::GCTisolaem:
1400       str[0] = "GCT em isolated";
1401       str[1] = "L1GctEmCandCollection";
1402       str[2] = "L1GctEmCand";
1403       break;
1404     case dedefs::GCTnoisoem:
1405       str[0] = "GCT em non-isolated";
1406       str[1] = "L1GctEmCandCollection";
1407       str[2] = "L1GctEmCand";
1408       break;
1409     case dedefs::GCTcenjets:
1410       str[0] = "GCT central jet";
1411       str[1] = "L1GctJetCandCollection";
1412       str[2] = "L1GctJetCand";
1413       break;
1414     case dedefs::GCTforjets:
1415       str[0] = "GCT forward jet";
1416       str[1] = "L1GctJetCandCollection";
1417       str[2] = "L1GctJetCand";
1418       break;
1419     case dedefs::GCTtaujets:
1420       str[0] = "GCT tau jet";
1421       str[1] = "L1GctJetCandCollection";
1422       str[2] = "L1GctJetCand";
1423       break;
1424     case dedefs::GCTisotaujets:
1425       str[0] = "Stage1Layer2 iso-tau jet";
1426       str[1] = "L1GctJetCandCollection";
1427       str[2] = "L1GctJetCand";
1428       break;
1429     case dedefs::GCTethad:
1430       str[0] = "GCT ht";
1431       str[1] = "L1GctEtHadCollection";
1432       str[2] = "L1GctEtHad";
1433       break;
1434     case dedefs::GCTetmiss:
1435       str[0] = "GCT et miss";
1436       str[1] = "L1GctEtMissCollection";
1437       str[2] = "L1GctEtMiss";
1438       break;
1439     case dedefs::GCTettot:
1440       str[0] = "GCT et total";
1441       str[1] = "L1GctEtTotalCollection";
1442       str[2] = "L1GctEtTotal";
1443       break;
1444     case dedefs::GCThtmiss:
1445       str[0] = "GCT ht miss";
1446       str[1] = "L1GctHtMissCollection";
1447       str[2] = "L1GctHtMiss";
1448       break;
1449     case dedefs::GCThfring:
1450       str[0] = "GCT hf ring";
1451       str[1] = "L1GctHFRingEtSumsCollection";
1452       str[2] = "L1GctHFRingEtSums";
1453       break;
1454     case dedefs::GCThfbit:
1455       str[0] = "GCT hf bit counts";
1456       str[1] = "L1GctHFBitCountsCollection";
1457       str[2] = "L1GctHFBitCounts";
1458       break;
1459 
1460     case dedefs::DTtpPh:
1461       str[0] = "DT tp phi";
1462       str[1] = "L1MuDTChambPhDigiCollection";
1463       str[2] = "L1MuDTChambPhDigi";
1464       break;
1465     case dedefs::DTtpTh:
1466       str[0] = "DT tp theta";
1467       str[1] = "L1MuDTChambThDigiCollection";
1468       str[2] = "L1MuDTChambThDigi";
1469       break;
1470     case dedefs::CSCtpa:
1471       str[0] = "CSC tpa";
1472       str[1] = "CSCALCTDigiCollection";
1473       str[2] = "CSCALCTDigi";
1474       break;
1475     case dedefs::CSCtpc:
1476       str[0] = "CSC tpc";
1477       str[1] = "CSCCLCTDigiCollection";
1478       str[2] = "CSCCLCTDigi";
1479       break;
1480     case dedefs::CSCtpl:
1481       str[0] = "CSC tp";
1482       str[1] = "CSCCorrelatedLCTDigiCollection";
1483       str[2] = "CSCCorrelatedLCTDigi";
1484       break;
1485     case dedefs::CSCsta:
1486       str[0] = "CSC tf status";
1487       str[1] = "L1CSCSPStatusDigiCollection_";
1488       str[2] = "L1CSCSPStatusDigi";
1489       break;
1490     case dedefs::MUrtf:
1491       str[0] = "Mu reg tf";
1492       str[1] = "L1MuRegionalCandCollection";
1493       str[2] = "L1MuRegionalCand";
1494       break;
1495     case dedefs::LTCi:
1496       str[0] = "LTC";
1497       str[1] = "LTCDigiCollection";
1498       str[2] = "LTCDigi";
1499       break;
1500     case dedefs::GMTcnd:
1501       str[0] = "GMT cand";
1502       str[1] = "L1MuGMTCandCollection";
1503       str[2] = "L1MuGMTCand";
1504       break;
1505     case dedefs::GMTrdt:
1506       str[0] = "GMT record";
1507       str[1] = "L1MuGMTReadoutRecordCollection";
1508       str[2] = "L1MuGMTReadoutRecord";
1509       break;
1510     case dedefs::GTdword:
1511       str[0] = "";
1512       str[1] = "";
1513       str[2] = "";
1514       break;
1515       //default:
1516   }
1517   return str[i];
1518 }
1519 
1520 /// --- order candidates ---
1521 
1522 template <typename T>
1523 struct de_rank : public DEutils<T> {
1524   typedef DEtrait<T> de_trait;
1525   typedef typename de_trait::cand_type cand_type;
1526   bool operator()(const cand_type& x, const cand_type& y) const {
1527     return false;  //default
1528   }
1529 };
1530 
1531 template <>
1532 inline bool de_rank<EcalTrigPrimDigiCollection>::operator()(const cand_type& x, const cand_type& y) const {
1533   return x.compressedEt() > y.compressedEt();
1534 }
1535 template <>
1536 inline bool de_rank<HcalTrigPrimDigiCollection>::operator()(const cand_type& x, const cand_type& y) const {
1537   return x.SOI_compressedEt() > y.SOI_compressedEt();
1538 }
1539 
1540 template <>
1541 inline bool de_rank<L1CaloEmCollection>::operator()(const cand_type& x, const cand_type& y) const {
1542   if (x.rank() != y.rank()) {
1543     return (x.rank() < y.rank());
1544   } else if (x.isolated() != y.isolated()) {
1545     return (x.isolated()) ? true : false;
1546   } else if (x.rctRegion() != y.rctRegion()) {
1547     return (x.rctRegion() < y.rctRegion());
1548   } else if (x.rctCrate() != y.rctCrate()) {
1549     return (x.rctCrate() < y.rctCrate());
1550   } else if (x.rctCard() != y.rctCard()) {
1551     return (x.rctCard() < y.rctCard());
1552   } else {
1553     return x.raw() < y.raw();
1554   }
1555 }
1556 
1557 template <>
1558 inline bool de_rank<L1CaloRegionCollection>::operator()(const cand_type& x, const cand_type& y) const {
1559   return x.et() < y.et();
1560 }
1561 
1562 template <>
1563 inline bool de_rank<L1GctEmCandCollection>::operator()(const cand_type& x, const cand_type& y) const {
1564   if (x.rank() != y.rank()) {
1565     return x.rank() < y.rank();
1566   } else {
1567     if (x.etaIndex() != y.etaIndex()) {
1568       return y.etaIndex() < x.etaIndex();
1569     } else {
1570       return x.phiIndex() < y.phiIndex();
1571     }
1572   }
1573 }
1574 template <>
1575 inline bool de_rank<L1GctJetCandCollection>::operator()(const cand_type& x, const cand_type& y) const {
1576   if (x.rank() != y.rank()) {
1577     return x.rank() < y.rank();
1578   } else {
1579     if (x.etaIndex() != y.etaIndex()) {
1580       return y.etaIndex() < x.etaIndex();
1581     } else {
1582       return x.phiIndex() < y.phiIndex();
1583     }
1584   }
1585 }
1586 //template <> inline bool de_rank<L1GctEtHadCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1587 //template <> inline bool de_rank<L1GctEtMissCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1588 //template <> inline bool de_rank<L1GctEtTotalCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1589 //template <> inline bool de_rank<L1GctHtMissCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1590 //template <> inline bool de_rank<L1GctHFRingEtSumsCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1591 //template <> inline bool de_rank<L1GctHFBitCountsCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1592 //template <> inline bool de_rank<L1GctJetCountsCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1593 
1594 template <>
1595 inline bool de_rank<L1MuDTChambPhDigiCollection>::operator()(const cand_type& x, const cand_type& y) const {
1596   if (x.whNum() != y.whNum()) {
1597     return x.whNum() < y.whNum();
1598   } else {
1599     if (x.scNum() != y.scNum()) {
1600       return y.scNum() < x.scNum();
1601     } else {
1602       return x.stNum() < y.stNum();
1603     }
1604   }
1605 }
1606 template <>
1607 inline bool de_rank<L1MuDTChambThDigiCollection>::operator()(const cand_type& x, const cand_type& y) const {
1608   if (x.whNum() != y.whNum()) {
1609     return x.whNum() < y.whNum();
1610   } else {
1611     if (x.scNum() != y.scNum()) {
1612       return y.scNum() < x.scNum();
1613     } else {
1614       return x.stNum() < y.stNum();
1615     }
1616   }
1617 }
1618 
1619 template <>
1620 inline bool de_rank<L1MuRegionalCandCollection>::operator()(const cand_type& x, const cand_type& y) const {
1621   if (x.phi_packed() != y.phi_packed()) {
1622     return x.phi_packed() < y.phi_packed();
1623   } else {
1624     if (x.eta_packed() != y.eta_packed()) {
1625       return y.eta_packed() < x.eta_packed();
1626     } else {
1627       return x.quality_packed() < y.quality_packed();
1628     }
1629   }
1630 }
1631 
1632 template <>
1633 inline bool de_rank<L1MuGMTCandCollection>::operator()(const cand_type& x, const cand_type& y) const {
1634   if (x.bx() != y.bx()) {
1635     return x.bx() < y.bx();
1636   } else if (x.ptIndex() != y.ptIndex()) {
1637     return x.ptIndex() < y.ptIndex();
1638   } else {
1639     return x.quality() < y.quality();
1640   }
1641 }
1642 
1643 template <>
1644 inline bool de_rank<CSCCorrelatedLCTDigiCollection_>::operator()(const cand_type& x, const cand_type& y) const {
1645   if (x.getTrknmb() != y.getTrknmb()) {
1646     return x.getTrknmb() < y.getTrknmb();
1647   } else {
1648     if (x.getKeyWG() != y.getKeyWG()) {
1649       return y.getKeyWG() < x.getKeyWG();
1650     } else {
1651       return x.getQuality() < y.getQuality();
1652     }
1653   }
1654 }
1655 
1656 #endif