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