Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
calib::Calibrator Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-10-28/Calibrator/art/Calibrator.h"

Public Types

using Parameters = art::ServiceTable< CalibratorParams >
 

Public Member Functions

 Calibrator (const Parameters &params, art::ActivityRegistry &reg)
 
 ~Calibrator ()
 
void preEvent (art::Event const &evt)
 
void postBeginRun (art::Run const &run)
 
void postBeginSubRun (art::SubRun const &subrun)
 
TTimeStamp GetTimeStamp () const
 
rb::CellHit MakeCellHit (const rawdata::RawDigit *rawdigit)
 
float GetPE (rb::CellHit const &)
 
float GetPE (const rawdata::RawDigit *rawdigit)
 
float GetTNS (const rawdata::RawDigit *rawdigit, bool &goodTime, double *maxadc=0)
 
rb::RecoHit MakeRecoHit (rb::CellHit const &cellhit, double w)
 
rb::RecoHit MakeRecoHit (rb::CellHit const &cellhit, double *xyz)
 
double GetT (rb::CellHit const &cellhit, double const &dist_to_readout)
 
double GetPECorr (rb::CellHit const &cellhit, double w)
 
double GetTimeRes (rb::CellHit const &cellhit)
 
double GetAttenScale (rb::CellHit const &cellhit, double w)
 for PE->PECorr conversion More...
 
double GetAttenScale (const calib::AttenCurve *curve, double const &minW, double const &maxW, double &w)
 
double GetDriftScale (rb::CellHit const &cellhit)
 Part of the PE->PECorr conversion. More...
 
double GetPECorrToGeVScale (rb::CellHit const &cellhit)
 
double GetGeVToMIPScale (rb::CellHit const &cellhit)
 For GeV->MIP conversion. More...
 
double GetGeVToCalorimetricScale () const
 For use by RecoBase classes. More...
 
double GetShowerEnergy (TVector3 const &start, TVector3 const &stop, double const &totalGeV)
 Estimate of true shower energy, adapted from RecoJMShower. More...
 
bool GetAttenCurve (int const &plane, int const &cell, bool const &is_realdata, const calib::AttenCurve *&, double &minW, double &maxW) const
 
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. More...
 
double SystematicUncertaintyScale (geo::View_t const &view, unsigned short const &plane, double const &w)
 
calib::EFEBType getFebType (novadaq::cnv::DetId det, const rawdata::RawDigit *dig)
 
std::string GetAttenCSVPath ()
 
std::string GetAbsConstsCSVPath ()
 
std::string GetTimingConstsCSVPath ()
 
std::string GetDriftConstsCSVPath ()
 
CalibratorParams GetCalibratorParams ()
 

Protected Attributes

CalibratorParams fParams
 

Private Member Functions

rb::RecoHit MakeRecoHit (rb::CellHit const &cellhit, double &w, double *xyz)
 Helper function for the two public MakeRecoHit methods. More...
 
void EnsureTimingCacheVldTime ()
 
double GetAdcPerPE (const rawdata::RawDigit *dig)
 Helper function for GetPE() More...
 
float GetPE (rb::CellHit const &, const double peakadc)
 Get PE when we have already calculated the peakadc through a call to GetTNS. More...
 
float GetPE (const rawdata::RawDigit *rawdigit, const double peakadc)
 

Private Attributes

TTimeStamp fCurrTimeStamp
 current time stamp More...
 
int fCalibrateMode
 
std::string fShapeTableFilenameFDMC
 Root file ADCShapeFitTable will load from. More...
 
std::string fShapeTableFilenameFDData
 
std::string fShapeTableFilenameNDMC
 
std::string fShapeTableFilenameNDData
 
ADCShapeFitTablefShapeTable
 
ADCShapeFitTablefShapeTable5TB
 FEBv5 table for TestBeam (fShapeTable will be FEBv4) More...
 
AttenCachefAttenCacheData
 Data attenutation corrections. More...
 
std::vector< AttenCache * > fAttenCacheMC
 MC attenutation corrections indexed by fiber brightness. More...
 
DriftCachefDriftCache
 
AbsCachefAbsCache
 
TimingCachefTimingCache
 
bool fTimingCacheVldTimeSet
 Is fTimingCache set to the right time? More...
 
int fCurrentRun
 
std::string fTag
 
double fGain
 
TF1 * fXFunction
 
TF1 * fXMuCFunction
 
TF1 * fYFunction
 
art::ServiceHandle< cmap::CMapfCMap
 
art::ServiceHandle< geo::GeometryfGeom
 
art::ServiceHandle< photrans::FiberBrightnessfFibBrightness
 
art::ServiceHandle< nova::dbi::RunHistoryServicefRH
 
unsigned int fStatsNumCalibrated
 Number of calibrated hits returned. More...
 
unsigned int fStatsNumUncalibrated
 Number of uncalibrated hits returned. More...
 
unsigned int fStatsNumAveraged
 Number of hits from uncalibrated diblocks using averaged calibrations. More...
 

Detailed Description

Definition at line 272 of file Calibrator.h.

Member Typedef Documentation

Definition at line 275 of file Calibrator.h.

Constructor & Destructor Documentation

calib::Calibrator::Calibrator ( const Parameters params,
art::ActivityRegistry reg 
)

Definition at line 41 of file Calibrator_service.cc.

