#include #include #include #include #include #include #include using namespace RAT; #include using namespace std; ChannelEfficiency::ChannelEfficiency() { fAverageEfficiency = -1.0; fAveEffPlusOWL = -1.0; } void ChannelEfficiency::BeginOfRun() { const size_t numChannels = DB::Get()->GetLink( "PMT_DQXX" )->GetIArray( "dqch" ).size(); const DU::ChanHWStatus& channelHardwareStatus = DU::Utility::Get()->GetChanHWStatus(); const DU::PMTInfo& pmtInfo = DU::Utility::Get()->GetPMTInfo(); if( numChannels != pmtInfo.GetCount() ) // This happens if the user does a bespoke simulation without a DAQ { warn << "ChannelEfficiency::BeginOfRun: Cannot calculate channel efficiency, different number of physical PMTs to DAQ channels.\n"; return; } fAverageEfficiency = 0.0; fAveEffPlusOWL = 0.0; fChannelEfficiency.resize( numChannels, 0.0 ); size_t activeChannels = 0; size_t activeOWLs = 0; for( size_t lcn = 0; lcn < numChannels; lcn++ ) { const double maxQ = 500.0; const double maxPMTCharge = PMTCharge::Get()->PIntegrate( maxQ, lcn ); // Channel efficiency = integral from threshold to maxQ / integral from zero to maxQ const double channelEfficiency = ( maxPMTCharge - PMTCharge::Get()->PIntegrate( channelHardwareStatus.GetThresholdAboveNoise( lcn ), lcn ) ) / maxPMTCharge; fChannelEfficiency[lcn] = channelEfficiency; if( pmtInfo.GetType( lcn ) == DU::PMTInfo::NORMAL || pmtInfo.GetType( lcn ) == DU::PMTInfo::HQE) // Consider only normal (type == 1) and HQE (type == 7) PMTs for the average { bool onlineChannel = true; if( channelHardwareStatus.IsEnabled() ) onlineChannel = channelHardwareStatus.IsTubeOnline( lcn ); if( onlineChannel ) { fAverageEfficiency += channelEfficiency; fAveEffPlusOWL += channelEfficiency; activeChannels++; } } if(pmtInfo.GetType(lcn) == DU::PMTInfo::OWL){ // consider OWL tubes bool onlineOWL = true; if(channelHardwareStatus.IsEnabled()) onlineOWL = channelHardwareStatus.IsTubeOnline(lcn); if(onlineOWL){ fAveEffPlusOWL += channelEfficiency; activeOWLs++; } } } fAverageEfficiency /= static_cast( activeChannels ); fAveEffPlusOWL /= static_cast((activeOWLs+activeChannels)); info << "ChannelEfficiency::BeginOfRun: Average channel efficiency across normal tubes is " << fAverageEfficiency << newline; info << "ChannelEfficiency::BeginOfRun: Average channel efficiency across normal + OWLs is "<