Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
calib::AttenCurve Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-10-23/Calibrator/func/AttenCurve.h"

Classes

struct  Pt
 

Public Member Functions

float MeanPEPerCmAt (double w) const
 Mean response of this channel at this distance from detector centre. More...
 
float MeanPEPerCmAt (double w, std::string version) const
 
bool IsCalibrated () const
 
void AddInterpPoint (float w, float factor)
 
void WriteToCSVs (FILE *fConsts, FILE *fPoints, bool mc) const
 

Static Public Member Functions

static AttenCurveUninitialized (int det, geo::OfflineChan chan)
 Return a new AttenCurve objects with fields uninitialized. More...
 

Public Attributes

std::vector< Ptinterp_pts
 
float atten_length
 
float coeff_exp
 
float background
 
float edge_low
 
float edge_high
 
float coeff_low
 
float coeff_high
 
float chisq
 
float cell_length
 
float center_offset
 Nonzero in short muon-catcher cells. Positive is closer to readout. More...
 
int det
 
geo::OfflineChan chan
 
bool initialized
 

Protected Member Functions

 AttenCurve ()
 

Detailed Description

Definition at line 18 of file AttenCurve.h.

Constructor & Destructor Documentation

calib::AttenCurve::AttenCurve ( )
inlineprotected

Definition at line 57 of file AttenCurve.h.

References calib::operator<<().

Referenced by Uninitialized().

57 {}

Member Function Documentation

void calib::AttenCurve::AddInterpPoint ( float  w,
float  factor 
)

Definition at line 122 of file AttenCurve.cxx.

References interp_pts, gen_flatrecord::pt, and w.

Referenced by calib::AttenFit::lowessFit(), and calib::AttenuationFit::lowessFit().

123  {
124  Pt pt = {w, factor};
125  interp_pts.push_back(pt);
126  }
Float_t w
Definition: plot.C:20
std::vector< Pt > interp_pts
Definition: AttenCurve.h:43
bool calib::AttenCurve::IsCalibrated ( ) const

Definition at line 97 of file AttenCurve.cxx.

References chisq.

Referenced by calib::Calibrator::GetAttenCurve().

98  {
99  // This isn't actually a chisq, but more an average fractional deviation of
100  // the fit from the data. 0.2 is the eyeballed position of the tails of the
101  // distribution in FD data.
102  return chisq >= 0 && chisq < 0.2;
103 
104  // Checking the LOWESS points is another way to achieve something
105  // similar. But this implementation tends to give to much weight to
106  // problems that only occur in single locations.
107 
108  // for(unsigned int n = 0; n < interp_pts.size(); ++n){
109  // // Don't let the interpolated corrections pull more than 15% off the
110  // // original fit. 15% is arbitrary, based on a desire to calibrate a
111  // // reasonable number of channels.
112  // if(fabs(interp_pts[n].factor-1) > .15){
113  // // Don't count interpolations where just the final point is off as bad
114  // if(n > 0 && n < interp_pts.size()-1)
115  // return false;
116  // }
117  // }
118  // return true;
119  }
float calib::AttenCurve::MeanPEPerCmAt ( double  w) const

Mean response of this channel at this distance from detector centre.

Definition at line 37 of file AttenCurve.cxx.

Referenced by calib::FindOutliers::endRun(), calib::AttenFit::fit_channel_prof(), calib::AttenuationFit::fit_channel_prof(), and calib::Calibrator::GetAttenScale().

38  {
39  return MeanPEPerCmAt(w,"");
40  }
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
float calib::AttenCurve::MeanPEPerCmAt ( double  w,
std::string  version 
) const

Definition at line 43 of file AttenCurve.cxx.

References ana::assert(), atten_length, background, cell_length, coeff_exp, coeff_high, coeff_low, edge_high, edge_low, stan::math::exp(), calib::FOURTH(), initialized, interp_pts, w, and y1.

