Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-01 03:53:42

0001 // Skip FED40 pilot-blade
0002 // Include parameter driven interface to SiPixelQuality for study purposes
0003 // exclude ROC(raw) based on bad ROC list in SiPixelQuality
0004 // enabled by: process.siPixelDigis.useQualityInfo = True (BY DEFAULT NOT USED)
0005 // 20-10-2010 Andrew York (Tennessee)
0006 // Jan 2016 Tamas Almos Vami (Tav) (Wigner RCP) -- Cabling Map label option
0007 // Jul 2017 Viktor Veszpremi -- added PixelFEDChannel
0008 
0009 #include <memory>
0010 
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/ESTransientHandle.h"
0014 #include "FWCore/Framework/interface/ESWatcher.h"
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/ConsumesCollector.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0022 #include "FWCore/Utilities/interface/ESGetToken.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 
0025 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
0026 #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
0027 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0028 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0029 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0030 
0031 #include "DataFormats/Common/interface/DetSetVector.h"
0032 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0033 #include "DataFormats/DetId/interface/DetIdCollection.h"
0034 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0035 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0036 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0037 #include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h"
0038 #include "DataFormats/SiPixelRawData/interface/SiPixelRawDataError.h"
0039 #include "DataFormats/SiPixelDigi/interface/SiPixelDigiConstants.h"
0040 
0041 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
0042 #include "EventFilter/SiPixelRawToDigi/interface/PixelUnpackingRegions.h"
0043 
0044 using namespace sipixelconstants;
0045 
0046 /** \class SiPixelRawToDigi
0047  *  Plug-in module that performs Raw data to digi conversion 
0048  *  for pixel subdetector
0049  */
0050 
0051 class SiPixelRawToDigi : public edm::stream::EDProducer<> {
0052 public:
0053   /// ctor
0054   explicit SiPixelRawToDigi(const edm::ParameterSet&);
0055 
0056   /// dtor
0057   ~SiPixelRawToDigi() override;
0058 
0059   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0060 
0061   /// get data, convert to digis attach againe to Event
0062   void produce(edm::Event&, const edm::EventSetup&) override;
0063 
0064 private:
0065   edm::ParameterSet config_;
0066   std::unique_ptr<SiPixelFedCablingTree> cabling_;
0067   const SiPixelQuality* badPixelInfo_;
0068   PixelUnpackingRegions* regions_;
0069   const std::vector<int> tkerrorlist_;
0070   const std::vector<int> usererrorlist_;
0071   std::vector<unsigned int> fedIds_;
0072   edm::ESWatcher<SiPixelFedCablingMapRcd> recordWatcher_;
0073   edm::ESWatcher<SiPixelQualityRcd> qualityWatcher_;
0074   // always consumed
0075   const edm::EDGetTokenT<FEDRawDataCollection> fedRawDataCollectionToken_;
0076   const edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> cablingMapToken_;
0077   // consume only if pixel quality is used -> useQuality_
0078   edm::ESGetToken<SiPixelQuality, SiPixelQualityRcd> siPixelQualityToken_;
0079   // always produced
0080   const edm::EDPutTokenT<edm::DetSetVector<PixelDigi>> siPixelDigiCollectionToken_;
0081   // produce only if error collections are included -> includeErrors_
0082   edm::EDPutTokenT<edm::DetSetVector<SiPixelRawDataError>> errorPutToken_;
0083   edm::EDPutTokenT<DetIdCollection> tkErrorPutToken_;
0084   edm::EDPutTokenT<DetIdCollection> userErrorPutToken_;
0085   edm::EDPutTokenT<edmNew::DetSetVector<PixelFEDChannel>> disabledChannelPutToken_;
0086   const bool includeErrors_;
0087   const bool useQuality_;
0088   const bool usePilotBlade_;
0089   const bool usePhase1_;
0090 };
0091 
0092 // -----------------------------------------------------------------------------
0093 SiPixelRawToDigi::SiPixelRawToDigi(const edm::ParameterSet& conf)
0094     : config_(conf),
0095       badPixelInfo_(nullptr),
0096       regions_(nullptr),
0097       tkerrorlist_(config_.getParameter<std::vector<int>>("ErrorList")),
0098       usererrorlist_(config_.getParameter<std::vector<int>>("UserErrorList")),
0099       fedRawDataCollectionToken_{consumes<FEDRawDataCollection>(config_.getParameter<edm::InputTag>("InputLabel"))},
0100       cablingMapToken_{esConsumes<SiPixelFedCablingMap, SiPixelFedCablingMapRcd>(
0101           edm::ESInputTag("", config_.getParameter<std::string>("CablingMapLabel")))},
0102       siPixelDigiCollectionToken_{produces<edm::DetSetVector<PixelDigi>>()},
0103       includeErrors_(config_.getParameter<bool>("IncludeErrors")),
0104       useQuality_(config_.getParameter<bool>("UseQualityInfo")),
0105       usePilotBlade_(config_.getParameter<bool>("UsePilotBlade")),
0106       usePhase1_(config_.getParameter<bool>("UsePhase1"))
0107 
0108 {
0109   if (useQuality_) {
0110     siPixelQualityToken_ = esConsumes<SiPixelQuality, SiPixelQualityRcd>(
0111         edm::ESInputTag("", config_.getParameter<std::string>("SiPixelQualityLabel")));
0112   }
0113 
0114   // Products
0115   if (includeErrors_) {
0116     errorPutToken_ = produces<edm::DetSetVector<SiPixelRawDataError>>();
0117     tkErrorPutToken_ = produces<DetIdCollection>();
0118     userErrorPutToken_ = produces<DetIdCollection>("UserErrorModules");
0119     disabledChannelPutToken_ = produces<edmNew::DetSetVector<PixelFEDChannel>>();
0120   }
0121 
0122   // regions
0123   if (!config_.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
0124     regions_ = new PixelUnpackingRegions(config_, consumesCollector());
0125   }
0126 
0127   // Control the usage of pilot-blade data, FED=40
0128   if (usePilotBlade_)
0129     edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
0130 
0131   // Control the usage of phase1
0132   if (usePhase1_)
0133     edm::LogInfo("SiPixelRawToDigi") << " Using phase1";
0134 }
0135 
0136 // -----------------------------------------------------------------------------
0137 SiPixelRawToDigi::~SiPixelRawToDigi() {
0138   edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
0139   if (regions_)
0140     delete regions_;
0141 }
0142 
0143 void SiPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0144   edm::ParameterSetDescription desc;
0145   desc.add<bool>("IncludeErrors", true);
0146   desc.add<bool>("UseQualityInfo", false);
0147   {
0148     desc.add<std::vector<int>>("ErrorList", std::vector<int>{29})
0149         ->setComment("## ErrorList: list of error codes used by tracking to invalidate modules");
0150   }
0151   {
0152     desc.add<std::vector<int>>("UserErrorList", std::vector<int>{40})
0153         ->setComment("## UserErrorList: list of error codes used by Pixel experts for investigation");
0154   }
0155   desc.add<edm::InputTag>("InputLabel", edm::InputTag("siPixelRawData"));
0156   {
0157     edm::ParameterSetDescription psd0;
0158     psd0.addOptional<std::vector<edm::InputTag>>("inputs");
0159     psd0.addOptional<std::vector<double>>("deltaPhi");
0160     psd0.addOptional<std::vector<double>>("maxZ");
0161     psd0.addOptional<edm::InputTag>("beamSpot");
0162     desc.add<edm::ParameterSetDescription>("Regions", psd0)
0163         ->setComment("## Empty Regions PSet means complete unpacking");
0164   }
0165   desc.add<bool>("UsePilotBlade", false)->setComment("##  Use pilot blades");
0166   desc.add<bool>("UsePhase1", false)->setComment("##  Use phase1");
0167   desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label");  //Tav
0168   desc.add<std::string>("SiPixelQualityLabel", "")->setComment("SiPixelQuality label");
0169   descriptions.add("siPixelRawToDigi", desc);
0170 }
0171 
0172 // -----------------------------------------------------------------------------
0173 
0174 // -----------------------------------------------------------------------------
0175 void SiPixelRawToDigi::produce(edm::Event& ev, const edm::EventSetup& es) {
0176   const uint32_t dummydetid = 0xffffffff;
0177 
0178   // initialize cabling map or update if necessary
0179   if (recordWatcher_.check(es)) {
0180     // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
0181     edm::ESHandle<SiPixelFedCablingMap> cablingMap = es.getHandle(cablingMapToken_);
0182     fedIds_ = cablingMap->fedIds();
0183     cabling_ = cablingMap->cablingTree();
0184     LogDebug("map version:") << cabling_->version();
0185   }
0186   // initialize quality record or update if necessary
0187   if (qualityWatcher_.check(es) && useQuality_) {
0188     // quality info for dead pixel modules or ROCs
0189     edm::ESHandle<SiPixelQuality> qualityInfo = es.getHandle(siPixelQualityToken_);
0190     badPixelInfo_ = qualityInfo.product();
0191     if (!badPixelInfo_) {
0192       edm::LogError("SiPixelQualityNotPresent") << "Configured to use SiPixelQuality, but SiPixelQuality not present";
0193     }
0194   }
0195 
0196   edm::Handle<FEDRawDataCollection> buffers;
0197   ev.getByToken(fedRawDataCollectionToken_, buffers);
0198 
0199   // create product (digis & errors)
0200   auto collection = edm::DetSetVector<PixelDigi>();
0201   // collection->reserve(8*1024);
0202   auto errorcollection = edm::DetSetVector<SiPixelRawDataError>{};
0203   auto tkerror_detidcollection = DetIdCollection{};
0204   auto usererror_detidcollection = DetIdCollection{};
0205   auto disabled_channelcollection = edmNew::DetSetVector<PixelFEDChannel>{};
0206 
0207   PixelDataFormatter formatter(cabling_.get(), usePhase1_);  // for phase 1 & 0
0208 
0209   formatter.setErrorStatus(includeErrors_);
0210 
0211   if (useQuality_)
0212     formatter.setQualityStatus(useQuality_, badPixelInfo_);
0213 
0214   bool errorsInEvent = false;
0215   PixelDataFormatter::DetErrors nodeterrors;
0216 
0217   if (regions_) {
0218     regions_->run(ev, es);
0219     formatter.setModulesToUnpack(regions_->modulesToUnpack());
0220     LogDebug("SiPixelRawToDigi") << "region2unpack #feds: " << regions_->nFEDs();
0221     LogDebug("SiPixelRawToDigi") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules() << " "
0222                                  << regions_->nForwardModules() << " " << regions_->nModules();
0223   }
0224 
0225   for (auto aFed = fedIds_.begin(); aFed != fedIds_.end(); ++aFed) {
0226     int fedId = *aFed;
0227 
0228     if (!usePilotBlade_ && (fedId == 40))
0229       continue;  // skip pilot blade data
0230 
0231     if (regions_ && !regions_->mayUnpackFED(fedId))
0232       continue;
0233 
0234     LogDebug("SiPixelRawToDigi") << "PRODUCE DIGI FOR FED:" << fedId;
0235 
0236     PixelDataFormatter::Errors errors;
0237 
0238     //get event data for this fed
0239     const FEDRawData& fedRawData = buffers->FEDData(fedId);
0240 
0241     //convert data to digi and strip off errors
0242     formatter.interpretRawData(errorsInEvent, fedId, fedRawData, collection, errors);
0243 
0244     //pack errors into collection
0245     if (includeErrors_) {
0246       formatter.unpackFEDErrors(errors,
0247                                 tkerrorlist_,
0248                                 usererrorlist_,
0249                                 errorcollection,
0250                                 tkerror_detidcollection,
0251                                 usererror_detidcollection,
0252                                 disabled_channelcollection,
0253                                 nodeterrors);
0254     }  // if errors to be included in the event
0255   }    // loop on FED data to be unpacked
0256 
0257   if (includeErrors_) {
0258     edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection.find_or_insert(dummydetid);
0259     errorDetSet.data = nodeterrors;
0260   }
0261   if (errorsInEvent)
0262     LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
0263 
0264   ev.emplace(siPixelDigiCollectionToken_, std::move(collection));
0265   if (includeErrors_) {
0266     ev.emplace(errorPutToken_, std::move(errorcollection));
0267     ev.emplace(tkErrorPutToken_, std::move(tkerror_detidcollection));
0268     ev.emplace(userErrorPutToken_, std::move(usererror_detidcollection));
0269     ev.emplace(disabledChannelPutToken_, std::move(disabled_channelcollection));
0270   }
0271 }
0272 // declare this as a framework plugin
0273 #include "FWCore/Framework/interface/MakerMacros.h"
0274 DEFINE_FWK_MODULE(SiPixelRawToDigi);