CMS 3D CMS Logo

InterestingDetIdFromSuperClusterProducer.cc
Go to the documentation of this file.
2 
6 
9 
12 
16 
20 
22  recHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsLabel"));
24  consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("superClustersLabel"));
25 
26  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
27 
28  minimalEtaSize_ = iConfig.getParameter<int>("etaSize");
29  minimalPhiSize_ = iConfig.getParameter<int>("phiSize");
30  if (minimalPhiSize_ % 2 == 0 || minimalEtaSize_ % 2 == 0)
31  edm::LogError("InterestingDetIdFromSuperClusterProducerError") << "Size of eta/phi should be odd numbers";
32 
33  //register your products
34  produces<DetIdCollection>(interestingDetIdCollection_);
35 
36  severityLevel_ = iConfig.getParameter<int>("severityLevel");
37  keepNextToDead_ = iConfig.getParameter<bool>("keepNextToDead");
38  keepNextToBoundary_ = iConfig.getParameter<bool>("keepNextToBoundary");
39 }
40 
42  edm::ESHandle<CaloTopology> theCaloTopology;
43  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
44  caloTopology_ = &(*theCaloTopology);
45 
47  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
48  severity_ = sevLv.product();
49 }
50 
51 // ------------ method called to produce the data ------------
53  using namespace edm;
54  using namespace std;
55 
56  // take BasicClusters
58  iEvent.getByToken(superClustersToken_, pClusters);
59 
60  // take EcalRecHits
61  Handle<EcalRecHitCollection> recHitsHandle;
62  iEvent.getByToken(recHitsToken_, recHitsHandle);
63 
64  //Create empty output collections
65  std::vector<DetId> indexToStore;
66  indexToStore.reserve(1000);
67 
68  reco::SuperClusterCollection::const_iterator sclusIt;
69 
70  std::vector<DetId> xtalsToStore;
71  xtalsToStore.reserve(50);
72 
73  //loop over superclusters
74  for (sclusIt = pClusters->begin(); sclusIt != pClusters->end(); sclusIt++) {
75  //loop over subclusters
76  for (reco::CaloCluster_iterator clusIt = sclusIt->clustersBegin(); clusIt != sclusIt->clustersEnd(); ++clusIt) {
77  //PG barrel
78 
79  float eMax = 0.;
80  DetId eMaxId(0);
81 
82  std::vector<std::pair<DetId, float> > clusterDetIds = (*clusIt)->hitsAndFractions();
83  std::vector<std::pair<DetId, float> >::iterator posCurrent;
84 
85  EcalRecHit testEcalRecHit;
86 
87  for (posCurrent = clusterDetIds.begin(); posCurrent != clusterDetIds.end(); posCurrent++) {
88  EcalRecHitCollection::const_iterator itt = recHitsHandle->find((*posCurrent).first);
89  if ((!((*posCurrent).first.null())) && (itt != recHitsHandle->end()) && ((*itt).energy() > eMax)) {
90  eMax = (*itt).energy();
91  eMaxId = (*itt).id();
92  }
93  }
94 
95  if (eMaxId.null())
96  continue;
97 
99 
100  xtalsToStore = topology->getWindow(eMaxId, minimalEtaSize_, minimalPhiSize_);
101  std::vector<std::pair<DetId, float> > xtalsInClus = (*clusIt)->hitsAndFractions();
102 
103  for (unsigned int ii = 0; ii < xtalsInClus.size(); ii++) {
104  xtalsToStore.push_back(xtalsInClus[ii].first);
105  }
106 
107  indexToStore.insert(indexToStore.end(), xtalsToStore.begin(), xtalsToStore.end());
108  }
109  }
110 
111  for (EcalRecHitCollection::const_iterator it = recHitsHandle->begin(); it != recHitsHandle->end(); ++it) {
112  // also add recHits of dead TT if the corresponding TP is saturated
113  if (it->checkFlag(EcalRecHit::kTPSaturated)) {
114  indexToStore.push_back(it->id());
115  }
116  // add hits for severities above a threshold
117  if (severityLevel_ >= 0 && severity_->severityLevel(*it) >= severityLevel_) {
118  indexToStore.push_back(it->id());
119  }
120  if (keepNextToDead_) {
121  // also keep channels next to dead ones
122  if (EcalTools::isNextToDead(it->id(), iSetup)) {
123  indexToStore.push_back(it->id());
124  }
125  }
126 
127  if (keepNextToBoundary_) {
128  // keep channels around EB/EE boundary
129  if (it->id().subdetId() == EcalBarrel) {
130  EBDetId ebid(it->id());
131  if (abs(ebid.ieta()) == 85)
132  indexToStore.push_back(it->id());
133  } else {
134  if (EEDetId::isNextToRingBoundary(it->id()))
135  indexToStore.push_back(it->id());
136  }
137  }
138  }
139 
140  //unify the vector
141  std::sort(indexToStore.begin(), indexToStore.end());
142  std::unique(indexToStore.begin(), indexToStore.end());
143 
144  auto detIdCollection = std::make_unique<DetIdCollection>(indexToStore);
145 
146  iEvent.put(std::move(detIdCollection), interestingDetIdCollection_);
147 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void beginRun(edm::Run const &, const edm::EventSetup &) final
static bool isNextToDead(const DetId &id, const edm::EventSetup &es)
true if the channel is near a dead one (in the 3x3)
Definition: EcalTools.cc:56
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
std::vector< EcalRecHit >::const_iterator const_iterator
int iEvent
Definition: GenABIO.cc:224
def unique(seq, keepstr=True)
Definition: tier0.py:24
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static bool isNextToRingBoundary(EEDetId id)
Definition: EEDetId.cc:284
void produce(edm::Event &, const edm::EventSetup &) override
producer
ii
Definition: cuy.py:590
const_iterator end() const
Definition: DetId.h:17
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
edm::EDGetTokenT< reco::SuperClusterCollection > superClustersToken_
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:17
iterator find(key_type k)
HLT enums.
T get() const
Definition: EventSetup.h:73
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
Definition: Run.h:45
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46