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();
19  iter != esigma_.end(); ++iter ){
20  iter->second = s*(iter->second);
21  }
22 }
23 
24 
26  PileUpSubtractor(iConfig, std::move(iC)),
27  dropZeroTowers_(iConfig.getUntrackedParameter<bool>("dropZeroTowers",true)),
28  cbins_(nullptr)
29 {
30 
31  centTag_ = iC.consumes<reco::Centrality>(iConfig.getUntrackedParameter<edm::InputTag>("centTag",edm::InputTag("hiCentrality","","RECO")));
32 
33  interpolate_ = iConfig.getParameter<bool>("interpolate");
34  sumRecHits_ = iConfig.getParameter<bool>("sumRecHits");
35 
36  std::string ifname = "RecoHI/HiJetAlgos/data/PU_DATA.root";
37  TFile* inf = new TFile(edm::FileInPath(ifname).fullPath().data());
38  fPU = (TF1*)inf->Get("fPU");
39  fMean = (TF1*)inf->Get("fMean");
40  fRMS = (TF1*)inf->Get("fRMS");
41  hC = (TH1D*)inf->Get("hC");
42 
43  for(int i = 0; i < 40; ++i){
44  hEta.push_back((TH1D*)inf->Get(Form("hEta_%d",i)));
45  hEtaMean.push_back((TH1D*)inf->Get(Form("hEtaMean_%d",i)));
46  hEtaRMS.push_back((TH1D*)inf->Get(Form("hEtaRMS_%d",i)));
47  }
48 
49 }
50 
51 
53  LogDebug("PileUpSubtractor")<<"The subtractor setting up geometry...\n";
54 
55  // The function below that is commented out was deleted from
56  // DataFormats/HeavyIonEvent/src/Centrality.cc
57  // in June 2015. See comments associated with that commit.
58  // if(!cbins_) getCentralityBinsFromDB(iSetup);
59 
61  iEvent.getByToken(centTag_,cent);
62 
63  centrality_ = cent->EtHFhitSum();
64  bin_ = 40-hC->FindBin(centrality_);
65  if(bin_ > 39) bin_ = 39;
66  if(bin_ < 0) bin_ = 0;
67 
68  if(!geo_) {
70  iSetup.get<CaloGeometryRecord>().get(pG);
71  geo_ = pG.product();
72  std::vector<DetId> alldid = geo_->getValidDetIds();
73 
74  int ietaold = -10000;
75  ietamax_ = -10000;
76  ietamin_ = 10000;
77  for(std::vector<DetId>::const_iterator did=alldid.begin(); did != alldid.end(); did++){
78  if( (*did).det() == DetId::Hcal ){
79  HcalDetId hid = HcalDetId(*did);
80  if( (hid).depth() == 1 ) {
81  allgeomid_.push_back(*did);
82 
83  if((hid).ieta() != ietaold){
84  ietaold = (hid).ieta();
85  geomtowers_[(hid).ieta()] = 1;
86  if((hid).ieta() > ietamax_) ietamax_ = (hid).ieta();
87  if((hid).ieta() < ietamin_) ietamin_ = (hid).ieta();
88  }
89  else{
90  geomtowers_[(hid).ieta()]++;
91  }
92  }
93  }
94  }
95  }
96 
97  for (int i = ietamin_; i<ietamax_+1; i++) {
98  emean_[i] = 0.;
99  esigma_[i] = 0.;
100  ntowersWithJets_[i] = 0;
101  }
102 }
103 
104 
105 void ParametrizedSubtractor::calculatePedestal( vector<fastjet::PseudoJet> const & coll ){
106  return;
107 }
108 
109 void ParametrizedSubtractor::subtractPedestal(vector<fastjet::PseudoJet> & coll)
110 {
111  if(false){
112  return;
113  }else{
114  LogDebug("PileUpSubtractor")<<"The subtractor subtracting pedestals...\n";
115 
116  int it = -100;
117  vector<fastjet::PseudoJet> newcoll;
118 
119  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin (),
120  fjInputsEnd = coll.end();
121  input_object != fjInputsEnd; ++input_object) {
122 
123  reco::CandidatePtr const & itow = (*inputs_)[ input_object->user_index() ];
124 
125  it = ieta( itow );
126  iphi( itow );
127 
128  double Original_Et = itow->et();
129  if(sumRecHits_){
130  Original_Et = getEt(itow);
131  }
132 
133  double etnew = Original_Et - getPU(it,true,true);
134  float mScale = etnew/input_object->Et();
135  if(etnew < 0.) mScale = 0.;
136 
137  math::XYZTLorentzVectorD towP4(input_object->px()*mScale, input_object->py()*mScale,
138  input_object->pz()*mScale, input_object->e()*mScale);
139 
140  int index = input_object->user_index();
141  input_object->reset ( towP4.px(),
142  towP4.py(),
143  towP4.pz(),
144  towP4.energy() );
145  input_object->set_user_index(index);
146  if(etnew > 0. && dropZeroTowers_) newcoll.push_back(*input_object);
147  }
148  if(dropZeroTowers_) coll = newcoll;
149 
150  }
151 }
152 
153 
154 void ParametrizedSubtractor::calculateOrphanInput(vector<fastjet::PseudoJet> & orphanInput)
155 {
156  orphanInput = *fjInputs_;
157 }
158 
159 
160 
162 {
163 
164  LogDebug("PileUpSubtractor")<<"The subtractor correcting jets...\n";
165  jetOffset_.clear();
166 
167  using namespace reco;
168 
169  (*fjInputs_) = fjOriginalInputs_;
172 
173  if(false){
174  const fastjet::JetDefinition& def = fjClusterSeq_->jet_def();
175  if ( !doAreaFastjet_ && !doRhoFastjet_) {
176  fastjet::ClusterSequence newseq( *fjInputs_, def );
177  (*fjClusterSeq_) = newseq;
178  } else {
179  fastjet::ClusterSequenceArea newseq( *fjInputs_, def , *fjActiveArea_ );
180  (*fjClusterSeq_) = newseq;
181  }
182 
183  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
184  }
185 
186  jetOffset_.reserve(fjJets_->size());
187 
188  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
189  jetsEnd = fjJets_->end();
190  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
191 
192  int ijet = pseudojetTMP - fjJets_->begin();
193  jetOffset_[ijet] = 0;
194 
195  std::vector<fastjet::PseudoJet> towers =
196  sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
197 
198  double newjetet = 0.;
199  for(vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(),
200  towEnd = towers.end();
201  ito != towEnd;
202  ++ito)
203  {
204  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
205  int it = ieta( originalTower );
206  double Original_Et = originalTower->et();
207 
208  if(sumRecHits_){
209  Original_Et = getEt(originalTower);
210  }
211 
212  double etnew = Original_Et - getPU(it,true,true);
213  if(etnew < 0.) etnew = 0;
214  newjetet = newjetet + etnew;
215  jetOffset_[ijet] += Original_Et - etnew;
216  }
217 
218  if(sumRecHits_){
219  double mScale = newjetet/pseudojetTMP->Et();
220  int cshist = pseudojetTMP->cluster_hist_index();
221  pseudojetTMP->reset(pseudojetTMP->px()*mScale, pseudojetTMP->py()*mScale,
222  pseudojetTMP->pz()*mScale, pseudojetTMP->e()*mScale);
223  pseudojetTMP->set_cluster_hist_index(cshist);
224  }
225 
226  }
227 }
228 
229 
231  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
232  const GlobalPoint& pos=geo_->getPosition(ctc->id());
233  double energy = ctc->emEnergy() + ctc->hadEnergy();
234 
235  if(false){
236  energy = 0;
237  const std::vector<DetId>& hitids = ctc->constituents();
238  for(unsigned int i = 0; i< hitids.size(); ++i){
239 
240  }
241  }
242 
243  double et = energy*sin(pos.theta());
244  return et;
245 }
246 
248  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
249  const GlobalPoint& pos=geo_->getPosition(ctc->id());
250  double eta = pos.eta();
251  return eta;
252 }
253 
255  int it = ieta(in);
256  return getPU(it,true,false);
257 }
258 
260  int it = ieta(in);
261  return getPU(it,false,true);
262 }
263 
265  int it = ieta(in);
266  return getPU(it,true,true);
267 }
268 
269 double ParametrizedSubtractor::getPU(int ieta,bool addMean, bool addSigma) const {
270 
271  //double e = hEta[bin_]->GetBinContent(hEta[bin_]->FindBin(ieta));
272  //double c = fPU->Eval(centrality_);
273 
274  double em = hEtaMean[bin_]->GetBinContent(hEtaMean[bin_]->FindBin(ieta));
275  double cm = fMean->Eval(centrality_);
276 
277  double er = hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_]->FindBin(ieta));
278  double cr = fRMS->Eval(centrality_);
279 
280  if(interpolate_){
281  double n = 0;
282  int hbin = 40-bin_;
283  double centerweight = (centrality_ - hC->GetBinCenter(hbin));
284  double lowerweight = (centrality_ - hC->GetBinLowEdge(hbin));
285  double upperweight = (centrality_ - hC->GetBinLowEdge(hbin+1));
286 
287  em *= lowerweight*upperweight;
288  er *= lowerweight*upperweight;
289  n += lowerweight*upperweight;
290 
291  if(bin_ > 0){
292  em += upperweight*centerweight*hEtaMean[bin_]->GetBinContent(hEtaMean[bin_-1]->FindBin(ieta));
293  er += upperweight*centerweight*hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_-1]->FindBin(ieta));
294  n += upperweight*centerweight;
295  }
296 
297  if(bin_ < 39){
298  em += lowerweight*centerweight*hEtaMean[bin_]->GetBinContent(hEtaMean[bin_+1]->FindBin(ieta));
299  er += lowerweight*centerweight*hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_+1]->FindBin(ieta));
300  n += lowerweight*centerweight;
301  }
302  em /= n;
303  er /= n;
304  }
305 
306  // return e*c;
307  return addMean*em*cm + addSigma*nSigmaPU_*er*cr;
308 }
309 
310 
#define LogDebug(id)
double getEt(const reco::CandidatePtr &in) const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > jetOffset_
double getEta(const reco::CandidatePtr &in) const
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
std::vector< fastjet::PseudoJet > * fjJets_
std::map< int, double > esigma_
std::vector< TH1D * > hEtaRMS
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
std::map< int, int > geomtowers_
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
#define nullptr
int ieta(const reco::CandidatePtr &in) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
std::vector< fastjet::PseudoJet > * fjInputs_
std::map< int, int > ntowersWithJets_
double getPileUpAtTower(const reco::CandidatePtr &in) const override
int iEvent
Definition: GenABIO.cc:230
double emEnergy() const
Definition: CaloTower.h:110
double getSigmaAtTower(const reco::CandidatePtr &in) const override
std::vector< TH1D * > hEta
edm::EDGetTokenT< reco::Centrality > centTag_
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:104
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:70
double getPU(int ieta, bool addMean, bool addSigma) const
double hadEnergy() const
Definition: CaloTower.h:111
int iphi(const reco::CandidatePtr &in) const
CaloTowerDetId id() const
Definition: CaloTower.h:103
JetCorrectorParametersCollection coll
Definition: classes.h:10
int inf(FILE *, FILE *)
ActiveAreaSpecPtr fjActiveArea_
ClusterSequencePtr fjClusterSeq_
const T & get() const
Definition: EventSetup.h:55
et
define resolution functions of each parameter
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:92
T eta() const
Definition: PV3DBase.h:76
double EtHFhitSum() const
Definition: Centrality.h:20
void subtractPedestal(std::vector< fastjet::PseudoJet > &coll) override
void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll) override
fixed size matrix
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double getMeanAtTower(const reco::CandidatePtr &in) const override
CaloGeometry const * geo_
std::map< int, double > emean_
JetCorrectorParameters::Definitions def
Definition: classes.h:6
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
std::vector< HcalDetId > allgeomid_
void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup) override
ParametrizedSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)