References calib::CalibratorParams::AbsConstsCSVPath, calib::CalibratorParams::AbsEpochTag, calib::CalibratorParams::CalibrationMode, calib::CalibratorParams::DriftConstsCSVPath, calib::CalibratorParams::DriftCSV, calib::CalibratorParams::DriftEpochTag, fAbsCache, fCalibrateMode, fDriftCache, fGain, cet::search_path::find_file(), fParams, fShapeTableFilenameFDData, fShapeTableFilenameFDMC, fShapeTableFilenameNDData, fShapeTableFilenameNDMC, fTag, fTimingCache, calib::CalibratorParams::Gain, fhicl::ParameterSet::get(), art::ServiceTable< T >::get_PSet(), postBeginRun(), postBeginSubRun(), preEvent(), calib::TimingCache::ReadEpochsFromCSV(), calib::AbsCache::ReadEpochsFromCSV(), calib::CalibratorParams::ReadEpochsFromCSV, calib::DriftCache::SetCSVFile(), calib::TimingCache::SetCSVSource(), calib::AbsCache::SetCSVSource(), calib::DriftCache::SetCSVSource(), calib::TimingCache::SetEpochTag(), calib::DriftCache::SetEpochTag(), calib::AbsCache::SetEpochTag(), calib::TimingCache::SetTag(), calib::AbsCache::SetTag(), calib::DriftCache::SetTag(), calib::TimingCache::SetUseEpochs(), calib::DriftCache::SetUseEpochs(), calib::AbsCache::SetUseEpochs(), art::ActivityRegistry::sPostBeginRun, art::ActivityRegistry::sPostBeginSubRun, art::ActivityRegistry::sPreProcessEvent, calib::CalibratorParams::Tag, calib::CalibratorParams::TimingConstsCSVPath, calib::CalibratorParams::TimingEpochTag, calib::CalibratorParams::TimingTag, calib::CalibratorParams::UseAbsEpochs, calib::TimingCache::UseCSVsFromUPS(), calib::AbsCache::UseCSVsFromUPS(), calib::DriftCache::UseCSVsFromUPS(), calib::CalibratorParams::UseCSVsFromUPS, calib::CalibratorParams::UseDriftEpochs, and calib::CalibratorParams::UseTimingEpochs.

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)
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  }
Atom< bool > UseTimingEpochs
Definition: Calibrator.h:117
void preEvent(art::Event const &evt)
void SetUseEpochs(bool b)
Definition: AbsCache.h:43
void UseCSVsFromUPS(bool use=true)
Definition: DriftCache.h:47
Atom< std::string > DriftEpochTag
Definition: Calibrator.h:149
void SetCSVSource(const std::string &src)
Definition: AbsCache.h:26
void UseCSVsFromUPS(bool use=true)
Definition: AbsCache.h:28
void SetEpochTag(const std::string &tag)
Definition: DriftCache.h:42
void SetCSVSource(const std::string &path)
Definition: DriftCache.h:48
Atom< std::string > Tag
Definition: Calibrator.h:81
TimingCache * fTimingCache
Definition: Calibrator.h:412
unsigned int fStatsNumUncalibrated
Number of uncalibrated hits returned.
Definition: Calibrator.h:451
Atom< double > Gain
Definition: Calibrator.h:161
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
GlobalSignal< detail::SignalResponseType::LIFO, void(Run const &)> sPostBeginRun
Atom< std::string > TimingTag
Definition: Calibrator.h:125
GlobalSignal< detail::SignalResponseType::LIFO, void(SubRun const &)> sPostBeginSubRun
Atom< std::string > AbsEpochTag
Definition: Calibrator.h:109
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: TimingCache.h:37
DriftCache * fDriftCache
Definition: Calibrator.h:410
void SetEpochTag(const std::string &tag)
Definition: AbsCache.h:48
Atom< std::string > CalibrationMode
Definition: Calibrator.h:75
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
void SetTag(const std::string &tag)
Definition: DriftCache.h:33
void postBeginSubRun(art::SubRun const &subrun)
Atom< std::string > TimingConstsCSVPath
Definition: Calibrator.h:129
void SetUseEpochs(bool use=true)
Definition: TimingCache.h:26
void SetUseEpochs(bool b)
Definition: DriftCache.h:36
std::string fShapeTableFilenameFDMC
Root file ADCShapeFitTable will load from.
Definition: Calibrator.h:399
T get(std::string const &key) const
Definition: ParameterSet.h:231
void SetTag(const std::string &tag)
Definition: AbsCache.h:30
void SetCSVSource(const std::string &src)
Definition: TimingCache.h:22
ADCShapeFitTable * fShapeTable
Definition: Calibrator.h:405
void SetEpochTag(const std::string &tag)
Definition: TimingCache.h:29
ADCShapeFitTable * fShapeTable5TB
FEBv5 table for TestBeam (fShapeTable will be FEBv4)
Definition: Calibrator.h:406
void SetCSVFile(std::string f)
Definition: DriftCache.h:31
CalibratorParams fParams
Definition: Calibrator.h:392
bool fTimingCacheVldTimeSet
Is fTimingCache set to the right time?
Definition: Calibrator.h:413
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: AbsCache.h:55
std::string fShapeTableFilenameNDMC
Definition: Calibrator.h:401
Atom< bool > UseAbsEpochs
Definition: Calibrator.h:101
TTimeStamp fCurrTimeStamp
current time stamp
Definition: Calibrator.h:395
AbsCache * fAbsCache
Definition: Calibrator.h:411
unsigned int fStatsNumAveraged
Number of hits from uncalibrated diblocks using averaged calibrations.
Definition: Calibrator.h:453
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string fTag
Definition: Calibrator.h:433
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 > TimingEpochTag
Definition: Calibrator.h:121
std::string fShapeTableFilenameNDData
Definition: Calibrator.h:402
Atom< std::string > DriftCSV
Definition: Calibrator.h:141
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
Atom< bool > ReadEpochsFromCSV
Definition: Calibrator.h:105
Atom< std::string > DriftConstsCSVPath
Definition: Calibrator.h:137
unsigned int fStatsNumCalibrated
Number of calibrated hits returned.
Definition: Calibrator.h:449
void postBeginRun(art::Run const &run)
void SetTag(const std::string &tag)
Definition: TimingCache.h:24
Atom< bool > UseDriftEpochs
Definition: Calibrator.h:145
Atom< std::string > AbsConstsCSVPath
Definition: Calibrator.h:113
calib::Calibrator::~Calibrator ( )

Definition at line 125 of file Calibrator_service.cc.

References plot_validation_datamc::c, fAbsCache, fAttenCacheData, fAttenCacheMC, fDriftCache, fShapeTable, fShapeTable5TB, fStatsNumAveraged, fStatsNumCalibrated, fStatsNumUncalibrated, fTimingCache, makeTrainCVSamples::int, and calib::ADCShapeFitTable::TableHitFraction().

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  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
TimingCache * fTimingCache
Definition: Calibrator.h:412
unsigned int fStatsNumUncalibrated
Number of uncalibrated hits returned.
Definition: Calibrator.h:451
DriftCache * fDriftCache
Definition: Calibrator.h:410
ADCShapeFitTable * fShapeTable
Definition: Calibrator.h:405
ADCShapeFitTable * fShapeTable5TB
FEBv5 table for TestBeam (fShapeTable will be FEBv4)
Definition: Calibrator.h:406
AbsCache * fAbsCache
Definition: Calibrator.h:411
double TableHitFraction() const
What fraction of calls to TNS went via the table?
unsigned int fStatsNumAveraged
Number of hits from uncalibrated diblocks using averaged calibrations.
Definition: Calibrator.h:453
std::vector< AttenCache * > fAttenCacheMC
MC attenutation corrections indexed by fiber brightness.
Definition: Calibrator.h:409
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
unsigned int fStatsNumCalibrated
Number of calibrated hits returned.
Definition: Calibrator.h:449

Member Function Documentation

void calib::Calibrator::EnsureTimingCacheVldTime ( )
private

Definition at line 1002 of file Calibrator_service.cc.

References DEFINE_ART_SERVICE, geo::GeometryBase::DetId(), fGeom, fTimingCache, fTimingCacheVldTimeSet, rh, calib::TimingCache::SetVldTime(), nova::dbi::RunHistory::TStart(), and nova::dbi::RunHistory::TStop().

Referenced by GetTimingOffset(), and MakeCellHit().

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  }
TH2 * rh
Definition: drawXsec.C:5
void SetVldTime(novadaq::cnv::DetId det, std::uint32_t minTime, std::uint32_t maxTime)
TimingCache * fTimingCache
Definition: Calibrator.h:412
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
bool fTimingCacheVldTimeSet
Is fTimingCache set to the right time?
Definition: Calibrator.h:413
std::string calib::Calibrator::GetAbsConstsCSVPath ( )
inline

Definition at line 386 of file Calibrator.h.

References cet::getenv().

Referenced by calib::CalibAna::endJob().

