File indexing completed on 2024-04-06 12:32:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "Validation/Mixing/interface/GlobalTest.h"
0017
0018
0019 #include <memory>
0020 #include <utility>
0021
0022 #include <string>
0023
0024 #include <fmt/format.h>
0025
0026
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033
0034 #include "DQMServices/Core/interface/DQMStore.h"
0035 #include "TFile.h"
0036
0037 using namespace edm;
0038
0039 GlobalTest::GlobalTest(const edm::ParameterSet &iConfig)
0040 : filename_(iConfig.getParameter<std::string>("fileName")),
0041 minbunch_(iConfig.getParameter<int>("minBunch")),
0042 maxbunch_(iConfig.getParameter<int>("maxBunch")),
0043 cfTrackToken_(consumes<CrossingFrame<SimTrack>>(iConfig.getParameter<edm::InputTag>("cfTrackTag"))),
0044 cfVertexToken_(consumes<CrossingFrame<SimTrack>>(iConfig.getParameter<edm::InputTag>("cfVertexTag"))) {
0045 std::string ecalsubdetb("");
0046 std::string ecalsubdete("g4SimHitsEcalHitsEE");
0047 g4SimHits_EB_Token_ = consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsEcalHitsEB"));
0048 g4SimHits_EE_Token_ = consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsEcalHitsEE"));
0049
0050 std::cout << "Constructed GlobalTest, filename: " << filename_ << " minbunch: " << minbunch_
0051 << ", maxbunch: " << maxbunch_ << std::endl;
0052 }
0053
0054 void GlobalTest::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) {
0055 using namespace std;
0056
0057 ibooker.setCurrentFolder("MixingV/Mixing");
0058
0059
0060 for (int i = minbunch_; i <= maxbunch_; ++i) {
0061 int ii = i - minbunch_;
0062 auto label = fmt::format("NrPileupEvts_{}", i);
0063 nrPileupsH_[ii] = ibooker.book1D(label, label, 100, 0, 100);
0064 label = fmt::format("NrVertices_{}", i);
0065 nrVerticesH_[ii] = ibooker.book1D(label, label, 100, 0, 5000);
0066 label = fmt::format("NrTracks_{}", i);
0067 nrTracksH_[ii] = ibooker.book1D(label, label, 100, 0, 10000);
0068 label = fmt::format("TrackPartId", i);
0069 trackPartIdH_[ii] = ibooker.book1D(label, label, 100, 0, 100);
0070 label = fmt::format("CaloEnergyEB", i);
0071 caloEnergyEBH_[ii] = ibooker.book1D(label, label, 100, 0., 1000.);
0072 label = fmt::format("CaloEnergyEE", i);
0073 caloEnergyEEH_[ii] = ibooker.book1D(label, label, 100, 0., 1000.);
0074 }
0075 }
0076
0077
0078
0079
0080
0081
0082 void GlobalTest::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0083 using namespace edm;
0084 using namespace std;
0085
0086
0087 edm::Handle<CrossingFrame<SimTrack>> cf_track;
0088 edm::Handle<CrossingFrame<SimTrack>> cf_vertex;
0089 edm::Handle<CrossingFrame<PCaloHit>> cf_calohitE;
0090 edm::Handle<CrossingFrame<PCaloHit>> cf_calohitB;
0091 std::string ecalsubdetb("g4SimHitsEcalHitsEB");
0092 std::string ecalsubdete("g4SimHitsEcalHitsEE");
0093 iEvent.getByToken(cfTrackToken_, cf_track);
0094 iEvent.getByToken(cfVertexToken_, cf_vertex);
0095 iEvent.getByToken(g4SimHits_EB_Token_, cf_calohitB);
0096 iEvent.getByToken(g4SimHits_EE_Token_, cf_calohitE);
0097
0098
0099
0100
0101 for (int i = minbunch_; i <= maxbunch_; ++i) {
0102 nrTracksH_[i - minbunch_]->Fill(cf_track->getNrPileups(i));
0103 }
0104
0105
0106 for (int i = minbunch_; i <= maxbunch_; ++i) {
0107 nrVerticesH_[i - minbunch_]->Fill(cf_vertex->getNrPileups(i));
0108 }
0109
0110
0111 std::unique_ptr<MixCollection<SimTrack>> coltr(new MixCollection<SimTrack>(cf_track.product()));
0112 MixCollection<SimTrack>::iterator cfitr;
0113 for (cfitr = coltr->begin(); cfitr != coltr->end(); cfitr++) {
0114 trackPartIdH_[cfitr.bunch() - minbunch_]->Fill(cfitr->type());
0115 }
0116
0117
0118 double sumE[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
0119 std::unique_ptr<MixCollection<PCaloHit>> colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
0120 MixCollection<PCaloHit>::iterator cfiecalb;
0121 for (cfiecalb = colecalb->begin(); cfiecalb != colecalb->end(); cfiecalb++) {
0122 sumE[cfiecalb.bunch() - minbunch_] += cfiecalb->energy();
0123
0124
0125 }
0126 for (int i = minbunch_; i <= maxbunch_; ++i) {
0127 caloEnergyEBH_[i - minbunch_]->Fill(sumE[i - minbunch_]);
0128 }
0129 double sumEE[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
0130 std::unique_ptr<MixCollection<PCaloHit>> colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
0131 MixCollection<PCaloHit>::iterator cfiecale;
0132 for (cfiecale = colecale->begin(); cfiecale != colecale->end(); cfiecale++) {
0133 sumEE[cfiecale.bunch() - minbunch_] += cfiecale->energy();
0134
0135
0136 }
0137 for (int i = minbunch_; i <= maxbunch_; ++i) {
0138 caloEnergyEEH_[i - minbunch_]->Fill(sumEE[i - minbunch_]);
0139 }
0140 }