Functions | Variables
POTSpillRate Namespace Reference

Functions

def get_spills (day, deltaDay, beam)
 
def num_spills_between (t0, t1, spills)
 
def main ()
 

Variables

 view = sys.argv[1]
 
 beam = str("numi")
 
int ndays = -1
 
int interval = -1
 
string BASE_DIR = "/nusoft/app/web/htdoc/nova/datacheck/nearline/data/"
 
 beamStruct = BeamStruct()
 
 f = TFile(BASE_DIR + 'POTSpillRateDay.root','RECREATE')
 
 tree = TTree('BeamMetrics','POTtree')
 

Detailed Description

  Compute average delivered POT during a given time range
  Justin Vasel (jvasel@fnal.gov)

Function Documentation

def POTSpillRate.get_spills (   day,
  deltaDay,
  beam 
)
Get info about spills during a particular day

  Args:
  day : A datetime object
  deltaDay : Number of days to consider

  Returns:
  spills : A list of spills (time in sec, pot number in 1E+12)

Definition at line 113 of file POTSpillRate.py.

References check_time_usage.float, novadaq::HexUtils.format(), and runNovaSAM.str.

Referenced by main().

113 def get_spills(day, deltaDay, beam):
114  """ Get info about spills during a particular day
115 
116  Args:
117  day : A datetime object
118  deltaDay : Number of days to consider
119 
120  Returns:
121  spills : A list of spills (time in sec, pot number in 1E+12)
122  """
123 
124  # Initialize list of spills
125  spills = []
126 
127  # Convert start and end of day to UNIX timestamp. We must explicitly specify
128  # the UTC timezone (+00:00) because the ifb data server uses CST (-06:00) as
129  # the default
130  t0 = str(day.isoformat('T')) + "+00:00"
131  t1 = str((day + timedelta(days = deltaDay)).isoformat('T')) + "+00:00"
132 
133  print "Getting spills for the period between {} and {}".format(t0,t1)
134 
135  # URL where the spill data live
136  if beam == str("numi"):
137  url = 'http://ifb-data.fnal.gov:8099/ifbeam/data/data?'\
138  'v=E:TRTGTD&e=e,a9&'\
139  't0={}&t1={}&&f=csv'.format(t0, t1)
140  elif beam == str("bnb"):
141  url = 'http://ifb-data.fnal.gov:8099/ifbeam/data/data?'\
142  'v=E:TOR860&e=e,1d&'\
143  't0={}&t1={}&&f=csv'.format(t0, t1)
144 
145  print "URL: {}".format(url)
146 
147  # Store the HTTP GET response here
148  response = None
149 
150  print "Trying for a response...",
151 
152  # Try to retrieve the URL contents. If this fails three times, then
153  # give up and return an empty array.
154  try:
155  response = urllib2.urlopen(url, None, 200)
156  except:
157  print "No response. Trying again..."
158  try:
159  response = urllib2.urlopen(url, None, 200)
160  except:
161  print "No response. Trying again..."
162  try:
163  response = urllib2.urlopen(url, None, 200)
164  except:
165  print "No response. Will not try again."
166  sys.exit()
167 
168  if (response == None):
169  return spills
170 
171  # Use csv module to parse the response as CSV
172  csvdata = csv.reader(response)
173  print "SUCCESS"
174 
175  # The response will look like this:
176  # "e,a9", E:TRTGTD, 1406851201047, E12, 22.0598346211
177  # We are interested in the third column (unix timestamp in ms)
178  # and the fifth column (value). The list will be populated with these
179  # values.
180  print "Importing Spills..."
181  if beam == str("numi"):
182  for row in csvdata:
183  if (row.count('E:TRTGTD') > 0):
184  if (row[4] != 'null'):
185  spills.append( (float(row[2]) / 1000., float(row[4])) )
186 
187  elif beam == str("bnb"):
188  for row in csvdata:
189  if (row.count('E:TOR860') > 0):
190  if (row[4] != 'null'):
191  spills.append( (float(row[2]) / 1000., float(row[4])) )
192  print "DONE"
193 
194  # Return spill info
195  return spills
196 
197 #.......................................................................
def get_spills(day, deltaDay, beam)
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
def POTSpillRate.main ( )

