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),
24  dropZeroTowers_(iConfig.getUntrackedParameter<bool>("dropZeroTowers",true)),
25  cbins_(0)
26 {
27  centTag_ = iConfig.getUntrackedParameter<edm::InputTag>("centTag",edm::InputTag("hiCentrality","","RECO"));
28 
29  interpolate_ = iConfig.getParameter<bool>("interpolate");
30  sumRecHits_ = iConfig.getParameter<bool>("sumRecHits");
31 
32  std::string ifname = "RecoHI/HiJetAlgos/data/PU_DATA.root";
33  TFile* inf = new TFile(edm::FileInPath(ifname).fullPath().data());
34  fPU = (TF1*)inf->Get("fPU");
35  fMean = (TF1*)inf->Get("fMean");
36  fRMS = (TF1*)inf->Get("fRMS");
37  hC = (TH1D*)inf->Get("hC");
38 
39  for(int i = 0; i < 40; ++i){
40  hEta.push_back((TH1D*)inf->Get(Form("hEta_%d",i)));
41  hEtaMean.push_back((TH1D*)inf->Get(Form("hEtaMean_%d",i)));
42  hEtaRMS.push_back((TH1D*)inf->Get(Form("hEtaRMS_%d",i)));
43  }
44 
45 }
46 
47 
49  LogDebug("PileUpSubtractor")<<"The subtractor setting up geometry...\n";
50 
51  // if(!cbins_) getCentralityBinsFromDB(iSetup);
52 
54  iEvent.getByLabel(centTag_,cent);
55 
56  centrality_ = cent->EtHFhitSum();
57  bin_ = 40-hC->FindBin(centrality_);
58  if(bin_ > 39) bin_ = 39;
59  if(bin_ < 0) bin_ = 0;
60 
61  if(!geo_) {
63  iSetup.get<CaloGeometryRecord>().get(pG);
64  geo_ = pG.product();
65  std::vector<DetId> alldid = geo_->getValidDetIds();
66 
67  int ietaold = -10000;
68  ietamax_ = -10000;
69  ietamin_ = 10000;
70  for(std::vector<DetId>::const_iterator did=alldid.begin(); did != alldid.end(); did++){
71  if( (*did).det() == DetId::Hcal ){
72  HcalDetId hid = HcalDetId(*did);
73  if( (hid).depth() == 1 ) {
74  allgeomid_.push_back(*did);
75 
76  if((hid).ieta() != ietaold){
77  ietaold = (hid).ieta();
78  geomtowers_[(hid).ieta()] = 1;
79  if((hid).ieta() > ietamax_) ietamax_ = (hid).ieta();
80  if((hid).ieta() < ietamin_) ietamin_ = (hid).ieta();
81  }
82  else{
83  geomtowers_[(hid).ieta()]++;
84  }
85  }
86  }
87  }
88  }
89 
90  for (int i = ietamin_; i<ietamax_+1; i++) {
91  emean_[i] = 0.;
92  esigma_[i] = 0.;
93  ntowersWithJets_[i] = 0;
94  }
95 }
96 
97 
98 void ParametrizedSubtractor::calculatePedestal( vector<fastjet::PseudoJet> const & coll ){
99  return;
100 }
101 
102 void ParametrizedSubtractor::subtractPedestal(vector<fastjet::PseudoJet> & coll)
103 {
104  if(0){
105  return;
106  }else{
107  LogDebug("PileUpSubtractor")<<"The subtractor subtracting pedestals...\n";
108 
109  int it = -100;
110  int ip = -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  ip = 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:15
std::vector< fastjet::PseudoJet > * fjJets_
std::map< int, double > esigma_
std::vector< TH1D * > hEtaRMS
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
ParametrizedSubtractor(const edm::ParameterSet &iConfig)
int ieta(const reco::CandidatePtr &in) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:69
std::vector< fastjet::PseudoJet > * fjInputs_
std::map< int, int > ntowersWithJets_
int iEvent
Definition: GenABIO.cc:243
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:148
double emEnergy() const
Definition: CaloTower.h:79
std::vector< TH1D * > hEta
string inf
Definition: EcalCondDB.py:94
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:73
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)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
virtual double getMeanAtTower(const reco::CandidatePtr &in) const
double getPU(int ieta, bool addMean, bool addSigma) const
double hadEnergy() const
Definition: CaloTower.h:80
int iphi(const reco::CandidatePtr &in) const
CaloTowerDetId id() const
Definition: CaloTower.h:72
JetCorrectorParametersCollection coll
Definition: classes.h:14
ActiveAreaSpecPtr fjActiveArea_
ClusterSequencePtr fjClusterSeq_
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
T eta() const
Definition: PV3DBase.h:70
CaloGeometry const * geo_
std::map< int, double > emean_
string s
Definition: asciidump.py:422
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
JetCorrectorParameters::Definitions def
Definition: classes.h:10
std::vector< HcalDetId > allgeomid_
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)