Skip to content

Commit

Permalink
Merge pull request #41049 from CTPPS/CMSSW_13_0_0_pre4_RandomDQM
Browse files Browse the repository at this point in the history
DQM module for PPS random stream - backport
  • Loading branch information
cmsbuild authored Mar 28, 2023
2 parents fd56960 + a55d2c1 commit 9d98e63
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 0 deletions.
206 changes: 206 additions & 0 deletions DQM/CTPPS/plugins/CTPPSRandomDQMSource.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/******************************************
*
* This is a part of CTPPSDQM software.
* Authors:
* A. Bellora (Universita' e INFN Torino)
*
*******************************************/

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"

#include "DataFormats/Common/interface/DetSetVector.h"

#include "CondFormats/PPSObjects/interface/CTPPSPixelIndices.h"
#include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
#include "DataFormats/CTPPSDigi/interface/CTPPSPixelDigi.h"
#include "DataFormats/CTPPSDigi/interface/CTPPSPixelDataError.h"
#include "DataFormats/CTPPSReco/interface/CTPPSPixelCluster.h"
#include "DataFormats/CTPPSReco/interface/CTPPSPixelLocalTrack.h"
#include "DataFormats/Common/interface/TriggerResults.h"

#include <string>

//-----------------------------------------------------------------------------

class CTPPSRandomDQMSource : public DQMEDAnalyzer {
public:
CTPPSRandomDQMSource(const edm::ParameterSet &ps);
~CTPPSRandomDQMSource() override = default;
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

protected:
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override;

private:
edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelDigi>> const tokenDigi_;

static constexpr int kNArms_ = 2;
static constexpr int kNStationMAX_ = 3; // in an arm
static constexpr int kNRPotsMAX_ = 6; // per station
static constexpr int kNplaneMAX_ = 6; // per RPot
static constexpr int kFirstRPn_ = 3, kLastRPn_ = 4;
static constexpr int kStationIDMAX_ = 4; // possible range of ID
static constexpr int kRPotsIDMAX_ = 8; // possible range of ID

const std::string folderName_ = "PPSRANDOM/RandomPixel";

unsigned int rpStatusWord_ = 0x8008; // 220_fr_hr(stn2rp3)+ 210_fr_hr
int rpStatus_[kStationIDMAX_][kRPotsIDMAX_]; // symmetric in both arms
int stationStatus_[kStationIDMAX_]; // symmetric in both arms
const int kIndexNotValid = 0;

MonitorElement *hBX_;

static constexpr int kRPotsTotalNumber_ = kNArms_ * kNStationMAX_ * kNRPotsMAX_;

int RPindexValid_[kRPotsTotalNumber_];
MonitorElement *h2HitsVsBXRandoms_[kRPotsTotalNumber_];

int getRPindex(int arm, int station, int rp) const {
if (arm < 0 || station < 0 || rp < 0)
return (kIndexNotValid);
if (arm > 1 || station >= kNStationMAX_ || rp >= kNRPotsMAX_)
return (kIndexNotValid);
int rc = (arm * kNStationMAX_ + station) * kNRPotsMAX_ + rp;
return (rc);
}
};

//-------------------------------------------------------------------------------

CTPPSRandomDQMSource::CTPPSRandomDQMSource(const edm::ParameterSet &ps)
: tokenDigi_(consumes<edm::DetSetVector<CTPPSPixelDigi>>(ps.getParameter<edm::InputTag>("tagRPixDigi"))),
folderName_(ps.getUntrackedParameter<std::string>("folderName", "PPSRANDOM/RandomPixel")),
rpStatusWord_(ps.getUntrackedParameter<unsigned int>("RPStatusWord", 0x8008)) {
for (int stn = 0; stn < kStationIDMAX_; stn++) {
stationStatus_[stn] = 0;
for (int rp = 0; rp < kRPotsIDMAX_; rp++)
rpStatus_[stn][rp] = 0;
}

unsigned int rpSts = rpStatusWord_ << 1;
for (int stn = 0; stn < kNStationMAX_; stn++) {
int stns = 0;
for (int rp = 0; rp < kNRPotsMAX_; rp++) {
rpSts = (rpSts >> 1);
rpStatus_[stn][rp] = rpSts & 1;
if (rpStatus_[stn][rp] > 0)
stns = 1;
}
stationStatus_[stn] = stns;
}

for (int index = 0; index < 2 * 3 * kNRPotsMAX_; index++)
RPindexValid_[index] = 0;
}

