CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Calibration/IsolatedParticles/src/MatrixHCALDetIds.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00002 
00003 #include "Calibration/IsolatedParticles/interface/MatrixHCALDetIds.h"
00004 
00005 #include<algorithm>
00006 #include<iostream>
00007 
00008 namespace spr{
00009 
00010   std::vector<DetId> matrixHCALIds(std::vector<DetId>& dets, 
00011                                    const HcalTopology* topology, int ieta, 
00012                                    int iphi, bool includeHO, bool debug) {
00013 
00014     if (debug) {
00015       std::cout << "matrixHCALIds::Add " << ieta << " rows and " << iphi 
00016                 << " columns of cells for " << dets.size() << " cells" 
00017                 << std::endl;
00018       for (unsigned int i1=0; i1<dets.size(); i1++) {
00019         HcalDetId id = HcalDetId(dets[i1]());   
00020         std::cout << "matrixHCALIds::Cell " << i1 << " 0x" << std::hex 
00021                   << id.rawId() << std::dec << " " << id << std::endl;
00022       }
00023     }
00024 
00025     std::vector<DetId> vdetN = spr::newHCALIdNS(dets, 0, topology, true,  ieta,
00026                                                iphi, debug);
00027     std::vector<DetId> vdetS = spr::newHCALIdNS(dets, 0, topology, false, ieta,
00028                                                 iphi, debug);
00029     for (unsigned int i1=0; i1<vdetS.size(); i1++) {
00030       if (std::count(vdetN.begin(),vdetN.end(),vdetS[i1]) == 0)
00031         vdetN.push_back(vdetS[i1]);
00032     }
00033 
00034     vdetS = spr::matrixHCALIdsDepth(vdetN, topology, includeHO, debug);
00035 
00036     if (debug) {
00037       std::cout << "matrixHCALIds::Total number of cells found is " 
00038                 << vdetS.size() << std::endl;
00039       for (unsigned int i1=0; i1<vdetS.size(); i1++) {
00040         HcalDetId id = HcalDetId(vdetS[i1]());  
00041         std::cout << "matrixHCALIds::Cell " << i1 << " " << id << std::endl;
00042       }
00043     }
00044     return vdetS;
00045   }
00046 
00047   std::vector<DetId> matrixHCALIds(std::vector<DetId>& dets, 
00048                                    const HcalTopology* topology, int ietaE, 
00049                                    int ietaW,int iphiN,int iphiS, 
00050                                    bool includeHO, bool debug) {
00051 
00052     if (debug) {
00053       std::cout << "matrixHCALIds::Add " <<ietaE << "|" <<ietaW << " rows and "
00054                 << iphiN << "|" << iphiS << " columns of cells for " 
00055                 << dets.size() << " cells" << std::endl;
00056       for (unsigned int i1=0; i1<dets.size(); i1++) {
00057         HcalDetId id = HcalDetId(dets[i1]());   
00058         std::cout << "matrixHCALIds::Cell " << i1 << " 0x" << std::hex 
00059                   << id.rawId() << std::dec << " " << id << std::endl;
00060       }
00061     }
00062 
00063     std::vector<DetId> vdetN = spr::newHCALIdNS(dets, 0, topology, true, ietaE,
00064                                                 ietaW, iphiN, iphiS, debug);
00065     std::vector<DetId> vdetS = spr::newHCALIdNS(dets, 0, topology, false,ietaE,
00066                                                 ietaW, iphiN, iphiS, debug);
00067     for (unsigned int i1=0; i1<vdetS.size(); i1++) {
00068       if (std::count(vdetN.begin(),vdetN.end(),vdetS[i1]) == 0)
00069         vdetN.push_back(vdetS[i1]);
00070     }
00071 
00072     vdetS = spr::matrixHCALIdsDepth(vdetN, topology, includeHO, debug);
00073 
00074     if (debug) {
00075       std::cout << "matrixHCALIds::Total number of cells found is " 
00076                 << vdetS.size() << std::endl;
00077       for (unsigned int i1=0; i1<vdetS.size(); i1++) {
00078         HcalDetId id = HcalDetId(vdetS[i1]());  
00079         std::cout << "matrixHCALIds::Cell " << i1 << " " << id << std::endl;
00080       }
00081     }
00082     return vdetS;
00083   }
00084 
00085   std::vector<DetId> newHCALIdNS(std::vector<DetId>& dets, unsigned int last,
00086                                  const HcalTopology* topology, bool shiftNorth,
00087                                  int ieta, int iphi, bool debug) {
00088 
00089     if (debug) {
00090       std::cout << "newHCALIdNS::Add " << iphi << " columns of cells along " 
00091                 << shiftNorth << " for " << (dets.size()-last) << " cells" 
00092                 << std::endl;
00093       for (unsigned int i1=last; i1<dets.size(); i1++) {
00094         HcalDetId id = HcalDetId(dets[i1]());   
00095         std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
00096       }
00097     }
00098 
00099     std::vector<DetId> vdets;
00100     vdets.insert(vdets.end(), dets.begin(), dets.end());
00101     std::vector<DetId> vdetE, vdetW;
00102     if (last == 0) {
00103       vdetE = spr::newHCALIdEW(dets, last, topology, true,  ieta, debug);
00104       vdetW = spr::newHCALIdEW(dets, last, topology, false, ieta, debug);
00105       for (unsigned int i1=0; i1<vdetW.size(); i1++) {
00106         if (std::count(vdets.begin(),vdets.end(),vdetW[i1]) == 0)
00107           vdets.push_back(vdetW[i1]);
00108       }
00109       for (unsigned int i1=0; i1<vdetE.size(); i1++) {
00110         if (std::count(vdets.begin(),vdets.end(),vdetE[i1]) == 0)
00111           vdets.push_back(vdetE[i1]);
00112       }
00113       if (debug) {
00114         std::cout <<"newHCALIdNS::With Added cells along E/W results a set of "
00115                   << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00116         for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00117           HcalDetId id = HcalDetId(vdets[i1]());        
00118           std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00119         }
00120       }
00121     }
00122     unsigned int last0 = vdets.size();
00123     if (iphi > 0) {
00124       std::vector<DetId> vdetnew;
00125       for (unsigned int i1=last; i1<dets.size(); i1++) {
00126         std::vector<DetId> vdet;
00127         if (shiftNorth) vdet = topology->north(dets[i1]);
00128         else            vdet = topology->south(dets[i1]);
00129         for (unsigned int i2=0; i2<vdet.size(); i2++) {
00130           if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
00131             vdetnew.push_back(vdet[i2]);
00132         }
00133       }
00134       iphi--;
00135       vdetE = spr::newHCALIdEW(vdetnew, 0, topology, true,  ieta, debug);
00136       vdetW = spr::newHCALIdEW(vdetnew, 0, topology, false, ieta, debug);
00137       for (unsigned int i2=0; i2<vdetW.size(); i2++) {
00138         if (std::count(vdets.begin(),vdets.end(),vdetW[i2]) == 0 &&
00139             std::count(vdetnew.begin(),vdetnew.end(),vdetW[i2]) == 0)
00140           vdets.push_back(vdetW[i2]);
00141       }
00142       for (unsigned int i2=0; i2<vdetE.size(); i2++) {
00143         if (std::count(vdets.begin(),vdets.end(),vdetE[i2]) == 0 &&
00144             std::count(vdetnew.begin(),vdetnew.end(),vdetE[i2]) == 0)
00145           vdets.push_back(vdetE[i2]);
00146       }
00147       last = vdets.size();
00148       vdets.insert(vdets.end(), vdetnew.begin(), vdetnew.end());
00149       if (debug) {
00150         std::cout << "newHCALIdNS::Addition results a set of " 
00151                   << (vdets.size()-last0)  << " new  cells" << std::endl;
00152         for (unsigned int i1=last0; i1<vdets.size(); i1++) {
00153           HcalDetId id = HcalDetId(vdets[i1]());        
00154           std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
00155         }
00156       }
00157       last0 = last;
00158     }
00159 
00160     if (iphi > 0) {
00161       last = last0;
00162       return spr::newHCALIdNS(vdets,last,topology,shiftNorth,ieta,iphi,debug);
00163     } else {
00164       if (debug) {
00165         std::cout << "newHCALIdNS::Final list consists of " << vdets.size()
00166                   << " cells" << std::endl;
00167         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00168           HcalDetId id = HcalDetId(vdets[i1]());        
00169           std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
00170         }
00171       }
00172       return vdets;
00173     }
00174   }
00175 
00176   std::vector<DetId> newHCALIdNS(std::vector<DetId>& dets, unsigned int last,
00177                                  const HcalTopology* topology, bool shiftNorth,
00178                                  int ietaE, int ietaW, int iphiN, int iphiS,
00179                                  bool debug) {
00180 
00181     if (debug) {
00182       std::cout << "newHCALIdNS::Add " << iphiN << "|" << iphiS
00183                 << " columns of cells along " << shiftNorth << " for " 
00184                 << (dets.size()-last) << " cells" << std::endl;
00185       for (unsigned int i1=last; i1<dets.size(); i1++) {
00186         HcalDetId id = HcalDetId(dets[i1]());   
00187         std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
00188       }
00189     }
00190 
00191     std::vector<DetId> vdets;
00192     vdets.insert(vdets.end(), dets.begin(), dets.end());
00193     std::vector<DetId> vdetE, vdetW;
00194     if (last == 0) {
00195       vdetE = spr::newHCALIdEW(dets,last, topology, true,  ietaE,ietaW, debug);
00196       vdetW = spr::newHCALIdEW(dets,last, topology, false, ietaE,ietaW, debug);
00197       for (unsigned int i1=0; i1<vdetW.size(); i1++) {
00198         if (std::count(vdets.begin(),vdets.end(),vdetW[i1]) == 0)
00199           vdets.push_back(vdetW[i1]);
00200       }
00201       for (unsigned int i1=0; i1<vdetE.size(); i1++) {
00202         if (std::count(vdets.begin(),vdets.end(),vdetE[i1]) == 0)
00203           vdets.push_back(vdetE[i1]);
00204       }
00205       if (debug) {
00206         std::cout <<"newHCALIdNS::With Added cells along E/W results a set of "
00207                   << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00208         for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00209           HcalDetId id = HcalDetId(vdets[i1]());        
00210           std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00211         }
00212       }
00213     }
00214     unsigned int last0 = vdets.size();
00215     int iphi = iphiS;
00216     if (shiftNorth) iphi = iphiN;
00217     if (iphi > 0) {
00218       std::vector<DetId> vdetnew;
00219       for (unsigned int i1=last; i1<dets.size(); i1++) {
00220         std::vector<DetId> vdet;
00221         if (shiftNorth) vdet = topology->north(dets[i1]);
00222         else            vdet = topology->south(dets[i1]);
00223         for (unsigned int i2=0; i2<vdet.size(); i2++) {
00224           if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
00225             vdetnew.push_back(vdet[i2]);
00226         }
00227       }
00228       iphi--;
00229       vdetE = spr::newHCALIdEW(vdetnew,0, topology, true,  ietaE,ietaW, debug);
00230       vdetW = spr::newHCALIdEW(vdetnew,0, topology, false, ietaE,ietaW, debug);
00231       for (unsigned int i2=0; i2<vdetW.size(); i2++) {
00232         if (std::count(vdets.begin(),vdets.end(),vdetW[i2]) == 0 &&
00233             std::count(vdetnew.begin(),vdetnew.end(),vdetW[i2]) == 0)
00234           vdets.push_back(vdetW[i2]);
00235       }
00236       for (unsigned int i2=0; i2<vdetE.size(); i2++) {
00237         if (std::count(vdets.begin(),vdets.end(),vdetE[i2]) == 0 &&
00238             std::count(vdetnew.begin(),vdetnew.end(),vdetE[i2]) == 0)
00239           vdets.push_back(vdetE[i2]);
00240       }
00241       last = vdets.size();
00242       vdets.insert(vdets.end(), vdetnew.begin(), vdetnew.end());
00243       if (debug) {
00244         std::cout << "newHCALIdNS::Addition results a set of " 
00245                   << (vdets.size()-last0)  << " new  cells" << std::endl;
00246         for (unsigned int i1=last0; i1<vdets.size(); i1++) {
00247           HcalDetId id = HcalDetId(vdets[i1]());        
00248           std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
00249         }
00250       }
00251       last0 = last;
00252     }
00253     if (shiftNorth) iphiN = iphi;
00254     else            iphiS = iphi;
00255 
00256     if (iphi > 0) {
00257       last = last0;
00258       return spr::newHCALIdNS(vdets,last,topology,shiftNorth,ietaE,ietaW,
00259                               iphiN,iphiS,debug);
00260     } else {
00261       if (debug) {
00262         std::cout << "newHCALIdNS::Final list consists of " << vdets.size()
00263                   << " cells" << std::endl;
00264         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00265           HcalDetId id = HcalDetId(vdets[i1]());        
00266           std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
00267         }
00268       }
00269       return vdets;
00270     }
00271   }
00272 
00273   std::vector<DetId> newHCALIdEW(std::vector<DetId>& dets, unsigned int last,
00274                                  const HcalTopology* topology, bool shiftEast,
00275                                  int ieta, bool debug) {
00276 
00277     if (debug) {
00278       std::cout << "newHCALIdEW::Add " << ieta << " rows of cells along " 
00279                 << shiftEast << " for " << (dets.size()-last) << " cells" 
00280                 << std::endl;
00281       for (unsigned int i1=last; i1<dets.size(); i1++) {
00282         HcalDetId id = HcalDetId(dets[i1]());   
00283         std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00284       }
00285     }
00286 
00287     std::vector<DetId> vdets;
00288     vdets.insert(vdets.end(), dets.begin(), dets.end());
00289     if (ieta > 0) {
00290       for (unsigned int i1=last; i1<dets.size(); i1++) {
00291         std::vector<DetId> vdet;
00292         if (shiftEast) vdet = topology->east(dets[i1]);
00293         else           vdet = topology->west(dets[i1]);
00294         for (unsigned int i2=0; i2<vdet.size(); i2++) {
00295           if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
00296             vdets.push_back(vdet[i2]);
00297         }
00298       }
00299       ieta--;
00300     }
00301     
00302     if (debug) {
00303       std::cout << "newHCALIdEW::Addition results a set of " 
00304                 << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00305       for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00306         HcalDetId id = HcalDetId(vdets[i1]());  
00307         std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00308       }
00309     }
00310 
00311     if (ieta > 0) {
00312       last = dets.size();
00313       return spr::newHCALIdEW(vdets, last, topology, shiftEast, ieta, debug);
00314     } else {
00315       if (debug) {
00316         std::cout << "newHCALIdEW::Final list (EW) consists of " <<vdets.size()
00317                   << " cells" << std::endl;
00318         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00319           HcalDetId id = HcalDetId(vdets[i1]());        
00320           std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00321         }
00322       }
00323       return vdets;
00324     }
00325   }
00326 
00327   std::vector<DetId> newHCALIdEW(std::vector<DetId>& dets, unsigned int last,
00328                                  const HcalTopology* topology, bool shiftEast,
00329                                  int ietaE, int ietaW, bool debug) {
00330 
00331     if (debug) {
00332       std::cout << "newHCALIdEW::Add " << ietaE << "|" << ietaW
00333                 << " rows of cells along " << shiftEast << " for " 
00334                 << (dets.size()-last) << " cells" << std::endl;
00335       for (unsigned int i1=last; i1<dets.size(); i1++) {
00336         HcalDetId id = HcalDetId(dets[i1]());   
00337         std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00338       }
00339     }
00340 
00341     int ieta = ietaW;
00342     if (shiftEast) ieta = ietaE;
00343     std::vector<DetId> vdets;
00344     vdets.insert(vdets.end(), dets.begin(), dets.end());
00345     if (ieta > 0) {
00346       for (unsigned int i1=last; i1<dets.size(); i1++) {
00347         std::vector<DetId> vdet;
00348         if (shiftEast) vdet = topology->east(dets[i1]);
00349         else           vdet = topology->west(dets[i1]);
00350         for (unsigned int i2=0; i2<vdet.size(); i2++) {
00351           if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
00352             vdets.push_back(vdet[i2]);
00353         }
00354       }
00355       ieta--;
00356     }
00357     if (shiftEast) ietaE = ieta;
00358     else           ietaW = ieta;
00359     
00360     if (debug) {
00361       std::cout << "newHCALIdEW::Addition results a set of " 
00362                 << (vdets.size()-dets.size()) << " new  cells" << std::endl;
00363       for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
00364         HcalDetId id = HcalDetId(vdets[i1]());  
00365         std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00366       }
00367     }
00368 
00369     if (ieta > 0) {
00370       last = dets.size();
00371       return spr::newHCALIdEW(vdets,last,topology,shiftEast,ietaE,ietaW,debug);
00372     } else {
00373       if (debug) {
00374         std::cout << "newHCALIdEW::Final list (EW) consists of " <<vdets.size()
00375                   << " cells" << std::endl;
00376         for (unsigned int i1=0; i1<vdets.size(); i1++) {
00377           HcalDetId id = HcalDetId(vdets[i1]());        
00378           std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
00379         }
00380       }
00381       return vdets;
00382     }
00383   }
00384 
00385   std::vector<DetId> matrixHCALIdsDepth(std::vector<DetId>& dets, 
00386                                         const HcalTopology* topology, 
00387                                         bool includeHO, bool debug) {
00388 
00389     if (debug) {
00390       std::cout << "matrixHCALIdsDepth::Add cells with higher depths with HO" 
00391                 << "Flag set to " << includeHO << " to existing "
00392                 << dets.size() << " cells" << std::endl;
00393       for (unsigned int i1=0; i1<dets.size(); i1++) {
00394         HcalDetId id = HcalDetId(dets[i1]());   
00395         std::cout << "matrixHCALIdsDepth::Cell " << i1 << " " <<id <<std::endl;
00396       }
00397     }
00398  
00399     std::vector<DetId> vdets(dets);
00400     for (unsigned int i1=0; i1<dets.size(); i1++) {
00401       HcalDetId vdet = dets[i1];
00402       for (int idepth = 0; idepth < 3; idepth++) {
00403         std::vector<DetId> vUpDetId = topology->up(vdet);
00404         if (vUpDetId.size() != 0) {
00405           if (includeHO || vUpDetId[0].subdetId() != (int)(HcalOuter)) {
00406             int n = std::count(vdets.begin(),vdets.end(),vUpDetId[0]);
00407             if (n == 0) {
00408               if (debug) std::cout << "matrixHCALIdsDepth:: Depth " << idepth << " " << vdet << " " << (HcalDetId)vUpDetId[0] << std::endl;
00409               vdets.push_back(vUpDetId[0]);
00410             }
00411           }
00412           vdet = vUpDetId[0];
00413         }
00414       }
00415     }
00416 
00417     if (debug) {
00418       std::cout << "matrixHCALIdsDepth::Final list contains " << vdets.size() 
00419                 << " cells" << std::endl;
00420       for (unsigned int i1=0; i1<vdets.size(); i1++) {
00421         HcalDetId id = HcalDetId(vdets[i1]());  
00422         std::cout << "matrixHCALIdsDepth::Cell " << i1 << " " <<id <<std::endl;
00423       }
00424     }
00425     return vdets;
00426   }
00427 
00428 }