24 #include "FWCore/Framework/interface/Frameworkfwd.h"
25 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
27 #include "FWCore/Framework/interface/Event.h"
28 #include "FWCore/Framework/interface/MakerMacros.h"
30 #include "FWCore/ParameterSet/interface/ParameterSet.h"
33 #include "HGCal/DataFormats/interface/HGCalTBDigiCollections.h"
34 #include "HGCal/CondObjects/interface/HGCalCondObjects.h"
35 #include "HGCal/CondObjects/interface/HGCalCondObjectTextIO.h"
36 #include "HGCal/CondObjects/interface/HGCalTBNumberingScheme.h"
51 class Pedestals :
public edm::one::EDAnalyzer<edm::one::SharedResources>
54 explicit Pedestals(
const edm::ParameterSet&);
57 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 virtual void beginJob()
override;
62 virtual void analyze(
const edm::Event&,
const edm::EventSetup&)
override;
63 virtual void endJob()
override;
67 edm::EDGetTokenT<HGCalTBDigiCollection> _digisToken;
75 typedef std::map< HGCalTBDetId, pedestalSum_t > pedestalMap_t;
76 pedestalMap_t pedestals;
91 Pedestals::Pedestals(
const edm::ParameterSet& iConfig) :
95 usesResource(
"TFileService");
100 Pedestals::~Pedestals()
115 Pedestals::analyze(
const edm::Event& iEvent,
const edm::EventSetup& iSetup)
119 edm::Handle<HGCalTBDigiCollection> digisHandle;
120 iEvent.getByToken(_digisToken, digisHandle);
128 condIO.load(
"CondObjects/data/map_FNAL_2.txt", emap);
130 for(
auto digi_itr = digisHandle->begin(); digi_itr != digisHandle->end(); ++digi_itr) {
135 unsigned int nSamples = digi.samples();
141 pedestalMap_t::iterator thisPedestal_itr = pedestals.find(detId);
142 if(thisPedestal_itr == pedestals.end()) {
143 pedestalSum_t empty_ped;
147 pedestals[detId] = empty_ped;
148 thisPedestal_itr = pedestals.find(detId);
149 assert(thisPedestal_itr != pedestals.end());
153 for(
unsigned int iSample = 0; iSample < nSamples; ++iSample) {
154 thisPedestal_itr->second.sum += digi[iSample].adcLow();
155 thisPedestal_itr->second.sum2 += digi[iSample].adcLow() * digi[iSample].adcLow();
156 ++(thisPedestal_itr->second.n);
158 std::cout <<
"[PEDESTAL PRODUCER: digi]" << *digi_itr << std::endl;
159 std::cout <<
" ** " << thisPedestal_itr->second.sum << std::endl;
166 for(
const auto pedestal : pedestals) {
167 float pedestal_mean = pedestal.second.sum / pedestal.second.n;
168 pedestals_cond.set(pedestal.first, pedestal_mean);
169 noise_cond.set(pedestal.first, sqrt(pedestal.second.sum2 / pedestal.second.n - (pedestal_mean * pedestal_mean)));
171 condIO.store(
"newPedestals.txt", pedestals_cond);
172 condIO.store(
"newNoise.txt", noise_cond);
179 Pedestals::beginJob()
191 Pedestals::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
195 edm::ParameterSetDescription desc;
197 descriptions.addDefault(desc);
DEFINE_FWK_MODULE(Pedestals)
static const HGCalCondObjectNumberingScheme * scheme()
provides the conversion between electronics Id to DetId