CMS 3D CMS Logo

EgammaIsoESDetIdCollectionProducer.cc
Go to the documentation of this file.
2 
5 
8 
11  consumes<reco::PFCluster::EEtoPSAssociation>(iConfig.getParameter<edm::InputTag>("eeClusToESMapLabel"));
12 
14  consumes<reco::PFClusterCollection>(iConfig.getParameter<edm::InputTag>("ecalPFClustersLabel"));
15  elesToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("elesLabel"));
16 
17  phosToken_ = consumes<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("phosLabel"));
18 
20  consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("superClustersLabel"));
21 
22  minSCEt_ = iConfig.getParameter<double>("minSCEt");
23  minEleEt_ = iConfig.getParameter<double>("minEleEt");
24  minPhoEt_ = iConfig.getParameter<double>("minPhoEt");
25 
26  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
27 
28  maxDR_ = iConfig.getParameter<double>("maxDR");
29 
30  //register your products
31  produces<DetIdCollection>(interestingDetIdCollection_);
32 }
33 
35 
36 // ------------ method called to produce the data ------------
38  // take BasicClusters
40  iEvent.getByToken(superClustersToken_, superClusters);
41 
43  iEvent.getByToken(elesToken_, eles);
44 
46  iEvent.getByToken(phosToken_, phos);
47 
49  iEvent.getByToken(eeClusToESMapToken_, eeClusToESMap);
50 
52  iEvent.getByToken(ecalPFClustersToken_, ecalPFClusters);
53 
54  //Create empty output collections
55  std::vector<DetId> indexToStore;
56  indexToStore.reserve(100);
57 
58  if (eles.isValid() && eeClusToESMap.isValid() && ecalPFClusters.isValid()) {
59  for (auto& ele : *eles) {
60  float scEt = ele.superCluster()->energy() * std::sin(ele.superCluster()->position().theta());
61  if (scEt > minEleEt_ || ele.et() > minEleEt_)
62  addDetIds(*ele.superCluster(), *ecalPFClusters, *eeClusToESMap, indexToStore);
63  }
64  }
65  if (phos.isValid() && eeClusToESMap.isValid() && ecalPFClusters.isValid()) {
66  for (auto& pho : *phos) {
67  float scEt = pho.superCluster()->energy() * std::sin(pho.superCluster()->position().theta());
68  if (scEt > minPhoEt_ || pho.et() > minPhoEt_)
69  addDetIds(*pho.superCluster(), *ecalPFClusters, *eeClusToESMap, indexToStore);
70  }
71  }
72  if (superClusters.isValid() && eeClusToESMap.isValid() && ecalPFClusters.isValid()) {
73  for (auto& sc : *superClusters) {
74  float scEt = sc.energy() * std::sin(sc.position().theta());
75  if (scEt > minSCEt_)
76  addDetIds(sc, *ecalPFClusters, *eeClusToESMap, indexToStore);
77  }
78  }
79 
80  //unify the vector
81  std::sort(indexToStore.begin(), indexToStore.end());
82  std::unique(indexToStore.begin(), indexToStore.end());
83 
84  auto detIdCollection = std::make_unique<DetIdCollection>(indexToStore);
85 
86  iEvent.put(std::move(detIdCollection), interestingDetIdCollection_);
87 }
88 
89 //find all clusters within dR2<maxDR2_ of supercluster and then save det id's of hits of all es clusters matched to said ecal clusters
92  const reco::PFCluster::EEtoPSAssociation& eeClusToESMap,
93  std::vector<DetId>& detIdsToStore) {
94  const float scEta = superClus.eta();
95  // if(std::abs(scEta)+maxDR_<1.5) return; //not possible to have a endcap cluster, let alone one with preshower (eta>1.65) so exit without checking further
96  const float scPhi = superClus.phi();
97 
98  const float maxDR2 = maxDR_ * maxDR_;
99 
100  for (size_t clusNr = 0; clusNr < clusters.size(); clusNr++) {
101  const reco::PFCluster& clus = clusters[clusNr];
102  if (clus.layer() == PFLayer::ECAL_ENDCAP && reco::deltaR2(scEta, scPhi, clus.eta(), clus.phi()) < maxDR2) {
103  auto keyVal = std::make_pair(clusNr, edm::Ptr<reco::PFCluster>());
104  const auto esClusters = std::equal_range(
105  eeClusToESMap.begin(),
106  eeClusToESMap.end(),
107  keyVal,
108  [](const reco::PFCluster::EEtoPSAssociation::value_type& rhs, //roll on c++14, auto & lambda 4 evar!
109  const reco::PFCluster::EEtoPSAssociation::value_type& lhs) -> bool { return rhs.first < lhs.first; });
110  // std::cout <<"cluster "<<clus.eta()<<" had "<<std::distance(esClusters.first,esClusters.second)<<" es clusters"<<std::endl;
111  for (auto esIt = esClusters.first; esIt != esClusters.second; ++esIt) {
112  // std::cout <<"es clus "<<esIt->second->hitsAndFractions().size()<<std::endl;
113  for (const auto& hitAndFrac : esIt->second->hitsAndFractions()) {
114  detIdsToStore.push_back(hitAndFrac.first);
115  }
116  }
117 
118  } //end of endcap & dR check
119  } //end of cluster loop
120 }
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:100
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void produce(edm::Event &, const edm::EventSetup &) override
producer
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:46
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::EDGetTokenT< reco::GsfElectronCollection > elesToken_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:180
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > eeClusToESMapToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< reco::PFClusterCollection > ecalPFClustersToken_
def unique(seq, keepstr=True)
Definition: tier0.py:24
void beginRun(edm::Run const &, const edm::EventSetup &) final
float energy() const
Energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:104
bool isValid() const
Definition: HandleBase.h:70
float theta() const
Momentum polar angle. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:144
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Definition: PFCluster.h:48
edm::EDGetTokenT< reco::PhotonCollection > phosToken_
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
edm::EDGetTokenT< reco::SuperClusterCollection > superClustersToken_
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:183
void addDetIds(const reco::SuperCluster &superClus, reco::PFClusterCollection clusters, const reco::PFCluster::EEtoPSAssociation &eeClusToESMap, std::vector< DetId > &detIdsToStore)
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
EgammaIsoESDetIdCollectionProducer(const edm::ParameterSet &)
ctor