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

StripAttenCalScheme.cxx

Go to the documentation of this file.
00001 
00002 // $Id: StripAttenCalScheme.cxx,v 1.20 2007/03/08 21:19:18 tagg Exp $
00003 //
00004 // StripAtten Calibrator class
00005 //
00006 // Responsible for correcting light output from center of strip
00007 // to position along strip.
00008 //
00009 // Nathaniel Tagg
00010 // n.tagg1@physics.ox.ac.uk
00012 #include "StripAttenCalScheme.h"
00013 #include "CalibrationSmearer.h"
00014 #include "UgliGeometry/UgliGeomHandle.h"
00015 #include "MessageService/MsgService.h"
00016 
00017 #include <cmath>
00018 
00019 ClassImp(StripAttenCalScheme)
00020 
00021 CVSID( " $Id: StripAttenCalScheme.cxx,v 1.20 2007/03/08 21:19:18 tagg Exp $ ");
00022 
00024 StripAttenCalScheme::StripAttenCalScheme()
00025   : fResPtr(),
00026     fDefaultAtten(0)
00027 {
00028   Registry r;
00029   r.Set("defF12",0.333);
00030   r.Set("defL1",1.0); 
00031   r.Set("defL2",7.0);
00032   r.Set("Task",0); 
00033   InitializeConfig(r);
00034 }
00035 
00036 
00037 //......................................................................
00038 StripAttenCalScheme::~StripAttenCalScheme()
00039 {
00040   if(fDefaultAtten) delete fDefaultAtten;
00041 }
00042 
00043 
00044 //......................................................................
00045 void StripAttenCalScheme::DoReset( const VldContext& vc )
00046 {
00047   MSG("Calib",Msg::kVerbose) << "StripAttenCalScheme::DoReset(VldContext) Task: " << fTask << endl;
00048 
00049   fResPtr.NewQuery(vc,fTask);
00050   if(fResPtr.GetNumRows()==0) {
00051     MAXMSG("Calib",Msg::kWarning,10) 
00052       << "StripAtten Scheme: No rows found for CALSTRIPATTEN database table"
00053       << vc.AsString() << ".\n";         
00054     IncrementErrors(kAttenCalibrator,kMissingTable);
00055   }
00056 }
00057 
00058 //......................................................................
00059 void StripAttenCalScheme::ConfigModified()
00060 {
00064 
00065   double f12,l1,l2;
00066   bool ok = true;
00067   ok = ok && GetConfig().Get("Task",fTask);
00068   ok = ok && GetConfig().Get("defF12",f12);
00069   ok = ok && GetConfig().Get("defL1",l1);
00070   ok = ok && GetConfig().Get("defL2",l2);
00071   if(!ok) MSG("Calib",Msg::kError) << "Problem setting up StripAttenCalScheme config." << endl;
00072 
00073   if(fDefaultAtten) delete fDefaultAtten;
00074   
00075   // Create a dummy seid. This is because the row constructor calls
00076   // seid.BuildPlnStripEndKey(), which prints out warning messages we don't want.
00077   // Doesn't matter, we don't use this seid for anything.
00078   PlexStripEndId dummy_seid(Detector::kNear,1,1,StripEnd::kPositive);
00079     
00080   // Build the 'default' row.  Uses the default values harvested above to create a
00081   // single DB row, which can do our calibration!
00082   fDefaultAtten = new CalStripAtten(dummy_seid,
00083                                     l1, l2, f12,  // L1, L2, N1/(N1+N2)
00084                                     l1/2., l2/2., f12/2.  // 50% errors
00085                                     );
00086   
00087   // Ensure that the DB has been changed for this event.
00088   Reset(GetContext(),true); 
00089 }
00090 
00091 //......................................................................
00092 void StripAttenCalScheme::PrintConfig( std::ostream& os ) const
00093 {
00094   os << " (NEW attenuation calibration scheme) " << endl;
00095   os << "  Task = " << fTask << endl;
00096   os << "  Default attenuation is " 
00097      << "F12 = " << fDefaultAtten->GetFrac1() << "\t"
00098      << "Lambda1 = " << fDefaultAtten->GetLambda1() << "\t"
00099      << "Lambda2 = " << fDefaultAtten->GetLambda2() << endl;
00100 }
00101 
00102 
00103 //......................................................................
00104 FloatErr StripAttenCalScheme::GetAttenCorrected(FloatErr sigcorr, 
00105                                                 FloatErr stripX, 
00106                                                 const PlexStripEndId& seid) const
00107 {
00117   // This bit ripped from the old StripCalibrator:
00118   // Change from 'stripX' to 'length of green fibre'
00119 
00120   UgliGeomHandle ugli(GetContext());
00121   UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00122 
00123   float outside = fabs(stripX) - ustrip.GetHalfLength();
00124   if(outside>0) {
00125     if(outside > 10.0*Munits::cm) {
00126       MSG("Calib",Msg::kDebug) 
00127         << "Reconstruction asked for non-physical attenuation correction: "
00128         << seid.AsString()
00129         << endl
00130         << "halflen=" << ustrip.GetHalfLength()
00131         << "  requested=" << stripX 
00132         << "  ... trimming to physical bounds now..."
00133         << endl;
00134       IncrementErrors(kAttenCalibrator,kBadInput);
00135     }
00136     // Trim it.
00137     stripX = TMath::Sign(ustrip.GetHalfLength(),stripX);
00138   }
00139   
00140   double halfgreen = ustrip.GetHalfLength() + ustrip.WlsPigtail(seid.GetEnd());
00141   double wlsLen = halfgreen;
00142   if(seid.GetEnd()==StripEnd::kPositive) wlsLen -= stripX;
00143   if(seid.GetEnd()==StripEnd::kNegative) wlsLen += stripX;
00144   // If not +ve or -ve, do nothing.
00145 
00146   const CalStripAtten* atten = fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00147   if(atten==0) {
00148     if((fResPtr.GetNumRows()>0)&&(!seid.IsVetoShield())) {
00149       MAXMSG("Calib",Msg::kWarning,10) << "StripAtten Scheme: Cannot find row for stripend "
00150                                        << seid.AsString() << ". Using default." << endl;
00151       IncrementErrors(kAttenCalibrator,kMissingRow,seid);
00152     }
00153     atten = fDefaultAtten;
00154   }
00155 
00156   // The correction is for the center of the strip to the new position
00157   // on the strip.
00158   
00159   float    a = atten->GetAttenuation(halfgreen);
00160   FloatErr b = atten->GetAttenuation(wlsLen);
00161   b.SetError( fabs( b.GetValue() - atten->GetAttenuation(wlsLen - stripX.GetError()) ) );
00162 
00163   if ( b < 4.0e-10 ) {  
00164     // The value of "b" gets raised to the 4-th power in
00165     // the error calculation of a/b. We cut below 4.0e-10 because it
00166     // is ~(1.175e-38)^(1/4) where that is the smallest representable
00167     // value for a Float_t; smaller values underflow to zero and are
00168     // then used as a denominator.
00169     MAXMSG("Calib",Msg::kWarning,10) 
00170       << "StripAtten Scheme: caught a divide-by-zero error on " 
00171       << seid.AsString() << endl;
00172     IncrementErrors(kAttenCalibrator,kFPE,seid);
00173     return sigcorr * FloatErr(1,0.5);
00174   }
00175 
00176   // New, March 2007. NJT, JL
00177   // Clamp the correction at the near end to be less that a factor of 10
00178   FloatErr ratio = a/b;
00179   if(ratio < 0.1) ratio = FloatErr(0.1,fabs(0.1-ratio.GetValue()));
00180   
00181   return sigcorr * ratio;
00182 }
00183   
00184 
00185 //......................................................................
00186 FloatErr StripAttenCalScheme::DecalAttenCorrected(FloatErr sigmap,
00187                                                 FloatErr stripX,
00188                                                 const PlexStripEndId& seid) const
00189 {
00201 
00202   UgliGeomHandle ugli(GetContext());
00203   UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00204   
00205   // Don't clip the MC.. trust that it's checked strip bounds.
00206   // I sometimes want to inject light into the pigtails, so I need the
00207   // flexibility. --Nathaniel, Jan 2006
00208 //   if(fabs(stripX) > ustrip.GetHalfLength()) {
00209 //     MSG("Calib",Msg::kDebug) << "Reconstruction asked for non-physical attenuation correction: "
00210 //                           << seid.AsString() << endl;
00211 //     MSG("Calib",Msg::kDebug) << "halflen=" << ustrip.GetHalfLength()
00212 //                           << "  requested=" << stripX 
00213 //                           << "  ... trimming to physical bounds now..."
00214 //                           << endl;
00215     
00216 //     // Increment error if it's more than 10 cm out.
00217 //     if(fabs(stripX) > ustrip.GetHalfLength()+0.1) 
00218 //       IncrementErrors(kAttenCalibrator,kBadInput);
00219 
00220 //     // Trim it.
00221 //     stripX = TMath::Sign(ustrip.GetHalfLength(),stripX);
00222 //   }
00223 
00224   double halfgreen = ustrip.GetHalfLength() + ustrip.WlsPigtail(seid.GetEnd());
00225   double wlsLen = halfgreen;
00226   if(seid.GetEnd()==StripEnd::kPositive) wlsLen -= stripX;
00227   if(seid.GetEnd()==StripEnd::kNegative) wlsLen += stripX;
00228   // If not +ve or -ve, do nothing.
00229 
00230   const CalStripAtten* atten = fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00231   if(atten==0) {
00232     if((fResPtr.GetNumRows()>0)&&(!seid.IsVetoShield())) {
00233       MAXMSG("Calib",Msg::kWarning,10) << "StripAtten Scheme: Cannot find row for stripend "
00234                                        << seid.AsString() << ". Using default." << endl;
00235       IncrementErrors(kAttenCalibrator,kMissingRow,seid);
00236     }
00237     atten = fDefaultAtten;
00238   }
00239 
00240   // The correction is for the center of the strip to the new position
00241   // on the strip.
00242   
00243   float a = atten->GetAttenuation(halfgreen);
00244   FloatErr b = atten->GetAttenuation(wlsLen);
00245   b.SetError( fabs( b.GetValue() - atten->GetAttenuation(wlsLen - stripX.GetError()) ) );
00246 
00247   if(a < 4e-10) {
00248     MAXMSG("Calib",Msg::kWarning,10) 
00249       << "StripAtten Scheme: caught a divide-by-zero error on " << seid.AsString() << endl;
00250     IncrementErrors(kAttenCalibrator,kFPE,seid);
00251     return sigmap * FloatErr(1,0.5);
00252   }
00253   
00254   // New, March 2007. NJT, JL
00255   // Clamp the correction at the near end to be less that a factor of 10
00256   FloatErr ratio = b/a;
00257   if(ratio > 10.) ratio = FloatErr(10.,fabs(10.-ratio.GetValue()));
00258   
00259   return sigmap * ratio;
00260 }
00261 
00262 
00263 

Generated on Mon Feb 15 11:07:40 2010 for loon by  doxygen 1.3.9.1