MakeLin Class Reference

#include <MakeLin.h>

List of all members.

Public Member Functions

 MakeLin (VldContext vld, int plane, int strip)
virtual ~MakeLin ()
bool DoCalc ()
void Draw (TCanvas *canvas)
void Draw (TCanvas *canvas, TCanvas *cres)

Private Member Functions

TGraphErrors * Residuals (TGraphErrors *g, TF1 *f)

Private Attributes

VldContext fVld
PlexHandle fPlex
int fPlane
int fStrip
DbiResultPtr< PulserRawGainPinfPinRP
DbiResultPtr< PulserRawGainfNearRP
DbiResultPtr< PulserRawGainFfFarRP
std::vector< float > fLinX [2]
std::vector< float > fLinXe [2]
std::vector< float > fY [2]
std::vector< float > fYe [2]
std::vector< float > fX [2]
std::vector< float > fXe [2]
TGraphErrors * fG1
TGraphErrors * fG2
TGraphErrors * fG3
TGraphErrors * fG4

Detailed Description

Definition at line 33 of file MakeLin.h.


Constructor & Destructor Documentation

MakeLin::MakeLin ( VldContext  vld,
int  plane,
int  strip 
)

Definition at line 35 of file MakeLin.cxx.

References fG1, fG2, fPlex, fVld, PlexHandle::GetPinDiodeIds(), Detector::kCalDet, and VldContext::Print().

00035                                                      : 
00036   fVld(vld), fPlex(vld), fPlane(plane), fStrip(strip), 
00037   fPinRP(vld), fNearRP(vld), fFarRP(vld),
00038   fG1(0), fG2(0), fG3(0), fG4(0)
00039   
00040 {
00041   fG1 = 0;
00042   fG2 = 0;
00043   fVld.Print();
00044   for (int i=1;i<7;i++) {
00045     
00046     PlexLedId l(Detector::kCalDet,0,i);
00047     cout<<l<<endl;
00048     std::pair<PlexPinDiodeId,PlexPinDiodeId> pins = fPlex.GetPinDiodeIds(l);
00049     cout<<pins.first<<"\n"<<pins.second<<endl;
00050   }
00051 }

virtual MakeLin::~MakeLin (  )  [inline, virtual]

Definition at line 36 of file MakeLin.h.

00036 {};


Member Function Documentation

bool MakeLin::DoCalc (  ) 

Definition at line 53 of file MakeLin.cxx.

References fFarRP, fLinX, fLinXe, fNearRP, fPinRP, fPlane, fPlex, fStrip, fVld, fX, fXe, fY, fYe, VldContext::GetDetector(), PulserRawGainPin::GetError(), PulserRawGainF::GetError(), PulserRawGain::GetError(), PlexHandle::GetLedId(), PulserRawGain::GetMean(), PulserRawGainF::GetMean(), PulserRawGainPin::GetMean(), PulserRawGainF::GetNumPoints(), PulserRawGainPin::GetNumPoints(), PulserRawGain::GetNumPoints(), PlexHandle::GetPinDiodeIds(), DbiResultPtr< T >::GetRowByIndex(), StripEnd::kEast, and StripEnd::kWest.