386 {return (fParams.UseCSVsFromUPS()) ? getenv("CALIBCSVS_CSV_PATH") : fParams.AbsConstsCSVPath();}
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
std::string getenv(std::string const &name)
CalibratorParams fParams
Definition: Calibrator.h:392
Atom< std::string > AbsConstsCSVPath
Definition: Calibrator.h:113
double calib::Calibrator::GetAdcPerPE ( const rawdata::RawDigit dig)
private

Helper function for GetPE()

Definition at line 420 of file Calibrator_service.cc.

References geo::GeometryBase::DetId(), fGain, fGeom, getFebType(), and calib::kFEB4p1.

Referenced by GetPE().

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  }
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
calib::EFEBType getFebType(novadaq::cnv::DetId det, const rawdata::RawDigit *dig)
std::string calib::Calibrator::GetAttenCSVPath ( )
inline

Definition at line 385 of file Calibrator.h.

References cet::getenv().

Referenced by calib::CalibAna::endJob().

385 {return (fParams.UseCSVsFromUPS()) ? getenv("CALIBCSVS_CSV_PATH") : fParams.AttenCSVPath();}
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
Atom< std::string > AttenCSVPath
Definition: Calibrator.h:97
std::string getenv(std::string const &name)
CalibratorParams fParams
Definition: Calibrator.h:392
bool calib::Calibrator::GetAttenCurve ( int const &  plane,
int const &  cell,
bool const &  is_realdata,
const calib::AttenCurve *&  curve,
double &  minW,
double &  maxW 
) const

Given plane, cell and whether the data is real, get attenuation curve and Max w for the plane

Definition at line 850 of file Calibrator_service.cc.

References geo::PlaneGeo::Cell(), om::cerr, om::cout, geo::GeometryBase::DetId(), allTimeWatchdog::endl, fAttenCacheData, fAttenCacheMC, fFibBrightness, fGeom, geo::GeometryBase::FirstPlaneInMuonCatcher(), calib::AttenCache::ForData(), fParams, fTag, art::ServiceHandle< T, SCOPE >::get(), photrans::FiberBrightness::getBrightnessIndex(), geo::CellGeo::HalfL(), MECModelEnuComparisons::i, makeTrainCVSamples::int, calib::AttenCurve::IsCalibrated(), novadaq::cnv::kNEARDET, geo::kX, calib::CalibratorParams::MaskUncalibratedChannelsInMC, geo::GeometryBase::Plane(), and geo::PlaneGeo::View().

Referenced by calib::FindOutliers::endRun(), and GetAttenScale().

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 &&
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  }
double HalfL() const
Definition: CellGeo.cxx:198
T * get() const
Definition: ServiceHandle.h:70
bool IsCalibrated() const
Definition: AttenCurve.cxx:97
const CellGeo * Cell(int icell) const
Definition: PlaneGeo.h:48
Vertical planes which measure X.
Definition: PlaneGeo.h:28
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
OStream cerr
Definition: OStream.cxx:7
const PlaneGeo * Plane(unsigned int i) const
Atom< bool > MaskUncalibratedChannelsInMC
Definition: Calibrator.h:229
unsigned int getBrightnessIndex(unsigned int plane, unsigned int cell) const
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:53
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Geometry information for a single readout plane.
Definition: PlaneGeo.h:36
Near Detector in the NuMI cavern.
CalibratorParams fParams
Definition: Calibrator.h:392
OStream cout
Definition: OStream.cxx:6
std::string fTag
Definition: Calibrator.h:433
A (plane, cell) pair.
Definition: OfflineChan.h:17
std::vector< AttenCache * > fAttenCacheMC
MC attenutation corrections indexed by fiber brightness.
Definition: Calibrator.h:409
art::ServiceHandle< photrans::FiberBrightness > fFibBrightness
Definition: Calibrator.h:445
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
Encapsulate the cell geometry.
Definition: CellGeo.h:25
const AttenCurve * ForData(const geo::GeometryBase *geom, geo::OfflineChan chan)
Definition: AttenCache.cxx:52
const unsigned int FirstPlaneInMuonCatcher() const
Returns the index of the first plane contained in the muon catcher.
double calib::Calibrator::GetAttenScale ( rb::CellHit const &  cellhit,
double  w 
)

for PE->PECorr conversion

Definition at line 772 of file Calibrator_service.cc.

References rb::CellHit::Cell(), calib::CalibratorParams::CellByCellCalibRandomOffset, calib::CalibratorParams::CellByCellCalibRandomOffsetHighResolution, calib::CalibratorParams::CellByCellCalibRandomOffsetSeed, calib::AttenCurve::chan, fParams, fStatsNumAveraged, GetAttenCurve(), makeTrainCVSamples::int, rawdata::RawDigit::IsRealData(), geo::OfflineChan::Plane(), rb::CellHit::Plane(), scale, and calib::CalibratorParams::UseCellByCellCalibRandomOffset.

Referenced by calib::DriftResponseCalc::FillPeCorrHits(), GetPECorr(), and calib::AttenuationFit::writeResults().

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  }
Atom< bool > CellByCellCalibRandomOffsetHighResolution
Definition: Calibrator.h:217
Double_t scale
Definition: plot.C:25
double GetAttenScale(rb::CellHit const &cellhit, double w)
for PE->PECorr conversion
Atom< bool > UseCellByCellCalibRandomOffset
Definition: Calibrator.h:213
CalibratorParams fParams
Definition: Calibrator.h:392
unsigned short Plane() const
Definition: OfflineChan.h:31
geo::OfflineChan chan
Definition: AttenCurve.h:53
Atom< double > CellByCellCalibRandomOffset
Definition: Calibrator.h:221
unsigned int fStatsNumAveraged
Number of hits from uncalibrated diblocks using averaged calibrations.
Definition: Calibrator.h:453
bool GetAttenCurve(int const &plane, int const &cell, bool const &is_realdata, const calib::AttenCurve *&, double &minW, double &maxW) const
Atom< int > CellByCellCalibRandomOffsetSeed
Definition: Calibrator.h:225
Float_t w
Definition: plot.C:20
double calib::Calibrator::GetAttenScale ( const calib::AttenCurve curve,
double const &  minW,
double const &  maxW,
double &  w 
)

Definition at line 814 of file Calibrator_service.cc.

References ana::assert(), geo::GeometryBase::DetId(), fGeom, fTag, novadaq::cnv::kFARDET, novadaq::cnv::kNDOS, novadaq::cnv::kNEARDET, novadaq::cnv::kTESTBEAM, extractScale::mean, and calib::AttenCurve::MeanPEPerCmAt().

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  }
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
Far Detector at Ash River, MN.
Prototype Near Detector on the surface at FNAL.
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
std::string fTag
Definition: Calibrator.h:433
assert(nhit_max >=nhit_nbins)
float MeanPEPerCmAt(double w) const
Mean response of this channel at this distance from detector centre.
Definition: AttenCurve.cxx:37
Float_t w
Definition: plot.C:20
CalibratorParams calib::Calibrator::GetCalibratorParams ( )
inline

Definition at line 389 of file Calibrator.h.

Referenced by calib::CalibAna::endJob().

389 {return fParams;}
CalibratorParams fParams
Definition: Calibrator.h:392
std::string calib::Calibrator::GetDriftConstsCSVPath ( )
inline

Definition at line 388 of file Calibrator.h.