1D plots hits vs w //

Definition at line 231 of file POTSpillRate.py.

References check_time_usage.float, novadaq::HexUtils.format(), get_spills(), makeTrainCVSamples.int, num_spills_between(), and PandAna.Demos.demo1.range.

231 def main():
232 
233  # Set startTime and currentTime to now
234  # (startTime is a constant; currenTime is variable).
235  startTime = datetime.utcnow()
236  currentTime = startTime
237 
238  # Loop over days
239  for i in range(1, int(ndays) + 1):
240  print "DAY {} of {}".format(i, ndays)
241  print "====================="
242 
243  # Get two days worth of spills (we'll only use a subset of this)
244  spills = get_spills(startTime - timedelta(days = i), 2, beam)
245 
246  # Get number of time steps
247  nsteps = int(math.floor(ndays * 24 * 60 / interval))
248 
249  print "Begin looping over {} intervals of {} minutes each".format(nsteps, interval)
250 
251  # Loop over steps in day
252  for j in range(0, int(nsteps / ndays)):
253  # Find total number of spills in this timestep
254  spillTotal = num_spills_between(currentTime - timedelta(minutes = interval), currentTime, spills)
255 
256  # Calculate spill rate (spills per second)
257  spillRate = spillTotal * 1.0 / (interval * 60)
258 
259  # Pring spill rate to screen
260  print spillRate
261 
262  # Fill ROOT branches/tree
263  beamStruct.Time = int((currentTime - datetime(1970,1,1)).total_seconds())
264  beamStruct.Beam = float(spillRate)
265  tree.Fill()
266 
267  # Advance to next timestep
268  currentTime = currentTime - timedelta(minutes = interval)
269 
270  print "\n"
271 
272  f.Write()
273  f.Close()
274 
275 
276 
277 # Prevent execution on import
def get_spills(day, deltaDay, beam)
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
def num_spills_between(t0, t1, spills)
def POTSpillRate.num_spills_between (   t0,
  t1,
  spills 
)
Determines the number of POT in a given time interval

  Args:
  t0     : A datetime object
  t1     : A datetime object
  spills : A list of spills

  Returns:
  potTotal : int

Definition at line 198 of file POTSpillRate.py.

References DCS_db_parser.database_connect(), novadaq::HexUtils.format(), runNovaSAM.str, and POTGetData.unix_timestamp().

Referenced by main().

198 def num_spills_between(t0, t1, spills):
199  """ Determines the number of POT in a given time interval
200 
201  Args:
202  t0 : A datetime object
203  t1 : A datetime object
204  spills : A list of spills
205 
206  Returns:
207  potTotal : int
208  """
209 
210  # Initiate connection to psql database
211  database_connect(beam)
212 
213  print "Couting spills between {} and {}: ".format(str(t0.isoformat('T')),str(t1.isoformat('T'))),
214 
215  # Convert to unix timestamps
216  t0 = unix_timestamp(t0)
217  t1 = unix_timestamp(t1)
218 
219  # initialize counter
220  counter = 0
221 
222  # Loop over spills, but only count the ones that fall into the
223  # appropriate time window.
224  for (time, value) in spills:
225  if ((time >= t0) & (time <= t1)):
226  counter = counter + 1
227 
228  return counter
229 
230 #.......................................................................
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
def unix_timestamp(input)
Definition: POTGetData.py:46
def database_connect()
def num_spills_between(t0, t1, spills)

Variable Documentation

string POTSpillRate.BASE_DIR = "/nusoft/app/web/htdoc/nova/datacheck/nearline/data/"

Definition at line 48 of file POTSpillRate.py.

POTSpillRate.beam = str("numi")

Definition at line 40 of file POTSpillRate.py.

