99#include " icaruscode/Timing/PMTTimingCorrections.h"
1010#include " icaruscode/Timing/IPMTTimingCorrectionService.h"
1111#include " icaruscode/Timing/PMTTimingCorrectionsProvider.h"
12+ #include " icaruscode/PMT/Calibration/ICARUSPhotonCalibratorServiceFromDB.h"
1213
1314// framework libraries
1415#include " canvas/Utilities/InputTag.h"
@@ -45,25 +46,25 @@ namespace icarus
4546 * gain and/or timing calibrations, and applies new ones.
4647 * A new collection of hits is produced containing a re-calibrated copy of all the
4748 * hits from the input collections.
48- *
49- * The PE recalibration is simple: for each optical hit, its `PE` value is recomputed
49+ *
50+ * The PE recalibration is simple: for each optical hit, its `PE` value is recomputed
5051 * from its `Area` [ADC x tick] based on a newly determined single-PE area.
5152 * If `UseGainDatabase` is set, the module calls retrieves the SPE area by channel and run number
52- * using the gain calibration service. If that option is disabled, a single SPE area value
53+ * using the gain calibration service. If that option is disabled, a single SPE area value
5354 * is used for all channels and run numbers. This value is read from the `SPEArea` paramater
5455 * set in the configuration.
55- *
56- * The timing recalibration requires removing previously-applied timing corrections and
57- * adding the new ones. Unfortunately, however, it's not possible to easily determine
56+ *
57+ * The timing recalibration requires removing previously-applied timing corrections and
58+ * adding the new ones. Unfortunately, however, it's not possible to easily determine
5859 * which timing corrections were previsouly applied to the optical hits.
5960 * The old corrections -- that need to be removed -- are therefore obtained by locally
60- * definining an instance of `icarusDB::PMTTimingCorrectionsProvider` and manually setting
61+ * definining an instance of `icarusDB::PMTTimingCorrectionsProvider` and manually setting
6162 * in the configuration the database tags that were used originally (`OldTimingDBTags`).
6263 * These need to be deduced by the `icaruscode` version that was used and the corresponding
6364 * settings in `calibration_database_GlobalTags_icarus.fcl`
6465 * On the other hand, the new corrections are obtained from the current timing correction
6566 * service `icarusDB::PMTTimingCorrections` as defined in `timing_icarus.fcl`.
66- *
67+ *
6768 * Input
6869 * ------
6970 * * `std::vector<recob::OpHit>` data products (as for `InputLabels`)
@@ -83,9 +84,9 @@ namespace icarus
8384 * * `SPEArea` (double, default: -1): if not using the gain database, single-photoelectron
8485 * area in ADC x tick to be used in the PE calibration.
8586 * * `RecalibrateTime` (flag, mandatory): if set, recalibrate hit times.
86- * * `OldTimingDBTags` (fhicl::ParameterSet, mandatory): configuration for the previously-applied timing corrections
87+ * * `OldTimingDBTags` (fhicl::ParameterSet, mandatory): configuration for the previously-applied timing corrections
8788 * that need to be removed/replace by the now ones. It should match what is tipically passed to
88- * `icarusDB::PMTTimingCorrectionsProvider`, specifying the database tags that were used.
89+ * `icarusDB::PMTTimingCorrectionsProvider`, specifying the database tags that were used.
8990 * * `Verbose` (flag, default: `false`): verbose printing
9091 *
9192 */
@@ -108,10 +109,11 @@ class icarus::OpHitRecalibrator : public art::SharedProducer
108109 bool const fRecalibrateTime ;
109110 bool const fUseGainDatabase ;
110111 double const fSPEArea ;
111- bool const fVerbose ;
112+ bool const fVerbose ;
112113
113- // / Pointer to the online pmt corrections service
114+ // / Pointers to the online corrections services
114115 icarusDB::PMTTimingCorrections const &fPMTTimingCorrectionsService ;
116+ icarusDB::PhotonCalibratorFromDB const &fPhotonCalibratorService ;
115117
116118 // / Pointer to the provider for the old pmt corrections
117119 std::unique_ptr<icarusDB::PMTTimingCorrectionsProvider> fOldTimingProvider ;
@@ -127,6 +129,7 @@ icarus::OpHitRecalibrator::OpHitRecalibrator(fhicl::ParameterSet const &config,
127129 fSPEArea {config.get <double >(" SPEArea" , -1 .)},
128130 fVerbose {config.get <bool >(" Verbose" , false )},
129131 fPMTTimingCorrectionsService {*(lar::providerFrom<icarusDB::IPMTTimingCorrectionService const >())},
132+ fPhotonCalibratorService {*(lar::providerFrom<icarusDB::ICARUSPhotonCalibratorServiceFromDB const >())},
130133 fOldTimingProvider {std::make_unique<icarusDB::PMTTimingCorrectionsProvider>(config.get <fhicl::ParameterSet>(" OldTimingDBTags" ))}
131134{
132135 async<art::InEvent>();
@@ -141,7 +144,7 @@ icarus::OpHitRecalibrator::OpHitRecalibrator(fhicl::ParameterSet const &config,
141144 if (!fRecalibratePE && !fRecalibrateTime )
142145 {
143146 throw art::Exception{art::errors::Configuration}
144- << " No re-calibration selected. Why are you running meeee!?!?! :/\n " ;
147+ << " No re-calibration selected. Why are you even running meeee, !?!?! :/\n " ;
145148 }
146149
147150 if (fRecalibratePE && !fUseGainDatabase && (fSPEArea < 0 ))
@@ -161,11 +164,10 @@ icarus::OpHitRecalibrator::OpHitRecalibrator(fhicl::ParameterSet const &config,
161164 << " -> new " << fPMTTimingCorrectionsService .getCosmicsDatabaseTag ();
162165 }
163166
164- // FIXME: temporary since no gain db exists yet...
165- if (fUseGainDatabase )
167+ if (fRecalibratePE && fUseGainDatabase )
166168 {
167- throw art::Exception{art::errors::Configuration}
168- << " Gain database interface doesn't exist yet. Try again later. \n " ;
169+ mf::LogInfo ( " OpHitRecalibrator " ) << " Re-calibration of PE (gain) enabled: \n "
170+ << " AreaTag: " << fPhotonCalibratorService . getAreaDatabaseTag () ;
169171 }
170172
171173 // Consumes
@@ -218,9 +220,16 @@ void icarus::OpHitRecalibrator::produce(art::Event &event, art::ProcessingFrame
218220
219221 if (fUseGainDatabase )
220222 {
221- // soon...
222- // newSPEArea = get_from_db(opHit.OpChannel())
223+ // service directly returns PE from area and channel
224+ // compute SPE area back for logging purposes
225+ hitPE = fPhotonCalibratorService .PE (opHit.Area (), opHit.OpChannel ());
226+ newSPEArea = opHit.Area () / hitPE;
223227 }
228+ else
229+ {
230+ // simple re-computation
231+ hitPE = opHit.Area () / newSPEArea;
232+ }
224233
225234 if (log)
226235 {
@@ -230,9 +239,7 @@ void icarus::OpHitRecalibrator::produce(art::Event &event, art::ProcessingFrame
230239 << " (old SPEArea: " << oldSPEArea
231240 << " ) --> new PE " << opHit.Area () / newSPEArea
232241 << " (new SPEArea: " << newSPEArea << " )\n " ;
233- }
234-
235- hitPE = opHit.Area () / newSPEArea;
242+ }
236243 }
237244
238245 // Second, recalibrate PMT times (if enabled)
0 commit comments