Go to the documentation of this file.00001 #include "SimCalorimetry/HcalSimProducers/interface/HcalHitRelabeller.h"
00002 #include "SimDataFormats/CaloTest/interface/HcalTestNumbering.h"
00003 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00004
00005 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00006 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00007
00008
00009
00010 HcalHitRelabeller::HcalHitRelabeller(const edm::ParameterSet& ps) {
00011
00012 m_segmentation.resize(29);
00013 m_CorrectPhi = ps.getUntrackedParameter<bool>("CorrectPhi",false);
00014 for (int i=0; i<29; i++) {
00015 char name[10];
00016 snprintf(name,10,"Eta%d",i+1);
00017 if (i>0) {
00018 m_segmentation[i]=ps.getUntrackedParameter<std::vector<int> >(name,m_segmentation[i-1]);
00019 } else {
00020 m_segmentation[i]=ps.getUntrackedParameter<std::vector<int> >(name);
00021 }
00022 }
00023 #ifdef DEBUG
00024 for (int i=0; i<29; i++) {
00025 std::cout << "Segmentation[" << i << "] with " << m_segmentation[i].size() << " elements:";
00026 for (unsigned int k=0; k<m_segmentation[i].size(); ++k)
00027 std::cout << " " << m_segmentation[i][k];
00028 std::cout << std::endl;
00029 }
00030 std::cout << "correctPhi " << m_CorrectPhi << std::endl;
00031 #endif
00032 }
00033
00034 void HcalHitRelabeller::process(std::vector<PCaloHit>& hcalHits) {
00035
00036 for (unsigned int ii=0; ii<hcalHits.size(); ++ii) {
00037
00038 #ifdef DEBUG
00039 std::cout << "Hit[" << ii << "] " << std::hex << hcalHits[ii].id() << std::dec << '\n';
00040 #endif
00041 DetId newid = relabel(hcalHits[ii].id());
00042 #ifdef DEBUG
00043 std::cout << "Hit " << ii << " out of " << hcalHits.size() << " " << std::hex << newid.rawId() << std::dec << '\n';
00044 HcalDetId newcell(newid);
00045 const CaloCellGeometry *cellGeometry =
00046 theGeometry->getSubdetectorGeometry(newcell)->getGeometry(newcell);
00047 GlobalPoint globalposition = (GlobalPoint)(cellGeometry->getPosition());
00048
00049 std::cout << "PCaloHit " << newcell << " position: " << globalposition << std::endl;
00050 std::cout.flush();
00051 #endif
00052 hcalHits[ii].setID(newid.rawId());
00053 #ifdef DEBUG
00054 std::cout << "Modified Hit " << hcalHits[ii] << std::endl;
00055 #endif
00056 }
00057
00058
00059 }
00060
00061
00062 void HcalHitRelabeller::setGeometry(const CaloGeometry*& geom) {
00063 theGeometry = geom;
00064 }
00065
00066 DetId HcalHitRelabeller::relabel(const uint32_t testId) const {
00067
00068 #ifdef DEBUG
00069 std::cout << "Enter HcalHitRelabeller::relabel " << std::endl;
00070 #endif
00071 HcalDetId hid;
00072 int det, z, depth, eta, phi, layer, sign;
00073 HcalTestNumbering::unpackHcalIndex(testId,det,z,depth,eta,phi,layer);
00074
00075 layer-=1;
00076
00077 sign=(z==0)?(-1):(1);
00078 #ifdef DEBUG
00079 std::cout << "det: " << det << " "
00080 << "z: " << z << " "
00081 << "depth: " << depth << " "
00082 << "ieta: " << eta << " "
00083 << "iphi: " << phi << " "
00084 << "layer: " << layer << " ";
00085 std::cout.flush();
00086 #endif
00087 int newDepth = 0;
00088 int phi_skip = phi;
00089 if (m_CorrectPhi) {
00090 if (eta >= 40) phi_skip = (phi-1)*4 - 1;
00091 else if (eta > 20) phi_skip = (phi-1)*2 + 1;
00092 if (phi_skip < 0) phi_skip += 72;
00093 }
00094
00095 if (det==int(HcalBarrel)) {
00096 newDepth=m_segmentation[eta-1][layer];
00097 if(eta==16 && newDepth > 2) newDepth=2;
00098 hid=HcalDetId(HcalBarrel,eta*sign,phi_skip,newDepth);
00099 }
00100 if (det==int(HcalEndcap)) {
00101 newDepth=m_segmentation[eta-1][layer];
00102 if (eta==16 && newDepth<3) newDepth=3;
00103 hid=HcalDetId(HcalEndcap,eta*sign,phi_skip,newDepth);
00104 }
00105 if (det==int(HcalOuter)) {
00106 hid=HcalDetId(HcalOuter,eta*sign,phi_skip,4);
00107 newDepth = 4;
00108 }
00109 if (det==int(HcalForward)) {
00110 hid=HcalDetId(HcalForward,eta*sign,phi_skip,depth);
00111 newDepth = depth;
00112 }
00113 #ifdef DEBUG
00114 std::cout << " new HcalDetId -> hex.RawID = "
00115 << std::hex << hid.rawId() << std::dec;
00116 std::cout.flush();
00117 std::cout << " det, z, depth, eta, phi = "
00118 << det << " "
00119 << z << " "
00120 << newDepth << " "
00121 << eta << " "
00122 << phi << " " << phi_skip << " "
00123 << " ---> " << hid << std::endl;
00124 #endif
00125 return hid;
00126 }