Xephyr  0.0
XeStat.h
1 #ifndef XeStat_h
2 #define XeStat_h
3 
4 #include <fstream>
5 #include "Math/ProbFunc.h"
6 #include "Math/DistFunc.h"
7 #include "Math/Minimizer.h"
8 #include "Math/Factory.h"
9 #include "Math/DistFunc.h"
10 #include <TRandom3.h>
11 #include "XeUtils.h"
12 
13 #include "Math/Functor.h"
14 
15 #include <iomanip>
16 #include <sstream>
17 #include <iostream>
18 #include <vector>
19 #include <set>
20 #include <map>
21 #include <math.h>
22 
23 #include "TCanvas.h"
24 #include "TF1.h"
25 #include "TFile.h"
26 #include "TGraphErrors.h"
27 #include "TGraph.h"
28 #include "TH1F.h"
29 #include "TH2F.h"
30 #include "TLatex.h"
31 #include "TLegend.h"
32 #include "TMath.h"
33 #include "TMultiGraph.h"
34 #include "TROOT.h"
35 #include "TStyle.h"
36 #include "TSystem.h"
37 #include "TTree.h"
38 
39 
40 
41 #define deleteWithPointer(ptr) {if(ptr!=NULL){ delete ptr;ptr=NULL;}}
42 
43 
44 enum content { SPECTRUM
45  , VALUES
46  } ;
47 
48 enum forceType { DO_NOT_FORCE
49  , FORCE_TRUE
50  , FORCE_FALSE
51  } ;
52 
53 enum analysisType { NO_ANALYSIS
54  , PL_ANALYSIS
55  , CUTS_ANALYSIS
56  } ;
57 
58 enum parameterType { PARAMETER_OF_INTEREST
59  , NUISANCE_PARAMETER
60  , FIXED_PARAMETER
61  , FROZEN_PARAMETER
62  , FREE_PARAMETER
63  , N_PARAMETER_TYPES
64  } ;
65 
66 enum sentivityModes { MINUS_TWO_SIGMAS
67  , MINUS_ONE_SIGMA
68  , MEDIAN
69  , PLUS_ONE_SIGMA
70  , PLUS_TWO_SIGMAS
71  , N_SENSITIVITY_MODES
72  } ;
73 
74 enum systematicModes { ONE_SIGMA_BELOW = 0 // has to be zero
75  , CENTRAL
76  , ONE_SIGMA_ABOVE
77  , N_SIGMA_MODES // should be 3
78  } ;
79 
80 enum rejectionFactor { REJECT995
81  , REJECT9975
82  , REJECT999
83  , REJECT_ALL
84  , N_REJECTION_MODES
85  } ;
86 
87 enum basicParameter { PAR_SIGMA = -1
88  , PAR_SYST_BKG_TVALUE = -2
89  , PAR_LEFF_TVALUE = -3
90  , PAR_QY_TVALUE = -4
91  , PAR_EFFICIENCY_TVALUE = -5
92  , PAR_SIGN_ACCEPTANCE_TVALUE = -6
93  , PAR_NOT_ASSIGNED = -900
94  , PAR_STAT_BKG_TVALUE = -120 /* run from -120 to -105*/
95  , PAR_GAUSS_TVALUE = -220 /* run from -220 to -120*/
96  } ;
97 
98 enum ciMode { CI_UP
99  , CI_LOW
100  , CI_TWO_SIDED
101  , CLS_UP
102  , CLS_LOW
103  , CLS_TWO_SIDED
104  , N_CI_MODES
105  } ;
106 
107 enum sigmaModes { ESTIMATED, UPPER_LIMIT };
108 enum sigmaUnits { SIGMA_UNIT , EVENT_UNIT };
109 
110 static const double DEFAULT_CL = 0.9 ;
111 static const double DEFAULT_SIMULATED_X0 = 0.1 ;
112 static const double DEFAULT_SIMULATED_SIGMA = 0.1 ;
113 static const double DEFAULT_SIMULATED_MU_GAUSS = 0.5 ;
114 static const double DEFAULT_SIMULATED_XMAX_B = 1.0 ;
115 static const double LOGSQR2PI = 0.918938533205 ;
116 static const double DEFAULT_EVENT_UPPER_LIMIT = 20.0 ;
117 
118 static const double VERY_LARGE = 1.E19
119  , TINY = 1.E-99
120  , VERY_SMALL = -VERY_LARGE
121  , VERY_SMALL_LOG = -10000.
122  , UNDEFINED = -9999
123  , AUTOMATIC = UNDEFINED*10.
124  , CRAZY = 98765432123456789.
125  ;
126 
127 
128 enum flagType { VERY_LARGE_INT = 9999999
129  , VERY_SMALL_INT = -VERY_LARGE_INT
130  , UNDEFINED_INT
131  , SAME
132  , NEXT
133  , AUTO
134  , ALL
135  , NONE
136  , GENERAL
137  , LINEAR
138  , LOG
139  , EXPONENTIAL
140  , LOGX_LINY
141  , PARABOLIC
142  } ;
143 
144 const string UNDEFINED_STRING="???";
145 
146 const string LABEL_BAND = "Band number"
147  , LABEL_ER = "E_{r} (KeV)"
148  , LABEL_EVT_AFTER_SEL = "Events after selection"
149  , LABEL_EVT_DAY = "Events (day^{-1})"
150  , LABEL_EVT = "Events"
151  , LABEL_EVT_MAX = "Events_{max}"
152  , LABEL_EVT_KEV = "Events (KeV^{-1})"
153  , LABEL_EVT_KG_DAY = "Events (Kg^{-1} day^{-1})"
154  , LABEL_EVT_KG_DAY_KEV = "Events (Kg^{-1} day^{-1} KeV^{-1})"
155  , LABEL_EVT_PE = "Events (p.e^{-1})"
156  , LABEL_FF = "F^{2}"
157  , LABEL_FLATTENED = "Flattened log_{10}(S2/S1)"
158  , LABEL_LEFF = "L_{eff}"
159  , LABEL_LEFF_TVALUE = "t-Value for L_{eff}"
160  , LABEL_MASS = "Mass (GeV/c^{2})"
161  , LABEL_NORMTO1 = "Distribution norm. to 1"
162  , LABEL_LOG_LIKELIHOOD = "-log(Likelihood)"
163  , LABEL_PVALUE = "P-value"
164  , LABEL_Q_EXCLUSION = "q_{excl.}"
165  , LABEL_S1 = "S1 (p.e.)"
166  , LABEL_S2 = "S2"
167  , LABEL_S2_OVER_S1 = "S2/S1"
168  , LABEL_SA = "SA(y)"
169  , LABEL_SIGMA = "\\sigma (cm^{2})"
170  , LABEL_SIGMA_MAX = "\\sigma_{max} (cm^{2})"
171  , LABEL_SLICE = "Slice Number"
172  , LABEL_VESC = "V_{esc}"
173  , LABEL_Y_UOVER2 = "y=u/2"
174  ;
180 class XeStat : public errorHandler, public printTools {
181 
182  public :
183 
184  /* -------------------------------------------------------------
185  * Basic methods
186  * ------------------------------------------------------------*/
187 
188  XeStat(TString name);
189 
194  static void setAnalysisMode(int mode);
195 
200  static int getAnalysisMode();
201 
207  static bool checkAnalysisMode(TString name, int requested);
208 
209 
210  /* -------------------------------------------------------------
211  * Advanced methods
212  * ------------------------------------------------------------*/
213 
218  static bool isAnalysisDefined(bool verbose=false);
219 
223  static bool isCutsBased();
224 
228  static bool isPL();
229 
230 
235  static int getSigmaLinLog(int unit);
236 
240  static TString getAnalysisModeName();
241 
246  static TString getAnalysisModeName(int mode);
247 
252  static TString getSystematicModeName(int syst);
253 
258  static TString getSigmaUnitName(int unit);
259 
264  static TString getSigmaLabel(int unit);
265 
270  static TString getSigmaModeName(int mode);
271 
272 
277  static TString getUpperSigmaLabel(int unit);
278 
279 
280 
282  void setName(TString nam="No_Name") { name = nam; };
283 
285  TString getName() { return name; };
286 
288  void setExperiment(int exp) { experiment = exp;};
289 
291  int getExperiment() { return experiment; };
292 
293  protected:
294 
295  static int analysisMode;
296  TString name;
297  int experiment;
298 
299 } ;
300 
301 
302 
303 
304 
305 
306 
307 
308 
312 class LKParameter : public XeStat {
313 
314  /* -------------------------------------------------------------
315  * Advanced methods
316  * ------------------------------------------------------------*/
317 
318  public :
319 
320 
321  static TString getTypeName(int type);
322 
323  virtual ~LKParameter();
324 
328  LKParameter(TString name);
329 
342  LKParameter(int id, int type,TString nam,double initial,double step
343  ,double min, double max);
344 
345  void printInitial();
346  virtual void printCurrent(bool withErrors);
347  void setId(int id);
348  void setType(int typ);
349  void setInitialValue(double i);
350  virtual void setCurrentValue(double c);
351  void setCurrentValueInMinuitUnits(double c);
352 
353 
359  void setT0value(double val) {t0 = val;};
360  double getT0value() {return t0;};
361  void setMinuitUnit(double s=1.);
362  void setStep(double st);
363  virtual void setSigma(double sig);
364  void setSigmaInMinuitUnits(double sig);
365  void setMinimum(double mi);
366  void setMaximum(double max);
367  int getType();
368  int getId();
369  double getCurrentValue();
370  double getCurrentValueInMinuitUnits();
371  double getInitialValue();
372  double getInitialValueInMinuitUnits();
373  double getMaximum();
374  double getMaximumInMinuitUnits();
375  double getMinimum();
376  double getMinimumInMinuitUnits();
377  double getStep();
378  double getStepInMinuitUnits();
379  double getSigma();
380  TString getTypeName();
381 
382  double getInitialSigma() { return initialSigma;};
383 
384  //return the gaussian constraint on the t-value
385  double getLLGausConstraint();
386 
387  /* -------------------------------------------------------------
388  * Advanced methods
389  * ------------------------------------------------------------*/
390 
391 
396  void setCommon(bool c=true);
397  bool isActive();
398  bool isOfInterest();
399  bool isCommon();
400 
405  void freeze(bool doFreeze);
406 
407  /* -------------------------------------------------------------
408  * Internal methods (not for user)
409  * ------------------------------------------------------------*/
410 
411  bool compares(LKParameter* par, bool print);
412  void printHeader();
413  bool inCombinedMode();
414  void initialize();
415  void setCombinedMode(bool mode=true);
416 
417  protected :
418 
419  double t0;
420  int type;
421  int id;
422  bool common;
423  bool combinedMode;
424  double initialValue;
425  double step;
426  double minimum;
427  double maximum;
428  double currentValue;
429  double sigma;
430  double initialSigma;
431  double MinuitUnit;
432 
433 
434 } ;
435 
439 class SigmaParameter : public LKParameter {
440  public :
441  SigmaParameter();
442  ~SigmaParameter();
443 
444 
445 } ;
446 
447 
452  public :
453  CombinedParameter(TString name);
455 
456  void setCurrentValue(double val);
457  void setSigma(double sig);
458  void correlateParameter(LKParameter *p);
459 
460  vector <LKParameter*> paramList;
461 
462 } ;
463 
468  public :
469  TSystBkgParameter(int run);
471 
472  static TString getTheName(int run);
473 
474 } ;
475 
476 class TGaussParameter : public LKParameter {
477  public :
478  TGaussParameter(int id, int run);
479  ~TGaussParameter();
480 
481  void setUncertainty(double unc) { uncertainty = unc;};
482  double getUncertainty() { return uncertainty; };
483 
484  static TString getTheName(int b, int run);
485 
486  double uncertainty;
487 
488 } ;
489 
494 
495  public :
497  TStatBkgParameter(int band, int run);
499 
500 
501  void setStatError(double err);
502  void printCurrent(bool withError);
503  protected :
504 
505  static TString getTheName(int b, int run);
506  int band;
507  double stat_error;
508 } ;
509 
510 
514 class TLEffParameter : public LKParameter {
515  public :
516  TLEffParameter();
517  ~TLEffParameter();
518 
519 
520 } ;
521 
525 class TQyParameter : public LKParameter {
526  public :
527  TQyParameter();
528  ~TQyParameter();
529 
530 
531 } ;
532 
533 
538  public :
541 
542 
543 } ;
544 
545 
550 class Likelihood : public XeStat {
551 
552 
553  public:
554 
555  /* -------------------------------------------------------------
556  * Basic methods
557  * ------------------------------------------------------------*/
558 
564  virtual double computeTheLogLikelihood()=0;
565  double computeTheConstraint();
566  virtual ~Likelihood();
567 
572  Likelihood(TString name);
573 
574 
579  double getSigmaHat();
580 
584  double getLogD();
585 
589  bool parameterExists(int p);
590 
601  void addParameter(int id, int type,TString nam,double initialVal
602  ,double step,double mi, double ma);
603 
609  void addParameter(LKParameter* param,int id=SAME);
610 
615  void replaceParameter(LKParameter* param);
616 
621  void addParameterTolerant(LKParameter* param);
622 
628  void activateParameter(LKParameter* param, bool active=true);
629 
635  void removeParameter(LKParameter* param, bool tolerant=false);
636 
642  void removeParameter(int id, bool tolerant=false);
643 
644  void listParameters();
645  void printInitialParameters();
646  void printResultParameters();
647  void printCurrentParameters();
648  void printCurrentParameters(bool with_err);
649  void ignoreParameter(int id);
650  void setParameterType(int id,int type);
651  void setParameterValue(int id,double v);
652  void setInitialValue(int id,double v);
653  double getParameterValue(int id);
654  double maximize(bool freezeParametersOfInterest);
655  double maximizeNumerically(int numberOfToys , bool freezeParametersOfInterest);
656  void setSeed(double Inputseed) {seed = Inputseed;};
657  /* -------------------------------------------------------------
658  * Advanced methods
659  * ------------------------------------------------------------*/
660  double seed;
661  int getNTotalParameters();
662  int getNActiveParameters();
663  int getNParametersOfInterest();
664  int getNMinuitParameters();
665  int getNNuisanceParameters();
666  int getNParameters(int type);
667  void resetParameters();
668  LKParameter* getParameter(int id);
669  LKParameter* getPOI();
670  map<int,LKParameter*>* getParameters();
671 
672  TH1F getPullsHisto(); // return a TH1F with current values of all NP
673 
674 
685  static double shapeLikelihood( vector<int>* bins, int nDist, double** dists
686  , double *norm );
687 
688  /* -------------------------------------------------------------
689  * Internal methods (not for user)
690  * ------------------------------------------------------------*/
691 
692  void setCurrentValues(const double* v,const double* ers=NULL);
693  void setCurrentValuesInMinuitUnits(const double*v,const double*e=NULL);
694  void setCombinedMode(bool mode=true);
695  void printInitialHeader();
696  void printCurrentHeader();
697  bool checkConsistency();
698  bool inCombinedMode();
699  int mapMinuitParameters(bool freezeParametersOfInterest);
700  int getNParametersForChi2();
701  void forceNParametersOfInterest(int nF);
702  void clearTheParameters();
703 
704  protected:
705 
709  void setup();
710 
711  int currentId;
712  int nParametersOfInterest;
713  int nActiveParameters;
714  int nNuisanceParameters;
715  int forcedNParametersOfInterest;
716  bool combinedMode;
717  vector<LKParameter*> MinuitParameters;
718  map<int,LKParameter*> parameters;
719 
720  double sigmaHat;
722  double LogD;
724  void clear();
725  bool checkParameter(int p, bool shouldExist);
726 
727 
728 } ;
729 
730 typedef map<int,LKParameter*>::iterator ParameterIterator;
731 
732 #define TRAVERSE_PARAMETERS(it) \
733  for(ParameterIterator it=parameters.begin(); it!=parameters.end(); it++)
734 
735 
736 
737 
743 
744  /* virtual class */
745 
746  public :
747 
748  /* -------------------------------------------------------------
749  * Basic methods
750  * ------------------------------------------------------------*/
751 
752 
757  ProfileLikelihood(TString name);
758 
759  /* -------------------------------------------------------------
760  * Advanced methods
761  * ------------------------------------------------------------*/
762 
763 
764  virtual ~ProfileLikelihood();
765 
766  /* -------------------------------------------------------------
767  * Internal methods (not for user)
768  * ------------------------------------------------------------*/
769 
770 
774  void printFlagsAndParameters();
775 
776 
780  void estimateCrossSection();
781  bool initialize() {return true;}; //FIXME ALE - place holder.
782 
783 
788  TGraph* getGraphOfLogLikelihood(int n_points);
789  //produce a graph of scan qValues scanning on mu, if forceMuhatComp=true then
790  //will recompute the minimum even if it was already computed and stored.
791  TGraph* getGraphAtQval(double qval, bool forceMuhatComp=true);
792  double getSigmaAtQval(double qval, bool forceMuhatComp=true);
793  double returnLimitHagar( double cl, bool forceMuhatComp=true);
794 
795  //double getMaximum()
802  vector<TGraph*> getGraphOfParameters(int n_points);
803 
804  TGraph* getLikelihoodScanOfParameter( int n_points, LKParameter * par, double mu = 0);
805 
806  virtual double getWimpMass();
807 
808  virtual void setData(int dataType)=0;
809 
810  virtual void generateAsimov(double mu_prime)=0 ;
811 
812  virtual void printEventSummary(bool isForWiki=false)=0;
813 
814  virtual void generateToyDataset(double seed, double mu_prime)=0;
815 
816  virtual double getSignalDefaultNorm()=0;
817  virtual double getSignalMultiplier()=0;
818  virtual void setSignalMultiplier(double val)=0;
819 
820  virtual void setTreeIndex( int index )=0;
821 
822  virtual vector<string> getTrueParamsNames() =0;
823 
824  virtual vector<double> getTrueParams() =0;
825 
826  virtual double getSafeguardValue()=0;
827 
828  protected :
829 
833  void setup();
834 
838 } ;
839 
845 
846  public :
847 
848  /* -------------------------------------------------------------
849  * Basic methods
850  * ------------------------------------------------------------*/
851 
852  CombinedProfileLikelihood(TString name);
854  void combine(ProfileLikelihood* pl);
855  double computeTheLogLikelihood();
856 
857  /* -------------------------------------------------------------
858  * Advanced methods
859  * ------------------------------------------------------------*/
860 
861  ProfileLikelihood* getProfile(int experiment);
862 
866  void printFlagsAndParameters();
867 // void setWimpMass(double);
868  double getWimpMass();
869 
870  void setData(int dataType);
871 
872  void generateAsimov(double mu_prime) ;
873 
874  void generateToyDataset(double seed, double mu_prime);
875 
876  double getSignalDefaultNorm();
877  double getSignalMultiplier();
878  void setSignalMultiplier(double val);
879 
880  void printEventSummary(bool isForWiki=false);
881 
882  void setTreeIndex(int index);
883 
884 
885  vector<string> getTrueParamsNames();
886 
887  vector<double> getTrueParams();
888 
889 
890  double getSafeguardValue(){return -999;};
891 
892  double getSafeguardValue(unsigned int exp);
893 
894  bool initialize();
895 
896  bool findParamPointer( LKParameter *p);
897 
898  /* -------------------------------------------------------------
899  * Internal methods (not for user)
900  * ------------------------------------------------------------*/
901 
902  // bool update();
903 
904 
905  protected:
906 
907  map<int,ProfileLikelihood* > exps;
908  int nCommon;
909  double sigToEvents;
910 
911 
912 };
913 
914 typedef map<int,ProfileLikelihood*>::iterator expIterator;
915 
916 #define TRAVERSE_EXPERIMENTS(it) \
917  for(expIterator it=exps.begin(); it!=exps.end(); it++)
918 
919 
920 #endif
static TString getUpperSigmaLabel(int unit)
Definition: XeStat.cxx:61
Definition: XeStat.h:180
Definition: XeStat.h:312
static bool isAnalysisDefined(bool verbose=false)
Definition: XeStat.cxx:27
static void setAnalysisMode(int mode)
Definition: XeStat.cxx:12
Definition: XeStat.h:439
TString getName()
helper method to return the name of this instance.
Definition: XeStat.h:285
static TString getSigmaUnitName(int unit)
Definition: XeStat.cxx:37
printing helpers, probably you wont use this class
Definition: XeUtils.h:88
double LogD
Definition: XeStat.h:722
void setT0value(double val)
Definition: XeStat.h:359
Helper Class to send consistently formatted messages. It allows different levels of severity for the ...
Definition: XeUtils.h:22
Definition: XeStat.h:493
static TString getAnalysisModeName()
Definition: XeStat.cxx:16
int getExperiment()
set the experiment number, usefull for combination
Definition: XeStat.h:291
double sigmaHat
Definition: XeStat.h:720
Definition: XeStat.h:467
static TString getSigmaLabel(int unit)
Definition: XeStat.cxx:53
Definition: XeStat.h:525
void setExperiment(int exp)
set the experiment number, usefull for combination
Definition: XeStat.h:288
static bool isCutsBased()
Definition: XeStat.cxx:13
static TString getSystematicModeName(int syst)
Definition: XeStat.cxx:18
Definition: XeStat.h:514
static int getSigmaLinLog(int unit)
Definition: XeStat.cxx:69
LKParameter * sigPar
Definition: XeStat.h:835
Definition: XeStat.h:550
static TString getSigmaModeName(int mode)
Definition: XeStat.cxx:45
static int getAnalysisMode()
Definition: XeStat.cxx:15
Definition: XeStat.h:844
Definition: XeStat.h:451
Definition: XeStat.h:537
static bool checkAnalysisMode(TString name, int requested)
Definition: XeStat.cxx:80
vector< LKParameter * > paramList
add parameter to list of parame to be correlated
Definition: XeStat.h:460
void setName(TString nam="No_Name")
helper method to set the name of this instance.
Definition: XeStat.h:282
static bool isPL()
Definition: XeStat.cxx:14
Definition: XeStat.h:742
Definition: XeStat.h:476