ZeeCalibration

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 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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
#ifndef CALIBRATION_ECALCALIBALGOS_ZEECALIBRATION
#define CALIBRATION_ECALCALIBALGOS_ZEECALIBRATION

// -*- C++ -*-
//
// Package:    ZeeCalibration
// Class:      ZeeCalibration
//
/**\class ZeeCalibration ZeeCalibration.cc Calibration/EcalCalibAlgos/src/ZeeCalibration.cc

 Description: Perform single electron calibration (tested on TB data only).

 Implementation:
     <Notes on implementation>
*/
//
//
//

// system include files
#include <memory>
#include <vector>
#include <map>
#include <string>

// user include files
#include "FWCore/Framework/interface/LooperFactory.h"
#include "FWCore/Framework/interface/ESProducerLooper.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "Calibration/Tools/interface/ZIterativeAlgorithmWithFit.h"
#include "Calibration/Tools/interface/CalibElectron.h"

#include "Calibration/EcalCalibAlgos/interface/ZeePlots.h"
#include "Calibration/EcalCalibAlgos/interface/ZeeRescaleFactorPlots.h"

#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"

#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/DetId/interface/DetId.h"

#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"

#include "TTree.h"
#include "TFile.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TH1.h"
#include "TH2.h"

#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
#include "DataFormats/EgammaCandidates/interface/Electron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"

// class declaration
//

class ZeeCalibration : public edm::ESProducerLooper {
public:
  /// Constructor
  ZeeCalibration(const edm::ParameterSet& iConfig);

  /// Destructor
  ~ZeeCalibration() override;

  /// Dummy implementation (job done in duringLoop)
  virtual void produce(edm::Event&, const edm::EventSetup&) {}

  /// Called at beginning of job
  void beginOfJob() override;

  /// Called at end of job
  void endOfJob() override;

  /// Called at beginning of loop
  void startingNewLoop(unsigned int iLoop) override;

  /// Called at end of loop
  Status endOfLoop(const edm::EventSetup&, unsigned int iLoop) override;

  /// Called at each event
  Status duringLoop(const edm::Event&, const edm::EventSetup&) override;

  /// Produce Ecal interCalibrations
  virtual std::shared_ptr<EcalIntercalibConstants> produceEcalIntercalibConstants(
      const EcalIntercalibConstantsRcd& iRecord);

private:
  /*   ElectronEnergyCorrector myCorrector; */
  /*   ElectronClassification myClassificator; */

  double fEtaBarrelBad(double scEta) const;
  double fEtaBarrelGood(double scEta) const;
  double fEtaEndcapBad(double scEta) const;
  double fEtaEndcapGood(double scEta) const;

  int ringNumberCorrector(int k);
  double getEtaCorrection(const reco::GsfElectron*);

  void fillEleInfo(std::vector<HepMC::GenParticle*>& a, std::map<HepMC::GenParticle*, const reco::GsfElectron*>& b);
  void fillMCInfo(HepMC::GenParticle* mcele);

  void fillMCmap(const std::vector<const reco::GsfElectron*>* electronCollection,
                 const std::vector<HepMC::GenParticle*>& mcEle,
                 std::map<HepMC::GenParticle*, const reco::GsfElectron*>& myMCmap);
  //  void fillMCmap(const reco::ElectronCollection* electronCollection, const std::vector<HepMC::GenParticle*>& mcEle,std::map<HepMC::GenParticle*,const reco::Electron*>& myMCmap);

  float EvalDPhi(float Phi, float Phi_ref);
  float EvalDR(float Eta, float Eta_ref, float Phi, float Phi_ref);

  void bookHistograms();

  void resetVariables();

  void resetHistograms();

  void printStatistics();

  std::pair<DetId, double> getHottestDetId(const std::vector<std::pair<DetId, float> >& mySCRecHits,
                                           const EBRecHitCollection* ebhits,
                                           const EERecHitCollection* eehits);

  bool xtalIsOnModuleBorder(EBDetId myEBDetId);

  float computeCoefficientDistanceAtIteration(float v1[250], float v2[250], int size);

  //  float Calculate_SigmaEtaEta(const reco::SuperCluster &passedCluster);

  // ----------member data ---------------------------

  TTree* myTree;

  std::string outputFileName_;

  const edm::InputTag hlTriggerResults_;