//--------------------------------------------------------------------------

void CTPPSRandomDQMSource::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) {
ibooker.cd();
ibooker.setCurrentFolder(folderName_);

hBX_ = ibooker.book1D("events per BX", "ctpps_pixel;Event.BX", 4002, -1.5, 4000. + 0.5);

for (int arm = 0; arm < kNArms_; arm++) {
CTPPSDetId ID(CTPPSDetId::sdTrackingPixel, arm, 0);
std::string sd;
ID.armName(sd, CTPPSDetId::nShort);
sd = folderName_ + "/sector " + sd;

ibooker.setCurrentFolder(sd);

for (int stn = 0; stn < kNStationMAX_; stn++) {
if (stationStatus_[stn] == 0)
continue;
ID.setStation(stn);
std::string stnd;
CTPPSDetId(ID.stationId()).stationName(stnd, CTPPSDetId::nShort);
stnd = sd + "/station " + stnd;

ibooker.setCurrentFolder(stnd);

for (int rp = kFirstRPn_; rp < kLastRPn_; rp++) { // only installed pixel pots
ID.setRP(rp);
std::string rpd, rpTitle;
CTPPSDetId(ID.rpId()).rpName(rpTitle, CTPPSDetId::nFull);
CTPPSDetId(ID.rpId()).rpName(rpd, CTPPSDetId::nShort);
rpd = stnd + "/" + rpd;

ibooker.setCurrentFolder(rpd);

int indexP = getRPindex(arm, stn, rp);
RPindexValid_[indexP] = 1;

h2HitsVsBXRandoms_[indexP] = ibooker.book2D("Digi per plane per BX - random triggers",
rpTitle + ";Event.BX;Plane",
4002,
-1.5,
4000. + 0.5,
kNplaneMAX_,
0,
kNplaneMAX_);
h2HitsVsBXRandoms_[indexP]->getTH2F()->SetOption("colz");

} // end for(int rp=0; rp<kNRPotsMAX_;...
} // end of for(int stn=0; stn<
} // end of for(int arm=0; arm<2;...

return;
}

//-------------------------------------------------------------------------------

void CTPPSRandomDQMSource::analyze(edm::Event const &event, edm::EventSetup const &eventSetup) {
auto const pixDigi = event.getHandle(tokenDigi_);

if (!pixDigi.isValid())
return;

hBX_->Fill(event.bunchCrossing());

for (int arm = 0; arm < 2; arm++) {
for (int stn = 0; stn < kNStationMAX_; stn++) {
if (!stationStatus_[stn])
continue;
for (int rp = 0; rp < kNRPotsMAX_; rp++) {
if (!rpStatus_[stn][rp])
continue;
int index = getRPindex(arm, stn, rp);
if (RPindexValid_[index] == 0)
continue;

for (int p = 0; p < kNplaneMAX_; p++) {
CTPPSPixelDetId planeId(arm, stn, rp, p);
auto pix_d = pixDigi->find(planeId.rawId());
if (pix_d != pixDigi->end()) {
int n_digis = pix_d->size();
h2HitsVsBXRandoms_[index]->Fill(event.bunchCrossing(), p, n_digis);
}
}
} // end for (int rp=0; rp<kNRPotsMAX_; rp++) {
} // end for (int stn = 0; stn < kNStationMAX_; stn++) {
} // end for (int arm=0; arm<2; arm++) {
}

//---------------------------------------------------------------------------

void CTPPSRandomDQMSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("tagRPixDigi", edm::InputTag("ctppsPixelDigisAlCaRecoProducer"));
desc.addUntracked<std::string>("folderName", "PPSRANDOM/RandomPixel");
desc.addUntracked<unsigned int>("RPStatusWord", 0x8008);
descriptions.add("ctppsRandomDQMSource", desc);
}

//---------------------------------------------------------------------------
DEFINE_FWK_MODULE(CTPPSRandomDQMSource);
15 changes: 15 additions & 0 deletions DQM/CTPPS/python/ctppsDQM_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from DQM.CTPPS.ctppsCommonDQMSource_cfi import *

