Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
#include "Calibration/IsolatedParticles/interface/FindCaloHit.h"
#include "Calibration/IsolatedParticles/interface/FindCaloHitCone.h"
#include "Calibration/IsolatedParticles/interface/FindDistCone.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>

namespace spr {

  // Basic cone energy cluster for hcal simhits and hcal rechits
  template <typename T>
  double eCone_hcal(const CaloGeometry* geo,
                    edm::Handle<T>& hits,
                    const GlobalPoint& hpoint1,
                    const GlobalPoint& point1,
                    double dR,
                    const GlobalVector& trackMom,
                    int& nRecHits,
                    double hbThr,
                    double heThr,
                    double hfThr,
                    double hoThr,
                    double tMin,
                    double tMax,
                    int detOnly,
                    int useRaw,
                    bool debug) {
    std::vector<typename T::const_iterator> hit = spr::findHitCone(geo, hits, hpoint1, point1, dR, trackMom, debug);

    nRecHits = -99;
    double energySum = 0.0;
    std::set<int> uniqueIdset;
    for (auto const& ihit : hit) {
      int subdet = DetId(ihit->id()).subdetId();
      if (detOnly < 0 || subdet == detOnly) {
        double eTower = spr::getEnergy(ihit, useRaw);
        double tt = ihit->time();
        bool ok = (eTower > hbThr);
        if (subdet == (int)(HcalEndcap))
          ok = (eTower > heThr);
        else if (subdet == (int)(HcalForward))
          ok = (eTower > hfThr);
        else if (subdet == (int)(HcalOuter))
          ok = (eTower > hoThr);
        if (ok && tt > tMin && tt < tMax) {
          energySum += eTower;
          int eta(-99);
          int phi(-99);
          spr::getEtaPhi(ihit, eta, phi);
          int uniqueEtaPhiId = 100 * eta + phi;
          uniqueIdset.insert(uniqueEtaPhiId);
        }
      }
    }
    nRecHits = uniqueIdset.size();
    if (debug) {
      edm::LogVerbatim("IsoTrack") << "eCone_hcal: Energy " << energySum << " from " << nRecHits << " in subdet "
                                   << detOnly;
    }
    return energySum;
  }

  // Cone energy cluster for hcal simhits and hcal rechits
  // that returns vector of rechit IDs and hottest cell info
  template <typename T>
  double eCone_hcal(const CaloGeometry* geo,
                    edm::Handle<T>& hits,
                    const GlobalPoint& hpoint1,
                    const GlobalPoint& point1,
                    double dR,
                    const GlobalVector& trackMom,
                    int& nRecHits,
                    std::vector<DetId>& coneRecHitDetIds,
                    double& distFromHotCell,
                    int& ietaHotCell,
                    int& iphiHotCell,
                    GlobalPoint& gposHotCell,
                    int detOnly,
                    int useRaw,
                    bool debug) {
    std::vector<typename T::const_iterator> hit = spr::findHitCone(geo, hits, hpoint1, point1, dR, trackMom, debug);

    double energyMax = -99.;
    int hottestIndex = -99;
    ietaHotCell = -99;
    iphiHotCell = -99;
    distFromHotCell = -99.;

    nRecHits = -99;
    double energySum = 0.0;
    std::set<int> uniqueIdset;
    for (unsigned int ihit = 0; ihit < hit.size(); ihit++) {
      int subdet = DetId(hit[ihit]->id()).subdetId();
      if (detOnly < 0 || subdet == detOnly) {
        // Sum energy getting hottest cell for later
        double energy = spr::getEnergy(hit.at(ihit), useRaw);
        if (energy > energyMax) {
          energyMax = energy;
          hottestIndex = ihit;
        }
        energySum += energy;
        // Don't double count depth in rechit multiplicity
        int eta(-99);
        int phi(-99);
        spr::getEtaPhi(hit[ihit], eta, phi);
        int uniqueEtaPhiId = 100 * eta + phi;
        uniqueIdset.insert(uniqueEtaPhiId);
        // Get list of det ids
        coneRecHitDetIds.emplace_back(hit[ihit]->id());
      }
    }

    // Get dist from center of cluster to hottest cell:
    if (hottestIndex != -99) {
      gposHotCell = spr::getGpos(geo, hit.at(hottestIndex));
      ietaHotCell = hit.at(hottestIndex)->id().ieta();
      iphiHotCell = hit.at(hottestIndex)->id().iphi();
      distFromHotCell = spr::getDistInPlaneTrackDir(hpoint1, trackMom, gposHotCell);
    }

    nRecHits = uniqueIdset.size();
    if (debug) {
      edm::LogVerbatim("IsoTrack") << "eCone_hcal: Energy " << energySum << " from " << nRecHits << ":"
                                   << coneRecHitDetIds.size() << " in subdet " << detOnly;
      edm::LogVerbatim("IsoTrack") << "HotCell " << ietaHotCell << ":" << iphiHotCell << " dist " << distFromHotCell;
    }
    return energySum;
  }