References cet::getenv().

Referenced by calib::CalibAna::endJob().

388 {return (fParams.UseCSVsFromUPS()) ? getenv("CALIBCSVS_CSV_PATH") : fParams.DriftConstsCSVPath();}
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
std::string getenv(std::string const &name)
CalibratorParams fParams
Definition: Calibrator.h:392
Atom< std::string > DriftConstsCSVPath
Definition: Calibrator.h:137
double calib::Calibrator::GetDriftScale ( rb::CellHit const &  cellhit)

Part of the PE->PECorr conversion.

Definition at line 920 of file Calibrator_service.cc.

References rb::CellHit::Cell(), fDriftCache, fParams, calib::DriftCache::GetFactor(), rawdata::RawDigit::IsRealData(), rb::CellHit::Plane(), and calib::CalibratorParams::UseDrift.

Referenced by GetPECorr().

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  }
DriftCache * fDriftCache
Definition: Calibrator.h:410
Atom< bool > UseDrift
Definition: Calibrator.h:133
CalibratorParams fParams
Definition: Calibrator.h:392
double GetFactor(int plane, int cell)
Definition: DriftCache.cxx:43
calib::EFEBType calib::Calibrator::getFebType ( novadaq::cnv::DetId  det,
const rawdata::RawDigit dig 
)

Definition at line 751 of file Calibrator_service.cc.

References ana::assert(), rawdata::RawDigit::DaqChannel(), febshutoff_auto::dcm, fCMap, daqchannelmap::DAQChannelMap::getDCM(), novadaq::cnv::kFARDET, calib::kFEB4p1, calib::kFEB5p2, novadaq::cnv::kNEARDET, novadaq::cnv::kTESTBEAM, and cmap::dataprov::CMap::Map().

Referenced by GetAdcPerPE(), GetTimeRes(), and GetTNS().

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  }
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
art::ServiceHandle< cmap::CMap > fCMap
Definition: Calibrator.h:443
Far Detector at Ash River, MN.
uint32_t DaqChannel() const
Definition: RawDigit.h:85
Near Detector in the NuMI cavern.
assert(nhit_max >=nhit_nbins)
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
double calib::Calibrator::GetGeVToCalorimetricScale ( ) const

For use by RecoBase classes.

Conversion from TotalGeV to CalorimetricEnergy. Takes account of dead material and threshold effects in an averaged fashion. Makes no sense to apply to individual hits. You probably don't want to use this, you probably want to look at functions of your RecoBase object.

Definition at line 953 of file Calibrator_service.cc.

Referenced by rb::Cluster::CalorimetricEnergy().

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  }
double calib::Calibrator::GetGeVToMIPScale ( rb::CellHit const &  cellhit)

For GeV->MIP conversion.

Definition at line 933 of file Calibrator_service.cc.

Referenced by MakeRecoHit().

934  {
935  // MIPs for one GeV times one cell in z in NOvA scintillator
936  return 94.62;
937  }
float calib::Calibrator::GetPE ( rb::CellHit const &  ch)

Definition at line 414 of file Calibrator_service.cc.

Referenced by calib::TestParticleCorrections::analyze(), GetPE(), and MakeCellHit().

415  {
416  return this->GetPE(&ch);
417  }
float GetPE(rb::CellHit const &)
float calib::Calibrator::GetPE ( const rawdata::RawDigit rawdigit)

Definition at line 439 of file Calibrator_service.cc.

References GetAdcPerPE(), and GetTNS().

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  }
float GetTNS(const rawdata::RawDigit *rawdigit, bool &goodTime, double *maxadc=0)
double GetAdcPerPE(const rawdata::RawDigit *dig)
Helper function for GetPE()
float calib::Calibrator::GetPE ( rb::CellHit const &  ch,
const double  peakadc 
)
private

Get PE when we have already calculated the peakadc through a call to GetTNS.

Definition at line 408 of file Calibrator_service.cc.

References GetPE().

409  {
410  return this->GetPE(&ch, peakadc);
411  }
float GetPE(rb::CellHit const &)
float calib::Calibrator::GetPE ( const rawdata::RawDigit rawdigit,
const double  peakadc 
)
private

Definition at line 433 of file Calibrator_service.cc.

References GetAdcPerPE().

434  {
435  return peakadc/GetAdcPerPE(dig);
436  }
double GetAdcPerPE(const rawdata::RawDigit *dig)
Helper function for GetPE()
double calib::Calibrator::GetPECorr ( rb::CellHit const &  cellhit,
double  w 
)

Definition at line 699 of file Calibrator_service.cc.

References GetAttenScale(), GetDriftScale(), rb::CellHit::PE(), rb::CellHit::Plane(), scale, SystematicUncertaintyScale(), rb::CellHit::View(), and w.

Referenced by calib::MuondEdx::getPECorr(), calib::DetRespDrift::getPECorr(), calib::MuonTrackHits::getPECorr(), calib::MuondEdxAna::getPECorr(), calib::CalibAna::GetPECorr(), MakeRecoHit(), jmshower::JMTrackMerge::produce(), lem::GenFromLib::readNext(), and slid::NuEEnergyAlg::VertexEnergy().

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  }
double SystematicUncertaintyScale(geo::View_t const &view, unsigned short const &plane, double const &w)
double GetDriftScale(rb::CellHit const &cellhit)
Part of the PE->PECorr conversion.
Double_t scale
Definition: plot.C:25
double GetAttenScale(rb::CellHit const &cellhit, double w)
for PE->PECorr conversion
Float_t w
Definition: plot.C:20
double calib::Calibrator::GetPECorrToGeVScale ( rb::CellHit const &  cellhit)

Definition at line 940 of file Calibrator_service.cc.

References rb::CellHit::Cell(), geo::GeometryBase::DetId(), daqchannelmap::DAQChannelMap::encodeDChan(), daqchannelmap::DAQChannelMap::encodeLChan(), fAbsCache, fCMap, fGeom, daqchannelmap::DAQChannelMap::getDiBlock(), calib::AbsCache::GetPECorrToGeVScale(), rawdata::RawDigit::IsRealData(), cmap::dataprov::CMap::Map(), and rb::CellHit::Plane().

Referenced by calib::MuonTrackHits::getPECorrToGeV(), calib::MuondEdxAna::getPECorrToGeV(), calib::CalibAna::GetPECorrToMeV(), and MakeRecoHit().

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  }
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
art::ServiceHandle< cmap::CMap > fCMap
Definition: Calibrator.h:443
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
AbsCache * fAbsCache
Definition: Calibrator.h:411
double GetPECorrToGeVScale(novadaq::cnv::DetId det, int diblock, bool isData)
Definition: AbsCache.cxx:34
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
uint32_t dchan
< DAQ Channel Map Package
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
double calib::Calibrator::GetShowerEnergy ( TVector3 const &  start,
TVector3 const &  stop,
double const &  totalGeV 
)

Estimate of true shower energy, adapted from RecoJMShower.

Accounts for dead material and threshold effects that can't be done at the individual cell level. Pass in the TVectors and energy explicitly rather than the rb::Track object to avoid a circular dependency with RecoBase

Definition at line 965 of file Calibrator_service.cc.

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  }
double calib::Calibrator::GetT ( rb::CellHit const &  cellhit,
double const &  dist_to_readout 
)

