CMS 3D CMS Logo

ParametrizedSubtractor.cc
Go to the documentation of this file.
8 
10 
11 #include "TFile.h"
12 
13 #include <string>
14 #include <iostream>
15 using namespace std;
16 
18  for (std::map<int, double>::iterator iter = esigma_.begin(); iter != esigma_.end(); ++iter) {
19  iter->second = s * (iter->second);
20  }
21 }
22 
24  : PileUpSubtractor(iConfig, std::move(iC)),
25  dropZeroTowers_(iConfig.getUntrackedParameter<bool>("dropZeroTowers", true)),
26  cbins_(nullptr) {
27  centTag_ = iC.consumes<reco::Centrality>(
28  iConfig.getUntrackedParameter<edm::InputTag>("centTag", edm::InputTag("hiCentrality", "", "RECO")));
29 
30  interpolate_ = iConfig.getParameter<bool>("interpolate");
31  sumRecHits_ = iConfig.getParameter<bool>("sumRecHits");
32 
33  std::string ifname = "RecoHI/HiJetAlgos/data/PU_DATA.root";
34  TFile* inf = new TFile(edm::FileInPath(ifname).fullPath().data());
35  fPU = (TF1*)inf->Get("fPU");
36  fMean = (TF1*)inf->Get("fMean");
37  fRMS = (TF1*)inf->Get("fRMS");
38  hC = (TH1D*)inf->Get("hC");
39 
40  for (int i = 0; i < 40; ++i) {
41  hEta.push_back((TH1D*)inf->Get(Form("hEta_%d", i)));
42  hEtaMean.push_back((TH1D*)inf->Get(Form("hEtaMean_%d", i)));
43  hEtaRMS.push_back((TH1D*)inf->Get(Form("hEtaRMS_%d", i)));
44  }
45 }
46 
48  LogDebug("PileUpSubtractor") << "The subtractor setting up geometry...\n";
49 
50  // The function below that is commented out was deleted from
51  // DataFormats/HeavyIonEvent/src/Centrality.cc
52  // in June 2015. See comments associated with that commit.
53  // if(!cbins_) getCentralityBinsFromDB(iSetup);
54 
56  iEvent.getByToken(centTag_, cent);
57 
58  centrality_ = cent->EtHFhitSum();
59  bin_ = 40 - hC->FindBin(centrality_);
60  if (bin_ > 39)
61  bin_ = 39;
62  if (bin_ < 0)
63  bin_ = 0;
64 
66  for (int i = ietamin_; i < ietamax_ + 1; i++) {
67  emean_[i] = 0.;
68  esigma_[i] = 0.;
69  }
70 }
71 
72 void ParametrizedSubtractor::calculatePedestal(vector<fastjet::PseudoJet> const& coll) { return; }
73 
74 void ParametrizedSubtractor::subtractPedestal(vector<fastjet::PseudoJet>& coll) {
75  if (false) {
76  return;
77  } else {
78  LogDebug("PileUpSubtractor") << "The subtractor subtracting pedestals...\n";
79 
80  int it = -100;
81  vector<fastjet::PseudoJet> newcoll;
82 
83  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin(), fjInputsEnd = coll.end();
84  input_object != fjInputsEnd;
85  ++input_object) {
86  reco::CandidatePtr const& itow = (*inputs_)[input_object->user_index()];
87 
88  it = ieta(itow);
89  iphi(itow);
90 
91  double Original_Et = itow->et();
92  if (sumRecHits_) {
93  Original_Et = getEt(itow);
94  }
95 
96  double etnew = Original_Et - getPU(it, true, true);
97  float mScale = etnew / input_object->Et();
98  if (etnew < 0.)
99  mScale = 0.;
100 
101  math::XYZTLorentzVectorD towP4(input_object->px() * mScale,
102  input_object->py() * mScale,
103  input_object->pz() * mScale,
104  input_object->e() * mScale);
105 
106  int index = input_object->user_index();
107  input_object->reset(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
108  input_object->set_user_index(index);
109  if (etnew > 0. && dropZeroTowers_)
110  newcoll.push_back(*input_object);
111  }
112  if (dropZeroTowers_)
113  coll = newcoll;
114  }
115 }
116 
117 void ParametrizedSubtractor::calculateOrphanInput(vector<fastjet::PseudoJet>& orphanInput) { orphanInput = *fjInputs_; }
118 
120  LogDebug("PileUpSubtractor") << "The subtractor correcting jets...\n";
121  jetOffset_.clear();
122 
123  using namespace reco;
124 
125  (*fjInputs_) = fjOriginalInputs_;
128 
129  if (false) {
130  const fastjet::JetDefinition& def = fjClusterSeq_->jet_def();
131  if (!doAreaFastjet_ && !doRhoFastjet_) {
132  fastjet::ClusterSequence newseq(*fjInputs_, def);
133  (*fjClusterSeq_) = newseq;
134  } else {
135  fastjet::ClusterSequenceArea newseq(*fjInputs_, def, *fjActiveArea_);
136  (*fjClusterSeq_) = newseq;
137  }
138 
139  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
140  }
141 
142  jetOffset_.reserve(fjJets_->size());
143 
144  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), jetsEnd = fjJets_->end();
145  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
146  int ijet = pseudojetTMP - fjJets_->begin();
147  jetOffset_[ijet] = 0;
148 
149  std::vector<fastjet::PseudoJet> towers = sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
150 
151  double newjetet = 0.;
152  for (vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(), towEnd = towers.end(); ito != towEnd; ++ito) {
153  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
154  int it = ieta(originalTower);
155  double Original_Et = originalTower->et();
156 
157  if (sumRecHits_) {
158  Original_Et = getEt(originalTower);
159  }
160 
161  double etnew = Original_Et - getPU(it, true, true);
162  if (etnew < 0.)
163  etnew = 0;
164  newjetet = newjetet + etnew;
165  jetOffset_[ijet] += Original_Et - etnew;
166  }
167 
168  if (sumRecHits_) {
169  double mScale = newjetet / pseudojetTMP->Et();
170  int cshist = pseudojetTMP->cluster_hist_index();
171  pseudojetTMP->reset(pseudojetTMP->px() * mScale,
172  pseudojetTMP->py() * mScale,
173  pseudojetTMP->pz() * mScale,
174  pseudojetTMP->e() * mScale);
175  pseudojetTMP->set_cluster_hist_index(cshist);
176  }
177  }
178 }
179 
181  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
182  const GlobalPoint& pos = geo_->getPosition(ctc->id());
183  double energy = ctc->emEnergy() + ctc->hadEnergy();
184 
185  if (false) {
186  energy = 0;
187  const std::vector<DetId>& hitids = ctc->constituents();
188  for (unsigned int i = 0; i < hitids.size(); ++i) {
189  }
190  }
191 
192  double et = energy * sin(pos.theta());
193  return et;
194 }
195 
197  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
198  const GlobalPoint& pos = geo_->getPosition(ctc->id());
199  double eta = pos.eta();
200  return eta;
201 }
202 
204  int it = ieta(in);
205  return getPU(it, true, false);
206 }
207 
209  int it = ieta(in);
210  return getPU(it, false, true);
211 }
212 
214  int it = ieta(in);
215  return getPU(it, true, true);
216 }
217 
218 double ParametrizedSubtractor::getPU(int ieta, bool addMean, bool addSigma) const {
219  //double e = hEta[bin_]->GetBinContent(hEta[bin_]->FindBin(ieta));
220  //double c = fPU->Eval(centrality_);
221 
222  double em = hEtaMean[bin_]->GetBinContent(hEtaMean[bin_]->FindBin(ieta));
223  double cm = fMean->Eval(centrality_);
224 
225  double er = hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_]->FindBin(ieta));
226  double cr = fRMS->Eval(centrality_);
227 
228  if (interpolate_) {
229  double n = 0;
230  int hbin = 40 - bin_;
231  double centerweight = (centrality_ - hC->GetBinCenter(hbin));
232  double lowerweight = (centrality_ - hC->GetBinLowEdge(hbin));
233  double upperweight = (centrality_ - hC->GetBinLowEdge(hbin + 1));
234 
235  em *= lowerweight * upperweight;
236  er *= lowerweight * upperweight;
237  n += lowerweight * upperweight;
238 
239  if (bin_ > 0) {
240  em += upperweight * centerweight * hEtaMean[bin_]->GetBinContent(hEtaMean[bin_ - 1]->FindBin(ieta));
241  er += upperweight * centerweight * hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_ - 1]->FindBin(ieta));
242  n += upperweight * centerweight;
243  }
244 
245  if (bin_ < 39) {
246  em += lowerweight * centerweight * hEtaMean[bin_]->GetBinContent(hEtaMean[bin_ + 1]->FindBin(ieta));
247  er += lowerweight * centerweight * hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_ + 1]->FindBin(ieta));
248  n += lowerweight * centerweight;
249  }
250  em /= n;
251  er /= n;
252  }
253 
254  // return e*c;
255  return addMean * em * cm + addSigma * nSigmaPU_ * er * cr;
256 }
int def(FILE *, FILE *, int)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< double > jetOffset_
std::map< int, double > esigma_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:124
double getMeanAtTower(const reco::CandidatePtr &in) const override
std::vector< fastjet::PseudoJet > * fjJets_
std::vector< TH1D * > hEtaRMS
std::vector< fastjet::PseudoJet > fjOriginalInputs_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput) override
std::vector< TH1D * > hEtaMean
double getPileUpAtTower(const reco::CandidatePtr &in) const override
T getUntrackedParameter(std::string const &, T const &) const
std::vector< fastjet::PseudoJet > * fjInputs_
std::map< int, double > emean_
int iEvent
Definition: GenABIO.cc:224
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
std::vector< TH1D * > hEta
edm::EDGetTokenT< reco::Centrality > centTag_
string inf
Definition: EcalCondDB.py:96
double getEta(const reco::CandidatePtr &in) const
int iphi(const reco::CandidatePtr &in) const
double getPU(int ieta, bool addMean, bool addSigma) const
double EtHFhitSum() const
Definition: Centrality.h:21
ActiveAreaSpecPtr fjActiveArea_
double emEnergy() const
Definition: CaloTower.h:130
ClusterSequencePtr fjClusterSeq_
double getEt(const reco::CandidatePtr &in) const
double hadEnergy() const
Definition: CaloTower.h:131
double getSigmaAtTower(const reco::CandidatePtr &in) const override
void subtractPedestal(std::vector< fastjet::PseudoJet > &coll) override
int ieta(const reco::CandidatePtr &in) const
void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll) override
fixed size matrix
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
CaloGeometry const * geo_
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)
CaloTowerDetId id() const
Definition: CaloTower.h:123
def move(src, dest)
Definition: eostools.py:511
void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup) override
ParametrizedSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
#define LogDebug(id)