Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-10 02:36:01

0001 //
0002 // Package:    HLTrigger/special
0003 // Class:      HLTRechitsToDigis
0004 //
0005 /**\class HLTRechitsToDigis HLTRechitsToDigis.cc HLTrigger/special/plugins/HLTRechitsToDigis.cc
0006 
0007  Description: [one line class summary]
0008 
0009  Implementation:
0010      [Notes on implementation]
0011 */
0012 //
0013 // Original Author:  Joshua Robert Hardenbrook
0014 //         Created:  Fri, 20 Feb 2015 15:51:36 GMT
0015 //
0016 //
0017 
0018 // system include files
0019 #include <memory>
0020 
0021 // user include files
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/stream/EDProducer.h"
0024 #include "FWCore/Framework/interface/Event.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 
0029 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0030 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0031 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0032 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0033 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0034 
0035 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0036 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0037 
0038 // for srFlags management
0039 #include "CalibCalorimetry/EcalTPGTools/interface/EcalReadoutTools.h"
0040 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0041 
0042 //
0043 // class declaration
0044 //
0045 
0046 class HLTRechitsToDigis : public edm::stream::EDProducer<> {
0047 public:
0048   explicit HLTRechitsToDigis(const edm::ParameterSet&);
0049   ~HLTRechitsToDigis() override;
0050   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051   enum ecalRegion { invalidRegion = 0, barrel, endcap };
0052   static const HLTRechitsToDigis::ecalRegion stringToRegion(const std::string& region);
0053 
0054 private:
0055   void produce(edm::Event&, edm::EventSetup const&) override;
0056 
0057   // ----------member data ---------------------------
0058   // tokens for the digi and rechits for matching
0059   edm::EDGetTokenT<EBDigiCollection> digisEBInToken_;
0060   edm::EDGetTokenT<EEDigiCollection> digisEEInToken_;
0061   edm::EDGetTokenT<EcalRecHitCollection> recHitsToken_;
0062   // tokens for srFlags
0063   edm::EDGetTokenT<EBSrFlagCollection> srFlagsEBInToken_;
0064   edm::EDGetTokenT<EESrFlagCollection> srFlagsEEInToken_;
0065 
0066   EcalReadoutTools::ESGetTokens const ecalReadoutToolsESGetTokens_;
0067 
0068   // input tags
0069   edm::InputTag digisIn_;
0070   edm::InputTag recHits_;
0071   // srFlags
0072   edm::InputTag srFlagsIn_;
0073 
0074   // string for the produced digi collection
0075   std::string digisOut_;
0076   ecalRegion region_;
0077   // string for the produced srFlags collection
0078   std::string srFlagsOut_;
0079 };
0080 //
0081 
0082 //
0083 // constructors and destructor
0084 //
0085 HLTRechitsToDigis::HLTRechitsToDigis(const edm::ParameterSet& iConfig)
0086     : ecalReadoutToolsESGetTokens_{iConfig, consumesCollector()} {
0087   //region to do rechit digi matching
0088   region_ = stringToRegion(iConfig.getParameter<std::string>("region"));
0089 
0090   // digis to match to hit collections
0091   digisIn_ = iConfig.getParameter<edm::InputTag>("digisIn");
0092   digisOut_ = iConfig.getParameter<std::string>("digisOut");
0093 
0094   // hit collections to save digis for
0095   recHits_ = iConfig.getParameter<edm::InputTag>("recHits");
0096 
0097   // srFlags matched to digis to be saved
0098   srFlagsIn_ = iConfig.getParameter<edm::InputTag>("srFlagsIn");
0099   srFlagsOut_ = iConfig.getParameter<std::string>("srFlagsOut");
0100 
0101   // region specific tokens
0102   switch (region_) {
0103     case barrel:
0104       digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
0105       produces<EBDigiCollection>(digisOut_);
0106       // protection against empty InputTag to allow for backward compatibility
0107       if (not srFlagsIn_.label().empty()) {
0108         srFlagsEBInToken_ = consumes<EBSrFlagCollection>(srFlagsIn_);
0109         produces<EBSrFlagCollection>(srFlagsOut_);
0110       }
0111       break;
0112     case endcap:
0113       digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
0114       produces<EEDigiCollection>(digisOut_);
0115       // protection against empty InputTag to allow for backward compatibility
0116       if (not srFlagsIn_.label().empty()) {
0117         srFlagsEEInToken_ = consumes<EESrFlagCollection>(srFlagsIn_);
0118         produces<EESrFlagCollection>(srFlagsOut_);
0119       }
0120       break;
0121     case invalidRegion:
0122       break;
0123   }
0124 
0125   recHitsToken_ = consumes<EcalRecHitCollection>(recHits_);
0126 }
0127 
0128 HLTRechitsToDigis::~HLTRechitsToDigis() {
0129   // do anything here that needs to be done at desctruction time
0130   // (e.g. close files, deallocate resources etc.)
0131 }
0132 
0133 //
0134 // member functions
0135 //
0136 const HLTRechitsToDigis::ecalRegion HLTRechitsToDigis::stringToRegion(const std::string& region) {
0137   if (region == "barrel")
0138     return barrel;
0139   else if (region == "endcap")
0140     return endcap;
0141   else
0142     return invalidRegion;
0143 }
0144 
0145 // ------------ method called to produce the data  ------------
0146 void HLTRechitsToDigis::produce(edm::Event& iEvent, edm::EventSetup const& setup) {
0147   using namespace edm;
0148   // handles for digis
0149   Handle<EBDigiCollection> digisEBHandle;
0150   Handle<EEDigiCollection> digisEEHandle;
0151 
0152   // output collections
0153   std::unique_ptr<EBDigiCollection> outputEBDigiCollection(new EBDigiCollection);
0154   std::unique_ptr<EEDigiCollection> outputEEDigiCollection(new EEDigiCollection);
0155 
0156   // handles for srFlags
0157   Handle<EBSrFlagCollection> srFlagsEBHandle;
0158   Handle<EESrFlagCollection> srFlagsEEHandle;
0159 
0160   // output collections
0161   std::unique_ptr<EBSrFlagCollection> outputEBSrFlagCollection(new EBSrFlagCollection);
0162   std::unique_ptr<EESrFlagCollection> outputEESrFlagCollection(new EESrFlagCollection);
0163   EcalReadoutTools ecalReadOutTool(iEvent, setup, ecalReadoutToolsESGetTokens_);
0164 
0165   // calibrated rechits
0166   Handle<EcalRecHitCollection> recHitsHandle;
0167   iEvent.getByToken(recHitsToken_, recHitsHandle);
0168 
0169   // match the digis based on the region
0170   switch (region_) {
0171     case barrel: {
0172       iEvent.getByToken(digisEBInToken_, digisEBHandle);
0173       const EBDigiCollection* digisEB = digisEBHandle.product();
0174 
0175       const EBSrFlagCollection* srFlagsEB = nullptr;
0176       // protection against uninitialized token (empty InputTag) to allow for backward compatibility
0177       if (not srFlagsEBInToken_.isUninitialized()) {
0178         iEvent.getByToken(srFlagsEBInToken_, srFlagsEBHandle);
0179         srFlagsEB = srFlagsEBHandle.product();
0180       }
0181 
0182       // loop over the collection of rechits and match to digis
0183       // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
0184       EcalRecHitCollection::const_iterator ituneEB;
0185       for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
0186         EcalRecHit const& hit = (*ituneEB);
0187         EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
0188         // protect against a digi not existing
0189         if (digiLookUp == digisEB->end())
0190           continue;
0191         outputEBDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
0192 
0193         EBSrFlagCollection::const_iterator srFlagLookUp;
0194         if (not srFlagsEBInToken_.isUninitialized()) {
0195           // same matching for srFlags
0196           // firstly, get the tower id
0197           const EcalTrigTowerDetId& ttId = ecalReadOutTool.readOutUnitOf(static_cast<EBDetId>(hit.id()));
0198           // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
0199           if (outputEBSrFlagCollection->find(ttId) != outputEBSrFlagCollection->end())
0200             continue;
0201           srFlagLookUp = srFlagsEB->find(ttId);
0202           // protect against a srFlag not existing
0203           if (srFlagLookUp == srFlagsEB->end())
0204             continue;
0205           outputEBSrFlagCollection->push_back(*srFlagLookUp);
0206         }
0207       }
0208 
0209       // add the built collection to the event
0210       iEvent.put(std::move(outputEBDigiCollection), digisOut_);
0211       if (not srFlagsEBInToken_.isUninitialized())
0212         iEvent.put(std::move(outputEBSrFlagCollection), srFlagsOut_);
0213       break;
0214     }
0215     case endcap: {
0216       iEvent.getByToken(digisEEInToken_, digisEEHandle);
0217       const EEDigiCollection* digisEE = digisEEHandle.product();
0218 
0219       const EESrFlagCollection* srFlagsEE = nullptr;
0220       // protection against uninitialized token (empty InputTag) to allow for backward compatibility
0221       if (not srFlagsEEInToken_.isUninitialized()) {
0222         iEvent.getByToken(srFlagsEEInToken_, srFlagsEEHandle);
0223         srFlagsEE = srFlagsEEHandle.product();
0224       }
0225 
0226       // loop over the collection of rechits and match to digis
0227       // at the same time, create the new sfFlags collection from the original one, keeping only the flags matched to digis
0228       EcalRecHitCollection::const_iterator ituneEE;
0229       for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
0230         EcalRecHit const& hit = (*ituneEE);
0231         EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
0232         // protect against a digi not existing for the saved rechit
0233         if (digiLookUp == digisEE->end())
0234           continue;
0235         outputEEDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
0236 
0237         EESrFlagCollection::const_iterator srFlagLookUp;
0238         if (not srFlagsEEInToken_.isUninitialized()) {
0239           // same matching for srFlags
0240           // firstly, get the tower id
0241           const EcalScDetId& scId = ecalReadOutTool.readOutUnitOf(static_cast<EEDetId>(hit.id()));
0242           // avoid inserting the same tower twice in the output collection (all the digis in the same tower will have the same SR flag)
0243           if (outputEESrFlagCollection->find(scId) != outputEESrFlagCollection->end())
0244             continue;
0245           srFlagLookUp = srFlagsEE->find(scId);
0246           // protect against an srFlag not existing for the saved rechit
0247           if (srFlagLookUp == srFlagsEE->end())
0248             continue;
0249           outputEESrFlagCollection->push_back(*srFlagLookUp);
0250         }
0251       }  // end loop over endcap rechits
0252 
0253       // add the built collection to the event
0254       iEvent.put(std::move(outputEEDigiCollection), digisOut_);
0255       if (not srFlagsEEInToken_.isUninitialized())
0256         iEvent.put(std::move(outputEESrFlagCollection), srFlagsOut_);
0257       break;
0258     }
0259     case invalidRegion: {
0260       break;
0261     }
0262   }  // end switch statement for the region (barrel, endcap, invalid)
0263 }
0264 
0265 // ------------ method called when starting to processes a run  ------------
0266 /*
0267 void
0268 HLTRechitsToDigis::beginRun(edm::Run const&, edm::EventSetup const&)
0269 {
0270 }
0271 */
0272 
0273 // ------------ method called when ending the processing of a run  ------------
0274 /*
0275 void
0276 HLTRechitsToDigis::endRun(edm::Run const&, edm::EventSetup const&)
0277 {
0278 }
0279 */
0280 
0281 // ------------ method called when starting to processes a luminosity block  ------------
0282 /*
0283 void
0284 HLTRechitsToDigis::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0285 {
0286 }
0287 */
0288 
0289 // ------------ method called when ending the processing of a luminosity block  ------------
0290 /*
0291 void
0292 HLTRechitsToDigis::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0293 {
0294 }
0295 */
0296 
0297 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0298 void HLTRechitsToDigis::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0299   //The following says we do not know what parameters are allowed so do no validation
0300   // Please change this to state exactly what you do use, even if it is no parameters
0301   edm::ParameterSetDescription desc;
0302 
0303   desc.add<std::string>("region", "barrel")
0304       ->setComment("Region of rechits to save Digis for. Allowed values: barrel or endcap.");
0305   desc.add<edm::InputTag>("digisIn", edm::InputTag("ecalDigis", "ebDigis"))
0306       ->setComment("The collection of either barrel or endcap digis which correspond to the rechit collection");
0307   desc.add<std::string>("digisOut", "pi0EBDigis")->setComment("Name for the collection of Digis saved by the module");
0308   desc.add<edm::InputTag>("recHits", edm::InputTag("hltAlCaPi0EBUncalibrator", "pi0EcalRecHitsEB"))
0309       ->setComment("Collection of rechits to match Digis to");
0310   desc.add<edm::InputTag>("srFlagsIn", edm::InputTag())
0311       ->setComment("The collection of either barrel or endcap srFlags which correspond to the rechit collection");
0312   desc.add<std::string>("srFlagsOut", "pi0EBSrFlags")
0313       ->setComment("Name for the collection of SrFlags saved by the module");
0314   descriptions.add("hltFindMatchingECALDigisToRechits", desc);
0315 }
0316 
0317 // declare this class as a framework plugin
0318 DEFINE_FWK_MODULE(HLTRechitsToDigis);