1 #ifndef RecoEcal_EgammaClusterProducers_EGRefinedSCFixer_h
2 #define RecoEcal_EgammaClusterProducers_EGRefinedSCFixer_h
19 #include <unordered_set>
61 static std::vector<edm::Ptr<reco::CaloCluster> >
67 static std::unordered_set<unsigned>
73 static std::vector<edm::Ptr<reco::PFCluster> >
93 token = consumes<T>(
tag);
121 ebeeClustersCollection_(
"EBEEClusters"),
122 esClustersCollection_(
"ESClusters"),
123 throwOnDupECALClustersInEvent_(iConfig.getParameter<bool>(
"throwOnDupECALClustersInEvent")),
124 throwOnDupESClustersInEvent_(iConfig.getParameter<bool>(
"throwOnDupESClustersInEvent"))
132 getToken(
orgSCToken_[1], iConfig,
"orgSC",
"particleFlowSuperClusterECALEndcapWithPreshower");
137 produces<reco::SuperClusterCollection>();
140 produces<reco::ConversionCollection>();
143 produces<SCRefMap>();
144 produces<SCRefMap>(
"parentSCsEB");
145 produces<SCRefMap>(
"parentSCsEE");
147 produces<bool>(
"dupECALClusters");
148 produces<bool>(
"dupESClusters");
165 auto const& orgBCs = getHandle(iEvent,
orgBCToken_);
166 auto const& orgESs = getHandle(iEvent,
orgESToken_);
168 auto const& orgEBSCs = getHandle(iEvent,
orgSCToken_[0]);
169 auto const& orgEESCs = getHandle(iEvent,
orgSCToken_[1]);
174 auto fixedRefinedSCs = std::make_unique<reco::SuperClusterCollection>();
176 auto fixedBCs = std::make_unique<reco::CaloClusterCollection>();
181 auto fixedESs = std::make_unique<reco::CaloClusterCollection>();
182 auto fixedConvs = std::make_unique<reco::ConversionCollection>();
184 std::vector<reco::SuperClusterRef> mappedRefinedSCs;
185 std::vector<reco::SuperClusterRef> mappedSCsEB(fixedEBSCs->size());
186 std::vector<reco::SuperClusterRef> mappedSCsEE(fixedEESCs->size());
188 std::vector<edm::Ptr<reco::CaloCluster> > clusterAddedToAnyEBSC;
189 for(
auto& refinedSC : *orgRefinedSCs){
190 if(refinedSC.seed()->seed().subdetId() ==
EcalBarrel) {
194 for(
auto clusPtr : clusAdded) clusterAddedToAnyEBSC.push_back(clusPtr);
196 for(
auto clusPtr : refinedSC.clusters()) clusterAddedToAnyEBSC.push_back(clusPtr);
201 for (
unsigned iO(0); iO != orgRefinedSCs->size(); ++iO) {
202 auto& orgRefinedSC(orgRefinedSCs->at(iO));
203 mappedRefinedSCs.emplace_back(orgRefinedSCs, iO);
206 if (orgRefinedSC.seed()->seed().subdetId() ==
EcalBarrel) {
211 if (orgEBSC.isNonnull()) {
213 if (fixedEBSC.isNonnull()) {
214 mappedSCsEB[fixedEBSC.key()] = orgEBSC;
216 auto fixedRefinedSC(
makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters,clusterAddedToAnyEBSC));
217 fixedRefinedSCs->push_back(fixedRefinedSC);
225 if (orgEESC.isNonnull()) {
232 if(fixedEESC.isNonnull()) mappedSCsEE[fixedEESC.key()] = orgEESC;
237 fixedRefinedSCs->push_back(orgRefinedSC);
242 std::auto_ptr<SCRefMap> pEBSCRefMap(
new SCRefMap);
244 ebSCMapFiller.
insert(fixedEBSCs, mappedSCsEB.begin(), mappedSCsEB.end());
245 ebSCMapFiller.
fill();
246 iEvent.
put(pEBSCRefMap,
"parentSCsEB");
248 std::auto_ptr<SCRefMap> pEESCRefMap(
new SCRefMap);
250 eeSCMapFiller.
insert(fixedEESCs, mappedSCsEE.begin(), mappedSCsEE.end());
251 eeSCMapFiller.
fill();
252 iEvent.
put(pEESCRefMap,
"parentSCsEE");
255 std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEBEE;
256 std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
258 bool duplicateECALClusters=
false;
259 bool duplicateESClusters=
false;
260 for (
auto& sc : *fixedRefinedSCs) {
263 for (
auto&& cItr(sc.clustersBegin()); cItr != sc.clustersEnd(); ++cItr) {
265 if (pfClusterMapEBEE.count(ptr) == 0) {
266 pfClusterMapEBEE[ptr] = fixedBCs->size();
267 fixedBCs->emplace_back(*ptr);
270 duplicateECALClusters=
true;
273 <<
"Found an EB/EE pfcluster matched to more than one supercluster!";
278 for (
auto&& cItr = sc.preshowerClustersBegin(); cItr!=sc.preshowerClustersEnd(); ++cItr) {
280 if (pfClusterMapES.count(ptr) == 0) {
281 pfClusterMapES[ptr] = fixedESs->size();
282 fixedESs->emplace_back(*ptr);
285 duplicateESClusters=
true;
288 <<
"Found an ES pfcluster matched to more than one supercluster!";
293 iEvent.
put(std::make_unique<bool>(duplicateECALClusters),
"dupECALClusters");
294 iEvent.
put(std::make_unique<bool>(duplicateESClusters),
"dupESClusters");
301 for (
auto& sc : *fixedRefinedSCs) {
306 for (
auto&& cItr(sc.clustersBegin()); cItr!=sc.clustersEnd(); ++cItr)
308 sc.setClusters(clusters);
311 for (
auto&& cItr(sc.preshowerClustersBegin()); cItr!=sc.preshowerClustersEnd(); ++cItr)
313 sc.setPreshowerClusters(psclusters);
319 std::auto_ptr<SCRefMap> pRefinedSCRefMap(
new SCRefMap);
321 refinedSCMapFiller.
insert(scHandle, mappedRefinedSCs.begin(), mappedRefinedSCs.end());
322 refinedSCMapFiller.
fill();
323 iEvent.
put(pRefinedSCRefMap);
326 for (
auto&
conv : *orgConvs) {
329 fixedConvs->emplace_back(
conv);
330 auto& newConv(fixedConvs->back());
336 newConv.setMatchingSuperCluster(scPtrVec);
343 std::vector<edm::Ptr<reco::CaloCluster> >
347 std::vector<edm::Ptr<reco::CaloCluster> > missingSubClusters;
348 for(
auto& subClus : lhs.
clusters()){
349 auto compFunc=[&subClus](
const auto& rhs){
return subClus->seed()==rhs->
seed();};
351 missingSubClusters.push_back(subClus);
354 return missingSubClusters;
357 std::unordered_set<unsigned>
368 std::unordered_set<unsigned> detIdsOfClustersForNewSC;
369 for(
auto& clus : fixedSC.
clusters()){
370 auto compFunc=[&clus](
auto& rhs){
return rhs->seed().rawId()==clus->seed().rawId();};
373 bool notRemoved = std::find_if(clusRemoved.begin(),clusRemoved.end(),compFunc)==clusRemoved.end();
379 bool notAddedToASuperCluster = std::find_if(clustersAddedToAnySC.begin(),
380 clustersAddedToAnySC.end(),compFunc)==clustersAddedToAnySC.end();
382 if(notRemoved && notAddedToASuperCluster){
383 detIdsOfClustersForNewSC.insert(clus->seed().rawId());
386 for(
auto clus : clusAdded){
387 detIdsOfClustersForNewSC.insert(clus->seed().rawId());
390 return detIdsOfClustersForNewSC;
393 std::vector<edm::Ptr<reco::PFCluster> >
396 std::vector<edm::Ptr<reco::PFCluster> > outClusters;
397 for(
size_t clusNr=0;clusNr<inClusters->size();clusNr++){
399 if(seedIds.count(clusPtr->seed().rawId())>0){
400 outClusters.push_back(clusPtr);
403 std::sort(outClusters.begin(),outClusters.end(),[](
auto& lhs,
auto& rhs){
return lhs->energy()>rhs->energy();});
420 unsigned seedSeedId(fixedSC.
seed()->seed().rawId());
421 listOfSeedIds.insert(seedSeedId);
427 for (
auto& ptr : clusters) {
428 if (ptr->seed().rawId() == seedSeedId) {
434 std::vector<const reco::PFCluster*> clustersBarePtrs;
436 double posX(0),posY(0),posZ(0);
437 double scNrgy(0),scCorrNrgy(0);
438 for(
auto & clus : clusters){
439 clustersBarePtrs.push_back(&*clus);
441 const double clusNrgy = clus->energy();
442 double clusCorrNrgy = clus->correctedEnergy();
444 posX += clusNrgy * clusPos.X();
445 posY += clusNrgy * clusPos.Y();
446 posZ += clusNrgy * clusPos.Z();
449 scCorrNrgy += clusCorrNrgy;
464 for(
const auto& clus : clusters ) {
466 for(
auto& hitAndFrac: clus->hitsAndFractions() ) {
const bool throwOnDupECALClustersInEvent_
T getParameter(std::string const &) const
virtual ~EGRefinedSCFixer()
bool isNonnull() const
Checks for non-null.
const std::string esClustersCollection_
void addHitAndFraction(DetId id, float fraction)
static std::unordered_set< unsigned > getListOfClusterSeedIdsForNewSC(const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC, const std::vector< edm::Ptr< reco::CaloCluster > > &clustersAddedToAnySC)
static std::vector< edm::Ptr< reco::CaloCluster > > getSubClustersMissing(const reco::SuperCluster &lhs, const reco::SuperCluster &rhs)
static HepMC::IO_HEPEVT conv
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void setPreshowerEnergyPlane2(double preshowerEnergy2)
#define DEFINE_FWK_MODULE(type)
void push_back(Ptr< T > const &iPtr)
const bool throwOnDupESClustersInEvent_
static std::vector< edm::Ptr< reco::PFCluster > > getClustersFromSeedIds(const std::unordered_set< unsigned > &seedIds, const edm::Handle< reco::PFClusterCollection > &inClusters)
double pflowPhiWidth() const
void insert(const H &h, I begin, I end)
edm::EDGetTokenT< reco::PFClusterCollection > fixedPFClustersToken_
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
void setPhiWidth(double pw)
double pflowEtaWidth() const
const std::string ebeeClustersCollection_
const_iterator begin() const
reco::SuperCluster makeFixedRefinedSC(const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC)
void setEtaWidth(double ew)
edm::EDGetTokenT< reco::ConversionCollection > orgConvToken_
edm::EDGetTokenT< reco::CaloClusterCollection > orgESToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
void setCorrectedEnergy(double cenergy)
const_iterator end() const
edm::EDGetTokenT< reco::SuperClusterCollection > fixedSCToken_[2]
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
XYZPointD XYZPoint
point in space with cartesian internal representation
static reco::SuperCluster makeFixedRefinedBarrelSC(const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC, const edm::Handle< reco::PFClusterCollection > &fixedClusters, const std::vector< edm::Ptr< reco::CaloCluster > > &clustersAddedToAnySC)
edm::EDGetTokenT< reco::SuperClusterCollection > orgRefinedSCToken_
edm::EDGetTokenT< reco::SuperClusterCollection > orgSCToken_[2]
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
edm::ValueMap< reco::SuperClusterRef > SCRefMap
void getToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &pset, const std::string &label, const std::string &instance="")
const CaloClusterPtr & seed() const
seed BasicCluster
edm::ValueMap< reco::ConversionRef > ConvRefMap
edm::EDGetTokenT< reco::CaloClusterCollection > orgBCToken_
EGRefinedSCFixer(const edm::ParameterSet &)
void setPreshowerEnergyPlane1(double preshowerEnergy1)
virtual void produce(edm::Event &, const edm::EventSetup &)
void setPreshowerEnergy(double preshowerEnergy)