Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-31 23:14:00

0001 
0002 // -*- C++ -*-
0003 //
0004 // Class:      SiStripShotFilterPlugins
0005 //
0006 /* Description: DQM source application to filter "shots" for SiStrip data
0007 */
0008 //
0009 //         Created:  2009/12/07
0010 //
0011 
0012 #include <sstream>
0013 #include <fstream>
0014 #include <iostream>
0015 #include <memory>
0016 #include <list>
0017 #include <algorithm>
0018 #include <cassert>
0019 
0020 #include "FWCore/Utilities/interface/EDGetToken.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/one/EDFilter.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/ESWatcher.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/Utilities/interface/InputTag.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "FWCore/ServiceRegistry/interface/Service.h"
0030 #include "FWCore/Utilities/interface/Exception.h"
0031 
0032 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0033 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0034 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0035 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0036 #include "DataFormats/DetId/interface/DetId.h"
0037 
0038 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0039 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0040 
0041 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0042 
0043 #include "DataFormats/Common/interface/DetSetVector.h"
0044 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0045 
0046 #include "DQM/SiStripCommon/interface/APVShotFinder.h"
0047 #include "DQM/SiStripCommon/interface/APVShot.h"
0048 
0049 //
0050 // Class declaration
0051 //
0052 
0053 class SiStripShotFilter : public edm::one::EDFilter<> {
0054 public:
0055   explicit SiStripShotFilter(const edm::ParameterSet&);
0056   ~SiStripShotFilter() override;
0057 
0058 private:
0059   void beginJob() override;
0060   bool filter(edm::Event&, const edm::EventSetup&) override;
0061   void endJob() override;
0062 
0063   //update the cabling if necessary
0064   void updateCabling(const SiStripFedCablingRcd& cablingRcd);
0065 
0066   //path to output file
0067   std::ofstream fOut_;
0068   std::string fOutPath_;
0069   //FED cabling
0070   const SiStripFedCabling* cabling_;
0071   edm::ESWatcher<SiStripFedCablingRcd> fedCablingWatcher_;
0072   edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0073 
0074   edm::InputTag digicollection_;
0075   edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> > digiToken_;
0076   bool zs_;
0077 };
0078 
0079 //
0080 // Constructors and destructor
0081 //
0082 
0083 SiStripShotFilter::SiStripShotFilter(const edm::ParameterSet& iConfig)
0084     : fOutPath_(iConfig.getUntrackedParameter<std::string>("OutputFilePath", "shotChannels.dat")),
0085       fedCablingWatcher_(this, &SiStripShotFilter::updateCabling),
0086       fedCablingToken_(esConsumes<>()),
0087       digicollection_(iConfig.getParameter<edm::InputTag>("DigiCollection")),
0088       zs_(iConfig.getUntrackedParameter<bool>("ZeroSuppressed", true))
0089 
0090 {
0091   digiToken_ = consumes<edm::DetSetVector<SiStripDigi> >(digicollection_);
0092 }
0093 
0094 SiStripShotFilter::~SiStripShotFilter() {}
0095 
0096 //
0097 // Member functions
0098 //
0099 
0100 // ------------ method called to for each event  ------------
0101 bool SiStripShotFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0102   fedCablingWatcher_.check(iSetup);
0103   //get digi data
0104   edm::Handle<edm::DetSetVector<SiStripDigi> > digis;
0105   iEvent.getByToken(digiToken_, digis);
0106 
0107   // loop on detector with digis
0108 
0109   APVShotFinder apvsf(*digis, zs_);
0110   const std::vector<APVShot>& shots = apvsf.getShots();
0111 
0112   //loop on feds first: there should be only a small number of shots...
0113   //better to loop only once on all channels....
0114   //to be able to output both fed/ch and module/APV.
0115 
0116   unsigned int lShots = 0;
0117 
0118   for (unsigned int fedId = FEDNumbering::MINSiStripFEDID; fedId <= FEDNumbering::MAXSiStripFEDID;
0119        fedId++) {  //loop over FED IDs
0120 
0121     for (unsigned int iCh = 0; iCh < sistrip::FEDCH_PER_FED; iCh++) {  //loop on channels
0122 
0123       const FedChannelConnection& lConnection = cabling_->fedConnection(fedId, iCh);
0124 
0125       uint32_t lDetId = lConnection.detId();
0126       short lAPVPair = lConnection.apvPairNumber();
0127 
0128       for (std::vector<APVShot>::const_iterator shot = shots.begin(); shot != shots.end(); ++shot) {  //loop on shots
0129 
0130         if (shot->detId() == lDetId && static_cast<short>(shot->apvNumber() / 2.) == lAPVPair) {
0131           if (shot->isGenuine()) {  //genuine shot
0132 
0133             fOut_ << fedId << " " << iCh << " " << shot->detId() << " " << shot->apvNumber() << std::endl;
0134             lShots++;
0135           }  //genuine shot
0136           if (shot->apvNumber() % 2 == 1)
0137             break;
0138         }
0139       }  //loop on shots
0140     }    //loop on channels
0141   }      //loop on FEDs.
0142 
0143   if (lShots > 0)
0144     fOut_ << "### " << iEvent.id().event() << " " << lShots << std::endl;
0145 
0146   return lShots;
0147 
0148 }  //analyze method
0149 
0150 // ------------ method called once each job just before starting event loop  ------------
0151 void SiStripShotFilter::beginJob() {
0152   fOut_.open(fOutPath_.c_str(), std::ios::out);
0153   if (!fOut_)
0154     std::cout << " WARNING ! Cannot open file " << fOutPath_
0155               << " for writting. List of shot channels will not be saved." << std::endl;
0156 }
0157 
0158 // ------------ method called once each job just after ending the event loop  ------------
0159 void SiStripShotFilter::endJob() { fOut_.close(); }
0160 
0161 void SiStripShotFilter::updateCabling(const SiStripFedCablingRcd& cablingRcd) {
0162   cabling_ = &cablingRcd.get(fedCablingToken_);
0163 }
0164 
0165 #include "FWCore/Framework/interface/MakerMacros.h"
0166 DEFINE_FWK_MODULE(SiStripShotFilter);