Newer
Older
TestStandRepository / Software / TbNtupleMaker / Alibava / Tracer.cc
@Federica Lionetto Federica Lionetto on 7 Oct 2014 821 bytes Added Software, Data, and AnalysisResults folders
  1. #include <TH1.h>
  2.  
  3. #include "Tracer.h"
  4.  
  5. Tracer::Tracer(const char *name, const char *title, int npts, int avrg)
  6. : size(npts), average(avrg), cntr(0.), val(0.)
  7. {
  8. hst = new TH1D(name, title, size, 0, size);
  9. }
  10.  
  11. Tracer::~Tracer()
  12. {
  13. delete hst;
  14. }
  15.  
  16. void Tracer::Draw(const char *opt)
  17. {
  18. hst->Draw(opt);
  19. }
  20.  
  21. void Tracer::fill(double x)
  22. {
  23. if (average>1.)
  24. {
  25. val = (x + cntr*val)/(++cntr);
  26. if ( (int(cntr)%average)==0 )
  27. {
  28. add_point(val);
  29. }
  30. }
  31. else
  32. add_point(x);
  33. }
  34.  
  35. void Tracer::add_point(double x)
  36. {
  37. queue.push_back(x);
  38. if (queue.size()>size)
  39. queue.pop_front();
  40. std::deque<double>::iterator ip;
  41. int ibin = 1;
  42. for (ip=queue.begin();ip!=queue.end();++ip, ibin++)
  43. {
  44. hst->SetBinContent(ibin, *ip);
  45. }
  46. }