  const std::string mcProducer_;
  const std::string rechitProducer_;
  const std::string rechitCollection_;
  const std::string erechitProducer_;
  const std::string erechitCollection_;
  const std::string scProducer_;
  const std::string scCollection_;

  const std::string scIslandProducer_;
  const std::string scIslandCollection_;

  const std::string electronProducer_;
  const std::string electronCollection_;

  std::string calibMode_;

  const edm::EDGetTokenT<edm::TriggerResults> trigResultsToken_;
  const edm::EDGetTokenT<edm::HepMCProduct> hepMCToken_;
  const edm::EDGetTokenT<EBRecHitCollection> ebRecHitToken_;
  const edm::EDGetTokenT<EERecHitCollection> eeRecHitToken_;
  const edm::EDGetTokenT<reco::SuperClusterCollection> scToken_;
  const edm::EDGetTokenT<reco::SuperClusterCollection> islandSCToken_;
  const edm::EDGetTokenT<reco::GsfElectronCollection> gsfElectronToken_;

  const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;

  unsigned int etaBins_;
  unsigned int etBins_;

  double etaMin_;
  double etMin_;
  double etaMax_;
  double etMax_;

  std::string barrelfile_;
  std::string endcapfile_;

  double minInvMassCut_;
  double maxInvMassCut_;
  double mass;

  float mass4tree;
  float massDiff4tree;

  int read_events;

  int loopFlag_;

  float calibCoeff[nMaxChannels];
  float NewCalibCoeff[nMaxChannels];
  float calibCoeffError[nMaxChannels];
  float initCalibCoeff[nMaxChannels];

  std::shared_ptr<EcalIntercalibConstants> ical;

  ZIterativeAlgorithmWithFit* theAlgorithm_;

  ZeePlots* myZeePlots_;
  ZeeRescaleFactorPlots* myZeeRescaleFactorPlots_;

  // steering parameters

  edm::ParameterSet theParameterSet;

  //  TGraph* graph;

  TH1F* h1_eventsBeforeEWKSelection_;
  TH1F* h1_eventsAfterEWKSelection_;

  TH1F* h1_eventsBeforeBorderSelection_;
  TH1F* h1_eventsAfterBorderSelection_;

  TH2F* h2_fEtaBarrelGood_;
  TH2F* h2_fEtaBarrelBad_;
  TH2F* h2_fEtaEndcapGood_;
  TH2F* h2_fEtaEndcapBad_;
  TH1F* h1_nEleReco_;
  TH1F* h1_eleClasses_;

  TH1F* h_eleEffEta[2];
  TH1F* h_eleEffPhi[2];
  TH1F* h_eleEffPt[2];

  TH1F* h1_seedOverSC_;
  TH1F* h1_preshowerOverSC_;

  TH1F* h1_zMassResol_;
  TH1F* h1_zEtaResol_;
  TH1F* h1_zPhiResol_;
  TH1F* h1_reco_ZMass_;

  TH1F* h1_reco_ZMassCorr_;
  TH1F* h1_reco_ZMassCorrBB_;
  TH1F* h1_reco_ZMassCorrEE_;
  TH1F* h1_reco_ZMassGood_;
  TH1F* h1_reco_ZMassBad_;
  TH1F* h1_ZCandMult_;
  TH1F* h1_RMin_;
  TH1F* h1_RMinZ_;
  TH1F* h1_eleERecoOverEtrue_;

  TH1F* h1_eleEtaResol_;
  TH1F* h1_elePhiResol_;

  TH1F* h_eleEffEta_[2];
  TH1F* h_eleEffPhi_[2];
  TH1F* h_eleEffPt_[2];
  TH1F* h_ESCEtrue_[25];
  TH2F* h_ESCEtrueVsEta_[25];

  TH1F* h_ESCcorrEtrue_[25];
  TH2F* h_ESCcorrEtrueVsEta_[25];

  TH2F* h2_coeffVsEta_;
  TH2F* h2_coeffVsEtaGrouped_;
  TH2F* h2_zMassVsLoop_;
  TH2F* h2_zMassDiffVsLoop_;
  TH2F* h2_zWidthVsLoop_;
  TH2F* h2_coeffVsLoop_;

