#include <TROOT.h>
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include "Plex/PlexHandle.h"
#include <iostream>
#include <TGraphErrors.h>
#include <TF1.h>
#include <TSystem.h>
#include <stdio.h>
#include "mysql.h"
#include <TPostScript.h>
#include "TMySQLServer.h"
#include "TSQLResult.h"
#include "TSQLRow.h"
#include "Calibrator/Calibrator.h"
Go to the source code of this file.
Functions | |
TCanvas * | GetCanvas (const char *name) |
void | MakeTemperaturePlot (TMySQLServer *server, Detector::Detector_t det, UInt_t start, UInt_t stop) |
int | PlotPmt (TMySQLServer *server, PlexPixelSpotId tube) |
void | pmt_plot () |
void | draw (UInt_t itube) |
Variables | |
static std::vector< TObject * > | cleanup |
static TGraph * | gTemperature1 = 0 |
static TGraph * | gTemperature2 = 0 |
TMySQLServer * | server = 0 |
void draw | ( | UInt_t | itube | ) |
Function to look at pmts more closely:
Definition at line 529 of file pmt_plot.cxx.
References PlexPixelSpotId::AsString(), PlexPixelSpotId::GetUniquePmtEncodedValue(), PlotPmt(), and server.
Referenced by LIAnalysis::AdcVsLed(), LIAnalysis::AdcVsPin(), LIPlexMaps::PlotPlexStripMap(), MINFDisplay::SetDrawHits(), and MINFDisplay::SetDrawParticles().
00530 { 00531 // Load db: 00532 TString host(getenv("ENV_TSQL_URL") ); 00533 host.ReplaceAll("odbc:",""); 00534 if(!server) server = new TMySQLServer( host.Data(), 00535 getenv("ENV_TSQL_USER"), 00536 getenv("ENV_TSQL_PSWD") 00537 ); 00538 00539 TCanvas* cpmt = (TCanvas*) gROOT->FindObject("cpmt"); 00540 if(!cpmt) cpmt = new TCanvas("cpmt","cpmt",1000,750); 00541 00542 PlexPixelSpotId tube(itube); 00543 00544 cout << "Trying tube " << itube << " " << tube.AsString() << tube.GetUniquePmtEncodedValue() << endl; 00545 PlotPmt(server, tube); 00546 }
TCanvas* GetCanvas | ( | const char * | name | ) |
Definition at line 42 of file pmt_plot.cxx.
Referenced by GuiAxis::ApplyRange(), GuiAxis::GuiAxis(), Anp::EventDisplay::InitTab(), PlotPmt(), and Anp::EventDisplay::PrintTab().
void MakeTemperaturePlot | ( | TMySQLServer * | server, | |
Detector::Detector_t | det, | |||
UInt_t | start, | |||
UInt_t | stop | |||
) |
Definition at line 75 of file pmt_plot.cxx.
References Form(), gTemperature1, gTemperature2, and Detector::kFar.
Referenced by PlotPmt().
00078 { 00079 const char* query; 00080 if(det == Detector::kFar) { 00081 query = Form("select " 00082 "UNIX_TIMESTAMP(DCS_ENV_FARVLD.TIMESTART), " 00083 "DCS_ENV_FAR.FAR_TEMPERATURE1, " 00084 "DCS_ENV_FAR.FAR_TEMPERATURE2 " 00085 "from DCS_ENV_FARVLD, DCS_ENV_FAR " 00086 "where (DCS_ENV_FAR.SEQNO=DCS_ENV_FARVLD.SEQNO) " 00087 "and (UNIX_TIMESTAMP(DCS_ENV_FARVLD.TIMESTART)>%d) " 00088 "and (UNIX_TIMESTAMP(DCS_ENV_FARVLD.TIMESTART)<%d) ", 00089 start,stop 00090 ); 00091 } else { 00092 //return; 00093 query = Form("select " 00094 "UNIX_TIMESTAMP(DCS_ENV_NEARVLD.TIMESTART), " 00095 "DCS_ENV_NEAR.NEAR_THERM_V3b, " 00096 "DCS_ENV_NEAR.NEAR_THERM_V3t " 00097 "from DCS_ENV_NEARVLD, DCS_ENV_NEAR " 00098 "where (DCS_ENV_NEAR.SEQNO=DCS_ENV_NEARVLD.SEQNO) " 00099 "and (UNIX_TIMESTAMP(DCS_ENV_NEARVLD.TIMESTART)>%d) " 00100 "and (UNIX_TIMESTAMP(DCS_ENV_NEARVLD.TIMESTART)<%d) ", 00101 start,stop 00102 ); 00103 } 00104 00105 cout << query << endl; 00106 00107 TSQLResult* result = server->Query(query); 00108 if(!result) return; 00109 00110 if(gTemperature1) delete gTemperature1; 00111 if(gTemperature2) delete gTemperature2; 00112 00113 cout << "Building temperature plot with " 00114 << " rows=" << result->GetRowCount() << endl; 00115 00116 gTemperature1 = new TGraph(result->GetRowCount()); 00117 gTemperature2 = new TGraph(result->GetRowCount()); 00118 00119 double* x1 = gTemperature1->GetX(); 00120 double* y1 = gTemperature1->GetY(); 00121 double* x2 = gTemperature2->GetX(); 00122 double* y2 = gTemperature2->GetY(); 00123 00124 int p = 0; 00125 00126 TSQLRow* row = 0; 00127 while( ( row = result->Next() ) ) { 00128 00129 UInt_t time; 00130 Float_t farenheit1; 00131 Float_t farenheit2; 00132 00133 sscanf(row->GetField(0),"%u",&time); 00134 sscanf(row->GetField(1),"%f",&farenheit1); 00135 sscanf(row->GetField(2),"%f",&farenheit2); 00136 00137 x1[p] = time; 00138 x2[p] = time; 00139 y1[p] = (farenheit1-32.0)/1.8; 00140 y2[p] = (farenheit2-32.0)/1.8; 00141 00142 p++; 00143 } 00144 00145 }
int PlotPmt | ( | TMySQLServer * | server, | |
PlexPixelSpotId | tube | |||
) |
Definition at line 148 of file pmt_plot.cxx.
References RawChannelId::AsString(), PlexPixelSpotId::AsString(), cleanup, Form(), GetCanvas(), PlexMuxBoxId::GetDetector(), PlexHandle::GetRawChannelId(), PlexPixelSpotId::GetUniquePmtEncodedValue(), gTemperature1, gTemperature2, SimFlag::kData, Detector::kNear, MakeTemperaturePlot(), PlexPixelSpotId::SetPixel(), and PlexPixelSpotId::SetSpot().
Referenced by draw(), and pmt_plot().
00151 { 00152 for(UInt_t i=0;i<cleanup.size();i++) delete cleanup[i]; 00153 cleanup.clear(); 00154 00155 UInt_t encoded = tube.GetUniquePmtEncodedValue(); 00156 00157 PlexHandle plex(VldContext(tube.GetDetector(), SimFlag::kData, VldTimeStamp())); 00158 PlexPixelSpotId psid = tube; 00159 psid.SetPixel(1); 00160 psid.SetSpot(1); 00161 RawChannelId rcid = plex.GetRawChannelId(psid); 00162 00163 char title[1000]; 00164 sprintf(title,"%s (%u) %s",tube.AsString("t"),encoded,rcid.AsString("e")); 00165 00166 cout << title << endl; 00167 00168 // Find number of points: 00169 Int_t point = 0; 00170 00171 const char* query = Form("select " 00172 "UNIX_TIMESTAMP(CALPMTDRIFTVLD.TIMESTART) " 00173 ",CALPMTDRIFT.DRIFT " 00174 ",CALPMTDRIFT.STATERROR " 00175 ",CALPMTDRIFT.SYSERROR " 00176 ",CALPMTDRIFT.SPOTSUSED " 00177 ",CALPMTDRIFT.SPOTSAVAIL " 00178 ",CALPMTDRIFT.CRUDEDRIFT " 00179 ",CALPMTDRIFT.MINDRIFT " 00180 ",CALPMTDRIFT.MAXDRIFT " 00181 "from CALPMTDRIFTVLD, CALPMTDRIFT where " 00182 "(CALPMTDRIFT.PMT = %u) " 00183 "and (CALPMTDRIFT.SEQNO=CALPMTDRIFTVLD.SEQNO) " 00184 "and (CALPMTDRIFTVLD.TASK=1) " 00185 //"and (CALPMTDRIFTVLD.TIMESTART < '2005-07-31 19:00:04') " 00186 //"and (CALPMTDRIFTVLD.CREATIONDATE >= '2005-09-02 21:00:05') " 00187 //"and (CALPMTDRIFTVLD.TIMESTART > '2005-06-25 00:00:00') " 00188 "and (CALPMTDRIFTVLD.DETECTORMASK=%d) order by CALPMTDRIFTVLD.TIMESTART;", 00189 encoded, 00190 tube.GetDetector() 00191 ); 00192 00193 cout << query << endl; 00194 00195 TSQLResult* result = server->Query(query); 00196 if(!result) return 0; 00197 00198 cout << tube.AsString("t") 00199 << " " << encoded 00200 << " rows=" << result->GetRowCount() << endl; 00201 00202 00203 int npoints = result->GetRowCount(); 00204 00205 TGraphErrors* gFinal = new TGraphErrors(npoints); cleanup.push_back(gFinal); 00206 TGraphErrors* gRaw = new TGraphErrors(npoints); cleanup.push_back(gRaw); 00207 TGraph* gHigh = new TGraph(npoints); cleanup.push_back(gHigh); 00208 TGraph* gLow = new TGraph(npoints); cleanup.push_back(gLow); 00209 TGraph* gNgood = new TGraph(npoints); cleanup.push_back(gNgood); 00210 TGraph* gNspot = new TGraph(npoints); cleanup.push_back(gNspot); 00211 00212 00213 TSQLRow* row = 0; 00214 while( ( row = result->Next() ) ) { 00215 00216 if(point>npoints) break; 00217 UInt_t time; 00218 Float_t drift; 00219 Float_t staterr; 00220 Float_t syserr; 00221 Float_t ngood; 00222 Float_t nspot; 00223 Float_t rawdrift; 00224 Float_t mindrift = -999; 00225 Float_t maxdrift = -999; 00226 00227 int irow=0; 00228 sscanf(row->GetField(irow++),"%u",&time); 00229 sscanf(row->GetField(irow++),"%f",&drift); 00230 sscanf(row->GetField(irow++),"%f",&staterr); 00231 sscanf(row->GetField(irow++),"%f",&syserr); 00232 sscanf(row->GetField(irow++),"%f",&ngood); 00233 sscanf(row->GetField(irow++),"%f",&nspot); 00234 sscanf(row->GetField(irow++),"%f",&rawdrift); 00235 sscanf(row->GetField(irow++),"%f",&mindrift); 00236 sscanf(row->GetField(irow++),"%f",&maxdrift); 00237 00238 00239 gFinal->SetPoint (point,time, drift); 00240 gFinal->SetPointError(point,0, staterr); 00241 gRaw->SetPoint (point,time, rawdrift); 00242 gRaw->SetPointError (point,0, 0); 00243 gHigh->SetPoint (point,time, mindrift); 00244 gLow->SetPoint (point,time, maxdrift); 00245 gNgood->SetPoint (point,time, ngood); 00246 gNspot->SetPoint (point,time, nspot); 00247 00248 //VldContext cx(det, SimFlag::kData, VldTimeStamp(time,0)); 00249 //Calibrator::Instance().Reset(cx); 00250 //Float_t temp = Calibrator::Instance().GetTemperature(1); 00251 //gTemp->SetPoint (point,time, temp); 00252 00253 point++; 00254 } 00255 00256 if(point==0) return 0; 00257 00258 // Find means of the gains over time. 00259 // Reject data points close to zero (likely HV failures) 00260 double finalmean = 0; 00261 double rawmean = 0; 00262 double finaln = 0; 00263 double rawn = 0; 00264 double* finalX = gFinal->GetX(); 00265 double* finalY = gFinal->GetY(); 00266 double* finalEY = gFinal->GetEY(); 00267 double* rawY = gRaw->GetY(); 00268 double* rawEY = gRaw->GetEY(); 00269 for(int i=0;i<point;i++) { 00270 if(finalY[i]>10.) { 00271 finalmean += finalY[i]; 00272 finaln+=1.; 00273 } 00274 if(rawY[i]>10.) { 00275 rawmean += rawY[i]; 00276 rawn += 1.0; 00277 } 00278 } 00279 finalmean /= rawn; 00280 rawmean /= finaln; 00281 00282 00283 TGraphErrors* gRelFinal = new TGraphErrors(npoints); cleanup.push_back(gRelFinal); 00284 TGraphErrors* gRelRaw = new TGraphErrors(npoints); cleanup.push_back(gRelRaw); 00285 00286 Double_t* relFinalX = gRelFinal->GetX(); 00287 Double_t* relFinalY = gRelFinal->GetY(); 00288 Double_t* relFinalEX= gRelFinal->GetEX(); 00289 Double_t* relFinalEY= gRelFinal->GetEY(); 00290 Double_t* relRawX = gRelRaw->GetX(); 00291 Double_t* relRawY = gRelRaw->GetY(); 00292 Double_t* relRawEX= gRelRaw->GetEX(); 00293 Double_t* relRawEY= gRelRaw->GetEY(); 00294 for(Int_t i=0;i<npoints;i++) { 00295 relFinalX[i] = finalX[i]; 00296 relFinalY[i] = (finalY[i]-finalmean)/finalmean * 100.; 00297 relFinalEX[i] = 0; 00298 relFinalEY[i] = finalEY[i]/finalmean * 100.; 00299 00300 relRawX[i] = finalX[i]; 00301 relRawY[i] = (rawY[i]-rawmean)/rawmean * 100.; 00302 relRawEX[i] = 0; 00303 relRawEY[i] = rawEY[i]/rawmean * 100.; 00304 } 00305 00306 00307 TCanvas* cpmt = GetCanvas("cpmt"); 00308 cpmt->cd(); 00309 cpmt->Clear(); 00310 cpmt->Divide(1,3,0.001,0.001,kWhite); 00311 cpmt->cd(1); 00312 00313 00314 double tlow = gFinal->GetX()[0]; 00315 double thigh = gFinal->GetX()[point-1]; 00316 00317 //const double kMonth = 60.*60.*24.*365./12.; 00318 //const double tref = VldTimeStamp(2005,01,15,0,0,0,0).GetSec(); 00319 00320 //tlow = ( (int)((tlow -tref)/kMonth) )*kMonth + tref; 00321 //thigh = ( (int)((thigh-tref)/kMonth) + 1)*kMonth + tref; 00322 00323 if(gTemperature1==0) MakeTemperaturePlot(server, 00324 tube.GetDetector(), 00325 (UInt_t)tlow, 00326 (UInt_t)thigh); 00327 00328 double ymax = 150.; 00329 if(tube.GetDetector()==Detector::kNear) ymax=500.; 00330 TH2F* hFrame1 = new TH2F("hFrame1", 00331 title, 00332 100,tlow,thigh, 00333 100,0,ymax); 00334 hFrame1->SetDirectory(0); 00335 cleanup.push_back(hFrame1); 00336 00337 hFrame1->GetXaxis()->SetTimeDisplay(1); 00338 hFrame1->GetXaxis()->SetTimeFormat("%d/%b/%y %Hh"); 00339 //hFrame1->SetLabelSize(0.04,"x"); 00340 hFrame1->SetXTitle("Date"); 00341 hFrame1->SetYTitle("Gain (ADC counts)"); 00342 hFrame1->SetStats(0); 00343 hFrame1->Draw(""); 00344 00345 00346 gRaw->SetLineColor(kRed); 00347 gRaw->SetMarkerColor(kRed); 00348 gRaw->SetMarkerStyle(20); 00349 gRaw->SetMarkerSize(0.45); 00350 gRaw->Draw("P"); 00351 00352 gFinal->SetMarkerStyle(20); 00353 gFinal->SetMarkerSize(0.5); 00354 gFinal->Draw("P"); 00355 00356 gLow->SetMarkerStyle(23); 00357 gLow->SetMarkerSize(0.6); 00358 gLow->SetMarkerColor(kBlue); 00359 gLow->Draw("P"); 00360 gHigh->SetMarkerStyle(24); 00361 gHigh->SetMarkerSize(0.6); 00362 gHigh->SetMarkerColor(kBlue); 00363 gHigh->Draw("P"); 00364 00365 gNspot->SetLineColor(kBlack); 00366 gNspot->Draw("L"); 00367 00368 gNgood->SetLineColor(kGreen); 00369 gNgood->Draw("L"); 00370 00371 if(gTemperature1) { 00372 gTemperature1->SetLineColor(kBlue); 00373 gTemperature1->Draw("L"); 00374 } 00375 00376 00377 cpmt->cd(2); 00378 TH2F* hFrame2 = new TH2F("hFrame2", 00379 title, 00380 100,tlow,thigh, 00381 100,-4,4.); 00382 hFrame2->SetDirectory(0); 00383 cleanup.push_back(hFrame2); 00384 00385 hFrame2->SetStats(0); 00386 hFrame2->GetXaxis()->SetTimeDisplay(1); 00387 hFrame2->GetXaxis()->SetTimeFormat("%d/%b/%y %Hh"); 00388 hFrame2->SetLabelSize(0.04,"x"); 00389 hFrame2->SetXTitle("Date"); 00390 hFrame2->SetYTitle("Relative Gain (%)"); 00391 hFrame2->Draw(""); 00392 00393 00394 gRelRaw->SetLineColor(kRed); 00395 gRelRaw->SetMarkerColor(kRed); 00396 gRelRaw->SetMarkerStyle(21); 00397 gRelRaw->SetMarkerSize(0.5); 00398 gRelRaw->Draw("P"); 00399 00400 gRelFinal->SetMarkerStyle(20); 00401 gRelFinal->SetMarkerSize(0.5); 00402 gRelFinal->Draw("P"); 00403 00404 gStyle->SetOptFit(11111); 00405 00406 TF1 *f1 = new TF1("f1","[0]",0,1e99); 00407 gRelFinal->Fit(f1,"RQ"); 00408 f1->Draw("l same"); 00409 00410 00411 cpmt->cd(3); 00412 TH2F* hFrame3 = new TH2F("hFrame3","Temperature", 00413 100,tlow,thigh, 00414 100,15,30.); 00415 hFrame3->SetDirectory(0); 00416 cleanup.push_back(hFrame3); 00417 00418 hFrame3->SetStats(0); 00419 hFrame3->GetXaxis()->SetTimeDisplay(1); 00420 hFrame2->GetXaxis()->SetTimeFormat("%d/%b/%y %Hh"); 00421 hFrame3->SetLabelSize(0.04,"x"); 00422 hFrame3->SetXTitle("Date"); 00423 hFrame3->SetYTitle("Temperature"); 00424 hFrame3->Draw(""); 00425 00426 if(gTemperature2) { 00427 gTemperature2->SetLineColor(kCyan); 00428 gTemperature2->SetMarkerColor(kCyan); 00429 gTemperature2->SetMarkerStyle(20); 00430 gTemperature2->SetMarkerSize(0.01); 00431 gTemperature2->Draw("P"); 00432 } 00433 00434 if(gTemperature1) { 00435 gTemperature1->SetLineColor(kBlue); 00436 gTemperature1->SetMarkerColor(kBlue); 00437 gTemperature1->SetMarkerStyle(20); 00438 gTemperature1->SetMarkerSize(0.01); 00439 gTemperature1->Draw("P"); 00440 } 00441 00442 cout << "Done." << endl; 00443 00444 cpmt->Update(); 00445 return point; 00446 }
void pmt_plot | ( | ) |
Definition at line 449 of file pmt_plot.cxx.
References PlexPixelSpotId::AsString(), det, Form(), PlexHandle::GetAllTubes(), Calibrator::Instance(), SimFlag::kData, Detector::kFar, PlotPmt(), and server.
00450 { 00451 TCanvas* cpmt = (TCanvas*) gROOT->FindObject("cpmt"); 00452 if(cpmt) delete cpmt; 00453 cpmt = new TCanvas("cpmt","cpmt",1000,750); 00454 00455 TPostScript* ps = 0; 00456 ps = new TPostScript("pmt_drift.ps",112); 00457 gStyle->SetTimeOffset(0); 00458 00459 00460 // For some reason, I have to do this before I open the TMySQL interface. 00461 Calibrator::Instance(); 00462 00463 // Load db: 00464 TString host(getenv("ENV_TSQL_URL") ); 00465 host.ReplaceAll("odbc:",""); 00466 if(!server) { 00467 //server = new TMySQLServer( "mysql://minos-db1.fnal.gov/offline", "reader","minos_db"); 00468 server = new TMySQLServer( "mysql://localhost/offline", "reader","numi96"); 00469 // host.Data(), 00470 // getenv("ENV_TSQL_USER"), 00471 // getenv("ENV_TSQL_PSWD") 00472 // ); 00473 } 00474 00475 PlexPixelSpotId tube; 00476 00477 /* 00478 tube = PlexPixelSpotId(2701264895); 00479 if(ps) ps->NewPage(); 00480 PlotPmt(server, tube); 00481 Pause(); 00482 00483 tube = PlexPixelSpotId(2701266943); 00484 if(ps) ps->NewPage(); 00485 PlotPmt(server, tube); 00486 Pause(); 00487 */ 00488 00489 //Detector::Detector_t det = Detector::kNear; 00490 Detector::Detector_t det = Detector::kFar; 00491 00492 00493 VldContext cx(det,SimFlag::kData,VldTimeStamp()); 00494 PlexHandle plex(cx); 00495 const std::vector<PlexPixelSpotId>& tubes = plex.GetAllTubes(); 00496 00497 //std::vector<PlexPixelSpotId> tubes; 00498 //ElecType::Elec_t elec = ElecType::kVA; 00499 //for(char ew = 'E'; ew<='W'; ew+='W'-'E') 00500 // for(char ul = 'L'; ul<='U'; ul+='U'-'L') 00501 // for(int bay=1;bay<=16;bay++) 00502 // for(int inrack=0;inrack<=9;inrack++) 00503 // for(int t=0;t<3;t++) { 00504 // tubes.push_back( 00505 // PlexPixelSpotId(det,elec,ew,ul,bay,inrack,t,0,0) 00506 // ); 00507 // } 00508 00509 if(ps) ps->NewPage(); 00510 00511 for(UInt_t i=0;i<tubes.size();i++) { 00512 tube = tubes[i]; 00513 int res = PlotPmt(server, tube); 00514 if(res) { 00515 ps->NewPage(); 00516 cpmt->Print(Form("pmt_drifts/%s.gif",tube.AsString("t"))); 00517 } 00518 } 00519 00520 if(ps) ps->Close(); 00521 }
std::vector<TObject*> cleanup [static] |
Definition at line 70 of file pmt_plot.cxx.
Referenced by PlotPmt().
TGraph* gTemperature1 = 0 [static] |
Definition at line 71 of file pmt_plot.cxx.
Referenced by MakeTemperaturePlot(), and PlotPmt().
TGraph* gTemperature2 = 0 [static] |
Definition at line 72 of file pmt_plot.cxx.
Referenced by MakeTemperaturePlot(), and PlotPmt().
TMySQLServer* server = 0 |
Definition at line 73 of file pmt_plot.cxx.
Referenced by draw(), main(), pmt_plot(), and DbiDBProxy::StoreMetaData().