147 art::ServiceHandle<art::TFileService const>
tfs;
149 for (
auto it =
fAreas.begin(); it !=
fAreas.end(); ++it) {
150 uint32_t Channel = it->first;
152 std::stringstream histname;
154 histname <<
"ch" << Channel <<
"area";
156 TH1D* HistArea = tfs->make<TH1D>(
159 for (
size_t j = 0; j != it->second.size(); ++j) {
160 HistArea->Fill(it->second.at(j));
163 std::stringstream fitname;
165 fitname <<
"ch" << Channel <<
"fit";
167 double Max = HistArea->GetMaximum();
168 double Mid = HistArea->GetBinContent(
fAreaDivs / 2.);
170 TF1* GausFit =
new TF1(fitname.str().c_str(),
"gaus(0)+gaus(3)+gaus(6)",
fAreaMin,
fAreaMax);
172 GausFit->SetParameters(Mid,
182 GausFit->SetParLimits(0, 0, 1.1 * Max);
183 GausFit->SetParLimits(1, 0,
fAreaMax);
184 GausFit->SetParLimits(2, 0,
fAreaMax);
186 GausFit->SetParLimits(3, 0, 1.1 * Max);
187 GausFit->FixParameter(4, 0);
188 GausFit->SetParLimits(5, 0, (fAreaMin +
fAreaMax) / 2.);
190 GausFit->SetParLimits(6, 0, 1.1 * Max);
191 GausFit->FixParameter(7, 0);
192 GausFit->SetParLimits(8, 0, (fAreaMin +
fAreaMax) / 2.);
194 HistArea->Fit(GausFit);
196 double Mean = GausFit->GetParameter(1);
197 double Width = GausFit->GetParameter(2);
199 double MeanErr = GausFit->GetParError(1);
200 double WidthErr = GausFit->GetParError(2);
202 double NPE = pow(Mean, 2) / pow(Width, 2);
203 double SPEScale = Mean / NPE;
205 double NPEError = NPE * pow(2. * (pow(MeanErr / Mean, 2) + pow(WidthErr / Width, 2)), 0.5);
206 double SPEError = SPEScale * pow(2. * pow(WidthErr / Width, 2) + pow(MeanErr / Mean, 2), 0.5);
208 std::cout <<
"Channel " << Channel <<
":\tSPE Scale \t" << SPEScale <<
"\t +/- \t" << SPEError
209 <<
",\t NPE \t" << NPE <<
"\t +/- \t" << NPEError << std::endl;
std::map< uint32_t, std::vector< double > > fAreas
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout