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:
54  void beginRun(edm::Run const&, const edm::EventSetup&) final;
56  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58 private:
59  // ----------member data ---------------------------
65 
70 
75 };
76 
79 
81  recHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsLabel"));
83  consumes<reco::BasicClusterCollection>(iConfig.getParameter<edm::InputTag>("basicClustersLabel"));
84  caloTopologyToken_ = esConsumes<CaloTopology, CaloTopologyRecord, edm::Transition::BeginRun>();
85  sevLVToken_ = esConsumes<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd, edm::Transition::BeginRun>();
86  nextToDeadToken_ = esConsumes<EcalNextToDeadChannel, EcalNextToDeadChannelRcd>();
87 
88  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
89 
90  minimalEtaSize_ = iConfig.getParameter<int>("etaSize");
91  minimalPhiSize_ = iConfig.getParameter<int>("phiSize");
92  if (minimalPhiSize_ % 2 == 0 || minimalEtaSize_ % 2 == 0)
93  edm::LogError("InterestingDetIdCollectionProducerError") << "Size of eta/phi should be odd numbers";
94 
95  //register your products
96  produces<DetIdCollection>(interestingDetIdCollection_);
97 
98  severityLevel_ = iConfig.getParameter<int>("severityLevel");
99  keepNextToDead_ = iConfig.getParameter<bool>("keepNextToDead");
100  keepNextToBoundary_ = iConfig.getParameter<bool>("keepNextToBoundary");
101 }
102 
104  edm::ESHandle<CaloTopology> theCaloTopology = iSetup.getHandle(caloTopologyToken_);
105  caloTopology_ = &(*theCaloTopology);
106 
108  severity_ = sevLv.product();
109 }
110 
111 // ------------ method called to produce the data ------------
113  using namespace edm;
114  using namespace std;
115 
116  // take BasicClusters
118  iEvent.getByToken(basicClustersToken_, pClusters);
119 
120  // take EcalRecHits
121  Handle<EcalRecHitCollection> recHitsHandle;
122  iEvent.getByToken(recHitsToken_, recHitsHandle);
123 
124  //Create empty output collections
125  std::vector<DetId> indexToStore;
126  indexToStore.reserve(1000);
127 
128  reco::BasicClusterCollection::const_iterator clusIt;
129 
130  std::vector<DetId> xtalsToStore;
131  xtalsToStore.reserve(50);
132  for (clusIt = pClusters->begin(); clusIt != pClusters->end(); clusIt++) {
133  const std::vector<std::pair<DetId, float> >& clusterDetIds = clusIt->hitsAndFractions();
134  for (const auto& detidpair : clusterDetIds) {
135  indexToStore.push_back(detidpair.first);
136  }
137 
138  //below checks and additional code are only relevant for EB/EE, not for ES
139  if (clusterDetIds.front().first.subdetId() == EcalBarrel || clusterDetIds.front().first.subdetId() == EcalEndcap) {
140  std::vector<std::pair<DetId, float> >::const_iterator posCurrent;
141 
142  float eMax = 0.;
143  DetId eMaxId(0);
144 
145  EcalRecHit testEcalRecHit;
146 
147  for (posCurrent = clusterDetIds.begin(); posCurrent != clusterDetIds.end(); posCurrent++) {
148  EcalRecHitCollection::const_iterator itt = recHitsHandle->find((*posCurrent).first);
149  if ((!((*posCurrent).first.null())) && (itt != recHitsHandle->end()) && ((*itt).energy() > eMax)) {
150  eMax = (*itt).energy();
151  eMaxId = (*itt).id();
152  }
153  }
154 
155  if (eMaxId.null())
156  continue;
157 
158  const CaloSubdetectorTopology* topology = caloTopology_->getSubdetectorTopology(eMaxId.det(), eMaxId.subdetId());
159 
160  xtalsToStore = topology->getWindow(eMaxId, minimalEtaSize_, minimalPhiSize_);
161 
162  for (const auto& detid : xtalsToStore) {
163  indexToStore.push_back(detid);
164  }
165  }
166  }
167 
169  for (EcalRecHitCollection::const_iterator it = recHitsHandle->begin(); it != recHitsHandle->end(); ++it) {
170  // also add recHits of dead TT if the corresponding TP is saturated
171  if (it->checkFlag(EcalRecHit::kTPSaturated)) {
172  indexToStore.push_back(it->id());
173  }
174  // add hits for severities above a threshold
175  if (severityLevel_ >= 0 && severity_->severityLevel(*it) >= severityLevel_) {
176  indexToStore.push_back(it->id());
177  }
178  if (keepNextToDead_) {
180  // also keep channels next to dead ones
181  if (EcalTools::isNextToDead(it->id(), *dch)) {
182  indexToStore.push_back(it->id());
183  }
184  }
185 
186  if (keepNextToBoundary_) {
187  // keep channels around EB/EE boundary
188  if (it->id().subdetId() == EcalBarrel) {
189  EBDetId ebid(it->id());
190  if (abs(ebid.ieta()) == 85)
191  indexToStore.push_back(it->id());
192  } else {
193  if (EEDetId::isNextToRingBoundary(it->id()))
194  indexToStore.push_back(it->id());
195  }
196  }
197  }
198  }
199 
200  //unify the vector
201  std::sort(indexToStore.begin(), indexToStore.end());
202  std::unique(indexToStore.begin(), indexToStore.end());
203 
204  iEvent.put(std::make_unique<DetIdCollection>(indexToStore), interestingDetIdCollection_);
205 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalSeverityLevelAlgo
Definition: EcalSeverityLevelAlgo.h:33
EcalRecHit
Definition: EcalRecHit.h:15
EcalRecHit::kTPSaturated
Definition: EcalRecHit.h:33
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
EcalSeverityLevelAlgo::severityLevel
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
Definition: EcalSeverityLevelAlgo.cc:85
ESHandle.h
InterestingDetIdCollectionProducer::caloTopology_
const CaloTopology * caloTopology_
Definition: InterestingDetIdCollectionProducer.cc:69
InterestingDetIdCollectionProducer
Definition: InterestingDetIdCollectionProducer.cc:50
EcalSeverityLevelAlgoRcd.h
edm::Run
Definition: Run.h:45
BasicCluster.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
EBDetId.h
EEDetId.h
EDProducer.h
InterestingDetIdCollectionProducer::beginRun
void beginRun(edm::Run const &, const edm::EventSetup &) final
Definition: InterestingDetIdCollectionProducer.cc:103
DetId::null
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
InterestingDetIdCollectionProducer::severityLevel_
int severityLevel_
Definition: InterestingDetIdCollectionProducer.cc:71
InterestingDetIdCollectionProducer::recHitsToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitsToken_
Definition: InterestingDetIdCollectionProducer.cc:60
edm::Handle
Definition: AssociativeIterator.h:50
InterestingDetIdCollectionProducer::sevLVToken_
edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > sevLVToken_
Definition: InterestingDetIdCollectionProducer.cc:63
ESGetToken.h
CaloTopology
Definition: CaloTopology.h:19
InterestingDetIdCollectionProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
producer
Definition: InterestingDetIdCollectionProducer.cc:112
EcalBarrel
Definition: EcalSubdetector.h:10
EcalRecHitCollections.h
BasicClusterFwd.h
DetId
Definition: DetId.h:17
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EcalTools::isNextToDead
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
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
edm::ESHandle< CaloTopology >
EcalSeverityLevelAlgo.h
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EcalEndcap
Definition: EcalSubdetector.h:10
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
EEDetId::isNextToRingBoundary
static bool isNextToRingBoundary(EEDetId id)
Definition: EEDetId.cc:284
cosmicPhotonAnalyzer_cfi.eMax
eMax
Definition: cosmicPhotonAnalyzer_cfi.py:10
InterestingDetIdCollectionProducer::keepNextToBoundary_
bool keepNextToBoundary_
Definition: InterestingDetIdCollectionProducer.cc:74
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
CaloTopology::getSubdetectorTopology
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:17
EcalNextToDeadChannelRcd.h
InterestingDetIdCollectionProducer::interestingDetIdCollection_
std::string interestingDetIdCollection_
Definition: InterestingDetIdCollectionProducer.cc:66
iEvent
int iEvent
Definition: GenABIO.cc:224
InterestingDetIdCollectionProducer::caloTopologyToken_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
Definition: InterestingDetIdCollectionProducer.cc:62
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
InterestingDetIdCollectionProducer::basicClustersToken_
edm::EDGetTokenT< reco::BasicClusterCollection > basicClustersToken_
Definition: InterestingDetIdCollectionProducer.cc:61
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
CaloSubdetectorTopology
Definition: CaloSubdetectorTopology.h:17
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
EcalTools.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< CaloTopology, CaloTopologyRecord >
InputTag.h
CaloTopology.h
CaloSubdetectorTopology::getWindow
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
Definition: CaloSubdetectorTopology.cc:4
CaloSubdetectorTopology.h
CaloTopologyRecord.h
InterestingDetIdCollectionProducer::nextToDeadToken_
edm::ESGetToken< EcalNextToDeadChannel, EcalNextToDeadChannelRcd > nextToDeadToken_
Definition: InterestingDetIdCollectionProducer.cc:64
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
Frameworkfwd.h
InterestingDetIdCollectionProducer::InterestingDetIdCollectionProducer
InterestingDetIdCollectionProducer(const edm::ParameterSet &)
ctor
Definition: InterestingDetIdCollectionProducer.cc:80
InterestingDetIdCollectionProducer::minimalPhiSize_
int minimalPhiSize_
Definition: InterestingDetIdCollectionProducer.cc:68
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
InterestingDetIdCollectionProducer::minimalEtaSize_
int minimalEtaSize_
Definition: InterestingDetIdCollectionProducer.cc:67
InterestingDetIdCollectionProducer::keepNextToDead_
bool keepNextToDead_
Definition: InterestingDetIdCollectionProducer.cc:73
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
DetIdCollection.h
InterestingDetIdCollectionProducer::severity_
const EcalSeverityLevelAlgo * severity_
Definition: InterestingDetIdCollectionProducer.cc:72