Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:45

0001 // @(#)root/roostats:$Id$
0002 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
0003 /*************************************************************************
0004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOSTATS_NumEventsTestStat
0012 #define ROOSTATS_NumEventsTestStat
0013 
0014 
0015 
0016 #include "Rtypes.h"
0017 
0018 
0019 #include "RooRealVar.h"
0020 
0021 #include "RooAbsData.h"
0022 
0023 #include "RooAbsPdf.h"
0024 
0025 #include "RooStats/TestStatistic.h"
0026 
0027 
0028 //#include "RooStats/DistributionCreator.h"
0029 
0030 
0031 namespace RooStats {
0032 
0033    /**
0034 
0035       NumEventsTestStat is a simple implementation of the TestStatistic interface used for simple number counting.
0036       It should probably support simple cuts as well.
0037 
0038       \ingroup Roostats
0039    */
0040 
0041   class NumEventsTestStat : public TestStatistic{
0042 
0043    public:
0044      NumEventsTestStat() : fPdf(nullptr) { }
0045      NumEventsTestStat(RooAbsPdf &pdf) : fPdf(&pdf) {}
0046 
0047      // Main interface to evaluate the test statistic on a dataset
0048      double Evaluate(RooAbsData& data, RooArgSet& /*paramsOfInterest*/) override  {
0049 
0050          if(data.isWeighted()) {
0051             return data.sumEntries();
0052          }
0053 
0054          // if no pdf is given in the constructor, we assume by default it can be extended
0055          if (!fPdf || fPdf->canBeExtended()) {
0056             return data.numEntries();
0057          }
0058 
0059          // data is not weighted as pdf cannot be extended
0060          if(data.numEntries() == 1) {
0061             double numEvents = 0.0;
0062             for (auto const *obs : static_range_cast<RooRealVar *>(*data.get(0))) {
0063                numEvents += obs->getValV();
0064             }
0065             return numEvents;
0066          }
0067 
0068          std::cout << "Data set is invalid" << std::endl;
0069          return 0;
0070      }
0071 
0072       // Get the TestStatistic
0073       virtual const RooAbsArg* GetTestStatistic()  const {return fPdf;}
0074 
0075       const TString GetVarName() const override {return "Number of events";}
0076 
0077 
0078    private:
0079       RooAbsPdf* fPdf;
0080 
0081    protected:
0082       ClassDefOverride(NumEventsTestStat,1)
0083    };
0084 
0085 }
0086 
0087 
0088 #endif