00054 {
00055   // Do the calculation. Return false if we couldn't get a GC for one
00056   // of the ends, or if there wasn't enough light at one end to make a
00057   // useful gaincurve, or whatever else.
00058 
00059   // Start with East end, say,
00060 
00061   for (int end=1;end<3;end++) {
00062 
00063     //    PlexStripEndId enda(fVld.GetDetector(), fPlane, fStrip, StripEnd::kEast); 
00064     //   PlexStripEndId endb(fVld.GetDetector(), fPlane, fStrip, StripEnd::kWest); 
00065     PlexStripEndId enda(fVld.GetDetector(), fPlane, fStrip, end==1?StripEnd::kEast:StripEnd::kWest); 
00066     PlexStripEndId endb(fVld.GetDetector(), fPlane, fStrip, end==1?StripEnd::kWest:StripEnd::kEast); 
00067     const PlexLedId ledid = fPlex.GetLedId(enda);
00068     cout<<"LED Id "<<ledid<<endl;
00069     const PulserRawGain *gn = fNearRP.GetRowByIndex(enda.BuildPlnStripEndKey());
00070     cout<<"Near "<<enda<<endl;
00071     const PulserRawGainF *gf = fFarRP.GetRowByIndex(endb.BuildPlnStripEndKey());
00072     cout<<"Far "<<endb<<endl;
00073 
00074 
00075 
00076     if (!gn) {
00077       cout<<"Can't get data for stripend "<<enda<<endl;
00078       return false;
00079     }
00080     if (!gf) {
00081       cout<<"Can't get data for stripend "<<endb<<endl;
00082       return false;
00083     }
00084     const float *yn = gn->GetMean();
00085     const float *yne = gn->GetError();
00086     int num = gn->GetNumPoints();
00087     
00088     const float *yf = gf->GetMean();
00089     const float *yfe = gf->GetError();
00090     if (num!=gf->GetNumPoints()) {
00091       cout<<"Wrong number of points - near and far ends don't match\n";
00092       return false;
00093     }
00094     std::pair<PlexPinDiodeId,PlexPinDiodeId> pinids =
00095       fPlex.GetPinDiodeIds(ledid);
00096     // .first = gain 1, .secons = gain 0;
00097     
00098     //    const PulserRawGainPin *hgpin = fPinRP.GetRowByIndex(pinids.first.GetEncoded());
00099     const PulserRawGainPin *lgpin = fPinRP.GetRowByIndex(pinids.second.GetEncoded());
00100     //   if (!hgpin) {
00101     //  cout<<"Can't get PIN data for "<<pinids.first<<endl;
00102     //  return false;
00103     //}
00104     if (!lgpin) {
00105       cout<<"Can't get PIN data for "<<pinids.second<<endl;
00106       return false;
00107     }
00108     // Just use low gain PIN for now - eventually we'll have some kind
00109     // of unified PIN scale, I think...
00110     
00111     const float *pin = lgpin->GetMean();
00112     const float *pine = lgpin->GetError();
00113     if (num!=lgpin->GetNumPoints()) {
00114       cout<<"Wrong number of points - PIN and ends don't match\n";
00115       return false;
00116     }
00117     
00118     // Make a new PIN scale such that PMT == PIN up to PMT = 7000 ADCs
00119     // far end is yf vs pin, near end is yn vs pin.
00120     fLinX[end-1].clear();
00121     fLinX[end-1].reserve(num);
00122     fLinXe[end-1].clear();
00123     fLinXe[end-1].reserve(num);
00124     fY[end-1].clear();
00125     fY[end-1].reserve(num);
00126     fYe[end-1].clear();
00127     fYe[end-1].reserve(num);
00128     fX[end-1].clear();
00129     fX[end-1].reserve(num);
00130     fXe[end-1].clear();
00131     fXe[end-1].reserve(num);
00132     for (int point = 0; point<num ; point++) {
00133       if (yf[point]>7000) break;
00134       if (yn[point]>10000) break;
00135       fLinX[end-1].push_back(yf[point]);
00136       fLinXe[end-1].push_back(yfe[point]);
00137       fY[end-1].push_back(yn[point]);
00138       fYe[end-1].push_back(yne[point]);
00139       fX[end-1].push_back(pin[point]);
00140       fXe[end-1].push_back(pine[point]);
00141     }
00142   }
00143   return true;
00144 }

void MakeLin::Draw ( TCanvas *  canvas,
TCanvas *  cres 
)

Definition at line 188 of file MakeLin.cxx.

References Draw(), fG1, fG2, fG3, fG4, and Residuals().

00189 {
00190   this->Draw(canvas);
00191   cres->Clear();
00192   cres->Divide(2,2,0,0,0);
00193 
00194   TF1 *func = new TF1("line","[0] + [1]*x",0,7000);
00195   func->SetParameters(0,1);
00196   fG1->Fit("line","QR");
00197   TGraphErrors *gres1 = Residuals(fG1,func);
00198   cres->cd(1);
00199   gres1->SetMarkerStyle(7);
00200   gres1->SetMarkerColor(3);
00201   gres1->Draw("AP");
00202 
00203   cres->cd(3);
00204   TF1 *func3 = new TF1("line3","[0] + [1]*x",0,7000);
00205   func3->SetParameters(0,1);
00206   fG3->Fit("line3","QR");
00207   TGraphErrors *gres3 = Residuals(fG3,func3);
00208   gres3->SetMarkerStyle(7);
00209   gres3->SetMarkerColor(4);
00210   gres3->Draw("AP");
00211 
00212   cres->cd(2);
00213   TF1 *func2 = new TF1("line2","[0] + [1]*x",0,7000);
00214   func2->SetParameters(0,1);
00215   fG2->Fit("line2","R");
00216   TGraphErrors *gres2 = Residuals(fG2,func2);
00217   gres2->SetMarkerStyle(7);
00218   gres2->SetMarkerColor(3);
00219   gres2->Draw("AP");
00220 
00221   cres->cd(4);
00222   TF1 *func4 = new TF1("line4","[0] + [1]*x",0,7000);
00223   func4->SetParameters(0,1);
00224   fG4->Fit("line4","R");
00225   TGraphErrors *gres4 = Residuals(fG4,func4);
00226   gres4->SetMarkerStyle(7);
00227   gres4->SetMarkerColor(4);
00228   gres4->Draw("AP");
00229   cres->Update();
00230   canvas->Update();
00231 }

void MakeLin::Draw ( TCanvas *  canvas  ) 

Definition at line 147 of file MakeLin.cxx.

References fG1, fG2, fG3, fG4, fLinX, fLinXe, fX, fXe, fY, fYe, and size.

Referenced by Draw().

