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 
19 // system include files
20 #include <memory>
21 
22 // user include files
27 
29 
35 
38 
39 // for srFlags management
42 
43 
44 //
45 // class declaration
46 //
47 
49 public:
50  explicit HLTRechitsToDigis(const edm::ParameterSet&);
51  ~HLTRechitsToDigis() override;
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54  static const HLTRechitsToDigis::ecalRegion stringToRegion(const std::string& region);
55 
56 private:
57  void produce( edm::Event&, edm::EventSetup const&) override;
58 
59  // ----------member data ---------------------------
60  // tokens for the digi and rechits for matching
64  // tokens for srFlags
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 //
84 // constructors and destructor
85 //
87 {
88  //region to do rechit digi matching
89  region_ = stringToRegion(iConfig.getParameter<std::string> ("region"));
90 
91  // digis to match to hit collections
92  digisIn_ = iConfig.getParameter<edm::InputTag> ("digisIn");
93  digisOut_ = iConfig.getParameter<std::string> ("digisOut");
94 
95  // hit collections to save digis for
96  recHits_ = iConfig.getParameter<edm::InputTag> ("recHits");
97 
98  // srFlags matched to digis to be saved
99  srFlagsIn_ = iConfig.getParameter<edm::InputTag> ("srFlagsIn");
100  srFlagsOut_ = iConfig.getParameter<std::string> ("srFlagsOut");
101 
102  // region specific tokens
103  switch(region_) {
104  case barrel:
105  digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
106  produces<EBDigiCollection>(digisOut_);
107  // protection against empty InputTag to allow for backward compatibility
108  if (not srFlagsIn_.label().empty()) {
109  srFlagsEBInToken_ = consumes<EBSrFlagCollection>(srFlagsIn_);
110  produces<EBSrFlagCollection>(srFlagsOut_);
111  }
112  break;
113  case endcap:
114  digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
115  produces<EEDigiCollection>(digisOut_);
116  // protection against empty InputTag to allow for backward compatibility
117  if (not srFlagsIn_.label().empty()) {
118  srFlagsEEInToken_ = consumes<EESrFlagCollection>(srFlagsIn_);
119  produces<EESrFlagCollection>(srFlagsOut_);
120  }
121  break;
122  case invalidRegion:
123  break;
124  }
125 
126  recHitsToken_ = consumes<EcalRecHitCollection>(recHits_);
127 }
128 
130 {
131  // do anything here that needs to be done at desctruction time
132  // (e.g. close files, deallocate resources etc.)
133 }
134 
135 //
136 // member functions
137 //
140  if (region == "barrel") return barrel;
141  else if (region == "endcap") return endcap;
142  else return invalidRegion;
143 }
144 
145 
146 // ------------ method called to produce the data ------------
147 void
149  using namespace edm;
150  // handles for digis
151  Handle<EBDigiCollection> digisEBHandle;
152  Handle<EEDigiCollection> digisEEHandle;
153 
154  // output collections
155  std::unique_ptr<EBDigiCollection> outputEBDigiCollection( new EBDigiCollection );
156  std::unique_ptr<EEDigiCollection> outputEEDigiCollection( new EEDigiCollection );
157 
158  // handles for srFlags
159  Handle<EBSrFlagCollection> srFlagsEBHandle;
160  Handle<EESrFlagCollection> srFlagsEEHandle;
161 
162  // output collections
163  std::unique_ptr<EBSrFlagCollection> outputEBSrFlagCollection( new EBSrFlagCollection );
164  std::unique_ptr<EESrFlagCollection> outputEESrFlagCollection( new EESrFlagCollection );
165  EcalReadoutTools ecalReadOutTool(iEvent, setup);
166 
167  // calibrated rechits
168  Handle<EcalRecHitCollection> recHitsHandle;
169  iEvent.getByToken(recHitsToken_, recHitsHandle);
170 
171  // match the digis based on the region
172  switch(region_) {
173  case barrel: {
174  iEvent.getByToken(digisEBInToken_, digisEBHandle);
175  const EBDigiCollection* digisEB = digisEBHandle.product();
176 
177  const EBSrFlagCollection* srFlagsEB = nullptr;
178  // protection against uninitialized token (empty InputTag) to allow for backward compatibility
179  if (not srFlagsEBInToken_.isUninitialized()) {
180  iEvent.getByToken(srFlagsEBInToken_, srFlagsEBHandle);
181  srFlagsEB = srFlagsEBHandle.product();
182  }
183 
184  // loop over the collection of rechits and match to digis
185  // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
187  for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
188  EcalRecHit const & hit = (*ituneEB);
189  EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
190  // protect against a digi not existing
191  if( digiLookUp == digisEB->end()) continue;
192  outputEBDigiCollection->push_back( digiLookUp->id(), digiLookUp->begin() );
193 
195  if (not srFlagsEBInToken_.isUninitialized()) {
196  // same matching for srFlags
197  // firstly, get the tower id
198  const EcalTrigTowerDetId& ttId = ecalReadOutTool.readOutUnitOf( static_cast<EBDetId>(hit.id()) );
199  // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
200  if (outputEBSrFlagCollection->find(ttId) != outputEBSrFlagCollection->end()) continue;
201  srFlagLookUp = srFlagsEB->find( ttId );
202  // protect against a srFlag not existing
203  if( srFlagLookUp == srFlagsEB->end()) continue;
204  outputEBSrFlagCollection->push_back( *srFlagLookUp );
205  }
206  }
207 
208  // add the built collection to the event
209  iEvent.put(std::move(outputEBDigiCollection), digisOut_);
210  if (not srFlagsEBInToken_.isUninitialized()) iEvent.put(std::move(outputEBSrFlagCollection), srFlagsOut_);
211  break;
212  }
213  case endcap: {
214  iEvent.getByToken(digisEEInToken_, digisEEHandle);
215  const EEDigiCollection* digisEE = digisEEHandle.product();
216 
217  const EESrFlagCollection* srFlagsEE = nullptr;
218  // protection against uninitialized token (empty InputTag) to allow for backward compatibility
219  if (not srFlagsEEInToken_.isUninitialized()) {
220  iEvent.getByToken(srFlagsEEInToken_, srFlagsEEHandle);
221  srFlagsEE = srFlagsEEHandle.product();
222  }
223 
224  // loop over the collection of rechits and match to digis
225  // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
227  for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
228  EcalRecHit const & hit = (*ituneEE);
229  EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
230  // protect against a digi not existing for the saved rechit
231  if(digiLookUp == digisEE->end()) 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()) continue;
241  srFlagLookUp = srFlagsEE->find( scId );
242  // protect against an srFlag not existing for the saved rechit
243  if(srFlagLookUp == srFlagsEE->end()) continue;
244  outputEESrFlagCollection->push_back( *srFlagLookUp );
245  }
246  } // end loop over endcap rechits
247 
248  // add the built collection to the event
249  iEvent.put(std::move(outputEEDigiCollection), digisOut_);
250  if (not srFlagsEEInToken_.isUninitialized()) 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 called when starting to processes a run ------------
260 /*
261 void
262 HLTRechitsToDigis::beginRun(edm::Run const&, edm::EventSetup const&)
263 {
264 }
265 */
266 
267 // ------------ method called when ending the processing of a run ------------
268 /*
269 void
270 HLTRechitsToDigis::endRun(edm::Run const&, edm::EventSetup const&)
271 {
272 }
273 */
274 
275 // ------------ method called when starting to processes a luminosity block ------------
276 /*
277 void
278 HLTRechitsToDigis::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
279 {
280 }
281 */
282 
283 // ------------ method called when ending the processing of a luminosity block ------------
284 /*
285 void
286 HLTRechitsToDigis::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
287 {
288 }
289 */
290 
291 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
292 void
294  //The following says we do not know what parameters are allowed so do no validation
295  // Please change this to state exactly what you do use, even if it is no parameters
297 
298  desc.add<std::string>("region", "barrel")
299  ->setComment("Region of rechits to save Digis for. Allowed values: barrel or endcap.");
300  desc.add<edm::InputTag>("digisIn",edm::InputTag("ecalDigis","ebDigis"))
301  ->setComment("The collection of either barrel or endcap digis which correspond to the rechit collection");
302  desc.add<std::string>("digisOut","pi0EBDigis")
303  ->setComment("Name for the collection of Digis saved by the module");
304  desc.add<edm::InputTag>("recHits",edm::InputTag("hltAlCaPi0EBUncalibrator","pi0EcalRecHitsEB"))
305  ->setComment("Collection of rechits to match Digis to");
306  desc.add<edm::InputTag>("srFlagsIn",edm::InputTag())
307  ->setComment("The collection of either barrel or endcap srFlags which correspond to the rechit collection");
308  desc.add<std::string>("srFlagsOut","pi0EBSrFlags")
309  ->setComment("Name for the collection of SrFlags saved by the module");
310  descriptions.add("hltFindMatchingECALDigisToRechits", desc);
311 }
312 
313 // 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:137
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
EcalTrigTowerDetId readOutUnitOf(const EBDetId &xtalId) const
std::vector< EcalRecHit >::const_iterator const_iterator
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
~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:230
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:81
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::InputTag recHits_
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:510
const_iterator begin() const