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

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
#include "Calibration/Tools/interface/calibXMLwriter.h"
#include "Calibration/Tools/interface/CalibrationCluster.h"
#include "Calibration/Tools/interface/HouseholderDecomposition.h"
#include "Calibration/Tools/interface/MinL3Algorithm.h"
#include "Calibration/EcalCalibAlgos/interface/ZeeKinematicTools.h"
#include "Calibration/Tools/interface/ZIterativeAlgorithmWithFit.h"
#include "DataFormats/EgammaCandidates/interface/Electron.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TF1.h"
#include "TRandom.h"

#include <iostream>
#include <string>
#include <stdexcept>
#include <vector>

#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"

ZeeKinematicTools::ZeeKinematicTools() {}

ZeeKinematicTools::~ZeeKinematicTools() {}

//--------------------------------------------

float ZeeKinematicTools::cosThetaElectrons_SC(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate,
                                              float ele1EnergyCorrection,
                                              float ele2EnergyCorrection) {
  float theta1 = 2. * atan(exp(-aZCandidate.first->getRecoElectron()->superCluster()->eta()));
  float phi1 = aZCandidate.first->getRecoElectron()->superCluster()->phi();

  float x1 = aZCandidate.first->getRecoElectron()->superCluster()->energy() * sin(theta1) * cos(phi1);
  float y1 = aZCandidate.first->getRecoElectron()->superCluster()->energy() * sin(theta1) * sin(phi1);
  float z1 = aZCandidate.first->getRecoElectron()->superCluster()->energy() * cos(theta1);
  float mod1 = sqrt(x1 * x1 + y1 * y1 + z1 * z1);

  float theta2 = 2. * atan(exp(-aZCandidate.second->getRecoElectron()->superCluster()->eta()));
  float phi2 = aZCandidate.second->getRecoElectron()->superCluster()->phi();

  float x2 = aZCandidate.second->getRecoElectron()->superCluster()->energy() * sin(theta2) * cos(phi2);
  float y2 = aZCandidate.second->getRecoElectron()->superCluster()->energy() * sin(theta2) * sin(phi2);
  float z2 = aZCandidate.second->getRecoElectron()->superCluster()->energy() * cos(theta2);
  float mod2 = sqrt(x2 * x2 + y2 * y2 + z2 * z2);

  return (x1 * x2 + y1 * y2 + z1 * z2) / (mod1 * mod2);
}

//--------------------------------------------

float ZeeKinematicTools::cosThetaElectrons_TK(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate,
                                              float ele1EnergyCorrection,
                                              float ele2EnergyCorrection) {
  float theta1 = 2. * atan(exp(-aZCandidate.first->getRecoElectron()->eta()));
  float phi1 = aZCandidate.first->getRecoElectron()->phi();

  float x1 = aZCandidate.first->getRecoElectron()->superCluster()->energy() * sin(theta1) * cos(phi1);
  float y1 = aZCandidate.first->getRecoElectron()->superCluster()->energy() * sin(theta1) * sin(phi1);
  float z1 = aZCandidate.first->getRecoElectron()->superCluster()->energy() * cos(theta1);
  float mod1 = sqrt(x1 * x1 + y1 * y1 + z1 * z1);

  float theta2 = 2. * atan(exp(-aZCandidate.second->getRecoElectron()->eta()));
  float phi2 = aZCandidate.second->getRecoElectron()->phi();

  float x2 = aZCandidate.second->getRecoElectron()->superCluster()->energy() * sin(theta2) * cos(phi2);
  float y2 = aZCandidate.second->getRecoElectron()->superCluster()->energy() * sin(theta2) * sin(phi2);
  float z2 = aZCandidate.second->getRecoElectron()->superCluster()->energy() * cos(theta2);
  float mod2 = sqrt(x2 * x2 + y2 * y2 + z2 * z2);

  return (x1 * x2 + y1 * y2 + z1 * z2) / (mod1 * mod2);
}

//--------------------------------------------

float ZeeKinematicTools::calculateZMassWithCorrectedElectrons_noTK(
    const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate,
    float ele1EnergyCorrection,
    float ele2EnergyCorrection) {
  return ZIterativeAlgorithmWithFit::invMassCalc(
      aZCandidate.first->getRecoElectron()->superCluster()->energy() / ele1EnergyCorrection,
      aZCandidate.first->getRecoElectron()->superCluster()->eta(),
      aZCandidate.first->getRecoElectron()->superCluster()->phi(),
      aZCandidate.second->getRecoElectron()->superCluster()->energy() / ele2EnergyCorrection,
      aZCandidate.second->getRecoElectron()->superCluster()->eta(),
      aZCandidate.second->getRecoElectron()->superCluster()->phi());
}

//--------------------------------------------

float ZeeKinematicTools::calculateZMassWithCorrectedElectrons_withTK(
    const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate,
    float ele1EnergyCorrection,
    float ele2EnergyCorrection) {
  return ZIterativeAlgorithmWithFit::invMassCalc(
      aZCandidate.first->getRecoElectron()->superCluster()->energy() / ele1EnergyCorrection,
      aZCandidate.first->getRecoElectron()->eta(),
      aZCandidate.first->getRecoElectron()->phi(),
      aZCandidate.second->getRecoElectron()->superCluster()->energy() / ele2EnergyCorrection,
      aZCandidate.second->getRecoElectron()->eta(),
      aZCandidate.second->getRecoElectron()->phi());
}

