CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReflectedIterator.cc
Go to the documentation of this file.
4 
6 using namespace std;
7 
9  for ( std::map<int, double>::iterator iter = esigma_.begin();
10  iter != esigma_.end(); ++iter ){
11  iter->second = s*(iter->second);
12  }
13 }
14 
15 
17 {
18 
19  LogDebug("PileUpSubtractor")<<"The subtractor correcting jets...\n";
20  jetOffset_.clear();
21 
22  using namespace reco;
23 
24  (*fjInputs_) = fjOriginalInputs_;
25  rescaleRMS(nSigmaPU_);
26  subtractPedestal(*fjInputs_);
27  const fastjet::JetDefinition& def = fjClusterSeq_->jet_def();
28  if ( !doAreaFastjet_ && !doRhoFastjet_) {
29  fastjet::ClusterSequence newseq( *fjInputs_, def );
30  (*fjClusterSeq_) = newseq;
31  } else {
32  fastjet::ClusterSequenceArea newseq( *fjInputs_, def , *fjActiveArea_ );
33  (*fjClusterSeq_) = newseq;
34  }
35 
36  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
37 
38  jetOffset_.reserve(fjJets_->size());
39 
40  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
41  jetsEnd = fjJets_->end();
42  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
43 
44  int ijet = pseudojetTMP - fjJets_->begin();
45  jetOffset_[ijet] = 0;
46 
47  std::vector<fastjet::PseudoJet> towers =
48  sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
49 
50  double newjetet = 0.;
51  for(vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(),
52  towEnd = towers.end();
53  ito != towEnd;
54  ++ito)
55  {
56  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
57  int it = ieta( originalTower );
58  double Original_Et = originalTower->et();
59  double etnew = Original_Et - (*emean_.find(-it)).second - (*esigma_.find(-it)).second;
60  if(etnew < 0.) etnew = 0;
61  newjetet = newjetet + etnew;
62  jetOffset_[ijet] += Original_Et - etnew;
63  }
64  }
65 }
66 
67 void ReflectedIterator::subtractPedestal(vector<fastjet::PseudoJet> & coll)
68 {
69 
70  LogDebug("PileUpSubtractor")<<"The subtractor subtracting pedestals...\n";
71 
72  int it = -100;
73 
74  vector<fastjet::PseudoJet> newcoll;
75 
76  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin (),
77  fjInputsEnd = coll.end();
78  input_object != fjInputsEnd; ++input_object) {
79 
80  reco::CandidatePtr const & itow = (*inputs_)[ input_object->user_index() ];
81 
82  it = ieta( itow );
83  iphi( itow );
84 
85  double Original_Et = itow->et();
86  if(sumRecHits_){
87  Original_Et = getEt(itow);
88  }
89 
90  double etnew = Original_Et - (*(emean_.find(-it))).second - (*(esigma_.find(-it))).second;
91  float mScale = etnew/input_object->Et();
92  if(etnew < 0.) mScale = 0.;
93 
94  math::XYZTLorentzVectorD towP4(input_object->px()*mScale, input_object->py()*mScale,
95  input_object->pz()*mScale, input_object->e()*mScale);
96 
97  int index = input_object->user_index();
98  input_object->reset ( towP4.px(),
99  towP4.py(),
100  towP4.pz(),
101  towP4.energy() );
102  input_object->set_user_index(index);
103 
104  if(etnew > 0. && dropZeroTowers_) newcoll.push_back(*input_object);
105  }
106 
107  if(dropZeroTowers_) coll = newcoll;
108 
109 }
110 
111 void ReflectedIterator::calculatePedestal( vector<fastjet::PseudoJet> const & coll )
112 {
113  LogDebug("PileUpSubtractor")<<"The subtractor calculating pedestals...\n";
114 
115  map<int,double> emean2;
116  map<int,int> ntowers;
117 
118  int ietaold = -10000;
119  int ieta0 = -100;
120 
121  // Initial values for emean_, emean2, esigma_, ntowers
122 
123  for(int i = ietamin_; i < ietamax_+1; i++)
124  {
125  emean_[i] = 0.;
126  emean2[i] = 0.;
127  esigma_[i] = 0.;
128  ntowers[i] = 0;
129  }
130 
131  for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin (),
132  fjInputsEnd = coll.end();
133  input_object != fjInputsEnd; ++input_object) {
134 
135  const reco::CandidatePtr & originalTower=(*inputs_)[ input_object->user_index()];
136  ieta0 = ieta( originalTower );
137  double Original_Et = originalTower->et();
138  if(sumRecHits_){
139  Original_Et = getEt(originalTower);
140  }
141 
142  if( ieta0-ietaold != 0 )
143  {
144  emean_[ieta0] = emean_[ieta0]+Original_Et;
145  emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
146  ntowers[ieta0] = 1;
147  ietaold = ieta0;
148  }
149  else
150  {
151  emean_[ieta0] = emean_[ieta0]+Original_Et;
152  emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
153  ntowers[ieta0]++;
154  }
155 
156  }
157 
158  for(map<int,int>::const_iterator gt = geomtowers_.begin(); gt != geomtowers_.end(); gt++)
159  {
160 
161  int it = (*gt).first;
162 
163  double e1 = (*(emean_.find(it))).second;
164  double e2 = (*emean2.find(it)).second;
165  int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;
166 
167  LogDebug("PileUpSubtractor")<<" ieta : "<<it<<" number of towers : "<<nt<<" e1 : "<<e1<<" e2 : "<<e2<<"\n";
168 
169  if(nt > 0) {
170  emean_[it] = e1/nt;
171  double eee = e2/nt - e1*e1/(nt*nt);
172  if(eee<0.) eee = 0.;
173  esigma_[it] = nSigmaPU_*sqrt(eee);
174  }
175  else
176  {
177  emean_[it] = 0.;
178  esigma_[it] = 0.;
179  }
180  LogDebug("PileUpSubtractor")<<" ieta : "<<it<<" Pedestals : "<<emean_[it]<<" "<<esigma_[it]<<"\n";
181  }
182 }
183 
185  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
186  const GlobalPoint& pos=geo_->getPosition(ctc->id());
187  double energy = ctc->emEnergy() + ctc->hadEnergy();
188  double et = energy*sin(pos.theta());
189  return et;
190 }
191 
193  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
194  const GlobalPoint& pos=geo_->getPosition(ctc->id());
195  double eta = pos.eta();
196  return eta;
197 }
#define LogDebug(id)
int def(FILE *, FILE *, int)
int i
Definition: DBlmapReader.cc:9
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T eta() const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
U second(std::pair< T, U > const &p)
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
double emEnergy() const
Definition: CaloTower.h:77
T sqrt(T t)
Definition: SSEVec.h:48
double getEta(const reco::CandidatePtr &in) const
int nt
Definition: AMPTWrapper.h:32
double hadEnergy() const
Definition: CaloTower.h:78
Float e1
Definition: deltaR.h:22
CaloTowerDetId id() const
Definition: CaloTower.h:70
Float e2
Definition: deltaR.h:23
virtual void subtractPedestal(std::vector< fastjet::PseudoJet > &coll)
T eta() const
Definition: PV3DBase.h:76
DTRecHit1DPair & gt
double getEt(const reco::CandidatePtr &in) const
virtual void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll)
void rescaleRMS(double s)
virtual void offsetCorrectJets()