Calibrator_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file Calibrator_service.cc
3 /// \brief Service that handles calibrations for a particular
4 /// validity context (eg: detector+timestamp).
5 /// \author Christopher Backhouse - bckhouse@caltech.edu
6 ////////////////////////////////////////////////////////////////////////
8 #include "RecoBaseHit/CellHit.h"
9 #include "RecoBaseHit/RecoHit.h"
10 
14 
20 
22 
23 #include "DAQDataFormats/NanoSliceVersionConvention.h"
24 
26 
28 
29 #include "TRandom3.h"
30 
31 #include <cmath>
32 
33 
34 
35 namespace calib
36 {
37  // Number of points we expect to receive, to find the best peak match with
38  //const unsigned int kNumFineTimingADCPoints = 4; // Including the DCS origin
39 
40  //------------------------------------------------------------
43  : fParams(params())
44  ,fCurrTimeStamp(0)
45  , fCalibrateMode(0)
46  , fShapeTable(nullptr)
47  , fShapeTable5TB(nullptr)
48  , fAttenCacheData(new AttenCache(true, -1)) // is data, no bin number
49  , fDriftCache(new DriftCache)
50  , fAbsCache(new AbsCache)
51  , fTimingCache(new TimingCache)
52  , fTimingCacheVldTimeSet(false)
53  , fGain(-1)
54  , fXFunction(nullptr)
55  , fXMuCFunction(nullptr)
56  , fYFunction(nullptr)
57  , fStatsNumCalibrated(0)
58  , fStatsNumUncalibrated(0)
59  , fStatsNumAveraged(0)
60  {
61  // AttenCacheMC is initialized in postBeginRun
62  // when number of brightness bins is known
63 
64 
65  // Fix up the filename by looking in the search path
66  cet::search_path sp("FW_SEARCH_PATH");
67  std::string calibrate_mode = fParams.CalibrationMode();
68  if (calibrate_mode == "default") fCalibrateMode = 0;
69  else fCalibrateMode = 1;
70  fhicl::ParameterSet fPSetFiles = params.get_PSet().get<fhicl::ParameterSet>(calibrate_mode);
71 
72  sp.find_file(fPSetFiles.get< std::string >("ShapeTableFilenameFDMC"), fShapeTableFilenameFDMC);
73  sp.find_file(fPSetFiles.get< std::string >("ShapeTableFilenameFDData"), fShapeTableFilenameFDData);
74  sp.find_file(fPSetFiles.get< std::string >("ShapeTableFilenameNDMC"), fShapeTableFilenameNDMC);
75  sp.find_file(fPSetFiles.get< std::string >("ShapeTableFilenameNDData"), fShapeTableFilenameNDData);
76 
77  if(fShapeTableFilenameFDMC.empty() ||
78  fShapeTableFilenameFDData.empty() ||
79  fShapeTableFilenameNDMC.empty() ||
81  throw cet::exception("Calibrator")
82  << "Cannot find at least one shape table file: "
83  << "\nFDMC: " << fShapeTableFilenameFDMC
84  << "\nFDData: " << fShapeTableFilenameFDData
85  << "\nNDMC: " << fShapeTableFilenameNDMC
86  << "\nNDData: " << fShapeTableFilenameNDData
87  << "\n";
88 
89 
90  // Special fcl parameters
91  fTag = fParams.Tag(); // will be typing this a lot
92  fGain = fParams.Gain(); // fGain may need to be reset
93 
94 
95  // Set tags and paths for Absolute, Timing, and Drift Calib
96  // Atten is set in postBeginRun
103  //
110  //
117 
118 
119  reg.sPreProcessEvent.watch(this, &Calibrator::preEvent);
121  reg.sPostBeginRun.watch(this, &Calibrator::postBeginRun);
122  }
123 
124  //------------------------------------------------------------
126  {
127  if(fShapeTable){
128  // Expecting about 95%
129  mf::LogInfo("Calibrator") << "ADCShapeFitTable hit rate was "
130  << int(100*fShapeTable->TableHitFraction())
131  << "%";
132  delete fShapeTable;
133  }
134  if(fShapeTable5TB){
135  // Expecting about 95%
136  mf::LogInfo("Calibrator") << "ADCShapeFitTable v5 (TB only) hit rate was "
138  << "%";
139  delete fShapeTable5TB;
140  }
141 
142  // NumCalibrated includes NumAveraged
143  const unsigned int numRet = fStatsNumCalibrated+fStatsNumUncalibrated;
144  if(numRet > 0){
145  // Hopefully around 1%
146  mf::LogInfo("Calibrator")
147  << "Provided " << numRet << " RecoHits, of which "
148  << ((1000*fStatsNumUncalibrated)/numRet)*.1 << "% were uncalibrated and "
149  << ((1000*fStatsNumAveraged)/numRet)*.1 << "% were average constants.";
150  }
151 
152  for(AttenCache* c: fAttenCacheMC) delete c;
153  delete fAttenCacheData;
154  delete fDriftCache;
155  delete fAbsCache;
156  delete fTimingCache;
157  }
158 
159  //------------------------------------------------------------
161  {
162  // use the art::Timestamp to create the fCurrTrimeStamp value
163  unsigned long long int tsval = evt.time().value();
164 
165  // taking it apart
166  // the masking isn't strictly necessary *if* "long" is truly 32bits
167  // but this can vary w/ compiler/platform
168  const unsigned long int mask32 = 0xFFFFFFFFUL;
169  time_t lup = ( tsval >> 32 ) & mask32;
170  int llo = tsval & mask32;
171  TTimeStamp tts(lup, llo);
172  fCurrTimeStamp = tts;
173  }
174 
175  //------------------------------------------------------------
177  {
178  return;
179  }
180 
181  //------------------------------------------------------------
183  {
184  fAbsCache->Reinit();
185 
186  // New run. We need to update the TimingCache VldTime. But don't do it
187  // until someone actually accesses TimingCache, just make a note. Avoids
188  // accessing RunHistory when we don't have to, especially in case of
189  // generation jobs where it will actually fail.
190  fTimingCacheVldTimeSet = false;
191  fCurrentRun=run.run();
192 
194  mf::LogInfo("Calibrator") << "Cacheing MC attenuation correction for each of "
196  << " fiber brightness bins.";
197 
203  if( fAttenCacheData->UseEpochs() ) {
205  fAttenCacheData->SetEpoch(" ");
206  }
207  //RJN addition to avoid epoch reading
210 
211  // Initialize MC AttenCaches, indexed by
212  // fiber brightness if brightness is modeled.
213  bool AttenCacheMCEmpty = fAttenCacheMC.empty();
214  for(size_t b=0; b<fFibBrightness->NumberBrightnessBins(); b++){
215 
216  // Initialize AttenCaches only in the first postBeginRun...
217  // done in postBeginRun so number of brightness bins known
218  if(AttenCacheMCEmpty){
219 
220  // when brightness is not modelled, let AttenCache know with -1
222  fAttenCacheMC.emplace_back(new AttenCache(false, -1)); // not data, no bin number
223  else
224  fAttenCacheMC.emplace_back(new AttenCache(false, int(b))); // not data, bin b
225 
226  fAttenCacheMC[b]->SetTag ( fTag );
227  fAttenCacheMC[b]->SetUseEpochs ( fParams.UseAttenEpochs() );
228  fAttenCacheMC[b]->SetEpochTag ( fParams.AttenEpochTag() );
229  fAttenCacheMC[b]->UseCSVsFromUPS ( fParams.UseCSVsFromUPS() );
230  fAttenCacheMC[b]->SetCSVSource ( fParams.AttenCSVPath() );
231  fAttenCacheMC[b]->ReadEpochsFromCSV( fParams.ReadEpochsFromCSV() );
232  }
233 
234  // ...but do reinit and set run/epoch every run
235  if( fAttenCacheMC[b]->UseEpochs() ) {
236  fAttenCacheMC[b]->SetRun(fCurrentRun);
237  fAttenCacheMC[b]->SetEpoch(" ");
238  }
239  fAttenCacheMC[b]->Reinit();
240  } // every bin
241 
242 
243  if (fParams.UseDrift()) {
244  // using RunHistory to set validity time range for drift correction
246  int runNum = rh->RunNumber();
247  // load from either CSV or DB
249  }
250 
251 
252  if (fAbsCache->UseEpochs()) {
254  fAbsCache->SetEpoch(" ");
255  }
256 
257  if (fTimingCache->UseEpochs()) {
259  fTimingCache->SetEpoch(" ");
260  }
261 
264  int gainSetting = rh->DetGainSetting();
265  if (fParams.UseGainSetting4Abs() &&
266  (gainSetting != fAbsCache->GainSetting())) {
267  fAbsCache->Reinit();
268  fAbsCache->SetGainSetting(gainSetting);
269  }
270  // reinit MC cahces
271  for(size_t b=0; b<fAttenCacheMC.size(); b++){
273  (gainSetting != fAttenCacheMC[b]->GainSetting())) {
274  fAttenCacheMC[b]->Reinit();
275  fAttenCacheMC[b]->SetGainSetting(gainSetting);
276  }
277  } // for each brightness bin
278 
279  // reinit data cache
281  (gainSetting != fAttenCacheData->GainSetting())) {
283  fAttenCacheData->SetGainSetting(gainSetting);
284  }
285  }
286 
287 
289  if(fGain < 0) // Signal to look in the DB
290  fGain = rh->DetGainSetting();
291 
292  if(fGain <= 0) { // something's not right
293  std::cerr << "Failed to get gain from DB. Aborting" << std::endl;
294  abort();
295  }
296 
297 
298  // Get the right functional form based off of gain
299  std::string XFunctionForm, XMuCFunctionForm, YFunctionForm;
300  std::vector<double> XFunctionParams, XMuCFunctionParams, YFunctionParams;
301  if( fGain==100 ){
302  XFunctionForm = fParams.Xg100FunctionForm();
303  XFunctionParams = fParams.Xg100FunctionParams();
304  YFunctionForm = fParams.Yg100FunctionForm();
305  YFunctionParams = fParams.Yg100FunctionParams();
306  }
307  else if( fGain==140 ){
308  XFunctionForm = fParams.Xg140FunctionForm();
309  XFunctionParams = fParams.Xg140FunctionParams();
310  YFunctionForm = fParams.Yg140FunctionForm();
311  YFunctionParams = fParams.Yg140FunctionParams();
312  }
313  else if( fParams.UseXFunction() || fParams.UseYFunction() ){
314  std::cerr << "Unexpected gain, no shape functions, aborting" << std::endl;
315  abort();
316  }
318  if( fGain==100 ){
319  XMuCFunctionForm = fParams.XMuCg100FunctionForm();
320  XMuCFunctionParams = fParams.XMuCg100FunctionParams();
321  } else {
322  std::cerr << "Unexpected gain in ND, no shape functions, aborting" << std::endl;
323  abort();
324  }
325  }
326 
327  // Initialize PECorr shift functions if configured
328  if (fParams.UseXFunction()){
329  fXFunction = new TF1("x_function", XFunctionForm.c_str(), -900, 900);
331  for (size_t i = 0; i < XFunctionParams.size(); ++i){
332  fXFunction->SetParameter(i, XFunctionParams[i]);
333  }
334 
335  // shift Muon Catcher separately if nonempty MuC function string
336  if(XMuCFunctionForm!=""){
337  fXMuCFunction = new TF1("x_mc_function", XMuCFunctionForm.c_str(), -900, 900);
339  for (size_t i = 0; i < XMuCFunctionParams.size(); ++i){
340  fXMuCFunction->SetParameter(i, XMuCFunctionParams[i]);
341  }
342  }
343 
344  }
345  if (fParams.UseYFunction()){
346  fYFunction = new TF1("y_function", YFunctionForm.c_str(), -900, 900);
348  for (size_t i = 0; i < YFunctionParams.size(); ++i){
349  fYFunction->SetParameter(i, YFunctionParams[i]);
350  }
351  }
352 
353  } // end postBeginRun
354 
355 
356 
357  //------------------------------------------------------------
358  // RawDigit-to-CellHit methods
359  //------------------------------------------------------------
360 
362  {
363  // Copy of the hit that's modified to look like single-point data
364  rawdata::RawDigit digSingle = *rawdigit;
365  if(fParams.MakeSinglePointCellHits() && rawdigit->Version() != 0){
366  digSingle.SetVersion(0);
367  digSingle.fADC.clear();
368  digSingle.SetADC(0, rawdigit->ADC());
369 
370  // Rest of function uses modified hit in place of argument provided
371  rawdigit = &digSingle;
372  }
373 
374  rb::CellHit chit(*rawdigit);
375 
376  // new info
377  chit.SetCell (fCMap->GetCell(rawdigit));
378  chit.SetPlane (fCMap->GetPlane(rawdigit));
379  chit.SetView (fGeom->Plane(chit.Plane())->View());
380  bool goodTime;
381  double peakadc;
382  const double tns = GetTNS(rawdigit, goodTime, &peakadc);
383 
385  chit.Plane(),
386  chit.Cell());
387  const daqchannelmap::dchan dchan = fCMap->Map()->encodeDChan(lchan);
388 
389  //check if timing offsets should be added in,
390  if (fParams.UseTimingOffsets()){
392  const double offset = fTimingCache->GetOffset(fCMap->Map()->getDCM(dchan),
393  fCMap->Map()->getDiBlock(dchan),
394  fCurrTimeStamp.GetSec(),
395  chit.IsRealData());
396  chit.SetTNS(tns+offset, goodTime);
397  }
398  else{
399  chit.SetTNS(tns, goodTime);
400  }
401 
402  chit.SetPE(GetPE(rawdigit, peakadc));
403 
404  return chit;
405  }
406 
407  //----------------------------------------------------------------------------
408  float Calibrator::GetPE(rb::CellHit const& ch, const double peakadc)
409  {
410  return this->GetPE(&ch, peakadc);
411  }
412 
413  //----------------------------------------------------------------------------
415  {
416  return this->GetPE(&ch);
417  }
418 
419  //----------------------------------------------------------------------------
421  {
422  const int maxadc = (1<<12)-1; // 4095
423 
424  // FEB 4.1
425  if(getFebType(fGeom->DetId(),dig)==calib::kFEB4p1)
426  return fGain*maxadc/217000.;
427 
428  // FEB 5.2
429  return fGain*maxadc/204800.;
430  }
431 
432  //----------------------------------------------------------------------------
433  float Calibrator::GetPE(const rawdata::RawDigit* dig, const double peakadc)
434  {
435  return peakadc/GetAdcPerPE(dig);
436  }
437 
438  //----------------------------------------------------------------------------
440  {
441  // PE comes from the value determined as a side-effect of the timing fit,
442  // the best-fit height of the curve when t0 is at its best value.
443 
444  // Doesn't matter whether or not timing fit suceeds, good fallbacks are in
445  // place.
446  bool junk;
447  double peakadc;
448  GetTNS(dig, junk, &peakadc);
449 
450  return peakadc/GetAdcPerPE(dig);
451  }
452 
453  //----------------------------------------------------------------------------
455  bool & goodTime,
456  double* maxadc)
457  {
458  // Allows the rest of the function to assume maxadc is writeable
459  double junk;
460  if(!maxadc) maxadc = &junk;
461 
462  const int det = fGeom->DetId();
463 
464  if(dig->IsMC() &&
465  dig->Version() == 0 &&
466  dig->NADC() == 3){
467  std::cout << "Calibrator: Unable to handle old-style RawDigit" << std::endl;
468  abort();
469  }
470 
472 
473  const unsigned int nSamples = conv.getNSamples(dig->Version());
474  assert(dig->NADC() == nSamples);
475 
476 
477  const double peakToBaselineOffset = getFebType(fGeom->DetId(),dig)==calib::kFEB4p1 ? 96 : 24;
478 
479 
480  const double tns0 = (dig->TDC()-peakToBaselineOffset)*15.625;
481 
482  // Version zero means this is a single DCS point
483  if(dig->Version() == 0){
484  goodTime = false;
485  *maxadc = dig->ADC(); // Make sure this gets set reasonably
486  // Simply convert the time stored in TDC to nanoseconds
487  return tns0;
488  }
489 
490  // Otherwise we can do the timing fit
491  const unsigned int nPretrig = conv.getNPretriggeredSamples(dig->Version());
492 
493  // Need to have enough points to be able to see back to the baseline
494  assert(nPretrig >= 3);
495  // Also need enough points to see up to the peak
496  assert(nSamples >= 4);
497 
498 
499  // Create TB lookup tables (need 2 - one for each FEB version)
500  if (det == novadaq::cnv::kTESTBEAM){
501  if (!fShapeTable || !fShapeTable5TB){
502  std::string fname4;
503  std::string fname5;
504  if(dig->IsMC()){
505  fname4 = fShapeTableFilenameFDMC;
506  fname5 = fShapeTableFilenameNDMC;
507  }
508  else{
509  fname4 = fShapeTableFilenameFDData;
510  fname5 = fShapeTableFilenameNDData;
511  }
512  fShapeTable = new ADCShapeFitTable(fname4, false, dig->IsMC(), fCalibrateMode);
513  fShapeTable5TB = new ADCShapeFitTable(fname5, true, dig->IsMC(), fCalibrateMode);
514  }
515  }
516 
517  //RJN we will need to change this switch from detector type to FEB type
518  //may need to make bespoke tables for testbeam
519  // Create lookup table if required
520  if(!fShapeTable){
521  const bool isFEB5p2 = getFebType(fGeom->DetId(),dig)==calib::kFEB5p2;
523  if(isFEB5p2){
524  if(dig->IsMC()){
525  fname = fShapeTableFilenameNDMC;
526  }
527  else{
529  }
530  }
531  else{
532  if(dig->IsMC()){
533  fname = fShapeTableFilenameFDMC;
534  }
535  else{
537  }
538  }
539  fShapeTable = new ADCShapeFitTable(fname, isFEB5p2, dig->IsMC(), fCalibrateMode);
540  }
541 
542  // Figure out which sample is the baseline sample (ie the one combined
543  // with the peak in the DCS calculation).
544  const int baseIdx = nPretrig - 3;
545  double tns = -1;
546  // ShapeTable expects points in order, baseline subtracted
547  if ( det == novadaq::cnv::kTESTBEAM && getFebType(fGeom->DetId(),dig)==calib::kFEB5p2 ){
548  tns = fShapeTable5TB->TNS(tns0,
549  dig->ADC(baseIdx + 1) - dig->ADC(baseIdx),
550  dig->ADC(baseIdx + 2) - dig->ADC(baseIdx),
551  dig->ADC(baseIdx + 3) - dig->ADC(baseIdx),
552  *maxadc,
553  goodTime,
554  junk);
555  }
556  else {
557  tns = fShapeTable->TNS(tns0,
558  dig->ADC(baseIdx + 1) - dig->ADC(baseIdx),
559  dig->ADC(baseIdx + 2) - dig->ADC(baseIdx),
560  dig->ADC(baseIdx + 3) - dig->ADC(baseIdx),
561  *maxadc,
562  goodTime,
563  junk);
564  }
565  return tns;
566  }
567 
568 
569  //------------------------------------------------------------
570  // CellHit-to-RecoHit methods
571  //------------------------------------------------------------
572 
573  // For these two, calculate the misssing piece of information, then forward
574  // to the protected version.
576  double w)
577  {
578  Double_t xyzd[4];
579  GetXYZD(cellhit.OfflineChan(), w, xyzd);
580  return MakeRecoHit(cellhit, w, xyzd);
581  }
582 
583  //---------------------------------------------------------------------------
585  double* xyz)
586  {
587  double w = xyz[0];
588  if(cellhit.View() == geo::kX) w = xyz[1];
589 
590  return MakeRecoHit(cellhit, w, xyz);
591  }
592 
593 
594  //---------------------------------------------------------------------------
596  double & w,
597  double* xyz)
598  {
599  rb::RecoHit rhit;
600 
601  rhit.SetX(xyz[0]);
602  rhit.SetY(xyz[1]);
603  rhit.SetZ(xyz[2]);
604 
605  rhit.SetT(GetT(chit, xyz[3]));
606 
607  // Set hit up uncalibrated in case we don't fill it below
608  rhit.SetPECorr(-1);
609  rhit.SetMIP (-1);
610  rhit.SetGeV (-1);
611 
612  if(std::isnan(w)){
613  LOG_ERROR("Calibrator")
614  << "W position provided is NaN. This hit will be uncalibrated.";
615  }
616 
617  const double peCorr = std::isnan(w) ? -1 : GetPECorr(chit, w);
618 
619  assert(!std::isnan(peCorr));
620  assert(!std::isinf(peCorr));
621 
622  if(peCorr > 0){
623  rhit.SetPECorr(peCorr);
624  const double gevPerPECorr = GetPECorrToGeVScale(chit);
625  if(gevPerPECorr > 0){
626  const double gev = peCorr * gevPerPECorr;
627  rhit.SetGeV(gev);
628  rhit.SetMIP(gev * GetGeVToMIPScale(chit));
630  }
631  else{
632  // Uncalibrated
633  rhit.SetPECorr(-1);
635  }
636  }
637  else{
639  }
640 
641  return rhit;
642  }
643 
644  //----------------------------------------------------------------------------
645  double Calibrator::GetT(rb::CellHit const& cellhit,
646  double const& dist_to_readout) {
647  // This needs to be calibrated and put in a DB table
648  Double_t speedOfFiberTransport = 15.3; // cm/ns, "first principles" calib.
649  // Differs from c/n due to zigzag
650  // paths down fiber. But, this
651  // value may be way off (10%? 30%?).
652  return (cellhit.TNS() - (dist_to_readout / speedOfFiberTransport) );
653  }
654 
655  //----------------------------------------------------------------------------
657  unsigned short const& plane,
658  double const& w)
659  {
660  double scale = 1.0;
661 
662  // scaling in the X view
663  if(view == geo::kX && fParams.UseXFunction()){
664 
665  //RJN this will do the wrong thing for the TestBeam.... but who cares
666  // if there is a seperate muon catcher function, use it
667  if( fXMuCFunction &&
669  plane >= int(fGeom->FirstPlaneInMuonCatcher()) ){
670  scale *= fXMuCFunction->Eval(w);
671  }
672  else {
673  scale *= fXFunction->Eval(w);
674  }
675  }
676 
677  // scaling in the Y view
678  if(view == geo::kY && fParams.UseYFunction()) scale *= fYFunction->Eval(w);
679 
680  // if simulating detector drift
681  if (fParams.SimulateDrift()) {
683  int time = rh->TStart() + (0.5*rh->Duration()); // set to midpoint of run;
684  double yDiff = 3.17098e-8 * (time - fParams.DriftReference()); // Amount of drift in years
685  //std::cout << "Drifting " << yDiff << " years with respect to nominal." << std::endl;
686  double drift = 1 - (fParams.DriftGradient()*yDiff);
687  double calCorrection = 1/drift;
688  //std::cout << "Calculated drift of " << drift
689  // << " from nominal, with inverse shift " << calCorrection
690  // << " applied to calibration. Scale corrected from " << scale << " to ";
691  scale *= calCorrection;
692  //std::cout << scale << std::endl;
693  }
694 
695  return scale;
696  }
697 
698  //----------------------------------------------------------------------------
699  double Calibrator::GetPECorr( rb::CellHit const& cellhit,
700  double w)
701  {
702  const double attenFactor = GetAttenScale(cellhit, w);
703  if(attenFactor <= 0) return -1;
704 
705  const double driftFactor = GetDriftScale(cellhit);
706  if(driftFactor <= 0) return -1;
707 
708  // get any scale applied for systematic uncertainties as set by the
709  // input parameters
710  auto scale = this->SystematicUncertaintyScale(cellhit.View(), cellhit.Plane(), w);
711 
712  return cellhit.PE() * attenFactor * driftFactor * scale;
713  }
714 
715  //---------------------------------------------------------------------------
716  double Calibrator::GetTimeRes(rb::CellHit const& cellhit)
717  {
718  double pe = cellhit.PE();
719  //This is a fit for the timing resolution as a function of PE.
720  //For FD single point data this is derived by plotting the time difference between
721  //pairs of hits within a DCM on a cosmic track. More information is in docdb-11571
722 
723  double stdev = 144.0; //simple assumption of 500ns/sqrt(12)
724  //RJN more FEB4 vs FEB5
725 
726  if(getFebType(fGeom->DetId(),&cellhit)==calib::kFEB4p1) {
727  //Far detector style electronics
728  if (cellhit.GoodTiming()){
729  stdev = 231594.0/(2267.16+pow(pe,2.01011)) + 9.55689; //2014-10-13 fit, multipoint readout from data, docdb-12122, with 460 ns rise time
730  }
731  else {
732  stdev = 848357.0/(5734.75+pow(pe,2.20060)) + 142.221; //2014-06-13 fit, from data
733  }
734  }
735  else {
736  //Near detector style electronics
737  if (cellhit.GoodTiming()){
738  stdev = 2229.53/(77.0043+pow(pe,1.22743)) + 4.89355; //2014-09-15 fit from data with 140 ns rise time, 4.5 us fall time
739  }
740  //TODO: ND single point timing resolution needs to be updated. Currently simulation and data are all in
741  //multipoint. For now take the FD singlpe point resolution and dived by 4 since the sampling is 4 times as fast
742  else {
743  stdev = 6136470.0/(185518.0+pow(pe,2.92360)) + 31.6071; //2014-09-15 singe point fit of data
744  }
745  }
746 
747  return stdev;
748 
749  }
750  //----------------------------------------------------------------------------
752  {
753  switch(det) {
754  case novadaq::cnv::kFARDET: return kFEB4p1;
755  case novadaq::cnv::kNEARDET: return kFEB5p2;
757  {
758  const uint32_t dcm = fCMap->Map()->getDCM(dig->DaqChannel());
759  //RJN magic number panic this magic number came from
760  //MergeTBDaqCollections_module.cc
761  if(dcm==3)
762  return kFEB5p2;
763  return kFEB4p1;
764 
765  }
766  default:
767  assert (!"The default case of getFebType switch was reached.");
768  return kFEB4p1;
769  }
770  }
771  //----------------------------------------------------------------------------
772  double Calibrator::GetAttenScale(rb::CellHit const& cellhit,
773  double w)
774  {
775 
776  const calib::AttenCurve* curve = 0;
777  double maxW = 0.0;
778  double minW = 0.0;
779 
780  if(!GetAttenCurve(cellhit.Plane(),
781  cellhit.Cell(),
782  cellhit.IsRealData(),
783  curve,
784  minW,
785  maxW)) return -1;
786 
787  if(curve->chan.Plane() >= 1000) ++fStatsNumAveraged;
788 
789  double scale = 1.0;
790 
791  //set random scaling factor for systematic studies at either the resolution of the cell or per cm in the cell around
792  //a gaussian with a sigma set at the fParams.CellByCellCalibRandomOffset()
795  int wInt = (int) w;
796  if(wInt == 0){
797  wInt = 9999;
798  }
799  TRandom3 *noiseGenerator = new TRandom3(fParams.CellByCellCalibRandomOffsetSeed()*(cellhit.Plane()+1)*(cellhit.Cell()+1)*wInt);
800  scale = noiseGenerator->Gaus(1, fParams.CellByCellCalibRandomOffset());
801  delete noiseGenerator;
802  }
803  else{
804  TRandom3 *noiseGenerator = new TRandom3(fParams.CellByCellCalibRandomOffsetSeed()*(cellhit.Plane()+1)*(cellhit.Cell()+1));
805  scale=noiseGenerator->Gaus(1, fParams.CellByCellCalibRandomOffset());
806  delete noiseGenerator;
807  }
808  }
809 
810  return scale * GetAttenScale(curve, minW, maxW, w);
811  }
812 
813  //----------------------------------------------------------------------------
815  double const& minW,
816  double const& maxW,
817  double & w)
818  {
819 
820  if(w < minW) w = minW;
821  if(w > maxW) w = maxW;
822 
823  const double mean = curve->MeanPEPerCmAt(w, fTag);
824 
825  if(mean <= 0) return -1;
826 
827  // The goal of this factor is to make PECorrs approximately the same size
828  // as PEs. But the exact values are terrible historical accident. If we
829  // decide to clean this up in future calibration versions we can do so and
830  // then condition this on the tag version.
831 
832  //RJN These numbers don't actually matter they are the value the relative
833  //calibration is normalised to... the absolute takes this factor out.
834  double pecorrscale = 0;
835  switch(fGeom->DetId()){
836  case novadaq::cnv::kNDOS: pecorrscale = 75.00; break;
837  case novadaq::cnv::kNEARDET: pecorrscale = 37.51; break;
838  case novadaq::cnv::kFARDET: pecorrscale = 39.91; break;
839  case novadaq::cnv::kTESTBEAM: pecorrscale = 39.91; break;
840  default:
841  assert(0 && "Unknown detector");
842  }
843 
844  const double factor = pecorrscale/mean;
845 
846  return factor;
847  }
848 
849  //----------------------------------------------------------------------------
851  int const& cell,
852  bool const& is_realdata,
853  const calib::AttenCurve*& curve,
854  double & minW,
855  double & maxW) const
856  {
857  const geo::OfflineChan offline_channel(plane, cell);
858 
859  unsigned int fbBin = fFibBrightness->getBrightnessIndex(plane,cell);
860  if( fbBin >= fAttenCacheMC.size() ){
861  std::cerr << "Brightness bin " << fbBin << " too high.";
862  std::abort();
863  }
864 
865  //make sure not to mask uncalibrated mc in perfect mc
866  bool maskUncalibratedChannels = fParams.MaskUncalibratedChannelsInMC();
867  if(fCurrentRun < 1e4 || fCurrentRun >= 1e6){
868  maskUncalibratedChannels = false;
869  }
870 
871  if(fTag == "v1" || fTag == "v2" ||
872  fTag == "v3" || fTag == "v3.1" ||
873  fTag == "v4" || fTag == "v5" ||
874  fTag == "v5.1" || fTag == "v6" ){
875  std::cout << "Calibrator: tag is too old: " << fTag << std::endl;
876  abort();
877  }
878 
879  bool isNDMCX = ( fGeom->DetId() == novadaq::cnv::kNEARDET &&
880  plane >= int(fGeom->FirstPlaneInMuonCatcher()) &&
881  (fGeom->Plane(plane)->View() == geo::kX) );
882 
883  //make sure not to mask the ND muon catcher x planes after v6 where we have forced the fit to converge
884  if(isNDMCX){
885  maskUncalibratedChannels = false;
886  }
887 
888  if(is_realdata)
889  curve = fAttenCacheData ->ForData(fGeom.get(), offline_channel);
890  else
891  curve = fAttenCacheMC[fbBin]->ForMC(fGeom.get(), offline_channel, maskUncalibratedChannels);
892  if(!curve) return false;
893 
894  // allow poor calibration quality in the ND muon catcher x planes after v6
895  // where we have used LOWESS to force fits to work in spite of the attenuation fit
896  if(!curve->IsCalibrated() && !isNDMCX) return false;
897 
898  // Clamp given w-coordinate into the detector to avoid bad behaviour of the
899  // attenuation function.
900  maxW = fGeom->Plane(plane)->Cell(cell)->HalfL();
901  minW = -fGeom->Plane(plane)->Cell(cell)->HalfL();
902 
903  //check to see if we're in the nd muon catcher and therefore have an asymmetric cell
905  plane >= int(fGeom->FirstPlaneInMuonCatcher())){
906  int i = 0;
907  const geo::PlaneGeo* regularPlane = fGeom->Plane(i);
908  while(regularPlane->View() != fGeom->Plane(plane)->View())
909  regularPlane = fGeom->Plane(++i);
910  const geo::CellGeo* regularCell = regularPlane->Cell(cell);
911  // Assume that the cells are aligned on the floor
912  minW = -regularCell->HalfL();
913  maxW = (2 * maxW) - regularCell->HalfL();
914  }
915 
916  return true;
917  }
918 
919  //----------------------------------------------------------------------------
920  double Calibrator::GetDriftScale(rb::CellHit const& cellhit)
921  {
922  if (!fParams.UseDrift()) return 1;
923 
924  // MC doesn't drift
925  if(!cellhit.IsRealData()) return 1;
926 
927  return fDriftCache->GetFactor(cellhit.Plane(),
928  cellhit.Cell());
929 
930  }
931 
932  //----------------------------------------------------------------------------
933  double Calibrator::GetGeVToMIPScale(rb::CellHit const& /* cellhit */ )
934  {
935  // MIPs for one GeV times one cell in z in NOvA scintillator
936  return 94.62;
937  }
938 
939  //----------------------------------------------------------------------------
941  {
943  chit.Plane(),
944  chit.Cell());
945  const daqchannelmap::dchan dchan = fCMap->Map()->encodeDChan(lchan);
946 
948  fCMap->Map()->getDiBlock(dchan),
949  chit.IsRealData());
950  }
951 
952  //----------------------------------------------------------------------------
954  {
955  // From Kanika's study: docdb 11528
956  //
957  // Could vary by detector or calibration version etc. We have all that
958  // information available here. If it gets complicated enough may need to
959  // come from database. For now it's a single number, and there's a
960  // reasonable chance it might never need to change.
961  return 1.78;
962  }
963 
964  //----------------------------------------------------------------------------
965  double Calibrator::GetShowerEnergy(TVector3 const& start,
966  TVector3 const& stop,
967  double const& totalGeV)
968  {//now only for electron
969  double ecor = 5.66050e-01;//for dead material correction
970 
971  double avgx = (start.X()+stop.X())/2.;
972  double avgy = (start.Y()+stop.Y())/2.;
973  double poscor = 1.0+7.00279e-05*avgx+6.91714e-05*avgy;//for position correction
974 
975  return totalGeV/(ecor*poscor);
976  }
977 
978  //------------------------------------------------------------------------------
979  double Calibrator::GetTimingOffset(unsigned int const& plane,
980  unsigned int const& cell,
981  bool const& isData)
982  {
984  plane,
985  cell);
986  const daqchannelmap::dchan dchan = fCMap->Map()->encodeDChan(lchan);
987 
988  double offset = 0.0;
989  //check if timing offsets should be added in,
990  if (fParams.UseTimingOffsets()){
992  offset = fTimingCache->GetOffset(fCMap->Map()->getDCM(dchan),
993  fCMap->Map()->getDiBlock(dchan),
994  fCurrTimeStamp.GetSec(),
995  isData);
996  }
997 
998  return offset;
999  }
1000 
1001  //------------------------------------------------------------------------------
1003  {
1004  if(fTimingCacheVldTimeSet) return;
1005 
1006  // use run history to improve database performance. Apparently asking the
1007  // run object start and end time was not producing the same result for each
1008  // subrun and so the cacheing performance of the timing calibration table
1009  // was poor, clogging the system.
1012  rh->TStart(),
1013  rh->TStop());
1014 
1015  fTimingCacheVldTimeSet = true;
1016  }
1017 
1018 
1020 }
1021  // end namespace calib
1022 ///////////////////////////////////////////////////////////////////////
float TNS() const
Definition: CellHit.h:46
Atom< bool > UseTimingEpochs
Definition: Calibrator.h:117
void SetGainSetting(int g)
Definition: AbsCache.h:32
double HalfL() const
Definition: CellGeo.cxx:198
void preEvent(art::Event const &evt)
int isinf(const stan::math::var &a)
Definition: std_isinf.hpp:16
double GetTimeRes(rb::CellHit const &cellhit)
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: AttenCache.h:55
def stdev(lst)
Definition: HandyFuncs.py:286
double GetPECorrToGeVScale(rb::CellHit const &cellhit)
void SetTNS(float tns, bool good)
Definition: CellHit.h:56
void SetGeV(float GeV)
Definition: RecoHit.h:44
void SetUseEpochs(bool b)
Definition: AbsCache.h:43
void UseCSVsFromUPS(bool use=true)
Definition: DriftCache.h:47
TH2 * rh
Definition: drawXsec.C:5
Atom< std::string > DriftEpochTag
Definition: Calibrator.h:149
int32_t TDC() const
The time of the last baseline sample.
Definition: RawDigit.h:94
void SetCSVSource(const std::string &src)
Definition: AbsCache.h:26
void SetVldTime(novadaq::cnv::DetId det, std::uint32_t minTime, std::uint32_t maxTime)
void SetEpoch(const std::string &epoch)
Definition: AbsCache.h:47
void UseCSVsFromUPS(bool use=true)
Definition: AbsCache.h:28
Sequence< double > Xg140FunctionParams
Definition: Calibrator.h:205
double SystematicUncertaintyScale(geo::View_t const &view, unsigned short const &plane, double const &w)
T * get() const
Definition: ServiceHandle.h:70
void SetRun(int detector, int run)
Definition: DriftCache.cxx:62
void SetEpochTag(const std::string &tag)
Definition: DriftCache.h:42
Atom< bool > CellByCellCalibRandomOffsetHighResolution
Definition: Calibrator.h:217
void SetCSVSource(const std::string &path)
Definition: DriftCache.h:48
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
void SetMIP(float MIP)
Definition: RecoHit.h:43
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
unsigned short Plane() const
Definition: CellHit.h:39
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
Atom< std::string > Tag
Definition: Calibrator.h:81
bool IsCalibrated() const
Definition: AttenCurve.cxx:97
geo::View_t View() const
Definition: CellHit.h:41
TimingCache * fTimingCache
Definition: Calibrator.h:412
const CellGeo * Cell(int icell) const
Definition: PlaneGeo.h:48
Atom< std::string > Yg100FunctionForm
Definition: Calibrator.h:181
unsigned int fStatsNumUncalibrated
Number of uncalibrated hits returned.
Definition: Calibrator.h:451
Atom< bool > UseGainSetting4Atten
Definition: Calibrator.h:157
Atom< double > Gain
Definition: Calibrator.h:161
constexpr T pow(T x)
Definition: pow.h:75
Vertical planes which measure X.
Definition: PlaneGeo.h:28
void SetGainSetting(int g)
Definition: AttenCache.h:61
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
rb::RecoHit MakeRecoHit(rb::CellHit const &cellhit, double w)
double GetGeVToCalorimetricScale() const
For use by RecoBase classes.
void SetX(float X)
Definition: RecoHit.h:45
void UseCSVsFromUPS(bool use=true)
Definition: AttenCache.h:38
OStream cerr
Definition: OStream.cxx:7
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
Atom< std::string > XMuCg100FunctionForm
Definition: Calibrator.h:177
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
GlobalSignal< detail::SignalResponseType::LIFO, void(Run const &)> sPostBeginRun
void SetT(float T)
Definition: RecoHit.h:48
Atom< std::string > TimingTag
Definition: Calibrator.h:125
Atom< bool > SimulateDrift
Definition: Calibrator.h:241
GlobalSignal< detail::SignalResponseType::LIFO, void(SubRun const &)> sPostBeginSubRun
float GetTNS(const rawdata::RawDigit *rawdigit, bool &goodTime, double *maxadc=0)
int GainSetting()
Definition: AbsCache.h:33
const PlaneGeo * Plane(unsigned int i) const
Atom< std::string > AbsEpochTag
Definition: Calibrator.h:109
geo::OfflineChan OfflineChan() const
Definition: CellHit.h:49
RunNumber_t run() const
Definition: Run.h:47
std::string find_file(std::string const &filename) const
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: TimingCache.h:37
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
Atom< std::string > AttenEpochTag
Definition: Calibrator.h:89
DriftCache * fDriftCache
Definition: Calibrator.h:410
double GetGeVToMIPScale(rb::CellHit const &cellhit)
For GeV->MIP conversion.
unsigned int NumberBrightnessBins() const
void SetEpochTag(const std::string &tag)
Definition: AbsCache.h:48
rb::CellHit MakeCellHit(const rawdata::RawDigit *rawdigit)
Atom< std::string > CalibrationMode
Definition: Calibrator.h:75
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
constexpr TimeValue_t value() const
Definition: Timestamp.h:24
Horizontal planes which measure Y.
Definition: PlaneGeo.h:29
void SetTag(const std::string &tag)
Definition: DriftCache.h:33
Definition: Run.h:31
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
art::ServiceHandle< cmap::CMap > fCMap
Definition: Calibrator.h:443
void SetView(geo::View_t view)
Definition: CellHit.h:54
Calibrated quantities relying on position in the orthogonal view. To generate a rb::CellHit from a rb...
Definition: RecoHit.h:19
void SetPlane(unsigned short plane)
Definition: CellHit.h:53
Atom< bool > MaskUncalibratedChannelsInMC
Definition: Calibrator.h:229
void SetVersion(uint8_t v)
Definition: RawDigit.h:101
void SetEpoch(const std::string &epoch)
Definition: TimingCache.h:28
void postBeginSubRun(art::SubRun const &subrun)
double GetDriftScale(rb::CellHit const &cellhit)
Part of the PE->PECorr conversion.
Atom< std::string > TimingConstsCSVPath
Definition: Calibrator.h:129
unsigned int getBrightnessIndex(unsigned int plane, unsigned int cell) const
void SetRun(int run)
Definition: AbsCache.h:57
unsigned short Cell() const
Definition: CellHit.h:40
void SetCell(unsigned short cell)
Definition: CellHit.h:52
Atom< std::string > AttenCSVPath
Definition: Calibrator.h:97
void SetADC(uint32_t i, int16_t iADC)
Definition: RawDigit.cxx:108
Double_t scale
Definition: plot.C:25
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:53
Far Detector at Ash River, MN.
CDPStorage service.
double GetAdcPerPE(const rawdata::RawDigit *dig)
Helper function for GetPE()
void SetUseEpochs(bool use=true)
Definition: TimingCache.h:26
Atom< bool > UseDrift
Definition: Calibrator.h:133
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
void SetPE(float pe)
Definition: CellHit.h:55
Atom< bool > MakeSinglePointCellHits
Definition: Calibrator.h:233
uint32_t DaqChannel() const
Definition: RawDigit.h:85
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
void SetUseEpochs(bool b)
Definition: DriftCache.h:36
Sequence< double > XMuCg100FunctionParams
Definition: Calibrator.h:197
double GetAttenScale(rb::CellHit const &cellhit, double w)
for PE->PECorr conversion
Prototype Near Detector on the surface at FNAL.
EFEBType
Enumeration for the FEB 4.2 and 5.1 which have different clocks.
Definition: CalibUtil.h:25
void SetEpochTag(const std::string &tag)
Definition: AttenCache.h:49
std::string fShapeTableFilenameFDMC
Root file ADCShapeFitTable will load from.
Definition: Calibrator.h:399
T get(std::string const &key) const
Definition: ParameterSet.h:231
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
void SetTag(const std::string &tag)
Definition: AbsCache.h:30
double TNS(double tns0, int16_t adc1, int16_t adc2, int16_t adc3, double &adcpeak, bool &goodTime, double &base) const
Geometry information for a single readout plane.
Definition: PlaneGeo.h:36
int evt
void SetCSVSource(const std::string &src)
Definition: TimingCache.h:22
Atom< bool > UseXFunction
Definition: Calibrator.h:165
bool UseEpochs()
Definition: AbsCache.h:45
float PE() const
Definition: CellHit.h:42
ADCShapeFitTable * fShapeTable
Definition: Calibrator.h:405
fhicl::ParameterSet const & get_PSet() const
Definition: ServiceTable.h:32
Near Detector in the NuMI cavern.
bool IsMC() const
Definition: RawDigit.h:108
Atom< bool > UseCellByCellCalibRandomOffset
Definition: Calibrator.h:213
Atom< bool > UseAttenEpochs
Definition: Calibrator.h:85
void GetXYZD(geo::OfflineChan chan, double w, double *xyzd)
Return position in world coordninates and distance to the readout.
Definition: CalibUtil.cxx:294
int Duration()
in units of seconds
Definition: RunHistory.h:389
void SetEpochTag(const std::string &tag)
Definition: TimingCache.h:29
unsigned short GetPlane(const rawdata::RawDigit *dig)
Definition: CMap.cxx:285
void SetRun(int run)
Definition: AttenCache.h:58
void Reinit()
Definition: AbsCache.h:35
double GetShowerEnergy(TVector3 const &start, TVector3 const &stop, double const &totalGeV)
Estimate of true shower energy, adapted from RecoJMShower.
ADCShapeFitTable * fShapeTable5TB
FEBv5 table for TestBeam (fShapeTable will be FEBv4)
Definition: Calibrator.h:406
double GetT(rb::CellHit const &cellhit, double const &dist_to_readout)
Atom< int > DriftReference
Definition: Calibrator.h:245
Look up absolute attenuation constants.
Definition: AbsCache.h:16
uint8_t Version() const
Definition: RawDigit.h:87
Definition: View.py:1
void SetCSVFile(std::string f)
Definition: DriftCache.h:31
CalibratorParams fParams
Definition: Calibrator.h:392
Calibrator(const Parameters &params, art::ActivityRegistry &reg)
bool fTimingCacheVldTimeSet
Is fTimingCache set to the right time?
Definition: Calibrator.h:413
Definition: run.py:1
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: AbsCache.h:55
OStream cout
Definition: OStream.cxx:6
std::string fShapeTableFilenameNDMC
Definition: Calibrator.h:401
unsigned short Plane() const
Definition: OfflineChan.h:31
Atom< bool > UseGainSetting4Abs
Definition: Calibrator.h:153
Atom< bool > UseAbsEpochs
Definition: Calibrator.h:101
Atom< std::string > Xg140FunctionForm
Definition: Calibrator.h:185
geo::OfflineChan chan
Definition: AttenCurve.h:53
TTimeStamp fCurrTimeStamp
current time stamp
Definition: Calibrator.h:395
AbsCache * fAbsCache
Definition: Calibrator.h:411
Atom< double > CellByCellCalibRandomOffset
Definition: Calibrator.h:221
double TableHitFraction() const
What fraction of calls to TNS went via the table?
double GetPECorrToGeVScale(novadaq::cnv::DetId det, int diblock, bool isData)
Definition: AbsCache.cxx:34
unsigned int fStatsNumAveraged
Number of hits from uncalibrated diblocks using averaged calibrations.
Definition: Calibrator.h:453
std::vector< int16_t > fADC
list of ADC(-like) charge values
Definition: RawDigit.h:49
void SetY(float Y)
Definition: RecoHit.h:46
bool GetAttenCurve(int const &plane, int const &cell, bool const &is_realdata, const calib::AttenCurve *&, double &minW, double &maxW) const
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
std::string fTag
Definition: Calibrator.h:433
void SetEpoch(const std::string &epoch)
Definition: AttenCache.h:48
int16_t ADC(uint32_t i) const
Definition: RawDigit.cxx:58
calib::EFEBType getFebType(novadaq::cnv::DetId det, const rawdata::RawDigit *dig)
double GetTimingOffset(unsigned int const &plane, unsigned int const &cell, bool const &isData)
Get the timing offset for a given plane, cell. Useful downstream to check calibration.
uint32_t NADC() const
Definition: RawDigit.h:81
std::string fShapeTableFilenameFDData
Definition: Calibrator.h:400
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
void UseCSVsFromUPS(bool use=true)
Definition: TimingCache.h:23
Atom< std::string > Xg100FunctionForm
Definition: Calibrator.h:173
A (plane, cell) pair.
Definition: OfflineChan.h:17
Atom< std::string > TimingEpochTag
Definition: Calibrator.h:121
std::string fShapeTableFilenameNDData
Definition: Calibrator.h:402
const hit & b
Definition: hits.cxx:21
std::vector< AttenCache * > fAttenCacheMC
MC attenutation corrections indexed by fiber brightness.
Definition: Calibrator.h:409
assert(nhit_max >=nhit_nbins)
Atom< std::string > DriftCSV
Definition: Calibrator.h:141
Sequence< double > Yg100FunctionParams
Definition: Calibrator.h:201
Timestamp time() const
Definition: Event.h:61
Atom< double > DriftGradient
Definition: Calibrator.h:249
art::ServiceHandle< photrans::FiberBrightness > fFibBrightness
Definition: Calibrator.h:445
unsigned short GetCell(const rawdata::RawDigit *dig)
Definition: CMap.cxx:327
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
Atom< bool > UseTimingOffsets
Definition: Calibrator.h:237
double GetOffset(int dcm, int diblock, std::uint32_t time, bool isData)
Definition: TimingCache.cxx:40
Atom< bool > ReadEpochsFromCSV
Definition: Calibrator.h:105
double GetPECorr(rb::CellHit const &cellhit, double w)
float MeanPEPerCmAt(double w) const
Mean response of this channel at this distance from detector centre.
Definition: AttenCurve.cxx:37
float GetPE(rb::CellHit const &)
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
Atom< bool > UseYFunction
Definition: Calibrator.h:169
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
void SetPECorr(float PECorr)
Definition: RecoHit.h:42
Atom< std::string > Yg140FunctionForm
Definition: Calibrator.h:189
Sequence< double > Yg140FunctionParams
Definition: Calibrator.h:209
Atom< std::string > DriftConstsCSVPath
Definition: Calibrator.h:137
void SetCSVSource(const std::string &path)
Definition: AttenCache.h:36
bool GoodTiming() const
Definition: CellHit.h:48
uint32_t dchan
< DAQ Channel Map Package
Encapsulate the cell geometry.
Definition: CellGeo.h:25
unsigned int fStatsNumCalibrated
Number of calibrated hits returned.
Definition: Calibrator.h:449
Atom< int > CellByCellCalibRandomOffsetSeed
Definition: Calibrator.h:225
double GetFactor(int plane, int cell)
Definition: DriftCache.cxx:43
void postBeginRun(art::Run const &run)
Float_t w
Definition: plot.C:20
void SetZ(float Z)
Definition: RecoHit.h:47
void SetRun(int run)
Definition: TimingCache.h:32
void SetTag(const std::string &tag)
Definition: AttenCache.h:40
Sequence< double > Xg100FunctionParams
Definition: Calibrator.h:193
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
void SetTag(const std::string &tag)
Definition: TimingCache.h:24
int RunNumber() const
Definition: RunHistory.h:374
#define LOG_ERROR(stream)
Definition: Messenger.h:129
Atom< bool > UseDriftEpochs
Definition: Calibrator.h:145
const AttenCurve * ForData(const geo::GeometryBase *geom, geo::OfflineChan chan)
Definition: AttenCache.cxx:52
Atom< std::string > AbsConstsCSVPath
Definition: Calibrator.h:113
void SetUseEpochs(bool b)
Definition: AttenCache.h:44
const unsigned int FirstPlaneInMuonCatcher() const
Returns the index of the first plane contained in the muon catcher.
bool IsRealData() const
Definition: RawDigit.h:107
enum BeamMode string