/// Class to plot gas properties inside TPC /// over a particular time period (or run). /// Blair Jamieson (C) 2010 #include "ITPCGasAnalysis.hxx" #include #include #include #include #include /// Initialize TPC gas properties averaging object using unix time ITPCGasAnalysis::ITPCGasAnalysis( int maxsamples, long autmin, long autmax) { fTimeMin = autmin; fTimeMax = autmax; fNSam = maxsamples; Process(); } /// Initialize TPC gas properties averaging object using year, /// month(0-11), day (1-31), ... ITPCGasAnalysis:: ITPCGasAnalysis(int maxsamples, int ayearmin, int amonthmin, int adaymin, int ahourmin, int aminmin, int asecmin, int ayearmax, int amonthmax, int adaymax, int ahourmax, int aminmax, int asecmax ) { fNSam = maxsamples; tm mt; // use time structure from time.h // to build unix time from year,month, etc. mt.tm_year = ayearmin - 1900; mt.tm_mon = amonthmin-1; mt.tm_mday = adaymin; mt.tm_hour = ahourmin; mt.tm_min = aminmin; mt.tm_sec = asecmin; mt.tm_isdst = -1; fTimeMin = (long)mktime(&mt); mt.tm_year = ayearmax - 1900; mt.tm_mon = amonthmax-1; mt.tm_mday = adaymax; mt.tm_hour = ahourmax; mt.tm_min = aminmax; mt.tm_sec = asecmax; mt.tm_isdst = -1; fTimeMax = (long)mktime(&mt); Process(); } ///---------------------------------------------------------------- /// Get TGraph time offset due to day light savings time /// messing things up int ITPCGasAnalysis::GetDSTOffset( long atime ){ // convert atime to the kind needed by TGraph // set conversion time. Values of 1 hour // and 2 hour offset seemed to work. tm mt; localtime_r( (const time_t*) &atime, &mt ); //std::cout<<"GetDSTOffset atime="< allT[ 8 ]; // gas analysis quantities int nAnVars = 10; const char * Annames[] = { "H2O (ppm)", "O2 (ppm)", "Ibu Mon (%)", "CO2 (ppm)", "CF4 (%)", "VdIn", "VdOut", "GainIn", "GainOut", "VdInUnc"}; std::vector< float > allAn[ 10 ]; // flow fractions int nFlows = 3; const char * Flownames [] = { "Fraction Ar (%)", "Fraction CF4 (%)", "Fraction iC4H10 (%)"}; std::vector< float > allFlow[3]; // first calculate delta-time for maximum number of samples: long adt; if ( fNSam >0 ){ adt = (fTimeMax-fTimeMin)/fNSam; if (adt<30) adt = 30; // readings are only every so often anyway so set minimum to every 30 seconds } else { // use a default of every 30 sec? adt = 30; } // Build Gas property reader ITPCGas aGas( fTimeMin, fTimeMax ); ITPCGasSmooth aGasSm( fTimeMin, fTimeMax, 7200 ); // use some smoothed quantities long atime = aGas.GetTime(); long astart_time; long aend_time; aGas.GetTimeInterval( astart_time, aend_time ); int nquery = 0; do { if (nquery%1 == 0 ){ std::cout<<"DB Query"< tgs; std::list tcs; // Graphs vs time for (int i=0; iSetMarkerStyle(7); tg->SetMarkerColor(kBlue); char tgname[256]; sprintf( tgname, "%s vs Time; Time; %s",Tnames[i],Tnames[i]); tg->SetTitle(tgname); sprintf( tgname,"Tvst%02d",i); tg->SetName(tgname); tg->GetXaxis()->SetTimeDisplay(1); tg->GetXaxis()->SetTimeFormat("#splitline{%b-%d}{%H:%M}"); tg->GetXaxis()->SetLabelOffset(0.03); tg->GetXaxis()->SetTimeOffset( X0, "gmt"); tg->GetXaxis()->SetNdivisions(507); tg->GetXaxis()->SetLabelSize(0.04); tgs.push_back( tg ); sprintf( tgname,"tcTvst%02d",i); TCanvas * tc = new TCanvas(tgname, tgname); tc->cd(); tg->Draw("AP"); tcs.push_back( tc ); } for (int i=0; iSetMarkerStyle(7); tg->SetMarkerColor(kBlue); char tgname[256]; sprintf( tgname, "%s vs Time; Time; %s",Annames[i],Annames[i]); tg->SetTitle(tgname); sprintf( tgname,"Vvst%02d",i); tg->SetName(tgname);; tg->GetXaxis()->SetTimeDisplay(1); tg->GetXaxis()->SetTimeFormat("#splitline{%b-%d}{%H:%M}"); tg->GetXaxis()->SetLabelOffset(0.03); tg->GetXaxis()->SetTimeOffset( X0, "gmt"); tg->GetXaxis()->SetNdivisions(507); tg->GetXaxis()->SetLabelSize(0.04); tgs.push_back( tg ); sprintf( tgname,"tcVvst%02d",i); TCanvas * tc = new TCanvas(tgname,tgname); tc->cd(); tg->Draw("AP"); tcs.push_back( tc ); } // Graphs vs temperatures for (int itemp=0; itempSetMarkerStyle(7); tg->SetMarkerColor(kBlue); char tgname[256]; sprintf( tgname, "%s vs %s; %s; %s", Annames[ian], Tnames[itemp], Tnames[itemp], Annames[ian] ); tg->SetTitle(tgname); sprintf( tgname,"V%02dvsT%02d",ian,itemp); tg->SetName(tgname); tgs.push_back( tg ); sprintf( tgname,"tcV%02dvsT%02d",ian,itemp); TCanvas * tc = new TCanvas(tgname,tgname); tc->cd(); tg->Draw("AP"); tcs.push_back( tc ); } } // Last added plots of fractional Flows vs time for (int i=0; iSetMarkerStyle(7); tg->SetMarkerColor(kBlue); char tgname[256]; sprintf( tgname, "%s vs Time; Time; %s",Flownames[i],Flownames[i]); tg->SetTitle(tgname); sprintf( tgname,"Flowvst%02d",i); tg->SetName(tgname); tg->GetXaxis()->SetTimeDisplay(1); tg->GetXaxis()->SetTimeFormat("#splitline{%b-%d}{%H:%M}"); tg->GetXaxis()->SetLabelOffset(0.03); tg->GetXaxis()->SetTimeOffset( X0, "gmt"); tg->GetXaxis()->SetNdivisions(507); tg->GetXaxis()->SetLabelSize(0.04); tgs.push_back( tg ); sprintf( tgname,"tcFlowvst%02d",i); TCanvas * tc = new TCanvas(tgname,tgname); tc->cd(); tg->Draw("AP"); tcs.push_back( tc ); } // write plots to file fout.cd(); for ( list::iterator it = tgs.begin(); it != tgs.end(); it++) { (*it)->Write(); } char apngname[256]; for ( list::iterator it = tcs.begin(); it != tcs.end(); it++) { sprintf(apngname,"%s.png",(*it)->GetName()); (*it)->Print(apngname); (*it)->Write(); } // close file fout.Close(); // make second file of plots vs time aGasSm.Plot(); }