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 
34 
37 
38 //
39 // class declaration
40 //
41 
43 public:
44  explicit HLTRechitsToDigis(const edm::ParameterSet&);
45  ~HLTRechitsToDigis() override;
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48  static const HLTRechitsToDigis::ecalRegion stringToRegion(const std::string& region);
49 
50 private:
51  void produce( edm::Event&, edm::EventSetup const&) override;
52 
53  // ----------member data ---------------------------
54  // tokens for the digi and rechits for matching
58 
59  // input tags
62 
63  // string for the produced digi collection
66 };
67 //
68 
69 //
70 // constructors and destructor
71 //
73 {
74  //region to do rechit digi matching
75  region_ = stringToRegion(iConfig.getParameter<std::string> ("region"));
76 
77  // digis to match to hit collections
78  digisIn_ = iConfig.getParameter<edm::InputTag> ("digisIn");
79  digisOut_ = iConfig.getParameter<std::string> ("digisOut");
80 
81  // hit collections to save digis for
82  recHits_ = iConfig.getParameter<edm::InputTag> ("recHits");
83 
84  // region specific tokens
85  switch(region_) {
86  case barrel:
87  digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
88  produces<EBDigiCollection>(digisOut_);
89  break;
90  case endcap:
91  digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
92  produces<EEDigiCollection>(digisOut_);
93  break;
94  case invalidRegion:
95  break;
96  }
97 
98  recHitsToken_ = consumes<EcalRecHitCollection>(recHits_);
99 }
100 
102 {
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 //
108 // member functions
109 //
112  if (region == "barrel") return barrel;
113  else if (region == "endcap") return endcap;
114  else return invalidRegion;
115 }
116 
117 
118 // ------------ method called to produce the data ------------
119 void
121  using namespace edm;
122  // handles for digis
123  Handle<EBDigiCollection> digisEBHandle;
124  Handle<EEDigiCollection> digisEEHandle;
125 
126  // output collections
127  std::unique_ptr<EBDigiCollection> outputEBDigiCollection( new EBDigiCollection );
128  std::unique_ptr<EEDigiCollection> outputEEDigiCollection( new EEDigiCollection );
129 
130  // calibrated rechits
131  Handle<EcalRecHitCollection> recHitsHandle;
132  iEvent.getByToken(recHitsToken_, recHitsHandle);
133 
134  // match the digis based on the region
135  switch(region_) {
136  case barrel: {
137  iEvent.getByToken(digisEBInToken_, digisEBHandle);
138  const EBDigiCollection* digisEB = digisEBHandle.product();
139 
140  // loop over the collection of rechits and match to digis
142  for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
143  EcalRecHit const & hit = (*ituneEB);
144  EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
145  // protect against a digi not existing
146  if( digiLookUp == digisEB->end()) continue;
147  outputEBDigiCollection->push_back( digiLookUp->id(), digiLookUp->begin() );
148  }
149 
150  // add the built collection to the event
151  iEvent.put(std::move(outputEBDigiCollection), digisOut_);
152  break;
153  }
154  case endcap: {
155  iEvent.getByToken(digisEEInToken_, digisEEHandle);
156  const EEDigiCollection* digisEE = digisEEHandle.product();
157 
158  // loop over the collection of rechits and match to digis
160  for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
161  EcalRecHit const & hit = (*ituneEE);
162  EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
163  // protect against a digi not existing for the saved rechit
164  if(digiLookUp == digisEE->end()) continue;
165  outputEEDigiCollection->push_back( digiLookUp->id(), digiLookUp->begin() );
166  } // end loop over endcap rechits
167 
168  // add the built collection to the event
169  iEvent.put(std::move(outputEEDigiCollection), digisOut_);
170  break;
171  }
172  case invalidRegion: {
173  break;
174  }
175  } // end switch statement for the region (barrel, endcap, invalid)
176 }
177 
178 // ------------ method called when starting to processes a run ------------
179 /*
180 void
181 HLTRechitsToDigis::beginRun(edm::Run const&, edm::EventSetup const&)
182 {
183 }
184 */
185 
186 // ------------ method called when ending the processing of a run ------------
187 /*
188 void
189 HLTRechitsToDigis::endRun(edm::Run const&, edm::EventSetup const&)
190 {
191 }
192 */
193 
194 // ------------ method called when starting to processes a luminosity block ------------
195 /*
196 void
197 HLTRechitsToDigis::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
198 {
199 }
200 */
201 
202 // ------------ method called when ending the processing of a luminosity block ------------
203 /*
204 void
205 HLTRechitsToDigis::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
206 {
207 }
208 */
209 
210 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
211 void
213  //The following says we do not know what parameters are allowed so do no validation
214  // Please change this to state exactly what you do use, even if it is no parameters
216 
217  desc.add<std::string>("region", "barrel")
218  ->setComment("Region of rechits to save Digis for. Allowed values: barrel or endcap.");
219  desc.add<edm::InputTag>("digisIn",edm::InputTag("ecalDigis","ebDigis"))
220  ->setComment("The collection of either barrel or endcap digis which correspond to the rechit collection");
221  desc.add<std::string>("digisOut","pi0EBDigis")
222  ->setComment("Name for the collection of Digis saved by the module");
223  desc.add<edm::InputTag>("recHits",edm::InputTag("hltAlCaPi0EBUncalibrator","pi0EcalRecHitsEB"))
224  ->setComment("Collection of rechits to match Digis to");
225  descriptions.add("hltFindMatchingECALDigisToRechits", desc);
226 }
227 
228 //define this as a plug-in
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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_
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_
const_iterator end() const
HLT enums.
edm::EDGetTokenT< EBDigiCollection > digisEBInToken_
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const