CMS 3D CMS Logo

EcalDigiSelector.cc
Go to the documentation of this file.
1 #include <vector>
15 #include <TMath.h>
16 #include <iostream>
17 #include <set>
18 
19 using namespace reco;
21  selectedEcalEBDigiCollection_ = ps.getParameter<std::string>("selectedEcalEBDigiCollection");
22  selectedEcalEEDigiCollection_ = ps.getParameter<std::string>("selectedEcalEEDigiCollection");
23 
24  barrelSuperClusterProducer_ =
25  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("barrelSuperClusterProducer"));
26  endcapSuperClusterProducer_ =
27  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSuperClusterProducer"));
28 
29  EcalEBRecHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalEBRecHitTag"));
30  EcalEERecHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalEERecHitTag"));
31 
32  EcalEBDigiToken_ = consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EcalEBDigiTag"));
33  EcalEEDigiToken_ = consumes<EEDigiCollection>(ps.getParameter<edm::InputTag>("EcalEEDigiTag"));
34 
35  caloTopologyToken_ = esConsumes<CaloTopology, CaloTopologyRecord>();
36 
37  cluster_pt_thresh_ = ps.getParameter<double>("cluster_pt_thresh");
38  single_cluster_thresh_ = ps.getParameter<double>("single_cluster_thresh");
39 
40  nclus_sel_ = ps.getParameter<int>("nclus_sel");
41  produces<EBDigiCollection>(selectedEcalEBDigiCollection_);
42  produces<EEDigiCollection>(selectedEcalEEDigiCollection_);
43 }
44 
46  //Get BarrelSuperClusters to start.
47  edm::Handle<reco::SuperClusterCollection> pBarrelSuperClusters;
48 
49  evt.getByToken(barrelSuperClusterProducer_, pBarrelSuperClusters);
50 
51  const reco::SuperClusterCollection& BarrelSuperClusters = *pBarrelSuperClusters;
52  //Got BarrelSuperClusters
53 
54  //Get BarrelSuperClusters to start.
55  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
56 
57  evt.getByToken(endcapSuperClusterProducer_, pEndcapSuperClusters);
58 
59  const reco::SuperClusterCollection& EndcapSuperClusters = *pEndcapSuperClusters;
60  //Got EndcapSuperClusters
61 
62  reco::SuperClusterCollection saveBarrelSuperClusters;
63  reco::SuperClusterCollection saveEndcapSuperClusters;
64  bool meet_single_thresh = false;
65  //Loop over barrel superclusters, and apply threshold
66  for (int loop = 0; loop < int(BarrelSuperClusters.size()); loop++) {
67  SuperCluster clus1 = BarrelSuperClusters[loop];
68  float eta1 = clus1.eta();
69  float energy1 = clus1.energy();
70  float theta1 = 2 * atan(exp(-1. * eta1));
71  float cluspt1 = energy1 * sin(theta1);
72  if (cluspt1 > cluster_pt_thresh_) {
73  saveBarrelSuperClusters.push_back(clus1);
74  if (cluspt1 > single_cluster_thresh_)
75  meet_single_thresh = true;
76  }
77  }
78 
79  //Loop over endcap superclusters, and apply threshold
80  for (int loop = 0; loop < int(EndcapSuperClusters.size()); loop++) {
81  SuperCluster clus1 = EndcapSuperClusters[loop];
82  float eta1 = clus1.eta();
83  float energy1 = clus1.energy();
84  float theta1 = 2 * atan(exp(-1. * eta1));
85  float cluspt1 = energy1 * sin(theta1);
86  if (cluspt1 > cluster_pt_thresh_) {
87  saveEndcapSuperClusters.push_back(clus1);
88  if (cluspt1 > single_cluster_thresh_)
89  meet_single_thresh = true;
90  }
91  }
92 
93  auto SEBDigiCol = std::make_unique<EBDigiCollection>();
94  auto SEEDigiCol = std::make_unique<EEDigiCollection>();
95  int TotClus = saveBarrelSuperClusters.size() + saveEndcapSuperClusters.size();
96 
97  if (TotClus >= nclus_sel_ || meet_single_thresh) {
98  if (!saveBarrelSuperClusters.empty()) {
99  edm::ESHandle<CaloTopology> pTopology = es.getHandle(caloTopologyToken_);
100  const CaloTopology* topology = pTopology.product();
101 
102  //get barrel digi collection
104  const EBDigiCollection* digis = nullptr;
105  evt.getByToken(EcalEBDigiToken_, pdigis);
106  digis = pdigis.product(); // get a ptr to the product
107 
109  const EcalRecHitCollection* rechits = nullptr;
110  evt.getByToken(EcalEBRecHitToken_, prechits);
111  rechits = prechits.product(); // get a ptr to the product
112 
113  if (digis) {
114  std::vector<DetId> saveTheseDetIds;
115  //pick out the detids for the 3x3 in each of the selected superclusters
116  for (int loop = 0; loop < int(saveBarrelSuperClusters.size()); loop++) {
117  SuperCluster clus1 = saveBarrelSuperClusters[loop];
118  const CaloClusterPtr& bcref = clus1.seed();
119  const BasicCluster* bc = bcref.get();
120  //Get the maximum detid
121  DetId maxDetId = EcalClusterTools::getMaximum(*bc, rechits).first;
122  // Loop over the 3x3 array centered on maximum detid
123  for (DetId detId : CaloRectangleRange(1, maxDetId, *topology))
124  saveTheseDetIds.push_back(detId);
125  }
126  for (int detloop = 0; detloop < int(saveTheseDetIds.size()); ++detloop) {
127  EBDetId detL = EBDetId(saveTheseDetIds[detloop]);
128 
129  for (EBDigiCollection::const_iterator blah = digis->begin(); blah != digis->end(); blah++) {
130  if (detL == blah->id()) {
131  EBDataFrame myDigi = (*blah);
132  SEBDigiCol->push_back(detL);
133 
134  EBDataFrame df(SEBDigiCol->back());
135  for (int iq = 0; iq < myDigi.size(); ++iq) {
136  df.setSample(iq, myDigi.sample(iq).raw());
137  }
138  //ebcounter++;
139  }
140  }
141  //if (ebcounter >= int(saveTheseDetIds.size())) break;
142  } //loop over dets
143  }
144 
145  } //If barrel superclusters need saving.
146 
147  if (!saveEndcapSuperClusters.empty()) {
148  edm::ESHandle<CaloTopology> pTopology = es.getHandle(caloTopologyToken_);
149  const CaloTopology* topology = pTopology.product();
150 
151  //Get endcap rec hit collection
152  //get endcap digi collection
154  const EEDigiCollection* digis = nullptr;
155  evt.getByToken(EcalEEDigiToken_, pdigis);
156  digis = pdigis.product(); // get a ptr to the product
157 
159  const EcalRecHitCollection* rechits = nullptr;
160  evt.getByToken(EcalEERecHitToken_, prechits);
161  rechits = prechits.product(); // get a ptr to the product
162 
163  if (digis) {
164  //std::vector<DetId> saveTheseDetIds;
165  std::set<DetId> saveTheseDetIds;
166  //pick out the digis for the 3x3 in each of the selected superclusters
167  for (int loop = 0; loop < int(saveEndcapSuperClusters.size()); loop++) {
168  SuperCluster clus1 = saveEndcapSuperClusters[loop];
169  const CaloClusterPtr& bcref = clus1.seed();
170  const BasicCluster* bc = bcref.get();
171  //Get the maximum detid
172  DetId maxDetId = EcalClusterTools::getMaximum(*bc, rechits).first;
173  // Loop over the 3x3 array centered on maximum detid
174  for (DetId detId : CaloRectangleRange(1, maxDetId, *topology))
175  saveTheseDetIds.insert(detId);
176  }
177  int eecounter = 0;
178  for (EEDigiCollection::const_iterator blah = digis->begin(); blah != digis->end(); blah++) {
179  std::set<DetId>::const_iterator finder = saveTheseDetIds.find(blah->id());
180  if (finder != saveTheseDetIds.end()) {
181  EEDetId detL = EEDetId(*finder);
182 
183  if (detL == blah->id()) {
184  EEDataFrame myDigi = (*blah);
185  SEEDigiCol->push_back(detL);
186  EEDataFrame df(SEEDigiCol->back());
187  for (int iq = 0; iq < myDigi.size(); ++iq) {
188  df.setSample(iq, myDigi.sample(iq).raw());
189  }
190  eecounter++;
191  }
192  }
193  if (eecounter >= int(saveTheseDetIds.size()))
194  break;
195  } //loop over digis
196  }
197  } //If endcap superclusters need saving.
198 
199  } //If we're actually saving stuff
200 
201  //Okay, either my collections have been filled with the requisite Digis, or they haven't.
202 
203  //Empty collection, or full, still put in event.
204  SEBDigiCol->sort();
205  SEEDigiCol->sort();
206  evt.put(std::move(SEBDigiCol), selectedEcalEBDigiCollection_);
207  evt.put(std::move(SEEDigiCol), selectedEcalEEDigiCollection_);
208 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalDataFrame::sample
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
MessageLogger.h
CaloRectangleRange
Definition: CaloRectangle.h:36
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EcalDigiSelector::EcalDigiSelector
EcalDigiSelector(const edm::ParameterSet &ps)
Definition: EcalDigiSelector.cc:20
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:51931
reco::SuperCluster
Definition: SuperCluster.h:18
BasicCluster.h
EBDetId
Definition: EBDetId.h:17
EBDataFrame
Definition: EBDataFrame.h:11
EBDetId.h
EEDetId.h
edm::SortedCollection< EcalRecHit >
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
CaloTopology
Definition: CaloTopology.h:19
EcalDataFrame.h
EcalDigiSelector.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
reco::CaloCluster
Definition: CaloCluster.h:31
edm::ESHandle< CaloTopology >
EcalDigiSelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: EcalDigiSelector.cc:45
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:535
EcalMGPASample::raw
uint16_t raw() const
get the raw word
Definition: EcalMGPASample.h:29
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
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
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
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
EBDataFrame.h
edm::EventSetup
Definition: EventSetup.h:58
edm::Ptr< CaloCluster >
EEDataFrame.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
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
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