  template <typename T>
  double eCone_hcal(const CaloGeometry* geo,
                    edm::Handle<T>& hits,
                    const GlobalPoint& hpoint1,
                    const GlobalPoint& point1,
                    double dR,
                    const GlobalVector& trackMom,
                    int& nRecHits,
                    std::vector<DetId>& coneRecHitDetIds,
                    std::vector<double>& eHit,
                    int useRaw,
                    bool debug) {
    std::vector<typename T::const_iterator> hit = spr::findHitCone(geo, hits, hpoint1, point1, dR, trackMom, debug);
    nRecHits = -99;
    double energySum = 0.0;
    std::set<int> uniqueIdset;
    for (auto const& ihit : hit) {
      // Sum energy getting hottest cell for later
      double energy = spr::getEnergy(ihit, useRaw);
      energySum += energy;
      // Don't double count depth in rechit multiplicity
      int eta(-99), phi(-99);
      spr::getEtaPhi(ihit, eta, phi);
      int uniqueEtaPhiId = 100 * eta + phi;
      uniqueIdset.insert(uniqueEtaPhiId);
      // Get list of det ids
      coneRecHitDetIds.emplace_back(ihit->id());
      eHit.emplace_back(energy);
    }

    nRecHits = uniqueIdset.size();
    if (debug) {
      edm::LogVerbatim("IsoTrack") << "eCone_hcal: Energy " << energySum << " from " << nRecHits << ":"
                                   << coneRecHitDetIds.size();
      for (unsigned int k = 0; k < eHit.size(); ++k)
        edm::LogVerbatim("IsoTrack") << "Hit[" << k << "] " << HcalDetId(coneRecHitDetIds[k]) << " energy " << eHit[k];
    }
    return energySum;
  }

  // Cone energy cluster for hcal simhits and hcal rechits
  // that returns vector of rechit IDs and hottest cell info
  // AND info for making "hit maps"
  template <typename T>
  double eCone_hcal(const CaloGeometry* geo,
                    edm::Handle<T>& hits,
                    const GlobalPoint& hpoint1,
                    const GlobalPoint& point1,
                    double dR,
                    const GlobalVector& trackMom,
                    int& nRecHits,
                    std::vector<int>& RH_ieta,
                    std::vector<int>& RH_iphi,
                    std::vector<double>& RH_ene,
                    std::vector<DetId>& coneRecHitDetIds,
                    double& distFromHotCell,
                    int& ietaHotCell,
                    int& iphiHotCell,
                    GlobalPoint& gposHotCell,
                    int detOnly,
                    int useRaw,
                    bool debug) {
    std::vector<typename T::const_iterator> hit = spr::findHitCone(geo, hits, hpoint1, point1, dR, trackMom, debug);

    double energyMax = -99.;
    int hottestIndex = -99;
    ietaHotCell = -99;
    iphiHotCell = -99;
    distFromHotCell = -99.;

    nRecHits = -99;
    double energySum = 0.0;
    std::set<int> uniqueIdset;
    for (unsigned int ihit = 0; ihit < hit.size(); ihit++) {
      int subdet = DetId(hit[ihit]->id()).subdetId();
      if (detOnly < 0 || subdet == detOnly) {
        // Sum energy getting hottest cell for later
        double energy = spr::getEnergy(hit.at(ihit), useRaw);
        if (energy > energyMax) {
          energyMax = energy;
          hottestIndex = ihit;
        }
        energySum += energy;

        // Get eta phi for counting unique cells
        int eta(-99);
        int phi(-99);
        spr::getEtaPhi(hit[ihit], eta, phi);
        // Put eta phi in vectors
        spr::getEtaPhi(hit[ihit], RH_ieta, RH_iphi, RH_ene);
        int uniqueEtaPhiId = 100 * eta + phi;
        uniqueIdset.insert(uniqueEtaPhiId);
        // Get vector of detids.
        coneRecHitDetIds.emplace_back(hit[ihit]->id());
      }
    }
    nRecHits = uniqueIdset.size();
    // Get dist from center of cluster to hottest cell:
    if (hottestIndex != -99) {
      gposHotCell = spr::getGpos(geo, hit.at(hottestIndex));
      ietaHotCell = hit.at(hottestIndex)->id().ieta();
      iphiHotCell = hit.at(hottestIndex)->id().iphi();
      distFromHotCell = spr::getDistInPlaneTrackDir(hpoint1, trackMom, gposHotCell);
    }

    nRecHits = uniqueIdset.size();
    if (debug) {
      edm::LogVerbatim("IsoTrack") << "eCone_hcal: Energy " << energySum << " from " << nRecHits << ":"
                                   << coneRecHitDetIds.size() << " in subdet " << detOnly;
      edm::LogVerbatim("IsoTrack") << "HotCell " << ietaHotCell << ":" << iphiHotCell << " dist " << distFromHotCell;
    }
    return energySum;
  }

