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 
65  if (!geo_) {
67  iSetup.get<CaloGeometryRecord>().get(pG);
68  geo_ = pG.product();
69  std::vector<DetId> alldid = geo_->getValidDetIds();
70 
71  int ietaold = -10000;
72  ietamax_ = -10000;
73  ietamin_ = 10000;
74  for (std::vector<DetId>::const_iterator did = alldid.begin(); did != alldid.end(); did++) {
75  if ((*did).det() == DetId::Hcal) {
76  HcalDetId hid = HcalDetId(*did);
77  if ((hid).depth() == 1) {
78  allgeomid_.push_back(*did);
79 
80  if ((hid).ieta() != ietaold) {
81  ietaold = (hid).ieta();
82  geomtowers_[(hid).ieta()] = 1;
83  if ((hid).ieta() > ietamax_)
84  ietamax_ = (hid).ieta();
85  if ((hid).ieta() < ietamin_)
86  ietamin_ = (hid).ieta();
87  } else {
88  geomtowers_[(hid).ieta()]++;
89  }
90  }
91  }
92  }
93  }
94 
95  for (int i = ietamin_; i < ietamax_ + 1; i++) {
96  emean_[i] = 0.;
97  esigma_[i] = 0.;
98  ntowersWithJets_[i] = 0;
99  }
100 }
101 
102 void ParametrizedSubtractor::calculatePedestal(vector<fastjet::PseudoJet> const& coll) { return; }
103 
104 void ParametrizedSubtractor::subtractPedestal(vector<fastjet::PseudoJet>& coll) {
105  if (false) {
106  return;
107  } else {
108  LogDebug("PileUpSubtractor") << "The subtractor subtracting pedestals...\n";
109 
110  int it = -100;
111  vector<fastjet::PseudoJet> newcoll;
112 
113  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin(), fjInputsEnd = coll.end();
114  input_object != fjInputsEnd;
115  ++input_object) {
116  reco::CandidatePtr const& itow = (*inputs_)[input_object->user_index()];
117 
118  it = ieta(itow);
119  iphi(itow);
120 
121  double Original_Et = itow->et();
122  if (sumRecHits_) {
123  Original_Et = getEt(itow);
124  }
125 
126  double etnew = Original_Et - getPU(it, true, true);
127  float mScale = etnew / input_object->Et();
128  if (etnew < 0.)
129  mScale = 0.;
130 
131  math::XYZTLorentzVectorD towP4(input_object->px() * mScale,
132  input_object->py() * mScale,
133  input_object->pz() * mScale,
134  input_object->e() * mScale);
135 
136  int index = input_object->user_index();
137  input_object->reset(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
138  input_object->set_user_index(index);
139  if (etnew > 0. && dropZeroTowers_)
140  newcoll.push_back(*input_object);
141  }
142  if (dropZeroTowers_)
143  coll = newcoll;
144  }
145 }
146 
147 void ParametrizedSubtractor::calculateOrphanInput(vector<fastjet::PseudoJet>& orphanInput) { orphanInput = *fjInputs_; }
148 
150  LogDebug("PileUpSubtractor") << "The subtractor correcting jets...\n";
151  jetOffset_.clear();
152 
153  using namespace reco;
154 
155  (*fjInputs_) = fjOriginalInputs_;
158 
159  if (false) {
160  const fastjet::JetDefinition& def = fjClusterSeq_->jet_def();
161  if (!doAreaFastjet_ && !doRhoFastjet_) {
162  fastjet::ClusterSequence newseq(*fjInputs_, def);
163  (*fjClusterSeq_) = newseq;
164  } else {
165  fastjet::ClusterSequenceArea newseq(*fjInputs_, def, *fjActiveArea_);
166  (*fjClusterSeq_) = newseq;
167  }
168 
169  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
170  }
171 
172  jetOffset_.reserve(fjJets_->size());
173 
174  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), jetsEnd = fjJets_->end();
175  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
176  int ijet = pseudojetTMP - fjJets_->begin();
177  jetOffset_[ijet] = 0;
178 
179  std::vector<fastjet::PseudoJet> towers = sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
180 
181  double newjetet = 0.;
182  for (vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(), towEnd = towers.end(); ito != towEnd; ++ito) {
183  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
184  int it = ieta(originalTower);
185  double Original_Et = originalTower->et();
186 
187  if (sumRecHits_) {
188  Original_Et = getEt(originalTower);
189  }
190 
191  double etnew = Original_Et - getPU(it, true, true);
192  if (etnew < 0.)
193  etnew = 0;
194  newjetet = newjetet + etnew;
195  jetOffset_[ijet] += Original_Et - etnew;
196  }
197 
198  if (sumRecHits_) {
199  double mScale = newjetet / pseudojetTMP->Et();
200  int cshist = pseudojetTMP->cluster_hist_index();
201  pseudojetTMP->reset(pseudojetTMP->px() * mScale,
202  pseudojetTMP->py() * mScale,
203  pseudojetTMP->pz() * mScale,
204  pseudojetTMP->e() * mScale);
205  pseudojetTMP->set_cluster_hist_index(cshist);
206  }
207  }
208 }
209 
211  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
212  const GlobalPoint& pos = geo_->getPosition(ctc->id());
213  double energy = ctc->emEnergy() + ctc->hadEnergy();
214 
215  if (false) {
216  energy = 0;
217  const std::vector<DetId>& hitids = ctc->constituents();
218  for (unsigned int i = 0; i < hitids.size(); ++i) {
219  }
220  }
221 
222  double et = energy * sin(pos.theta());
223  return et;
224 }
225 
227  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
228  const GlobalPoint& pos = geo_->getPosition(ctc->id());
229  double eta = pos.eta();
230  return eta;
231 }
232 
234  int it = ieta(in);
235  return getPU(it, true, false);
236 }
237 
239  int it = ieta(in);
240  return getPU(it, false, true);
241 }
242 
244  int it = ieta(in);
245  return getPU(it, true, true);
246 }
247 
248 double ParametrizedSubtractor::getPU(int ieta, bool addMean, bool addSigma) const {
249  //double e = hEta[bin_]->GetBinContent(hEta[bin_]->FindBin(ieta));
250  //double c = fPU->Eval(centrality_);
251 
252  double em = hEtaMean[bin_]->GetBinContent(hEtaMean[bin_]->FindBin(ieta));
253  double cm = fMean->Eval(centrality_);
254 
255  double er = hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_]->FindBin(ieta));
256  double cr = fRMS->Eval(centrality_);
257 
258  if (interpolate_) {
259  double n = 0;
260  int hbin = 40 - bin_;
261  double centerweight = (centrality_ - hC->GetBinCenter(hbin));
262  double lowerweight = (centrality_ - hC->GetBinLowEdge(hbin));
263  double upperweight = (centrality_ - hC->GetBinLowEdge(hbin + 1));
264 
265  em *= lowerweight * upperweight;
266  er *= lowerweight * upperweight;
267  n += lowerweight * upperweight;
268 
269  if (bin_ > 0) {
270  em += upperweight * centerweight * hEtaMean[bin_]->GetBinContent(hEtaMean[bin_ - 1]->FindBin(ieta));
271  er += upperweight * centerweight * hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_ - 1]->FindBin(ieta));
272  n += upperweight * centerweight;
273  }
274 
275  if (bin_ < 39) {
276  em += lowerweight * centerweight * hEtaMean[bin_]->GetBinContent(hEtaMean[bin_ + 1]->FindBin(ieta));
277  er += lowerweight * centerweight * hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_ + 1]->FindBin(ieta));
278  n += lowerweight * centerweight;
279  }
280  em /= n;
281  er /= n;
282  }
283 
284  // return e*c;
285  return addMean * em * cm + addSigma * nSigmaPU_ * er * cr;
286 }
ParametrizedSubtractor::hEta
std::vector< TH1D * > hEta
Definition: ParametrizedSubtractor.h:39
CaloTower::emEnergy
double emEnergy() const
Definition: CaloTower.h:134
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
PileUpSubtractor::ieta
int ieta(const reco::CandidatePtr &in) const
Definition: PileUpSubtractor.cc:327
PileUpSubtractor::iphi
int iphi(const reco::CandidatePtr &in) const
Definition: PileUpSubtractor.cc:338
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
ParametrizedSubtractor::getSigmaAtTower
double getSigmaAtTower(const reco::CandidatePtr &in) const override
Definition: ParametrizedSubtractor.cc:238
ESHandle.h
CaloGeometry::getPosition
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
reco::Centrality::EtHFhitSum
double EtHFhitSum() const
Definition: Centrality.h:21
math::XYZTLorentzVectorD
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
pos
Definition: PixelAliasList.h:18
DetId::Hcal
Definition: DetId.h:28
ParametrizedSubtractor::getPU
double getPU(int ieta, bool addMean, bool addSigma) const
Definition: ParametrizedSubtractor.cc:248
ParametrizedSubtractor::getEt
double getEt(const reco::CandidatePtr &in) const
Definition: ParametrizedSubtractor.cc:210
CaloTower::id
CaloTowerDetId id() const
Definition: CaloTower.h:127
PileUpSubtractor::doRhoFastjet_
bool doRhoFastjet_
Definition: PileUpSubtractor.h:65
ParametrizedSubtractor::interpolate_
bool interpolate_
Definition: ParametrizedSubtractor.h:33
ParametrizedSubtractor::fMean
TF1 * fMean
Definition: ParametrizedSubtractor.h:44
ParametrizedSubtractor::subtractPedestal
void subtractPedestal(std::vector< fastjet::PseudoJet > &coll) override
Definition: ParametrizedSubtractor.cc:104
PileUpSubtractor::allgeomid_
std::vector< HcalDetId > allgeomid_
Definition: PileUpSubtractor.h:79
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
tools.TF1
TF1
Definition: tools.py:23
edm::Handle< reco::Centrality >
FileInPath.h
ParametrizedSubtractor::setupGeometryMap
void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: ParametrizedSubtractor.cc:47
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
CandidateFwd.h
ParametrizedSubtractor::calculatePedestal
void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll) override
Definition: ParametrizedSubtractor.cc:102
PileUpSubtractor::fjActiveArea_
ActiveAreaSpecPtr fjActiveArea_
Definition: PileUpSubtractor.h:75
edm::FileInPath
Definition: FileInPath.h:64
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
PVValHelper::eta
Definition: PVValidationHelpers.h:69
PileUpSubtractor::doAreaFastjet_
bool doAreaFastjet_
Definition: PileUpSubtractor.h:64
CaloTower::hadEnergy
double hadEnergy() const
Definition: CaloTower.h:135
edm::ESHandle< CaloGeometry >
CaloTower::constituents
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:128
ParametrizedSubtractor::ParametrizedSubtractor
ParametrizedSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
Definition: ParametrizedSubtractor.cc:23
ParametrizedSubtractor::rescaleRMS
void rescaleRMS(double s)
Definition: ParametrizedSubtractor.cc:17
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
ParametrizedSubtractor::dropZeroTowers_
bool dropZeroTowers_
Definition: ParametrizedSubtractor.h:34
Point3DBase< float, GlobalTag >
PileUpSubtractor::geo_
CaloGeometry const * geo_
Definition: PileUpSubtractor.h:76
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
ParametrizedSubtractor::bin_
int bin_
Definition: ParametrizedSubtractor.h:35
CaloGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PileUpSubtractor::jetOffset_
std::vector< double > jetOffset_
Definition: PileUpSubtractor.h:85
funct::true
true
Definition: Factorize.h:173
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
PileUpSubtractor::fjOriginalInputs_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
Definition: PileUpSubtractor.h:60
edm::ParameterSet
Definition: ParameterSet.h:36
ParametrizedSubtractor::fRMS
TF1 * fRMS
Definition: ParametrizedSubtractor.h:45
ParametrizedSubtractor.h
ParametrizedSubtractor::calculateOrphanInput
void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput) override
Definition: ParametrizedSubtractor.cc:147
PileUpSubtractor
Definition: PileUpSubtractor.h:23
PileUpSubtractor::fjJets_
std::vector< fastjet::PseudoJet > * fjJets_
Definition: PileUpSubtractor.h:59
recoMuon::in
Definition: RecoMuonEnumerators.h:6
HcalDetId
Definition: HcalDetId.h:12
PileUpSubtractor::geomtowers_
std::map< int, int > geomtowers_
Definition: PileUpSubtractor.h:80
iEvent
int iEvent
Definition: GenABIO.cc:224
ParametrizedSubtractor::hEtaRMS
std::vector< TH1D * > hEtaRMS
Definition: ParametrizedSubtractor.h:41
CaloTower
Definition: CaloTower.h:26
PileUpSubtractor::esigma_
std::map< int, double > esigma_
Definition: PileUpSubtractor.h:82
reco::Centrality
Definition: Centrality.h:11
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
ParametrizedSubtractor::getMeanAtTower
double getMeanAtTower(const reco::CandidatePtr &in) const override
Definition: ParametrizedSubtractor.cc:233
edm::Ptr< Candidate >
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
PileUpSubtractor::fjInputs_
std::vector< fastjet::PseudoJet > * fjInputs_
Definition: PileUpSubtractor.h:58
HLT_2018_cff.towers
towers
Definition: HLT_2018_cff.py:35030
ParametrizedSubtractor::fPU
TF1 * fPU
Definition: ParametrizedSubtractor.h:43
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PileUpSubtractor::ietamin_
int ietamin_
Definition: PileUpSubtractor.h:78
CaloGeometry::getValidDetIds
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
dqmiodatasetharvest.inf
inf
Definition: dqmiodatasetharvest.py:38
PileUpSubtractor::ietamax_
int ietamax_
Definition: PileUpSubtractor.h:77
PileUpSubtractor::nSigmaPU_
double nSigmaPU_
Definition: PileUpSubtractor.h:73
CaloGeometry.h
PileUpSubtractor::jetPtMin_
double jetPtMin_
Definition: PileUpSubtractor.h:66
ParametrizedSubtractor::hC
TH1D * hC
Definition: ParametrizedSubtractor.h:46
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ParametrizedSubtractor::centTag_
edm::EDGetTokenT< reco::Centrality > centTag_
Definition: ParametrizedSubtractor.h:38
ParametrizedSubtractor::offsetCorrectJets
void offsetCorrectJets() override
Definition: ParametrizedSubtractor.cc:149
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
spu::def
int def(FILE *, FILE *, int)
Definition: SherpackUtilities.cc:14
Candidate.h
PileUpSubtractor::ntowersWithJets_
std::map< int, int > ntowersWithJets_
Definition: PileUpSubtractor.h:81
edm::Event
Definition: Event.h:73
ParametrizedSubtractor::hEtaMean
std::vector< TH1D * > hEtaMean
Definition: ParametrizedSubtractor.h:40
edm::InputTag
Definition: InputTag.h:15
PileUpSubtractor::emean_
std::map< int, double > emean_
Definition: PileUpSubtractor.h:83
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
ParametrizedSubtractor::sumRecHits_
bool sumRecHits_
Definition: ParametrizedSubtractor.h:32
ParametrizedSubtractor::getEta
double getEta(const reco::CandidatePtr &in) const
Definition: ParametrizedSubtractor.cc:226
PileUpSubtractor::fjClusterSeq_
ClusterSequencePtr fjClusterSeq_
Definition: PileUpSubtractor.h:56
ParametrizedSubtractor::getPileUpAtTower
double getPileUpAtTower(const reco::CandidatePtr &in) const override
Definition: ParametrizedSubtractor.cc:243
ParametrizedSubtractor::centrality_
double centrality_
Definition: ParametrizedSubtractor.h:36