Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Stat.hpp

Go to the documentation of this file.
00001 #ifndef CAFE_STAT_HPP__
00002 #define CAFE_STAT_HPP__
00003 
00004 #include "cafe/StatSample.hpp"
00005 #include "cafe/Processor.hpp"
00006 
00007 #include <string>
00008 #include <vector>
00009 #include <map>
00010 
00011 namespace cafe {
00012 
00014   struct Syst {
00015     std::string name ;
00016     const StatSample* reference;
00017     StatSample pos, neg ;
00018     Syst(const std::string& syst_name, const StatSample* reference_sample) :
00019       name(syst_name), reference(reference_sample), 
00020       pos(reference_sample->name()+"_"+name+"_pos"), 
00021       neg(reference_sample->name()+"_"+name+"_neg") {
00022 
00023       pos.AddTags(reference->tags()) ;
00024       pos.AddAndTags(reference->tagsAnd()) ;
00025       pos.AddAndTags(syst_name+"_pos") ;
00026 
00027       neg.AddTags(reference->tags()) ;
00028       neg.AddAndTags(reference->tagsAnd()) ;
00029       neg.AddAndTags(syst_name+"_neg") ;
00030 
00031     }
00032   };
00033     
00089   class Stat : public cafe::Processor{
00090 
00091     std::vector<StatSample> _samples ; //< number of selected events for the different samples
00092     std::vector<Syst> _syst ; //< vector with systematics samples
00093     cafe::Event* _event ; //< pointer to the event object
00094     std::vector<std::string> _tags ; //< initial tags used to tag events
00095     bool _ignoreauto ;  //< ignore records made automatically
00096 
00098     double syst_pos(std::vector<Syst>::const_iterator jt) const ;
00099 
00101     double syst_neg(std::vector<Syst>::const_iterator jt) const ;
00102 
00104     double systerr_pos(std::vector<Syst>::const_iterator jt) const ;
00105 
00107     double systerr_neg(std::vector<Syst>::const_iterator jt) const ;
00108 
00110         Stat *_parent_stat;
00111 
00112   public:
00113 
00115     Stat(const char *name);
00117         Stat(const char *name, bool duplicate_ok);
00118     ~Stat();
00119 
00124     double eventWeight(const std::string& name="global", 
00125                        const std::string sample_name="not_specified") const ;
00126 
00128     double nevents(const std::string& name="Initial", const std::string& sample_name="not_specified") const ;
00129 
00131     double efficiencyCorrected(const std::string& sample_name="not_specified") const;
00132 
00134     double efficiency(const std::string& sample_name="not_specified") const;
00135 
00137     double syst_pos(const std::string& name, const std::string& sample_name="not_specified") const ; 
00138 
00140     double syst_neg(const std::string& name, const std::string& sample_name="not_specified") const ; 
00141 
00143     double systerr_pos(const std::string& name, const std::string& sample_name="not_specified") const ; 
00144 
00146     double systerr_neg(const std::string& name, const std::string& sample_name="not_specified") const ; 
00147 
00149     std::vector<const cafe::StatSample*> get_samples() const ;
00150 
00152     std::vector<const cafe::Syst*> get_syst() const ;
00153 
00155     void begin();
00156 
00158     void finish() ;
00159 
00161     bool processEvent(cafe::Event& event);
00162 
00164     void EventSelected(const std::string& selection_name) ;
00165 
00167     void applyWeight(const std::string& weight_name, 
00168                      double weight, double weight_pos=-1.0, double weight_neg=-1.0) ;
00169 
00171     double calculateGlobalWeight() ;
00172 
00174     void eventEnd() ;
00175 
00177     StatSample&  add_sample(const std::string& name) {_samples.push_back(name); return _samples.back();} 
00178 
00179     /* \brief Add samples for the systematics (with name "name") study. If sample == 0, 
00180               systematics samples will be added to all existing samples .
00181     */
00182     void add_syst(const std::string& name, StatSample* sample=0) ;
00183 
00185     void tag(const std::vector<std::string>& tags) ;
00186 
00188     ostream& print_html(ostream& os) const ; 
00189     ostream& print_tex(ostream& os, const std::string title="Efficiency") const ; 
00190 
00191         // Use when you need to use a sub-stat processor.
00192         void chain (void);
00193         void unchain (void);
00194         
00195         // Use to inherrit current weights from parent
00196         void inheritWeights();
00197     
00198   public:
00199     ClassDef(Stat, 0) ;
00200   };
00201 
00203   class StatPointer {
00204     Stat* _stat ;
00205     
00206   public :
00207     StatPointer(Stat* stat=0) ;
00208     virtual ~StatPointer() ;
00209     Stat* pointer() {return _stat;}
00210  
00212     void EventSelected(const std::string& selection_name) ;
00213 
00215     void applyWeight(const std::string& weight_name, 
00216                      double weight, double weight_pos=-1.0, double weight_neg=-1.0) ;
00217 
00219     double calculateGlobalWeight() ;
00220     
00221     ClassDef(StatPointer, 0) ;
00222 
00223   } ;
00224 }
00225 
00226 #endif // CAFE_STAT_HPP__

Generated on Tue Mar 28 10:13:04 2006 for CAF by doxygen 1.3.4