CMS 3D CMS Logo

EcalDigiSelector.cc
Go to the documentation of this file.
22 
23 #include <TMath.h>
24 
25 #include <iostream>
26 #include <map>
27 #include <memory>
28 #include <set>
29 #include <string>
30 #include <vector>
31 
33 public:
35 
36  void produce(edm::Event&, const edm::EventSetup&) override;
37 
38 private:
41 
44 
45  // input configuration
51 
55 };
56 
59 
60 using namespace reco;
62  selectedEcalEBDigiCollection_ = ps.getParameter<std::string>("selectedEcalEBDigiCollection");
63  selectedEcalEEDigiCollection_ = ps.getParameter<std::string>("selectedEcalEEDigiCollection");
64 
65  barrelSuperClusterProducer_ =
66  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("barrelSuperClusterProducer"));
67  endcapSuperClusterProducer_ =
68  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSuperClusterProducer"));
69 
70  EcalEBRecHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalEBRecHitTag"));
71  EcalEERecHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalEERecHitTag"));
72 
73  EcalEBDigiToken_ = consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EcalEBDigiTag"));
74  EcalEEDigiToken_ = consumes<EEDigiCollection>(ps.getParameter<edm::InputTag>("EcalEEDigiTag"));
75 
76  caloTopologyToken_ = esConsumes<CaloTopology, CaloTopologyRecord>();
77 
78  cluster_pt_thresh_ = ps.getParameter<double>("cluster_pt_thresh");
79  single_cluster_thresh_ = ps.getParameter<double>("single_cluster_thresh");
80 
81  nclus_sel_ = ps.getParameter<int>("nclus_sel");
82  produces<EBDigiCollection>(selectedEcalEBDigiCollection_);
83  produces<EEDigiCollection>(selectedEcalEEDigiCollection_);
84 }
85 
87  //Get BarrelSuperClusters to start.
88  edm::Handle<reco::SuperClusterCollection> pBarrelSuperClusters;
89 
90  evt.getByToken(barrelSuperClusterProducer_, pBarrelSuperClusters);
91 
92  const reco::SuperClusterCollection& BarrelSuperClusters = *pBarrelSuperClusters;
93  //Got BarrelSuperClusters
94 
95  //Get BarrelSuperClusters to start.
96  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
97 
98  evt.getByToken(endcapSuperClusterProducer_, pEndcapSuperClusters);
99 
100  const reco::SuperClusterCollection& EndcapSuperClusters = *pEndcapSuperClusters;
101  //Got EndcapSuperClusters
102 
103  reco::SuperClusterCollection saveBarrelSuperClusters;
104  reco::SuperClusterCollection saveEndcapSuperClusters;
105  bool meet_single_thresh = false;
106  //Loop over barrel superclusters, and apply threshold
107  for (int loop = 0; loop < int(BarrelSuperClusters.size()); loop++) {
108  SuperCluster clus1 = BarrelSuperClusters[loop];
109  float eta1 = clus1.eta();
110  float energy1 = clus1.energy();
111  float theta1 = 2 * atan(exp(-1. * eta1));
112  float cluspt1 = energy1 * sin(theta1);
113  if (cluspt1 > cluster_pt_thresh_) {
114  saveBarrelSuperClusters.push_back(clus1);
115  if (cluspt1 > single_cluster_thresh_)
116  meet_single_thresh = true;
117  }
118  }
119 
120  //Loop over endcap superclusters, and apply threshold
121  for (int loop = 0; loop < int(EndcapSuperClusters.size()); loop++) {
122  SuperCluster clus1 = EndcapSuperClusters[loop];
123  float eta1 = clus1.eta();
124  float energy1 = clus1.energy();
125  float theta1 = 2 * atan(exp(-1. * eta1));
126  float cluspt1 = energy1 * sin(theta1);
127  if (cluspt1 > cluster_pt_thresh_) {
128  saveEndcapSuperClusters.push_back(clus1);
129  if (cluspt1 > single_cluster_thresh_)
130  meet_single_thresh = true;
131  }
132  }
133 
134  auto SEBDigiCol = std::make_unique<EBDigiCollection>();
135  auto SEEDigiCol = std::make_unique<EEDigiCollection>();
136  int TotClus = saveBarrelSuperClusters.size() + saveEndcapSuperClusters.size();
137 
138  if (TotClus >= nclus_sel_ || meet_single_thresh) {
139  if (!saveBarrelSuperClusters.empty()) {
140  edm::ESHandle<CaloTopology> pTopology = es.getHandle(caloTopologyToken_);
141  const CaloTopology* topology = pTopology.product();
142 
143  //get barrel digi collection
145  const EBDigiCollection* digis = nullptr;
146  evt.getByToken(EcalEBDigiToken_, pdigis);
147  digis = pdigis.product(); // get a ptr to the product
148 
150  const EcalRecHitCollection* rechits = nullptr;
151  evt.getByToken(EcalEBRecHitToken_, prechits);
152  rechits = prechits.product(); // get a ptr to the product
153 
154  if (digis) {
155  std::vector<DetId> saveTheseDetIds;
156  //pick out the detids for the 3x3 in each of the selected superclusters
157  for (int loop = 0; loop < int(saveBarrelSuperClusters.size()); loop++) {
158  SuperCluster clus1 = saveBarrelSuperClusters[loop];
159  const CaloClusterPtr& bcref = clus1.seed();
160  const BasicCluster* bc = bcref.get();
161  //Get the maximum detid
162  DetId maxDetId = EcalClusterTools::getMaximum(*bc, rechits).first;
163  // Loop over the 3x3 array centered on maximum detid
164  for (DetId detId : CaloRectangleRange(1, maxDetId, *topology))
165  saveTheseDetIds.push_back(detId);
166  }
167  for (int detloop = 0; detloop < int(saveTheseDetIds.size()); ++detloop) {
168  EBDetId detL = EBDetId(saveTheseDetIds[detloop]);
169 
170  for (EBDigiCollection::const_iterator blah = digis->begin(); blah != digis->end(); blah++) {
171  if (detL == blah->id()) {
172  EBDataFrame myDigi = (*blah);
173  SEBDigiCol->push_back(detL);
174 
175  EBDataFrame df(SEBDigiCol->back());
176  for (int iq = 0; iq < myDigi.size(); ++iq) {
177  df.setSample(iq, myDigi.sample(iq).raw());
178  }
179  //ebcounter++;
180  }
181  }
182  //if (ebcounter >= int(saveTheseDetIds.size())) break;
183  } //loop over dets
184  }
185 
186  } //If barrel superclusters need saving.
187 
188  if (!saveEndcapSuperClusters.empty()) {
189  edm::ESHandle<CaloTopology> pTopology = es.getHandle(caloTopologyToken_);
190  const CaloTopology* topology = pTopology.product();
191 
192  //Get endcap rec hit collection
193  //get endcap digi collection
195  const EEDigiCollection* digis = nullptr;
196  evt.getByToken(EcalEEDigiToken_, pdigis);
197  digis = pdigis.product(); // get a ptr to the product
198 
200  const EcalRecHitCollection* rechits = nullptr;
201  evt.getByToken(EcalEERecHitToken_, prechits);
202  rechits = prechits.product(); // get a ptr to the product
203 
204  if (digis) {
205  //std::vector<DetId> saveTheseDetIds;
206  std::set<DetId> saveTheseDetIds;
207  //pick out the digis for the 3x3 in each of the selected superclusters
208  for (int loop = 0; loop < int(saveEndcapSuperClusters.size()); loop++) {
209  SuperCluster clus1 = saveEndcapSuperClusters[loop];
210  const CaloClusterPtr& bcref = clus1.seed();
211  const BasicCluster* bc = bcref.get();
212  //Get the maximum detid
213  DetId maxDetId = EcalClusterTools::getMaximum(*bc, rechits).first;
214  // Loop over the 3x3 array centered on maximum detid
215  for (DetId detId : CaloRectangleRange(1, maxDetId, *topology))
216  saveTheseDetIds.insert(detId);
217  }
218  int eecounter = 0;
219  for (EEDigiCollection::const_iterator blah = digis->begin(); blah != digis->end(); blah++) {
220  std::set<DetId>::const_iterator finder = saveTheseDetIds.find(blah->id());
221  if (finder != saveTheseDetIds.end()) {
222  EEDetId detL = EEDetId(*finder);
223 
224  if (detL == blah->id()) {
225  EEDataFrame myDigi = (*blah);
226  SEEDigiCol->push_back(detL);
227  EEDataFrame df(SEEDigiCol->back());
228  for (int iq = 0; iq < myDigi.size(); ++iq) {
229  df.setSample(iq, myDigi.sample(iq).raw());
230  }
231  eecounter++;
232  }
233  }
234  if (eecounter >= int(saveTheseDetIds.size()))
235  break;
236  } //loop over digis
237  }
238  } //If endcap superclusters need saving.
239 
240  } //If we're actually saving stuff
241 
242  //Okay, either my collections have been filled with the requisite Digis, or they haven't.
243 
244  //Empty collection, or full, still put in event.
245  SEBDigiCol->sort();
246  SEEDigiCol->sort();
247  evt.put(std::move(SEBDigiCol), selectedEcalEBDigiCollection_);
248  evt.put(std::move(SEEDigiCol), selectedEcalEEDigiCollection_);
249 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalDataFrame::sample
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
EcalDigiSelector::selectedEcalEBDigiCollection_
std::string selectedEcalEBDigiCollection_
Definition: EcalDigiSelector.cc:39
MessageLogger.h
CaloRectangleRange
Definition: CaloRectangle.h:36
EcalDigiSelector
Definition: EcalDigiSelector.cc:32
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EcalDigiSelector::EcalDigiSelector
EcalDigiSelector(const edm::ParameterSet &ps)
Definition: EcalDigiSelector.cc:61
ESHandle.h
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
HLT_FULL_cff.finder
finder
Definition: HLT_FULL_cff.py:51974
reco::SuperCluster
Definition: SuperCluster.h:18
BasicCluster.h
edm::EDGetTokenT< reco::SuperClusterCollection >
EBDetId
Definition: EBDetId.h:17
EBDataFrame
Definition: EBDataFrame.h:11
EcalDigiSelector::cluster_pt_thresh_
double cluster_pt_thresh_
Definition: EcalDigiSelector.cc:52
EBDetId.h
EEDetId.h
EcalDigiSelector::EcalEEDigiToken_
edm::EDGetTokenT< EEDigiCollection > EcalEEDigiToken_
Definition: EcalDigiSelector.cc:49
EDProducer.h
edm::SortedCollection< EcalRecHit >
EcalDigiSelector::EcalEERecHitToken_
edm::EDGetTokenT< EcalRecHitCollection > EcalEERecHitToken_
Definition: EcalDigiSelector.cc:47
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
CaloTopology
Definition: CaloTopology.h:19
EcalDataFrame.h
EcalRecHitCollections.h
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
DetId
Definition: DetId.h:17
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EcalDigiSelector::EcalEBRecHitToken_
edm::EDGetTokenT< EcalRecHitCollection > EcalEBRecHitToken_
Definition: EcalDigiSelector.cc:46
reco::CaloCluster
Definition: CaloCluster.h:31
EcalDigiCollections.h
edm::ESHandle< CaloTopology >
EcalDigiSelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: EcalDigiSelector.cc:86
EcalDigiSelector::endcapSuperClusterProducer_
edm::EDGetTokenT< reco::SuperClusterCollection > endcapSuperClusterProducer_
Definition: EcalDigiSelector.cc:43
HI_PhotonSkim_cff.rechits
rechits
Definition: HI_PhotonSkim_cff.py:76
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
EcalMGPASample::raw
uint16_t raw() const
get the raw word
Definition: EcalMGPASample.h:29
EcalDigiSelector::caloTopologyToken_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
Definition: EcalDigiSelector.cc:50
EEDetId
Definition: EEDetId.h:14
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9550
EcalDigiSelector::EcalEBDigiToken_
edm::EDGetTokenT< EBDigiCollection > EcalEBDigiToken_
Definition: EcalDigiSelector.cc:48
edm::ParameterSet
Definition: ParameterSet.h:47
reco::SuperCluster::seed
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
reco::CaloCluster::eta
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
Event.h
EBDigiCollection
Definition: EcalDigiCollections.h:56
EcalClusterTools.h
EEDigiCollection
Definition: EcalDigiCollections.h:69
heppy_loop.loop
loop
Definition: heppy_loop.py:28
createfilelist.int
int
Definition: createfilelist.py:10
EcalDigiSelector::single_cluster_thresh_
double single_cluster_thresh_
Definition: EcalDigiSelector.cc:53
edm::DataFrameContainer::begin
const_iterator begin() const
The iterator returned can not safely be used across threads.
Definition: DataFrameContainer.h:149
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::stream::EDProducer
Definition: EDProducer.h:36
EBDataFrame.h
edm::EventSetup
Definition: EventSetup.h:58
edm::ESGetToken< CaloTopology, CaloTopologyRecord >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Ptr< CaloCluster >
CaloTopology.h
EEDataFrame.h
EcalDigiSelector::barrelSuperClusterProducer_
edm::EDGetTokenT< reco::SuperClusterCollection > barrelSuperClusterProducer_
Definition: EcalDigiSelector.cc:42
CaloTopologyRecord.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
SuperClusterFwd.h
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:733
DetId.h
SuperCluster.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EcalDataFrame::size
int size() const
Definition: EcalDataFrame.h:26
ParameterSet.h
EcalDigiSelector::selectedEcalEEDigiCollection_
std::string selectedEcalEEDigiCollection_
Definition: EcalDigiSelector.cc:40
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
EEDataFrame
Definition: EEDataFrame.h:12
edm::Event
Definition: Event.h:73
reco::CaloCluster::energy
double energy() const
cluster energy
Definition: CaloCluster.h:149
edm::DataFrameContainer::end
const_iterator end() const
Definition: DataFrameContainer.h:152
edm::InputTag
Definition: InputTag.h:15
EcalDigiSelector::nclus_sel_
int nclus_sel_
Definition: EcalDigiSelector.cc:54