CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParametrizedSubtractor.cc
Go to the documentation of this file.
8 
10 #include <string>
11 #include <iostream>
12 using namespace std;
13 
15  for ( std::map<int, double>::iterator iter = esigma_.begin();
16  iter != esigma_.end(); ++iter ){
17  iter->second = s*(iter->second);
18  }
19 }
20 
21 
23  PileUpSubtractor(iConfig, std::move(iC)),
24  dropZeroTowers_(iConfig.getUntrackedParameter<bool>("dropZeroTowers",true)),
25  cbins_(0)
26 {
27 
28  centTag_ = iC.consumes<reco::Centrality>(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 }
47 
48 
50  LogDebug("PileUpSubtractor")<<"The subtractor setting up geometry...\n";
51 
52  // if(!cbins_) getCentralityBinsFromDB(iSetup);
53 
55  iEvent.getByToken(centTag_,cent);
56 
57  centrality_ = cent->EtHFhitSum();
58  bin_ = 40-hC->FindBin(centrality_);
59  if(bin_ > 39) bin_ = 39;
60  if(bin_ < 0) bin_ = 0;
61 
62  if(!geo_) {
64  iSetup.get<CaloGeometryRecord>().get(pG);
65  geo_ = pG.product();
66  std::vector<DetId> alldid = geo_->getValidDetIds();
67 
68  int ietaold = -10000;
69  ietamax_ = -10000;
70  ietamin_ = 10000;
71  for(std::vector<DetId>::const_iterator did=alldid.begin(); did != alldid.end(); did++){
72  if( (*did).det() == DetId::Hcal ){
73  HcalDetId hid = HcalDetId(*did);
74  if( (hid).depth() == 1 ) {
75  allgeomid_.push_back(*did);
76 
77  if((hid).ieta() != ietaold){
78  ietaold = (hid).ieta();
79  geomtowers_[(hid).ieta()] = 1;
80  if((hid).ieta() > ietamax_) ietamax_ = (hid).ieta();
81  if((hid).ieta() < ietamin_) ietamin_ = (hid).ieta();
82  }
83  else{
84  geomtowers_[(hid).ieta()]++;
85  }
86  }
87  }
88  }
89  }
90 
91  for (int i = ietamin_; i<ietamax_+1; i++) {
92  emean_[i] = 0.;
93  esigma_[i] = 0.;
94  ntowersWithJets_[i] = 0;
95  }
96 }
97 
98 
99 void ParametrizedSubtractor::calculatePedestal( vector<fastjet::PseudoJet> const & coll ){
100  return;
101 }
102 
103 void ParametrizedSubtractor::subtractPedestal(vector<fastjet::PseudoJet> & coll)
104 {
105  if(0){
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 (),
114  fjInputsEnd = coll.end();
115  input_object != fjInputsEnd; ++input_object) {
116 
117  reco::CandidatePtr const & itow = (*inputs_)[ input_object->user_index() ];
118 
119  it = ieta( itow );
120  iphi( itow );
121 
122  double Original_Et = itow->et();
123  if(sumRecHits_){
124  Original_Et = getEt(itow);
125  }
126 
127  double etnew = Original_Et - getPU(it,1,1);
128  float mScale = etnew/input_object->Et();
129  if(etnew < 0.) mScale = 0.;
130 
131  math::XYZTLorentzVectorD towP4(input_object->px()*mScale, input_object->py()*mScale,
132  input_object->pz()*mScale, input_object->e()*mScale);
133 
134  int index = input_object->user_index();
135  input_object->reset ( towP4.px(),
136  towP4.py(),
137  towP4.pz(),
138  towP4.energy() );
139  input_object->set_user_index(index);
140  if(etnew > 0. && dropZeroTowers_) newcoll.push_back(*input_object);
141  }
142  if(dropZeroTowers_) coll = newcoll;
143 
144  }
145 }
146 
147 
148 void ParametrizedSubtractor::calculateOrphanInput(vector<fastjet::PseudoJet> & orphanInput)
149 {
150  orphanInput = *fjInputs_;
151 }
152 
153 
154 
156 {
157 
158  LogDebug("PileUpSubtractor")<<"The subtractor correcting jets...\n";
159  jetOffset_.clear();
160 
161  using namespace reco;
162 
163  (*fjInputs_) = fjOriginalInputs_;
166 
167  if(0){
168  const fastjet::JetDefinition& def = fjClusterSeq_->jet_def();
169  if ( !doAreaFastjet_ && !doRhoFastjet_) {
170  fastjet::ClusterSequence newseq( *fjInputs_, def );
171  (*fjClusterSeq_) = newseq;
172  } else {
173  fastjet::ClusterSequenceArea newseq( *fjInputs_, def , *fjActiveArea_ );
174  (*fjClusterSeq_) = newseq;
175  }
176 
177  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
178  }
179 
180  jetOffset_.reserve(fjJets_->size());
181 
182  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
183  jetsEnd = fjJets_->end();
184  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
185 
186  int ijet = pseudojetTMP - fjJets_->begin();
187  jetOffset_[ijet] = 0;
188 
189  std::vector<fastjet::PseudoJet> towers =
190  sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
191 
192  double newjetet = 0.;
193  for(vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(),
194  towEnd = towers.end();
195  ito != towEnd;
196  ++ito)
197  {
198  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
199  int it = ieta( originalTower );
200  double Original_Et = originalTower->et();
201 
202  if(sumRecHits_){
203  Original_Et = getEt(originalTower);
204  }
205 
206  double etnew = Original_Et - getPU(it,1,1);
207  if(etnew < 0.) etnew = 0;
208  newjetet = newjetet + etnew;
209  jetOffset_[ijet] += Original_Et - etnew;
210  }
211 
212  if(sumRecHits_){
213  double mScale = newjetet/pseudojetTMP->Et();
214  int cshist = pseudojetTMP->cluster_hist_index();
215  pseudojetTMP->reset(pseudojetTMP->px()*mScale, pseudojetTMP->py()*mScale,
216  pseudojetTMP->pz()*mScale, pseudojetTMP->e()*mScale);
217  pseudojetTMP->set_cluster_hist_index(cshist);
218  }
219 
220  }
221 }
222 
223 
225  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
226  const GlobalPoint& pos=geo_->getPosition(ctc->id());
227  double energy = ctc->emEnergy() + ctc->hadEnergy();
228 
229  if(0){
230  energy = 0;
231  const std::vector<DetId>& hitids = ctc->constituents();
232  for(unsigned int i = 0; i< hitids.size(); ++i){
233 
234  }
235  }
236 
237  double et = energy*sin(pos.theta());
238  return et;
239 }
240 
242  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
243  const GlobalPoint& pos=geo_->getPosition(ctc->id());
244  double eta = pos.eta();
245  return eta;
246 }
247 
249  int it = ieta(in);
250  return getPU(it,1,0);
251 }
252 
254  int it = ieta(in);
255  return getPU(it,0,1);
256 }
257 
259  int it = ieta(in);
260  return getPU(it,1,1);
261 }
262 
263 double ParametrizedSubtractor::getPU(int ieta,bool addMean, bool addSigma) const {
264 
265  //double e = hEta[bin_]->GetBinContent(hEta[bin_]->FindBin(ieta));
266  //double c = fPU->Eval(centrality_);
267 
268  double em = hEtaMean[bin_]->GetBinContent(hEtaMean[bin_]->FindBin(ieta));
269  double cm = fMean->Eval(centrality_);
270 
271  double er = hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_]->FindBin(ieta));
272  double cr = fRMS->Eval(centrality_);
273 
274  if(interpolate_){
275  double n = 0;
276  int hbin = 40-bin_;
277  double centerweight = (centrality_ - hC->GetBinCenter(hbin));
278  double lowerweight = (centrality_ - hC->GetBinLowEdge(hbin));
279  double upperweight = (centrality_ - hC->GetBinLowEdge(hbin+1));
280 
281  em *= lowerweight*upperweight;
282  er *= lowerweight*upperweight;
283  n += lowerweight*upperweight;
284 
285  if(bin_ > 0){
286  em += upperweight*centerweight*hEtaMean[bin_]->GetBinContent(hEtaMean[bin_-1]->FindBin(ieta));
287  er += upperweight*centerweight*hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_-1]->FindBin(ieta));
288  n += upperweight*centerweight;
289  }
290 
291  if(bin_ < 39){
292  em += lowerweight*centerweight*hEtaMean[bin_]->GetBinContent(hEtaMean[bin_+1]->FindBin(ieta));
293  er += lowerweight*centerweight*hEtaRMS[bin_]->GetBinContent(hEtaRMS[bin_+1]->FindBin(ieta));
294  n += lowerweight*centerweight;
295  }
296  em /= n;
297  er /= n;
298  }
299 
300  // return e*c;
301  return addMean*em*cm + addSigma*nSigmaPU_*er*cr;
302 }
303 
304 
#define LogDebug(id)
double getEt(const reco::CandidatePtr &in) const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< double > jetOffset_
virtual void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll)
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:449
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:143
std::map< int, int > geomtowers_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
virtual double getSigmaAtTower(const reco::CandidatePtr &in) const
virtual double getPileUpAtTower(const reco::CandidatePtr &in) const
std::vector< TH1D * > hEtaMean
T eta() const
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_
int iEvent
Definition: GenABIO.cc:230
double emEnergy() const
Definition: CaloTower.h:94
std::vector< TH1D * > hEta
edm::EDGetTokenT< reco::Centrality > centTag_
def move
Definition: eostools.py:508
string inf
Definition: EcalCondDB.py:94
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:88
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
virtual void subtractPedestal(std::vector< fastjet::PseudoJet > &coll)
virtual double getMeanAtTower(const reco::CandidatePtr &in) const
double getPU(int ieta, bool addMean, bool addSigma) const
double hadEnergy() const
Definition: CaloTower.h:95
int iphi(const reco::CandidatePtr &in) const
CaloTowerDetId id() const
Definition: CaloTower.h:87
JetCorrectorParametersCollection coll
Definition: classes.h:10
ActiveAreaSpecPtr fjActiveArea_
ClusterSequencePtr fjClusterSeq_
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
T eta() const
Definition: PV3DBase.h:76
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
CaloGeometry const * geo_
std::map< int, double > emean_
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
JetCorrectorParameters::Definitions def
Definition: classes.h:6
std::vector< HcalDetId > allgeomid_
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)
ParametrizedSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)