Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:50

0001 /* \file SiStripSpyDisplayModule.cc
0002  * \brief File containing code for the SiStripMonitorFEDProcessing plugin module.
0003  */
0004 // -*- C++ -*-
0005 //
0006 // Package:    SiStripMonitorHardware
0007 // Class:      SiStripSpyDisplayModule
0008 //
0009 // Standard
0010 #include <memory>
0011 #include <vector>
0012 #include <iostream>
0013 #include <string>
0014 #include <sstream>
0015 
0016 // Framework include files
0017 #include "FWCore/Utilities/interface/EDGetToken.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/Framework/interface/ESWatcher.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 
0025 // Needed for the SST cabling
0026 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0027 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0028 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0029 
0030 // Needed for the pedestal values
0031 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0032 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
0033 
0034 // Needed for the noise values
0035 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0036 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
0037 
0038 // For translating between FED key and det ID
0039 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0040 
0041 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0042 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0043 #include "DataFormats/SiStripDigi/interface/SiStripProcessedRawDigi.h"
0044 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0045 #include "DataFormats/Common/interface/DetSetVector.h"
0046 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0047 
0048 // Needed for the FED raw data processing
0049 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0050 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferGenerator.h"
0051 
0052 // #include "EventFilter/SiStripRawToDigi/interface/SiStripDigiToRaw.h"
0053 
0054 //for cabling
0055 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
0056 
0057 // For plotting
0058 #include "FWCore/ServiceRegistry/interface/Service.h"
0059 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0060 #include "TH1S.h"
0061 #include "TH1D.h"
0062 
0063 //
0064 // constants, enums and typedefs
0065 //
0066 enum FEDSpyHistogramType {
0067   SCOPE_MODE,
0068   PAYLOAD_RAW,
0069   REORDERED_PAYLOAD_RAW,
0070   REORDERED_MODULE_RAW,
0071   PEDESTAL_VALUES,
0072   NOISE_VALUES,
0073   POST_PEDESTAL,
0074   POST_COMMON_MODE,
0075   ZERO_SUPPRESSED_PADDED,
0076   ZERO_SUPPRESSED,
0077   VR_COMP,
0078   ZERO_SUPPRESSED_COMP
0079 };
0080 
0081 //
0082 // class declaration
0083 //
0084 
0085 /*! \brief EDAnalyzer for the online monitoring of the FED using STT spy channel data.
0086  *
0087  * \author Tom Whyntie
0088  * \date Autumn 2009
0089  * 
0090  * See https://twiki.cern.ch/twiki/bin/view/CMS/SiStripSpyDisplayModule for
0091  * further code documentation, and
0092  * https://twiki.cern.ch/twiki/bin/view/CMS/FEDSpyChannelMonitoring
0093  * for more information about the spy channel monitoring project.
0094  *
0095  */
0096 class SiStripSpyDisplayModule : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0097 public:
0098   explicit SiStripSpyDisplayModule(const edm::ParameterSet&);
0099   ~SiStripSpyDisplayModule() override;
0100 
0101 private:
0102   void beginJob() override;
0103   void analyze(const edm::Event&, const edm::EventSetup&) override;
0104   void endJob() override;
0105 
0106   Bool_t MakeRawDigiHist_(const edm::Handle<edm::DetSetVector<SiStripRawDigi> >& digi_handle,
0107                           uint32_t specifier,
0108                           const TFileDirectory& dir,
0109                           FEDSpyHistogramType type);
0110 
0111   Bool_t MakeProcessedRawDigiHist_(const edm::Handle<edm::DetSetVector<SiStripProcessedRawDigi> >& digi_handle,
0112                                    uint32_t specifier,
0113                                    const TFileDirectory& dir,
0114                                    FEDSpyHistogramType type);
0115 
0116   Bool_t MakeDigiHist_(const edm::Handle<edm::DetSetVector<SiStripDigi> >& digi_handle,
0117                        uint32_t detID,
0118                        const TFileDirectory& dir,
0119                        FEDSpyHistogramType type);
0120 
0121   // ----------member data ---------------------------
0122   std::vector<uint32_t> detIDs_;  //!< Vector of detIDs that are of interest (config-specified).
0123   //now from utility class
0124   //    edm::ESHandle<SiStripDetCabling> cabling_;        //!< The Strip Tracker cabling object.
0125   edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> detCablingToken_;
0126   const SiStripDetCabling* detCabling_;
0127   edm::ESWatcher<SiStripDetCablingRcd> cablingWatcher_;
0128   void updateDetCabling(const SiStripDetCablingRcd& rcd);
0129 
0130   // Data input labels
0131   //===================
0132   edm::InputTag inputScopeModeRawDigiLabel_;         //!< Label for the scope-mode RawDigi collection input tag
0133   edm::InputTag inputPayloadRawDigiLabel_;           //!< Label for the virgin raw RawDigi collection input tag.
0134   edm::InputTag inputReorderedPayloadRawDigiLabel_;  //!< Label for the re-ordered RawDigi module input tag.
0135   edm::InputTag inputReorderedModuleRawDigiLabel_;   //!< Label for the re-ordered RawDigi module input tag.
0136   edm::InputTag inputPedestalsLabel_;                //!< Label for the pedestals.
0137   edm::InputTag inputNoisesLabel_;                   //!< Label for the noises.
0138   edm::InputTag inputPostPedestalRawDigiLabel_;  //!< Label for the post-pedestal subtraction RawDigi module input tag.
0139   edm::InputTag inputPostCMRawDigiLabel_;  //!< Label for the post-common mode subtraction RawDigi module input tag.
0140   edm::InputTag
0141       inputZeroSuppressedRawDigiLabel_;  //!< Label for the zero-suppressed, zero-padded RawDigi module input tag.
0142   edm::InputTag inputZeroSuppressedDigiLabel_;      //!< Guess what? It's the input label for the zero-suppressed digi
0143   edm::InputTag inputCompVirginRawDigiLabel_;       //!< VR RawDigis to compare (from mainline)
0144   edm::InputTag inputCompZeroSuppressedDigiLabel_;  //!< Zero-suppressed digis to compare (from mainline)
0145 
0146   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0147       inputScopeModeRawDigiToken_;  //!< Token for the scope-mode RawDigi collection input tag
0148   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0149       inputPayloadRawDigiToken_;  //!< Token for the virgin raw RawDigi collection input tag.
0150   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0151       inputReorderedPayloadRawDigiToken_;  //!< Token for the re-ordered RawDigi module input tag.
0152   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0153       inputReorderedModuleRawDigiToken_;  //!< Token for the re-ordered RawDigi module input tag.
0154   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> > inputPedestalsToken_;        //!< Token for the pedestals.
0155   edm::EDGetTokenT<edm::DetSetVector<SiStripProcessedRawDigi> > inputNoisesToken_;  //!< Token for the noises.
0156   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0157       inputPostPedestalRawDigiToken_;  //!< Token for the post-pedestal subtraction RawDigi module input tag.
0158   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0159       inputPostCMRawDigiToken_;  //!< Token for the post-common mode subtraction RawDigi module input tag.
0160   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0161       inputZeroSuppressedRawDigiToken_;  //!< Token for the zero-suppressed, zero-padded RawDigi module input tag.
0162   edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> >
0163       inputZeroSuppressedDigiToken_;  //!< Guess what? It's the input label for the zero-suppressed digi
0164   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> >
0165       inputCompVirginRawDigiToken_;  //!< VR RawDigis to compare (from mainline)
0166   edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> >
0167       inputCompZeroSuppressedDigiToken_;  //!< Zero-suppressed digis to compare (from mainline)
0168   //
0169   // Output information
0170   //====================
0171   std::string outputFolderName_;  //!< Name for the folder in the TFileService file output.
0172 
0173 };  // end of SiStripSpyDisplayModule class
0174 
0175 //
0176 // static data member definitions
0177 //
0178 
0179 using namespace sistrip;
0180 using namespace std;
0181 
0182 //
0183 // constructors and destructor
0184 //
0185 SiStripSpyDisplayModule::SiStripSpyDisplayModule(const edm::ParameterSet& iConfig)
0186     : detIDs_(iConfig.getParameter<std::vector<uint32_t> >("detIDs")),
0187       detCablingToken_(esConsumes<>()),
0188       cablingWatcher_(this, &SiStripSpyDisplayModule::updateDetCabling),
0189       inputScopeModeRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputScopeModeRawDigiLabel")),
0190       inputPayloadRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputPayloadRawDigiLabel")),
0191       inputReorderedPayloadRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputReorderedPayloadRawDigiLabel")),
0192       inputReorderedModuleRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputReorderedModuleRawDigiLabel")),
0193       inputPedestalsLabel_(iConfig.getParameter<edm::InputTag>("InputPedestalsLabel")),
0194       inputNoisesLabel_(iConfig.getParameter<edm::InputTag>("InputNoisesLabel")),
0195       inputPostPedestalRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputPostPedestalRawDigiLabel")),
0196       inputPostCMRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputPostCMRawDigiLabel")),
0197       inputZeroSuppressedRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputZeroSuppressedRawDigiLabel")),
0198       inputZeroSuppressedDigiLabel_(iConfig.getParameter<edm::InputTag>("InputZeroSuppressedDigiLabel")),
0199       inputCompVirginRawDigiLabel_(iConfig.getParameter<edm::InputTag>("InputCompVirginRawDigiLabel")),
0200       inputCompZeroSuppressedDigiLabel_(iConfig.getParameter<edm::InputTag>("InputCompZeroSuppressedDigiLabel")),
0201       outputFolderName_(iConfig.getParameter<std::string>("OutputFolderName")) {
0202   //now do what ever initialization is needed
0203   inputScopeModeRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputScopeModeRawDigiLabel_);
0204   inputPayloadRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputPayloadRawDigiLabel_);
0205   inputReorderedPayloadRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputReorderedPayloadRawDigiLabel_);
0206   inputReorderedModuleRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputReorderedModuleRawDigiLabel_);
0207   inputPedestalsToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputPedestalsLabel_);
0208   inputNoisesToken_ = consumes<edm::DetSetVector<SiStripProcessedRawDigi> >(inputNoisesLabel_);
0209   inputPostPedestalRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputPostPedestalRawDigiLabel_);
0210   inputPostCMRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputPostCMRawDigiLabel_);
0211   inputZeroSuppressedRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputZeroSuppressedRawDigiLabel_);
0212   inputZeroSuppressedDigiToken_ = consumes<edm::DetSetVector<SiStripDigi> >(inputZeroSuppressedDigiLabel_);
0213   inputCompVirginRawDigiToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(inputCompVirginRawDigiLabel_);
0214   inputCompZeroSuppressedDigiToken_ = consumes<edm::DetSetVector<SiStripDigi> >(inputCompZeroSuppressedDigiLabel_);
0215 
0216   usesResource(TFileService::kSharedResource);
0217 }
0218 
0219 SiStripSpyDisplayModule::~SiStripSpyDisplayModule() {
0220   // do anything here that needs to be done at desctruction time
0221   // (e.g. close files, deallocate resources etc.)
0222 }
0223 
0224 //
0225 // member functions
0226 //
0227 //
0228 
0229 void SiStripSpyDisplayModule::updateDetCabling(const SiStripDetCablingRcd& rcd) {
0230   detCabling_ = &rcd.get(detCablingToken_);
0231 }
0232 
0233 // ------------ method called once each job just before starting event loop  ------------
0234 void SiStripSpyDisplayModule::beginJob() {
0235   // register to the TFileService
0236   edm::Service<TFileService> fs;
0237   // Check that the TFileService has been configured
0238   if (!fs.isAvailable()) {
0239     throw cms::Exception("Configuration") << "TFileService not available: did you configure it ?";
0240   }
0241 }  // end of beginJob method.
0242 
0243 // ------------ method called once each job just after ending the event loop  ------------
0244 void SiStripSpyDisplayModule::endJob() {}
0245 
0246 // ------------ method called to for each event  ------------
0247 void SiStripSpyDisplayModule::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0248   using namespace edm;
0249   using namespace std;
0250 
0251   cablingWatcher_.check(iSetup);
0252 
0253   // Set up the event-level histogram folder
0254   //-----------------------------------------
0255   // register to the TFileService
0256   edm::Service<TFileService> fs;
0257 
0258   // Make the EDAnalyzer instance name directory
0259   TFileDirectory an_dir = fs->mkdir(outputFolderName_);
0260 
0261   // Make the event directory filename
0262   stringstream ev_dir_name;
0263   ev_dir_name << "run" << iEvent.id().run() << "_event" << iEvent.id().event();
0264   TFileDirectory evdir = an_dir.mkdir(ev_dir_name.str());
0265 
0266   //if there are no detIds, get them from the comparison digis...
0267   if (detIDs_.empty()) {
0268     //get the detIds of the modules in the zero-suppressed comparison
0269     if (!((inputCompZeroSuppressedDigiLabel_.label().empty()) &&
0270           (inputCompZeroSuppressedDigiLabel_.instance().empty()))) {
0271       edm::Handle<edm::DetSetVector<SiStripDigi> > czs_digis;
0272       //            iEvent.getByLabel( inputCompZeroSuppressedDigiLabel_, czs_digis );
0273       iEvent.getByToken(inputCompZeroSuppressedDigiToken_, czs_digis);
0274       std::vector<edm::DetSet<SiStripDigi> >::const_iterator digis_it = czs_digis->begin();
0275       for (; digis_it != czs_digis->end(); ++digis_it) {
0276         detIDs_.push_back(digis_it->detId());
0277       }
0278     } else if (!((inputCompVirginRawDigiLabel_.label().empty()) && (inputCompVirginRawDigiLabel_.instance().empty()))) {
0279       edm::Handle<edm::DetSetVector<SiStripRawDigi> > cvr_digis;
0280       //            iEvent.getByLabel( inputCompVirginRawDigiLabel_, cvr_digis );
0281       iEvent.getByToken(inputCompVirginRawDigiToken_, cvr_digis);
0282       std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digis_it = cvr_digis->begin();
0283       for (; digis_it != cvr_digis->end(); ++digis_it) {
0284         detIDs_.push_back(digis_it->detId());
0285       }
0286     }
0287   }
0288 
0289   // Loop over detIDs as obtained from the SpyChannelMonitor config file.
0290   for (std::vector<uint32_t>::iterator d = detIDs_.begin(); d != detIDs_.end(); ++d) {
0291     // TODO: Need some error checking here, probably...
0292     const std::vector<const FedChannelConnection*>& conns = detCabling_->getConnections(*d);
0293     //cout << "________________________________________________" << endl;
0294     //cout << "FED channels found in detId " << *d << " is " << conns.size() << endl;
0295     if (conns.empty()) {
0296       // TODO: Properly DEBUG/warning this...
0297       //cout << "Skipping detID " << uint32_t(*d) << endl;
0298       continue;
0299     }
0300 
0301     // Create a histogram directory for each specified and available detID
0302     stringstream sss;  //!< detID folder filename
0303     sss << "detID_" << *d;
0304     TFileDirectory detID_dir = evdir.mkdir(sss.str());
0305 
0306     // Loop over the channels found with the detID and add directories.
0307     for (uint32_t ch = 0; ch < conns.size(); ch++) {
0308       if (conns[ch] && conns[ch]->isConnected()) {
0309         // Name of channel histogram directory
0310         stringstream ssss;
0311         ssss << sss.str() << "_APVpair_" << ch;
0312         TFileDirectory chan_dir = detID_dir.mkdir(ssss.str());
0313 
0314         // Get the fed key from the detID and the channel
0315         uint32_t fedkey = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
0316 
0317         // (Spy) Scope Mode (SM)
0318         //=======================
0319         // Get the fed key from the FED ID and the FED channel (from conns)
0320         // This is because scope mode always stores in the collection by FED ID
0321         if (!((inputScopeModeRawDigiLabel_.label().empty()) && (inputScopeModeRawDigiLabel_.instance().empty()))) {
0322           // Use the SiStripFedKey object to return the FED key
0323           //cout << "detID=" << *d << ", FED key looking for is " << fedkey << endl;
0324           //cout << "Attempting to find scope mode raw digis" << endl;
0325           //
0326           edm::Handle<edm::DetSetVector<SiStripRawDigi> > sm_rawdigis;
0327           //                iEvent.getByLabel( inputScopeModeRawDigiLabel_, sm_rawdigis );
0328           iEvent.getByToken(inputScopeModeRawDigiToken_, sm_rawdigis);
0329           //
0330           // Note that the fed key (also a uint32_t) is passed in this case.
0331           // The method itself doesn't actually care, but it assumes whatever collection
0332           // is stored in sm_rawdigis is indexed by FED key ;-)
0333           // TODO: Make this, um, better.
0334           if (!(MakeRawDigiHist_(sm_rawdigis, fedkey, chan_dir, SCOPE_MODE))) {
0335             ;
0336           }
0337         }
0338 
0339         // Payload Unordered Raw (UR)
0340         //============================
0341         if (!((inputPayloadRawDigiLabel_.label().empty()) && (inputPayloadRawDigiLabel_.instance().empty()))) {
0342           uint32_t fedindex = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
0343           //cout << "Attempting to find payload mode raw digis" << endl;
0344           edm::Handle<edm::DetSetVector<SiStripRawDigi> > ur_rawdigis;
0345           //                iEvent.getByLabel( inputPayloadRawDigiLabel_, ur_rawdigis );
0346           iEvent.getByToken(inputPayloadRawDigiToken_, ur_rawdigis);
0347           if (!(MakeRawDigiHist_(ur_rawdigis, fedindex, chan_dir, PAYLOAD_RAW))) {
0348             ;
0349           }
0350         }
0351         // Payload Reordered Raw
0352         //=======================
0353         if (!((inputReorderedPayloadRawDigiLabel_.label().empty()) &&
0354               (inputReorderedPayloadRawDigiLabel_.instance().empty()))) {
0355           uint32_t fedkey = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
0356           edm::Handle<edm::DetSetVector<SiStripRawDigi> > rrp_rawdigis;
0357           //                iEvent.getByLabel( inputReorderedPayloadRawDigiLabel_, rrp_rawdigis );
0358           iEvent.getByToken(inputReorderedPayloadRawDigiToken_, rrp_rawdigis);
0359           if (!(MakeRawDigiHist_(rrp_rawdigis, fedkey, chan_dir, REORDERED_PAYLOAD_RAW))) {
0360             ;
0361           }
0362         }
0363       }
0364     }  // end of loop over channels
0365     //
0366     // Module Reordered Raw (RR)
0367     //====================
0368     if (!((inputReorderedModuleRawDigiLabel_.label().empty()) &&
0369           (inputReorderedModuleRawDigiLabel_.instance().empty()))) {
0370       edm::Handle<edm::DetSetVector<SiStripRawDigi> > rr_rawdigis;
0371       //            iEvent.getByLabel( inputReorderedModuleRawDigiLabel_, rr_rawdigis );
0372       iEvent.getByToken(inputReorderedModuleRawDigiToken_, rr_rawdigis);
0373       //cout << "Making Reordered module histogram for detID " << *d << endl;
0374       if (!(MakeRawDigiHist_(rr_rawdigis, *d, detID_dir, REORDERED_MODULE_RAW))) {
0375         ;
0376       }
0377     }  // end of ReorderedModuleRaw check
0378 
0379     //
0380     // Pedestal values
0381     //========================
0382     if (!((inputPedestalsLabel_.label().empty()) && (inputPedestalsLabel_.instance().empty()))) {
0383       edm::Handle<edm::DetSetVector<SiStripRawDigi> > pd_rawdigis;
0384       //            iEvent.getByLabel( inputPedestalsLabel_, pd_rawdigis );
0385       iEvent.getByToken(inputPedestalsToken_, pd_rawdigis);
0386       //cout << "Making pedestal values module histogram for detID " << *d << endl;
0387       if (!(MakeRawDigiHist_(pd_rawdigis, *d, detID_dir, PEDESTAL_VALUES))) {
0388         ;
0389       }
0390     }
0391     //
0392     // Noise values
0393     //========================
0394     if (!((inputNoisesLabel_.label().empty()) && (inputNoisesLabel_.instance().empty()))) {
0395       edm::Handle<edm::DetSetVector<SiStripProcessedRawDigi> > pd_rawdigis;
0396       //            iEvent.getByLabel( inputNoisesLabel_, pd_rawdigis );
0397       iEvent.getByToken(inputNoisesToken_, pd_rawdigis);
0398       //cout << "Making noise values module histogram for detID " << *d << endl;
0399       if (!(MakeProcessedRawDigiHist_(pd_rawdigis, *d, detID_dir, NOISE_VALUES))) {
0400         ;
0401       }
0402     }
0403     //
0404     // Post-Pedestal Raw (PP)
0405     //========================
0406     if (!((inputPostPedestalRawDigiLabel_.label().empty()) && (inputPostPedestalRawDigiLabel_.instance().empty()))) {
0407       edm::Handle<edm::DetSetVector<SiStripRawDigi> > pp_rawdigis;
0408       //            iEvent.getByLabel( inputPostPedestalRawDigiLabel_, pp_rawdigis );
0409       iEvent.getByToken(inputPostPedestalRawDigiToken_, pp_rawdigis);
0410       //cout << "Making post-pedestal module histogram for detID " << *d << endl;
0411       if (!(MakeRawDigiHist_(pp_rawdigis, *d, detID_dir, POST_PEDESTAL))) {
0412         ;
0413       }
0414     }
0415     //
0416     // Post-Common Mode Subtraction Raw (PC)
0417     //=======================================
0418     if (!((inputPostCMRawDigiLabel_.label().empty()) && (inputPostCMRawDigiLabel_.instance().empty()))) {
0419       edm::Handle<edm::DetSetVector<SiStripRawDigi> > pc_rawdigis;
0420       //            iEvent.getByLabel( inputPostCMRawDigiLabel_, pc_rawdigis );
0421       iEvent.getByToken(inputPostCMRawDigiToken_, pc_rawdigis);
0422       //cout << "Making post-CM module histogram for detID " << *d << endl;
0423       if (!(MakeRawDigiHist_(pc_rawdigis, *d, detID_dir, POST_COMMON_MODE))) {
0424         ;
0425       }
0426     }
0427 
0428     //
0429     // Zero-Suppressed Digis
0430     //=======================
0431     //bool founddigispy = false, founddigimain = false;
0432     if (!((inputZeroSuppressedDigiLabel_.label().empty()) && (inputZeroSuppressedDigiLabel_.instance().empty()))) {
0433       //cout << "Making ZeroSuppressed histogram!" << endl;
0434       edm::Handle<edm::DetSetVector<SiStripDigi> > zs_digis;
0435       //            iEvent.getByLabel( inputZeroSuppressedDigiLabel_, zs_digis );
0436       iEvent.getByToken(inputZeroSuppressedDigiToken_, zs_digis);
0437       //founddigispy =
0438       MakeDigiHist_(zs_digis, *d, detID_dir, ZERO_SUPPRESSED);
0439     }
0440     //comparison to mainline data
0441     if (!((inputCompVirginRawDigiLabel_.label().empty()) && (inputCompVirginRawDigiLabel_.instance().empty()))) {
0442       //cout << "Making Mainline VirginRaw histogram!" << endl;
0443       edm::Handle<edm::DetSetVector<SiStripRawDigi> > cvr_digis;
0444       //            iEvent.getByLabel( inputCompVirginRawDigiLabel_, cvr_digis );
0445       iEvent.getByToken(inputCompVirginRawDigiToken_, cvr_digis);
0446       //founddigimain =
0447       MakeRawDigiHist_(cvr_digis, *d, detID_dir, VR_COMP);
0448     }
0449     if (!((inputCompZeroSuppressedDigiLabel_.label().empty()) &&
0450           (inputCompZeroSuppressedDigiLabel_.instance().empty()))) {
0451       //cout << "Making ZeroSuppressed histogram!" << endl;
0452       edm::Handle<edm::DetSetVector<SiStripDigi> > czs_digis;
0453       //            iEvent.getByLabel( inputCompZeroSuppressedDigiLabel_, czs_digis );
0454       iEvent.getByToken(inputCompZeroSuppressedDigiToken_, czs_digis);
0455       //founddigimain =
0456       MakeDigiHist_(czs_digis, *d, detID_dir, ZERO_SUPPRESSED_COMP);
0457     }
0458     //if (founddigimain && founddigispy) cout << "Found digis for both in detid=" << *d << endl;
0459 
0460   }  // end of loop over detIDs specified in the config.
0461 
0462 }  // end of Analyze method.
0463 
0464 Bool_t SiStripSpyDisplayModule::MakeRawDigiHist_(const edm::Handle<edm::DetSetVector<SiStripRawDigi> >& digi_handle,
0465                                                  uint32_t specifier,
0466                                                  const TFileDirectory& dir,
0467                                                  FEDSpyHistogramType type)
0468 //const std::string & name)
0469 {
0470   // TODO: Remove the hard-coded numbers(!).
0471   TH1S* hist;
0472   if (type == SCOPE_MODE)
0473     hist = dir.make<TH1S>("ScopeMode", ";Sample number;ADC counts / strip", 298, 0, 298);
0474   else if (type == PAYLOAD_RAW)
0475     hist = dir.make<TH1S>("PayloadRaw", ";Sample number;ADC counts / strip", 256, 0, 256);
0476   else if (type == REORDERED_PAYLOAD_RAW)
0477     hist = dir.make<TH1S>("ReorderedPayloadRaw", ";Sample number;ADC counts / strip", 256, 0, 256);
0478   else if (type == REORDERED_MODULE_RAW)
0479     hist = dir.make<TH1S>("ReorderedModuleRaw", ";Sample number;ADC counts / strip", 768, 0, 768);
0480   else if (type == PEDESTAL_VALUES)
0481     hist = dir.make<TH1S>("PedestalValues", ";Strip number;Pedestal / strip", 768, 0, 768);
0482   else if (type == POST_PEDESTAL)
0483     hist = dir.make<TH1S>("PostPedestal", ";Strip number;ADC counts / strip", 768, 0, 768);
0484   else if (type == POST_COMMON_MODE)
0485     hist = dir.make<TH1S>("PostCommonMode", ";Strip number;ADC counts / strip", 768, 0, 768);
0486   else if (type == ZERO_SUPPRESSED_PADDED)
0487     hist = dir.make<TH1S>("ZeroSuppressedRaw", ";Strip number;ADC counts / strip", 768, 0, 768);
0488   else if (type == VR_COMP)
0489     hist = dir.make<TH1S>("VirginRawCom", ";Strip number;ADC counts / strip", 768, 0, 768);
0490   else {
0491     hist = nullptr;
0492     return false;
0493   }
0494 
0495   // TODO: May need to make this error checking independent when refactoring...
0496   //std::cout << "| * digis for " << type << " and detID " << specifier;
0497   std::vector<edm::DetSet<SiStripRawDigi> >::const_iterator digis_it = digi_handle->find(specifier);
0498   if (digis_it == digi_handle->end()) {
0499     //std::cout << " not found :( ";
0500     return false;
0501   }
0502   //std::cout << std::endl;
0503 
0504   // Loop over the digis for the detID and APV pair.
0505   edm::DetSet<SiStripRawDigi>::const_iterator idigi = digis_it->data.begin();
0506   uint32_t count = 0;
0507   for (; idigi != digis_it->data.end(); ++idigi) {
0508     count++;
0509     hist->SetBinContent(count, static_cast<int>((*idigi).adc()));
0510   }             // end of loop over the digis
0511   return true;  // Success! (Probably.)
0512 }
0513 
0514 Bool_t SiStripSpyDisplayModule::MakeProcessedRawDigiHist_(
0515     const edm::Handle<edm::DetSetVector<SiStripProcessedRawDigi> >& digi_handle,
0516     uint32_t specifier,
0517     const TFileDirectory& dir,
0518     FEDSpyHistogramType type)
0519 //const std::string & name)
0520 {
0521   // TODO: Remove the hard-coded numbers(!).
0522   TH1F* hist;
0523   if (type == NOISE_VALUES)
0524     hist = dir.make<TH1F>("NoiseValues", ";Strip number;Noise / strip", 768, 0, 768);
0525   else {
0526     hist = nullptr;
0527     return false;
0528   }
0529 
0530   // TODO: May need to make this error checking independent when refactoring...
0531   //std::cout << "| * digis for " << type << " and detID " << specifier;
0532   std::vector<edm::DetSet<SiStripProcessedRawDigi> >::const_iterator digis_it = digi_handle->find(specifier);
0533   if (digis_it == digi_handle->end()) {
0534     //std::cout << " not found :( ";
0535     return false;
0536   }
0537   //std::cout << std::endl;
0538 
0539   // Loop over the digis for the detID and APV pair.
0540   edm::DetSet<SiStripProcessedRawDigi>::const_iterator idigi = digis_it->data.begin();
0541   uint32_t count = 0;
0542   for (; idigi != digis_it->data.end(); ++idigi) {
0543     count++;
0544     hist->SetBinContent(count, static_cast<float>((*idigi).adc()));
0545   }             // end of loop over the digis
0546   return true;  // Success! (Probably.)
0547 }
0548 
0549 Bool_t SiStripSpyDisplayModule::MakeDigiHist_(const edm::Handle<edm::DetSetVector<SiStripDigi> >& digi_handle,
0550                                               uint32_t detID,
0551                                               //uint32_t channel,
0552                                               const TFileDirectory& dir,
0553                                               FEDSpyHistogramType type)
0554 //const std::string & name)
0555 {
0556   // TODO: Remove the hard-coded numbers.
0557   TH1S* hist;
0558   if (type == ZERO_SUPPRESSED)
0559     hist = dir.make<TH1S>("ZeroSuppressedDigi", ";Strip number;ADC counts / strip", 768, 0, 768);
0560   else if (type == ZERO_SUPPRESSED_COMP)
0561     hist = dir.make<TH1S>("ZeroSuppressedDigiComp", ";Strip number;ADC counts / strip", 768, 0, 768);
0562   else {
0563     hist = nullptr;
0564     return false;
0565   }
0566 
0567   // TODO: May need to make this error checking independent when refactoring...
0568   std::vector<edm::DetSet<SiStripDigi> >::const_iterator digis_it = digi_handle->find(detID);
0569   if (digis_it == digi_handle->end()) {
0570     return false;
0571   } else {
0572     //cout << "--* ZS digis found for detID " << detID << endl;
0573   }
0574 
0575   // Loop over the digis for the detID and APV pair.
0576   edm::DetSet<SiStripDigi>::const_iterator idigi = digis_it->data.begin();
0577   bool founddigi = false;
0578   for (; idigi != digis_it->data.end(); ++idigi) {
0579     // Check strip number is within the channel limits
0580     //if ( static_cast<uint16_t>( (*idigi).strip()/256. ) == channel ) {
0581     //    hist->SetBinContent( ((*idigi).strip())%256 + 1,(*idigi).adc());
0582     //}
0583     hist->SetBinContent(static_cast<int>(((*idigi).strip())) + 1, static_cast<int>((*idigi).adc()));
0584     if ((*idigi).adc() > 0)
0585       founddigi = true;
0586     //cout << "----* ZS digi found at " << static_cast<int>(((*idigi).strip()))
0587     //     << ", " << static_cast<int>((*idigi).adc()) << endl;
0588   }  // end of loop over the digis
0589 
0590   return founddigi;
0591 }
0592 
0593 // Define this as a plug-in
0594 DEFINE_FWK_MODULE(SiStripSpyDisplayModule);