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/N21-04-18/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, art::ScheduleContext)
 
void postBeginRun (art::Run const &run)
 
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 273 of file Calibrator.h.

Member Typedef Documentation

Definition at line 276 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(), 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::sPreProcessEvent, string, 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);
120  reg.sPostBeginRun.watch(this, &Calibrator::postBeginRun);
121  }
Atom< bool > UseTimingEpochs
Definition: Calibrator.h:118
void SetUseEpochs(bool b)
Definition: AbsCache.h:43
void UseCSVsFromUPS(bool use=true)
Definition: DriftCache.h:47
Atom< std::string > DriftEpochTag
Definition: Calibrator.h:150
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:82
TimingCache * fTimingCache
Definition: Calibrator.h:412
unsigned int fStatsNumUncalibrated
Number of uncalibrated hits returned.
Definition: Calibrator.h:451
Atom< double > Gain
Definition: Calibrator.h:162
::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:126
Atom< std::string > AbsEpochTag
Definition: Calibrator.h:110
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:76
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:94
void SetTag(const std::string &tag)
Definition: DriftCache.h:33
Atom< std::string > TimingConstsCSVPath
Definition: Calibrator.h:130
void preEvent(art::Event const &evt, art::ScheduleContext)
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
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
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:102
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
std::string fTag
Definition: Calibrator.h:433
std::string fShapeTableFilenameFDData
Definition: Calibrator.h:400
void UseCSVsFromUPS(bool use=true)
Definition: TimingCache.h:23
Atom< std::string > TimingEpochTag
Definition: Calibrator.h:122
std::string fShapeTableFilenameNDData
Definition: Calibrator.h:402
Atom< std::string > DriftCSV
Definition: Calibrator.h:142
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
Atom< bool > ReadEpochsFromCSV
Definition: Calibrator.h:106
Atom< std::string > DriftConstsCSVPath
Definition: Calibrator.h:138
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:146
Atom< std::string > AbsConstsCSVPath
Definition: Calibrator.h:114
enum BeamMode string
calib::Calibrator::~Calibrator ( )

Definition at line 124 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().

125  {
126  if(fShapeTable){
127  // Expecting about 95%
128  mf::LogInfo("Calibrator") << "ADCShapeFitTable hit rate was "
129  << int(100*fShapeTable->TableHitFraction())
130  << "%";
131  delete fShapeTable;
132  }
133  if(fShapeTable5TB){
134  // Expecting about 95%
135  mf::LogInfo("Calibrator") << "ADCShapeFitTable v5 (TB only) hit rate was "
137  << "%";
138  delete fShapeTable5TB;
139  }
140 
141  // NumCalibrated includes NumAveraged
142  const unsigned int numRet = fStatsNumCalibrated+fStatsNumUncalibrated;
143  if(numRet > 0){
144  // Hopefully around 1%
145  mf::LogInfo("Calibrator")
146  << "Provided " << numRet << " RecoHits, of which "
147  << ((1000*fStatsNumUncalibrated)/numRet)*.1 << "% were uncalibrated and "
148  << ((1000*fStatsNumAveraged)/numRet)*.1 << "% were average constants.";
149  }
150 
151  for(AttenCache* c: fAttenCacheMC) delete c;
152  delete fAttenCacheData;
153  delete fDriftCache;
154  delete fAbsCache;
155  delete fTimingCache;
156  }
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 995 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().

996  {
997  if(fTimingCacheVldTimeSet) return;
998 
999  // use run history to improve database performance. Apparently asking the
1000  // run object start and end time was not producing the same result for each
1001  // subrun and so the cacheing performance of the timing calibration table
1002  // was poor, clogging the system.
1005  rh->TStart(),
1006  rh->TStop());
1007 
1008  fTimingCacheVldTimeSet = true;
1009  }
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:94
std::string getenv(std::string const &name)
CalibratorParams fParams
Definition: Calibrator.h:392
Atom< std::string > AbsConstsCSVPath
Definition: Calibrator.h:114
double calib::Calibrator::GetAdcPerPE ( const rawdata::RawDigit dig)
private

Helper function for GetPE()

Definition at line 413 of file Calibrator_service.cc.

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

Referenced by GetPE().

414  {
415  const int maxadc = (1<<12)-1; // 4095
416 
417  // FEB 4.1
418  if(getFebType(fGeom->DetId(),dig)==calib::kFEB4p1)
419  return fGain*maxadc/217000.;
420 
421  // FEB 5.2
422  return fGain*maxadc/204800.;
423  }
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:94
Atom< std::string > AttenCSVPath
Definition: Calibrator.h:98
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 843 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().

