CMS 3D CMS Logo

SimG4HcalHitJetFinder.cc
Go to the documentation of this file.
1 // File: SimG4HcalHitJetFinder.cc
3 // Description: Jet finder class for SimG4HcalValidation
8 
9 #include <algorithm>
10 #include <iostream>
11 #include <cmath>
12 
13 SimG4HcalHitJetFinder::SimG4HcalHitJetFinder(double cone): jetcone(cone) {}
14 
16  edm::LogInfo("ValidHcal") << "SimG4HcalHitJetFinder:: Deleting";
17 }
18 
19 void SimG4HcalHitJetFinder::setCone(double cone) {
20  jetcone = cone;
21 }
22 
23 void SimG4HcalHitJetFinder::setInput(std::vector<CaloHit>* hhit) {
24  input = * hhit;
25 }
26 
27 std::vector<SimG4HcalHitCluster>* SimG4HcalHitJetFinder::getClusters(bool hcal_only){
28  clusvector.erase(clusvector.begin(),clusvector.end());
29  if (input.empty()) {
30  return &clusvector;
31  }
32 
33  std::vector<CaloHit>::iterator itr;
34  for (itr = input.begin(); itr != input.end(); itr++) {
35  LogDebug("ValidHcal") << "HcalHitJetFinder::getClusters_1 - input : e "
36  << itr->e() << " eta " << itr->eta() << " phi "
37  << itr->phi() << " subdet " << itr->det();
38  }
39 
40  sort(input.begin(),input.end()); // sort input in descending order
41 
42  for (itr = input.begin(); itr != input.end(); itr++) {
43  LogDebug("ValidHcal") << "HcalHitJetFinder::getClusters_2 - input : e "
44  << itr->e() << " eta " << itr->eta() << " phi "
45  << itr->phi() << " subdet " << itr->det();
46  }
47 
48  std::vector<SimG4HcalHitCluster> temp; // dummy container for clusters
49 
50  // first input hit -> first cluster
51 
52  CaloHit hit;
53  SimG4HcalHitCluster cluster;
54 
55  std::vector<CaloHit>::iterator itr_hits;
56 
57  int j, first_seed = 0;
58  for (j=0, itr_hits = input.begin(); itr_hits != input.end();
59  j++, itr_hits++) {
60  int h_type = itr_hits->det(); //if desired HCAL hits (only) clusterfinding
61  if (((h_type == static_cast<int>(HcalBarrel) ||
62  h_type == static_cast<int>(HcalEndcap) ||
63  h_type == static_cast<int>(HcalForward)) && hcal_only) ||
64  (!hcal_only)) {
65  cluster += input[j];
66  LogDebug("ValidHcal") << "HcalHitJetFinder:: First seed hit "
67  << "..................\n" << (*itr_hits);
68  first_seed = j;
69  break;
70  }
71  }
72 
73  temp.push_back(cluster);
74 
75  std::vector<SimG4HcalHitCluster>::iterator itr_clus;
76 
77  for (j=0, itr_hits = input.begin(); itr_hits != input.end();
78  j++, itr_hits++) {
79  int h_type = itr_hits->det(); //if desired HCAL hits (only) clusterfinding
80  if ((((h_type == static_cast<int>(HcalBarrel) ||
81  h_type == static_cast<int>(HcalEndcap) ||
82  h_type == static_cast<int>(HcalForward)) && hcal_only) ||
83  (!hcal_only)) && (j != first_seed)) {
84  LogDebug("ValidHcal") << "HcalHitJetFinder:: ........... Consider hit"
85  << " ..................\n" << (*itr_hits);
86 
87  int incl = 0; // if the hit is included in one of clusters
88 
89  int iclus;
90  for (itr_clus = temp.begin(), iclus = 0; itr_clus != temp.end();
91  itr_clus++, iclus++) {
92 
93  LogDebug("ValidHcal") << "HcalHitJetFinder::=======> Cluster "
94  << iclus << "\n" << (*itr_clus);
95 
96  double d = rDist(&(*itr_clus), &(*itr_hits));
97  if (d < jetcone) {
98  LogDebug("ValidHcal") << "HcalHitJetFinder:: -> associated ... ";
99  temp[iclus] += *itr_hits;
100  incl = 1;
101  break;
102  }
103  }
104 
105  // to here jumps "break"
106  if (incl == 0) {
108  cl += *itr_hits;
109  temp.push_back(cl);
110  LogDebug("ValidHcal") << "HcalHitJetFinder:: ************ NEW CLUSTER"
111  << " !\n" << cl;
112  }
113  }
114  }
115 
116  clusvector = temp;
117  return &clusvector;
118 }
119 
121  const CaloHit* hit) const {
122 
123  double etac = cluster->eta();
124  double phic = cluster->phi();
125 
126  double etah = hit->eta();
127  double phih = hit->phi();
128 
129  return rDist(etac, phic, etah, phih);
130 }
131 
132 
133 double SimG4HcalHitJetFinder::rDist(const double etac,const double phic,
134  const double etah,const double phih) const{
135 
136  double delta_eta = etac - etah;
137  double delta_phi = phic - phih;
138 
139  if (phic < phih) delta_phi = phih - phic;
140  if (delta_phi > M_PI) delta_phi = 2*M_PI - delta_phi;
141 
142  double tmp = sqrt(delta_eta * delta_eta + delta_phi * delta_phi);
143 
144  LogDebug("ValidHcal") << "HcalHitJetFinder::rDist:\n"
145  << " Clus. eta, phi = " << etac << " " << phic << "\n"
146  << " hit eta, phi = " << etah << " " << phih
147  << " rDist = " << tmp;
148 
149  return tmp;
150 }
151 
#define LogDebug(id)
double phi() const
Definition: CaloHit.h:26
void setInput(std::vector< CaloHit > *)
double eta() const
Definition: CaloHit.h:25
std::vector< CaloHit > input
SimG4HcalHitJetFinder(double cone=0.5)
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< SimG4HcalHitCluster > clusvector
#define M_PI
std::vector< SimG4HcalHitCluster > * getClusters(bool)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double rDist(const SimG4HcalHitCluster *, const CaloHit *) const