RooThresholdCategory.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooThresholdCategory.cxx 25184 2008-08-20 13:59:55Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // Class RooThresholdCategory provides a real-to-category mapping defined
00021 // by a series of thresholds.
00022 // END_HTML
00023 //
00024 
00025 
00026 #include "RooFit.h"
00027 
00028 #include "Riostream.h"
00029 #include "Riostream.h"
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include "TString.h"
00033 #include "RooThresholdCategory.h"
00034 #include "RooStreamParser.h"
00035 #include "RooThreshEntry.h"
00036 #include "RooMsgService.h"
00037 
00038 ClassImp(RooThresholdCategory)
00039 
00040 
00041 
00042 //_____________________________________________________________________________
00043 RooThresholdCategory::RooThresholdCategory(const char *name, const char *title, RooAbsReal& inputVar, 
00044                                            const char* defOut, Int_t defIdx) :
00045   RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar)
00046 {
00047   // Constructor with input function to be mapped and name and index of default
00048   // output state of unmapped values
00049 
00050   _defCat = (RooCatType*) defineType(defOut,defIdx) ;
00051   _threshIter = _threshList.MakeIterator() ;
00052 }
00053 
00054 
00055 
00056 //_____________________________________________________________________________
00057 RooThresholdCategory::RooThresholdCategory(const RooThresholdCategory& other, const char *name) :
00058   RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar)
00059 {
00060   // Copy constructor
00061 
00062   _defCat = (RooCatType*) lookupType(other._defCat->GetName()) ;
00063 
00064   other._threshIter->Reset() ;
00065   RooThreshEntry* te ;
00066   while((te=(RooThreshEntry*)other._threshIter->Next())) {
00067     _threshList.Add(new RooThreshEntry(*te)) ;
00068   }
00069 
00070   _threshIter = _threshList.MakeIterator() ;
00071 }
00072 
00073 
00074 
00075 //_____________________________________________________________________________
00076 RooThresholdCategory::~RooThresholdCategory() 
00077 {
00078   // Destructor
00079 
00080   _threshList.Delete() ;
00081   delete _threshIter ;
00082 }
00083 
00084 
00085 
00086 //_____________________________________________________________________________
00087 Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit, const char* catName, Int_t catIdx) 
00088 {  
00089   // Insert threshold at value upperLimit. All values below upper limit (and above any lower
00090   // thresholds, if any) will be mapped to a state name 'catName' with index 'catIdx'
00091 
00092   // Check if identical threshold values is not defined yet
00093   _threshIter->Reset() ;
00094   RooThreshEntry* te ;
00095   while ((te=(RooThreshEntry*)_threshIter->Next())) {
00096     if (te->thresh() == upperLimit) {
00097       coutW(InputArguments) << "RooThresholdCategory::addThreshold(" << GetName() 
00098                             << ") threshold at " << upperLimit << " already defined" << endl ;
00099       return kTRUE ;
00100     }    
00101   }
00102 
00103 
00104   // Add a threshold entry
00105   const RooCatType* type = lookupType(catName,kFALSE) ;
00106   if (!type) {
00107     if (catIdx==-99999) {
00108       type=defineType(catName) ;
00109     } else {
00110       type=defineType(catName,catIdx) ;      
00111     }
00112   }
00113   te = new RooThreshEntry(upperLimit,*type) ;
00114   _threshList.Add(te) ;
00115      
00116   return kFALSE ;
00117 }
00118 
00119 
00120 
00121 //_____________________________________________________________________________
00122 RooCatType RooThresholdCategory::evaluate() const
00123 {
00124   // Calculate and return the value of the mapping function
00125 
00126   // Scan the threshold list
00127   _threshIter->Reset() ;
00128   RooThreshEntry* te ;
00129   while((te=(RooThreshEntry*)_threshIter->Next())) {
00130     if (_inputVar<te->thresh()) return te->cat() ;
00131   }
00132 
00133   // Return default if nothing found
00134   return *_defCat ;
00135 }
00136 
00137 
00138 
00139 //_____________________________________________________________________________
00140 void RooThresholdCategory::writeToStream(ostream& os, Bool_t compact) const
00141 {
00142   // Write object contents to given stream
00143 
00144   if (compact) {
00145     // Write value only
00146     os << getLabel() ;
00147   } else {
00148     // Write mapping expression
00149 
00150     // Scan list of threshold
00151     _threshIter->Reset() ;
00152     RooThreshEntry* te ;
00153     while((te=(RooThreshEntry*)_threshIter->Next())) {
00154       os << te->cat().GetName() << ":<" << te->thresh() << " " ;
00155     }
00156     os << _defCat->GetName() << ":*" ;
00157   }
00158 }
00159 
00160 
00161 
00162 //_____________________________________________________________________________
00163 void RooThresholdCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
00164 {
00165   // Print info about this threshold category to the specified stream. In addition to the info
00166   // from RooAbsCategory::printStream() we add:
00167   //
00168   //  Standard : input category
00169   //     Shape : default value
00170   //   Verbose : list of thresholds
00171 
00172    RooAbsCategory::printMultiline(os,content,verbose,indent);
00173 
00174    if (verbose) {
00175      os << indent << "--- RooThresholdCategory ---" << endl
00176         << indent << "  Maps from " ;
00177      _inputVar.arg().printStream(os,0,kStandard);
00178      
00179      os << indent << "  Threshold list" << endl ;
00180      _threshIter->Reset() ;
00181      RooThreshEntry* te ;
00182      while((te=(RooThreshEntry*)_threshIter->Next())) {
00183        os << indent << "    input < " << te->thresh() << " --> " ; 
00184        te->cat().printStream(os,kName|kValue,kSingleLine) ;
00185      }
00186      os << indent << "  Default value is " ;
00187      _defCat->printStream(os,kValue,kSingleLine);
00188 
00189 
00190    }
00191 }
00192 
00193 

Generated on Tue Jul 5 15:07:35 2011 for ROOT_528-00b_version by  doxygen 1.5.1