849  {
850  const geo::OfflineChan offline_channel(plane, cell);
851 
852  unsigned int fbBin = fFibBrightness->getBrightnessIndex(plane,cell);
853  if( fbBin >= fAttenCacheMC.size() ){
854  std::cerr << "Brightness bin " << fbBin << " too high.";
855  std::abort();
856  }
857 
858  //make sure not to mask uncalibrated mc in perfect mc
859  bool maskUncalibratedChannels = fParams.MaskUncalibratedChannelsInMC();
860  if(fCurrentRun < 1e4 || fCurrentRun >= 1e6){
861  maskUncalibratedChannels = false;
862  }
863 
864  if(fTag == "v1" || fTag == "v2" ||
865  fTag == "v3" || fTag == "v3.1" ||
866  fTag == "v4" || fTag == "v5" ||
867  fTag == "v5.1" || fTag == "v6" ){
868  std::cout << "Calibrator: tag is too old: " << fTag << std::endl;
869  abort();
870  }
871 
872  bool isNDMCX = ( fGeom->DetId() == novadaq::cnv::kNEARDET &&
874  (fGeom->Plane(plane)->View() == geo::kX) );
875 
876  //make sure not to mask the ND muon catcher x planes after v6 where we have forced the fit to converge
877  if(isNDMCX){
878  maskUncalibratedChannels = false;
879  }
880 
881  if(is_realdata)
882  curve = fAttenCacheData ->ForData(fGeom.get(), offline_channel);
883  else
884  curve = fAttenCacheMC[fbBin]->ForMC(fGeom.get(), offline_channel, maskUncalibratedChannels);
885  if(!curve) return false;
886 
887  // allow poor calibration quality in the ND muon catcher x planes after v6
888  // where we have used LOWESS to force fits to work in spite of the attenuation fit
889  if(!curve->IsCalibrated() && !isNDMCX) return false;
890 
891  // Clamp given w-coordinate into the detector to avoid bad behaviour of the
892  // attenuation function.
893  maxW = fGeom->Plane(plane)->Cell(cell)->HalfL();
894  minW = -fGeom->Plane(plane)->Cell(cell)->HalfL();
895 
896  //check to see if we're in the nd muon catcher and therefore have an asymmetric cell
898  plane >= int(fGeom->FirstPlaneInMuonCatcher())){
899  int i = 0;
900  const geo::PlaneGeo* regularPlane = fGeom->Plane(i);
901  while(regularPlane->View() != fGeom->Plane(plane)->View())
902  regularPlane = fGeom->Plane(++i);
903  const geo::CellGeo* regularCell = regularPlane->Cell(cell);
904  // Assume that the cells are aligned on the floor
905  minW = -regularCell->HalfL();
906  maxW = (2 * maxW) - regularCell->HalfL();
907  }
908 
909  return true;
910  }
double HalfL() const
Definition: CellGeo.cxx:198
T * get() const
Definition: ServiceHandle.h:63
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:230
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 765 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().

767  {
768 
769  const calib::AttenCurve* curve = 0;
770  double maxW = 0.0;
771  double minW = 0.0;
772 
773  if(!GetAttenCurve(cellhit.Plane(),
774  cellhit.Cell(),
775  cellhit.IsRealData(),
776  curve,
777  minW,
778  maxW)) return -1;
779 
780  if(curve->chan.Plane() >= 1000) ++fStatsNumAveraged;
781 
782  double scale = 1.0;
783 
784  //set random scaling factor for systematic studies at either the resolution of the cell or per cm in the cell around
785  //a gaussian with a sigma set at the fParams.CellByCellCalibRandomOffset()
788  int wInt = (int) w;
789  if(wInt == 0){
790  wInt = 9999;
791  }
792  TRandom3 *noiseGenerator = new TRandom3(fParams.CellByCellCalibRandomOffsetSeed()*(cellhit.Plane()+1)*(cellhit.Cell()+1)*wInt);
793  scale = noiseGenerator->Gaus(1, fParams.CellByCellCalibRandomOffset());
794  delete noiseGenerator;
795  }
796  else{
797  TRandom3 *noiseGenerator = new TRandom3(fParams.CellByCellCalibRandomOffsetSeed()*(cellhit.Plane()+1)*(cellhit.Cell()+1));
798  scale=noiseGenerator->Gaus(1, fParams.CellByCellCalibRandomOffset());
799  delete noiseGenerator;
800  }
801  }
802 
803  return scale * GetAttenScale(curve, minW, maxW, w);
804  }
Atom< bool > CellByCellCalibRandomOffsetHighResolution
Definition: Calibrator.h:218
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:214
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:222
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:226
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 807 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().