Definition at line 645 of file Calibrator_service.cc.

References rb::CellHit::TNS().

Referenced by MakeRecoHit().

646  {
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  }
double calib::Calibrator::GetTimeRes ( rb::CellHit const &  cellhit)

Definition at line 716 of file Calibrator_service.cc.

References geo::GeometryBase::DetId(), fGeom, getFebType(), rb::CellHit::GoodTiming(), calib::kFEB4p1, rb::CellHit::PE(), cet::pow(), and HandyFuncs::stdev().

Referenced by slicer::S4DParamCalc::analyze(), zcl::FmmTrackerAna::analyze(), zcl::FmmTrackerValidation::analyze(), slicer::SlicerAna::analyze(), tf::TimingFitAlg::HoughFit(), and slicer::Slicer4D::produce().

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  }
def stdev(lst)
Definition: HandyFuncs.py:286
constexpr T pow(T x)
Definition: pow.h:75
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
calib::EFEBType getFebType(novadaq::cnv::DetId det, const rawdata::RawDigit *dig)
TTimeStamp calib::Calibrator::GetTimeStamp ( ) const
inline

Definition at line 285 of file Calibrator.h.

References getBrightness::cell, fillBadChanDBTables::det, NDAPDHVSetting::plane, febshutoff_auto::start, POTSpillRate::view, and w.

285 { return fCurrTimeStamp; }
TTimeStamp fCurrTimeStamp
current time stamp
Definition: Calibrator.h:395
std::string calib::Calibrator::GetTimingConstsCSVPath ( )
inline

Definition at line 387 of file Calibrator.h.

References cet::getenv().

Referenced by calib::CalibAna::endJob().

387 {return (fParams.UseCSVsFromUPS()) ? getenv("CALIBCSVS_CSV_PATH") : fParams.TimingConstsCSVPath();}
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
Atom< std::string > TimingConstsCSVPath
Definition: Calibrator.h:129
std::string getenv(std::string const &name)
CalibratorParams fParams
Definition: Calibrator.h:392
double calib::Calibrator::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.

Definition at line 979 of file Calibrator_service.cc.

References getBrightness::cell, geo::GeometryBase::DetId(), daqchannelmap::DAQChannelMap::encodeDChan(), daqchannelmap::DAQChannelMap::encodeLChan(), EnsureTimingCacheVldTime(), fCMap, fCurrTimeStamp, fGeom, fParams, fTimingCache, daqchannelmap::DAQChannelMap::getDCM(), daqchannelmap::DAQChannelMap::getDiBlock(), calib::TimingCache::GetOffset(), cmap::dataprov::CMap::Map(), PandAna.reco_validation.add_data::offset, NDAPDHVSetting::plane, and calib::CalibratorParams::UseTimingOffsets.

Referenced by calib::TimingCalibration::produce().

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  }
TimingCache * fTimingCache
Definition: Calibrator.h:412
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
art::ServiceHandle< cmap::CMap > fCMap
Definition: Calibrator.h:443
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
CalibratorParams fParams
Definition: Calibrator.h:392
TTimeStamp fCurrTimeStamp
current time stamp
Definition: Calibrator.h:395
Atom< bool > UseTimingOffsets
Definition: Calibrator.h:237
double GetOffset(int dcm, int diblock, std::uint32_t time, bool isData)
Definition: TimingCache.cxx:40
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
uint32_t dchan
< DAQ Channel Map Package
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
float calib::Calibrator::GetTNS ( const rawdata::RawDigit rawdigit,
bool &  goodTime,
double *  maxadc = 0 
)
Parameters
goodTimeDid the timing fit go well?
maxadcInternal hook for use of GetPE

Definition at line 454 of file Calibrator_service.cc.

References rawdata::RawDigit::ADC(), ana::assert(), om::cout, fillBadChanDBTables::det, geo::GeometryBase::DetId(), allTimeWatchdog::endl, fCalibrateMode, fGeom, plot_validation_datamc::fname, fShapeTable, fShapeTable5TB, fShapeTableFilenameFDData, fShapeTableFilenameFDMC, fShapeTableFilenameNDData, fShapeTableFilenameNDMC, getFebType(), daqdataformats::NanoSliceVersionConvention::getNPretriggeredSamples(), daqdataformats::NanoSliceVersionConvention::getNSamples(), rawdata::RawDigit::IsMC(), calib::kFEB4p1, calib::kFEB5p2, novadaq::cnv::kTESTBEAM, rawdata::RawDigit::NADC(), rawdata::RawDigit::TDC(), calib::ADCShapeFitTable::TNS(), and rawdata::RawDigit::Version().

Referenced by GetPE(), MakeCellHit(), and comi::Cana::produce().

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  }
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
uint32_t getNSamples(const version_t ver) const
Get the number of samples.
uint32_t getNPretriggeredSamples(const version_t ver) const
Get number of pretriggered samples.
std::string fShapeTableFilenameFDMC
Root file ADCShapeFitTable will load from.
Definition: Calibrator.h:399
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
double TNS(double tns0, int16_t adc1, int16_t adc2, int16_t adc3, double &adcpeak, bool &goodTime, double &base) const
ADCShapeFitTable * fShapeTable
Definition: Calibrator.h:405
ADCShapeFitTable * fShapeTable5TB
FEBv5 table for TestBeam (fShapeTable will be FEBv4)
Definition: Calibrator.h:406
OStream cout
Definition: OStream.cxx:6
std::string fShapeTableFilenameNDMC
Definition: Calibrator.h:401
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
calib::EFEBType getFebType(novadaq::cnv::DetId det, const rawdata::RawDigit *dig)
std::string fShapeTableFilenameFDData
Definition: Calibrator.h:400
std::string fShapeTableFilenameNDData
Definition: Calibrator.h:402
assert(nhit_max >=nhit_nbins)
rb::CellHit calib::Calibrator::MakeCellHit ( const rawdata::RawDigit rawdigit)

Definition at line 361 of file Calibrator_service.cc.

References rawdata::RawDigit::ADC(), rb::CellHit::Cell(), geo::GeometryBase::DetId(), daqchannelmap::DAQChannelMap::encodeDChan(), daqchannelmap::DAQChannelMap::encodeLChan(), EnsureTimingCacheVldTime(), rawdata::RawDigit::fADC, fCMap, fCurrTimeStamp, fGeom, fParams, fTimingCache, cmap::dataprov::CMap::GetCell(), daqchannelmap::DAQChannelMap::getDCM(), daqchannelmap::DAQChannelMap::getDiBlock(), calib::TimingCache::GetOffset(), GetPE(), cmap::dataprov::CMap::GetPlane(), GetTNS(), rawdata::RawDigit::IsRealData(), calib::CalibratorParams::MakeSinglePointCellHits, cmap::dataprov::CMap::Map(), PandAna.reco_validation.add_data::offset, rb::CellHit::Plane(), geo::GeometryBase::Plane(), rawdata::RawDigit::SetADC(), rb::CellHit::SetCell(), rb::CellHit::SetPE(), rb::CellHit::SetPlane(), rb::CellHit::SetTNS(), rawdata::RawDigit::SetVersion(), rb::CellHit::SetView(), calib::CalibratorParams::UseTimingOffsets, and rawdata::RawDigit::Version().

