hcalCalib

Macros

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
////////////////////////////////////////////////////////////////
// This class skeleton has been automatically generated on
// from TTree hcalCalibTree/Tree for IsoTrack Calibration
// with ROOT version 5.17/02
//
//  TSelector-based code for getting the HCAL resp. correction
//  from physics events. Works for DiJet and IsoTrack calibration.
//
//  Anton Anastassov (Northwestern)
//  Email: aa@fnal.gov
//
//
///////////////////////////////////////////////////////////////

#ifndef hcalCalib_h
#define hcalCalib_h

#include <vector>
#include <map>

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>

#include <TLorentzVector.h>
#include <TClonesArray.h>
#include <TRefArray.h>

#include <TH2.h>
#include <TStyle.h>
#include <TFile.h>
#include <TMatrixF.h>
#include <TMatrixD.h>
#include <TDecompSVD.h>
#include <TDecompQRH.h>

// needed to get cell coordinates
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"

class hcalCalib : public TSelector {
public:
  TTree *fChain;  //!pointer to the analyzed TTree or TChain

  UInt_t eventNumber;
  UInt_t runNumber;
  Int_t iEtaHit;
  UInt_t iPhiHit;
  TClonesArray *cells;
  Float_t emEnergy;
  Float_t targetE;
  Float_t etVetoJet;

  Float_t xTrkHcal;
  Float_t yTrkHcal;
  Float_t zTrkHcal;
  Float_t xTrkEcal;
  Float_t yTrkEcal;
  Float_t zTrkEcal;

  TLorentzVector *tagJetP4;
  TLorentzVector *probeJetP4;

  Float_t tagJetEmFrac;
  Float_t probeJetEmFrac;

  // List of branches
  TBranch *b_eventNumber;  //!
  TBranch *b_runNumber;    //!
  TBranch *b_iEtaHit;      //!
  TBranch *b_iPhiHit;      //!
  TBranch *b_cells;        //!
  TBranch *b_emEnergy;     //!
  TBranch *b_targetE;      //!
  TBranch *b_etVetoJet;    //!

  TBranch *b_xTrkHcal;
  TBranch *b_yTrkHcal;
  TBranch *b_zTrkHcal;
  TBranch *b_xTrkEcal;
  TBranch *b_yTrkEcal;
  TBranch *b_zTrkEcal;

  TBranch *b_tagJetEmFrac;    //!
  TBranch *b_probeJetEmFrac;  //!

  TBranch *b_tagJetP4;    //!
  TBranch *b_probeJetP4;  //!

  UInt_t nEvents;

  TFile *histoFile;

  // sanity check histograms
  TH1F *h1_trkP;
  TH1F *h1_allTrkP;

  TH1F *h1_selTrkP_iEta10;

  TH1F *h1_rawSumE;
  TH1F *h1_rawResp;
  TH1F *h1_corResp;
  TH1F *h1_rawRespBarrel;
  TH1F *h1_corRespBarrel;
  TH1F *h1_rawRespEndcap;
  TH1F *h1_corRespEndcap;
  TH1F *h1_numEventsTwrIEta;

  TH2F *h2_dHitRefBarrel;
  TH2F *h2_dHitRefEndcap;

  // histograms based on iEta, iPhi of refPosition forthe cluster (at the moment: hottest tower)
  // expect range |iEta|<=24 (to do: add flexibility for arbitrary range)
  TH1F *h1_corRespIEta[48];

  hcalCalib(TTree * /*tree*/ = nullptr) {}
  ~hcalCalib() override {}
  Int_t Version() const override { return 2; }
  void Begin(TTree *tree) override;
  //   virtual void    SlaveBegin(TTree *tree);
  void Init(TTree *tree) override;
  Bool_t Notify() override;
  Bool_t Process(Long64_t entry) override;
  Int_t GetEntry(Long64_t entry, Int_t getall = 0) override {
    return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0;
  }
  void SetOption(const char *option) override { fOption = option; }
  void SetObject(TObject *obj) override { fObject = obj; }
  void SetInputList(TList *input) override { fInput = input; }
  TList *GetOutputList() const override { return fOutput; }
  //   virtual void    SlaveTerminate();
  void Terminate() override;

  //------------ CUTS ---------------
  Float_t MIN_TARGET_E;
  Float_t MAX_TARGET_E;

  Float_t MIN_CELL_E;
  Float_t MIN_EOVERP;
  Float_t MAX_EOVERP;
  Float_t MAX_TRK_EME;

  Float_t MAX_ET_THIRD_JET;
  Float_t MIN_DPHI_DIJETS;

  Bool_t SUM_DEPTHS;
  Bool_t SUM_SMALL_DEPTHS;
  Bool_t COMBINE_PHI;

  Int_t HB_CLUSTER_SIZE;
  Int_t HE_CLUSTER_SIZE;