811  {
812 
813  if(w < minW) w = minW;
814  if(w > maxW) w = maxW;
815 
816  const double mean = curve->MeanPEPerCmAt(w, fTag);
817 
818  if(mean <= 0) return -1;
819 
820  // The goal of this factor is to make PECorrs approximately the same size
821  // as PEs. But the exact values are terrible historical accident. If we
822  // decide to clean this up in future calibration versions we can do so and
823  // then condition this on the tag version.
824 
825  //RJN These numbers don't actually matter they are the value the relative
826  //calibration is normalised to... the absolute takes this factor out.
827  double pecorrscale = 0;
828  switch(fGeom->DetId()){
829  case novadaq::cnv::kNDOS: pecorrscale = 75.00; break;
830  case novadaq::cnv::kNEARDET: pecorrscale = 37.51; break;
831  case novadaq::cnv::kFARDET: pecorrscale = 39.91; break;
832  case novadaq::cnv::kTESTBEAM: pecorrscale = 39.91; break;
833  default:
834  assert(0 && "Unknown detector");
835  }
836 
837  const double factor = pecorrscale/mean;
838 
839  return factor;
840  }
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:94
std::string getenv(std::string const &name)
CalibratorParams fParams
Definition: Calibrator.h:392
Atom< std::string > DriftConstsCSVPath
Definition: Calibrator.h:138
double calib::Calibrator::GetDriftScale ( rb::CellHit const &  cellhit)

Part of the PE->PECorr conversion.

Definition at line 913 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().

914  {
915  if (!fParams.UseDrift()) return 1;
916 
917  // MC doesn't drift
918  if(!cellhit.IsRealData()) return 1;
919 
920  return fDriftCache->GetFactor(cellhit.Plane(),
921  cellhit.Cell());
922 
923  }
DriftCache * fDriftCache
Definition: Calibrator.h:410
Atom< bool > UseDrift
Definition: Calibrator.h:134
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 744 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().

745  {
746  switch(det) {
747  case novadaq::cnv::kFARDET: return kFEB4p1;
748  case novadaq::cnv::kNEARDET: return kFEB5p2;
750  {
751  const uint32_t dcm = fCMap->Map()->getDCM(dig->DaqChannel());
752  //RJN magic number panic this magic number came from
753  //MergeTBDaqCollections_module.cc
754  if(dcm==3)
755  return kFEB5p2;
756  return kFEB4p1;
757 
758  }
759  default:
760  assert (!"The default case of getFebType switch was reached.");
761  return kFEB4p1;
762  }
763  }
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 946 of file Calibrator_service.cc.

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

947  {
948  // From Kanika's study: docdb 11528
949  //
950  // Could vary by detector or calibration version etc. We have all that
951  // information available here. If it gets complicated enough may need to
952  // come from database. For now it's a single number, and there's a
953  // reasonable chance it might never need to change.
954  return 1.78;
955  }
double calib::Calibrator::GetGeVToMIPScale ( rb::CellHit const &  cellhit)

For GeV->MIP conversion.

Definition at line 926 of file Calibrator_service.cc.

Referenced by MakeRecoHit().

927  {
928  // MIPs for one GeV times one cell in z in NOvA scintillator
929  return 94.62;
930  }
float calib::Calibrator::GetPE ( rb::CellHit const &  ch)

Definition at line 407 of file Calibrator_service.cc.

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

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

Definition at line 432 of file Calibrator_service.cc.

References GetAdcPerPE(), and GetTNS().

433  {
434  // PE comes from the value determined as a side-effect of the timing fit,
435  // the best-fit height of the curve when t0 is at its best value.
436 
437  // Doesn't matter whether or not timing fit suceeds, good fallbacks are in
438  // place.
439  bool junk;
440  double peakadc;
441  GetTNS(dig, junk, &peakadc);
442 
443  return peakadc/GetAdcPerPE(dig);
444  }
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 401 of file Calibrator_service.cc.

References GetPE().

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

Definition at line 426 of file Calibrator_service.cc.

References GetAdcPerPE().

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

Definition at line 692 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().

694  {
695  const double attenFactor = GetAttenScale(cellhit, w);
696  if(attenFactor <= 0) return -1;
697 
698  const double driftFactor = GetDriftScale(cellhit);
699  if(driftFactor <= 0) return -1;
700 
701  // get any scale applied for systematic uncertainties as set by the
702  // input parameters
703  auto scale = this->SystematicUncertaintyScale(cellhit.View(), cellhit.Plane(), w);
704 
705  return cellhit.PE() * attenFactor * driftFactor * scale;
706  }
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 933 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().