Referenced by bsf::BremShowerFilter::filter(), MergeDaqCollections::MergeDaqCollections::produce(), calhit::CalHit::produce(), murem::MuonRemove::produce(), and lem::GenFromLib::readNext().

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  }
TimingCache * fTimingCache
Definition: Calibrator.h:412
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
float GetTNS(const rawdata::RawDigit *rawdigit, bool &goodTime, double *maxadc=0)
const PlaneGeo * Plane(unsigned int i) const
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
art::ServiceHandle< cmap::CMap > fCMap
Definition: Calibrator.h:443
void SetVersion(uint8_t v)
Definition: RawDigit.h:101
void SetADC(uint32_t i, int16_t iADC)
Definition: RawDigit.cxx:108
Atom< bool > MakeSinglePointCellHits
Definition: Calibrator.h:233
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
unsigned short GetPlane(const rawdata::RawDigit *dig)
Definition: CMap.cxx:285
uint8_t Version() const
Definition: RawDigit.h:87
Definition: View.py:1
CalibratorParams fParams
Definition: Calibrator.h:392
TTimeStamp fCurrTimeStamp
current time stamp
Definition: Calibrator.h:395
std::vector< int16_t > fADC
list of ADC(-like) charge values
Definition: RawDigit.h:49
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
int16_t ADC(uint32_t i) const
Definition: RawDigit.cxx:58
unsigned short GetCell(const rawdata::RawDigit *dig)
Definition: CMap.cxx:327
Atom< bool > UseTimingOffsets
Definition: Calibrator.h:237
double GetOffset(int dcm, int diblock, std::uint32_t time, bool isData)
Definition: TimingCache.cxx:40
float GetPE(rb::CellHit const &)
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
uint32_t dchan
< DAQ Channel Map Package
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
rb::RecoHit calib::Calibrator::MakeRecoHit ( rb::CellHit const &  cellhit,
double  w 
)

Definition at line 575 of file Calibrator_service.cc.

References calib::GetXYZD(), rb::CellHit::OfflineChan(), and w.

Referenced by calib::TestParticleCorrections::analyze(), mcchk::MonopoleAna::analyze(), calib::AssessCalib::analyze(), zcl::FmmTrackerAna::analyze(), zcl::FmmTrackerValidation::analyze(), rockmuon::NDRockMuon::analyze(), remid::ReMIdDedxRock::analyze(), remid::ReMIdDedxFD::analyze(), remid::ReMIdDedxStudies::analyze(), bpfit::BPFTmvaTrainer::analyze(), bpfit::BreakPointProtonAna::analyze(), ncs::Xeff::analyze(), ncs::ROCKMRE::analyze(), slid::LIDTraining::analyze(), ncs::NCAna::analyze(), fuzz::ViewMatchAlg::CalcEnergyProfile(), nerd::ViewMatchAlg::CalcEnergyProfile(), slid::NuEEnergyAlg::CellEnergy(), bpfit::dEdxCalculator::computeDEDX(), caf::FillHadClustVars(), caf::FillSliceVars(), jmshower::RecoJMShower::GetRVPStats(), slid::NuEEnergyAlg::HadronicDepEnergy(), rvp::RecVarPID::MakeRecoHit(), xnue::XnuePID::MakeRecoHit(), ncs::GenieTruth::MakeRecoHit(), ncs::Xbeam::MakeRecoHit(), ncs::Xeff::MakeRecoHit(), ncs::ROCKMRE::MakeRecoHit(), ncs::NCAna::MakeRecoHit(), MakeRecoHit(), nuesand::FillNueSandbox::produce(), lem::Preselection::produce(), presel::NuePresel::produce(), zcl::SMMCluster::produce(), zcl::FMMTracker::produce(), jmshower::NueSel::produce(), jmshower::NueSelLID::produce(), bpfit::BPFEnergyEstimator::produce(), remid::RecoMuon::produce(), bpfit::BPFEnergyEstimatorOnly::produce(), rb::Cluster::RecoHit(), jmshower::RecoJMShower::RecoShowers(), lem::LEMSummarizer::SliceToLEMInput(), rb::Cluster::TotalGeVFastClusterOnly(), and slid::NuEEnergyAlg::VertexEnergy().

577  {
578  Double_t xyzd[4];
579  GetXYZD(cellhit.OfflineChan(), w, xyzd);
580  return MakeRecoHit(cellhit, w, xyzd);
581  }
rb::RecoHit MakeRecoHit(rb::CellHit const &cellhit, double w)
void GetXYZD(geo::OfflineChan chan, double w, double *xyzd)
Return position in world coordninates and distance to the readout.
Definition: CalibUtil.cxx:294
Float_t w
Definition: plot.C:20
rb::RecoHit calib::Calibrator::MakeRecoHit ( rb::CellHit const &  cellhit,
double *  xyz 
)

Definition at line 584 of file Calibrator_service.cc.

References geo::kX, MakeRecoHit(), rb::CellHit::View(), and w.

586  {
587  double w = xyz[0];
588  if(cellhit.View() == geo::kX) w = xyz[1];
589 
590  return MakeRecoHit(cellhit, w, xyz);
591  }
Vertical planes which measure X.
Definition: PlaneGeo.h:28
rb::RecoHit MakeRecoHit(rb::CellHit const &cellhit, double w)
Float_t w
Definition: plot.C:20
rb::RecoHit calib::Calibrator::MakeRecoHit ( rb::CellHit const &  cellhit,
double &  w,
double *  xyz 
)
private

Helper function for the two public MakeRecoHit methods.

Definition at line 595 of file Calibrator_service.cc.

References ana::assert(), fStatsNumCalibrated, fStatsNumUncalibrated, GetGeVToMIPScale(), GetPECorr(), GetPECorrToGeVScale(), GetT(), std::isinf(), std::isnan(), LOG_ERROR, rb::RecoHit::SetGeV(), rb::RecoHit::SetMIP(), rb::RecoHit::SetPECorr(), rb::RecoHit::SetT(), rb::RecoHit::SetX(), rb::RecoHit::SetY(), and rb::RecoHit::SetZ().

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  }
int isinf(const stan::math::var &a)
Definition: std_isinf.hpp:16
double GetPECorrToGeVScale(rb::CellHit const &cellhit)
void SetGeV(float GeV)
Definition: RecoHit.h:44
void SetMIP(float MIP)
Definition: RecoHit.h:43
unsigned int fStatsNumUncalibrated
Number of uncalibrated hits returned.
Definition: Calibrator.h:451
void SetX(float X)
Definition: RecoHit.h:45
void SetT(float T)
Definition: RecoHit.h:48
double GetGeVToMIPScale(rb::CellHit const &cellhit)
For GeV->MIP conversion.
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
Calibrated quantities relying on position in the orthogonal view. To generate a rb::CellHit from a rb...
Definition: RecoHit.h:19
double GetT(rb::CellHit const &cellhit, double const &dist_to_readout)
void SetY(float Y)
Definition: RecoHit.h:46
assert(nhit_max >=nhit_nbins)
double GetPECorr(rb::CellHit const &cellhit, double w)
void SetPECorr(float PECorr)
Definition: RecoHit.h:42
unsigned int fStatsNumCalibrated
Number of calibrated hits returned.
Definition: Calibrator.h:449
Float_t w
Definition: plot.C:20
void SetZ(float Z)
Definition: RecoHit.h:47
#define LOG_ERROR(stream)
Definition: Messenger.h:129
void calib::Calibrator::postBeginRun ( art::Run const &  run)

