File indexing completed on 2024-04-06 11:59:50
0001 #include "CalibTracker/SiStripDCS/test/Synchronization/SyncDCSO2O.h"
0002
0003 #include "CoralBase/TimeStamp.h"
0004 #include "CondFormats/Common/interface/Time.h"
0005 #include "CondFormats/Common/interface/TimeConversions.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008
0009 #include <iostream>
0010 #include <algorithm>
0011
0012 #include "TFile.h"
0013 #include "TCanvas.h"
0014
0015 SyncDCSO2O::SyncDCSO2O(const edm::ParameterSet& iConfig) : dcsToken_(esConsumes()) {
0016
0017 digiProducersList_ = iConfig.getParameter<Parameters>("DigiProducersList");
0018 }
0019
0020 SyncDCSO2O::~SyncDCSO2O() {
0021 std::cout << "Analyzed events with digis = " << timeInfo_.size() << std::endl;
0022
0023
0024 std::sort(timeInfo_.begin(), timeInfo_.end(), SortByTime());
0025
0026 TFile* outputFile = new TFile("digisAndHVvsTime.root", "RECREATE");
0027 outputFile->cd();
0028
0029 TH1F* digis = new TH1F("digis", "digis", timeInfo_.size(), 0, timeInfo_.size());
0030 TH1F* digisWithMasking = new TH1F("digisWithMasking", "digisWithMasking", timeInfo_.size(), 0, timeInfo_.size());
0031 TH1F* HVoff = new TH1F("HVoff", "HVoff", timeInfo_.size(), 0, timeInfo_.size());
0032 TH1F* time = new TH1F("time", "time", timeInfo_.size(), 0, timeInfo_.size());
0033 std::vector<TimeInfo>::const_iterator it = timeInfo_.begin();
0034
0035 unsigned int i = 1;
0036 for (; it != timeInfo_.end(); ++it, ++i) {
0037 digis->SetBinContent(i, it->digiOccupancy);
0038 digisWithMasking->SetBinContent(i, it->digiOccupancyWithMasking);
0039 HVoff->SetBinContent(i, it->HVoff);
0040
0041
0042 coral::TimeStamp coralTime(cond::time::to_boost(it->time));
0043
0044
0045 TDatime date1(coralTime.year(),
0046 coralTime.month(),
0047 coralTime.day(),
0048 coralTime.hour() + 1,
0049 coralTime.minute(),
0050 coralTime.second());
0051
0052 time->SetBinContent(i, date1.Convert());
0053 }
0054
0055
0056
0057
0058
0059 digis->Draw();
0060 digis->Write();
0061
0062 digisWithMasking->Draw("same");
0063 digisWithMasking->Write();
0064
0065 HVoff->Draw("same");
0066 HVoff->SetLineColor(2);
0067 HVoff->Write();
0068
0069 time->Draw("same");
0070 time->Write();
0071
0072
0073
0074
0075
0076
0077
0078
0079 outputFile->Write();
0080 outputFile->Close();
0081
0082
0083 }
0084
0085
0086 void SyncDCSO2O::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0087 using namespace edm;
0088
0089 const SiStripDetVOff* detVOff = &iSetup.getData(dcsToken_);
0090
0091 std::vector<uint32_t> detIds;
0092 detVOff->getDetIds(detIds);
0093 std::cout << "Number of DetIds with HV off = " << detIds.size() << std::endl;
0094
0095
0096
0097
0098
0099
0100 std::cout << "event time = " << iEvent.time().value() << std::endl;
0101
0102
0103 coral::TimeStamp coralTime(cond::time::to_boost(iEvent.time().value()));
0104
0105 std::cout << "year = " << coralTime.year() << ", month = " << coralTime.month() << ", day = " << coralTime.day();
0106
0107
0108 std::cout << ", hour = " << coralTime.hour() + 1 << ", minute = " << coralTime.minute()
0109 << ", second = " << coralTime.second();
0110 std::cout << ", nanosecond = " << coralTime.nanosecond() << std::endl;
0111
0112 getDigis(iEvent);
0113 if (!(digiDetsetVector_[0].isValid()))
0114 std::cout << "NOT VALID DIGI COLLECTION 0" << std::endl;
0115 else {
0116 edm::DetSetVector<SiStripDigi>::const_iterator it = digiDetsetVector_[0]->begin();
0117 unsigned int totDigis = 0;
0118 unsigned int totDigisWithMasking = 0;
0119 for (; it != digiDetsetVector_[0]->end(); ++it) {
0120 totDigis += it->size();
0121
0122 if (!(detVOff->IsModuleHVOff(it->detId()))) {
0123 totDigisWithMasking += it->size();
0124 }
0125 }
0126 std::cout << "digis = " << totDigis << std::endl;
0127 timeInfo_.push_back(TimeInfo(iEvent.time().value(), totDigis, totDigisWithMasking, detVOff->getHVoffCounts()));
0128 }
0129 }
0130
0131 void SyncDCSO2O::getDigis(const edm::Event& iEvent) {
0132 using namespace edm;
0133
0134 int icoll = 0;
0135 Parameters::iterator itDigiProducersList = digiProducersList_.begin();
0136 for (; itDigiProducersList != digiProducersList_.end(); ++itDigiProducersList) {
0137 std::string digiProducer = itDigiProducersList->getParameter<std::string>("DigiProducer");
0138 std::string digiLabel = itDigiProducersList->getParameter<std::string>("DigiLabel");
0139
0140 iEvent.getByLabel(digiProducer, digiLabel, digiDetsetVector_[icoll]);
0141 icoll++;
0142 }
0143 }
0144
0145
0146 TGraph* SyncDCSO2O::buildGraph(TH1F* histo, Float_t* timeArray) {
0147 unsigned int arraySize = histo->GetNbinsX();
0148
0149 Float_t* valueArray = (histo->GetArray()) + 1;
0150
0151 TGraph* graph = new TGraph(arraySize, valueArray, timeArray);
0152 graph->Draw("A*");
0153 graph->GetXaxis()->SetTimeDisplay(1);
0154 graph->GetXaxis()->SetLabelOffset(0.02);
0155 graph->GetXaxis()->SetTimeFormat("#splitline{ %d}{%H:%M}");
0156 graph->GetXaxis()->SetTimeOffset(0, "gmt");
0157 graph->GetYaxis()->SetRangeUser(0, 16000);
0158 graph->GetXaxis()->SetTitle("day/hour");
0159 graph->GetXaxis()->SetTitleSize(0.03);
0160 graph->GetXaxis()->SetTitleColor(kBlack);
0161 graph->GetXaxis()->SetTitleOffset(1.80);
0162 graph->GetYaxis()->SetTitle("number of digis");
0163 graph->GetYaxis()->SetTitleSize(0.03);
0164 graph->GetYaxis()->SetTitleColor(kBlack);
0165 graph->GetYaxis()->SetTitleOffset(1.80);
0166 graph->SetTitle();
0167
0168 return graph;
0169 }
0170
0171
0172 void SyncDCSO2O::beginJob() {}
0173
0174
0175 void SyncDCSO2O::endJob() {}