934  {
936  chit.Plane(),
937  chit.Cell());
938  const daqchannelmap::dchan dchan = fCMap->Map()->encodeDChan(lchan);
939 
941  fCMap->Map()->getDiBlock(dchan),
942  chit.IsRealData());
943  }
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 958 of file Calibrator_service.cc.

961  {//now only for electron
962  double ecor = 5.66050e-01;//for dead material correction
963 
964  double avgx = (start.X()+stop.X())/2.;
965  double avgy = (start.Y()+stop.Y())/2.;
966  double poscor = 1.0+7.00279e-05*avgx+6.91714e-05*avgy;//for position correction
967 
968  return totalGeV/(ecor*poscor);
969  }
double calib::Calibrator::GetT ( rb::CellHit const &  cellhit,
double const &  dist_to_readout 
)

Definition at line 638 of file Calibrator_service.cc.

References rb::CellHit::TNS().

Referenced by MakeRecoHit().

639  {
640  // This needs to be calibrated and put in a DB table
641  Double_t speedOfFiberTransport = 15.3; // cm/ns, "first principles" calib.
642  // Differs from c/n due to zigzag
643  // paths down fiber. But, this
644  // value may be way off (10%? 30%?).
645  return (cellhit.TNS() - (dist_to_readout / speedOfFiberTransport) );
646  }
double calib::Calibrator::GetTimeRes ( rb::CellHit const &  cellhit)

Definition at line 709 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().

710  {
711  double pe = cellhit.PE();
712  //This is a fit for the timing resolution as a function of PE.
713  //For FD single point data this is derived by plotting the time difference between
714  //pairs of hits within a DCM on a cosmic track. More information is in docdb-11571
715 
716  double stdev = 144.0; //simple assumption of 500ns/sqrt(12)
717  //RJN more FEB4 vs FEB5
718 
719  if(getFebType(fGeom->DetId(),&cellhit)==calib::kFEB4p1) {
720  //Far detector style electronics
721  if (cellhit.GoodTiming()){
722  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
723  }
724  else {
725  stdev = 848357.0/(5734.75+pow(pe,2.20060)) + 142.221; //2014-06-13 fit, from data
726  }
727  }
728  else {
729  //Near detector style electronics
730  if (cellhit.GoodTiming()){
731  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
732  }
733  //TODO: ND single point timing resolution needs to be updated. Currently simulation and data are all in
734  //multipoint. For now take the FD singlpe point resolution and dived by 4 since the sampling is 4 times as fast
735  else {
736  stdev = 6136470.0/(185518.0+pow(pe,2.92360)) + 31.6071; //2014-09-15 singe point fit of data
737  }
738  }
739 
740  return stdev;
741 
742  }
def stdev(lst)
Definition: HandyFuncs.py:286
constexpr T pow(T x)
Definition: pow.h:72
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:94
Atom< std::string > TimingConstsCSVPath
Definition: Calibrator.h:130
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 972 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().

975  {
977  plane,
978  cell);
979  const daqchannelmap::dchan dchan = fCMap->Map()->encodeDChan(lchan);
980 
981  double offset = 0.0;
982  //check if timing offsets should be added in,
983  if (fParams.UseTimingOffsets()){
985  offset = fTimingCache->GetOffset(fCMap->Map()->getDCM(dchan),
986  fCMap->Map()->getDiBlock(dchan),
987  fCurrTimeStamp.GetSec(),
988  isData);
989  }
990 
991  return offset;
992  }
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:238
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 447 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(), string, rawdata::RawDigit::TDC(), calib::ADCShapeFitTable::TNS(), and rawdata::RawDigit::Version().

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