Definition at line 182 of file Calibrator_service.cc.

References ana::assert(), calib::CalibratorParams::AttenCSVPath, calib::CalibratorParams::AttenEpochTag, b, om::cerr, nova::dbi::RunHistory::DetGainSetting(), geo::GeometryBase::DetId(), allTimeWatchdog::endl, fAbsCache, fAttenCacheData, fAttenCacheMC, fCurrentRun, fDriftCache, fFibBrightness, fGain, fGeom, fParams, fTag, fTimingCache, fTimingCacheVldTimeSet, fXFunction, fXMuCFunction, fYFunction, calib::AbsCache::GainSetting(), calib::AttenCache::GainSetting(), MECModelEnuComparisons::i, novadaq::cnv::kNEARDET, photrans::FiberBrightness::NumberBrightnessBins(), calib::AttenCache::ReadEpochsFromCSV(), calib::CalibratorParams::ReadEpochsFromCSV, calib::AbsCache::Reinit(), calib::AttenCache::Reinit(), rh, art::Run::run(), runNovaSAM::runNum, nova::dbi::RunHistory::RunNumber(), calib::AttenCache::SetCSVSource(), calib::TimingCache::SetEpoch(), calib::AbsCache::SetEpoch(), calib::AttenCache::SetEpoch(), calib::AttenCache::SetEpochTag(), calib::AbsCache::SetGainSetting(), calib::AttenCache::SetGainSetting(), calib::DriftCache::SetRun(), calib::TimingCache::SetRun(), calib::AbsCache::SetRun(), calib::AttenCache::SetRun(), calib::AttenCache::SetTag(), calib::AttenCache::SetUseEpochs(), calib::CalibratorParams::UseAttenEpochs, calib::AttenCache::UseCSVsFromUPS(), calib::CalibratorParams::UseCSVsFromUPS, calib::CalibratorParams::UseDrift, calib::TimingCache::UseEpochs(), calib::AbsCache::UseEpochs(), calib::AttenCache::UseEpochs(), calib::CalibratorParams::UseGainSetting4Abs, calib::CalibratorParams::UseGainSetting4Atten, calib::CalibratorParams::UseXFunction, calib::CalibratorParams::UseYFunction, calib::CalibratorParams::Xg100FunctionForm, calib::CalibratorParams::Xg100FunctionParams, calib::CalibratorParams::Xg140FunctionForm, calib::CalibratorParams::Xg140FunctionParams, calib::CalibratorParams::XMuCg100FunctionForm, calib::CalibratorParams::XMuCg100FunctionParams, calib::CalibratorParams::Yg100FunctionForm, calib::CalibratorParams::Yg100FunctionParams, calib::CalibratorParams::Yg140FunctionForm, and calib::CalibratorParams::Yg140FunctionParams.

Referenced by Calibrator().

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
void SetGainSetting(int g)
Definition: AbsCache.h:32
void ReadEpochsFromCSV(bool readEpochs=true)
Definition: AttenCache.h:55
TH2 * rh
Definition: drawXsec.C:5
void SetEpoch(const std::string &epoch)
Definition: AbsCache.h:47
Sequence< double > Xg140FunctionParams
Definition: Calibrator.h:205
void SetRun(int detector, int run)
Definition: DriftCache.cxx:62
TimingCache * fTimingCache
Definition: Calibrator.h:412
Atom< std::string > Yg100FunctionForm
Definition: Calibrator.h:181
Atom< bool > UseGainSetting4Atten
Definition: Calibrator.h:157
void SetGainSetting(int g)
Definition: AttenCache.h:61
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
void UseCSVsFromUPS(bool use=true)
Definition: AttenCache.h:38
OStream cerr
Definition: OStream.cxx:7
Atom< std::string > XMuCg100FunctionForm
Definition: Calibrator.h:177
int GainSetting()
Definition: AbsCache.h:33
Atom< std::string > AttenEpochTag
Definition: Calibrator.h:89
DriftCache * fDriftCache
Definition: Calibrator.h:410
unsigned int NumberBrightnessBins() const
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:93
void SetEpoch(const std::string &epoch)
Definition: TimingCache.h:28
void SetRun(int run)
Definition: AbsCache.h:57
Atom< std::string > AttenCSVPath
Definition: Calibrator.h:97
Atom< bool > UseDrift
Definition: Calibrator.h:133
Sequence< double > XMuCg100FunctionParams
Definition: Calibrator.h:197
void SetEpochTag(const std::string &tag)
Definition: AttenCache.h:49
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Atom< bool > UseXFunction
Definition: Calibrator.h:165
bool UseEpochs()
Definition: AbsCache.h:45
Near Detector in the NuMI cavern.
Atom< bool > UseAttenEpochs
Definition: Calibrator.h:85
void SetRun(int run)
Definition: AttenCache.h:58
void Reinit()
Definition: AbsCache.h:35
CalibratorParams fParams
Definition: Calibrator.h:392
bool fTimingCacheVldTimeSet
Is fTimingCache set to the right time?
Definition: Calibrator.h:413
Definition: run.py:1
Atom< bool > UseGainSetting4Abs
Definition: Calibrator.h:153
Atom< std::string > Xg140FunctionForm
Definition: Calibrator.h:185
AbsCache * fAbsCache
Definition: Calibrator.h:411
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string fTag
Definition: Calibrator.h:433
void SetEpoch(const std::string &epoch)
Definition: AttenCache.h:48
Atom< std::string > Xg100FunctionForm
Definition: Calibrator.h:173
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)
Sequence< double > Yg100FunctionParams
Definition: Calibrator.h:201
art::ServiceHandle< photrans::FiberBrightness > fFibBrightness
Definition: Calibrator.h:445
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
Atom< bool > ReadEpochsFromCSV
Definition: Calibrator.h:105
Atom< bool > UseYFunction
Definition: Calibrator.h:169
Atom< std::string > Yg140FunctionForm
Definition: Calibrator.h:189
Sequence< double > Yg140FunctionParams
Definition: Calibrator.h:209
void SetCSVSource(const std::string &path)
Definition: AttenCache.h:36
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
int RunNumber() const
Definition: RunHistory.h:374
void SetUseEpochs(bool b)
Definition: AttenCache.h:44
void calib::Calibrator::postBeginSubRun ( art::SubRun const &  subrun)

Definition at line 176 of file Calibrator_service.cc.

Referenced by Calibrator().

177  {
178  return;
179  }
void calib::Calibrator::preEvent ( art::Event const &  evt)

Definition at line 160 of file Calibrator_service.cc.

References fCurrTimeStamp, art::Event::time(), and art::Timestamp::value().

Referenced by Calibrator().

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  }
int evt
TTimeStamp fCurrTimeStamp
current time stamp
Definition: Calibrator.h:395
double calib::Calibrator::SystematicUncertaintyScale ( geo::View_t const &  view,
unsigned short const &  plane,
double const &  w 
)

