00001
00002
00003
00005 #include "Validation/HcalHits/interface/SimG4HcalHitJetFinder.h"
00006 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009 #include <iostream>
00010 #include <cmath>
00011
00012 SimG4HcalHitJetFinder::SimG4HcalHitJetFinder(double cone): jetcone(cone) {}
00013
00014 SimG4HcalHitJetFinder::~SimG4HcalHitJetFinder() {
00015 edm::LogInfo("ValidHcal") << "SimG4HcalHitJetFinder:: Deleting";
00016 }
00017
00018 void SimG4HcalHitJetFinder::setCone(double cone) {
00019 jetcone = cone;
00020 }
00021
00022 void SimG4HcalHitJetFinder::setInput(std::vector<CaloHit>* hhit) {
00023 input = * hhit;
00024 }
00025
00026 std::vector<SimG4HcalHitCluster>* SimG4HcalHitJetFinder::getClusters(bool hcal_only){
00027 clusvector.erase(clusvector.begin(),clusvector.end());
00028 if (input.size() == 0) {
00029 return &clusvector;
00030 }
00031
00032 std::vector<CaloHit>::iterator itr;
00033 for (itr = input.begin(); itr != input.end(); itr++) {
00034 LogDebug("ValidHcal") << "HcalHitJetFinder::getClusters_1 - input : e "
00035 << itr->e() << " eta " << itr->eta() << " phi "
00036 << itr->phi() << " subdet " << itr->det();
00037 }
00038
00039 sort(input.begin(),input.end());
00040
00041 for (itr = input.begin(); itr != input.end(); itr++) {
00042 LogDebug("ValidHcal") << "HcalHitJetFinder::getClusters_2 - input : e "
00043 << itr->e() << " eta " << itr->eta() << " phi "
00044 << itr->phi() << " subdet " << itr->det();
00045 }
00046
00047 std::vector<SimG4HcalHitCluster> temp;
00048
00049
00050
00051 CaloHit hit;
00052 SimG4HcalHitCluster cluster;
00053
00054 std::vector<CaloHit>::iterator itr_hits;
00055
00056 int j, first_seed = 0;
00057 for (j=0, itr_hits = input.begin(); itr_hits != input.end();
00058 j++, itr_hits++) {
00059 int h_type = itr_hits->det();
00060 if (((h_type == static_cast<int>(HcalBarrel) ||
00061 h_type == static_cast<int>(HcalEndcap) ||
00062 h_type == static_cast<int>(HcalForward)) && hcal_only) ||
00063 (!hcal_only)) {
00064 cluster += input[j];
00065 LogDebug("ValidHcal") << "HcalHitJetFinder:: First seed hit "
00066 << "..................\n" << (*itr_hits);
00067 first_seed = j;
00068 break;
00069 }
00070 }
00071
00072 temp.push_back(cluster);
00073
00074 std::vector<SimG4HcalHitCluster>::iterator itr_clus;
00075
00076 for (j=0, itr_hits = input.begin(); itr_hits != input.end();
00077 j++, itr_hits++) {
00078 int h_type = itr_hits->det();
00079 if ((((h_type == static_cast<int>(HcalBarrel) ||
00080 h_type == static_cast<int>(HcalEndcap) ||
00081 h_type == static_cast<int>(HcalForward)) && hcal_only) ||
00082 (!hcal_only)) && (j != first_seed)) {
00083 LogDebug("ValidHcal") << "HcalHitJetFinder:: ........... Consider hit"
00084 << " ..................\n" << (*itr_hits);
00085
00086 int incl = 0;
00087
00088 int iclus;
00089 for (itr_clus = temp.begin(), iclus = 0; itr_clus != temp.end();
00090 itr_clus++, iclus++) {
00091
00092 LogDebug("ValidHcal") << "HcalHitJetFinder::=======> Cluster "
00093 << iclus << "\n" << (*itr_clus);
00094
00095 double d = rDist(&(*itr_clus), &(*itr_hits));
00096 if (d < jetcone) {
00097 LogDebug("ValidHcal") << "HcalHitJetFinder:: -> associated ... ";
00098 temp[iclus] += *itr_hits;
00099 incl = 1;
00100 break;
00101 }
00102 }
00103
00104
00105 if (incl == 0) {
00106 SimG4HcalHitCluster cl;
00107 cl += *itr_hits;
00108 temp.push_back(cl);
00109 LogDebug("ValidHcal") << "HcalHitJetFinder:: ************ NEW CLUSTER"
00110 << " !\n" << cl;
00111 }
00112 }
00113 }
00114
00115 clusvector = temp;
00116 return &clusvector;
00117 }
00118
00119 double SimG4HcalHitJetFinder::rDist(const SimG4HcalHitCluster* cluster,
00120 const CaloHit* hit) const {
00121
00122 double etac = cluster->eta();
00123 double phic = cluster->phi();
00124
00125 double etah = hit->eta();
00126 double phih = hit->phi();
00127
00128 return rDist(etac, phic, etah, phih);
00129 }
00130
00131
00132 double SimG4HcalHitJetFinder::rDist(const double etac,const double phic,
00133 const double etah,const double phih) const{
00134
00135 double delta_eta = etac - etah;
00136 double delta_phi = phic - phih;
00137
00138 if (phic < phih) delta_phi = phih - phic;
00139 if (delta_phi > M_PI) delta_phi = 2*M_PI - delta_phi;
00140
00141 double tmp = sqrt(delta_eta * delta_eta + delta_phi * delta_phi);
00142
00143 LogDebug("ValidHcal") << "HcalHitJetFinder::rDist:\n"
00144 << " Clus. eta, phi = " << etac << " " << phic << "\n"
00145 << " hit eta, phi = " << etah << " " << phih
00146 << " rDist = " << tmp;
00147
00148 return tmp;
00149 }
00150