Referenced by accum_nue_numu_equivalent(), accum_nue_numu_equivalent_fhc(), accum_nue_numu_equivalent_rhc(), caf::CAFMaker.AddMCTruthToVec(), Ana2018_box_opening_macro(), caf::Proxy< caf::SRNeutrino >.CheckEquals(), CosmicPred(), generate_fake_data(), ana2019::fakedata.Get2019Prediction(), get_numi_data_histogram(), get_spectra_2dplots(), GetNuePrediction2018(), GetNuePrediction2019(), ana.GetNuePrediction2020(), ana.GetNueQuantCuts2020(), GetNumuCosmics2018(), GetNumuCosmics2019(), ana.GetNumuCosmics2020(), GetNumuData2018(), GetNumuData2019(), ana.GetNumuData2020(), ana.GetNumuEhadFracQuantCuts2020(), GetNumuPredictions2018(), GetNumuPredictions2019(), ana.GetNumuPredictions2020(), ana.GetNumuPtQuantCuts2020(), cmf::ShifterAndWeighter.HornNormWeight(), fnex::ShifterAndWeighter.HornNormWeight(), cmf::CalibSyst.LoadCalibSystRatios(), ana::PredictionSystJoint2018.LoadFrom(), ana::PredictionSystJointDemo.LoadFrom(), make_eff_plots_areaNorm(), make_fc_mass_and_oct_nersc_2018(), make_fc_mass_and_oct_nersc_2019(), make_fc_mh_nersc_2018(), make_fc_mh_nersc_2019(), make_fc_nus_surfs_nersc_2018(), make_fc_nus_surfs_nersc_2019(), make_fc_oct_nersc_2018(), make_fc_oct_nersc_2019(), make_fc_slices_nersc_2018(), make_fc_slices_nersc_2018_stats(), make_fc_slices_nersc_2019(), make_fc_surfaces_2020(), make_fc_surfaces_2020_validation(), make_fc_surfaces_nersc_2018(), make_fc_surfaces_nersc_2018_stats(), make_fc_surfaces_nersc_2019(), MakeBkgEMPlot(), MakeDQValidityCSVND(), mec_tuning_fitter_2020(), mec_tuning_preds_2020(), monoprob(), NueExtrap(), NumuCosmic(), NumuExtrap(), caf::Proxy< caf::SRNeutrino >.operator=(), plot_spectra_2dplots(), pred_debug(), systematics_extrap_comp_from_pred_interp(), systematics_summary_from_pred_interp(), test_predInterp_debug(), and ana2019::TieredAnaObjStorage< StorageType >.TieredAnaObjStorage().

POTSpillRate.beamStruct = BeamStruct()

Definition at line 53 of file POTSpillRate.py.

POTSpillRate.f = TFile(BASE_DIR + 'POTSpillRateDay.root','RECREATE')

Definition at line 58 of file POTSpillRate.py.

int POTSpillRate.interval = -1

Definition at line 46 of file POTSpillRate.py.

Referenced by stan::mcmc::chains< RNG >.central_interval(), and TEST_F().

int POTSpillRate.ndays = -1

Definition at line 45 of file POTSpillRate.py.

POTSpillRate.tree = TTree('BeamMetrics','POTtree')

Definition at line 107 of file POTSpillRate.py.

POTSpillRate.view = sys.argv[1]

Definition at line 39 of file POTSpillRate.py.

