CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Calibration/IsolatedParticles/src/MatrixECALDetIds.cc

Go to the documentation of this file.
00001 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00002 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00003 
00004 #include "Calibration/IsolatedParticles/interface/MatrixECALDetIds.h"
00005 
00006 #include <algorithm>
00007 #include <iostream>
00008 
00009 namespace spr{
00010 
00011   void matrixECALIds(const DetId& det, int ieta, int iphi,
00012                      const CaloGeometry* geo, const CaloTopology* caloTopology,
00013                      std::vector<DetId>& vdets, bool debug) {
00014 
00015     const CaloSubdetectorTopology *barrelTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel));
00016     const CaloSubdetectorTopology *endcapTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap));
00017     const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
00018     const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
00019 
00020     if (debug) {
00021       std::cout << "matrixECALIds::Add " << ieta << " rows and " << iphi 
00022                 << " columns of cells for 1 cell" << std::endl;
00023       if (det.subdetId() == EcalBarrel) {
00024         EBDetId id = det;
00025         std::cout << "matrixECALIds::Cell 0x" << std::hex << det() << std::dec 
00026                   << " " << id << std::endl;
00027       } else if (det.subdetId() == EcalEndcap) {
00028         EEDetId id = det;
00029         std::cout << "matrixECALIds::Cell 0x" << std::hex << det() << std::dec
00030                   << " " << id << std::endl;
00031       } else {
00032         std::cout << "matrixECALIds::Cell 0x" << std::hex << det() << std::dec
00033                   << " Unknown Type" << std::endl;
00034       }
00035     }
00036 
00037     std::vector<DetId> dets(1,det);
00038     std::vector<CaloDirection> dirs(1,NORTH);
00039     vdets = spr::newECALIdNS(dets, 0, ieta,iphi, dirs, *barrelTopo,*endcapTopo,
00040                              *barrelGeom,*endcapGeom,debug);
00041     dirs[0] = SOUTH;
00042     std::vector<DetId> vdetS = spr::newECALIdNS(dets, 0, ieta, iphi, dirs,
00043                                                 *barrelTopo,*endcapTopo, 
00044                                                 *barrelGeom,*endcapGeom,debug);
00045     for (unsigned int i1=0; i1<vdetS.size(); i1++) {
00046       if (std::count(vdets.begin(),vdets.end(),vdetS[i1]) == 0)
00047         vdets.push_back(vdetS[i1]);
00048     }
00049     unsigned int ndet = (2*ieta+1)*(2*iphi+1);
00050     if (vdets.size() != ndet) {
00051       std::vector<DetId> vdetExtra;
00052       spr::extraIds(det, vdets, ieta, ieta, iphi, iphi, 
00053                     *barrelGeom, *endcapGeom, vdetExtra, debug);
00054       if (vdetExtra.size() > 0) 
00055         vdets.insert(vdets.end(), vdetExtra.begin(), vdetExtra.end());
00056     }
00057 
00058     if (debug) {
00059       std::cout << "matrixECALIds::Total number of cells found is " 
00060                 << vdets.size() << std::endl;
00061       for (unsigned int i1=0; i1<vdets.size(); i1++) {
00062         if (vdets[i1].subdetId() == EcalBarrel) {
00063           EBDetId id = vdets[i1];
00064           std::cout << "matrixECALIds::Cell " << i1 << " 0x" << std::hex 
00065                     << vdets[i1]() << std::dec << " " << id << std::endl;
00066         } else if (vdets[i1].subdetId() == EcalEndcap) {
00067           EEDetId id = vdets[i1];
00068           std::cout << "matrixECALIds::Cell " << i1 << " 0x" << std::hex 
00069                     << vdets[i1]() << std::dec << " " << id << std::endl;
00070         } else {
00071           std::cout << "matrixECALIds::Cell " << i1 << " 0x" << std::hex 
00072                     << vdets[i1]() << std::dec << " Unknown Type" << std::endl;
00073         }
00074       }
00075     }
00076   }
00077 
00078   std::vector<DetId> matrixECALIds(const DetId& det,int ieta,int iphi, 
00079                                    const CaloGeometry* geo, 
00080                                    const CaloTopology* caloTopology,
00081                                    bool debug) {
00082 
00083     std::vector<DetId> vdets;
00084     matrixECALIds(det, ieta, iphi, geo, caloTopology, vdets, debug);
00085     return vdets;
00086   }
00087 
00088   void matrixECALIds(const DetId& det, int ietaE,int ietaW,int iphiN,int iphiS,
00089                      const CaloGeometry* geo, const CaloTopology* caloTopology,
00090                      std::vector<DetId>& vdets, bool debug) {
00091 
00092     const CaloSubdetectorTopology *barrelTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel));
00093     const CaloSubdetectorTopology *endcapTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap));
00094     const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
00095     const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
00096 
00097     if (debug) {
00098       std::cout << "matrixECALIds::Add " << ietaE << "|" << ietaW
00099                 << " rows and " << iphiN << "|" << iphiS
00100                 << " columns of cells for 1 cell" << std::endl;
00101       if (det.subdetId() == EcalBarrel) {
00102         EBDetId id = det;
00103         std::cout << "matrixECALIds::Cell 0x" << std::hex << det() << std::dec 
00104                   << " " << id << std::endl;
00105       } else if (det.subdetId() == EcalEndcap) {
00106         EEDetId id = det;
00107         std::cout << "matrixECALIds::Cell 0x" << std::hex << det() << std::dec
00108                   << " " << id << std::endl;
00109       } else {
00110         std::cout << "matrixECALIds::Cell 0x" << std::hex << det() << std::dec
00111                   << " Unknown Type" << std::endl;
00112       }
00113     }
00114 
00115     std::vector<DetId> dets(1,det);
00116     std::vector<CaloDirection> dirs(1,NORTH);
00117     std::vector<int> jetaE(1,ietaE), jetaW(1,ietaW);
00118     std::vector<int> jphiN(1,iphiN), jphiS(1,iphiS);
00119     vdets = spr::newECALIdNS(dets, 0, jetaE, jetaW, jphiN, jphiS, dirs, 
00120                              *barrelTopo, *endcapTopo, *barrelGeom,
00121                              *endcapGeom, debug);
00122     dirs[0] = SOUTH;
00123     std::vector<DetId> vdetS = spr::newECALIdNS(dets, 0, jetaE, jetaW, jphiN,
00124                                                 jphiS, dirs, *barrelTopo,
00125                                                 *endcapTopo, *barrelGeom,
00126                                                 *endcapGeom, debug);
00127     for (unsigned int i1=0; i1<vdetS.size(); i1++) {
00128       if (std::count(vdets.begin(),vdets.end(),vdetS[i1]) == 0)
00129         vdets.push_back(vdetS[i1]);
00130     }
00131 
00132     unsigned int ndet = (ietaE+ietaW+1)*(iphiN+iphiS+1);
00133     if (vdets.size() != ndet) {
00134       std::vector<DetId> vdetExtra;
00135       spr::extraIds(det, vdets, ietaE, ietaW, iphiN, iphiS, 
00136                     *barrelGeom, *endcapGeom, vdetExtra, debug);
00137       if (vdetExtra.size() > 0) 
00138         vdets.insert(vdets.end(), vdetExtra.begin(), vdetExtra.end());
00139     }
00140 
00141     if (debug) {
00142       std::cout << "matrixECALIds::Total number of cells found is " 
00143                 << vdets.size() << std::endl;
00144       for (unsigned int i1=0; i1<vdets.size(); i1++) {
00145         if (vdets[i1].subdetId() == EcalBarrel) {
00146           EBDetId id = vdets[i1];
00147           std::cout << "matrixECALIds::Cell " << i1 << " 0x" << std::hex 
00148                     << vdets[i1]() << std::dec << " " << id << std::endl;
00149         } else if (vdets[i1].subdetId() == EcalEndcap) {
00150           EEDetId id = vdets[i1];
00151           std::cout << "matrixECALIds::Cell " << i1 << " 0x" << std::hex 
00152                     << vdets[i1]() << std::dec << " " << id << std::endl;
00153         } else {
00154           std::cout << "matrixECALIds::Cell " << i1 << " 0x" << std::hex 
00155                     << vdets[i1]() << std::dec << " Unknown Type" << std::endl;
00156         }
00157       }
00158     }
00159   }
00160 
00161   std::vector<DetId> matrixECALIds(const DetId& det, int ietaE, int ietaW,
00162                                    int iphiN, int iphiS,
00163                                    const CaloGeometry* geo, 
00164                                    const CaloTopology* caloTopology,
00165                                    bool debug) {
00166 
00167     std::vector<DetId> vdets;
00168     spr::matrixECALIds(det, ietaE, ietaW, iphiN, iphiS, geo, caloTopology,
00169                        vdets, debug);
00170     return vdets;
00171   }
00172 
00173   std::vector<DetId> newECALIdNS(std::vector<DetId>& dets, unsigned int last,
00174                                  int ieta, int iphi, 
00175                                  std::vector<CaloDirection>& dir,
00176                                  const CaloSubdetectorTopology& barrelTopo,
00177                                  const CaloSubdetectorTopology& endcapTopo,
00178                                  const EcalBarrelGeometry& barrelGeom, 
00179                                  const EcalEndcapGeometry& endcapGeom,
00180                                  bool debug) {
00181 
00182     if (debug) {
00183       std::cout << "newECALIdNS::Add " << iphi << " columns of cells for " 
00184                 << (dets.size()-last) << " cells (last " << last << ")"
00185                 << std::endl;
00186       for (unsigned int i1=last; i1<dets.size(); i1++) {
00187         if (dets[i1].subdetId() == EcalBarrel) {
00188           EBDetId id = dets[i1];
00189           std::cout << "newECALIdNS::Cell " << i1 << " "  << id << " along "
00190                     << dir[i1] << std::endl;
00191         } else if (dets[i1].subdetId() == EcalEndcap) {
00192           EEDetId id = dets[i1];
00193           std::cout << "newECALIdNS::Cell " << i1 << " " << id << " along "
00194                     << dir[i1] << std::endl;
00195         } else {
00196           std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00197                     << dets[i1]() << std::dec << " Unknown Type along " 
00198                     << dir[i1] << std::endl;
00199         }
00200       }
00201     }
00202     
00203     std::vector<DetId> vdets;
00204     std::vector<CaloDirection> dirs;
00205     vdets.insert(vdets.end(), dets.begin(), dets.end());
00206     dirs.insert(dirs.end(), dir.begin(), dir.end());
00207 
00208     std::vector<DetId> vdetE, vdetW;
00209     if (last == 0) {
00210       unsigned int ndet = vdets.size();
00211       std::vector<CaloDirection> dirE(ndet,EAST), dirW(ndet,WEST);
00212       vdetE = spr::newECALIdEW(dets, last, ieta, dirE, barrelTopo, endcapTopo, 
00213                                barrelGeom, endcapGeom, debug);
00214       vdetW = spr::newECALIdEW(dets, last, ieta, dirW, barrelTopo, endcapTopo,
00215                                barrelGeom, endcapGeom, debug);
00216       for (unsigned int i1=0; i1<vdetW.size(); i1++) {
00217         if (std::count(vdets.begin(),vdets.end(),vdetW[i1]) == 0) {
00218           vdets.push_back(vdetW[i1]);
00219           dirs.push_back(dir[0]);
00220         }
00221       }
00222       for (unsigned int i1=0; i1<vdetE.size(); i1++) {
00223         if (std::count(vdets.begin(),vdets.end(),vdetE[i1]) == 0) {
00224           vdets.push_back(vdetE[i1]);
00225           dirs.push_back(dir[0]);
00226         }
00227       }
00228       if (debug) {
00229         std::cout <<"newECALIdNS::With Added cells along E/W results a set of "
00230                   << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00231         for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00232           if (vdets[i1].subdetId() == EcalBarrel) {
00233             EBDetId id = vdets[i1];
00234             std::cout << "newECALIdNS::Cell " << i1 << " "  << id << " along "
00235                       << dirs[i1] << std::endl;
00236           } else if (vdets[i1].subdetId() == EcalEndcap) {
00237             EEDetId id = vdets[i1];
00238             std::cout << "newECALIdNS::Cell " << i1 << " " << id << " along "
00239                       << dirs[i1] << std::endl;
00240           } else {
00241             std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00242                       << vdets[i1]() << std::dec << " Unknown Type along " 
00243                       << dirs[i1] << std::endl;
00244           }
00245         }
00246       }
00247     }
00248 
00249     unsigned int last0 = vdets.size();
00250     std::vector<DetId> vdetnew;
00251     std::vector<CaloDirection> dirnew;
00252     if (iphi > 0) {
00253       std::vector<DetId> vdetn(1);
00254       std::vector<CaloDirection> dirn(1);
00255       std::vector<CaloDirection> dirnE(1,EAST), dirnW(1,WEST);
00256       int flag=0;
00257       for (unsigned int i1=last; i1<dets.size(); i1++) {
00258         std::vector<DetId> cells;
00259         spr::simpleMove(dets[i1], dir[i1], barrelTopo, endcapTopo,
00260                         barrelGeom, endcapGeom, cells, flag, debug);
00261         /*
00262         if (dets[i1].subdetId() == EcalBarrel) {
00263           EBDetId id = dets[i1];
00264           std::cout << "Moved Cell " << i1 << " "  << id << " along "
00265                     << dir[i1] << std::endl;
00266         } else if (dets[i1].subdetId() == EcalEndcap) {
00267           EEDetId id = dets[i1];
00268           std::cout << "Moved Cell " << i1 << " " << id << " along "
00269                     << dir[i1] << std::endl;
00270         } else {
00271           std::cout << "Moved Cell " << i1 << " 0x" << std::hex 
00272                     << dets[i1]() << std::dec << " Unknown Type along " 
00273                     << dir[i1] << std::endl;
00274         }
00275         for (unsigned int kk=0; kk<cells.size(); kk++) {
00276           if (cells[kk].subdetId() == EcalBarrel) {
00277             EBDetId id = cells[kk];
00278             std::cout << "Moved to " << id << " flag " << flag << "\n";
00279           } else if (cells[kk].subdetId() == EcalEndcap) {
00280             EEDetId id = cells[kk];
00281             std::cout << "Moved to " << id << " flag " << flag << "\n";
00282           } else {
00283             std::cout << "Moved Cell " << i1 << " 0x" << std::hex 
00284                       << cells[kk]() << std::dec << " Unknown Type flag " 
00285                       << flag << std::endl;
00286           }
00287         }
00288         */
00289         if (flag != 0) {
00290           if (std::count(vdets.begin(),vdets.end(),cells[0]) == 0) {
00291             vdetn[0] = cells[0];
00292             vdetnew.push_back(vdetn[0]);
00293             dirn[0] = dir[i1];
00294             if (flag < 0) {
00295               if (dirn[0] == NORTH) dirn[0] = SOUTH;
00296               else                  dirn[0] = NORTH;
00297             }
00298             dirnew.push_back(dirn[0]);
00299             vdetE = spr::newECALIdEW(vdetn, 0, ieta, dirnE, barrelTopo, 
00300                                      endcapTopo, barrelGeom, endcapGeom,debug);
00301             vdetW = spr::newECALIdEW(vdetn, 0, ieta, dirnW, barrelTopo, 
00302                                      endcapTopo, barrelGeom, endcapGeom,debug);
00303             for (unsigned int i2=0; i2<vdetW.size(); i2++) {
00304               if (std::count(vdets.begin(),vdets.end(),vdetW[i2]) == 0 &&
00305                   std::count(vdetnew.begin(),vdetnew.end(),vdetW[i2]) == 0) {
00306                 vdets.push_back(vdetW[i2]);
00307                 dirs.push_back(dirn[0]);
00308               }
00309             }
00310             for (unsigned int i2=0; i2<vdetE.size(); i2++) {
00311               if (std::count(vdets.begin(),vdets.end(),vdetE[i2]) == 0 &&
00312                   std::count(vdetnew.begin(),vdetnew.end(),vdetE[i2]) == 0) {
00313                 vdets.push_back(vdetE[i2]);
00314                 dirs.push_back(dirn[0]);
00315               }
00316             }
00317           }
00318         }
00319       }
00320       iphi--;
00321       last = vdets.size();
00322       for (unsigned int i2=0; i2<vdetnew.size(); i2++) {
00323         if (std::count(vdets.begin(),vdets.end(),vdetnew[i2]) == 0) {
00324           vdets.push_back(vdetnew[i2]);
00325           dirs.push_back(dirnew[i2]);
00326         }
00327       }
00328       if (debug) {
00329         std::cout << "newECALIdNS::Addition results a set of " 
00330                   << (vdets.size()-last0)  << " new  cells (last " << last0
00331                   << ", iphi " << iphi << ")" << std::endl;
00332         for (unsigned int i1=last0; i1<vdets.size(); i1++) {
00333           if (vdets[i1].subdetId() == EcalBarrel) {
00334             EBDetId id = vdets[i1];
00335             std::cout << "newECALIdNS::Cell " << i1 << " "  << id << " along "
00336                       << dirs[i1] << std::endl;
00337           } else if (vdets[i1].subdetId() == EcalEndcap) {
00338             EEDetId id = vdets[i1];
00339             std::cout << "newECALIdNS::Cell " << i1 << " " << id << " along "
00340                       << dirs[i1] << std::endl;
00341           } else {
00342             std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00343                       << vdets[i1]() << std::dec << " Unknown Type along " 
00344                       << dirs[i1] << std::endl;
00345           }
00346         }
00347       }
00348       last0 = last;
00349     }
00350 
00351     if (iphi > 0) {
00352       last = last0;
00353       return spr::newECALIdNS(vdets,last,ieta,iphi,dirs,barrelTopo,endcapTopo,barrelGeom,endcapGeom,debug);
00354     } else {
00355       if (debug) {
00356         std::cout << "newECALIdNS::Final list consists of " << vdets.size()
00357                   << " cells" << std::endl;
00358         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00359           if (vdets[i1].subdetId() == EcalBarrel) {
00360             EBDetId id = vdets[i1];
00361             std::cout << "newECALIdNS::Cell " << i1 << " "  << id << std::endl;
00362           } else if (vdets[i1].subdetId() == EcalEndcap) {
00363             EEDetId id = vdets[i1];
00364             std::cout << "newECALIdNS::Cell " << i1 << " " << id << std::endl;
00365           } else {
00366             std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00367                       << vdets[i1]() << std::dec << " Unknown Type" 
00368                       << std::endl;
00369           }
00370         }
00371       }
00372       return vdets;
00373     }
00374   }
00375 
00376   std::vector<DetId> newECALIdNS(std::vector<DetId>& dets, unsigned int last,
00377                                  std::vector<int>& ietaE, 
00378                                  std::vector<int>& ietaW, 
00379                                  std::vector<int>& iphiN, 
00380                                  std::vector<int>& iphiS,
00381                                  std::vector<CaloDirection>& dir,
00382                                  const CaloSubdetectorTopology& barrelTopo,
00383                                  const CaloSubdetectorTopology& endcapTopo,
00384                                  const EcalBarrelGeometry& barrelGeom, 
00385                                  const EcalEndcapGeometry& endcapGeom,
00386                                  bool debug) {
00387 
00388     if (debug) {
00389       std::cout << "newECALIdNS::Add columns of cells for " 
00390                 << (dets.size()-last) << " cells (last) " << last << std::endl;
00391       for (unsigned int i1=last; i1<dets.size(); i1++) {
00392         if (dets[i1].subdetId() == EcalBarrel) {
00393           EBDetId id = dets[i1];
00394           std::cout << "newECALIdNS::Cell " << i1 << " "  << id << " along "
00395                     << dir[i1] << " # " << iphiN[i1] << "|" << iphiS[i1]
00396                     << std::endl;
00397         } else if (dets[i1].subdetId() == EcalEndcap) {
00398           EEDetId id = dets[i1];
00399           std::cout << "newECALIdNS::Cell " << i1 << " " << id << " along "
00400                     << dir[i1] << " # " << iphiN[i1] << "|" << iphiS[i1]
00401                     << std::endl;
00402         } else {
00403           std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00404                     << dets[i1]() << std::dec << " Unknown Type along " 
00405                     << dir[i1] << " # " << iphiN[i1] << "|" << iphiS[i1] 
00406                     << std::endl;
00407         }
00408       }
00409     }
00410 
00411     std::vector<DetId> vdets;
00412     std::vector<CaloDirection> dirs;
00413     std::vector<int> jetaE, jetaW, jphiN, jphiS;
00414     vdets.insert(vdets.end(), dets.begin(), dets.end());
00415     dirs.insert(dirs.end(), dir.begin(), dir.end());
00416     jetaE.insert(jetaE.end(), ietaE.begin(), ietaE.end());
00417     jetaW.insert(jetaW.end(), ietaW.begin(), ietaW.end());
00418     jphiN.insert(jphiN.end(), iphiN.begin(), iphiN.end());
00419     jphiS.insert(jphiS.end(), iphiS.begin(), iphiS.end());
00420     std::vector<DetId> vdetE, vdetW;
00421     if (last == 0) {
00422       unsigned int ndet = vdets.size();
00423       std::vector<CaloDirection> dirE(ndet,EAST), dirW(ndet,WEST);
00424       vdetE = spr::newECALIdEW(dets, last, ietaE, ietaW, dirE, barrelTopo, 
00425                                endcapTopo, barrelGeom, endcapGeom, debug);
00426       vdetW = spr::newECALIdEW(dets, last, ietaE, ietaW, dirW, barrelTopo,
00427                                endcapTopo, barrelGeom, endcapGeom, debug);
00428       for (unsigned int i1=0; i1<vdetW.size(); i1++) {
00429         if (std::count(vdets.begin(),vdets.end(),vdetW[i1]) == 0) {
00430           vdets.push_back(vdetW[i1]);
00431           dirs.push_back(dir[0]);
00432           jetaE.push_back(0);
00433           jetaW.push_back(0);
00434           jphiN.push_back(iphiN[0]);
00435           jphiS.push_back(iphiS[0]);
00436         }
00437       }
00438       for (unsigned int i1=0; i1<vdetE.size(); i1++) {
00439         if (std::count(vdets.begin(),vdets.end(),vdetE[i1]) == 0) {
00440           vdets.push_back(vdetE[i1]);
00441           dirs.push_back(dir[0]);
00442           jetaE.push_back(0);
00443           jetaW.push_back(0);
00444           jphiN.push_back(iphiN[0]);
00445           jphiS.push_back(iphiS[0]);
00446         }
00447       }
00448       if (debug) {
00449         std::cout <<"newECALIdNS::With Added cells along E/W results a set of "
00450                   << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00451         for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00452           if (vdets[i1].subdetId() == EcalBarrel) {
00453             EBDetId id = vdets[i1];
00454             std::cout << "newECALIdNS::Cell " << i1 << " "  << id << " along "
00455                       << dirs[i1] << std::endl;
00456           } else if (vdets[i1].subdetId() == EcalEndcap) {
00457             EEDetId id = vdets[i1];
00458             std::cout << "newECALIdNS::Cell " << i1 << " " << id << " along "
00459                       << dirs[i1] << std::endl;
00460           } else {
00461             std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00462                       << vdets[i1]() << std::dec << " Unknown Type along " 
00463                       << dirs[i1] << std::endl;
00464           }
00465         }
00466       }
00467     }
00468 
00469     unsigned int last0 = vdets.size();
00470     std::vector<DetId> vdetnew;
00471     std::vector<CaloDirection> dirnew;
00472     std::vector<int> kphiN, kphiS, ketaE, ketaW;
00473     int kphi = 0;
00474     for (unsigned int i1=last; i1<dets.size(); i1++) {
00475       int iphi = iphiS[i1];
00476       if (dir[i1] == NORTH) iphi = iphiN[i1];
00477       if (iphi > 0) {
00478         std::vector<DetId>         vdetn(1);
00479         std::vector<CaloDirection> dirn(1);
00480         std::vector<CaloDirection> dirnE(1,EAST), dirnW(1,WEST);
00481         int flag=0;
00482         std::vector<DetId> cells;
00483         spr::simpleMove(dets[i1], dir[i1], barrelTopo, endcapTopo,
00484                         barrelGeom, endcapGeom, cells, flag, debug);
00485         iphi--;
00486         if (iphi > kphi) kphi = iphi;
00487         if (dir[i1] == NORTH) jphiN[i1] = iphi;
00488         else                  jphiS[i1] = iphi;
00489         if (flag != 0) {
00490           if (std::count(vdets.begin(),vdets.end(),cells[0]) == 0) {
00491             int kfiN = iphiN[i1];
00492             int kfiS = iphiS[i1];
00493             vdetn[0] = cells[0];
00494             vdetnew.push_back(vdetn[0]);
00495             dirn[0] = dir[i1];
00496             if (dir[i1] == NORTH) kfiN = iphi;
00497             else                  kfiS = iphi;
00498             if (flag < 0) {
00499               int ktmp = kfiS; kfiS = kfiN; kfiN = ktmp;
00500               if (dirn[0] == NORTH) dirn[0] = SOUTH;
00501               else                  dirn[0] = NORTH;
00502             }
00503             dirnew.push_back(dirn[0]);
00504             kphiN.push_back(kfiN); ketaE.push_back(ietaE[i1]);
00505             kphiS.push_back(kfiS); ketaW.push_back(ietaW[i1]);
00506             std::vector<int>       ietE(1,ietaE[i1]), ietW(1,ietaW[i1]);
00507             vdetE = spr::newECALIdEW(vdetn, 0, ietE, ietW, dirnE, barrelTopo,
00508                                      endcapTopo, barrelGeom, endcapGeom,debug);
00509             vdetW = spr::newECALIdEW(vdetn, 0, ietE, ietW, dirnW, barrelTopo,
00510                                      endcapTopo, barrelGeom, endcapGeom,debug);
00511             for (unsigned int i2=0; i2<vdetW.size(); i2++) {
00512               if (std::count(vdets.begin(),vdets.end(),vdetW[i2]) == 0 &&
00513                   std::count(vdetnew.begin(),vdetnew.end(),vdetW[i2]) == 0) {
00514                 vdets.push_back(vdetW[i2]);
00515                 dirs.push_back(dirn[0]);
00516                 jetaE.push_back(0); jphiN.push_back(kfiN);
00517                 jetaW.push_back(0); jphiS.push_back(kfiS);
00518               }
00519             }
00520             for (unsigned int i2=0; i2<vdetE.size(); i2++) {
00521               if (std::count(vdets.begin(),vdets.end(),vdetE[i2]) == 0 &&
00522                   std::count(vdetnew.begin(),vdetnew.end(),vdetE[i2]) == 0) {
00523                 vdets.push_back(vdetE[i2]);
00524                 dirs.push_back(dirn[0]);
00525                 jetaE.push_back(0); jphiN.push_back(kfiN);
00526                 jetaW.push_back(0); jphiS.push_back(kfiS);
00527               }
00528             }
00529           } 
00530         }
00531       }
00532     }
00533     last = vdets.size();
00534     for (unsigned int i2=0; i2<vdetnew.size(); i2++) {
00535       if (std::count(vdets.begin(),vdets.end(),vdetnew[i2]) == 0) {
00536         vdets.push_back(vdetnew[i2]);
00537         dirs.push_back(dirnew[i2]);
00538         jetaE.push_back(ketaE[i2]);
00539         jetaW.push_back(ketaW[i2]);
00540         jphiN.push_back(kphiN[i2]);
00541         jphiS.push_back(kphiS[i2]);
00542       }
00543     }
00544     if (debug) {
00545       std::cout << "newECALIdNS::Addition results a set of " 
00546                 << (vdets.size()-last0)  << " new  cells (last " << last0
00547                 << ", iphi " << kphi << ")" << std::endl;
00548       for (unsigned int i1=last0; i1<vdets.size(); i1++) {
00549         if (vdets[i1].subdetId() == EcalBarrel) {
00550           EBDetId id = vdets[i1];
00551           std::cout << "newECALIdNS::Cell " << i1 << " "  << id << " along "
00552                     << dirs[i1] << " iphi " << jphiN[i1] << "|" << jphiS[i1]
00553                     << " ieta " << jetaE[i1] << "|" << jetaW[i1] << std::endl;
00554         } else if (vdets[i1].subdetId() == EcalEndcap) {
00555           EEDetId id = vdets[i1];
00556           std::cout << "newECALIdNS::Cell " << i1 << " " << id << " along "
00557                     << dirs[i1] << " iphi " << jphiN[i1] << "|" << jphiS[i1]
00558                     << " ieta " << jetaE[i1] << "|" << jetaW[i1] << std::endl;
00559         } else {
00560           std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00561                     << vdets[i1]() << std::dec << " Unknown Type along "
00562                     << dirs[i1] << " iphi " << jphiN[i1] << "|" << jphiS[i1]
00563                     << " ieta " << jetaE[i1] << "|" << jetaW[i1] << std::endl;
00564         }
00565       }
00566     }
00567     last0 = last;
00568       
00569     if (kphi > 0) {
00570       last = last0;
00571       return spr::newECALIdNS(vdets, last, jetaE, jetaW, jphiN, jphiS, dirs,
00572                               barrelTopo, endcapTopo, barrelGeom, endcapGeom,
00573                               debug);
00574     } else {
00575       if (debug) {
00576         std::cout << "newECALIdNS::Final list consists of " << vdets.size()
00577                   << " cells" << std::endl;
00578         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00579           if (vdets[i1].subdetId() == EcalBarrel) {
00580             EBDetId id = vdets[i1];
00581             std::cout << "newECALIdNS::Cell " << i1 << " "  << id << std::endl;
00582           } else if (vdets[i1].subdetId() == EcalEndcap) {
00583             EEDetId id = vdets[i1];
00584             std::cout << "newECALIdNS::Cell " << i1 << " " << id << std::endl;
00585           } else {
00586             std::cout << "newECALIdNS::Cell " << i1 << " 0x" << std::hex 
00587                       << vdets[i1]() << std::dec << " Unknown Type" 
00588                       << std::endl;
00589           }
00590         }
00591       }
00592       return vdets;
00593     }
00594   }
00595 
00596   std::vector<DetId> newECALIdEW(std::vector<DetId>& dets, unsigned int last,
00597                                  int ieta, std::vector<CaloDirection>& dir, 
00598                                  const CaloSubdetectorTopology& barrelTopo, 
00599                                  const CaloSubdetectorTopology& endcapTopo, 
00600                                  const EcalBarrelGeometry& barrelGeom, 
00601                                  const EcalEndcapGeometry& endcapGeom,
00602                                  bool debug) {
00603 
00604     if (debug) {
00605       std::cout << "newECALIdEW::Add " << ieta << " rows of cells for " 
00606                 << last << ":" << dets.size() << ":" << (dets.size()-last) 
00607                 << " cells" << std::endl;
00608       for (unsigned int i1=last; i1<dets.size(); i1++) {
00609         if (dets[i1].subdetId() == EcalBarrel) {
00610           EBDetId id = dets[i1];
00611           std::cout << "newECALIdEW::Cell " << i1 << " "  << id << " along "
00612                     << dir[i1] << std::endl;
00613         } else if (dets[i1].subdetId() == EcalEndcap) {
00614           EEDetId id = dets[i1];
00615           std::cout << "newECALIdEW::Cell " << i1 << " " << id << " along "
00616                     << dir[i1] << std::endl;
00617         } else {
00618           std::cout << "newECALIdEW::Cell " << i1 << " 0x" << std::hex 
00619                     << dets[i1]() << std::dec << " Unknown Type along " 
00620                     << dir[i1] << std::endl;
00621         }
00622       }
00623     }
00624 
00625     std::vector<DetId> vdets; vdets.clear();
00626     std::vector<CaloDirection> dirs; dirs.clear();
00627     vdets.insert(vdets.end(), dets.begin(), dets.end());
00628     dirs.insert(dirs.end(), dir.begin(), dir.end());
00629 
00630     if (ieta > 0) {
00631       for (unsigned int i1=last; i1<dets.size(); i1++) {
00632         int flag = 0;
00633         std::vector<DetId> cells;
00634         spr::simpleMove(dets[i1], dir[i1], barrelTopo, endcapTopo,
00635                         barrelGeom, endcapGeom, cells, flag, debug);
00636         /*
00637         if (dets[i1].subdetId() == EcalBarrel) {
00638           EBDetId id = dets[i1];
00639           std::cout << "Moved Cell " << i1 << " "  << id << " along "
00640                     << dir[i1] << std::endl;
00641         } else if (dets[i1].subdetId() == EcalEndcap) {
00642           EEDetId id = dets[i1];
00643           std::cout << "Moved Cell " << i1 << " " << id << " along "
00644                     << dir[i1] << std::endl;
00645         } else {
00646           std::cout << "Moved Cell " << i1 << " 0x" << std::hex 
00647                     << dets[i1]() << std::dec << " Unknown Type along " 
00648                     << dir[i1] << std::endl;
00649         }
00650         for (unsigned int kk=0; kk<cells.size(); kk++) {
00651           if (cells[kk].subdetId() == EcalBarrel) {
00652             EBDetId id = cells[kk];
00653             std::cout << "Moved to " << id << " flag " << flag << "\n";
00654           } else if (cells[kk].subdetId() == EcalEndcap) {
00655             EEDetId id = cells[kk];
00656             std::cout << "Moved to " << id << " flag " << flag << "\n";
00657           } else {
00658             std::cout << "Moved Cell " << i1 << " 0x" << std::hex 
00659                       << cells[kk]() << std::dec << " Unknown Type flag " 
00660                       << flag << std::endl;
00661           }
00662         }
00663         */
00664         if (flag != 0) {
00665           if (std::count(vdets.begin(),vdets.end(),cells[0]) == 0) {
00666             CaloDirection dirn = dir[i1];
00667             if (flag < 0) {
00668               if (dirn == EAST) dirn = WEST;
00669               else              dirn = EAST;
00670             }
00671             vdets.push_back(cells[0]);
00672             dirs.push_back(dirn);
00673           }
00674         }
00675       }
00676       ieta--;
00677     }
00678     
00679     if (debug) {
00680       std::cout << "newECALIdEW::Addition results a set of " 
00681                 << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00682       for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00683         if (vdets[i1].subdetId() == EcalBarrel) {
00684           EBDetId id = vdets[i1];
00685           std::cout << "newECALIdEW::Cell " << i1 << " "  << id << " along " 
00686                     << dirs[i1] << std::endl;
00687         } else if (vdets[i1].subdetId() == EcalEndcap) {
00688           EEDetId id = vdets[i1];
00689           std::cout << "newECALIdEW::Cell " << i1 << " " << id << " along " 
00690                     << dirs[i1] << std::endl;
00691         } else {
00692           std::cout << "newECALIdEW::Cell " << i1 << " 0x" << std::hex 
00693                     << vdets[i1]() << std::dec << " Unknown Type along " 
00694                     << dirs[i1] << std::endl;
00695         }
00696       }
00697     }
00698 
00699     if (ieta > 0) {
00700       last = dets.size();
00701       return spr::newECALIdEW(vdets,last,ieta,dirs,barrelTopo,endcapTopo,barrelGeom,endcapGeom,debug);
00702     } else {
00703       if (debug) {
00704         std::cout << "newECALIdEW::Final list (EW) consists of " <<vdets.size()
00705                   << " cells" << std::endl;
00706         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00707           if (vdets[i1].subdetId() == EcalBarrel) {
00708             EBDetId id = vdets[i1];
00709             std::cout << "newECALIdEW::Cell " << i1 << " "  << id << std::endl;
00710           } else if (vdets[i1].subdetId() == EcalEndcap) {
00711             EEDetId id = vdets[i1];
00712             std::cout << "newECALIdEW::Cell " << i1 << " " << id << std::endl;
00713           } else {
00714             std::cout << "newECALIdEW::Cell " << i1 << " 0x" << std::hex 
00715                       << vdets[i1]() <<std::dec << " Unknown Type" <<std::endl;
00716           }
00717         }
00718       }
00719       return vdets;
00720     }
00721   }
00722 
00723   std::vector<DetId> newECALIdEW(std::vector<DetId>& dets, unsigned int last,
00724                                  std::vector<int>& ietaE, 
00725                                  std::vector<int>& ietaW,
00726                                  std::vector<CaloDirection>& dir, 
00727                                  const CaloSubdetectorTopology& barrelTopo, 
00728                                  const CaloSubdetectorTopology& endcapTopo, 
00729                                  const EcalBarrelGeometry& barrelGeom, 
00730                                  const EcalEndcapGeometry& endcapGeom,
00731                                  bool debug) {
00732 
00733     if (debug) {
00734       std::cout << "newECALIdEW::Add " << ietaE[0] << "|" << ietaW[0]
00735                 << " rows of cells for " << (dets.size()-last) 
00736                 << " cells (last " << last << ")" << std::endl;
00737       for (unsigned int i1=last; i1<dets.size(); i1++) {
00738         if (dets[i1].subdetId() == EcalBarrel) {
00739           EBDetId id = dets[i1];
00740           std::cout << "newECALIdEW::Cell " << i1 << " "  << id << " along "
00741                     << dir[i1] << std::endl;
00742         } else if (dets[i1].subdetId() == EcalEndcap) {
00743           EEDetId id = dets[i1];
00744           std::cout << "newECALIdEW::Cell " << i1 << " " << id << " along "
00745                     << dir[i1] << std::endl;
00746         } else {
00747           std::cout << "newECALIdEW::Cell " << i1 << " 0x" << std::hex 
00748                     << dets[i1]() << std::dec << " Unknown Type along " 
00749                     << dir[i1] << std::endl;
00750         }
00751       }
00752     }
00753 
00754     std::vector<DetId> vdets;
00755     vdets.insert(vdets.end(), dets.begin(), dets.end());
00756     std::vector<CaloDirection> dirs;
00757     dirs.insert(dirs.end(), dir.begin(), dir.end());
00758     std::vector<int> jetaE, jetaW;
00759     jetaE.insert(jetaE.end(), ietaE.begin(), ietaE.end());
00760     jetaW.insert(jetaW.end(), ietaW.begin(), ietaW.end());
00761     int keta = 0;
00762     for (unsigned int i1=last; i1<dets.size(); i1++) {
00763       int ieta = ietaW[i1];
00764       if (dir[i1] == EAST) ieta = ietaE[i1]; 
00765       if (ieta > 0) {
00766         int flag=0;
00767         std::vector<DetId> cells;
00768         spr::simpleMove(dets[i1], dir[i1], barrelTopo, endcapTopo,
00769                         barrelGeom, endcapGeom, cells, flag, debug);
00770         ieta--;
00771         if (ieta > keta) keta = ieta;
00772         if (dir[i1] == EAST) jetaE[i1] = ieta;
00773         else                 jetaW[i1] = ieta;
00774         if (flag != 0) {
00775           if (std::count(vdets.begin(),vdets.end(),cells[0]) == 0) {
00776             vdets.push_back(cells[0]);
00777             CaloDirection dirn = dir[i1];
00778             int ketaE = ietaE[i1];
00779             int ketaW = ietaW[i1];
00780             if (dirn == EAST) ketaE = ieta;
00781             else              ketaW = ieta;
00782             if (flag < 0) {
00783               int ktmp = ketaW; ketaW    = ketaE; ketaE    = ktmp;
00784               if (dirn == EAST) dirn = WEST;
00785               else              dirn = EAST;
00786             }
00787             dirs.push_back(dirn);
00788             jetaE.push_back(ketaE);
00789             jetaW.push_back(ketaW);
00790           }
00791         }
00792       }
00793     }
00794     
00795     if (debug) {
00796       std::cout << "newECALIdEW::Addition results a set of " 
00797                 << (vdets.size()-dets.size()) << " new  cells (last " 
00798                 << dets.size() << ", ieta " << keta << ")" << std::endl;
00799       for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00800         if (vdets[i1].subdetId() == EcalBarrel) {
00801           EBDetId id = vdets[i1];
00802           std::cout << "newECALIdEW::Cell " << i1 << " "  << id << std::endl;
00803         } else if (vdets[i1].subdetId() == EcalEndcap) {
00804           EEDetId id = vdets[i1];
00805           std::cout << "newECALIdEW::Cell " << i1 << " " << id << std::endl;
00806         } else {
00807           std::cout << "newECALIdEW::Cell " << i1 << " 0x" << std::hex 
00808                     << vdets[i1]() << std::dec << " Unknown Type" << std::endl;
00809         }
00810       }
00811     }
00812 
00813     if (keta > 0) {
00814       last = dets.size();
00815       return spr::newECALIdEW(vdets, last, jetaE, jetaW, dirs, barrelTopo,
00816                               endcapTopo, barrelGeom, endcapGeom, debug);
00817     } else {
00818       if (debug) {
00819         std::cout << "newECALIdEW::Final list (EW) consists of " <<vdets.size()
00820                   << " cells" << std::endl;
00821         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00822           if (vdets[i1].subdetId() == EcalBarrel) {
00823             EBDetId id = vdets[i1];
00824             std::cout << "newECALIdEW::Cell " << i1 << " "  << id << std::endl;
00825           } else if (vdets[i1].subdetId() == EcalEndcap) {
00826             EEDetId id = vdets[i1];
00827             std::cout << "newECALIdEW::Cell " << i1 << " " << id << std::endl;
00828           } else {
00829             std::cout << "newECALIdEW::Cell " << i1 << " 0x" << std::hex 
00830                       << vdets[i1]() <<std::dec << " Unknown Type" <<std::endl;
00831           }
00832         }
00833       }
00834       return vdets;
00835     }
00836   }
00837 
00838   void simpleMove(DetId& det, const CaloDirection& dir, 
00839                   const CaloSubdetectorTopology& barrelTopo, 
00840                   const CaloSubdetectorTopology& endcapTopo, 
00841                   const EcalBarrelGeometry& barrelGeom, 
00842                   const EcalEndcapGeometry& endcapGeom, 
00843                   std::vector<DetId>& cells, int& ok, bool debug) {
00844 
00845     DetId cell;
00846     ok = 0;
00847     if (det.subdetId() == EcalBarrel) {
00848       EBDetId detId = det;
00849       std::vector<DetId> neighbours = barrelTopo.getNeighbours(detId,dir);
00850       if (neighbours.size()>0 && !neighbours[0].null()) {
00851         cells.push_back(neighbours[0]);
00852         cell = neighbours[0];
00853         ok   = 1;
00854       } else {
00855         const int ietaAbs ( detId.ietaAbs() ) ; // abs value of ieta
00856         if (EBDetId::MAX_IETA == ietaAbs ) {
00857           // get ee nbrs for for end of barrel crystals
00858           const EcalBarrelGeometry::OrderedListOfEEDetId&
00859             ol( * barrelGeom.getClosestEndcapCells(detId) ) ;
00860           // take closest neighbour on the other side, that is in the endcap
00861           cell = *(ol.begin() );
00862           neighbours = endcapTopo.getNeighbours(cell,dir);
00863           if (neighbours.size()>0 && !neighbours[0].null()) ok = 1;
00864           else                                              ok =-1;
00865           for (EcalBarrelGeometry::OrderedListOfEEDetId::const_iterator iptr=ol.begin(); iptr != ol.end(); ++iptr)
00866             cells.push_back(*iptr);
00867         }
00868       }
00869     } else if (det.subdetId() == EcalEndcap) {
00870       EEDetId detId = det;
00871       std::vector<DetId> neighbours = endcapTopo.getNeighbours(detId,dir);
00872       if (neighbours.size()>0 && !neighbours[0].null()) {
00873         cells.push_back(neighbours[0]);
00874         cell = neighbours[0];
00875         ok   = 1;
00876       } else {
00877         // are we on the outer ring ?
00878         const int iphi ( detId.iPhiOuterRing() ) ;
00879         if (iphi!= 0) {
00880           // get eb nbrs for for end of endcap crystals
00881           const EcalEndcapGeometry::OrderedListOfEBDetId&
00882             ol( * endcapGeom.getClosestBarrelCells(detId) ) ;
00883           // take closest neighbour on the other side, that is in the barrel.
00884           cell = *(ol.begin() );
00885           neighbours = barrelTopo.getNeighbours(cell,dir);
00886           if (neighbours.size()>0 && !neighbours[0].null()) ok = 1;
00887           else                                              ok =-1;
00888           for (EcalEndcapGeometry::OrderedListOfEBDetId::const_iterator iptr=ol.begin(); iptr != ol.end(); ++iptr)
00889             cells.push_back(*iptr);
00890         }
00891       }
00892     }  
00893     if (debug) {
00894       std::cout << "simpleMove:: Move DetId 0x" << std::hex << det() 
00895                 << std::dec << " along " << dir << " to get 0x" << std::hex
00896                 << cell() << std::dec << " with flag " << ok << " # "
00897                 << cells.size();
00898       for (unsigned int i1=0; i1<cells.size(); ++i1) 
00899         std::cout << " " << std::hex << cells[0]() << std::dec;
00900       std::cout << std::endl;
00901     }
00902   }
00903 
00904   void extraIds(const DetId& det, std::vector<DetId>& dets, int ietaE, int ietaW, int iphiN, int iphiS, const EcalBarrelGeometry& barrelGeom, const EcalEndcapGeometry& endcapGeom, std::vector<DetId>& cells, bool debug) {
00905 
00906     if (det.subdetId() == EcalBarrel) {
00907       EBDetId id = det;
00908       if (debug) std::cout << "extraIds::Cell " << id << " rows "  << ietaW
00909                            << "|" << ietaE << " columns " << iphiS << "|"
00910                            << iphiN << std::endl;
00911       int etaC = id.ietaAbs();
00912       int phiC = id.iphi();
00913       int zsid = id.zside();
00914       for (int eta = -ietaW; eta <= ietaE; ++eta) {
00915         for (int phi = -iphiS; phi <= iphiN; ++phi) {
00916           int iphi = phiC+phi;
00917           if (iphi < 0)        iphi += 360;
00918           else if (iphi > 360) iphi -= 360;    
00919           int ieta = zsid*(etaC+eta);
00920           if (EBDetId::validDetId(ieta,iphi)) {
00921             id = EBDetId(ieta,iphi);
00922             if (barrelGeom.present(id)) {
00923               if (std::count(dets.begin(),dets.end(),(DetId)id) == 0) {
00924                 cells.push_back((DetId)id);
00925               }
00926             }
00927           }
00928         }
00929       }
00930     } else if (det.subdetId() == EcalEndcap) {
00931       EEDetId id = det;
00932       if (debug) std::cout << "extraIds::Cell " << id << " rows "  << ietaW
00933                            << "|" << ietaE << " columns " << iphiS << "|"
00934                            << iphiN << std::endl;
00935       int ixC  = id.ix();
00936       int iyC  = id.iy();
00937       int zsid = id.zside();
00938       for (int kx = -ietaW; kx <= ietaE; ++kx) {
00939         for (int ky = -iphiS; ky <= iphiN; ++ky) {
00940           int ix = ixC+kx;
00941           int iy = iyC+ky;
00942           if (EEDetId::validDetId(ix,iy,zsid)) {
00943             id = EEDetId(ix,iy,zsid);
00944             if (endcapGeom.present(id)) {
00945               if (std::count(dets.begin(),dets.end(),(DetId)id) == 0) {
00946                 cells.push_back((DetId)id);
00947               }
00948             }
00949           }
00950         }
00951       }
00952     } 
00953 
00954     if (debug) {
00955       std::cout << "extraIds:: finds " << cells.size() << " new cells" 
00956                 << std::endl;
00957       for (unsigned int i1=0; i1<cells.size(); ++i1) {
00958         if (cells[i1].subdetId() == EcalBarrel) {
00959           EBDetId id = cells[i1];
00960           std::cout << "extraIds::Cell " << i1 << " "  << id << std::endl;
00961         } else if (cells[i1].subdetId() == EcalEndcap) {
00962           EEDetId id = cells[i1];
00963           std::cout << "ectraIds::Cell " << i1 << " " << id << std::endl;
00964         } else {
00965           std::cout << "extraIds::Cell " << i1 << " 0x" << std::hex 
00966                     << cells[i1]() <<std::dec << " Unknown Type" <<std::endl;
00967         }
00968       }
00969     }
00970   }
00971 }