Skip to content

Commit

Permalink
add fake digi analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
rozchlastywacz committed Aug 4, 2022
1 parent 69c9a5b commit 2b4124b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 4 deletions.
110 changes: 110 additions & 0 deletions DQM/CTPPS/plugins/TotemT2DigiAnalyzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"

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

#include "DataFormats/CTPPSDetId/interface/TotemT2DetId.h"
#include "DataFormats/TotemReco/interface/TotemT2Digi.h"

class TotemT2DigiAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit TotemT2DigiAnalyzer(const edm::ParameterSet&);
// ~TotemT2DigiAnalyzer();

// static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;

edm::EDGetTokenT<edm::DetSetVector<TotemT2Digi>> digiToken_;
std::vector<std::vector<unsigned int>> testCasesVec;
unsigned int numberOfAllEvents;

std::unordered_map<unsigned int, unsigned int> ids_counters_;
std::unordered_map<unsigned int, unsigned int> event_counters_;

};

TotemT2DigiAnalyzer::TotemT2DigiAnalyzer(const edm::ParameterSet& iConfig) :
digiToken_(consumes<edm::DetSetVector<TotemT2Digi>>(iConfig.getParameter<edm::InputTag>("digisTag"))),
numberOfAllEvents(iConfig.getParameter<unsigned int>("numberOfAllEvents")) {

for (const auto& ids : iConfig.getParameter<std::vector<edm::ParameterSet>>("testCasesSet")){
testCasesVec.push_back(ids.getParameter<std::vector<unsigned int>>("detId"));
}

}

void TotemT2DigiAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::LogWarning("analyze job") << "whatsup";
for (const auto& ds_digis : iEvent.get(digiToken_)) {
const TotemT2DetId detid(ds_digis.detId());
for (const auto& digi : ds_digis) {
event_counters_[detid]++;
(void)digi;
}
}

}

// ------------ method called once each job just before starting event loop ------------
void TotemT2DigiAnalyzer::beginJob() {
edm::LogWarning("Begin job") << "hello";
for(auto vec : testCasesVec){
for (const auto& id : vec) {
// count how many times each id appeared in test cases
if(ids_counters_.find(id) != ids_counters_.end()){
ids_counters_[id]++;
}else{
ids_counters_[id] = 0;
}
// initialize event counter for each id
event_counters_[id] = 0;
}
}
}

// ------------ method called once each job just after ending the event loop ------------
void TotemT2DigiAnalyzer::endJob() {
for(auto vec : testCasesVec){
for (const auto& id : vec) {
edm::LogWarning("End job summary: ") << "there should be " << numberOfAllEvents << " events, there is " << event_counters_[id] * ids_counters_[id] << " events";
// ids_counters[id];
// event_counters_[id];
}
}
}

// // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
// void TotemT2DigiAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
// //The following says we do not know what parameters are allowed so do no validation
// // Please change this to state exactly what you do use, even if it is no parameters
// // edm::ParameterSetDescription desc;
// // desc.setUnknown();
// // descriptions.addDefault(desc);

// //Specify that only 'tracks' is allowed
// //To use, remove the default given above and uncomment below
// //ParameterSetDescription desc;
// //desc.addUntracked<edm::InputTag>("tracks","ctfWithMaterialTracks");
// //descriptions.addWithDefaultLabel(desc);
// }

DEFINE_FWK_MODULE(TotemT2DigiAnalyzer);
20 changes: 16 additions & 4 deletions DQM/CTPPS/test/totemt2_dqm_test_fake_digi_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@
t2DataFile=cms.string(PATH_TO_FAKE_T2_DATA),
# set of test cases
testCasesSet = cms.VPSet(
cms.PSet(detId = cms.vuint32(*ids_arm_0_plane_all_tile_0)),
# cms.PSet(detId = cms.vuint32(*ids_arm_0_plane_all_tile_0)),
# cms.PSet(detId = cms.vuint32(*ids_arm_1_plane_1))
)
)

# fake digi analyzer
process.totemT2DigiAnalyzer = cms.EDAnalyzer('TotemT2DigiAnalyzer',
digisTag = cms.InputTag('totemT2Digis', 'TotemT2'),
numberOfAllEvents = cms.uint32(MAX_NUMBER_OF_EVENTS),
testCasesSet = cms.VPSet(
cms.PSet(detId = cms.vuint32(*ids_arm_0_plane_all_tile_0))
# cms.PSet(detId = cms.vuint32(*ids_arm_1_plane_1))
)
Expand All @@ -96,13 +107,14 @@

process.path = cms.Path(
process.totemT2Digis *
process.totemT2RecHits *
process.totemT2DQMSource
process.totemT2DigiAnalyzer
# process.totemT2RecHits *
# process.totemT2DQMSource
)

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

process.schedule = cms.Schedule(
Expand Down

0 comments on commit 2b4124b

Please sign in to comment.