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  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void produce(edm::Event&, edm::EventSetup const&) override;
55 
56  // ----------member data ---------------------------
57  // tokens for the digi and rechits for matching
61  // tokens for srFlags
64 
66 
67  // input tags
70  // srFlags
72 
73  // string for the produced digi collection
76  // string for the produced srFlags collection
78 };
79 //
80 
81 //
82 // constructors and destructor
83 //
85  : ecalReadoutToolsESGetTokens_{iConfig, consumesCollector()} {
86  //region to do rechit digi matching
87  region_ = stringToRegion(iConfig.getParameter<std::string>("region"));
88 
89  // digis to match to hit collections
90  digisIn_ = iConfig.getParameter<edm::InputTag>("digisIn");
91  digisOut_ = iConfig.getParameter<std::string>("digisOut");
92 
93  // hit collections to save digis for
94  recHits_ = iConfig.getParameter<edm::InputTag>("recHits");
95 
96  // srFlags matched to digis to be saved
97  srFlagsIn_ = iConfig.getParameter<edm::InputTag>("srFlagsIn");
98  srFlagsOut_ = iConfig.getParameter<std::string>("srFlagsOut");
99 
100  // region specific tokens
101  switch (region_) {
102  case barrel:
103  digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
104  produces<EBDigiCollection>(digisOut_);
105  // protection against empty InputTag to allow for backward compatibility
106  if (not srFlagsIn_.label().empty()) {
107  srFlagsEBInToken_ = consumes<EBSrFlagCollection>(srFlagsIn_);
108  produces<EBSrFlagCollection>(srFlagsOut_);
109  }
110  break;
111  case endcap:
112  digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
113  produces<EEDigiCollection>(digisOut_);
114  // protection against empty InputTag to allow for backward compatibility
115  if (not srFlagsIn_.label().empty()) {
116  srFlagsEEInToken_ = consumes<EESrFlagCollection>(srFlagsIn_);
117  produces<EESrFlagCollection>(srFlagsOut_);
118  }
119  break;
120  case invalidRegion:
121  break;
122  }
123 
124  recHitsToken_ = consumes<EcalRecHitCollection>(recHits_);
125 }
126 
127 //
128 // member functions
129 //
131  if (region == "barrel")
132  return barrel;
133  else if (region == "endcap")
134  return endcap;
135  else
136  return invalidRegion;
137 }
138 
139 // ------------ method called to produce the data ------------
141  using namespace edm;
142  // handles for digis
143  Handle<EBDigiCollection> digisEBHandle;
144  Handle<EEDigiCollection> digisEEHandle;
145 
146  // output collections
147  std::unique_ptr<EBDigiCollection> outputEBDigiCollection(new EBDigiCollection);
148  std::unique_ptr<EEDigiCollection> outputEEDigiCollection(new EEDigiCollection);
149 
150  // handles for srFlags
151  Handle<EBSrFlagCollection> srFlagsEBHandle;
152  Handle<EESrFlagCollection> srFlagsEEHandle;
153 
154  // output collections
155  std::unique_ptr<EBSrFlagCollection> outputEBSrFlagCollection(new EBSrFlagCollection);
156  std::unique_ptr<EESrFlagCollection> outputEESrFlagCollection(new EESrFlagCollection);
158 
159  // calibrated rechits
160  Handle<EcalRecHitCollection> recHitsHandle;
161  iEvent.getByToken(recHitsToken_, recHitsHandle);
162 
163  // match the digis based on the region
164  switch (region_) {
165  case barrel: {
166  iEvent.getByToken(digisEBInToken_, digisEBHandle);
167  const EBDigiCollection* digisEB = digisEBHandle.product();
168 
169  const EBSrFlagCollection* srFlagsEB = nullptr;
170  // protection against uninitialized token (empty InputTag) to allow for backward compatibility
171  if (not srFlagsEBInToken_.isUninitialized()) {
172  iEvent.getByToken(srFlagsEBInToken_, srFlagsEBHandle);
173  srFlagsEB = srFlagsEBHandle.product();
174  }
175 
176  // loop over the collection of rechits and match to digis
177  // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
179  for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
180  EcalRecHit const& hit = (*ituneEB);
181  EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
182  // protect against a digi not existing
183  if (digiLookUp == digisEB->end())
184  continue;
185  outputEBDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
186 
188  if (not srFlagsEBInToken_.isUninitialized()) {
189  // same matching for srFlags
190  // firstly, get the tower id
191  const EcalTrigTowerDetId& ttId = ecalReadOutTool.readOutUnitOf(static_cast<EBDetId>(hit.id()));
192  // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
193  if (outputEBSrFlagCollection->find(ttId) != outputEBSrFlagCollection->end())
194  continue;
195  srFlagLookUp = srFlagsEB->find(ttId);
196  // protect against a srFlag not existing
197  if (srFlagLookUp == srFlagsEB->end())
198  continue;
199  outputEBSrFlagCollection->push_back(*srFlagLookUp);
200  }
201  }
202 
203  // add the built collection to the event
204  iEvent.put(std::move(outputEBDigiCollection), digisOut_);
205  if (not srFlagsEBInToken_.isUninitialized())
206  iEvent.put(std::move(outputEBSrFlagCollection), srFlagsOut_);
207  break;
208  }
209  case endcap: {
210  iEvent.getByToken(digisEEInToken_, digisEEHandle);
211  const EEDigiCollection* digisEE = digisEEHandle.product();
212 
213  const EESrFlagCollection* srFlagsEE = nullptr;
214  // protection against uninitialized token (empty InputTag) to allow for backward compatibility
215  if (not srFlagsEEInToken_.isUninitialized()) {
216  iEvent.getByToken(srFlagsEEInToken_, srFlagsEEHandle);
217  srFlagsEE = srFlagsEEHandle.product();
218  }
219 
220  // loop over the collection of rechits and match to digis
221  // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
223  for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
224  EcalRecHit const& hit = (*ituneEE);
225  EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
226  // protect against a digi not existing for the saved rechit
227  if (digiLookUp == digisEE->end())
228  continue;
229  outputEEDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
230 
232  if (not srFlagsEEInToken_.isUninitialized()) {
233  // same matching for srFlags
234  // firstly, get the tower id
235  const EcalScDetId& scId = ecalReadOutTool.readOutUnitOf(static_cast<EEDetId>(hit.id()));
236  // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
237  if (outputEESrFlagCollection->find(scId) != outputEESrFlagCollection->end())
238  continue;
239  srFlagLookUp = srFlagsEE->find(scId);
240  // protect against an srFlag not existing for the saved rechit
241  if (srFlagLookUp == srFlagsEE->end())
242  continue;
243  outputEESrFlagCollection->push_back(*srFlagLookUp);
244  }
245  } // end loop over endcap rechits
246 
247  // add the built collection to the event
248  iEvent.put(std::move(outputEEDigiCollection), digisOut_);
249  if (not srFlagsEEInToken_.isUninitialized())
250  iEvent.put(std::move(outputEESrFlagCollection), srFlagsOut_);
251  break;
252  }
253  case invalidRegion: {
254  break;
255  }
256  } // end switch statement for the region (barrel, endcap, invalid)
257 }
258 
259 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
261  //The following says we do not know what parameters are allowed so do no validation
262  // Please change this to state exactly what you do use, even if it is no parameters
264 
265  desc.add<std::string>("region", "barrel")
266  ->setComment("Region of rechits to save Digis for. Allowed values: barrel or endcap.");
267  desc.add<edm::InputTag>("digisIn", edm::InputTag("ecalDigis", "ebDigis"))
268  ->setComment("The collection of either barrel or endcap digis which correspond to the rechit collection");
269  desc.add<std::string>("digisOut", "pi0EBDigis")->setComment("Name for the collection of Digis saved by the module");
270  desc.add<edm::InputTag>("recHits", edm::InputTag("hltAlCaPi0EBUncalibrator", "pi0EcalRecHitsEB"))
271  ->setComment("Collection of rechits to match Digis to");
272  desc.add<edm::InputTag>("srFlagsIn", edm::InputTag())
273  ->setComment("The collection of either barrel or endcap srFlags which correspond to the rechit collection");
274  desc.add<std::string>("srFlagsOut", "pi0EBSrFlags")
275  ->setComment("Name for the collection of SrFlags saved by the module");
276  descriptions.add("hltFindMatchingECALDigisToRechits", desc);
277 }
278 
279 // declare this class as a framework plugin
edm::EDGetTokenT< EBSrFlagCollection > srFlagsEBInToken_
edm::EDGetTokenT< EESrFlagCollection > srFlagsEEInToken_
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
std::string const & label() const
Definition: InputTag.h:36
edm::EDGetTokenT< EEDigiCollection > digisEEInToken_
unsigned ttId(DetId const &, EcalElectronicsMapping const *)
void produce(edm::Event &, edm::EventSetup const &) override
EcalReadoutTools::ESGetTokens const ecalReadoutToolsESGetTokens_
HLTRechitsToDigis(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
static const HLTRechitsToDigis::ecalRegion stringToRegion(const std::string &region)
edm::EDGetTokenT< EcalRecHitCollection > recHitsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
edm::InputTag digisIn_
const_iterator end() const
unsigned int id
const_iterator end() const
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
iterator find(key_type k)
HLT enums.
const_iterator find(id_type i) const
edm::InputTag srFlagsIn_
edm::EDGetTokenT< EBDigiCollection > digisEBInToken_
def move(src, dest)
Definition: eostools.py:511
EcalTrigTowerDetId readOutUnitOf(const EBDetId &xtalId) const