44  {
46 
47  //Now check just once in Calibrator instead
48  //if(!IsCalibrated()) return -1;
49 
50  // TODO: take account of center_offset here for muon catcher planes. Need
51  // to fix the todo below at the same time.
52 
53  //The attenuation formulae has a minor correction relative to tag v6 and earlier.
54  //Backwards compatibility is ensured in calibrator by passing the tag version to
55  //this function. Users can also call this function directly without specifying a
56  //tag in which case they get the latest, corrected, version of the attenuation
57  //formulae.
58 
59  // Distance to travel the long way round the fibre
60  double wlong;
61  if(version=="v1"||version=="v2"||version=="v3"||version=="v3.1"||version=="v4"||version=="v5"||version=="v5.1"||version=="v6"){
62  wlong = 1.5*cell_length+w;
63  }
64  else{
65  wlong = cell_length+w;
66  }
67 
68  const double expPart = coeff_exp*(exp(w/atten_length)+
69  exp(-wlong/atten_length))+background;
70 
71  double edgePart = 1;
72  if(w < -edge_low) edgePart -= coeff_low *FOURTH(w+edge_low);
73  if(w > edge_high) edgePart -= coeff_high*FOURTH(w-edge_high);
74 
75  double interpPart = 1;
76  if(interp_pts.size() >= 2){
77  typedef std::vector<Pt>::const_iterator it_t;
78 
79  // Find the point after w
80  it_t itNext = std::lower_bound(interp_pts.begin(), interp_pts.end(), w);
81  if(itNext == interp_pts.end()) --itNext;
82  if(itNext == interp_pts.begin()) ++itNext;
83  // And the point before
84  it_t itPrev = itNext; --itPrev;
85 
86  // Interpolate
87  const double w0 = itPrev->w; const double y0 = itPrev->factor;
88  const double w1 = itNext->w; const double y1 = itNext->factor;
89 
90  interpPart = ((w1-w)*y0+(w-w0)*y1)/(w1-w0);
91  }
92 
93  return expPart*edgePart*interpPart;
94  }
T FOURTH(T x)
Definition: AttenCurve.cxx:35
Float_t y1[n_points_granero]
Definition: compare.C:5
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
const XML_Char * version
Definition: expat.h:187
assert(nhit_max >=nhit_nbins)
Float_t w
Definition: plot.C:20
std::vector< Pt > interp_pts
Definition: AttenCurve.h:43
AttenCurve * calib::AttenCurve::Uninitialized ( int  det,
geo::OfflineChan  chan 
)
static

Return a new AttenCurve objects with fields uninitialized.

Definition at line 25 of file AttenCurve.cxx.

References AttenCurve(), center_offset, chan, det, and initialized.

Referenced by calib::AttenFit::endJob(), calib::AttenCache::LoadFromDatabase(), and calib::AttenuationFit::writeResults().

26  {
27  AttenCurve* res = new AttenCurve;
28  res->det = det;
29  res->chan = chan;
30  res->initialized = false;
31  res->center_offset = 0;
32  return res;
33  }
geo::OfflineChan chan
Definition: AttenCurve.h:53
void calib::AttenCurve::WriteToCSVs ( FILE *  fConsts,
FILE *  fPoints,
bool  mc 
) const

Definition at line 129 of file AttenCurve.cxx.

References ana::assert(), atten_length, background, chan, chisq, coeff_exp, coeff_high, coeff_low, edge_high, edge_low, initialized, interp_pts, getGoodRuns4SAM::n, geo::OfflineChan::ToDBValidityChan(), and w.

Referenced by calib::AttenFit::endJob(), and calib::AttenuationFit::writeResults().

130  {
131  const int vldTime = 1; // 1970
132 
133 
135  fprintf(fConsts, "%g,%g,%g,%g,%g,%g,%g,%g,%d,%d\n",
138  chan.ToDBValidityChan(), vldTime);
139 
140  const int N = interp_pts.size();
141  for(int n = 0; n < N; ++n){
142  fprintf(fPoints, "%g,%g,%d,%d\n",
143  interp_pts[n].w, interp_pts[n].factor,
144  1000*chan.ToDBValidityChan()+n, vldTime);
145  }
146  }
int ToDBValidityChan() const
Definition: OfflineChan.cxx:19
geo::OfflineChan chan
Definition: AttenCurve.h:53
assert(nhit_max >=nhit_nbins)
Float_t w
Definition: plot.C:20
std::vector< Pt > interp_pts
Definition: AttenCurve.h:43

Member Data Documentation

float calib::AttenCurve::atten_length
float calib::AttenCurve::background
float calib::AttenCurve::cell_length
float calib::AttenCurve::center_offset

Nonzero in short muon-catcher cells. Positive is closer to readout.

Definition at line 51 of file AttenCurve.h.

Referenced by calib::AttenCache::LoadFromDatabase(), and Uninitialized().

geo::OfflineChan calib::AttenCurve::chan
float calib::AttenCurve::chisq
float calib::AttenCurve::coeff_exp
float calib::AttenCurve::coeff_high
float calib::AttenCurve::coeff_low
int calib::AttenCurve::det

Definition at line 52 of file AttenCurve.h.

Referenced by calib::AttenCache::Add(), calib::operator<<(), and Uninitialized().

float calib::AttenCurve::edge_high
float calib::AttenCurve::edge_low
bool calib::AttenCurve::initialized
std::vector<Pt> calib::AttenCurve::interp_pts

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