00148 {
00149   canvas->Clear();
00150   canvas->Divide(2,2,0,0,0);
00151   canvas->cd(1);
00152 
00153   if (fG1) delete fG1;
00154   if (fG2) delete fG2;
00155   fG1 = new TGraphErrors(fY[0].size(),
00156                          &(fLinX[0][0]),&(fY[0][0]),
00157                          &(fLinXe[0][0]),&(fYe[0][0]));
00158   fG1->SetMarkerColor(2);
00159   fG1->SetMarkerStyle(5);
00160   fG1->Draw("AP");
00161   canvas->cd(2);
00162   fG2 = new TGraphErrors(fY[1].size(),
00163                          &(fLinX[1][0]),&(fY[1][0]),
00164                          &(fLinXe[1][0]),&(fYe[1][0]));
00165   fG2->SetMarkerColor(2);
00166   fG2->SetMarkerStyle(5);
00167   fG2->Draw("AP");
00168   if (fG3) delete fG4;
00169   if (fG4) delete fG4;
00170   canvas->cd(3);
00171   fG3 = new TGraphErrors(fY[0].size(),
00172                          &(fX[0][0]),&(fY[0][0]),
00173                          &(fXe[0][0]),&(fYe[0][0]));
00174   fG3->SetMarkerColor(4);
00175   fG3->SetMarkerStyle(5);
00176   fG3->Draw("AP");
00177   canvas->cd(4);
00178   fG4 = new TGraphErrors(fY[1].size(),
00179                          &(fX[1][0]),&(fY[1][0]),
00180                          &(fXe[1][0]),&(fYe[1][0]));
00181   fG4->SetMarkerColor(4);
00182   fG4->SetMarkerStyle(5);
00183   fG4->Draw("AP");
00184 
00185   canvas->Update();
00186 }

TGraphErrors * MakeLin::Residuals ( TGraphErrors *  g,
TF1 *  f 
) [private]

Definition at line 233 of file MakeLin.cxx.

References n.

Referenced by Draw().

00234 {
00235   // f is a fit to g - make residuals and return a TGraphErrors.
00236   vector<double> res;
00237   vector<double> rese;
00238   int n = g->GetN();
00239   double *x = g->GetX();
00240   double *y = g->GetY();
00241   double *xe = g->GetEX();
00242   double *ye = g->GetEY();
00243 
00244   for (int i=0;i<n;i++) {
00245     double val = f->Eval(x[i]);
00246     if (y[i]>0) {
00247       res.push_back((y[i]-val)/y[i]);
00248       rese.push_back((ye[i])/y[i]);
00249     }
00250     else {
00251       res.push_back((y[i]-val));
00252       rese.push_back((ye[i]));
00253     }
00254   }
00255   TGraphErrors *gr = new TGraphErrors(n,x,&(res[0]),xe,&(rese[0]));
00256   return gr;
00257 }


Member Data Documentation

Definition at line 51 of file MakeLin.h.

Referenced by DoCalc().

TGraphErrors* MakeLin::fG1 [private]

Definition at line 58 of file MakeLin.h.

Referenced by Draw(), and MakeLin().

TGraphErrors* MakeLin::fG2 [private]

Definition at line 59 of file MakeLin.h.

Referenced by Draw(), and MakeLin().

TGraphErrors* MakeLin::fG3 [private]

Definition at line 60 of file MakeLin.h.

Referenced by Draw().

TGraphErrors* MakeLin::fG4 [private]

Definition at line 61 of file MakeLin.h.

Referenced by Draw().

std::vector<float> MakeLin::fLinX[2] [private]

Definition at line 52 of file MakeLin.h.

Referenced by DoCalc(), and Draw().

std::vector<float> MakeLin::fLinXe[2] [private]

Definition at line 53 of file MakeLin.h.

Referenced by DoCalc(), and Draw().

Definition at line 50 of file MakeLin.h.

Referenced by DoCalc().

Definition at line 49 of file MakeLin.h.

Referenced by DoCalc().

int MakeLin::fPlane [private]

Definition at line 47 of file MakeLin.h.

Referenced by DoCalc().

Definition at line 46 of file MakeLin.h.

Referenced by DoCalc(), and MakeLin().

int MakeLin::fStrip [private]

Definition at line 48 of file MakeLin.h.

Referenced by DoCalc().

Definition at line 45 of file MakeLin.h.

Referenced by DoCalc(), and MakeLin().

std::vector<float> MakeLin::fX[2] [private]

Definition at line 56 of file MakeLin.h.

Referenced by DoCalc(), and Draw().

std::vector<float> MakeLin::fXe[2] [private]

Definition at line 57 of file MakeLin.h.

Referenced by DoCalc(), and Draw().

std::vector<float> MakeLin::fY[2] [private]

Definition at line 54 of file MakeLin.h.

Referenced by DoCalc(), and Draw().

std::vector<float> MakeLin::fYe[2] [private]

Definition at line 55 of file MakeLin.h.

Referenced by DoCalc(), and Draw().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1