Referenced by cvn::RegPixelMap.Add(), cvn::PixelMap.Add(), fuzz::FuzzyKVertex.AddProng(), calib::ThresholdAna.analyze(), chaninfo::CosmicEff.analyze(), comi::CosmicMetrics.analyze(), mcchk::DetAna.analyze(), dprf::ChannelPlots.analyze(), dprf::TrackPlots.analyze(), align::Alignment.analyze(), sn::SupernovaAna.analyze(), comi::NumiFilteringAna.analyze(), showere::ShowerEnergyAna.analyze(), novaddt::UpMuAna.analyze(), remid::ReMIdDedxRock.analyze(), remid::ReMIdDedxFD.analyze(), remid::ReMIdDedxStudies.analyze(), upmuana::UpMuRecoAna.analyze(), upmuana::UpMuAnalysis.analyze(), htk::HoughTrack.analyze(), avgefficiency(), calib::FindOutliers.beginJob(), comi::CosmicMetrics.beginJob(), calib::MuonTrackHits.beginJob(), calib::ThresholdAna.beginRun(), dprf::ChannelPlots.beginRun(), calib::CosmicCalib.beginRun(), dprf::TrackPlots.beginRun(), calib::MakeAttenuationProfiles.beginRun(), calib::DriftResponseCalc.beginRun(), calib.BestPathEstimates(), cvn::Boundary.Boundary(), noe.build_cell_lookup_table(), CalcCluster(), supernova::sliceAna.CalculatePCorr(), trk::KalmanTrackMerge.CanJoinTracks(), slid::NuEEnergyAlg.CellEnergy(), dt::Chunk.CellMeasurements(), dt::Chunk.CellPoints(), caf::Proxy< caf::SRShower >.CheckEquals(), caf::Proxy< caf::SRMRProperties >.CheckEquals(), caf::Proxy< caf::SRTrack >.CheckEquals(), caf::Proxy< caf::SRProng >.CheckEquals(), cheat::RecoCheckAna.CheckRecoClusters(), trk::KalmanTrackAna.CheckRecoTracks(), art::Wrapper< T >.Class_Version(), murem::TrackCleanUpAlg.CleanUpTrack(), geo::GeometryBase.ClosestApproach(), murem::TrackCleanUpAlg.ComputeVertexRegion(), calib::AttenFit.ConsolidateViews(), calib::AttenuationFit.ConsolidateViews(), cvn::RegCVNImageUtils.ConvertChargeVectorsToViewVectors(), geo::GeometryBase.CountCellsOnLine(), geo::GeometryBase.CountCellsOnLineFast(), trk::KalmanGeoHelper.CountMissedCellsOnLine(), cvn::PixelMapProducer.CreateMapGivenBoundary(), cvn::RegPixelMapProducer.CreateMapGivenShowerVertex(), cvn::RegPixelMapProducer.CreateMapGivenVertex(), lem.DefaultVertex(), evd::GeometryDrawer.DrawBadBoxesPretty(), evd::GeometryDrawer.DrawCells2D(), evd::GeometryDrawer.DrawDCMBoxes(), evd::GeometryDrawer.DrawHighlightCell(), eff_plots(), efficiency(), calib::AttenFit.endJob(), calib::FindOutliers.endRun(), comi::ChanOcc.endSubRun(), calib::AttenFit.expFit(), calib::AttenuationFit.expFit(), dt::ViewMerger.FakeThirdDimension(), om::PlotClickHandler.FEButcInfo(), novaddt::Merge2DTracks.fillDummyTracks(), hv::HoughVertexAlg.FillMaps(), skim::CosmicBeamComparison.FillNumuHistograms(), calib::CosmicCalib.FillPathLengthInfo(), calib::MakeAttenuationProfiles.FillPathLengthInfo(), lem.FillPotential(), trk::CosmicTrackAna.FillTrackHistograms(), novaddt::NuMuTrigger.filter(), comi::NumiFiltering.filter(), showere::ShowerEnergyFilterMC.filter(), mono::MonopoleTrack.filter(), novaddt::UpMuTrigger.filter(), calib::MuonTrackHits.filter(), mono::MonopoleCluster.find_isolated_hits(), calib.FindBelowThresholdCalibCandidates(), cvn::RegPixelMapProducer.FindCenterMedian(), cvn::PixelMapProducer.FindCenterMedian(), dt::DiscreteTracker.FindVertex(), cvn::Boundary.FirstCell(), calib::AttenFit.fit_channel_prof(), calib::AttenuationFit.fit_channel_prof(), fit_thresh_corrs(), fit_thresh_corrs_fb(), tut::TutProducer.FitPhoton(), evd::SimulationDrawer.FLSHit2D(), nuesand::FillNueSandbox.FracAngChanges(), nuesand::FillNueSandbox.FracModalHits(), jmshower::RecoJMShower.GetCellDistToPoint(), jmshower::RecoJMShower.GetCellDistToTrk(), calib::MakeAttenuationProfiles.GetChannelHists(), calib::MakeAttenuationProfiles.GetChannelProfiles(), evd::RecoBaseDrawer.GetClusterOutlines(), evd::RecoBaseDrawer.GetClusterOutlinesConvexHull(), evd::GeometryDrawer.GetDCMBoxes(), evd::SimulationDrawer.GetLimits(), geo::GeometryBase.GetPigtail(), geo::GeometryBase.getPlaneAndCellID(), calib::Calibrator.GetTimeStamp(), jmshower::JMShower.GetTransHits(), jmshower::RecoJMShower.GetTrkHitPos(), jmshower::RecoJMShower.GetTrkPlaneCell(), calib::ThresholdAna.GetView(), cmap::dataprov::CMap.getView(), calib::CosmicCalib.GetView(), calib::MakeAttenuationProfiles.GetView(), calib::AttenFit.GetView(), calib::AttenuationFit.GetView(), cvn::RegPixelMap.GlobalToIndex(), cvn::RegPixelMap.GlobalToIndexSingle(), slid::NuEEnergyAlg.HadronicDepEnergy(), bpfit.HighestPIDTrack(), remid.HighestPIDTrack(), mono::MonopoleTrack.hit_is_on_track(), cheat::BackTracker.HitCollectionPurity(), om::PlotClickHandler.HwDCMHistogramInfo(), om::PlotClickHandler.HwDetHistogramInfo(), om::PlotClickHandler.HwPCHistogramInfoX(), om::PlotClickHandler.HwPCHistogramInfoY(), cvn::Boundary.IsWithin(), cvn::Boundary.LastCell(), numue::NumuEAlg.LongestTrack(), calib::AttenFit.lowessFit(), calib::AttenuationFit.lowessFit(), main(), airshower::AirSlicer.MakeTrackSlices(), trk::KalmanGeoHelper.MatchTrajectoryToPlaneInView(), rb::Cluster.MinMaxMeanXYZ(), numue::NumuEAlg.MuonEnergies(), cvn::RegPixelMap.NInput(), cvn::PixelMap.NInput(), slid::NuEEnergyAlg.NonStdCellEnergy(), evd::RecoBaseDrawer.OfflineChans2D(), dt::Chunk.operator<(), mono.operator<<(), caf::Proxy< caf::SRShower >.operator=(), caf::Proxy< caf::SRMRProperties >.operator=(), caf::Proxy< caf::SRTrack >.operator=(), caf::Proxy< caf::SRProng >.operator=(), slid::ParticleIDAlg.PlaneHitCell(), plot(), plot_abstree(), plot_assess(), plot_assess_nd(), plot_assess_pretty(), plot_assess_pretty_nd(), plot_thresholds(), plotmodulewise(), ddthelpers.print(), novaddt::RemoveOneDSlices.printDDTSlice(), novaddt::RemoveSpatialNoise.printDDTSlice(), novaddt::ContainedSlice.printDDTSlices(), printEventToJson(), calib::PCHitsList.ProcessTrackForBelowThresholdHits(), nuesand::FillNueSandbox.produce(), novaddt::TrackFit.produce(), jmshower::JMTrackMerge.produce(), cvn::CVNCosmicMapper.produce(), earms::ElasticArmsHS.produce(), dt::DiscreteTracker.produce(), jmshower::JMClusterMerge.produce(), vdt::VertexDT.produce(), cvntf::CVNProngEvaluatorTF.produce(), cheat::MCCheater.produce(), remid::RecoMuon.produce(), rb::Prong.Prong(), novaddt::RemoveSpatialNoise.pruneOutlyingCells(), jmshower::RecoJMShower.RecoShowers(), trk::RLFit.RLFit(), calib::AttenFit.rolloffFit(), calib::AttenuationFit.rolloffFit(), RunCalibration(), screen_to_activetrack(), screen_to_activevertex(), earms::ElasticArms.SetHit(), rb::CellHit.SetView(), trk::WindowTrackingAlg.ShortTrack(), novaddt::Merge2DTracks.simpleMerge(), lem::MakeLibrary.SliceMeanPosEWeighted(), DAQChannelMapTests.testViewLookups(), calib::ThresholdCorrMap.ThresholdCorrAt(), calib::ThresholdCorrMap.ThresholdCorrMap(), thresholdshadowing(), cvn::PixelMap.ToFile(), dt::Chain.ToTrack(), rb::Track.Track(), calib::AttenCache.TranslateChannelData(), uncorrected_PE(), slid::NuEEnergyAlg.VertexEnergy(), rb::WeightedProng.WeightedProng(), novaddt::DDTEvd.WriteHitListInfo(), moonshadowana::MoonShadowAna.WriteHitListInfo(), moonshadowana::MoonShadowAnaHough.WriteHitListInfo(), calib::AttenuationFit.writeResults(), and rect.xmax().