from DQM.CTPPS.ctppsRandomDQMSource_cfi import *

# sequences used by the online DQM in normal running
ctppsCommonDQMSourceOnline = ctppsCommonDQMSource.clone(
makeProtonRecoPlots = False
Expand Down Expand Up @@ -51,6 +53,14 @@
makeProtonRecoPlots = True
)

# sequences used by the dedicated random trigger stream
_ctppsDQMRandomSource = cms.Sequence(
ctppsRandomDQMSource
)

_ctppsDQMRandomHarvest = cms.Sequence(
)

#Check if perLSsaving is enabled to mask MEs vs LS
from Configuration.ProcessModifiers.dqmPerLSsaving_cff import dqmPerLSsaving
dqmPerLSsaving.toModify(ctppsDiamondDQMSource, perLSsaving=True)
Expand Down Expand Up @@ -99,3 +109,8 @@
ctppsDQMOfflineHarvest = cms.Sequence()
ctpps.toReplaceWith(ctppsDQMOfflineSource, _ctppsDQMOfflineSource)
ctpps.toReplaceWith(ctppsDQMOfflineHarvest, _ctppsDQMOfflineHarvest)

ctppsDQMRandomSource = cms.Sequence()
ctppsDQMRandomHarvest = cms.Sequence()
ctpps.toReplaceWith(ctppsDQMRandomSource, _ctppsDQMRandomSource)
ctpps.toReplaceWith(ctppsDQMRandomHarvest, _ctppsDQMRandomHarvest)
9 changes: 9 additions & 0 deletions DQM/CTPPS/python/ctppsRandomDQMSource_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FWCore.ParameterSet.Config as cms

from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer

ctppsRandomDQMSource = DQMEDAnalyzer('CTPPSRandomDQMSource',
tagRPixDigi = cms.InputTag("ctppsPixelDigisAlCaRecoProducer", ""),
folderName = cms.untracked.string("PPSRANDOM/RandomPixel"),
RPStatusWord = cms.untracked.uint32(0x8008) # rpots in readout:220_fr_hr; 210_fr_hr
)
62 changes: 62 additions & 0 deletions DQM/CTPPS/test/pps_random_dqm_test_from_alcaraw_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import FWCore.ParameterSet.Config as cms

from Configuration.Eras.Modifier_ctpps_cff import ctpps
process = cms.Process('ctppsRandomDQMfromRAW', ctpps)

# minimum of logs
process.MessageLogger = cms.Service("MessageLogger",
statistics = cms.untracked.vstring(),
destinations = cms.untracked.vstring('cerr'),
cerr = cms.untracked.PSet(
threshold = cms.untracked.string('WARNING')
)
)

# load DQM framework
process.load("DQM.Integration.config.environment_cfi")
process.dqmEnv.subSystemFolder = "CTPPS"
process.dqmEnv.eventInfoFolder = "EventInfo"
process.dqmSaver.path = ""
process.dqmSaver.tag = "CTPPS"

# raw data source
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
'/store/group/dpg_ctpps/comm_ctpps/PixelRandomTrigger2023/outputExpressPPSRandom.root'
),

inputCommands = cms.untracked.vstring(
'drop *',
'keep FEDRawDataCollection_*_*_*'
)
)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(-1)
)

# global tag - conditions for P5 cluster
process.load("DQM.Integration.config.FrontierCondition_GT_cfi")

# raw-to-digi conversion
from EventFilter.CTPPSRawToDigi.ctppsRawToDigi_cff import ctppsPixelDigis as _ctppsPixelDigis
process.ctppsPixelDigisAlCaRecoProducer = _ctppsPixelDigis.clone(inputLabel = 'hltPPSCalibrationRaw')

# CTPPS DQM modules
process.load("DQM.CTPPS.ctppsDQM_cff")

process.path = cms.Path(
process.ctppsPixelDigisAlCaRecoProducer *
process.ctppsDQMRandomSource *
process.ctppsDQMRandomHarvest
)

process.end_path = cms.EndPath(
process.dqmEnv +
process.dqmSaver
)

process.schedule = cms.Schedule(
process.path,
process.end_path
)
Loading

0 comments on commit 9d98e63

Please sign in to comment.