450  {
451  // Allows the rest of the function to assume maxadc is writeable
452  double junk;
453  if(!maxadc) maxadc = &junk;
454 
455  const int det = fGeom->DetId();
456 
457  if(dig->IsMC() &&
458  dig->Version() == 0 &&
459  dig->NADC() == 3){
460  std::cout << "Calibrator: Unable to handle old-style RawDigit" << std::endl;
461  abort();
462  }
463 
465 
466  const unsigned int nSamples = conv.getNSamples(dig->Version());
467  assert(dig->NADC() == nSamples);
468 
469 
470  const double peakToBaselineOffset = getFebType(fGeom->DetId(),dig)==calib::kFEB4p1 ? 96 : 24;
471 
472 
473  const double tns0 = (dig->TDC()-peakToBaselineOffset)*15.625;
474 
475  // Version zero means this is a single DCS point
476  if(dig->Version() == 0){
477  goodTime = false;
478  *maxadc = dig->ADC(); // Make sure this gets set reasonably
479  // Simply convert the time stored in TDC to nanoseconds
480  return tns0;
481  }
482 
483  // Otherwise we can do the timing fit
484  const unsigned int nPretrig = conv.getNPretriggeredSamples(dig->Version());
485 
486  // Need to have enough points to be able to see back to the baseline
487  assert(nPretrig >= 3);
488  // Also need enough points to see up to the peak
489  assert(nSamples >= 4);
490 
491 
492  // Create TB lookup tables (need 2 - one for each FEB version)
493  if (det == novadaq::cnv::kTESTBEAM){
494  if (!fShapeTable || !fShapeTable5TB){
495  std::string fname4;
496  std::string fname5;
497  if(dig->IsMC()){
498  fname4 = fShapeTableFilenameFDMC;
499  fname5 = fShapeTableFilenameNDMC;
500  }
501  else{
502  fname4 = fShapeTableFilenameFDData;
503  fname5 = fShapeTableFilenameNDData;
504  }
505  fShapeTable = new ADCShapeFitTable(fname4, false, dig->IsMC(), fCalibrateMode);
506  fShapeTable5TB = new ADCShapeFitTable(fname5, true, dig->IsMC(), fCalibrateMode);
507  }
508  }
509 
510  //RJN we will need to change this switch from detector type to FEB type
511  //may need to make bespoke tables for testbeam
512  // Create lookup table if required
513  if(!fShapeTable){
514  const bool isFEB5p2 = getFebType(fGeom->DetId(),dig)==calib::kFEB5p2;
516  if(isFEB5p2){
517  if(dig->IsMC()){
518  fname = fShapeTableFilenameNDMC;
519  }
520  else{
522  }
523  }
524  else{
525  if(dig->IsMC()){
526  fname = fShapeTableFilenameFDMC;
527  }
528  else{
530  }
531  }
532  fShapeTable = new ADCShapeFitTable(fname, isFEB5p2, dig->IsMC(), fCalibrateMode);
533  }
534 
535  // Figure out which sample is the baseline sample (ie the one combined
536  // with the peak in the DCS calculation).
537  const int baseIdx = nPretrig - 3;
538  double tns = -1;
539  // ShapeTable expects points in order, baseline subtracted
540  if ( det == novadaq::cnv::kTESTBEAM && getFebType(fGeom->DetId(),dig)==calib::kFEB5p2 ){
541  tns = fShapeTable5TB->TNS(tns0,
542  dig->ADC(baseIdx + 1) - dig->ADC(baseIdx),
543  dig->ADC(baseIdx + 2) - dig->ADC(baseIdx),
544  dig->ADC(baseIdx + 3) - dig->ADC(baseIdx),
545  *maxadc,
546  goodTime,
547  junk);
548  }
549  else {
550  tns = fShapeTable->TNS(tns0,
551  dig->ADC(baseIdx + 1) - dig->ADC(baseIdx),
552  dig->ADC(baseIdx + 2) - dig->ADC(baseIdx),
553  dig->ADC(baseIdx + 3) - dig->ADC(baseIdx),
554  *maxadc,
555  goodTime,
556  junk);
557  }
558  return tns;
559  }
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
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)
enum BeamMode string
rb::CellHit calib::Calibrator::MakeCellHit ( const rawdata::RawDigit rawdigit)

Definition at line 354 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().

355  {
356  // Copy of the hit that's modified to look like single-point data
357  rawdata::RawDigit digSingle = *rawdigit;
358  if(fParams.MakeSinglePointCellHits() && rawdigit->Version() != 0){
359  digSingle.SetVersion(0);
360  digSingle.fADC.clear();
361  digSingle.SetADC(0, rawdigit->ADC());
362 
363  // Rest of function uses modified hit in place of argument provided
364  rawdigit = &digSingle;
365  }
366 
367  rb::CellHit chit(*rawdigit);
368 
369  // new info
370  chit.SetCell (fCMap->GetCell(rawdigit));
371  chit.SetPlane (fCMap->GetPlane(rawdigit));
372  chit.SetView (fGeom->Plane(chit.Plane())->View());
373  bool goodTime;
374  double peakadc;
375  const double tns = GetTNS(rawdigit, goodTime, &peakadc);
376 
378  chit.Plane(),
379  chit.Cell());
380  const daqchannelmap::dchan dchan = fCMap->Map()->encodeDChan(lchan);
381 
382  //check if timing offsets should be added in,
383  if (fParams.UseTimingOffsets()){
385  const double offset = fTimingCache->GetOffset(fCMap->Map()->getDCM(dchan),
386  fCMap->Map()->getDiBlock(dchan),
387  fCurrTimeStamp.GetSec(),
388  chit.IsRealData());
389  chit.SetTNS(tns+offset, goodTime);
390  }
391  else{
392  chit.SetTNS(tns, goodTime);
393  }
394 
395  chit.SetPE(GetPE(rawdigit, peakadc));
396 
397  return chit;
398  }
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:234
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
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:238
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 568 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().

