21 doAreaFastjet_ = iConfig.
getParameter<
bool>(
"doAreaFastjet");
22 doRhoFastjet_ = iConfig.
getParameter<
bool>(
"doRhoFastjet");
27 ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
28 activeAreaRepeats = iConfig.
getParameter<
int>(
"Active_Area_Repeats");
31 if ( doAreaFastjet_ || doRhoFastjet_ ) {
35 if ( ( ghostEtaMax < 0 ) || ( activeAreaRepeats < 0 ) || ( ghostArea < 0 ) )
36 throw cms::Exception(
"doAreaFastjet or doRhoFastjet") <<
"Parameters ghostEtaMax, activeAreaRepeats or ghostArea for doAreaFastjet/doRhoFastjet are not defined." << std::endl;
42 std::vector<fastjet::PseudoJet>& towers,
43 std::vector<fastjet::PseudoJet>&
output){
48 fjOriginalInputs_ = (*fjInputs_);
49 for (
unsigned int i = 0;
i < fjInputs_->size(); ++
i){
50 fjOriginalInputs_[
i].set_user_index((*fjInputs_)[
i].user_index());
56 fjJetDefinition_ =
JetDefPtr(
new fastjet::JetDefinition( *jetDef ) );
62 LogDebug(
"PileUpSubtractor")<<
"The subtractor setting up geometry...\n";
73 for(std::vector<DetId>::const_iterator did=alldid.begin(); did != alldid.end(); did++){
76 if( (hid).
depth() == 1 ) {
77 allgeomid_.push_back(*did);
79 if((hid).ieta() != ietaold){
80 ietaold = (hid).ieta();
81 geomtowers_[(hid).ieta()] = 1;
82 if((hid).ieta() > ietamax_) ietamax_ = (hid).ieta();
83 if((hid).ieta() < ietamin_) ietamin_ = (hid).ieta();
86 geomtowers_[(hid).ieta()]++;
93 for (
int i = ietamin_;
i<ietamax_+1;
i++) {
94 ntowersWithJets_[
i] = 0;
103 LogDebug(
"PileUpSubtractor")<<
"The subtractor calculating pedestals...\n";
104 map<int,double> emean2;
105 map<int,int> ntowers;
107 int ietaold = -10000;
112 for(
int i = ietamin_;
i < ietamax_+1;
i++)
120 for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin (),
121 fjInputsEnd = coll.end();
122 input_object != fjInputsEnd; ++input_object) {
124 ieta0 = ieta( originalTower );
125 double Original_Et = originalTower->et();
126 if( ieta0-ietaold != 0 )
128 emean_[ieta0] = emean_[ieta0]+Original_Et;
129 emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
135 emean_[ieta0] = emean_[ieta0]+Original_Et;
136 emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
141 for(map<int,int>::const_iterator gt = geomtowers_.begin(); gt != geomtowers_.end(); gt++)
143 int it = (*gt).first;
145 double e1 = (*(emean_.find(it))).second;
146 double e2 = (*emean2.find(it)).
second;
147 int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;
149 LogDebug(
"PileUpSubtractor")<<
" ieta : "<<it<<
" number of towers : "<<nt<<
" e1 : "<<e1<<
" e2 : "<<e2<<
"\n";
152 double eee = e2/nt - e1*e1/(nt*
nt);
154 esigma_[it] = nSigmaPU_*
sqrt(eee);
161 LogDebug(
"PileUpSubtractor")<<
" ieta : "<<it<<
" Pedestals : "<<emean_[it]<<
" "<<esigma_[it]<<
"\n";
172 LogDebug(
"PileUpSubtractor")<<
"The subtractor subtracting pedestals...\n";
175 for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin (),
176 fjInputsEnd = coll.end();
177 input_object != fjInputsEnd; ++input_object) {
183 double etnew = itow->et() - (*(emean_.find(it))).second - (*(esigma_.find(it))).second;
184 float mScale = etnew/input_object->Et();
185 if(etnew < 0.) mScale = 0.;
188 input_object->pz()*mScale, input_object->e()*mScale);
190 int index = input_object->user_index();
191 input_object->reset_momentum ( towP4.px(),
195 input_object->set_user_index(index);
202 LogDebug(
"PileUpSubtractor")<<
"The subtractor calculating orphan input...\n";
204 (*fjInputs_) = fjOriginalInputs_;
206 vector<int> jettowers;
207 vector<pair<int,int> > excludedTowers;
209 vector <fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
210 fjJetsEnd = fjJets_->end();
211 for (; pseudojetTMP != fjJetsEnd ; ++pseudojetTMP) {
212 if(pseudojetTMP->perp() < puPtMin_)
continue;
215 for(vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++)
218 vector<pair<int,int> >::const_iterator exclude =
find(excludedTowers.begin(),excludedTowers.end(),pair<int,int>(im->ieta(),im->iphi()));
219 if( dr < radiusPU_ && exclude == excludedTowers.end()) {
220 ntowersWithJets_[(*im).ieta()]++;
221 excludedTowers.push_back(pair<int,int>(im->ieta(),im->iphi()));
224 vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(),
225 fjInputsEnd = fjInputs_->end();
227 for (; it != fjInputsEnd; ++it ) {
228 int index = it->user_index();
229 int ie = ieta((*inputs_)[index]);
230 int ip = iphi((*inputs_)[index]);
231 vector<pair<int,int> >::const_iterator exclude =
find(excludedTowers.begin(),excludedTowers.end(),pair<int,int>(ie,ip));
232 if(exclude != excludedTowers.end()) {
233 jettowers.push_back(index);
241 for(vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(),
242 fjInputsEnd = fjInputs_->end(); it != fjInputsEnd; ++it ) {
243 int index = it->user_index();
244 vector<int>::const_iterator itjet =
find(jettowers.begin(),jettowers.end(),
index);
245 if( itjet == jettowers.end() ){
247 fastjet::PseudoJet orphan(originalTower->px(),originalTower->py(),originalTower->pz(),originalTower->energy());
248 orphan.set_user_index(index);
250 orphanInput.push_back(orphan);
258 LogDebug(
"PileUpSubtractor")<<
"The subtractor correcting jets...\n";
260 using namespace reco;
265 jetOffset_.reserve(fjJets_->size());
266 vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
267 jetsEnd = fjJets_->end();
268 for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
269 int ijet = pseudojetTMP - fjJets_->begin();
270 jetOffset_[ijet] = 0;
272 std::vector<fastjet::PseudoJet> towers =
273 fastjet::sorted_by_pt( pseudojetTMP->constituents() );
274 double newjetet = 0.;
275 for(vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(),
276 towEnd = towers.end();
281 int it = ieta( originalTower );
282 double Original_Et = originalTower->et();
283 double etnew = Original_Et - (*emean_.find(it)).
second - (*esigma_.find(it)).
second;
284 if(etnew < 0.) etnew = 0;
285 newjetet = newjetet + etnew;
286 jetOffset_[ijet] += Original_Et - etnew;
288 double mScale = newjetet/pseudojetTMP->Et();
289 LogDebug(
"PileUpSubtractor")<<
"pseudojetTMP->Et() : "<<pseudojetTMP->Et()<<
'\n';
290 LogDebug(
"PileUpSubtractor")<<
"newjetet : "<<newjetet<<
'\n';
291 LogDebug(
"PileUpSubtractor")<<
"jetOffset_[ijet] : "<<jetOffset_[ijet]<<
'\n';
292 LogDebug(
"PileUpSubtractor")<<
"pseudojetTMP->Et() - jetOffset_[ijet] : "<<pseudojetTMP->Et() - jetOffset_[ijet]<<
'\n';
293 LogDebug(
"PileUpSubtractor")<<
"Scale is : "<<mScale<<
'\n';
294 int cshist = pseudojetTMP->cluster_hist_index();
295 pseudojetTMP->reset_momentum(pseudojetTMP->px()*mScale, pseudojetTMP->py()*mScale,
296 pseudojetTMP->pz()*mScale, pseudojetTMP->e()*mScale);
297 pseudojetTMP->set_cluster_hist_index(cshist);
305 for(vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++){
306 if( im->depth() != 1 )
continue;
310 pu += (*emean_.find(im->ieta())).second+(*esigma_.find(im->ieta())).second;
319 return (*emean_.find(it)).
second;
324 return (*esigma_.find(it)).
second;
329 return (*emean_.find(it)).
second + (*esigma_.find(it)).
second;
335 int n = (*(geomtowers_.find(it))).second - (*(ntowersWithJets_.find(it))).second;
342 int n = (*(ntowersWithJets_.find(it))).second;
355 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
367 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
std::shared_ptr< fastjet::JetDefinition > JetDefPtr
T getParameter(std::string const &) const
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
virtual double getMeanAtTower(const reco::CandidatePtr &in) const
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
int getNwithJets(const reco::CandidatePtr &in) const
T const * get() const
Returns C++ pointer to the item.
Geom::Phi< T > phi() const
virtual double getPileUpAtTower(const reco::CandidatePtr &in) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static std::string const input
int ieta(const reco::CandidatePtr &in) const
U second(std::pair< T, U > const &p)
virtual void offsetCorrectJets()
int iphi() const
get the tower iphi
boost::shared_ptr< fastjet::GhostedAreaSpec > ActiveAreaSpecPtr
virtual void subtractPedestal(std::vector< fastjet::PseudoJet > &coll)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
#define EDM_REGISTER_PLUGINFACTORY(_factory_, _category_)
int iphi(const reco::CandidatePtr &in) const
CaloTowerDetId id() const
virtual double getSigmaAtTower(const reco::CandidatePtr &in) const
virtual void setDefinition(JetDefPtr const &jetDef)
et
define resolution functions of each parameter
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
PileUpSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
virtual void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll)
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)
int ieta() const
get the tower ieta
virtual double getCone(double cone, double eta, double phi, double &et, double &pu)
virtual void reset(std::vector< edm::Ptr< reco::Candidate > > &input, std::vector< fastjet::PseudoJet > &towers, std::vector< fastjet::PseudoJet > &output)
T const * product() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
int getN(const reco::CandidatePtr &in) const
boost::shared_ptr< fastjet::JetDefinition > JetDefPtr