  Bool_t USE_CONE_CLUSTERING;
  Float_t MAX_CONE_DIST;

  Int_t CALIB_ABS_IETA_MAX;
  Int_t CALIB_ABS_IETA_MIN;

  Float_t MAX_PROBEJET_EMFRAC;
  Float_t MAX_TAGJET_EMFRAC;
  Float_t MAX_TAGJET_ABSETA;
  Float_t MIN_TAGJET_ET;

  Float_t MIN_PROBEJET_ABSETA;

  TString CALIB_TYPE;    // "ISO_TRACK" or "DI_JET"
  TString CALIB_METHOD;  // L3, matrix inversion, everage then matrix inversion,...

  TString PHI_SYM_COR_FILENAME;
  Bool_t APPLY_PHI_SYM_COR_FLAG;

  TString OUTPUT_COR_COEF_FILENAME;
  TString HISTO_FILENAME;

  const CaloGeometry *theCaloGeometry;
  const HcalTopology *topo_;

  void SetMinTargetE(Float_t e) { MIN_TARGET_E = e; }
  void SetMaxTargetE(Float_t e) { MAX_TARGET_E = e; }
  void SetSumDepthsFlag(Bool_t b) { SUM_DEPTHS = b; }
  void SetSumSmallDepthsFlag(Bool_t b) { SUM_SMALL_DEPTHS = b; }
  void SetCombinePhiFlag(Bool_t b) { COMBINE_PHI = b; }
  void SetMinCellE(Float_t e) { MIN_CELL_E = e; }
  void SetMinEOverP(Float_t e) { MIN_EOVERP = e; }
  void SetMaxEOverP(Float_t e) { MAX_EOVERP = e; }
  void SetMaxTrkEmE(Float_t e) { MAX_TRK_EME = e; }
  void SetCalibType(const TString &s) { CALIB_TYPE = s; }
  void SetCalibMethod(const TString &s) { CALIB_METHOD = s; }
  void SetHbClusterSize(Int_t i) { HB_CLUSTER_SIZE = i; }
  void SetHeClusterSize(Int_t i) { HE_CLUSTER_SIZE = i; }

  void SetUseConeClustering(Bool_t b) { USE_CONE_CLUSTERING = b; }
  void SetConeMaxDist(Float_t d) { MAX_CONE_DIST = d; }

  void SetCalibAbsIEtaMax(Int_t i) { CALIB_ABS_IETA_MAX = i; }
  void SetCalibAbsIEtaMin(Int_t i) { CALIB_ABS_IETA_MIN = i; }
  void SetMaxEtThirdJet(Float_t et) { MAX_ET_THIRD_JET = et; }
  void SetMinDPhiDiJets(Float_t dphi) { MIN_DPHI_DIJETS = dphi; }
  void SetApplyPhiSymCorFlag(Bool_t b) { APPLY_PHI_SYM_COR_FLAG = b; }
  void SetPhiSymCorFileName(const TString &filename) { PHI_SYM_COR_FILENAME = filename; }
  void SetMaxProbeJetEmFrac(Float_t f) { MAX_PROBEJET_EMFRAC = f; }
  void SetMaxTagJetEmFrac(Float_t f) { MAX_TAGJET_EMFRAC = f; }
  void SetMaxTagJetAbsEta(Float_t e) { MAX_TAGJET_ABSETA = e; }
  void SetMinTagJetEt(Float_t e) { MIN_TAGJET_ET = e; }
  void SetMinProbeJetAbsEta(Float_t e) { MIN_PROBEJET_ABSETA = e; }
  void SetOutputCorCoefFileName(const TString &filename) { OUTPUT_COR_COEF_FILENAME = filename; }
  void SetHistoFileName(const TString &filename) { HISTO_FILENAME = filename; }

  void SetCaloGeometry(const CaloGeometry *g, const HcalTopology *topo) {
    theCaloGeometry = g;
    topo_ = topo;
  }

  void GetCoefFromMtrxInvOfAve();

  Bool_t ReadPhiSymCor();

  void makeTextFile();

  // --------- containers passed to minimizers ----------------
  std::vector<std::vector<Float_t> > cellEnergies;
  std::vector<std::vector<UInt_t> > cellIds;
  std::vector<std::pair<Int_t, UInt_t> > refIEtaIPhi;  // centroid of jet or hottest tower iEta, iPhi
  std::vector<Float_t> targetEnergies;

  std::map<UInt_t, Float_t> phiSymCor;  // holds the phi symmetry corrections read from the file

  std::map<UInt_t, Float_t> solution;  // correction coef: solution from L3, holds final coef for hybrid methods as well
  std::map<Int_t, Float_t>
      iEtaCoefMap;  // correction coef: from matrix inversion AFTER averaging, also intermediate results for hybrid methods

  //   ClassDef(hcalCalib,0);
};

#endif