//--------------------------------------------

float ZeeKinematicTools::calculateZMass_noTK(
    const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  return ZIterativeAlgorithmWithFit::invMassCalc(aZCandidate.first->getRecoElectron()->superCluster()->energy(),
                                                 aZCandidate.first->getRecoElectron()->superCluster()->eta(),
                                                 aZCandidate.first->getRecoElectron()->superCluster()->phi(),
                                                 aZCandidate.second->getRecoElectron()->superCluster()->energy(),
                                                 aZCandidate.second->getRecoElectron()->superCluster()->eta(),
                                                 aZCandidate.second->getRecoElectron()->superCluster()->phi());
}

//--------------------------------------------

float ZeeKinematicTools::calculateZMass_withTK(
    const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  return ZIterativeAlgorithmWithFit::invMassCalc(aZCandidate.first->getRecoElectron()->superCluster()->energy(),
                                                 aZCandidate.first->getRecoElectron()->eta(),
                                                 aZCandidate.first->getRecoElectron()->phi(),
                                                 aZCandidate.second->getRecoElectron()->superCluster()->energy(),
                                                 aZCandidate.second->getRecoElectron()->eta(),
                                                 aZCandidate.second->getRecoElectron()->phi());
}

//--------------------------------------------

float ZeeKinematicTools::calculateZRapidity(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  TLorentzVector ele1LV(aZCandidate.first->getRecoElectron()->px(),
                        aZCandidate.first->getRecoElectron()->py(),
                        aZCandidate.first->getRecoElectron()->pz(),
                        aZCandidate.first->getRecoElectron()->superCluster()->energy());

  TLorentzVector ele2LV(aZCandidate.second->getRecoElectron()->px(),
                        aZCandidate.second->getRecoElectron()->py(),
                        aZCandidate.second->getRecoElectron()->pz(),
                        aZCandidate.second->getRecoElectron()->superCluster()->energy());

  return (ele1LV + ele2LV).Rapidity();
}

//--------------------------------------------

float ZeeKinematicTools::calculateZEta(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  TLorentzVector ele1LV(aZCandidate.first->getRecoElectron()->px(),
                        aZCandidate.first->getRecoElectron()->py(),
                        aZCandidate.first->getRecoElectron()->pz(),
                        aZCandidate.first->getRecoElectron()->superCluster()->energy());

  TLorentzVector ele2LV(aZCandidate.second->getRecoElectron()->px(),
                        aZCandidate.second->getRecoElectron()->py(),
                        aZCandidate.second->getRecoElectron()->pz(),
                        aZCandidate.second->getRecoElectron()->superCluster()->energy());

  return (ele1LV + ele2LV).Eta();
}

//--------------------------------------------

float ZeeKinematicTools::calculateZTheta(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  TLorentzVector ele1LV(aZCandidate.first->getRecoElectron()->px(),
                        aZCandidate.first->getRecoElectron()->py(),
                        aZCandidate.first->getRecoElectron()->pz(),
                        aZCandidate.first->getRecoElectron()->superCluster()->energy());

  TLorentzVector ele2LV(aZCandidate.second->getRecoElectron()->px(),
                        aZCandidate.second->getRecoElectron()->py(),
                        aZCandidate.second->getRecoElectron()->pz(),
                        aZCandidate.second->getRecoElectron()->superCluster()->energy());

  return (ele1LV + ele2LV).Theta();
}

//--------------------------------------------

float ZeeKinematicTools::calculateZPhi(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  TLorentzVector ele1LV(aZCandidate.first->getRecoElectron()->px(),
                        aZCandidate.first->getRecoElectron()->py(),
                        aZCandidate.first->getRecoElectron()->pz(),
                        aZCandidate.first->getRecoElectron()->superCluster()->energy());

  TLorentzVector ele2LV(aZCandidate.second->getRecoElectron()->px(),
                        aZCandidate.second->getRecoElectron()->py(),
                        aZCandidate.second->getRecoElectron()->pz(),
                        aZCandidate.second->getRecoElectron()->superCluster()->energy());

  return (ele1LV + ele2LV).Phi();
}

//--------------------------------------------

float ZeeKinematicTools::calculateZPt(const std::pair<calib::CalibElectron*, calib::CalibElectron*>& aZCandidate) {
  TLorentzVector ele1LV(aZCandidate.first->getRecoElectron()->px(),
                        aZCandidate.first->getRecoElectron()->py(),
                        aZCandidate.first->getRecoElectron()->pz(),
                        aZCandidate.first->getRecoElectron()->superCluster()->energy());

  TLorentzVector ele2LV(aZCandidate.second->getRecoElectron()->px(),
                        aZCandidate.second->getRecoElectron()->py(),
                        aZCandidate.second->getRecoElectron()->pz(),
                        aZCandidate.second->getRecoElectron()->superCluster()->energy());

  return (ele1LV + ele2LV).Pt();
}