Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:35

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripTools
0004 // Class:      CommonModeAnalyzer
0005 //
0006 /**\class CommonModeAnalyzer CommonModeAnalyzer.cc DPGAnalysis/SiStripTools/plugins/CommonModeAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Tue Jul 19 11:56:00 CEST 2009
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "TH1D.h"
0024 #include "TProfile.h"
0025 #include <vector>
0026 #include <algorithm>
0027 #include <string>
0028 
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0031 #include "FWCore/Framework/interface/ESWatcher.h"
0032 
0033 #include "FWCore/Framework/interface/Event.h"
0034 #include "FWCore/Framework/interface/MakerMacros.h"
0035 
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039 
0040 #include "FWCore/ServiceRegistry/interface/Service.h"
0041 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0042 
0043 #include "FWCore/Utilities/interface/InputTag.h"
0044 
0045 #include "DataFormats/DetId/interface/DetId.h"
0046 #include "DataFormats/DetId/interface/DetIdCollection.h"
0047 
0048 #include "DataFormats/Common/interface/DetSetVector.h"
0049 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0050 
0051 #include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"
0052 #include "DPGAnalysis/SiStripTools/interface/APVCyclePhaseCollection.h"
0053 
0054 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
0055 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0056 
0057 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0058 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0059 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0060 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0061 //
0062 // class decleration
0063 //
0064 
0065 class CommonModeAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
0066 public:
0067   explicit CommonModeAnalyzer(const edm::ParameterSet&);
0068   ~CommonModeAnalyzer() override;
0069 
0070 private:
0071   void beginJob() override;
0072   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0073   void endRun(const edm::Run&, const edm::EventSetup&) override;
0074   void analyze(const edm::Event&, const edm::EventSetup&) override;
0075   void endJob() override;
0076 
0077   void updateDetCabling(const SiStripDetCablingRcd& iRcd);
0078 
0079   // ----------member data ---------------------------
0080 
0081   edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> > m_digicollectionToken;
0082   edm::EDGetTokenT<EventWithHistory> m_historyProductToken;
0083   edm::EDGetTokenT<APVCyclePhaseCollection> m_apvphasecollToken;
0084   edm::EDGetTokenT<DetIdCollection> m_digibadmodulecollectionToken;
0085   const std::string m_phasepart;
0086   const bool m_ignorebadfedmod;
0087   const bool m_ignorenotconnected;
0088   int m_nevents;
0089 
0090   std::vector<DetIdSelector> m_selections;
0091   std::vector<std::string> m_labels;
0092   std::vector<TH1D*> m_cmdist;
0093   std::vector<TH1D*> m_nmodules;
0094   std::vector<TH1D*> m_napvs;
0095   std::vector<TProfile*> m_cmvsdbxincycle;
0096   std::vector<TProfile**> m_cmvsbxrun;
0097   std::vector<TProfile**> m_cmvsorbitrun;
0098 
0099   RunHistogramManager m_rhm;
0100 
0101   edm::ESWatcher<SiStripDetCablingRcd> m_detCablingWatcher;
0102   edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> m_detCablingToken;
0103   const SiStripDetCabling* m_detCabling = nullptr;  //!< The cabling object.
0104 };
0105 
0106 //
0107 // constants, enums and typedefs
0108 //
0109 
0110 //
0111 // static data member definitions
0112 //
0113 
0114 //
0115 // constructors and destructor
0116 //
0117 CommonModeAnalyzer::CommonModeAnalyzer(const edm::ParameterSet& iConfig)
0118     : m_digicollectionToken(
0119           consumes<edm::DetSetVector<SiStripRawDigi> >(iConfig.getParameter<edm::InputTag>("digiCollection"))),
0120       m_historyProductToken(consumes<EventWithHistory>(iConfig.getParameter<edm::InputTag>("historyProduct"))),
0121       m_apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
0122       m_digibadmodulecollectionToken(
0123           consumes<DetIdCollection>(iConfig.getParameter<edm::InputTag>("badModuleDigiCollection"))),
0124       m_phasepart(iConfig.getUntrackedParameter<std::string>("phasePartition", "None")),
0125       m_ignorebadfedmod(iConfig.getParameter<bool>("ignoreBadFEDMod")),
0126       m_ignorenotconnected(iConfig.getParameter<bool>("ignoreNotConnected")),
0127       m_nevents(0),
0128       m_selections(),
0129       m_labels(),
0130       m_cmdist(),
0131       m_nmodules(),
0132       m_napvs(),
0133       m_cmvsdbxincycle(),
0134       m_cmvsbxrun(),
0135       m_cmvsorbitrun(),
0136       m_rhm(consumesCollector()),
0137       m_detCablingWatcher(this, &CommonModeAnalyzer::updateDetCabling),
0138       m_detCablingToken(esConsumes()) {
0139   //now do what ever initialization is needed
0140   usesResource(TFileService::kSharedResource);
0141 
0142   edm::Service<TFileService> tfserv;
0143 
0144   std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
0145 
0146   for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
0147        ++selconfig) {
0148     std::string label = selconfig->getParameter<std::string>("label");
0149     DetIdSelector selection(*selconfig);
0150     m_selections.push_back(selection);
0151 
0152     {
0153       std::string hname = label + "_CommonMode";
0154       std::string htitle = label + " Common Mode";
0155       m_cmdist.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 1024, -0.5, 1024 - 0.5));
0156       m_cmdist.back()->GetXaxis()->SetTitle("ADC");
0157     }
0158     {
0159       std::string hname = label + "_nmodules";
0160       std::string htitle = label + " Number of Modules with CM value";
0161       m_nmodules.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 20000, -0.5, 20000 - 0.5));
0162       m_nmodules.back()->GetXaxis()->SetTitle("#modules");
0163     }
0164     {
0165       std::string hname = label + "_napvs";
0166       std::string htitle = label + " Number of APVs with CM value";
0167       m_napvs.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 2000, -0.5, 80000 - 0.5));
0168       m_napvs.back()->GetXaxis()->SetTitle("#apvs");
0169     }
0170     {
0171       std::string hname = label + "_CMvsDBXinCycle";
0172       std::string htitle = label + " Common Mode vs DBX in Cycle";
0173       m_cmvsdbxincycle.push_back(tfserv->make<TProfile>(hname.c_str(), htitle.c_str(), 1000, -0.5, 1000 - 0.5));
0174       m_cmvsdbxincycle.back()->GetXaxis()->SetTitle("DBX in cycle");
0175       m_cmvsdbxincycle.back()->GetYaxis()->SetTitle("CM (ADC counts)");
0176     }
0177     {
0178       std::string hname = label + "_CMvsBX";
0179       std::string htitle = label + " Common Mode vs BX";
0180       m_cmvsbxrun.push_back(m_rhm.makeTProfile(hname.c_str(), htitle.c_str(), 3565, -0.5, 3565 - 0.5));
0181     }
0182     {
0183       std::string hname = label + "_CMvsOrbit";
0184       std::string htitle = label + " Common Mode vs Orbit";
0185       m_cmvsorbitrun.push_back(m_rhm.makeTProfile(hname.c_str(), htitle.c_str(), 4 * 500, 0, 500 * 262144));
0186     }
0187   }
0188 }
0189 
0190 CommonModeAnalyzer::~CommonModeAnalyzer() {
0191   // do anything here that needs to be done at desctruction time
0192   // (e.g. close files, deallocate resources etc.)
0193 }
0194 
0195 //
0196 // member functions
0197 //
0198 
0199 // ------------ method called to for each event  ------------
0200 void CommonModeAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0201   using namespace edm;
0202 
0203   m_detCablingWatcher.check(iSetup);
0204 
0205   m_nevents++;
0206 
0207   edm::Handle<EventWithHistory> he;
0208   iEvent.getByToken(m_historyProductToken, he);
0209 
0210   edm::Handle<APVCyclePhaseCollection> apvphase;
0211   iEvent.getByToken(m_apvphasecollToken, apvphase);
0212 
0213   Handle<DetIdCollection> badmodules;
0214   iEvent.getByToken(m_digibadmodulecollectionToken, badmodules);
0215 
0216   int thephase = APVCyclePhaseCollection::invalid;
0217   if (apvphase.isValid() && !apvphase.failedToGet()) {
0218     thephase = apvphase->getPhase(m_phasepart);
0219   }
0220   bool isphaseok = (thephase != APVCyclePhaseCollection::invalid && thephase != APVCyclePhaseCollection::multiphase &&
0221                     thephase != APVCyclePhaseCollection::nopartition);
0222 
0223   Handle<edm::DetSetVector<SiStripRawDigi> > digis;
0224   iEvent.getByToken(m_digicollectionToken, digis);
0225 
0226   // loop on detector with digis
0227 
0228   std::vector<int> nmodules(m_selections.size(), 0);
0229   std::vector<int> napvs(m_selections.size(), 0);
0230 
0231   for (edm::DetSetVector<SiStripRawDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
0232     std::vector<const FedChannelConnection*> conns = m_detCabling->getConnections(mod->detId());
0233 
0234     if (!m_ignorebadfedmod || std::find(badmodules->begin(), badmodules->end(), mod->detId()) == badmodules->end()) {
0235       for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
0236         if (m_selections[isel].isSelected(mod->detId())) {
0237           unsigned int strip = 0;
0238           ++nmodules[isel];
0239           for (edm::DetSet<SiStripRawDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++, strip++) {
0240             LogDebug("StripNumber") << "Strip number " << strip;
0241             if (!m_ignorenotconnected ||
0242                 ((conns.size() > strip / 2) && conns[strip / 2] && conns[strip / 2]->isConnected())) {
0243               ++napvs[isel];
0244               m_cmdist[isel]->Fill(digi->adc());
0245               if (isphaseok)
0246                 m_cmvsdbxincycle[isel]->Fill(he->deltaBXinCycle(thephase), digi->adc());
0247               if (m_cmvsbxrun[isel] && *(m_cmvsbxrun[isel]))
0248                 (*(m_cmvsbxrun[isel]))->Fill(iEvent.bunchCrossing(), digi->adc());
0249               if (m_cmvsorbitrun[isel] && *(m_cmvsorbitrun[isel]))
0250                 (*(m_cmvsorbitrun[isel]))->Fill(iEvent.orbitNumber(), digi->adc());
0251             } else if (digi->adc() > 0) {
0252               edm::LogWarning("NonZeroCMWhenDisconnected")
0253                   << " Non zero CM in " << mod->detId() << " APV " << strip << " with " << conns.size()
0254                   << " connections and connection pointer" << conns[strip / 2];
0255             }
0256           }
0257         }
0258       }
0259     }
0260   }
0261   for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
0262     m_nmodules[isel]->Fill(nmodules[isel]);
0263     m_napvs[isel]->Fill(napvs[isel]);
0264   }
0265 }
0266 
0267 void CommonModeAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup&) {
0268   m_rhm.beginRun(iRun);
0269 
0270   for (std::vector<TProfile**>::const_iterator cmvsbx = m_cmvsbxrun.begin(); cmvsbx != m_cmvsbxrun.end(); ++cmvsbx) {
0271     if (*cmvsbx && *(*cmvsbx)) {
0272       (*(*cmvsbx))->GetXaxis()->SetTitle("BX");
0273       (*(*cmvsbx))->GetYaxis()->SetTitle("CM (ADC counts)");
0274     }
0275   }
0276   for (std::vector<TProfile**>::const_iterator cmvsorbit = m_cmvsorbitrun.begin(); cmvsorbit != m_cmvsorbitrun.end();
0277        ++cmvsorbit) {
0278     if (*cmvsorbit && *(*cmvsorbit)) {
0279       (*(*cmvsorbit))->GetXaxis()->SetTitle("orbit");
0280       (*(*cmvsorbit))->GetYaxis()->SetTitle("CM (ADC counts)");
0281       (*(*cmvsorbit))->SetCanExtend(TH1::kXaxis);
0282     }
0283   }
0284 }
0285 
0286 void CommonModeAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup&) {}
0287 
0288 // ------------ method called once each job just before starting event loop  ------------
0289 void CommonModeAnalyzer::beginJob() {}
0290 
0291 // ------------ method called once each job just after ending the event loop  ------------
0292 void CommonModeAnalyzer::endJob() { edm::LogInfo("EndOfJob") << m_nevents << " analyzed events"; }
0293 
0294 void CommonModeAnalyzer::updateDetCabling(const SiStripDetCablingRcd& iRcd) {
0295   m_detCabling = &iRcd.get(m_detCablingToken);
0296 }
0297 
0298 //define this as a plug-in
0299 DEFINE_FWK_MODULE(CommonModeAnalyzer);