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  allgeomid_.push_back(*did);
78 
79  if (hid.ieta() != ietaold) {
80  ietaold = hid.ieta();
81  geomtowers_[hid.ieta()] = 1;
82  if (hid.ieta() > ietamax_)
83  ietamax_ = hid.ieta();
84  if (hid.ieta() < ietamin_)
85  ietamin_ = hid.ieta();
86  } else {
87  geomtowers_[hid.ieta()]++;
88  }
89  }
90  }
91  }
92 
93  for (int i = ietamin_; i < ietamax_ + 1; i++) {
94  emean_[i] = 0.;
95  esigma_[i] = 0.;
96  ntowersWithJets_[i] = 0;
97  }
98 }
99 
100 void ParametrizedSubtractor::calculatePedestal(vector<fastjet::PseudoJet> const& coll) { return; }
101 
102 void ParametrizedSubtractor::subtractPedestal(vector<fastjet::PseudoJet>& coll) {
103  if (false) {
104  return;
105  } else {
106  LogDebug("PileUpSubtractor") << "The subtractor subtracting pedestals...\n";
107 
108  int it = -100;
109  vector<fastjet::PseudoJet> newcoll;
110 
111  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin(), fjInputsEnd = coll.end();
112  input_object != fjInputsEnd;
113  ++input_object) {
114  reco::CandidatePtr const& itow = (*inputs_)[input_object->user_index()];
115 
116  it = ieta(itow);
117  iphi(itow);
118 
119  double Original_Et = itow->et();
120  if (sumRecHits_) {
121  Original_Et = getEt(itow);
122  }
123 
124  double etnew = Original_Et - getPU(it, true, true);
125  float mScale = etnew / input_object->Et();
126  if (etnew < 0.)
127  mScale = 0.;
128 
129  math::XYZTLorentzVectorD towP4(input_object->px() * mScale,
130  input_object->py() * mScale,
131  input_object->pz() * mScale,
132  input_object->e() * mScale);
133 
134  int index = input_object->user_index();
135  input_object->reset(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
136  input_object->set_user_index(index);
137  if (etnew > 0. && dropZeroTowers_)
138  newcoll.push_back(*input_object);
139  }
140  if (dropZeroTowers_)
141  coll = newcoll;
142  }
143 }
144 
145 void ParametrizedSubtractor::calculateOrphanInput(vector<fastjet::PseudoJet>& orphanInput) { orphanInput = *fjInputs_; }
146 
148  LogDebug("PileUpSubtractor") << "The subtractor correcting jets...\n";
149  jetOffset_.clear();
150 
151  using namespace reco;
152 
153  (*fjInputs_) = fjOriginalInputs_;
156 
157  if (false) {
158  const fastjet::JetDefinition& def = fjClusterSeq_->jet_def();
159  if (!doAreaFastjet_ && !doRhoFastjet_) {
160  fastjet::ClusterSequence newseq(*fjInputs_, def);
161  (*fjClusterSeq_) = newseq;
162  } else {
163  fastjet::ClusterSequenceArea newseq(*fjInputs_, def, *fjActiveArea_);
164  (*fjClusterSeq_) = newseq;
165  }
166 
167  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
168  }
169 
170  jetOffset_.reserve(fjJets_->size());
171 
172  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), jetsEnd = fjJets_->end();
173  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
174  int ijet = pseudojetTMP - fjJets_->begin();
175  jetOffset_[ijet] = 0;
176 
177  std::vector<fastjet::PseudoJet> towers = sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
178 
179  double newjetet = 0.;
180  for (vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(), towEnd = towers.end(); ito != towEnd; ++ito) {
181  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
182  int it = ieta(originalTower);
183  double Original_Et = originalTower->et();
184 
185  if (sumRecHits_) {
186  Original_Et = getEt(originalTower);
187  }
188 
189  double etnew = Original_Et - getPU(it, true, true);
190  if (etnew < 0.)
191  etnew = 0;
192  newjetet = newjetet + etnew;
193  jetOffset_[ijet] += Original_Et - etnew;
194  }
195 
196  if (sumRecHits_) {
197  double mScale = newjetet / pseudojetTMP->Et();
198  int cshist = pseudojetTMP->cluster_hist_index();
199  pseudojetTMP->reset(pseudojetTMP->px() * mScale,
200  pseudojetTMP->py() * mScale,
201  pseudojetTMP->pz() * mScale,
202  pseudojetTMP->e() * mScale);
203  pseudojetTMP->set_cluster_hist_index(cshist);
204  }
205  }
206 }
207 
209  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
210  const GlobalPoint& pos = geo_->getPosition(ctc->id());
211  double energy = ctc->emEnergy() + ctc->hadEnergy();
212 
213  if (false) {
214  energy = 0;
215  const std::vector<DetId>& hitids = ctc->constituents();
216  for (unsigned int i = 0; i < hitids.size(); ++i) {
217  }
218  }
219 
220  double et = energy * sin(pos.theta());
221  return et;
222 }
223 
225  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
226  const GlobalPoint& pos = geo_->getPosition(ctc->id());
227  double eta = pos.eta();
228  return eta;
229 }
230 
232  int it = ieta(in);
233  return getPU(it, true, false);
234 }
235 
237  int it = ieta(in);
238  return getPU(it, false, true);
239 }
240 
242  int it = ieta(in);
243  return getPU(it, true, true);
244 }
245 
246 double ParametrizedSubtractor::getPU(int ieta, bool addMean, bool addSigma) const {
247  //double e = hEta[bin_]->GetBinContent(hEta[bin_]->FindBin(ieta));
248  //double c = fPU->Eval(centrality_);
249 
250  double em = hEtaMean[bin_]->GetBinContent(hEtaMean[bin_]->FindBin(ieta));
251  double cm = fMean->Eval(centrality_);
252 
253  double er = hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_]->FindBin(ieta));
254  double cr = fRMS->Eval(centrality_);
255 
256  if (interpolate_) {
257  double n = 0;
258  int hbin = 40 - bin_;
259  double centerweight = (centrality_ - hC->GetBinCenter(hbin));
260  double lowerweight = (centrality_ - hC->GetBinLowEdge(hbin));
261  double upperweight = (centrality_ - hC->GetBinLowEdge(hbin + 1));
262 
263  em *= lowerweight * upperweight;
264  er *= lowerweight * upperweight;
265  n += lowerweight * upperweight;
266 
267  if (bin_ > 0) {
268  em += upperweight * centerweight * hEtaMean[bin_]->GetBinContent(hEtaMean[bin_ - 1]->FindBin(ieta));
269  er += upperweight * centerweight * hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_ - 1]->FindBin(ieta));
270  n += upperweight * centerweight;
271  }
272 
273  if (bin_ < 39) {
274  em += lowerweight * centerweight * hEtaMean[bin_]->GetBinContent(hEtaMean[bin_ + 1]->FindBin(ieta));
275  er += lowerweight * centerweight * hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_ + 1]->FindBin(ieta));
276  n += lowerweight * centerweight;
277  }
278  em /= n;
279  er /= n;
280  }
281 
282  // return e*c;
283  return addMean * em * cm + addSigma * nSigmaPU_ * er * cr;
284 }
ParametrizedSubtractor::hEta
std::vector< TH1D * > hEta
Definition: ParametrizedSubtractor.h:39
CaloTower::emEnergy
double emEnergy() const
Definition: CaloTower.h:130
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
HLT_FULL_cff.towers
towers
Definition: HLT_FULL_cff.py:36362
PileUpSubtractor::ieta
int ieta(const reco::CandidatePtr &in) const
Definition: PileUpSubtractor.cc:325
PileUpSubtractor::iphi
int iphi(const reco::CandidatePtr &in) const
Definition: PileUpSubtractor.cc:336
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
ParametrizedSubtractor::getSigmaAtTower
double getSigmaAtTower(const reco::CandidatePtr &in) const override
Definition: ParametrizedSubtractor.cc:236
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:246
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
ParametrizedSubtractor::getEt
double getEt(const reco::CandidatePtr &in) const
Definition: ParametrizedSubtractor.cc:208
CaloTower::id
CaloTowerDetId id() const
Definition: CaloTower.h:123
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:102
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
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:100
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:87
PVValHelper::eta
Definition: PVValidationHelpers.h:70
PileUpSubtractor::doAreaFastjet_
bool doAreaFastjet_
Definition: PileUpSubtractor.h:64
CaloTower::hadEnergy
double hadEnergy() const
Definition: CaloTower.h:131
edm::ESHandle< CaloGeometry >
CaloTower::constituents
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:124
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
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
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
PileUpSubtractor::fjOriginalInputs_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
Definition: PileUpSubtractor.h:60
edm::ParameterSet
Definition: ParameterSet.h:47
ParametrizedSubtractor::fRMS
TF1 * fRMS
Definition: ParametrizedSubtractor.h:45
ParametrizedSubtractor.h
ParametrizedSubtractor::calculateOrphanInput
void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput) override
Definition: ParametrizedSubtractor.cc:145
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:58
get
#define get
ParametrizedSubtractor::getMeanAtTower
double getMeanAtTower(const reco::CandidatePtr &in) const override
Definition: ParametrizedSubtractor.cc:231
edm::Ptr< Candidate >
PileUpSubtractor::fjInputs_
std::vector< fastjet::PseudoJet > * fjInputs_
Definition: PileUpSubtractor.h:58
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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:147
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:45
ParametrizedSubtractor::sumRecHits_
bool sumRecHits_
Definition: ParametrizedSubtractor.h:32
ParametrizedSubtractor::getEta
double getEta(const reco::CandidatePtr &in) const
Definition: ParametrizedSubtractor.cc:224
PileUpSubtractor::fjClusterSeq_
ClusterSequencePtr fjClusterSeq_
Definition: PileUpSubtractor.h:56
ParametrizedSubtractor::getPileUpAtTower
double getPileUpAtTower(const reco::CandidatePtr &in) const override
Definition: ParametrizedSubtractor.cc:241
ParametrizedSubtractor::centrality_
double centrality_
Definition: ParametrizedSubtractor.h:36