CMS 3D CMS Logo

InterestingDetIdFromSuperClusterProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: InterestingDetIdFromSuperClusterProducer
4 // Class: InterestingDetIdFromSuperClusterProducer
5 //
46 
47 #include <memory>
48 
50 public:
54  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
55 
56 private:
57  // ----------member data ---------------------------
66 
70 };
71 
74 
76  recHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsLabel"));
78  consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("superClustersLabel"));
79  caloTopologyToken_ = esConsumes<CaloTopology, CaloTopologyRecord>();
80  severityLevelToken_ = esConsumes<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd>();
81  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
82 
83  minimalEtaSize_ = iConfig.getParameter<int>("etaSize");
84  minimalPhiSize_ = iConfig.getParameter<int>("phiSize");
85  if (minimalPhiSize_ % 2 == 0 || minimalEtaSize_ % 2 == 0)
86  edm::LogError("InterestingDetIdFromSuperClusterProducerError") << "Size of eta/phi should be odd numbers";
87 
88  //register your products
89  produces<DetIdCollection>(interestingDetIdCollection_);
90 
91  severityLevel_ = iConfig.getParameter<int>("severityLevel");
92  keepNextToDead_ = iConfig.getParameter<bool>("keepNextToDead");
93  keepNextToBoundary_ = iConfig.getParameter<bool>("keepNextToBoundary");
94  if (keepNextToDead_) {
95  nextToDeadToken_ = esConsumes<EcalNextToDeadChannel, EcalNextToDeadChannelRcd>();
96  }
97 }
98 
99 // ------------ method called to produce the data ------------
102  const edm::EventSetup& iSetup) const {
103  using namespace edm;
104  using namespace std;
105 
106  auto const& caloTopology = iSetup.getData(caloTopologyToken_);
107 
108  auto const& severity = iSetup.getData(severityLevelToken_);
109  // take BasicClusters
111  iEvent.getByToken(superClustersToken_, pClusters);
112 
113  // take EcalRecHits
114  Handle<EcalRecHitCollection> recHitsHandle;
115  iEvent.getByToken(recHitsToken_, recHitsHandle);
116 
117  //Create empty output collections
118  std::vector<DetId> indexToStore;
119  indexToStore.reserve(1000);
120 
121  reco::SuperClusterCollection::const_iterator sclusIt;
122 
123  std::vector<DetId> xtalsToStore;
124  xtalsToStore.reserve(50);
125 
126  //loop over superclusters
127  for (sclusIt = pClusters->begin(); sclusIt != pClusters->end(); sclusIt++) {
128  //loop over subclusters
129  for (reco::CaloCluster_iterator clusIt = sclusIt->clustersBegin(); clusIt != sclusIt->clustersEnd(); ++clusIt) {
130  //PG barrel
131 
132  float eMax = 0.;
133  DetId eMaxId(0);
134 
135  std::vector<std::pair<DetId, float> > clusterDetIds = (*clusIt)->hitsAndFractions();
136  std::vector<std::pair<DetId, float> >::iterator posCurrent;
137 
138  EcalRecHit testEcalRecHit;
139 
140  for (posCurrent = clusterDetIds.begin(); posCurrent != clusterDetIds.end(); posCurrent++) {
141  EcalRecHitCollection::const_iterator itt = recHitsHandle->find((*posCurrent).first);
142  if ((!((*posCurrent).first.null())) && (itt != recHitsHandle->end()) && ((*itt).energy() > eMax)) {
143  eMax = (*itt).energy();
144  eMaxId = (*itt).id();
145  }
146  }
147 
148  if (eMaxId.null())
149  continue;
150 
151  const CaloSubdetectorTopology* topology = caloTopology.getSubdetectorTopology(eMaxId.det(), eMaxId.subdetId());
152 
153  xtalsToStore = topology->getWindow(eMaxId, minimalEtaSize_, minimalPhiSize_);
154  std::vector<std::pair<DetId, float> > xtalsInClus = (*clusIt)->hitsAndFractions();
155 
156  for (unsigned int ii = 0; ii < xtalsInClus.size(); ii++) {
157  xtalsToStore.push_back(xtalsInClus[ii].first);
158  }
159 
160  indexToStore.insert(indexToStore.end(), xtalsToStore.begin(), xtalsToStore.end());
161  }
162  }
163 
164  for (EcalRecHitCollection::const_iterator it = recHitsHandle->begin(); it != recHitsHandle->end(); ++it) {
165  // also add recHits of dead TT if the corresponding TP is saturated
166  if (it->checkFlag(EcalRecHit::kTPSaturated)) {
167  indexToStore.push_back(it->id());
168  }
169  // add hits for severities above a threshold
170  if (severityLevel_ >= 0 && severity.severityLevel(*it) >= severityLevel_) {
171  indexToStore.push_back(it->id());
172  }
173  if (keepNextToDead_) {
175  // also keep channels next to dead ones
176  if (EcalTools::isNextToDead(it->id(), *dch)) {
177  indexToStore.push_back(it->id());
178  }
179  }
180 
181  if (keepNextToBoundary_) {
182  // keep channels around EB/EE boundary
183  if (it->id().subdetId() == EcalBarrel) {
184  EBDetId ebid(it->id());
185  if (abs(ebid.ieta()) == 85)
186  indexToStore.push_back(it->id());
187  } else {
189  indexToStore.push_back(it->id());
190  }
191  }
192  }
193 
194  //unify the vector
195  std::sort(indexToStore.begin(), indexToStore.end());
196  std::unique(indexToStore.begin(), indexToStore.end());
197 
198  auto detIdCollection = std::make_unique<DetIdCollection>(indexToStore);
199 
200  iEvent.put(std::move(detIdCollection), interestingDetIdCollection_);
201 }
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::vector< EcalRecHit >::const_iterator const_iterator
Log< level::Error, false > LogError
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
int iEvent
Definition: GenABIO.cc:224
def unique(seq, keepstr=True)
Definition: tier0.py:24
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static bool isNextToRingBoundary(EEDetId id)
Definition: EEDetId.cc:284
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
const_iterator begin() const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
ii
Definition: cuy.py:589
edm::ESGetToken< EcalNextToDeadChannel, EcalNextToDeadChannelRcd > nextToDeadToken_
const_iterator end() const
static bool isNextToDead(const DetId &id, const EcalNextToDeadChannel &es)
true if the channel is near a dead one (in the 3x3)
Definition: EcalTools.cc:54
Definition: DetId.h:17
edm::EDGetTokenT< reco::SuperClusterCollection > superClustersToken_
iterator find(key_type k)
HLT enums.
edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > severityLevelToken_
def move(src, dest)
Definition: eostools.py:511
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
producer