Method to determine the systematic uncertainty scale factor to apply when those options are turned on. This function should only be called by code wishing to check the behavior of the systematic scaling, it is not useful outside of the Calibrator service otherwise

Definition at line 656 of file Calibrator_service.cc.

References geo::GeometryBase::DetId(), calib::CalibratorParams::DriftGradient, calib::CalibratorParams::DriftReference, nova::dbi::RunHistory::Duration(), fGeom, geo::GeometryBase::FirstPlaneInMuonCatcher(), fParams, fXFunction, fXMuCFunction, fYFunction, makeTrainCVSamples::int, novadaq::cnv::kNEARDET, geo::kX, geo::kY, rh, scale, calib::CalibratorParams::SimulateDrift, nova::dbi::RunHistory::TStart(), calib::CalibratorParams::UseXFunction, and calib::CalibratorParams::UseYFunction.

Referenced by GetPECorr().

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 &&
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  }
TH2 * rh
Definition: drawXsec.C:5
Vertical planes which measure X.
Definition: PlaneGeo.h:28
art::ServiceHandle< geo::Geometry > fGeom
Definition: Calibrator.h:444
Atom< bool > SimulateDrift
Definition: Calibrator.h:241
Horizontal planes which measure Y.
Definition: PlaneGeo.h:29
Double_t scale
Definition: plot.C:25
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Atom< bool > UseXFunction
Definition: Calibrator.h:165
Near Detector in the NuMI cavern.
int Duration()
in units of seconds
Definition: RunHistory.h:389
Atom< int > DriftReference
Definition: Calibrator.h:245
CalibratorParams fParams
Definition: Calibrator.h:392
Atom< double > DriftGradient
Definition: Calibrator.h:249
Atom< bool > UseYFunction
Definition: Calibrator.h:169
Float_t w
Definition: plot.C:20
const unsigned int FirstPlaneInMuonCatcher() const
Returns the index of the first plane contained in the muon catcher.

Member Data Documentation

AbsCache* calib::Calibrator::fAbsCache
private

Definition at line 411 of file Calibrator.h.

Referenced by Calibrator(), GetPECorrToGeVScale(), postBeginRun(), and ~Calibrator().

AttenCache* calib::Calibrator::fAttenCacheData
private

Data attenutation corrections.

Definition at line 408 of file Calibrator.h.

Referenced by GetAttenCurve(), postBeginRun(), and ~Calibrator().

std::vector< AttenCache* > calib::Calibrator::fAttenCacheMC
private

MC attenutation corrections indexed by fiber brightness.

Definition at line 409 of file Calibrator.h.

Referenced by GetAttenCurve(), postBeginRun(), and ~Calibrator().

int calib::Calibrator::fCalibrateMode
private

Definition at line 397 of file Calibrator.h.

Referenced by Calibrator(), and GetTNS().

art::ServiceHandle<cmap::CMap> calib::Calibrator::fCMap
private

Definition at line 443 of file Calibrator.h.

Referenced by getFebType(), GetPECorrToGeVScale(), GetTimingOffset(), and MakeCellHit().

int calib::Calibrator::fCurrentRun
private

get the current run to make sure that we know if we have perfect MC

Definition at line 414 of file Calibrator.h.

Referenced by postBeginRun().

TTimeStamp calib::Calibrator::fCurrTimeStamp
private

current time stamp

Definition at line 395 of file Calibrator.h.

Referenced by GetTimingOffset(), MakeCellHit(), and preEvent().

DriftCache* calib::Calibrator::fDriftCache
private

Definition at line 410 of file Calibrator.h.

Referenced by Calibrator(), GetDriftScale(), postBeginRun(), and ~Calibrator().

art::ServiceHandle<photrans::FiberBrightness> calib::Calibrator::fFibBrightness
private

Definition at line 445 of file Calibrator.h.

Referenced by GetAttenCurve(), and postBeginRun().

double calib::Calibrator::fGain
private

Definition at line 434 of file Calibrator.h.

Referenced by Calibrator(), GetAdcPerPE(), and postBeginRun().

art::ServiceHandle<geo::Geometry> calib::Calibrator::fGeom
private
CalibratorParams calib::Calibrator::fParams
protected
art::ServiceHandle<nova::dbi::RunHistoryService> calib::Calibrator::fRH
private

Definition at line 446 of file Calibrator.h.

ADCShapeFitTable* calib::Calibrator::fShapeTable
private

Definition at line 405 of file Calibrator.h.

Referenced by GetTNS(), and ~Calibrator().

ADCShapeFitTable* calib::Calibrator::fShapeTable5TB
private

FEBv5 table for TestBeam (fShapeTable will be FEBv4)

Definition at line 406 of file Calibrator.h.

Referenced by GetTNS(), and ~Calibrator().

std::string calib::Calibrator::fShapeTableFilenameFDData
private

Definition at line 400 of file Calibrator.h.

Referenced by Calibrator(), and GetTNS().

std::string calib::Calibrator::fShapeTableFilenameFDMC
private

Root file ADCShapeFitTable will load from.

Definition at line 399 of file Calibrator.h.

Referenced by Calibrator(), and GetTNS().

std::string calib::Calibrator::fShapeTableFilenameNDData
private

Definition at line 402 of file Calibrator.h.

Referenced by Calibrator(), and GetTNS().

std::string calib::Calibrator::fShapeTableFilenameNDMC
private

Definition at line 401 of file Calibrator.h.

Referenced by Calibrator(), and GetTNS().

unsigned int calib::Calibrator::fStatsNumAveraged
private

Number of hits from uncalibrated diblocks using averaged calibrations.

Definition at line 453 of file Calibrator.h.

Referenced by GetAttenScale(), and ~Calibrator().

unsigned int calib::Calibrator::fStatsNumCalibrated
private

Number of calibrated hits returned.

Definition at line 449 of file Calibrator.h.

Referenced by MakeRecoHit(), and ~Calibrator().

unsigned int calib::Calibrator::fStatsNumUncalibrated
private

Number of uncalibrated hits returned.

Definition at line 451 of file Calibrator.h.

Referenced by MakeRecoHit(), and ~Calibrator().

std::string calib::Calibrator::fTag
private

Definition at line 433 of file Calibrator.h.

Referenced by Calibrator(), GetAttenCurve(), GetAttenScale(), and postBeginRun().

TimingCache* calib::Calibrator::fTimingCache
private
bool calib::Calibrator::fTimingCacheVldTimeSet
private

Is fTimingCache set to the right time?

Definition at line 413 of file Calibrator.h.

Referenced by EnsureTimingCacheVldTime(), and postBeginRun().

TF1* calib::Calibrator::fXFunction
private

Definition at line 436 of file Calibrator.h.

Referenced by postBeginRun(), and SystematicUncertaintyScale().

TF1* calib::Calibrator::fXMuCFunction
private

Definition at line 437 of file Calibrator.h.

Referenced by postBeginRun(), and SystematicUncertaintyScale().

TF1* calib::Calibrator::fYFunction
private

Definition at line 438 of file Calibrator.h.

Referenced by postBeginRun(), and SystematicUncertaintyScale().


The documentation for this class was generated from the following files: