File indexing completed on 2024-04-06 12:26:38
0001 #ifndef RecoLuminosity_LumiProducer_genLumiRaw_h
0002 #define RecoLuminosity_LumiProducer_genLumiRaw_h
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/Run.h"
0007 #include "FWCore/Framework/interface/LuminosityBlock.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "RecoLuminosity/LumiProducer/interface/LumiRawDataStructures.h"
0011 #include "TFile.h"
0012 #include "TTree.h"
0013 #include "TBranch.h"
0014 #include <iostream>
0015 #include <cstring>
0016 #include <cstdio>
0017
0018
0019
0020
0021
0022 class genLumiRaw : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0023 public:
0024 explicit genLumiRaw(edm::ParameterSet const&);
0025 ~genLumiRaw();
0026
0027 private:
0028 void beginJob() override;
0029 void beginRun(const edm::Run& run, const edm::EventSetup& c) override;
0030 void beginLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& c) override {}
0031 void analyze(edm::Event const& e, edm::EventSetup const& c) override;
0032 void endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& c) override;
0033 void endRun(edm::Run const&, edm::EventSetup const&) override;
0034 void endJob() override;
0035
0036 void generateRunSummary(unsigned int runnumber, unsigned int totalCMSls);
0037 void generateHLT(unsigned int runnumber, unsigned int lsnumber);
0038 void generateTRG(unsigned int runnumber, unsigned int lsnumber);
0039 void generateHLX(unsigned int runnumber, unsigned int lsnumber);
0040
0041 private:
0042 static const std::string s_filetype;
0043 static const std::string s_fileprefix;
0044
0045 static const std::string s_runsummaryTree;
0046 static const std::string s_runsummaryBranch;
0047 static const std::string s_runsummaryName;
0048
0049 static const std::string s_hltTree;
0050 static const std::string s_hltBranch;
0051 static const std::string s_hltName;
0052
0053 static const std::string s_trgTree;
0054 static const std::string s_trgBranch;
0055 static const std::string s_trgName;
0056
0057 static const std::string s_hlxTree;
0058 static const std::string s_lumiHeaderBranch;
0059 static const std::string s_lumiHeaderName;
0060 static const std::string s_lumiSummaryBranch;
0061 static const std::string s_lumiSummaryName;
0062 static const std::string s_lumiDetailBranch;
0063 static const std::string s_lumiDetailName;
0064
0065 unsigned int m_nls;
0066 int m_bsize;
0067 int m_splitlevel;
0068 TFile* m_file;
0069
0070 TTree* m_runsummaryTree;
0071 HCAL_HLX::RUN_SUMMARY* m_runsummary;
0072
0073
0074 TTree* m_hlxTree;
0075 HCAL_HLX::LUMI_SECTION* m_lumisection;
0076 HCAL_HLX::LUMI_SECTION_HEADER* m_lumiheader;
0077 HCAL_HLX::LUMI_SUMMARY* m_lumisummary;
0078 HCAL_HLX::LUMI_DETAIL* m_lumidetail;
0079
0080 TTree* m_trgTree;
0081 HCAL_HLX::LEVEL1_TRIGGER* m_trg;
0082
0083
0084 TTree* m_hltTree;
0085 HCAL_HLX::HLTRIGGER* m_hlt;
0086
0087 };
0088
0089 const std::string genLumiRaw::s_fileprefix = "CMS_LUMI_RAW_00000000_";
0090
0091 const std::string genLumiRaw::s_runsummaryTree = "RunSummary";
0092 const std::string genLumiRaw::s_runsummaryBranch = "RunSummary.";
0093 const std::string genLumiRaw::s_runsummaryName = "HCAL_HLX::RUN_SUMMARY";
0094
0095 const std::string genLumiRaw::s_hltTree = "HLTrigger";
0096 const std::string genLumiRaw::s_hltBranch = "HLTrigger.";
0097 const std::string genLumiRaw::s_hltName = "HCAL_HLX::HLTRIGGER";
0098
0099 const std::string genLumiRaw::s_trgTree = "L1Trigger";
0100 const std::string genLumiRaw::s_trgBranch = "L1Trigger.";
0101 const std::string genLumiRaw::s_trgName = "HCAL_HLX::LEVEL1_TRIGGER";
0102
0103 const std::string genLumiRaw::s_hlxTree = "HLXData";
0104 const std::string genLumiRaw::s_lumiHeaderBranch = "Header.";
0105 const std::string genLumiRaw::s_lumiHeaderName = "HCAL_HLX::LUMI_SECTION_HEADER";
0106 const std::string genLumiRaw::s_lumiSummaryBranch = "Summary.";
0107 const std::string genLumiRaw::s_lumiSummaryName = "HCAL_HLX::LUMI_SUMMARY";
0108 const std::string genLumiRaw::s_lumiDetailBranch = "Detail.";
0109 const std::string genLumiRaw::s_lumiDetailName = "HCAL_HLX::LUMI_DETAIL";
0110
0111
0112
0113 genLumiRaw::genLumiRaw(edm::ParameterSet const& iConfig)
0114 : m_nls(0),
0115 m_bsize(64000),
0116 m_splitlevel(2),
0117 m_file(0),
0118 m_runsummary(new HCAL_HLX::RUN_SUMMARY),
0119 m_lumisection(new HCAL_HLX::LUMI_SECTION),
0120 m_lumiheader(0),
0121 m_lumisummary(0),
0122 m_lumidetail(0),
0123 m_trg(new HCAL_HLX::LEVEL1_TRIGGER),
0124 m_hlt(new HCAL_HLX::HLTRIGGER) {}
0125
0126
0127
0128 genLumiRaw::~genLumiRaw() {
0129 delete m_runsummary;
0130 delete m_lumisection;
0131 delete m_trg;
0132 delete m_hlt;
0133 }
0134
0135
0136
0137 void genLumiRaw::analyze(edm::Event const& e, edm::EventSetup const&) {
0138
0139 }
0140
0141
0142 void genLumiRaw::endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& c) {
0143 ++m_nls;
0144 std::cout << "I'm in run " << lumiBlock.run() << " lumi block " << lumiBlock.id().luminosityBlock() << std::endl;
0145 generateHLT(lumiBlock.run(), lumiBlock.id().luminosityBlock());
0146 generateTRG(lumiBlock.run(), lumiBlock.id().luminosityBlock());
0147 generateHLX(lumiBlock.run(), lumiBlock.id().luminosityBlock());
0148 }
0149
0150
0151
0152 void genLumiRaw::beginJob() {}
0153
0154
0155
0156 void genLumiRaw::beginRun(const edm::Run& run, const edm::EventSetup& c) {
0157
0158 std::cout << "in generate filename " << run.run() << std::endl;
0159 char runnumber[15];
0160 ::snprintf(runnumber, sizeof(runnumber), "%09d", run.run());
0161 std::string filename = s_fileprefix + runnumber + "_0000" + "_0" + ".root";
0162
0163
0164
0165
0166
0167
0168 m_file = new TFile(filename.c_str(), "RECREATE");
0169
0170
0171 m_runsummaryTree = new TTree(s_runsummaryTree.c_str(), s_runsummaryTree.c_str());
0172 m_runsummaryTree->Branch(s_runsummaryBranch.c_str(), s_runsummaryName.c_str(), &m_runsummary, m_bsize, m_splitlevel);
0173
0174
0175
0176 m_hlxTree = new TTree(s_hlxTree.c_str(), s_hlxTree.c_str());
0177
0178 m_lumiheader = &(m_lumisection->hdr);
0179 m_hlxTree->Branch(s_lumiHeaderBranch.c_str(), s_lumiHeaderName.c_str(), &m_lumiheader, m_bsize, m_splitlevel);
0180 m_lumisummary = &(m_lumisection->lumiSummary);
0181 m_hlxTree->Branch(s_lumiSummaryBranch.c_str(), s_lumiSummaryName.c_str(), &m_lumisummary, m_bsize, m_splitlevel);
0182 m_lumidetail = &(m_lumisection->lumiDetail);
0183 m_hlxTree->Branch(s_lumiDetailBranch.c_str(), s_lumiDetailName.c_str(), &m_lumidetail, m_bsize, m_splitlevel);
0184
0185
0186 m_trgTree = new TTree(s_trgTree.c_str(), s_trgTree.c_str());
0187 m_trgTree->Branch(s_trgBranch.c_str(), s_trgName.c_str(), &m_trg, m_bsize, m_splitlevel);
0188
0189
0190 m_hltTree = new TTree(s_hltTree.c_str(), s_hltTree.c_str());
0191 m_hltTree->Branch(s_hltBranch.c_str(), s_hltName.c_str(), &m_hlt, m_bsize, m_splitlevel);
0192 }
0193
0194
0195 void genLumiRaw::endRun(edm::Run const& run, edm::EventSetup const& c) {
0196 std::cout << "run number in endRun " << run.run() << " " << m_nls << std::endl;
0197
0198 generateRunSummary(run.run(), m_nls);
0199 }
0200
0201
0202 void genLumiRaw::endJob() {
0203 std::cout << "genLumiRaw::endJob" << std::endl;
0204 if (m_file) {
0205 m_file->Write();
0206 m_file->Close();
0207 delete m_file;
0208 m_file = 0;
0209 }
0210 }
0211
0212
0213 void genLumiRaw::generateRunSummary(unsigned int runnumber, unsigned int totalCMSls) {
0214 std::cout << "inside generateRunSummary " << runnumber << " " << totalCMSls << std::endl;
0215 HCAL_HLX::RUN_SUMMARY localrunsummary;
0216 const char* runsequence = "Fake Run Summary";
0217 std::strncpy(localrunsummary.runSequenceName, runsequence, 128);
0218 localrunsummary.HLTConfigId = 7792;
0219 localrunsummary.timestamp = 2;
0220 localrunsummary.timestamp_micros = 3;
0221 localrunsummary.startOrbitNumber = 4;
0222 localrunsummary.endOrbitnumber = 5;
0223 localrunsummary.runNumber = runnumber;
0224 localrunsummary.fillNumber = 6;
0225 localrunsummary.numberCMSLumiSections = totalCMSls;
0226 localrunsummary.numberLumiDAQLumiSections = totalCMSls + 2;
0227 std::memmove(m_runsummary, &localrunsummary, sizeof(HCAL_HLX::RUN_SUMMARY));
0228 m_runsummaryTree->Fill();
0229 }
0230
0231 void genLumiRaw::generateHLT(unsigned int runnumber, unsigned int lsnumber) {
0232 HCAL_HLX::HLTRIGGER localhlt;
0233 localhlt.runNumber = runnumber;
0234 localhlt.sectionNumber = lsnumber;
0235 const char* pathname = "Fake Path";
0236 const char* modulename = "Fake Module";
0237 unsigned int npath = 0;
0238 for (unsigned int iHLT = 0; iHLT < 256; ++iHLT) {
0239 ++npath;
0240 std::strncpy(localhlt.HLTPaths[iHLT].PathName, pathname, 128);
0241 localhlt.HLTPaths[iHLT].L1Pass = iHLT;
0242 localhlt.HLTPaths[iHLT].PSPass = iHLT * 2;
0243 localhlt.HLTPaths[iHLT].PAccept = iHLT * 3;
0244 localhlt.HLTPaths[iHLT].PExcept = iHLT * 4;
0245 localhlt.HLTPaths[iHLT].PReject = iHLT * 5;
0246 std::strncpy(localhlt.HLTPaths[iHLT].PrescalerModule, modulename, 64);
0247 localhlt.HLTPaths[iHLT].PSIndex = iHLT;
0248 localhlt.HLTPaths[iHLT].Prescale = iHLT;
0249 localhlt.HLTPaths[iHLT].HLTConfigId = 6785;
0250 }
0251 localhlt.numPaths = npath;
0252 std::memmove(m_hlt, &localhlt, sizeof(HCAL_HLX::HLTRIGGER));
0253 m_hltTree->Fill();
0254 }
0255 void genLumiRaw::generateTRG(unsigned int runnumber, unsigned int lsnumber) {
0256 HCAL_HLX::LEVEL1_TRIGGER localtrg;
0257 const char* algoname = "Fake";
0258 const char* techname = "11";
0259 localtrg.runNumber = runnumber;
0260 localtrg.sectionNumber = lsnumber;
0261 localtrg.deadtimecount = 3;
0262 for (unsigned int iAlgo = 0; iAlgo < 128; ++iAlgo) {
0263 std::strncpy(localtrg.GTAlgo[iAlgo].pathName, algoname, 128);
0264 localtrg.GTAlgo[iAlgo].counts = iAlgo;
0265 localtrg.GTAlgo[iAlgo].prescale = iAlgo;
0266 }
0267 for (unsigned int iTech = 0; iTech < 64; ++iTech) {
0268 std::strncpy(localtrg.GTTech[iTech].pathName, techname, 128);
0269 localtrg.GTTech[iTech].counts = iTech;
0270 localtrg.GTTech[iTech].prescale = iTech;
0271 }
0272 std::memmove(m_trg, &localtrg, sizeof(HCAL_HLX::LEVEL1_TRIGGER));
0273 m_trgTree->Fill();
0274 }
0275 void genLumiRaw::generateHLX(unsigned int runnumber, unsigned int lsnumber) {
0276 HCAL_HLX::LUMI_SECTION locallumisection;
0277
0278 locallumisection.hdr.timestamp = 1;
0279 locallumisection.hdr.timestamp_micros = 2;
0280 locallumisection.hdr.runNumber = runnumber;
0281 locallumisection.hdr.sectionNumber = lsnumber;
0282 locallumisection.hdr.startOrbit = 3;
0283 locallumisection.hdr.numOrbits = 4;
0284 locallumisection.hdr.numBunches = 5;
0285 locallumisection.hdr.numHLXs = 6;
0286 locallumisection.hdr.bCMSLive = true;
0287 locallumisection.hdr.bOC0 = false;
0288
0289
0290 locallumisection.lumiSummary.DeadTimeNormalization = 1;
0291 locallumisection.lumiSummary.LHCNormalization = 2;
0292 locallumisection.lumiSummary.InstantLumi = 3;
0293 locallumisection.lumiSummary.InstantLumiErr = 4;
0294 locallumisection.lumiSummary.InstantLumiQlty = 5;
0295
0296 locallumisection.lumiSummary.InstantETLumi = 6;
0297 locallumisection.lumiSummary.InstantETLumiErr = 7;
0298 locallumisection.lumiSummary.InstantETLumiQlty = 8;
0299 locallumisection.lumiSummary.ETNormalization = 9;
0300
0301 locallumisection.lumiSummary.InstantOccLumi[0] = 10;
0302 locallumisection.lumiSummary.InstantOccLumiErr[0] = 11;
0303 locallumisection.lumiSummary.InstantOccLumiQlty[0] = 12;
0304 locallumisection.lumiSummary.OccNormalization[0] = 13;
0305
0306 locallumisection.lumiSummary.lumiNoise[0] = 14;
0307
0308 locallumisection.lumiSummary.InstantOccLumi[1] = 10;
0309 locallumisection.lumiSummary.InstantOccLumiErr[1] = 11;
0310 locallumisection.lumiSummary.InstantOccLumiQlty[1] = 12;
0311 locallumisection.lumiSummary.OccNormalization[1] = 13;
0312
0313 locallumisection.lumiSummary.lumiNoise[1] = 14;
0314
0315
0316 for (unsigned int iBX = 0; iBX < HCAL_HLX_MAX_BUNCHES; ++iBX) {
0317 locallumisection.lumiDetail.LHCLumi[iBX] = 143;
0318 locallumisection.lumiDetail.ETLumi[iBX] = 143;
0319 locallumisection.lumiDetail.ETLumiErr[iBX] = 143;
0320 locallumisection.lumiDetail.ETLumiQlty[iBX] = 143;
0321 locallumisection.lumiDetail.ETBXNormalization[iBX] = 143;
0322 locallumisection.lumiDetail.OccLumi[0][iBX] = 143;
0323 locallumisection.lumiDetail.OccLumiErr[0][iBX] = 143;
0324 locallumisection.lumiDetail.OccLumiQlty[0][iBX] = 143;
0325 locallumisection.lumiDetail.OccBXNormalization[0][iBX] = 143;
0326 locallumisection.lumiDetail.OccLumi[1][iBX] = 143;
0327 locallumisection.lumiDetail.OccLumiErr[1][iBX] = 143;
0328 locallumisection.lumiDetail.OccLumiQlty[1][iBX] = 143;
0329 locallumisection.lumiDetail.OccBXNormalization[1][iBX] = 143;
0330 }
0331 std::memmove(m_lumisection, &locallumisection, sizeof(HCAL_HLX::LUMI_SECTION));
0332 m_hlxTree->Fill();
0333 }
0334
0335
0336 DEFINE_FWK_MODULE(genLumiRaw);
0337 #endif