File indexing completed on 2024-04-06 12:27:56
0001 #include "RecoTBCalo/EcalTBHodoscopeReconstructor/interface/EcalTBHodoscopeRawInfoDumper.h"
0002 #include "TBDataFormats/EcalTBObjects/interface/EcalTBHodoscopeRawInfo.h"
0003 #include "DataFormats/Common/interface/EDCollection.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007
0008 #include <TFile.h>
0009 #include <FWCore/Framework/interface/MakerMacros.h>
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011
0012 EcalTBHodoscopeRawInfoDumper::EcalTBHodoscopeRawInfoDumper(edm::ParameterSet const& ps) {
0013 rawInfoCollection_ = ps.getParameter<std::string>("rawInfoCollection");
0014 rawInfoProducer_ = ps.getParameter<std::string>("rawInfoProducer");
0015 rootfile_ = ps.getUntrackedParameter<std::string>("rootfile", "ecalHodoscopeRawInfoPlots.root");
0016 }
0017
0018 EcalTBHodoscopeRawInfoDumper::~EcalTBHodoscopeRawInfoDumper() {}
0019
0020
0021 void EcalTBHodoscopeRawInfoDumper::beginJob() {
0022
0023
0024 char histoName[100];
0025 char histoTitle[100];
0026
0027 for (int i = 0; i < 4; i++) {
0028 sprintf(histoName, "h_numberOfFiredHits_%d", i);
0029 sprintf(histoTitle, "NumberOfFiredHits Plane %d", i);
0030 h_numberOfFiredHits_[i] = new TH1F(histoName, histoTitle, 10, 0., 10.);
0031 }
0032
0033 for (int i = 0; i < 4; i++) {
0034 sprintf(histoName, "h_firedHits_%d", i);
0035 sprintf(histoTitle, "firedHits Plane %d", i);
0036 h_firedHits_[i] = new TH1F(histoName, histoTitle, 64, -0.5, 63.5);
0037 }
0038 }
0039
0040
0041 void EcalTBHodoscopeRawInfoDumper::endJob() {
0042
0043
0044 TFile f(rootfile_.c_str(), "RECREATE");
0045
0046 for (int i = 0; i < 4; i++)
0047 h_numberOfFiredHits_[i]->Write();
0048
0049 for (int i = 0; i < 4; i++)
0050 h_firedHits_[i]->Write();
0051
0052 f.Close();
0053 }
0054
0055 void EcalTBHodoscopeRawInfoDumper::analyze(const edm::Event& e, const edm::EventSetup& es) {
0056
0057 edm::Handle<EcalTBHodoscopeRawInfo> ecalRawHodoscope;
0058 const EcalTBHodoscopeRawInfo* hodoscopeRawInfo = nullptr;
0059
0060 e.getByLabel(rawInfoProducer_, ecalRawHodoscope);
0061 if (!ecalRawHodoscope.isValid()) {
0062 edm::LogError("EcalTBHodoscopeRecInfoError") << "Error! can't get the product " << rawInfoCollection_.c_str();
0063 } else {
0064 hodoscopeRawInfo = ecalRawHodoscope.product();
0065 }
0066
0067 if (hodoscopeRawInfo)
0068 for (int i = 0; i < 4; i++) {
0069 std::ostringstream str;
0070 str << " Hits ";
0071 std::vector<int> firedHits;
0072 h_numberOfFiredHits_[i]->Fill((*hodoscopeRawInfo)[i].numberOfFiredHits());
0073 for (int j = 0; j < 64; j++)
0074 if ((*hodoscopeRawInfo)[i][j]) {
0075 h_firedHits_[i]->Fill(j);
0076 firedHits.push_back(j);
0077 str << j << " ";
0078 }
0079 LogDebug("EcalTBHodoscope") << "Looking plane " << i << " number of hits "
0080 << (*hodoscopeRawInfo)[i].numberOfFiredHits() << str.str();
0081 }
0082
0083 }