570  {
571  Double_t xyzd[4];
572  GetXYZD(cellhit.OfflineChan(), w, xyzd);
573  return MakeRecoHit(cellhit, w, xyzd);
574  }
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 577 of file Calibrator_service.cc.

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

579  {
580  double w = xyz[0];
581  if(cellhit.View() == geo::kX) w = xyz[1];
582 
583  return MakeRecoHit(cellhit, w, xyz);
584  }
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 588 of file Calibrator_service.cc.

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

591  {
592  rb::RecoHit rhit;
593 
594  rhit.SetX(xyz[0]);
595  rhit.SetY(xyz[1]);
596  rhit.SetZ(xyz[2]);
597 
598  rhit.SetT(GetT(chit, xyz[3]));
599 
600  // Set hit up uncalibrated in case we don't fill it below
601  rhit.SetPECorr(-1);
602  rhit.SetMIP (-1);
603  rhit.SetGeV (-1);
604 
605  if(std::isnan(w)){
606  MF_LOG_ERROR("Calibrator")
607  << "W position provided is NaN. This hit will be uncalibrated.";
608  }
609 
610  const double peCorr = std::isnan(w) ? -1 : GetPECorr(chit, w);
611 
612  assert(!std::isnan(peCorr));
613  assert(!std::isinf(peCorr));
614 
615  if(peCorr > 0){
616  rhit.SetPECorr(peCorr);
617  const double gevPerPECorr = GetPECorrToGeVScale(chit);
618  if(gevPerPECorr > 0){
619  const double gev = peCorr * gevPerPECorr;
620  rhit.SetGeV(gev);
621  rhit.SetMIP(gev * GetGeVToMIPScale(chit));
623  }
624  else{
625  // Uncalibrated
626  rhit.SetPECorr(-1);
628  }
629  }
630  else{
632  }
633 
634  return rhit;
635  }
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
#define MF_LOG_ERROR(category)
void SetT(float T)
Definition: RecoHit.h:48
double GetGeVToMIPScale(rb::CellHit const &cellhit)
For GeV->MIP conversion.
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
void calib::Calibrator::postBeginRun ( art::Run const &  run)

Definition at line 175 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::DataViewImpl::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(), string, 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().

