00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00076
00077
00078 PlexStripEndId dummy_seid(Detector::kNear,1,1,StripEnd::kPositive);
00079
00080
00081
00082 fDefaultAtten = new CalStripAtten(dummy_seid,
00083 l1, l2, f12,
00084 l1/2., l2/2., f12/2.
00085 );
00086
00087
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
00118
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
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
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
00157
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
00165
00166
00167
00168
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
00177
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
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
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
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
00241
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
00255
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