Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:43

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 
0015 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0016 
0017 #include <TProfile.h>
0018 #include <TH1F.h>
0019 
0020 #include <vector>
0021 #include <deque>
0022 
0023 using namespace std;
0024 using namespace edm;
0025 using namespace tt;
0026 
0027 namespace trackerDTC {
0028 
0029   /*! \class  trackerDTC::AnalyzerDAQ
0030    *  \brief  Class to analyze TTCluster Occupancies on DTCs, plots cluster occupancy
0031    *  \author Thomas Schuh
0032    *  \date   2020, Oct
0033    */
0034   class AnalyzerDAQ : public one::EDAnalyzer<one::WatchRuns, one::SharedResources> {
0035   public:
0036     AnalyzerDAQ(const ParameterSet& iConfig);
0037     void beginJob() override {}
0038     void beginRun(const Run& iEvent, const EventSetup& iSetup) override;
0039     void analyze(const Event& iEvent, const EventSetup& iSetup) override;
0040     void endRun(const Run& iEvent, const EventSetup& iSetup) override {}
0041     void endJob() override {}
0042 
0043   private:
0044     // ED input token of accepted TTClusters
0045     EDGetTokenT<TTClusterDetSetVec> edGetToken_;
0046     // Setup token
0047     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0048     // stores, calculates and provides run-time constants
0049     const Setup* setup_ = nullptr;
0050 
0051     // Histograms
0052 
0053     TProfile* profModules_;
0054     TH1F* hisModules_;
0055     TProfile* profDTCs_;
0056     TH1F* hisDTCs_;
0057     TH1F* hisTracker_;
0058   };
0059 
0060   AnalyzerDAQ::AnalyzerDAQ(const ParameterSet& iConfig) {
0061     usesResource("TFileService");
0062     // book input ED products
0063     const auto& inputTag = iConfig.getParameter<InputTag>("InputTagTTClusterDetSetVec");
0064     edGetToken_ = consumes<TTClusterDetSetVec>(inputTag);
0065     // book ES products
0066     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0067   }
0068 
0069   void AnalyzerDAQ::beginRun(const Run& iEvent, const EventSetup& iSetup) {
0070     // helper class to store configurations
0071     setup_ = &iSetup.getData(esGetTokenSetup_);
0072     // book histograms
0073     Service<TFileService> fs;
0074     TFileDirectory dir;
0075     dir = fs->mkdir("Modules");
0076     int maxOcc = 150;
0077     int numChannels = setup_->numDTCs() * setup_->numModulesPerDTC();
0078     hisModules_ = dir.make<TH1F>("His Module Occupancy", ";", maxOcc, -.5, maxOcc - .5);
0079     profModules_ = dir.make<TProfile>("Prof Module Occupancy", ";", numChannels, -.5, numChannels - .5);
0080     dir = fs->mkdir("DTCs");
0081     maxOcc = 3456;
0082     numChannels = setup_->numDTCs();
0083     hisDTCs_ = dir.make<TH1F>("His DTC Occupancy", ";", maxOcc / 16, -.5, maxOcc - .5);
0084     profDTCs_ = dir.make<TProfile>("Prof DTC Occupancy", ";", numChannels, -.5, numChannels - .5);
0085     dir = fs->mkdir("Tracker");
0086     maxOcc = pow(2, 29);
0087     hisTracker_ = dir.make<TH1F>("His Tracker Occupancy", ";", maxOcc * pow(2., -12), -.5, maxOcc - .5);
0088   }
0089 
0090   void AnalyzerDAQ::analyze(const Event& iEvent, const EventSetup& iSetup) {
0091     // read in original TTCluster collection
0092     Handle<TTClusterDetSetVec> handle;
0093     iEvent.getByToken<TTClusterDetSetVec>(edGetToken_, handle);
0094     // apply cabling map, reorganise cluster collections
0095     vector<vector<deque<TTClusterRef>>> dtcs(setup_->numDTCs(),
0096                                              vector<deque<TTClusterRef>>(setup_->numModulesPerDTC()));
0097     for (auto itModule = handle->begin(); itModule != handle->end(); itModule++) {
0098       // DetSetVec->detId - 1 or + 0 = tk layout det id depending from which of both sensor planes the cluster has been constructed
0099       const DetId& detIdModule = itModule->detId();
0100       const int offset = setup_->trackerTopology()->isLower(detIdModule) ? 0 : setup_->offsetDetIdTP();
0101       const DetId detId = detIdModule + offset;
0102       // corresponding sensor module
0103       SensorModule* sm = setup_->sensorModule(detId);
0104       // empty cluster collection
0105       deque<TTClusterRef>& module = dtcs[sm->dtcId()][sm->modId()];
0106       for (TTClusterDetSet::const_iterator itCluster = itModule->begin(); itCluster != itModule->end(); itCluster++)
0107         module.emplace_back(makeRefTo(handle, itCluster));
0108     }
0109     // analyze organized TTCluster collections
0110     int iDTC(0);
0111     int iModule(0);
0112     int nAll(0);
0113     for (const vector<deque<TTClusterRef>>& dtc : dtcs) {
0114       int nCluster(0);
0115       for (const deque<TTClusterRef>& module : dtc) {
0116         nCluster += module.size();
0117         hisModules_->Fill(module.size());
0118         profModules_->Fill(iModule++, module.size());
0119       }
0120       nAll += nCluster;
0121       hisDTCs_->Fill(nCluster);
0122       profDTCs_->Fill(iDTC++, nCluster);
0123     }
0124     hisTracker_->Fill(nAll);
0125   }
0126 
0127 }  // namespace trackerDTC
0128 
0129 DEFINE_FWK_MODULE(trackerDTC::AnalyzerDAQ);