00001 #include "Calibration/EcalCalibAlgos/interface/MatrixFillMap.h"
00002 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00003 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00004 #include "FWCore/Utilities/interface/isFinite.h"
00005
00006 MatrixFillMap::MatrixFillMap (int WindowX,
00007 int WindowY,
00008 std::map<int,int> xtalReg,
00009 double minE,
00010 double maxE,
00011 std::map<int,int> IndexReg,
00012 EcalIntercalibConstantMap * barrelMap,
00013 EcalIntercalibConstantMap * endcapMap):
00014
00015 VFillMap (WindowX,WindowY,xtalReg,minE,
00016 maxE, IndexReg,
00017 barrelMap,endcapMap)
00018 {
00019 }
00020
00021 MatrixFillMap::~MatrixFillMap ()
00022 {
00023 }
00024
00025
00026 void
00027 MatrixFillMap::fillMap (const std::vector<std::pair<DetId,float> > & v1,
00028 const DetId Max,
00029 const EcalRecHitCollection * barrelHitsCollection,
00030 const EcalRecHitCollection * endcapHitsCollection,
00031 std::map<int, double> & xtlMap,
00032 double & pSubtract)
00033 {
00034 if (Max.subdetId() == EcalBarrel ){
00035 EBDetId EBMax = Max;
00036 fillEBMap (EBMax, barrelHitsCollection, xtlMap,
00037 m_xtalRegionId[Max.rawId()], pSubtract ) ;
00038 }
00039 else if (Max.subdetId()== EcalEndcap){
00040 EEDetId EEMax = Max;
00041 fillEEMap (EEMax, endcapHitsCollection, xtlMap,
00042 m_xtalRegionId[Max.rawId()],pSubtract ) ;
00043 }
00044 }
00045
00046
00047
00048 void
00049 MatrixFillMap::fillEBMap (EBDetId EBmax,
00050 const EcalRecHitCollection * barrelHitsCollection,
00051 std::map<int, double> & EBRegionMap,
00052 int EBNumberOfRegion, double & pSubtract)
00053 {
00054 int curr_eta;
00055 int curr_phi;
00056
00057 for (int ii = 0 ; ii< m_recoWindowSidex ; ++ii)
00058 for (int ij =0 ; ij< m_recoWindowSidey ; ++ij)
00059 {
00060 curr_eta=EBmax.ieta() + ii - (m_recoWindowSidex/2);
00061 curr_phi=EBmax.iphi() + ij - (m_recoWindowSidey/2);
00062
00063 if (abs(curr_eta)>85) continue;
00064
00065 if (curr_eta * EBmax.ieta() <= 0) {
00066 if (EBmax.ieta() > 0) curr_eta--;
00067 else curr_eta++;
00068 }
00069
00070 if (curr_phi < 1) curr_phi += 360;
00071 if (curr_phi >= 360) curr_phi -= 360;
00072
00073 if(EBDetId::validDetId(curr_eta,curr_phi))
00074 {
00075 EBDetId det = EBDetId(curr_eta,curr_phi,EBDetId::ETAPHIMODE);
00076 int ID= det.rawId();
00077
00078 EcalRecHitCollection::const_iterator curr_recHit = barrelHitsCollection->find(det) ;
00079 double dummy = 0;
00080 dummy = curr_recHit->energy () ;
00081
00082 if (edm::isNotFinite(dummy)){
00083 dummy=0;
00084 }
00085 if ( dummy < m_minEnergyPerCrystal) continue;
00086 if (dummy > m_maxEnergyPerCrystal) continue;
00087
00088 dummy *= (*m_barrelMap)[det];
00089
00090 if (m_xtalRegionId[ID]==EBNumberOfRegion)
00091 EBRegionMap[m_IndexInRegion[ID]]+= dummy;
00092
00093 else pSubtract +=dummy;
00094 }
00095 }
00096 }
00097
00098 void MatrixFillMap::fillEEMap (EEDetId EEmax,
00099 const EcalRecHitCollection * endcapHitsCollection,
00100 std::map<int,double> & EExtlMap,
00101 int EENumberOfRegion, double & pSubtract )
00102 {
00103 int curr_x;
00104 int curr_y;
00105 for (int ii = 0 ; ii< m_recoWindowSidex ; ++ii)
00106 for (int ij =0 ; ij< m_recoWindowSidey ; ++ij)
00107 {
00108
00109 curr_x = EEmax.ix() - m_recoWindowSidex/2 +ii;
00110 curr_y = EEmax.iy() - m_recoWindowSidey /2 +ij;
00111 if(EEDetId::validDetId(curr_x,curr_y,EEmax.zside()))
00112 {
00113 EEDetId det = EEDetId(curr_x,curr_y,EEmax.zside(),EEDetId::XYMODE);
00114 int ID=det.rawId();
00115 EcalRecHitCollection::const_iterator curr_recHit = endcapHitsCollection->find(det) ;
00116 double dummy = curr_recHit->energy () ;
00117 if (edm::isNotFinite(dummy)) {
00118 dummy=0;
00119 }
00120 if ( dummy < m_minEnergyPerCrystal ) continue;
00121 if ( dummy > m_maxEnergyPerCrystal ) {
00122 dummy=0;
00123 continue;
00124 }
00125 dummy *= (*m_endcapMap)[det];
00126 if (m_xtalRegionId[ID]==EENumberOfRegion)
00127 EExtlMap[m_IndexInRegion[ID]] += dummy;
00128 else pSubtract +=dummy;
00129 }
00130 }
00131 }