/// Class to hold Gas Properties inside TPC /// at a particular time /// Blair Jamieson (C) 2009, 2010 #include #include #include "ITPCGas.hxx" ///-------------------------------------------------------------------- /// build new TTPC Gas reading with intended time range of use specified ITPCGas::ITPCGas( long autimemin, long autimemax ){ fTime = autimemin; fStartTime = autimemin; fEndTime = autimemax; fDebug = false; fTimeStamp = 0x0; Init(); } ///-------------------------------------------------------------------- /// build new TTPC Gas reading with intended time range of use specified ITPCGas::ITPCGas( int ayearmin, int amonthmin, int adaymin, int ahourmin, int aminmin, int asecmin, int ayearmax, int amonthmax, int adaymax, int ahourmax, int aminmax, int asecmax ){ fTimeStamp=0x0; fDebug = false; SetTimeNoRead(ayearmax, amonthmax, adaymax, ahourmax, aminmax, asecmax); fEndTime = fTime; SetTimeNoRead(ayearmin, amonthmin, adaymin, ahourmin, aminmin, asecmin); fStartTime = fTime; Init(); } /// Initialize gas properties object void ITPCGas::Init(){ // set up the field names SetupFieldNames(); fPlca_vec.clear(); // set timestamp of when Jordan implemented isobutane T, P corrections in PLC fIbuCorTime = GetUnixTime( 2010, 3, 4, 16, 14 ); // set timestamp of when Jordan implemented gas analyzer T, P corrections in PLC // 03/25/2010 ~13:40:30 fAnalyzerCorTime = GetUnixTime( 2010, 3, 25, 13, 40, 30 ); // set timestamp of when Jordan changed gas analyzer T, P corrections to P/T in PLC // 05/2/2010 ~22:59 fAnalyzerCorTime2 = GetUnixTime( 2010, 5, 2, 22, 59 ); // Now read gas properties Read(); } ///-------------------------------------------------------------------- /// Setup vectors of strings for field names /// that will be querried in the database void ITPCGas::SetupFieldNames(){ fPlca_names.clear(); fTpc1_names.clear(); fTpc2_names.clear(); fTpc3_names.clear(); fVda_names.clear(); fVdb_names.clear(); fGa_names.clear(); fGb_names.clear(); fPlca_names.push_back("d0fc1_rdflow_plca"); fPlca_names.push_back("d0fc2_rdflow_plca"); fPlca_names.push_back("d0fc3_rdflow_plca"); fPlca_names.push_back("d2pa1_rdpress_plca"); fPlca_names.push_back("g1pd1_rdpress_plca"); fPlca_names.push_back("d1pd1_rdpress_plca"); fPlca_names.push_back("d0pd4_rdpress_plca"); fPlca_names.push_back("a0an1_rdmon_plca"); fPlca_names.push_back("a0an2_rdmon_plca"); fPlca_names.push_back("d0an1_rdmon_plca"); fPlca_names.push_back("a0an3_rdmon_plca"); fPlca_names.push_back("a0an3b_rdmon_plca"); fPlca_names.push_back("a0an3c_rdmon_plca"); fPlca_names.push_back("a0an2b_rdmon_plca"); fPlca_names.push_back("d0tc1_rdtemp_plca"); fPlca_names.push_back("d0tc2_rdtemp_plca"); fPlca_names.push_back("d0tc3_rdtemp_plca"); fPlca_names.push_back("d0tc4_rdtemp_plca"); fPlca_names.push_back("d0tc5_rdtemp_plca"); fPlca_names.push_back("p0tc1_rdtemp_plca"); fPlca_names.push_back("p0tc2_rdtemp_plca"); fPlca_names.push_back("p0tc3_rdtemp_plca"); fPlca_names.push_back("p0tc4_rdtemp_plca"); fPlca_names.push_back("p0tc5_rdtemp_plca"); fPlca_names.push_back("p0tc6_rdtemp_plca"); fPlca_names.push_back("dxtc1_rdtemp_plca"); fPlca_names.push_back("dxtc2_rdtemp_plca"); fTpc1_names.push_back("tr0agasmanleft_tpc1"); fTpc1_names.push_back("tr0agasmanright_tpc1"); fTpc1_names.push_back("tr1agasmanleft_tpc1"); fTpc1_names.push_back("tr1agasmanright_tpc1"); fTpc2_names.push_back("tr0agasmanleft_tpc2"); fTpc2_names.push_back("tr0agasmanright_tpc2"); fTpc2_names.push_back("tr1agasmanleft_tpc2"); fTpc2_names.push_back("tr1agasmanright_tpc2"); fTpc3_names.push_back("tr0agasmanleft_tpc3"); fTpc3_names.push_back("tr0agasmanright_tpc3"); fTpc3_names.push_back("tr1agasmanleft_tpc3"); fTpc3_names.push_back("tr1agasmanright_tpc3"); fVda_names.push_back("mean_vda") ; fVda_names.push_back("sigma_vda") ; fVdb_names.push_back("mean_vdb") ; fVdb_names.push_back("sigma_vdb") ; fGa_names.push_back("mean_ga") ; fGa_names.push_back("sigma_ga") ; fGb_names.push_back("mean_gb") ; fGb_names.push_back("sigma_gb") ; return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Plca(){ /// read next 500 entries starting from 5 minutes ago long astart = fTime - 300; fPlca_vec.clear(); fPlca_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "tpcgasplc_plca", fPlca_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Tpc1(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 300; fTpc1_vec.clear(); fTpc1_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "tpc1temp_tpc1", fTpc1_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Tpc2(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 300; fTpc2_vec.clear(); fTpc2_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "tpc2temp_tpc2", fTpc2_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Tpc3(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 300; fTpc3_vec.clear(); fTpc3_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "tpc3temp_tpc3", fTpc3_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Vda(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 1000; fVda_vec.clear(); fVda_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "gasmonchamber_vda", fVda_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Vdb(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 1000; fVdb_vec.clear(); fVdb_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "gasmonchamber_vdb", fVdb_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Ga(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 2000; fGa_vec.clear(); fGa_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "gasmonchamber_ga", fGa_names, 100 ); return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCGas::ReadSlowDB_Gb(){ /// read next 500 entries starting from 10 minutes ago long astart = fTime - 2000; fGb_vec.clear(); fGb_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "gasmonchamber_gb", fGb_names, 100 ); return; } ///-------------------------------------------------------------------- /// Print out the values for the current time void ITPCGas::Print(){ std::cout<<" Record for "< fPlca_idx+2 ){ start_time = (long) fPlca_vec[ fPlca_idx ].first; end_time = (long) fPlca_vec[ fPlca_idx+1 ].first; } else if ( fPlca_vec.size() < 2 ){ end_time = fEndTime+1; } return; } ///-------------------------------------------------------------------- /// Get unix time long ITPCGas::GetUnixTime( int ayear, int amonth, int aday, int ahour, int amin, int asec){ tm mt; // use time structure from time.h // to build unix time from year,month, etc. mt.tm_year = ayear - 1900; mt.tm_mon = amonth-1; mt.tm_mday = aday; mt.tm_hour = ahour; mt.tm_min = amin; mt.tm_sec = asec; mt.tm_isdst = -1; return (long)mktime(&mt); } ///-------------------------------------------------------------------- /// Set the time for this object void ITPCGas::SetTimeNoRead( int ayear, int amonth, int aday, int ahour, int amin, int asec){ fTime = (int)GetUnixTime(ayear, amonth, aday, ahour, amin, asec ); //std::cout<<"SetTimeNoRead "< 0.0 ) aT = fTO2; float aP = fPatm*1000.0; // Isobutane analyzer corrections. if ( fTime < fIbuCorTime ){ // pressure correction always done by PLC, just need to // include temperature correction... fIbuMon = TMath::Log( fIbuMon / 0.286 ) / 0.1564; // now do overall calib fIbuMon = 0.286*TMath::Exp( 0.1564*( fIbuMon - 0.1967*(aT-29.19) ) ) ; } // Main gas analyzer corrections. // First undo any corrections applied in PLC if ( fTime < fAnalyzerCorTime ) { // no corrections were done } else { // first step is to undo cross term corrections fCO2An = UnCorrectCO2( fCO2An, 2.0, fCF4An ); fCF4An = UnCorrectCF4( fCF4An, 2.0 ); // now undo temperature or pressure correction... // depending on date if ( fTime < fAnalyzerCorTime2 ){ // undo older temperature only correction fCF4An -= 0.0438 * aT - 0.625; fCO2An -= 12.94 * aT - 250.0; } else { fCF4An -= -2.962 * aP/(aT+273.15) + 10.71; fCO2An -= -901.8 * aP/(aT+273.15) + 3165.0; } } // Apply the new temperature correction // P/T correction seemed about right for CF4, now add slight T only correction fCF4An += -2.0 * aP/(aT+273.15) + 6.8 + 0.0213*aT; // CO2 is dominated by temperature correction fCO2An += 0.036 * fCO2An * (aT-20) + 8.287 * aT - 1.47 * aP + 1327.3; // now do cross term corrections fCF4An = CorrectCF4( fCF4An, 2.0 ); fCO2An = CorrectCO2( fCO2An, 2.0, fCF4An ); // Apply corrections to gain and drift velocity fVdIn += 4.0 * aP / (aT+273.15) - 14.0; fVdOut += 4.0 * aP / (aT+273.15) - 14.0; fGainIn += 2350.0 * aP / (aT+273.15) - 8225.0; fGainOut += 2350.0 * aP / (aT+273.15) - 8225.0; } ///------------------------------------------------------------------------ /// Get index into each of the vectors of database query /// results for the current time void ITPCGas::UpdateVectorTimeIdx(){ // Find index for current time for PLCA fPlca_isok = false; if ( fPlca_vec.size()==1 ){ fPlca_idx = 0; fPlca_isok = true; } else { for (int i=0; i= long( (fPlca_vec[i].first) ) && fTime < long( (fPlca_vec[i+1].first) ) ) { fPlca_idx = i; fPlca_isok = true; break; } } } //if (fPlca_isok==false) std::cout<<"Plca_isok==false for "<= long( (fTpc1_vec[i].first) ) && fTime < long( (fTpc1_vec[i+1].first) ) ) { fTpc1_idx = i; fTpc1_isok = true; break; } } } //if (fTpc1_isok==false) std::cout<<"fTpc1_isok==false for "<= long( (fTpc2_vec[i].first) ) && fTime < long( (fTpc2_vec[i+1].first) ) ) { fTpc2_idx = i; fTpc2_isok = true; break; } } } //if (fTpc2_isok==false) std::cout<<"fTpc2_isok==false for "<= long( (fTpc3_vec[i].first) ) && fTime < long( (fTpc3_vec[i+1].first) ) ) { fTpc3_idx = i; fTpc3_isok = true; break; } } } //if (fTpc3_isok==false) std::cout<<"fTpc3_isok==false for "<= long( (fVda_vec[i].first) ) && fTime < long( (fVda_vec[i+1].first) ) ) { fVda_idx = i; fVda_isok = true; break; } } } //if (fVda_isok==false) std::cout<<"fVda_isok==false for "<= long( (fVdb_vec[i].first) ) && fTime < long( (fVdb_vec[i+1].first) ) ) { fVdb_idx = i; fVdb_isok = true; break; } } } //if (fVdb_isok==false) std::cout<<"fVdb_isok==false for "<= long( (fGa_vec[i].first) ) && fTime < long( (fGa_vec[i+1].first) ) ) { fGa_idx = i; fGa_isok = true; break; } } } //if (fGa_isok==false) std::cout<<"fGa_isok==false for "< "< long( fPlca_vec[ fPlca_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Plca"< long( fTpc1_vec[ fTpc1_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Tpc1"< long( fTpc2_vec[ fTpc2_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Tpc2"< long( fTpc3_vec[ fTpc3_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Tpc3"< long( fVda_vec[ fVda_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Vda"< long( fVdb_vec[ fVdb_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Vdb"< long( fGa_vec[ fGa_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Ga"< long( fGb_vec[ fGb_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Gb"<0.1 && tman[ii] < 60.0 ){ nman++; fTTPC1+=tman[ii]; } } if (nman>0) fTTPC1 /= float(nman); else fTTPC1 = -273.; } if ( fTpc2_isok == true ) { tman[0] = fTpc2_vec[ fTpc2_idx ].second[0]; tman[1] = fTpc2_vec[ fTpc2_idx ].second[1]; tman[2] = fTpc2_vec[ fTpc2_idx ].second[2]; tman[3] = fTpc2_vec[ fTpc2_idx ].second[3]; fTTPC2 = 0; nman=0; for (int ii=0;ii<4;ii++){ if ( tman[ii]>0.1 && tman[ii] < 60.0 ){ nman++; fTTPC2+=tman[ii]; } } if (nman>0) fTTPC2 /= float(nman); else fTTPC2 = -273.; } if ( fTpc3_isok == true ) { tman[0] = fTpc3_vec[ fTpc3_idx ].second[0]; tman[1] = fTpc3_vec[ fTpc3_idx ].second[1]; tman[2] = fTpc3_vec[ fTpc3_idx ].second[2]; tman[3] = fTpc3_vec[ fTpc3_idx ].second[3]; fTTPC3 = 0; nman=0; for (int ii=0;ii<4;ii++){ if ( tman[ii]>0.1 && tman[ii] < 60.0 ){ nman++; fTTPC3+=tman[ii]; } } if (nman>0) fTTPC3 /= float(nman); else fTTPC3 = -273.; } // Read monitor chamber drift information if ( fVdb_isok == true ){ fVdIn = fVdb_vec[ fVdb_idx ].second[0]; fVdInUnc = fVdb_vec[ fVdb_idx ].second[1]; } if ( fVda_isok == true ){ fVdOut = fVda_vec[ fVda_idx ].second[0]; fVdOutUnc= fVda_vec[ fVda_idx ].second[1]; } if ( fGb_isok == true ){ fGainIn = fGb_vec[ fGb_idx ].second[0]; fGainInUnc = fGb_vec[ fGb_idx ].second[1]; } if ( fGa_isok == true ){ fGainOut = fGa_vec[ fGa_idx ].second[0]; fGainOutUnc= fGa_vec[ fGa_idx ].second[1]; } // check if gas analyzer corrections are done here // or if they were already done by the PLC // note that between (March 25,2010 13:40) and (May 2, 2010 22:59) // the correction was not final version, but it is too // tricky to uncorrect then correct it, so not optimal. if ( fPlca_isok == true ) ApplyCorrections(); if (fDebug){ // Time check: long db_time = (long)ISlowControlDatabase::Get().QueryShowField(fTime,"tpcgasplc_plca","_i_time"); std::cout << ""< fEnd){ amult = 1; fTime = fTime + adeltat; } else { if ( fEnd+1 <= fTime ){ // handle case where no readings for a while amult*=2; fTime += amult; } else { amult = 1; fTime = fEnd+1; } } Read(); return 1; }