#include <CalVaLinearity.h>
Inheritance diagram for CalVaLinearity:

Public Member Functions | |
| CalVaLinearity () | |
| CalVaLinearity (const RawChannelId &rcid, Float_t param[kPMAX]) | |
| CalVaLinearity (UInt_t index, Float_t param[kPMAX]) | |
| CalVaLinearity (const RawChannelId &rcid, Double_t p0=0, Double_t p1=0, Double_t p2=0, Double_t p3=0, Double_t p4=0) | |
| virtual | ~CalVaLinearity () |
| Bool_t | CanL2Cache () const |
| UInt_t | GetIndex (UInt_t) const |
| void | GetParam (Double_t p[kPMAX]) const |
| RawChannelId | GetRawChannelId () const |
| UInt_t | GetVAChannel () const |
| Double_t | Linearize (const Double_t adc) const |
| Double_t | UnLinearize (const Double_t linearAdc) const |
| virtual DbiTableRow * | CreateTableRow () const |
| virtual void | Fill (DbiResultSet &rs, const DbiValidityRec *vrec) |
| virtual void | Store (DbiOutRowStream &ors, const DbiValidityRec *vrec) const |
Static Public Member Functions | |
| Double_t | FitFunction (Double_t *arg, Double_t *par) |
| UInt_t | Rcid2Index (const RawChannelId &rcid) |
| RawChannelId | Index2Rcid (Int_t index) |
Private Types | |
| enum | { kPMAX = 8 } |
Private Member Functions | |
| CalVaLinearity (const CalVaLinearity &from) | |
Static Private Member Functions | |
| Int_t | CheckParameters (Double_t *par) |
| Double_t | Pole (Double_t x, Double_t k1, Double_t k2, Double_t sign) |
Private Attributes | |
| Double_t | fParam [kPMAX] |
| UInt_t | fVAChannel |
|
|
Definition at line 25 of file CalVaLinearity.h. 00025 { kPMAX = 8 }; // Total number of parameters to fit function
|
|
|
Definition at line 29 of file CalVaLinearity.h. 00029 { LEA_CTOR; }
|
|
||||||||||||
|
Definition at line 30 of file CalVaLinearity.h. References fParam, fVAChannel, and Rcid2Index(). 00030 {
00031 fVAChannel = Rcid2Index(rcid);
00032 for (int i=0; i<kPMAX; i++) fParam[i] = param[i];
00033
00034 LEA_CTOR;
00035 }
|
|
||||||||||||
|
Definition at line 36 of file CalVaLinearity.h. References fParam, and fVAChannel. 00036 {
00037 fVAChannel = index;
00038 for (int i=0; i<kPMAX; i++) fParam[i] = param[i];
00039 LEA_CTOR;
00040 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 42 of file CalVaLinearity.h. References fParam, fVAChannel, and Rcid2Index(). 00042 {
00043 fVAChannel = Rcid2Index(rcid);
00044 fParam[0]=p0; fParam[1]=p1; fParam[2]=p2; fParam[3]=p3; fParam[4]=p4;
00045 LEA_CTOR;
00046 }
|
|
|
Definition at line 49 of file CalVaLinearity.h. 00049 { LEA_DTOR; };
|
|
|
Definition at line 76 of file CalVaLinearity.h. 00077 : DbiTableRow(from) { LEA_CTOR; *this = from; }
|
|
|
Reimplemented from DbiTableRow. Definition at line 52 of file CalVaLinearity.h. 00052 { return kTRUE; }
|
|
|
|
|
|
Implements DbiTableRow. Definition at line 61 of file CalVaLinearity.h. 00061 { return new CalVaLinearity; }
|
|
||||||||||||
|
Implements DbiTableRow. Definition at line 71 of file CalVaLinearity.cxx. References DbiRowStream::CurColName(), fParam, fVAChannel, DbiRowStream::HasRowCounter(), DbiRowStream::IncrementCurCol(), MSG, DbiRowStream::NumCols(), and DbiRowStream::TableName(). 00072 {
00073 // Purpose: Fill object from Result Set
00074 //
00075 // Arguments:
00076 // rs in Result Set used to fill object
00077 // vrec in Associated validity record (or 0 if filling
00078 // DbiValidityRec)
00079 // o Fill object from current row of Result Set.
00080
00081 // Program Notes
00082 // Following the template from which this was copied, this method demonstrates
00083 // both the "dumb" fill method (just load the data as it comes) and the smart
00084 // method (check column name and load according to column order). The smart method
00085 // has been 'enhanced' to include a check that all the columns got filled. It will
00086 // go kFatal if we don't because we are heading for a divide by zero if some are
00087 // incorrect.
00088
00089 if ( rs.TableName() == "CALVALINEARITY" ) {
00090 // Dumb method.
00091 rs >> fVAChannel >> fParam[0]
00092 >> fParam[1] >> fParam[2] >> fParam[3] >> fParam[4] >> fParam[5];
00093 fParam[6] = 0.;
00094 fParam[7] = 1.;
00095 } else {
00096 // Smart method
00097 Int_t numCol = rs.NumCols();
00098 fVAChannel = 0;
00099
00100 // The first column (SeqNo) has already been processed.
00101 for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00102 string colName = rs.CurColName();
00103 if ( colName == "VACHANNEL" ) rs >> fVAChannel;
00104 else if( colName == "FSEL" ) rs >> fParam[0];
00105 else if( colName == "PARAM1" ) rs >> fParam[1];
00106 else if( colName == "PARAM2" ) rs >> fParam[2];
00107 else if( colName == "PARAM3" ) rs >> fParam[3];
00108 else if( colName == "PARAM4" ) rs >> fParam[4];
00109 else if( colName == "PARAM5" ) rs >> fParam[5];
00110 else {
00111 MSG("Dbi",Msg::kDebug) << "Ignoring column " << curCol
00112 << "(" << colName << ")"
00113 << "; not part of CalVaLinearity"
00114 << endl;
00115 rs.IncrementCurCol();
00116 } // colname if
00117 } // for
00118 } // if/else
00119 }
|
|
||||||||||||
|
Definition at line 162 of file CalVaLinearity.cxx. References Pole(). Referenced by PulserGainFit::Fit(), PulserLinearityCalScheme::GetCorrected(), Linearize(), PulserGainFit::RunNearFarFits(), and UnLinearize(). 00163 {
00164 // Static function to fit linearity response of PIN channels
00165 // This is used by the VALinearityConstantMaker package
00166 // as well as the Calibrator package.
00167
00168 double x = *arg;
00169 double dtype = par[0];
00170 int type = static_cast<int>(dtype+0.1);
00171 double k1 = par[1];
00172 double k2 = par[2];
00173 double k3 = par[3];
00174 double k4 = par[4];
00175 // double k5 = par[5];
00176 double ped = par[6];
00177 double gain = par[7];
00178
00179 // **************************************************************************
00180 // **** Pole with adjustable power and one variable high end pole kicker ****
00181 // **************************************************************************
00182
00183 if (x < 0.1) return x; // Do not linearise negative values
00184
00185 if (type == 24) {
00186 double x1 = x;
00187 x1 = ped + x1 * gain ;
00188 x1 = Pole(x1,k1,k2,-1.);
00189 if ((x1-k3) > 0) { // High end kicker function
00190 x1 = (x1 - k3)/(1. - (x1-k3)/k4) + k3;
00191 }
00192 return x1;
00193 }
00194 else if (type == 25) { // Non-inverted function
00195 double x1 = x;
00196 if ((x1-k3) > 0) { // High end kicker function
00197 x1 = (x1 - k3)/(1. + (x1-k3)/k4) + k3;
00198 }
00199 x1 = Pole(x1,k1,k2,+1.);
00200 x1 = (x1-ped)/gain ;
00201 return x1;
00202 }
00203
00204 // **************************************************************************
00205 // Pole with adjustable power, no kicker
00206 // **************************************************************************
00207
00208 else if (type == 4) {
00209 double x1 = x;
00210 x1 = ped + x1 * gain ;
00211 x1 = Pole(x1,k1,k2,-1.);
00212 return x1;
00213 }
00214 else if (type == 5) { // Non-inverted function
00215 double x1 = x;
00216 x1 = Pole(x1,k1,k2,+1.);
00217 x1 = (x1-ped)/gain ;
00218 return x1;
00219 // printf("f %g %g %g %g\n",result,x,k1,k2);
00220 }
00221
00222 // **************************************************************************
00223 // Straight line conversion (used for fitting, not for linearization)
00224 // **************************************************************************
00225
00226 else if (type == 0) {
00227 return ped + x * gain ;
00228 }
00229 else if (type == 1) {
00230 return (x-ped)/gain;
00231 }
00232
00233 // **************************************************************************
00234 // Remedial functions
00235 // **************************************************************************
00236
00237 else if (type == 10) {
00238 return x; // Straight line y = x function
00239 }
00240 else if (type == 12) {
00241 return 0.; // Dead channel function
00242 }
00243 else if (type == 14) {
00244 return k1; // Saturated on main Pole
00245 }
00246 else if (type == 16) {
00247 return 1.e7; // Infinity
00248 }
00249
00250 return x; // Default (last resort) is to return y=x function
00251 }
|
|
|
Reimplemented from DbiTableRow. Definition at line 53 of file CalVaLinearity.h. 00053 { return fVAChannel; }
|
|
|
Definition at line 54 of file CalVaLinearity.h. References fParam. 00054 {
00055 for (int i=0; i<kPMAX; i++) p[i] = fParam[i]; }
|
|
|
Definition at line 56 of file CalVaLinearity.h. References fVAChannel, and Index2Rcid(). 00056 { return Index2Rcid(fVAChannel); }
|
|
|
Definition at line 57 of file CalVaLinearity.h. 00057 { return fVAChannel; }
|
|
|
Definition at line 146 of file CalVaLinearity.cxx. Referenced by GetRawChannelId(). 00147 {
00148 // This static function produces a RawChannelId object from a channel index
00149 // The pedmode, sparsemode, commonmode bits are set to zero (by default)
00150 UInt_t crate = (index>>24)&0xf;
00151 UInt_t varc = (index>>20)&0xf;
00152 UInt_t vmm = (index>>16)&0xf;
00153 UInt_t vfb = (index>>12)&0xf;
00154 UInt_t va = (index>> 8)&0xf;
00155 UInt_t ch = (index>> 0)&0xff;
00156
00157 return RawChannelId(Detector::kFar
00158 ,ElecType::kVA
00159 ,crate,varc,vmm,vfb,va,ch);
00160 }
|
|
|
Definition at line 37 of file CalVaLinearity.cxx. References FitFunction(). Referenced by LILinResp::GetLinearity(), and VaLinearityCalScheme::GetLinearizedVA(). 00038 {
00039 // From raw VA adc value to linearaized VA adc value. For data correction
00040 Double_t arg[1];
00041 Double_t par[8];
00042
00043 arg[0] = adc;
00044
00045 for (Int_t i=0; i<6; i++) par[i] = fParam[i];
00046 par[6] = 0.; // Internal Pedestal
00047 par[7] = 1.; // Internal Gain
00048
00049 // par[0] is the function select (normally 4 or 24)
00050
00051 return CalVaLinearity::FitFunction(arg,par);
00052 }
|
|
||||||||||||||||||||
|
Definition at line 253 of file CalVaLinearity.cxx. Referenced by FitFunction(). 00255 {
00256 // Local function to do the pole calculation. sign is either +1 or -1
00257 // depending on wheter the function is in use for the inverse or not.
00258
00259 // The function implemented is
00260 // x1 = x / (1 + (x1/k1)**k2 ) ** (1./k2)
00261
00262 Double_t x1 = x;
00263 if (k1 <= 500.) { // Function is flatline [was if (k1<=0.)]
00264 x1 = 0.;
00265 } else if (sign <= 0. && k1 <= x1) { // Above pole: make function 'flatline'
00266 x1 = 0.;
00267 } else if (x1 < 0.1) { // Don't modify (x=y when x is negative)
00268 } else if (k2 <= 0.1) { // don't modify with negative power [was if (k2<=0.)]
00269 } else {
00270 Double_t a = k2*log(x1/k1); // Not negative log, both x1 and k1 checked
00271 if (a > 228.) {
00272 if (sign < 0.) { // Only happens when sign positive (print if not)
00273 //printf("pole:s x1 %g k1 %g k2 %g sign %g\n",x1,k1,k2,sign);
00274 x1 = k1;
00275 }
00276 } else { // Should not overflow exp()
00277 Double_t b = pow(1. + sign * exp(a), 1./k2);
00278 if (b > 1.0e-20) { // OK
00279 x1 = x1 / b;
00280 } else { // Very close to pole
00281 x1 = x1*1.0e20;
00282 }
00283 }
00284 }
00285 return x1;
00286 }
|
|
|
Definition at line 135 of file CalVaLinearity.cxx. References RawChannelId::GetCrate(), RawChannelId::GetDetector(), RawChannelId::GetVaAdcSel(), RawChannelId::GetVaChannel(), RawChannelId::GetVaChip(), RawChannelId::GetVarcId(), and RawChannelId::GetVmm(). Referenced by CalVaLinearity(), VaLinearityCalScheme::DecalVALinearity(), and VaLinearityCalScheme::GetLinearizedVA(). 00136 {
00137 // This static function produces a channel index (used by the database)
00138 // from a raw channel ID
00139 return
00140 ( rcid.GetDetector() <<28) |
00141 ( rcid.GetCrate() <<24) | ( rcid.GetVarcId() <<20) |
00142 ( rcid.GetVmm() <<16) | ( rcid.GetVaAdcSel() <<12) |
00143 ( rcid.GetVaChip() << 8) | ( rcid.GetVaChannel()<< 0);
00144 }
|
|
||||||||||||
|
Reimplemented from DbiTableRow. Definition at line 122 of file CalVaLinearity.cxx. References fParam, and fVAChannel. 00123 {
00124 //
00125 // Purpose: Stream object to output row stream
00126 //
00127 // Arguments:
00128 // ors in Output row stream.
00129 // vrec in Associated validity record (or 0 if filling
00130
00131 ors << fVAChannel << fParam[0]
00132 << fParam[1] << fParam[2] << fParam[3] << fParam[4] << fParam[5];
00133 }
|
|
|
Definition at line 54 of file CalVaLinearity.cxx. References FitFunction(), and fParam. Referenced by VaLinearityCalScheme::DecalVALinearity(), and SimVaElectronics::GenSimulatedADC(). 00055 {
00056 // From linearized VA adc to raw adc (i.e. add the saturation in). For MC
00057 Double_t arg[1];
00058 Double_t par[8];
00059
00060 arg[0] = linearAdc;
00061
00062 for (Int_t i=0; i<6; i++) par[i] = fParam[i];
00063 par[6] = 0.; // Internal Pedestal
00064 par[7] = 1.; // Internal Gain
00065
00066 par[0] = par[0] + 1; // 5 or 25 is the inverse
00067
00068 return CalVaLinearity::FitFunction(arg,par);
00069 }
|
|
|
Definition at line 84 of file CalVaLinearity.h. Referenced by CalVaLinearity(), Fill(), GetParam(), Store(), and UnLinearize(). |
|
|
Definition at line 85 of file CalVaLinearity.h. Referenced by CalVaLinearity(), Fill(), GetRawChannelId(), and Store(). |
1.3.9.1