  TH2F* h2_miscalRecal_;
  //  TH2F* h2_miscalRecalParz_[25];
  TH1F* h1_mc_;
  TH1F* h1_mcParz_[25];
  /*
  TH1F* h_DiffZMassDistr_[25];  
  TH1F* h_ZMassDistr_[25];  
  */
  TH2F* h2_residualSigma_;
  TH2F* h2_miscalRecalEB_;
  //TH2F* h2_miscalRecalEBParz_[25];
  TH1F* h1_mcEB_;
  TH1F* h1_mcEBParz_[25];
  TH2F* h2_miscalRecalEE_;
  //TH2F* h2_miscalRecalEEParz_[25];
  TH1F* h1_mcEE_;
  TH1F* h1_mcEEParz_[25];

  TH2F* h2_chi2_[25];
  TH2F* h2_iterations_[25];

  TH2F* h2_xtalRecalibCoeffBarrel_[25];
  TH2F* h2_xtalRecalibCoeffEndcapMinus_[25];
  TH2F* h2_xtalRecalibCoeffEndcapPlus_[25];

  TH2F* h2_xtalMiscalibCoeffBarrel_;
  TH2F* h2_xtalMiscalibCoeffEndcapMinus_;
  TH2F* h2_xtalMiscalibCoeffEndcapPlus_;

  TH1F* h1_weightSumMeanBarrel_;
  TH1F* h1_weightSumMeanEndcap_;

  TH1F* h1_occupancyVsEta_;
  TH1F* h1_occupancyVsEtaGold_;
  TH1F* h1_occupancyVsEtaSilver_;
  TH1F* h1_occupancyVsEtaCrack_;
  TH1F* h1_occupancyVsEtaShower_;
  TH1F* h1_occupancy_;
  TH1F* h1_occupancyBarrel_;
  TH1F* h1_occupancyEndcap_;

  TH1F* h1_electronCosTheta_TK_;
  TH1F* h1_electronCosTheta_SC_;
  TH1F* h1_electronCosTheta_SC_TK_;

  TH1F* h1_borderElectronClassification_;

  Int_t BBZN, EBZN, EEZN, BBZN_gg, EBZN_gg, EEZN_gg, BBZN_tt, EBZN_tt, EEZN_tt, BBZN_t0, EBZN_t0, EEZN_t0;
  Int_t NEVT, MCZBB, MCZEB, MCZEE;

  TFile* outputFile_;

  unsigned int theMaxLoops;  // Number of loops to loop

  bool wantEtaCorrection_;

  unsigned int electronSelection_;

  double loopArray[50];
  double sigmaArray[50];
  double sigmaErrorArray[50];
  double coefficientDistanceAtIteration[50];

  int BARREL_ELECTRONS_BEFORE_BORDER_CUT;
  int BARREL_ELECTRONS_AFTER_BORDER_CUT;

  int TOTAL_ELECTRONS_IN_BARREL;
  int TOTAL_ELECTRONS_IN_ENDCAP;

  int GOLDEN_ELECTRONS_IN_BARREL;
  int GOLDEN_ELECTRONS_IN_ENDCAP;

  int SILVER_ELECTRONS_IN_BARREL;
  int SILVER_ELECTRONS_IN_ENDCAP;

  int SHOWER_ELECTRONS_IN_BARREL;
  int SHOWER_ELECTRONS_IN_ENDCAP;

  int CRACK_ELECTRONS_IN_BARREL;
  int CRACK_ELECTRONS_IN_ENDCAP;

  unsigned int nEvents_;  // number of events processed

  unsigned int nWasRun_;  // # where at least one HLT was run
  unsigned int nAccept_;  // # of accepted events
  unsigned int nErrors_;  // # where at least one HLT had error

  std::vector<unsigned int> hlWasRun_;  // # where HLT[i] was run
  std::vector<unsigned int> hlAccept_;  // # of events accepted by HLT[i]
  std::vector<unsigned int> hlErrors_;  // # of events with error in HLT[i]

  std::vector<std::string> hlNames_;  // name of each HLT algorithm
  bool init_;                         // vectors initialised or not

  Int_t triggerCount;
  char aTriggerNames[200][30];
  bool aTriggerResults[200];

  Int_t hltCount;
  char aHLTNames[6000];
  Int_t hltNamesLen;
  TString aNames[200];
  bool aHLTResults[200];

  bool isfirstcall_;
};
#endif