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
EcalRecHit
Definition: EcalRecHit.h:15
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
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:73
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:76
HLTRechitsToDigis::~HLTRechitsToDigis
~HLTRechitsToDigis() override
Definition: HLTRechitsToDigis.cc:125
edm::EDGetTokenT< EBDigiCollection >
HLTRechitsToDigis::digisEEInToken_
edm::EDGetTokenT< EEDigiCollection > digisEEInToken_
Definition: HLTRechitsToDigis.cc:60
edm
HLT enums.
Definition: AlignableModifier.h:19
EBDetId.h
EEDetId.h
EcalDetIdCollections.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ecaldqm::ttId
unsigned ttId(DetId const &)
Definition: EcalDQMCommonUtils.cc:101
EDProducer.h
edm::SortedCollection
Definition: SortedCollection.h:49
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
edm::Handle< EBDigiCollection >
HLTRechitsToDigis::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: HLTRechitsToDigis.cc:143
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
EcalRecHitCollections.h
EcalReadoutTools.h
EcalReadoutTools::readOutUnitOf
EcalTrigTowerDetId readOutUnitOf(const EBDetId &xtalId) const
Definition: EcalReadoutTools.cc:13
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:67
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:133
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:83
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:88272
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:57
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:70
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HLTRechitsToDigis::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTRechitsToDigis.cc:295
HLTRechitsToDigis
Definition: HLTRechitsToDigis.cc:46
HLTRechitsToDigis::region_
ecalRegion region_
Definition: HLTRechitsToDigis.cc:74
ParameterSet.h
HLTRechitsToDigis::srFlagsEEInToken_
edm::EDGetTokenT< EESrFlagCollection > srFlagsEEInToken_
Definition: HLTRechitsToDigis.cc:64
HLTRechitsToDigis::recHits_
edm::InputTag recHits_
Definition: HLTRechitsToDigis.cc:68
EcalReadoutTools
Definition: EcalReadoutTools.h:13
edm::Event
Definition: Event.h:73
EcalChannelStatus.h
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