  //
  template <typename T>
  double eCone_ecal(const CaloGeometry* geo,
                    edm::Handle<T>& barrelhits,
                    edm::Handle<T>& endcaphits,
                    const GlobalPoint& hpoint1,
                    const GlobalPoint& point1,
                    double dR,
                    const GlobalVector& trackMom,
                    int& nRecHits,
                    double ebThr,
                    double eeThr,
                    double tMin,
                    double tMax,
                    bool debug) {
    std::vector<typename T::const_iterator> hit =
        spr::findHitCone(geo, barrelhits, endcaphits, hpoint1, point1, dR, trackMom, debug);

    // No depth in Ecal so nRecHits = hit.size()
    nRecHits = hit.size();
    double energySum = 0.0;
    for (auto const& ihit : hit) {
      bool ok = true;
      double eTower = ihit->energy();
      double tt = ihit->time();
      if (DetId(ihit->id()).subdetId() == EcalBarrel)
        ok = (eTower > ebThr);
      else if (DetId(ihit->id()).subdetId() == EcalEndcap)
        ok = (eTower > eeThr);
      // No need for hcal sampling weight
      if (ok && tt > tMin && tt < tMax)
        energySum += eTower;
    }

    if (debug) {
      edm::LogVerbatim("IsoTrack") << "eCone_ecal: Energy " << energySum << " from " << hit.size() << " hits";
    }
    return energySum;
  }

  //
  template <typename T>
  double eCone_ecal(const CaloGeometry* geo,
                    edm::Handle<T>& barrelhits,
                    edm::Handle<T>& endcaphits,
                    const GlobalPoint& hpoint1,
                    const GlobalPoint& point1,
                    double dR,
                    const GlobalVector& trackMom,
                    std::vector<DetId>& coneRecHitDetIds,
                    std::vector<double>& eHit,
                    double ebThr,
                    double eeThr,
                    double tMin,
                    double tMax,
                    bool debug) {
    std::vector<typename T::const_iterator> hit =
        spr::findHitCone(geo, barrelhits, endcaphits, hpoint1, point1, dR, trackMom, debug);

    // No depth in Ecal
    double energySum = 0.0;
    for (auto const& ihit : hit) {
      bool ok = true;
      double eTower = ihit->energy();
      double tt = ihit->time();
      if (DetId(ihit->id()).subdetId() == EcalBarrel)
        ok = (eTower > ebThr);
      else if (DetId(ihit->id()).subdetId() == EcalEndcap)
        ok = (eTower > eeThr);
      // No need for hcal sampling weight
      if (tt > tMin && tt < tMax) {
        if (ok)
          energySum += eTower;
        // Get list of det ids
        coneRecHitDetIds.emplace_back(ihit->id());
        eHit.emplace_back(eTower);
      }
    }

    if (debug) {
      edm::LogVerbatim("IsoTrack") << "eCone_ecal: Energy " << energySum << " from " << hit.size() << " hits";
    }
    return energySum;
  }

}  // namespace spr