Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PulserSigLinCalScheme.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PulserSigLinCalScheme.cxx,v 1.14 2006/04/19 18:50:38 rhatcher Exp $
00003 //
00004 // Prototype PE gain Calibrator class
00005 //
00006 // rjn@hep.ucl.ac.uk
00008 #include "Calibrator/PulserSigLinCalScheme.h"
00009 #include "Calibrator.h"
00010 #include "MessageService/MsgService.h"
00011 #include "Plex/PlexSEIdAltL.h"
00012 #include "Plex/PlexStripEndId.h"
00013 #include "Plex/PlexPinDiodeId.h"
00014 #include "Plex/PlexHandle.h"
00015 #include "DatabaseInterface/DbiValidityRec.h"
00016 #include "Validity/VldRange.h"
00017 
00018 ClassImp(PulserSigLinCalScheme)
00019 CVSID("$Id: PulserSigLinCalScheme.cxx,v 1.14 2006/04/19 18:50:38 rhatcher Exp $");
00020 
00021 
00022 //......................................................................
00023 PulserSigLinCalScheme::PulserSigLinCalScheme()
00024 {
00025    MSG("Calib",Msg::kVerbose) 
00026      << "PulserSigLinCalScheme::PulserSigLinCalScheme" 
00027      << endl;
00028 
00029    Registry r;
00030    r.Set("CalMode",1);
00031    r.Set("MinNumPulses",500);
00032    r.Set("VATemperatureCalibration","off");
00033    InitializeConfig(r);
00034    
00035    fRefTemp = 18.0; //reference temperature
00036    fVATempCorFactor = -0.0022; //frac diff in VA electronics response with temp
00037 }
00038 
00039 //......................................................................
00040 void PulserSigLinCalScheme::DoReset( const VldContext& vc )
00041 {
00045   fNearDriftRef.NewQuery(vc,0);
00046   fFarDriftRef.NewQuery(vc,0);
00047   fPinDriftRef.NewQuery(vc,0);
00048   fNearDrift.NewQuery(vc,0);
00049   fFarDrift.NewQuery(vc,0);
00050   fPinDrift.NewQuery(vc,0);
00051   fLinearity.NewQuery(vc,2);
00052   
00053   // Don't bother with warning messages, but do increment errors.
00054   
00055   if(fNearDriftRef.GetNumRows()<=0) IncrementErrors(kDriftCalibrator,kMissingTable);
00056   if(fFarDriftRef.GetNumRows()<=0) IncrementErrors(kDriftCalibrator,kMissingTable);
00057   if(fPinDriftRef.GetNumRows()<=0) IncrementErrors(kDriftCalibrator,kMissingTable);
00058   if(fNearDrift.GetNumRows()<=0) IncrementErrors(kDriftCalibrator,kMissingTable);
00059   if(fFarDrift.GetNumRows()<=0) IncrementErrors(kDriftCalibrator,kMissingTable);
00060   if(fPinDrift.GetNumRows()<=0) IncrementErrors(kDriftCalibrator,kMissingTable);
00061   if(fLinearity.GetNumRows()<=0) IncrementErrors(kLinCalibrator,kMissingTable);
00062 }
00063 
00064 //......................................................................
00065 void PulserSigLinCalScheme::ConfigModified()
00066 {
00067 
00068   const char* str_tempcal;
00069 
00070   bool ok = true;
00071   ok = ok && GetConfig().Get("CalMode",     fCalMode);
00072   ok = ok && GetConfig().Get("MinNumPulses",fMinNumPulses);
00073   ok = ok && GetConfig().Get("VATemperatureCalibration",str_tempcal);
00074   if(!ok) MSG("Calib",Msg::kWarning) << "PulserSigLinCalibrator "
00075                                           << " Problem when configuring. " <<endl;
00076 
00077   // Interpret strings.
00078   if(strcasecmp(str_tempcal,"on")==0) fDoTempCal = true;
00079   else fDoTempCal = false;
00080 
00081 }
00082 //......................................................................
00083 void PulserSigLinCalScheme::PrintConfig( std::ostream& os ) const
00084 {
00085   os << "  CalMode:      " << fCalMode << endl;
00086   os << "  MinNumPulses: " << fMinNumPulses << endl;
00087   os << "  VA Temperature calibration is " << ((fDoTempCal)?"on":"off") << endl;
00088   if(fDoTempCal) {
00089     os << "  VA Temp Correction Factor = 1 / [ 1 - " 
00090        << fVATempCorFactor << "*(" 
00091        << fRefTemp << " - temp) ]" << endl;
00092   }
00093 
00094 }
00095 
00096 
00097 
00098 //......................................................................
00099 FloatErr  PulserSigLinCalScheme::GetDriftCorrected(FloatErr rawcharge, 
00100                                                   const PlexStripEndId& seid) const
00101 {
00110  
00111   // FIXME: We are applying BOTH drift and linearity here.
00112   switch (fCalMode) {
00113   case 0: // Shouldn't ever be zero, but you never know...
00114   case 1: // Mode 1: No linearity correction, just drift points 
00115     return ApplyCalib(rawcharge,seid);
00116   default:
00117     // Undefined mode!
00118     MSG("Calib",Msg::kWarning)<<"PulserSigLinCalScheme doesn't understand mode "<<fCalMode<<". Defaulting to mode 2."<<endl;
00119     fCalMode = 2;
00120   case 2: // Bendy lines parameterised with a straight line and a cubic.
00121     return ApplyBendyCalib(rawcharge,seid);
00122   };  
00123 }
00124 
00125 
00126 //......................................................................
00127 FloatErr  PulserSigLinCalScheme::GetLinearized(FloatErr sigdrift,      
00128                                               const PlexStripEndId& /*seid*/) const
00129 {
00140 
00141   // FIXME: Linearity is applied at the drift stage. This is wrong.
00142   return sigdrift;
00143 }
00144 
00145 //......................................................................
00146 FloatErr  PulserSigLinCalScheme::DecalDrift(FloatErr undrifted, const PlexStripEndId& /*seid*/) const
00147 {
00158 
00159   //FIXME: No method yet.
00160   MSG("Calib",Msg::kWarning) << "DecalDrift method is unimplimented!" << endl;
00161   return undrifted;
00162 }
00163 
00164 //......................................................................
00165 FloatErr  PulserSigLinCalScheme::DecalLinearity(FloatErr lin,   const PlexStripEndId& /*seid*/) const
00166 {
00177 
00178   //FIXME: No method yet.
00179   MSG("Calib",Msg::kWarning) << "DecalLinearity method is unimplimented!" << endl;
00180   return lin;
00181 }
00182 
00184 // Private functions follow:
00186 
00187 //......................................................................
00188 FloatErr  PulserSigLinCalScheme::ApplyCalib(FloatErr rawcharge, 
00189                                            PlexStripEndId seid) const
00190 {
00191 
00192   //check for VA temperature correction and that channel is VA:
00193   FloatErr tempCor = 1.0;  
00194   if(fDoTempCal) {
00195     PlexHandle ph(GetContext());
00196     //if(ph.GetRawChannelId(seid).GetElecType()==ElecType::kVA ||
00197     //   this->CalDet2003Check())
00198     tempCor = GetVATemperatureCorrection();
00199   }
00200 
00201   Drift d = GetDriftPoint(seid);
00202   if (d.adc > 0) {
00203     return rawcharge/d.adc * d.pin * d.refadc/d.refpin * tempCor; // Fixme: no error set
00204   }
00205   else {
00206     MAXMSG("Calib",Msg::kWarning,20) 
00207         << "No drift point for  StripEnd " << seid.AsString()
00208         << " so NOT CALIBRATING THIS CHANNEL\n";
00209 
00210     IncrementErrors(kDriftCalibrator,kMissingRow,seid);
00211     return rawcharge * tempCor * FloatErr(1.0,0.5); // 50% error added.
00212   }
00213   
00214 }   
00215 
00216 FloatErr  PulserSigLinCalScheme::ApplyCalibFar(FloatErr rawcharge, 
00217                                                PlexStripEndId seid) const
00218 {      
00219 
00220   //check for VA temperature correction and that channel is VA:
00221   FloatErr tempCor = 1.0;
00222   if(fDoTempCal) {
00223     PlexHandle ph(GetContext());
00224     //if(ph.GetRawChannelId(seid).GetElecType()==ElecType::kVA || 
00225     // this->CalDet2003Check())
00226     tempCor = GetVATemperatureCorrection();
00227   }
00228 
00229   Drift d = GetDriftFar(seid);
00230   if (d.adc > 0) {
00231     return rawcharge/d.adc * d.pin * d.refadc/d.refpin * tempCor; // Fixme: no error set
00232   }
00233   else {
00234     MAXMSG("Calib",Msg::kWarning,20) 
00235         << "No drift point for  StripEnd " << seid.AsString()
00236         << " so NOT CALIBRATING THIS CHANNEL\n";
00237 
00238     IncrementErrors(kDriftCalibrator,kMissingRow,seid);
00239     return rawcharge * tempCor * FloatErr(1.0,0.5); // Add 50% error
00240   }
00241 }
00242 
00243 
00244 FloatErr PulserSigLinCalScheme::GetDriftPinDiodeValue(PlexLedId ledid, Int_t highOrLow) const
00245 {
00246    
00247    PlexHandle ph(GetContext());
00248    std::pair<PlexPinDiodeId,PlexPinDiodeId> myPins = 
00249       ph.GetPinDiodeIds(ledid); // hi, low
00250       //myGetPinDiodeIds(GetContext(),ledid);
00251    //cout << ledid << "\t" << myPins.first << endl;
00252    
00253    if(highOrLow==0) {//high ==0  low ==1
00254       const PulserRawDriftPin *highpin =fPinDrift.GetRowByIndex(myPins.first.GetEncoded());
00255       if(highpin==0) {
00256          
00257         MSG("Calib",Msg::kWarning) 
00258            << "No Drift Point database row for Pin " << myPins.first 
00259             << " (indexed as " << myPins.first.GetEncoded() << " there are "
00260             << fPinDrift.GetNumRows() << " rows\n.";
00261         IncrementErrors(kDriftCalibrator,kMissingRow,ledid);
00262 
00263         //  for ( UInt_t irow = 0; irow < fPinDrift.GetNumRows(); irow++) {
00264 //         const PulserRawDriftPin* ddd1 = fPinDrift.GetRow(irow);
00265 //         cout << "Bastard: " << ddd1->GetIndex(1) << endl;
00266 //      }
00267         
00268         // Process row.
00269         
00270       
00271 
00272 
00273          return -1;
00274       }  
00275       else {
00276          MSG("Calib",Msg::kDebug) 
00277             << "Got Drift Point database row for Pin " << myPins.first 
00278             << " (indexed as " << myPins.first.GetEncoded() << " )\n";
00279          
00280          if(highpin->GetNumEntries()<fMinNumPulses) {
00281             MSG("Calib",Msg::kWarning) 
00282                << "Only " << highpin->GetNumEntries() << " entries for  " 
00283                << myPins.first 
00284                << " (indexed as " << myPins.first.GetEncoded() << " )" << endl;
00285             return -1;
00286          }
00287          return highpin->GetMean();
00288       }
00289    }
00290    else if(highOrLow==1) { //low gain pin 
00291       const PulserRawDriftPin *lowpin =fPinDrift.GetRowByIndex(myPins.second.GetEncoded());
00292       if(lowpin==0) {
00293          
00294          MSG("Calib",Msg::kWarning) 
00295             << "No Drift Point database row for Pin " << myPins.second 
00296             << " (indexed as " << myPins.second.GetEncoded() << " )\n";
00297          return -1;
00298       }  
00299       else {
00300          MSG("Calib",Msg::kDebug) 
00301             << "Got Drift Point database row for Pin " << myPins.second 
00302             << " (indexed as " << myPins.second.GetEncoded() << " )\n";
00303          
00304          if(lowpin->GetNumEntries()<fMinNumPulses) {
00305             MSG("Calib",Msg::kWarning) 
00306                << "Only " << lowpin->GetNumEntries() << " entries for  " 
00307                << myPins.second 
00308                << " (indexed as " << myPins.second.GetEncoded() << " )" << endl;
00309             return -1;
00310          }
00311          return lowpin->GetMean();
00312       }
00313    }           
00314    
00315    return -1;
00316 }
00317 
00318 //......................................................................
00319 
00320 FloatErr PulserSigLinCalScheme::GetReferencePinDiodeValue(PlexLedId ledid, Int_t highOrLow) const
00321 {
00322    
00323    PlexHandle ph(GetContext());
00324    std::pair<PlexPinDiodeId,PlexPinDiodeId> myPins = 
00325       ph.GetPinDiodeIds(ledid); // hi, low
00326       //myGetPinDiodeIds(GetContext(),ledid);
00327    
00328    if(highOrLow==0) {//high ==0  low ==1
00329       const PulserRefDriftPin *highpin =fPinDriftRef.GetRowByIndex(myPins.first.GetEncoded());
00330       if(highpin==0) {
00331          
00332         MAXMSG("Calib",Msg::kWarning,20) 
00333           << "No Reference Point database row for Pin " << myPins.first 
00334           << " (indexed as " << myPins.first.GetEncoded() << " )\n";
00335         IncrementErrors(kDriftCalibrator,kMissingRow,ledid);
00336         return -1;
00337       }  
00338       else {
00339          MSG("Calib",Msg::kDebug) 
00340             << "Got Reference Point database row for Pin " << myPins.first 
00341             << " (indexed as " << myPins.first.GetEncoded() << " )\n";
00342          
00343          if(highpin->GetNumEntries()<fMinNumPulses) {
00344             MSG("Calib",Msg::kWarning) 
00345               << "Only " << highpin->GetNumEntries() << " entries for  " 
00346               << myPins.first 
00347               << " (indexed as " << myPins.first.GetEncoded() << " )" << endl;
00348             IncrementErrors(kDriftCalibrator,kDataInsufficient,ledid);  
00349             return -1;
00350          }
00351          return highpin->GetMean();
00352       }
00353    }
00354    else if(highOrLow==1) { //low gain pin 
00355       const PulserRefDriftPin *lowpin =fPinDriftRef.GetRowByIndex(myPins.second.GetEncoded());
00356       if(lowpin==0) {
00357          MSG("Calib",Msg::kWarning) 
00358             << "No Reference Point database row for Pin " << myPins.second 
00359             << " (indexed as " << myPins.second.GetEncoded() << " )\n";
00360          IncrementErrors(kDriftCalibrator,kMissingRow,ledid);
00361          return -1;
00362       }  
00363       else {
00364          MSG("Calib",Msg::kDebug) 
00365             << "Got Reference Point database row for Pin " << myPins.second 
00366             << " (indexed as " << myPins.second.GetEncoded() << " )\n";
00367          
00368          if(lowpin->GetNumEntries()<fMinNumPulses) {
00369             MSG("Calib",Msg::kWarning) 
00370                << "Only " << lowpin->GetNumEntries() << " entries for  " 
00371                << myPins.second 
00372                << " (indexed as " << myPins.second.GetEncoded() << " )" <<endl;
00373             IncrementErrors(kDriftCalibrator,kDataInsufficient,ledid);  
00374             return -1;
00375          }
00376          return lowpin->GetMean();
00377       }
00378    }
00379    return -1;
00380 }     
00381 
00382 
00383 
00384 //......................................................................
00385 
00386 
00387 //  std::pair<PlexPinDiodeId,PlexPinDiodeId> PulserSigLinCalScheme::myGetPinDiodeIds(PlexHandle plex, PlexLedId led) const
00388    
00389 //  {
00390 //     Int_t highpinchads[6]={4146,4274,4402,4786,4914,5042};
00391 //     Int_t lowpinchads[6]={4114,4242,4370,4626,4882,5010};
00392 //     PlexPinDiodeId high = 
00393 //       plex.GetPinDiodeId(RawChannelId(Detector::kCalDet,ElecType::kVA,
00394 //                                   0,highpinchads[led.GetLedInBox()-1]));
00395 //     PlexPinDiodeId low = 
00396 //       plex.GetPinDiodeId(RawChannelId(Detector::kCalDet,ElecType::kVA,
00397 //                                   0,lowpinchads[led.GetLedInBox()-1]));
00398 //      return std::make_pair(high,low);
00399    
00400    
00401 
00402 //  }
00403 
00404 
00405 
00406 
00407 FloatErr PulserSigLinCalScheme::ApplyBendyCalib(FloatErr rawcharge, 
00408                                                 PlexStripEndId seid) const
00409 {
00410   // Curve is parameterised by the numbers in the nonlinearity table.
00411   // We call the ADCtoLin method of the linearity table, with the 
00412   // mode from fCalMode. This returns a number in the arbitrary linear
00413   // scale for that stripend, LIN.
00414 
00415   // Also call ADCtoLin with the drift point PMT adc, to get the drift 
00416   // point in the magic linear scale, DLIN. 
00417 
00418   // so do LIN/DLIN * DPIN to give linear, drift corrected PIN units, 
00419   // then multiply by REFADC/REFPIN to give an ADC count again.
00420 
00421   // We'll probably want to cache DLIN at some point.
00422 
00423   const CalLinearity *linearity = 
00424     fLinearity.GetRowByIndex(seid.BuildPlnStripEndKey());  
00425   if (linearity==0) {
00426     MAXMSG("Calib",Msg::kWarning,20) 
00427       << "No Linearity table for  StripEnd " << seid 
00428       << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00429     MAXMSG("Calib",Msg::kWarning,20) 
00430       <<"Defaulting to linear assumption\n";
00431  
00432     IncrementErrors(kLinCalibrator,kMissingRow,seid);
00433     return ApplyCalib(rawcharge,seid);
00434   }
00435 
00436   //check for VA temperature correction and that channel is VA:
00437   double tempCor = 1.0;
00438   if(fDoTempCal) {
00439     PlexHandle ph(GetContext());
00440     //if(ph.GetRawChannelId(seid).GetElecType()==ElecType::kVA ||
00441     //   this->CalDet2003Check())
00442     tempCor = GetVATemperatureCorrection();
00443   }
00444 
00445   // Get drift bits
00446   Drift d = GetDriftPoint(seid);
00447   if (d.adc > 0) {
00448     float lin = linearity->ADCtoLin(rawcharge);
00449     float dlin = linearity->ADCtoLin(d.adc);
00450 
00451     //if (d.adc!=dlin)    cout<<"Drift "<<d.adc<<" "<<dlin<<endl;    
00452 
00453    return lin/dlin * d.pin * linearity->ADCtoLin(d.refadc)/d.refpin * tempCor;
00454    //   return rawcharge/d.adc * d.pin * d.refadc/d.refpin;
00455   }
00456   else {
00457     MAXMSG("Calib",Msg::kWarning,20) 
00458       << "No drift point for  StripEnd " << seid 
00459       << " so NOT CALIBRATING THIS CHANNEL\n";
00460     IncrementErrors(kLinCalibrator,kMissingRow,seid);
00461     return rawcharge * FloatErr(1.0,0.5); // Add 50% error
00462   }
00463 }
00464 
00465 PulserSigLinCalScheme::Drift 
00466   PulserSigLinCalScheme::GetDriftPoint(PlexStripEndId seid) const
00467 {
00468   Drift drift;
00469   
00470   const PulserRawDrift *nearrawdrift =
00471     fNearDrift.GetRowByIndex(seid.BuildPlnStripEndKey());
00472   if(nearrawdrift==0) {
00473     MAXMSG("Calib",Msg::kWarning,20) 
00474       << "No Near Drift Point database row for StripEnd " << seid 
00475       << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00476     IncrementErrors(kDriftCalibrator,kMissingRow,seid);
00477     return GetDriftFar(seid);
00478   }
00479   MSG("Calib",Msg::kDebug) 
00480     << "Got Near Drift row for StripEnd " << seid 
00481     << " (indexed as " << seid.BuildPlnStripEndKey() << " )"
00482     << " aggregate. " << nearrawdrift->GetAggregateNo() << endl;
00483   if(nearrawdrift->GetNumEntries()<fMinNumPulses) {
00484     MAXMSG("Calib",Msg::kWarning,20) 
00485       << "Only " << nearrawdrift->GetNumEntries() << " entries for  " 
00486       << seid
00487       << " (indexed as " << seid.BuildPlnStripEndKey() << " )" << endl;
00488     IncrementErrors(kDriftCalibrator,kDataInsufficient,seid);
00489     return GetDriftFar(seid);
00490   }
00491 
00492   drift.adc = nearrawdrift->GetMean();
00493   if (drift.adc<1) return GetDriftFar(seid);
00494   if (drift.adc>8000) {
00495     // If the near side has a big number, try to use the far side.
00496     // If the far side doesn't have data, we'll have to use the near side, 
00497     // even though it's a big number.
00498        Drift fardrift = GetDriftFar(seid);
00499           if (fardrift.adc>0) return fardrift;
00500    }
00501   
00502   PlexLedId veryTempLedId = PlexLedId(nearrawdrift->GetAggregateNo());
00503   PlexLedId tempLedId = PlexLedId(GetContext().GetDetector(),
00504                                   veryTempLedId.GetPulserBox(),
00505                                   veryTempLedId.GetLedInBox());
00506   //Now need to get PIN info.
00507   int tempWhichPin=0; // high gain pin.
00508   float tempPinValue=GetDriftPinDiodeValue(tempLedId, tempWhichPin);
00509   if(tempPinValue<=0) {
00510     tempWhichPin=1; // low gain pin.
00511     tempPinValue=GetDriftPinDiodeValue(tempLedId, tempWhichPin);
00512     if(tempPinValue<=0) {
00513       return GetDriftFar(seid);
00514     } 
00515   }
00516   
00517   const PulserRefDrift *nearrefdrift = 
00518     fNearDriftRef.GetRowByIndex(seid.BuildPlnStripEndKey());
00519   if(nearrefdrift==0) {
00520     MAXMSG("Calib",Msg::kWarning,20) 
00521       << "No Near Reference Drift Point database row for StripEnd " 
00522       << seid 
00523       << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00524     IncrementErrors(kDriftCalibrator,kMissingRow,seid);
00525     return GetDriftFar(seid);
00526   }  
00527   MSG("Calib",Msg::kDebug) 
00528     << "Got Near Reference Drift row for StripEnd " << seid 
00529     << " (indexed as " << seid.BuildPlnStripEndKey() << " )"
00530     << " aggregate. " << nearrawdrift->GetAggregateNo() << endl;
00531   if(nearrefdrift->GetNumEntries()<fMinNumPulses) {
00532     MAXMSG("Calib",Msg::kWarning,20) 
00533       << "Only " << nearrefdrift->GetNumEntries() 
00534       << " entries for  " 
00535       << seid
00536       << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00537     IncrementErrors(kDriftCalibrator,kDataInsufficient,seid);
00538     return GetDriftFar(seid);
00539   }
00540   float tempRefAdcValue=nearrefdrift->GetMean();
00541   PlexLedId veryTempRefLedId = PlexLedId(nearrefdrift->GetAggregateNo());
00542   PlexLedId tempRefLedId = PlexLedId(GetContext().GetDetector(),
00543                                      veryTempRefLedId.GetPulserBox(),
00544                                      veryTempRefLedId.GetLedInBox());
00545   if(tempRefLedId.GetEncoded()!=tempLedId.GetEncoded()) {
00546     MSG("Calib",Msg::kWarning) 
00547       << "The drift point led is: " << tempLedId 
00548       << " the reference led is: " << tempRefLedId
00549       << " for " << seid << " (indexed as " 
00550       << seid.BuildPlnStripEndKey() << ")\t"
00551       << " Oh what to do!!!\n";
00552     IncrementErrors(kDriftCalibrator,kGeneralErr);
00553     return GetDriftFar(seid);
00554   }
00555   float tempRefPinValue=GetReferencePinDiodeValue(tempRefLedId, tempWhichPin);
00556   if(tempRefPinValue<=0) {
00557     if(tempWhichPin==0) {
00558       tempWhichPin=1; // low gain pin.
00559       tempPinValue=GetDriftPinDiodeValue(tempLedId, tempWhichPin);
00560       if(tempPinValue<=0) {
00561         return GetDriftFar(seid);
00562       } 
00563       tempRefPinValue=GetReferencePinDiodeValue(tempRefLedId, tempWhichPin);
00564       if(tempRefPinValue<=0) {
00565         return GetDriftFar(seid);
00566       } 
00567     }
00568   }
00569   drift.pin = tempPinValue;
00570   drift.refadc = tempRefAdcValue;
00571   drift.refpin = tempRefPinValue;
00572   return drift; 
00573 
00574 }
00575 
00576 
00577 PulserSigLinCalScheme::Drift PulserSigLinCalScheme::GetDriftFar(PlexStripEndId seid) const
00578 {
00579   // Return drift point bits using the far end, or zeros if we can't manage it
00580   Drift drift;
00581 
00582    const PulserRawDriftF *farrawdrift =
00583      fFarDrift.GetRowByIndex(seid.BuildPlnStripEndKey());
00584    
00585    if(farrawdrift==0) {
00586      MAXMSG("Calib",Msg::kWarning,20) 
00587        << "No Far Drift Point database row for StripEnd " << seid 
00588        << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00589      IncrementErrors(kDriftCalibrator,kMissingRow,seid);
00590      return DriftZero(); // need to flag this as error
00591    }
00592    MSG("Calib",Msg::kDebug) 
00593      << "Got Far Drift row for StripEnd " << seid 
00594      << " (indexed as " << seid.BuildPlnStripEndKey() << " )"
00595      << " aggregate. " << farrawdrift->GetAggregateNo() << endl;
00596    if(farrawdrift->GetNumEntries()<fMinNumPulses) {
00597      MAXMSG("Calib",Msg::kWarning,20) 
00598        << "Only " << farrawdrift->GetNumEntries() << " entries for  " 
00599        << seid
00600        << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00601      IncrementErrors(kDriftCalibrator,kDataInsufficient,seid);
00602      return DriftZero(); 
00603    }
00604    drift.adc = farrawdrift->GetMean();
00605    PlexLedId veryTempLedId = PlexLedId(farrawdrift->GetAggregateNo());
00606    PlexLedId tempLedId = PlexLedId(GetContext().GetDetector(),
00607                                    veryTempLedId.GetPulserBox(),
00608                                    veryTempLedId.GetLedInBox());
00609    //Now need to get PIN info.
00610    int tempWhichPin=0; // high gain pin.
00611    float tempPinValue=GetDriftPinDiodeValue(tempLedId, tempWhichPin);
00612    if(tempPinValue<=0) {
00613      tempWhichPin=1; // low gain pin.
00614      tempPinValue=GetDriftPinDiodeValue(tempLedId, tempWhichPin);
00615      if(tempPinValue<=0) {
00616        return DriftZero(); 
00617      } 
00618    }
00619    const PulserRefDriftF *farrefdrift =
00620      fFarDriftRef.GetRowByIndex(seid.BuildPlnStripEndKey());
00621    if(farrefdrift==0) {
00622      MAXMSG("Calib",Msg::kWarning,20) 
00623        << "No Far Reference Drift Point database row for StripEnd " 
00624        << seid 
00625        << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00626      return DriftZero(); // Need to add error.
00627    }
00628    MSG("Calib",Msg::kDebug) 
00629      << "Got Far Reference Drift row for StripEnd " << seid 
00630      << " (indexed as " << seid.BuildPlnStripEndKey() << " )"
00631      << " aggregate. " << farrawdrift->GetAggregateNo() << endl;
00632    if(farrefdrift->GetNumEntries()<fMinNumPulses) {
00633      MAXMSG("Calib",Msg::kWarning,20) 
00634        << "Only " << farrefdrift->GetNumEntries() 
00635        << " entries for  " 
00636        << seid
00637        << " (indexed as " << seid.BuildPlnStripEndKey() << " )" << endl;
00638      IncrementErrors(kDriftCalibrator,kDataInsufficient,seid);
00639      return DriftZero(); 
00640    }
00641    float tempRefAdcValue=farrefdrift->GetMean();
00642    PlexLedId veryTempRefLedId = PlexLedId(farrefdrift->GetAggregateNo());
00643    PlexLedId tempRefLedId = PlexLedId(GetContext().GetDetector(),
00644                                       veryTempRefLedId.GetPulserBox(),
00645                                       veryTempRefLedId.GetLedInBox());
00646    if(tempRefLedId.GetEncoded()!=tempLedId.GetEncoded()) {
00647      MSG("Calib",Msg::kWarning) 
00648        << "The drift point led is: " << tempLedId 
00649        << " the reference led is: " << tempRefLedId
00650        << " for " << seid << " (indexed as " 
00651        << seid.BuildPlnStripEndKey() << ")\t"
00652        << " Oh what to do!!!\n";
00653      IncrementErrors(kDriftCalibrator,kGeneralErr,seid);
00654      return DriftZero(); 
00655    }
00656    float tempRefPinValue=GetReferencePinDiodeValue(tempRefLedId, tempWhichPin);
00657    if(tempRefPinValue<=0) {
00658      if(tempWhichPin==0) {
00659        tempWhichPin=1; // low gain pin.
00660        tempPinValue=GetDriftPinDiodeValue(tempLedId, tempWhichPin);
00661        if(tempPinValue<=0) {
00662          return DriftZero(); 
00663        } 
00664        tempRefPinValue=GetReferencePinDiodeValue(tempRefLedId, tempWhichPin);
00665        if(tempRefPinValue<=0) {
00666          return DriftZero(); 
00667        } 
00668      }
00669    }
00670    if (drift.adc <1) return DriftZero();
00671    drift.pin = tempPinValue;
00672    drift.refadc = tempRefAdcValue;
00673    drift.refpin = tempRefPinValue;
00674    return drift;
00675 }
00676 
00677 PulserSigLinCalScheme::Drift PulserSigLinCalScheme::DriftZero() const
00678 {
00679   Drift d;
00680   d.adc = 0;
00681   d.pin = 0;
00682   d.refadc = 0;
00683   d.pin = 0;
00684   return d;
00685 }
00686 
00687 //......................................................................
00688 FloatErr PulserSigLinCalScheme::GetVATemperatureCorrection() const
00689 {
00690   //======================================================================
00691   // Purpose: Do VA temperature correction
00692   //======================================================================
00693   
00694   float temp = Calibrator::Instance().GetTemperature();
00695 
00696   float correction = 1 - fVATempCorFactor * (fRefTemp - temp);
00697   
00698   return 1./correction;
00699 
00700   MSG("Calib",Msg::kVerbose) << "Got Temperature Correction of: " 
00701                              << correction << endl;
00702 
00703 }
00704 
00705 //......................................................................
00706 Bool_t PulserSigLinCalScheme::CalDet2003Check() const
00707 {
00708   const VldContext &vldc = GetContext();
00709   //is this CalDet:
00710   if(vldc.GetDetector()!=Detector::kCalDet) return false;
00711   //is this 2003:
00712   VldTimeStamp vldstart = VldTimeStamp(2003,8,22,0,0,0); //T7 Sept 2003 N/F
00713   VldTimeStamp vldend   = VldTimeStamp(2003,9,26,0,0,0); //Run Nums: 70000's
00714   if(vldc.GetTimeStamp()<vldstart) return false;
00715   if(vldc.GetTimeStamp()>=vldend) return false;
00716   //must be CalDet 2003
00717   return true;
00718 }

Generated on Mon Jun 16 14:58:22 2008 for loon by  doxygen 1.3.9.1