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  const 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  const 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 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T const * product() const
Definition: Handle.h:70
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
std::string selectedEcalEEDigiCollection_
int size() const
Definition: EcalDataFrame.h:26
double getMaximum(TObjArray *array)
edm::EDGetTokenT< reco::SuperClusterCollection > barrelSuperClusterProducer_
std::string selectedEcalEBDigiCollection_
T const * product() const
Definition: ESHandle.h:86
EcalDigiSelector(const edm::ParameterSet &ps)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
edm::EDGetTokenT< EEDigiCollection > EcalEEDigiToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
const_iterator end() const
double energy() const
cluster energy
Definition: CaloCluster.h:148
Definition: DetId.h:17
const_iterator begin() const
The iterator returned can not safely be used across threads.
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:79
fixed size matrix
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:180
edm::EDGetTokenT< EBDigiCollection > EcalEBDigiToken_
edm::EDGetTokenT< EcalRecHitCollection > EcalEERecHitToken_
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::SuperClusterCollection > endcapSuperClusterProducer_
uint16_t raw() const
get the raw word
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
edm::EDGetTokenT< EcalRecHitCollection > EcalEBRecHitToken_
def move(src, dest)
Definition: eostools.py:511