CMS 3D CMS Logo

HLTRechitsToDigis.cc
Go to the documentation of this file.
1 //
2 // Package: HLTrigger/special
3 // Class: HLTRechitsToDigis
4 //
12 //
13 // Original Author: Joshua Robert Hardenbrook
14 // Created: Fri, 20 Feb 2015 15:51:36 GMT
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // user include files
26 
28 
34 
37 
38 // for srFlags management
41 
42 //
43 // class declaration
44 //
45 
47 public:
48  explicit HLTRechitsToDigis(const edm::ParameterSet&);
49  ~HLTRechitsToDigis() override;
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void produce(edm::Event&, edm::EventSetup const&) override;
56 
57  // ----------member data ---------------------------
58  // tokens for the digi and rechits for matching
62  // tokens for srFlags
65 
66  // input tags
69  // srFlags
71 
72  // string for the produced digi collection
75  // string for the produced srFlags collection
77 };
78 //
79 
80 //
81 // constructors and destructor
82 //
84  //region to do rechit digi matching
85  region_ = stringToRegion(iConfig.getParameter<std::string>("region"));
86 
87  // digis to match to hit collections
88  digisIn_ = iConfig.getParameter<edm::InputTag>("digisIn");
89  digisOut_ = iConfig.getParameter<std::string>("digisOut");
90 
91  // hit collections to save digis for
92  recHits_ = iConfig.getParameter<edm::InputTag>("recHits");
93 
94  // srFlags matched to digis to be saved
95  srFlagsIn_ = iConfig.getParameter<edm::InputTag>("srFlagsIn");
96  srFlagsOut_ = iConfig.getParameter<std::string>("srFlagsOut");
97 
98  // region specific tokens
99  switch (region_) {
100  case barrel:
101  digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
102  produces<EBDigiCollection>(digisOut_);
103  // protection against empty InputTag to allow for backward compatibility
104  if (not srFlagsIn_.label().empty()) {
105  srFlagsEBInToken_ = consumes<EBSrFlagCollection>(srFlagsIn_);
106  produces<EBSrFlagCollection>(srFlagsOut_);
107  }
108  break;
109  case endcap:
110  digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
111  produces<EEDigiCollection>(digisOut_);
112  // protection against empty InputTag to allow for backward compatibility
113  if (not srFlagsIn_.label().empty()) {
114  srFlagsEEInToken_ = consumes<EESrFlagCollection>(srFlagsIn_);
115  produces<EESrFlagCollection>(srFlagsOut_);
116  }
117  break;
118  case invalidRegion:
119  break;
120  }
121 
122  recHitsToken_ = consumes<EcalRecHitCollection>(recHits_);
123 }
124 
126  // do anything here that needs to be done at desctruction time
127  // (e.g. close files, deallocate resources etc.)
128 }
129 
130 //
131 // member functions
132 //
134  if (region == "barrel")
135  return barrel;
136  else if (region == "endcap")
137  return endcap;
138  else
139  return invalidRegion;
140 }
141 
142 // ------------ method called to produce the data ------------
144  using namespace edm;
145  // handles for digis
146  Handle<EBDigiCollection> digisEBHandle;
147  Handle<EEDigiCollection> digisEEHandle;
148 
149  // output collections
150  std::unique_ptr<EBDigiCollection> outputEBDigiCollection(new EBDigiCollection);
151  std::unique_ptr<EEDigiCollection> outputEEDigiCollection(new EEDigiCollection);
152 
153  // handles for srFlags
154  Handle<EBSrFlagCollection> srFlagsEBHandle;
155  Handle<EESrFlagCollection> srFlagsEEHandle;
156 
157  // output collections
158  std::unique_ptr<EBSrFlagCollection> outputEBSrFlagCollection(new EBSrFlagCollection);
159  std::unique_ptr<EESrFlagCollection> outputEESrFlagCollection(new EESrFlagCollection);
160  EcalReadoutTools ecalReadOutTool(iEvent, setup);
161 
162  // calibrated rechits
163  Handle<EcalRecHitCollection> recHitsHandle;
164  iEvent.getByToken(recHitsToken_, recHitsHandle);
165 
166  // match the digis based on the region
167  switch (region_) {
168  case barrel: {
169  iEvent.getByToken(digisEBInToken_, digisEBHandle);
170  const EBDigiCollection* digisEB = digisEBHandle.product();
171 
172  const EBSrFlagCollection* srFlagsEB = nullptr;
173  // protection against uninitialized token (empty InputTag) to allow for backward compatibility
174  if (not srFlagsEBInToken_.isUninitialized()) {
175  iEvent.getByToken(srFlagsEBInToken_, srFlagsEBHandle);
176  srFlagsEB = srFlagsEBHandle.product();
177  }
178 
179  // loop over the collection of rechits and match to digis
180  // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
182  for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
183  EcalRecHit const& hit = (*ituneEB);
184  EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
185  // protect against a digi not existing
186  if (digiLookUp == digisEB->end())
187  continue;
188  outputEBDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
189 
191  if (not srFlagsEBInToken_.isUninitialized()) {
192  // same matching for srFlags
193  // firstly, get the tower id
194  const EcalTrigTowerDetId& ttId = ecalReadOutTool.readOutUnitOf(static_cast<EBDetId>(hit.id()));
195  // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
196  if (outputEBSrFlagCollection->find(ttId) != outputEBSrFlagCollection->end())
197  continue;
198  srFlagLookUp = srFlagsEB->find(ttId);
199  // protect against a srFlag not existing
200  if (srFlagLookUp == srFlagsEB->end())
201  continue;
202  outputEBSrFlagCollection->push_back(*srFlagLookUp);
203  }
204  }
205 
206  // add the built collection to the event
207  iEvent.put(std::move(outputEBDigiCollection), digisOut_);
208  if (not srFlagsEBInToken_.isUninitialized())
209  iEvent.put(std::move(outputEBSrFlagCollection), srFlagsOut_);
210  break;
211  }
212  case endcap: {
213  iEvent.getByToken(digisEEInToken_, digisEEHandle);
214  const EEDigiCollection* digisEE = digisEEHandle.product();
215 
216  const EESrFlagCollection* srFlagsEE = nullptr;
217  // protection against uninitialized token (empty InputTag) to allow for backward compatibility
218  if (not srFlagsEEInToken_.isUninitialized()) {
219  iEvent.getByToken(srFlagsEEInToken_, srFlagsEEHandle);
220  srFlagsEE = srFlagsEEHandle.product();
221  }
222 
223  // loop over the collection of rechits and match to digis
224  // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
226  for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
227  EcalRecHit const& hit = (*ituneEE);
228  EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
229  // protect against a digi not existing for the saved rechit
230  if (digiLookUp == digisEE->end())
231  continue;
232  outputEEDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
233 
235  if (not srFlagsEEInToken_.isUninitialized()) {
236  // same matching for srFlags
237  // firstly, get the tower id
238  const EcalScDetId& scId = ecalReadOutTool.readOutUnitOf(static_cast<EEDetId>(hit.id()));
239  // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
240  if (outputEESrFlagCollection->find(scId) != outputEESrFlagCollection->end())
241  continue;
242  srFlagLookUp = srFlagsEE->find(scId);
243  // protect against an srFlag not existing for the saved rechit
244  if (srFlagLookUp == srFlagsEE->end())
245  continue;
246  outputEESrFlagCollection->push_back(*srFlagLookUp);
247  }
248  } // end loop over endcap rechits
249 
250  // add the built collection to the event
251  iEvent.put(std::move(outputEEDigiCollection), digisOut_);
252  if (not srFlagsEEInToken_.isUninitialized())
253  iEvent.put(std::move(outputEESrFlagCollection), srFlagsOut_);
254  break;
255  }
256  case invalidRegion: {
257  break;
258  }
259  } // end switch statement for the region (barrel, endcap, invalid)
260 }
261 
262 // ------------ method called when starting to processes a run ------------
263 /*
264 void
265 HLTRechitsToDigis::beginRun(edm::Run const&, edm::EventSetup const&)
266 {
267 }
268 */
269 
270 // ------------ method called when ending the processing of a run ------------
271 /*
272 void
273 HLTRechitsToDigis::endRun(edm::Run const&, edm::EventSetup const&)
274 {
275 }
276 */
277 
278 // ------------ method called when starting to processes a luminosity block ------------
279 /*
280 void
281 HLTRechitsToDigis::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
282 {
283 }
284 */
285 
286 // ------------ method called when ending the processing of a luminosity block ------------
287 /*
288 void
289 HLTRechitsToDigis::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
290 {
291 }
292 */
293 
294 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
296  //The following says we do not know what parameters are allowed so do no validation
297  // Please change this to state exactly what you do use, even if it is no parameters
299 
300  desc.add<std::string>("region", "barrel")
301  ->setComment("Region of rechits to save Digis for. Allowed values: barrel or endcap.");
302  desc.add<edm::InputTag>("digisIn", edm::InputTag("ecalDigis", "ebDigis"))
303  ->setComment("The collection of either barrel or endcap digis which correspond to the rechit collection");
304  desc.add<std::string>("digisOut", "pi0EBDigis")->setComment("Name for the collection of Digis saved by the module");
305  desc.add<edm::InputTag>("recHits", edm::InputTag("hltAlCaPi0EBUncalibrator", "pi0EcalRecHitsEB"))
306  ->setComment("Collection of rechits to match Digis to");
307  desc.add<edm::InputTag>("srFlagsIn", edm::InputTag())
308  ->setComment("The collection of either barrel or endcap srFlags which correspond to the rechit collection");
309  desc.add<std::string>("srFlagsOut", "pi0EBSrFlags")
310  ->setComment("Name for the collection of SrFlags saved by the module");
311  descriptions.add("hltFindMatchingECALDigisToRechits", desc);
312 }
313 
314 // declare this class as a framework plugin
T getParameter(std::string const &) const
edm::EDGetTokenT< EBSrFlagCollection > srFlagsEBInToken_
edm::EDGetTokenT< EESrFlagCollection > srFlagsEEInToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
EcalTrigTowerDetId readOutUnitOf(const EBDetId &xtalId) const
std::vector< EcalRecHit >::const_iterator const_iterator
~HLTRechitsToDigis() override
edm::EDGetTokenT< EEDigiCollection > digisEEInToken_
unsigned ttId(DetId const &)
void produce(edm::Event &, edm::EventSetup const &) override
const_iterator find(id_type i) const
HLTRechitsToDigis(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static const HLTRechitsToDigis::ecalRegion stringToRegion(const std::string &region)
edm::EDGetTokenT< EcalRecHitCollection > recHitsToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::InputTag digisIn_
const_iterator end() const
DetId id() const
get the id
Definition: EcalRecHit.h:77
T const * product() const
Definition: Handle.h:69
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::InputTag recHits_
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
std::string const & label() const
Definition: InputTag.h:36
const_iterator end() const
iterator find(key_type k)
HLT enums.
edm::InputTag srFlagsIn_
edm::EDGetTokenT< EBDigiCollection > digisEBInToken_
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const