176  {
177  fAbsCache->Reinit();
178 
179  // New run. We need to update the TimingCache VldTime. But don't do it
180  // until someone actually accesses TimingCache, just make a note. Avoids
181  // accessing RunHistory when we don't have to, especially in case of
182  // generation jobs where it will actually fail.
183  fTimingCacheVldTimeSet = false;
184  fCurrentRun=run.run();
185 
187  mf::LogInfo("Calibrator") << "Cacheing MC attenuation correction for each of "
189  << " fiber brightness bins.";
190 
196  if( fAttenCacheData->UseEpochs() ) {
198  fAttenCacheData->SetEpoch(" ");
199  }
200  //RJN addition to avoid epoch reading
203 
204  // Initialize MC AttenCaches, indexed by
205  // fiber brightness if brightness is modeled.
206  bool AttenCacheMCEmpty = fAttenCacheMC.empty();
207  for(size_t b=0; b<fFibBrightness->NumberBrightnessBins(); b++){
208 
209  // Initialize AttenCaches only in the first postBeginRun...
210  // done in postBeginRun so number of brightness bins known
211  if(AttenCacheMCEmpty){
212 
213  // when brightness is not modelled, let AttenCache know with -1
215  fAttenCacheMC.emplace_back(new AttenCache(false, -1)); // not data, no bin number
216  else
217  fAttenCacheMC.emplace_back(new AttenCache(false, int(b))); // not data, bin b
218 
219  fAttenCacheMC[b]->SetTag ( fTag );
220  fAttenCacheMC[b]->SetUseEpochs ( fParams.UseAttenEpochs() );
221  fAttenCacheMC[b]->SetEpochTag ( fParams.AttenEpochTag() );
222  fAttenCacheMC[b]->UseCSVsFromUPS ( fParams.UseCSVsFromUPS() );
223  fAttenCacheMC[b]->SetCSVSource ( fParams.AttenCSVPath() );
224  fAttenCacheMC[b]->ReadEpochsFromCSV( fParams.ReadEpochsFromCSV() );
225  }
226 
227  // ...but do reinit and set run/epoch every run
228  if( fAttenCacheMC[b]->UseEpochs() ) {
229  fAttenCacheMC[b]->SetRun(fCurrentRun);
230  fAttenCacheMC[b]->SetEpoch(" ");
231  }
232  fAttenCacheMC[b]->Reinit();
233  } // every bin
234 
235 
236  if (fParams.UseDrift()) {
237  // using RunHistory to set validity time range for drift correction
239  int runNum = rh->RunNumber();
240  // load from either CSV or DB
242  }
243 
244 
245  if (fAbsCache->UseEpochs()) {
247  fAbsCache->SetEpoch(" ");
248  }
249 
250  if (fTimingCache->UseEpochs()) {
252  fTimingCache->SetEpoch(" ");
253  }
254 
257  int gainSetting = rh->DetGainSetting();
258  if (fParams.UseGainSetting4Abs() &&
259  (gainSetting != fAbsCache->GainSetting())) {
260  fAbsCache->Reinit();
261  fAbsCache->SetGainSetting(gainSetting);
262  }
263  // reinit MC cahces
264  for(size_t b=0; b<fAttenCacheMC.size(); b++){
266  (gainSetting != fAttenCacheMC[b]->GainSetting())) {
267  fAttenCacheMC[b]->Reinit();
268  fAttenCacheMC[b]->SetGainSetting(gainSetting);
269  }
270  } // for each brightness bin
271 
272  // reinit data cache
274  (gainSetting != fAttenCacheData->GainSetting())) {
276  fAttenCacheData->SetGainSetting(gainSetting);
277  }
278  }
279 
280 
282  if(fGain < 0) // Signal to look in the DB
283  fGain = rh->DetGainSetting();
284 
285  if(fGain <= 0) { // something's not right
286  std::cerr << "Failed to get gain from DB. Aborting" << std::endl;
287  abort();
288  }
289 
290 
291  // Get the right functional form based off of gain
292  std::string XFunctionForm, XMuCFunctionForm, YFunctionForm;
293  std::vector<double> XFunctionParams, XMuCFunctionParams, YFunctionParams;
294  if( fGain==100 ){
295  XFunctionForm = fParams.Xg100FunctionForm();
296  XFunctionParams = fParams.Xg100FunctionParams();
297  YFunctionForm = fParams.Yg100FunctionForm();
298  YFunctionParams = fParams.Yg100FunctionParams();
299  }
300  else if( fGain==140 ){
301  XFunctionForm = fParams.Xg140FunctionForm();
302  XFunctionParams = fParams.Xg140FunctionParams();
303  YFunctionForm = fParams.Yg140FunctionForm();
304  YFunctionParams = fParams.Yg140FunctionParams();
305  }
306  else if( fParams.UseXFunction() || fParams.UseYFunction() ){
307  std::cerr << "Unexpected gain, no shape functions, aborting" << std::endl;
308  abort();
309  }
311  if( fGain==100 ){
312  XMuCFunctionForm = fParams.XMuCg100FunctionForm();
313  XMuCFunctionParams = fParams.XMuCg100FunctionParams();
314  } else {
315  std::cerr << "Unexpected gain in ND, no shape functions, aborting" << std::endl;
316  abort();
317  }
318  }
319 
320  // Initialize PECorr shift functions if configured
321  if (fParams.UseXFunction()){
322  fXFunction = new TF1("x_function", XFunctionForm.c_str(), -900, 900);
324  for (size_t i = 0; i < XFunctionParams.size(); ++i){
325  fXFunction->SetParameter(i, XFunctionParams[i]);
326  }
327 
328  // shift Muon Catcher separately if nonempty MuC function string
329  if(XMuCFunctionForm!=""){
330  fXMuCFunction = new TF1("x_mc_function", XMuCFunctionForm.c_str(), -900, 900);
332  for (size_t i = 0; i < XMuCFunctionParams.size(); ++i){
333  fXMuCFunction->SetParameter(i, XMuCFunctionParams[i]);
334  }
335  }
336 
337  }
338  if (fParams.UseYFunction()){
339  fYFunction = new TF1("y_function", YFunctionForm.c_str(), -900, 900);
341  for (size_t i = 0; i < YFunctionParams.size(); ++i){
342  fYFunction->SetParameter(i, YFunctionParams[i]);
343  }
344  }
345 
346  } // 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:206
void SetRun(int detector, int run)
Definition: DriftCache.cxx:62
TimingCache * fTimingCache
Definition: Calibrator.h:412
Atom< std::string > Yg100FunctionForm
Definition: Calibrator.h:182
Atom< bool > UseGainSetting4Atten
Definition: Calibrator.h:158
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:178
int GainSetting()
Definition: AbsCache.h:33
Atom< std::string > AttenEpochTag
Definition: Calibrator.h:90
DriftCache * fDriftCache
Definition: Calibrator.h:410
unsigned int NumberBrightnessBins() const
Atom< bool > UseCSVsFromUPS
Definition: Calibrator.h:94
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:98
Atom< bool > UseDrift
Definition: Calibrator.h:134
Sequence< double > XMuCg100FunctionParams
Definition: Calibrator.h:198
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:166
bool UseEpochs()
Definition: AbsCache.h:45
Near Detector in the NuMI cavern.
Atom< bool > UseAttenEpochs
Definition: Calibrator.h:86
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:154
Atom< std::string > Xg140FunctionForm
Definition: Calibrator.h:186
AbsCache * fAbsCache
Definition: Calibrator.h:411
std::string fTag
Definition: Calibrator.h:433
void SetEpoch(const std::string &epoch)
Definition: AttenCache.h:48
Atom< std::string > Xg100FunctionForm
Definition: Calibrator.h:174
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:202
art::ServiceHandle< photrans::FiberBrightness > fFibBrightness
Definition: Calibrator.h:445
AttenCache * fAttenCacheData
Data attenutation corrections.
Definition: Calibrator.h:408
Atom< bool > ReadEpochsFromCSV
Definition: Calibrator.h:106
Atom< bool > UseYFunction
Definition: Calibrator.h:170
Atom< std::string > Yg140FunctionForm
Definition: Calibrator.h:190
Sequence< double > Yg140FunctionParams
Definition: Calibrator.h:210
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:194
int RunNumber() const
Definition: RunHistory.h:374
void SetUseEpochs(bool b)
Definition: AttenCache.h:44
enum BeamMode string
void calib::Calibrator::preEvent ( art::Event const &  evt,
art::ScheduleContext   
)

