CMS 3D CMS Logo

InterestingDetIdCollectionProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: InterestingDetIdCollectionProducer
4 // Class: InterestingDetIdCollectionProducer
5 //
47 
48 #include <memory>
49 
51 public:
55  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
56 
57 private:
58  // ----------member data ---------------------------
64 
68 
72 };
73 
76 
78  recHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsLabel"));
80  consumes<reco::BasicClusterCollection>(iConfig.getParameter<edm::InputTag>("basicClustersLabel"));
81  caloTopologyToken_ = esConsumes<CaloTopology, CaloTopologyRecord>();
82  sevLVToken_ = esConsumes<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd>();
83  nextToDeadToken_ = esConsumes<EcalNextToDeadChannel, EcalNextToDeadChannelRcd>();
84 
85  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
86 
87  minimalEtaSize_ = iConfig.getParameter<int>("etaSize");
88  minimalPhiSize_ = iConfig.getParameter<int>("phiSize");
89  if (minimalPhiSize_ % 2 == 0 || minimalEtaSize_ % 2 == 0)
90  edm::LogError("InterestingDetIdCollectionProducerError") << "Size of eta/phi should be odd numbers";
91 
92  //register your products
93  produces<DetIdCollection>(interestingDetIdCollection_);
94 
95  severityLevel_ = iConfig.getParameter<int>("severityLevel");
96  keepNextToDead_ = iConfig.getParameter<bool>("keepNextToDead");
97  keepNextToBoundary_ = iConfig.getParameter<bool>("keepNextToBoundary");
98 }
99 
100 // ------------ method called to produce the data ------------
103  const edm::EventSetup& iSetup) const {
104  using namespace edm;
105  using namespace std;
106 
107  auto const& caloTopology = iSetup.getData(caloTopologyToken_);
108 
109  auto const& severity = iSetup.getData(sevLVToken_);
110 
111  // take BasicClusters
113  iEvent.getByToken(basicClustersToken_, pClusters);
114 
115  // take EcalRecHits
116  Handle<EcalRecHitCollection> recHitsHandle;
117  iEvent.getByToken(recHitsToken_, recHitsHandle);
118 
119  //Create empty output collections
120  std::vector<DetId> indexToStore;
121  indexToStore.reserve(1000);
122 
123  reco::BasicClusterCollection::const_iterator clusIt;
124 
125  std::vector<DetId> xtalsToStore;
126  xtalsToStore.reserve(50);
127  for (clusIt = pClusters->begin(); clusIt != pClusters->end(); clusIt++) {
128  const std::vector<std::pair<DetId, float> >& clusterDetIds = clusIt->hitsAndFractions();
129  for (const auto& detidpair : clusterDetIds) {
130  indexToStore.push_back(detidpair.first);
131  }
132 
133  //below checks and additional code are only relevant for EB/EE, not for ES
134  if (clusterDetIds.front().first.subdetId() == EcalBarrel || clusterDetIds.front().first.subdetId() == EcalEndcap) {
135  std::vector<std::pair<DetId, float> >::const_iterator posCurrent;
136 
137  float eMax = 0.;
138  DetId eMaxId(0);
139 
140  EcalRecHit testEcalRecHit;
141 
142  for (posCurrent = clusterDetIds.begin(); posCurrent != clusterDetIds.end(); posCurrent++) {
143  EcalRecHitCollection::const_iterator itt = recHitsHandle->find((*posCurrent).first);
144  if ((!((*posCurrent).first.null())) && (itt != recHitsHandle->end()) && ((*itt).energy() > eMax)) {
145  eMax = (*itt).energy();
146  eMaxId = (*itt).id();
147  }
148  }
149 
150  if (eMaxId.null())
151  continue;
152 
153  const CaloSubdetectorTopology* topology = caloTopology.getSubdetectorTopology(eMaxId.det(), eMaxId.subdetId());
154 
155  xtalsToStore = topology->getWindow(eMaxId, minimalEtaSize_, minimalPhiSize_);
156 
157  for (const auto& detid : xtalsToStore) {
158  indexToStore.push_back(detid);
159  }
160  }
161  }
162 
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 
195  //unify the vector
196  std::sort(indexToStore.begin(), indexToStore.end());
197  std::unique(indexToStore.begin(), indexToStore.end());
198 
199  iEvent.put(std::make_unique<DetIdCollection>(indexToStore), interestingDetIdCollection_);
200 }
edm::ESGetToken< EcalNextToDeadChannel, EcalNextToDeadChannelRcd > nextToDeadToken_
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
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
producer
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
edm::EDGetTokenT< EcalRecHitCollection > recHitsToken_
InterestingDetIdCollectionProducer(const edm::ParameterSet &)
ctor
edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > sevLVToken_
#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
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
iterator find(key_type k)
HLT enums.
edm::EDGetTokenT< reco::BasicClusterCollection > basicClustersToken_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_