File indexing completed on 2024-04-06 11:57:49
0001
0002
0003
0004
0005
0006
0007
0008 #include <TFile.h>
0009 #include <TTree.h>
0010 #include <TChain.h>
0011
0012 #include "EcalPerEvtMatacqAnalyzer.h"
0013
0014 #include <sstream>
0015 #include <iostream>
0016 #include <iomanip>
0017
0018 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0019 #include <FWCore/Utilities/interface/Exception.h>
0020
0021 #include <FWCore/Framework/interface/Event.h>
0022 #include <FWCore/Framework/interface/MakerMacros.h>
0023 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0024 #include <FWCore/Framework/interface/EventSetup.h>
0025
0026 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h>
0027
0028
0029 EcalPerEvtMatacqAnalyzer::EcalPerEvtMatacqAnalyzer(const edm::ParameterSet& iConfig)
0030 : iEvent(0),
0031
0032
0033 _presample(iConfig.getUntrackedParameter<double>("nPresamples", 6.7)),
0034 _nsamplesaftmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesAftMax", 80)),
0035 _nsamplesbefmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesBefMax", 20)),
0036 _noiseCut(iConfig.getUntrackedParameter<unsigned int>("noiseCut", 7)),
0037 _parabnbefmax(iConfig.getUntrackedParameter<unsigned int>("paraBeforeMax", 8)),
0038 _parabnaftmax(iConfig.getUntrackedParameter<unsigned int>("paraAfterMax", 7)),
0039 _thres(iConfig.getUntrackedParameter<unsigned int>("threshold", 10)),
0040 _lowlev(iConfig.getUntrackedParameter<unsigned int>("lowLevel", 20)),
0041 _highlev(iConfig.getUntrackedParameter<unsigned int>("highLevel", 80)),
0042 _nevlasers(iConfig.getUntrackedParameter<unsigned int>("nEventLaser", 600)),
0043 resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
0044 digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
0045 digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
0046 eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
0047 eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
0048 pmatToken_(consumes<EcalMatacqDigiCollection>(edm::InputTag(digiProducer_, digiCollection_))),
0049 dccToken_(consumes<EcalRawDataCollection>(edm::InputTag(digiProducer_)))
0050
0051
0052 {
0053
0054 }
0055
0056
0057 void EcalPerEvtMatacqAnalyzer::beginJob() {
0058
0059
0060
0061
0062 IsFileCreated = 0;
0063 IsTreeCreated = 0;
0064 }
0065
0066
0067 void EcalPerEvtMatacqAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& c) {
0068
0069
0070 ++iEvent;
0071
0072
0073 const edm::Handle<EcalMatacqDigiCollection>& pmatacqDigi = e.getHandle(pmatToken_);
0074 const EcalMatacqDigiCollection* matacqDigi = (pmatacqDigi.isValid()) ? pmatacqDigi.product() : nullptr;
0075 if (!(pmatacqDigi.isValid()))
0076 edm::LogWarning("EcalPerEvtMatacqAnalyzer") << "Error! can't get the product " << digiCollection_.c_str();
0077
0078
0079
0080 const edm::Handle<EcalRawDataCollection>& pDCCHeader = e.getHandle(dccToken_);
0081 const EcalRawDataCollection* DCCHeader = (pDCCHeader.isValid()) ? pDCCHeader.product() : nullptr;
0082 if (!pDCCHeader.isValid())
0083 edm::LogWarning("EcalPerEvtMatacqAnalyzer") << "Error! can't get the product " << eventHeaderCollection_.c_str();
0084
0085
0086
0087
0088
0089 for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
0090 ++headerItr) {
0091 event = headerItr->getLV1();
0092 EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
0093
0094 laser_color = (int)settings.wavelength;
0095
0096
0097
0098 runType = headerItr->getRunType();
0099 runNum = headerItr->getRunNumber();
0100
0101
0102
0103 if (runType != EcalDCCHeaderBlock::LASER_STD && runType != EcalDCCHeaderBlock::LASER_GAP &&
0104 runType != EcalDCCHeaderBlock::LASER_POWER_SCAN && runType != EcalDCCHeaderBlock::LASER_DELAY_SCAN)
0105 return;
0106
0107
0108
0109 if (IsFileCreated == 0) {
0110 std::stringstream namefile;
0111
0112 namefile << resdir_ << "/MatacqPerEvt-Run" << runNum << ".root";
0113 outfile = namefile.str();
0114
0115 outFile = new TFile(outfile.c_str(), "RECREATE");
0116
0117
0118
0119 tree = new TTree("MatacqTree", "MatacqTree");
0120
0121 IsFileCreated = 1;
0122 }
0123 }
0124
0125
0126
0127
0128
0129 int iCh = 0;
0130 double max = 0;
0131
0132 for (EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it != matacqDigi->end();
0133 ++it) {
0134
0135
0136 const EcalMatacqDigi& digis = *it;
0137
0138 if (digis.size() == 0 || iCh >= N_channels)
0139 continue;
0140
0141 max = 0;
0142 maxsamp = 0;
0143 nsamples = digis.size();
0144
0145 if (IsTreeCreated == 0) {
0146
0147
0148 std::stringstream mat;
0149 mat << "matacq[" << nsamples << "]/D" << std::endl;
0150
0151 tree->Branch("event", &event, "event/I");
0152 tree->Branch("laser_color", &laser_color, "laser_color/I");
0153
0154 tree->Branch("matacq", &matacq, mat.str().c_str());
0155 tree->Branch("maxsamp", &maxsamp, "maxsamp/I");
0156 tree->Branch("ttrig", &ttrig, "ttrig/D");
0157
0158 tree->SetBranchAddress("event", &event);
0159 tree->SetBranchAddress("laser_color", &laser_color);
0160 tree->SetBranchAddress("matacq", matacq);
0161
0162 tree->SetBranchAddress("maxsamp", &maxsamp);
0163 tree->SetBranchAddress("ttrig", &ttrig);
0164
0165 IsTreeCreated = 1;
0166 }
0167
0168 ttrig = digis.tTrig();
0169
0170 for (int i = 0; i < digis.size(); ++i) {
0171 matacq[i] = digis.adcCount(i);
0172 if (matacq[i] > max) {
0173 max = matacq[i];
0174 maxsamp = i;
0175 }
0176 }
0177
0178 iCh++;
0179 }
0180
0181 tree->Fill();
0182
0183 }
0184
0185
0186 void EcalPerEvtMatacqAnalyzer::endJob() {
0187 tree->Write();
0188 outFile->Close();
0189 }
0190
0191 DEFINE_FWK_MODULE(EcalPerEvtMatacqAnalyzer);