Definition at line 159 of file Calibrator_service.cc.

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

Referenced by Calibrator().

160  {
161  // use the art::Timestamp to create the fCurrTrimeStamp value
162  unsigned long long int tsval = evt.time().value();
163 
164  // taking it apart
165  // the masking isn't strictly necessary *if* "long" is truly 32bits
166  // but this can vary w/ compiler/platform
167  const unsigned long int mask32 = 0xFFFFFFFFUL;
168  time_t lup = ( tsval >> 32 ) & mask32;
169  int llo = tsval & mask32;
170  TTimeStamp tts(lup, llo);
171  fCurrTimeStamp = tts;
172  }
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 649 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().

652  {
653  double scale = 1.0;
654 
655  // scaling in the X view
656  if(view == geo::kX && fParams.UseXFunction()){
657 
658  //RJN this will do the wrong thing for the TestBeam.... but who cares
659  // if there is a seperate muon catcher function, use it
660  if( fXMuCFunction &&
663  scale *= fXMuCFunction->Eval(w);
664  }
665  else {
666  scale *= fXFunction->Eval(w);
667  }
668  }
669 
670  // scaling in the Y view
671  if(view == geo::kY && fParams.UseYFunction()) scale *= fYFunction->Eval(w);
672 
673  // if simulating detector drift
674  if (fParams.SimulateDrift()) {
676  int time = rh->TStart() + (0.5*rh->Duration()); // set to midpoint of run;
677  double yDiff = 3.17098e-8 * (time - fParams.DriftReference()); // Amount of drift in years
678  //std::cout << "Drifting " << yDiff << " years with respect to nominal." << std::endl;
679  double drift = 1 - (fParams.DriftGradient()*yDiff);
680  double calCorrection = 1/drift;
681  //std::cout << "Calculated drift of " << drift
682  // << " from nominal, with inverse shift " << calCorrection
683  // << " applied to calibration. Scale corrected from " << scale << " to ";
684  scale *= calCorrection;
685  //std::cout << scale << std::endl;
686  }
687 
688  return scale;
689  }
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:242
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:166
Near Detector in the NuMI cavern.
int Duration()
in units of seconds
Definition: RunHistory.h:389
Atom< int > DriftReference
Definition: Calibrator.h:246
CalibratorParams fParams
Definition: Calibrator.h:392
Atom< double > DriftGradient
Definition: Calibrator.h:250
Atom< bool > UseYFunction
Definition: Calibrator.h:170
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: