File indexing completed on 2023-03-17 11:23:43
0001
0002
0003
0004
0005
0006
0007 #include <SimCalorimetry/EcalSimProducers/test/ESDigisReferenceDistrib.h>
0008
0009 ESDigisReferenceDistrib::ESDigisReferenceDistrib(const edm::ParameterSet &ps)
0010 : ESdigiCollection_(ps.getParameter<edm::InputTag>("ESdigiCollection")),
0011 ecalDigiESToken_(consumes<ESDigiCollection>(ESdigiCollection_)) {
0012
0013 outputRootFile_ = ps.getUntrackedParameter<std::string>("outputRootFile", "");
0014 outputTxtFile_ = ps.getUntrackedParameter<std::string>("outputTxtFile", "");
0015
0016
0017 char histo[200];
0018 for (int ii = 0; ii < 3; ii++) {
0019 sprintf(histo, "esRefHistos%02d", ii);
0020 meESDigiADC_[ii] = new TH1F(histo, histo, 80, 960.5, 1040.5);
0021 }
0022
0023 meESDigi3D_ = new TH3F("meESDigi3D_", "meESDigi3D_", 80, 960.5, 1040.5, 80, 960.5, 1040.5, 80, 960.5, 1040.5);
0024 }
0025
0026 ESDigisReferenceDistrib::~ESDigisReferenceDistrib() {
0027
0028 std::ofstream *outFile_ = new std::ofstream(outputTxtFile_.c_str(), std::ios::out);
0029 *outFile_ << "# number of bin" << std::endl;
0030 *outFile_ << "# axis inf (common to the three axes" << std::endl;
0031 *outFile_ << "# axis sup (common to the three axes" << std::endl;
0032 *outFile_ << "# bin x bin content" << std::endl;
0033 *outFile_ << "# " << std::endl;
0034
0035 if (!meESDigi3D_)
0036 throw cms::Exception("ESDigisReferenceDistrib: problems with the reference histo");
0037 else {
0038 float histoBin_ = meESDigi3D_->GetNbinsX();
0039 float histoInf_ = meESDigi3D_->GetBinLowEdge(1);
0040 float histoSup_ = meESDigi3D_->GetBinLowEdge((int)histoBin_) + meESDigi3D_->GetBinWidth((int)histoBin_);
0041
0042 *outFile_ << histoBin_ << std::endl;
0043 *outFile_ << histoInf_ << std::endl;
0044 *outFile_ << histoSup_ << std::endl;
0045
0046 for (int thisBinZ = 1; thisBinZ <= meESDigi3D_->GetNbinsZ(); thisBinZ++) {
0047 for (int thisBinY = 1; thisBinY <= meESDigi3D_->GetNbinsY(); thisBinY++) {
0048 for (int thisBinX = 1; thisBinX <= meESDigi3D_->GetNbinsX(); thisBinX++) {
0049 *outFile_ << meESDigi3D_->GetBinContent(thisBinX, thisBinY, thisBinZ) << std::endl;
0050 }
0051 }
0052 }
0053 }
0054
0055
0056 TFile file(outputRootFile_.c_str(), "RECREATE");
0057 for (int ii = 0; ii < 3; ii++) {
0058 meESDigiADC_[ii]->Write();
0059 }
0060 meESDigi3D_->Write();
0061 file.Close();
0062
0063 for (int ii = 0; ii < 3; ii++) {
0064 if (meESDigiADC_[ii]) {
0065 delete meESDigiADC_[ii];
0066 }
0067 }
0068 if (meESDigi3D_)
0069 delete meESDigi3D_;
0070 }
0071
0072 void ESDigisReferenceDistrib::beginJob() {}
0073
0074 void ESDigisReferenceDistrib::endJob() {}
0075
0076 void ESDigisReferenceDistrib::analyze(const edm::Event &e, const edm::EventSetup &c) {
0077 const auto &EcalDigiES = e.getHandle(ecalDigiESToken_);
0078
0079
0080 const ESDigiCollection *preshowerDigi = EcalDigiES.product();
0081
0082 std::vector<double> esADCCounts;
0083 esADCCounts.reserve(ESDataFrame::MAXSAMPLES);
0084
0085 for (unsigned int digis = 0; digis < EcalDigiES->size(); ++digis) {
0086 ESDataFrame esdf = (*preshowerDigi)[digis];
0087 int nrSamples = esdf.size();
0088
0089 if (meESDigi3D_)
0090 meESDigi3D_->Fill(esdf[0].adc(), esdf[1].adc(), esdf[2].adc());
0091 for (int sample = 0; sample < nrSamples; ++sample) {
0092 ESSample mySample = esdf[sample];
0093 if (meESDigiADC_[sample]) {
0094 meESDigiADC_[sample]->Fill(mySample.adc());
0095 }
0096 }
0097 }
0098 }
0099
0100
0101
0102 DEFINE_FWK_MODULE(ESDigisReferenceDistrib);