CMS 3D CMS Logo

AlCaHcalNoiseProducer.cc
Go to the documentation of this file.
1 /*
2 Original author Grigory Safronov
3 
4 27/03/09 - compilation from :
5 HLTrigger/special/src/HLTHcalNoiseFilter.cc
6 Calibration/HcalAlCaRecoProducers/src/AlCaEcalHcalReadoutsProducer.cc
7 Calibration/HcalIsolatedTrackReco/src/SubdetFEDSelector.cc
8 
9 */
10 
11 // -*- C++ -*-
12 
13 // system include files
14 #include <memory>
15 #include <string>
16 // user include files
17 
26 
30 
35 
44 
48 
52 
53 //
54 // class decleration
55 //
56 
58 public:
60  ~AlCaHcalNoiseProducer() override = default;
61 
62  void produce(edm::Event&, const edm::EventSetup&) override;
63  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
64 
65 private:
66  // ----------member data ---------------------------
67 
68  bool useMet_;
69  bool useJet_;
70  double MetCut_;
71  double JetMinE_;
74  int nEvents;
75 
76  std::vector<edm::InputTag> ecalLabels_;
77 
81 
85 
88  std::vector<edm::EDGetTokenT<EcalRecHitCollection>> toks_ecal_;
89 };
90 
92  tok_jets_ = consumes<reco::CaloJetCollection>(iConfig.getParameter<edm::InputTag>("JetSource"));
93  tok_met_ = consumes<reco::CaloMETCollection>(iConfig.getParameter<edm::InputTag>("MetSource"));
94  tok_tower_ = consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("TowerSource"));
95  useMet_ = iConfig.getParameter<bool>("UseMET");
96  useJet_ = iConfig.getParameter<bool>("UseJet");
97  MetCut_ = iConfig.getParameter<double>("MetCut");
98  JetMinE_ = iConfig.getParameter<double>("JetMinE");
99  JetHCALminEnergyFraction_ = iConfig.getParameter<double>("JetHCALminEnergyFraction");
100 
101  tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
102  tok_hf_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"));
103  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
104  ecalLabels_ = iConfig.getParameter<std::vector<edm::InputTag>>("ecalInputs");
105  tok_ps_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalPSInput"));
106  tok_raw_ = consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("rawInput"));
107 
108  const unsigned nLabels = ecalLabels_.size();
109  for (unsigned i = 0; i != nLabels; i++)
110  toks_ecal_.push_back(consumes<EcalRecHitCollection>(ecalLabels_[i]));
111 
112  //register products
113  produces<HBHERecHitCollection>("HBHERecHitCollectionFHN");
114  produces<HORecHitCollection>("HORecHitCollectionFHN");
115  produces<HFRecHitCollection>("HFRecHitCollectionFHN");
116 
117  produces<EcalRecHitCollection>("EcalRecHitCollectionFHN");
118  produces<EcalRecHitCollection>("PSEcalRecHitCollectionFHN");
119 
120  produces<FEDRawDataCollection>("HcalFEDsFHN");
121 }
122 
123 // ------------ method called to produce the data ------------
125  bool acceptEvent = false;
126 
127  // filtering basing on HLTrigger/special/src/HLTHcalNoiseFilter.cc:
128 
129  bool isAnomalous_BasedOnMET = false;
130  bool isAnomalous_BasedOnEnergyFraction = false;
131 
132  if (useMet_) {
134  const reco::CaloMETCollection* metCol = metHandle.product();
135  const reco::CaloMET met = metCol->front();
136 
137  if (met.pt() > MetCut_)
138  isAnomalous_BasedOnMET = true;
139  }
140 
141  if (useJet_) {
142  edm::Handle<reco::CaloJetCollection> calojetHandle = iEvent.getHandle(tok_jets_);
143  edm::Handle<CaloTowerCollection> towerHandle = iEvent.getHandle(tok_tower_);
144 
145  std::vector<CaloTower> TowerContainer;
146  std::vector<reco::CaloJet> JetContainer;
147  TowerContainer.clear();
148  JetContainer.clear();
149  CaloTower seedTower;
150  nEvents++;
151  for (reco::CaloJetCollection::const_iterator calojetIter = calojetHandle->begin();
152  calojetIter != calojetHandle->end();
153  ++calojetIter) {
154  if (((calojetIter->et()) * cosh(calojetIter->eta()) > JetMinE_) &&
155  (calojetIter->energyFractionHadronic() > JetHCALminEnergyFraction_)) {
156  JetContainer.push_back(*calojetIter);
157  double maxTowerE = 0.0;
158  for (CaloTowerCollection::const_iterator kal = towerHandle->begin(); kal != towerHandle->end(); kal++) {
159  double dR = deltaR((*calojetIter).eta(), (*calojetIter).phi(), (*kal).eta(), (*kal).phi());
160  if ((dR < 0.50) && (kal->p() > maxTowerE)) {
161  maxTowerE = kal->p();
162  seedTower = *kal;
163  }
164  }
165  TowerContainer.push_back(seedTower);
166  }
167  }
168  if (!JetContainer.empty()) {
170  isAnomalous_BasedOnEnergyFraction = true;
171  }
172  }
173 
174  acceptEvent = ((useMet_ && isAnomalous_BasedOnMET) || (useJet_ && isAnomalous_BasedOnEnergyFraction));
175 
177 
178  //Create empty output collections
179 
180  auto miniHBHERecHitCollection = std::make_unique<HBHERecHitCollection>();
181  auto miniHORecHitCollection = std::make_unique<HORecHitCollection>();
182  auto miniHFRecHitCollection = std::make_unique<HFRecHitCollection>();
183 
184  auto outputEColl = std::make_unique<EcalRecHitCollection>();
185  auto outputESColl = std::make_unique<EcalRecHitCollection>();
186 
187  auto outputFEDs = std::make_unique<FEDRawDataCollection>();
188 
189  // if good event get and save all colletions
190  if (acceptEvent) {
194 
195  edm::Handle<EcalRecHitCollection> pRecHits = iEvent.getHandle(tok_ps_);
196 
197  // temporary collection of EB+EE recHits
198 
199  auto tmpEcalRecHitCollection = std::make_unique<EcalRecHitCollection>();
200 
201  std::vector<edm::EDGetTokenT<EcalRecHitCollection>>::const_iterator i;
202  for (i = toks_ecal_.begin(); i != toks_ecal_.end(); i++) {
203  edm::Handle<EcalRecHitCollection> ec = iEvent.getHandle(*i);
204  for (EcalRecHitCollection::const_iterator recHit = (*ec).begin(); recHit != (*ec).end(); ++recHit) {
205  tmpEcalRecHitCollection->push_back(*recHit);
206  }
207  }
208 
210 
212  const HBHERecHitCollection Hithbhe = *(hbhe.product());
213  for (HBHERecHitCollection::const_iterator hbheItr = Hithbhe.begin(); hbheItr != Hithbhe.end(); hbheItr++) {
214  miniHBHERecHitCollection->push_back(*hbheItr);
215  }
216  const HORecHitCollection Hitho = *(ho.product());
217  for (HORecHitCollection::const_iterator hoItr = Hitho.begin(); hoItr != Hitho.end(); hoItr++) {
218  miniHORecHitCollection->push_back(*hoItr);
219  }
220 
221  const HFRecHitCollection Hithf = *(hf.product());
222  for (HFRecHitCollection::const_iterator hfItr = Hithf.begin(); hfItr != Hithf.end(); hfItr++) {
223  miniHFRecHitCollection->push_back(*hfItr);
224  }
226 
228  for (std::vector<EcalRecHit>::const_iterator ehit = tmpEcalRecHitCollection->begin();
229  ehit != tmpEcalRecHitCollection->end();
230  ehit++) {
231  outputEColl->push_back(*ehit);
232  }
234 
235  // write PS
236  const EcalRecHitCollection& psrechits = *(pRecHits.product());
237 
238  for (EcalRecHitCollection::const_iterator i = psrechits.begin(); i != psrechits.end(); i++) {
239  outputESColl->push_back(*i);
240  }
241 
242  // get HCAL FEDs
244 
245  std::vector<int> selFEDs;
247  selFEDs.push_back(i);
248  }
250 
251  // Copying FEDs :
252  const FEDRawDataCollection* rdc = rawIn.product();
253 
254  // if ( ( rawData[i].provenance()->processName() != e.processHistory().rbegin()->processName() ) )
255  // continue ; // skip all raw collections not produced by the current process
256 
257  for (int j = 0; j <= FEDNumbering::MAXFEDID; ++j) {
258  bool rightFED = false;
259  for (uint32_t k = 0; k < selFEDs.size(); k++) {
260  if (j == selFEDs[k]) {
261  rightFED = true;
262  }
263  }
264  if (!rightFED)
265  continue;
266  const FEDRawData& fedData = rdc->FEDData(j);
267  size_t size = fedData.size();
268 
269  if (size > 0) {
270  // this fed has data -- lets copy it
271  FEDRawData& fedDataProd = outputFEDs->FEDData(j);
272  if (fedDataProd.size() != 0) {
273  edm::LogWarning("HcalNoise") << " More than one FEDRawDataCollection with data in FED " << j
274  << " Skipping the 2nd\n";
275  continue;
276  }
277  fedDataProd.resize(size);
278  unsigned char* dataProd = fedDataProd.data();
279  const unsigned char* data = fedData.data();
280  for (unsigned int k = 0; k < size; ++k) {
281  dataProd[k] = data[k];
282  }
283  }
284  }
286  }
287 
288  //Put selected information in the event
289  iEvent.put(std::move(miniHBHERecHitCollection), "HBHERecHitCollectionFHN");
290  iEvent.put(std::move(miniHORecHitCollection), "HORecHitCollectionFHN");
291  iEvent.put(std::move(miniHFRecHitCollection), "HFRecHitCollectionFHN");
292  iEvent.put(std::move(outputEColl), "EcalRecHitCollectionFHN");
293  iEvent.put(std::move(outputESColl), "PSEcalRecHitCollectionFHN");
294  iEvent.put(std::move(outputFEDs), "HcalFEDsFHN");
295 }
296 
299  desc.add<edm::InputTag>("JetSource", edm::InputTag("iterativeCone5CaloJets"));
300  desc.add<edm::InputTag>("MetSource", edm::InputTag("met"));
301  desc.add<edm::InputTag>("TowerSource", edm::InputTag("towerMaker"));
302  desc.add<bool>("UseJet", true);
303  desc.add<bool>("UseMET", false);
304  desc.add<double>("MetCut", 0);
305  desc.add<double>("JetMinE", 20);
306  desc.add<double>("JetHCALminEnergyFraction", 0.98);
307  desc.add<edm::InputTag>("hbheInput", edm::InputTag("hbhereco"));
308  desc.add<edm::InputTag>("hfInput", edm::InputTag("hfreco"));
309  desc.add<edm::InputTag>("hoInput", edm::InputTag("horeco"));
310  std::vector<edm::InputTag> inputs = {edm::InputTag("ecalRecHit", "EcalRecHitsEB"),
311  edm::InputTag("ecalRecHit", "EcalRecHitsEE")};
312  desc.add<std::vector<edm::InputTag>>("ecalInputs", inputs);
313  desc.add<edm::InputTag>("ecalPSInput", edm::InputTag("ecalPreshowerRecHit", "EcalRecHitsES"));
314  desc.add<edm::InputTag>("rawInput", edm::InputTag("rawDataCollector"));
315  descriptions.add("alcaHcalNoiseProducer", desc);
316 }
317 
319 
edm::EDGetTokenT< HFRecHitCollection > tok_hf_
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< HORecHitCollection > tok_ho_
T const * product() const
Definition: Handle.h:70
std::vector< CaloTower >::const_iterator const_iterator
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > toks_ecal_
edm::EDGetTokenT< CaloTowerCollection > tok_tower_
void push_back(T const &t)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
edm::EDGetTokenT< EcalRecHitCollection > tok_ps_
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
edm::EDGetTokenT< reco::CaloJetCollection > tok_jets_
std::vector< edm::InputTag > ecalLabels_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void resize(size_t newsize)
Definition: FEDRawData.cc:28
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
const_iterator begin() const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const_iterator end() const
std::vector< reco::CaloMET > CaloMETCollection
collection of CaloMET objects
AlCaHcalNoiseProducer(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~AlCaHcalNoiseProducer() override=default
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::CaloMETCollection > tok_met_