#include <PhysicsTools/UtilAlgos/interface/ConfigurableHisto.h>
Public Member Functions | |
void | book (TFileDirectory *dir) |
ConfigurableHisto * | clone () const |
void | complete () |
void | fill (const edm::Event &e) |
SplittingConfigurableHisto (HType t, std::string name, edm::ParameterSet &pset) | |
Private Types | |
typedef std::map< const Splitter *, std::vector < ConfigurableHisto * > > | SubHistoMap |
typedef std::map< const Splitter *, THStack * > | SubHistoStacks |
Private Member Functions | |
SplittingConfigurableHisto (const SplittingConfigurableHisto &master) | |
Private Attributes | |
const Splitter * | splitter_ |
THStack * | stack_ |
SubHistoMap | subHistoMap_ |
std::vector< ConfigurableHisto * > | subHistos_ |
SubHistoStacks | subHistoStacks_ |
Definition at line 225 of file ConfigurableHisto.h.
typedef std::map<const Splitter *, std::vector<ConfigurableHisto* > > SplittingConfigurableHisto::SubHistoMap [private] |
Definition at line 375 of file ConfigurableHisto.h.
typedef std::map<const Splitter *, THStack *> SplittingConfigurableHisto::SubHistoStacks [private] |
Definition at line 376 of file ConfigurableHisto.h.
SplittingConfigurableHisto::SplittingConfigurableHisto | ( | HType | t, | |
std::string | name, | |||
edm::ParameterSet & | pset | |||
) | [inline] |
Definition at line 227 of file ConfigurableHisto.h.
References ConfigurableHisto::ConfigurableHisto(), e, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), i, edm::ParameterSet::insert(), Splitter::label(), label, Splitter::maxSlots(), CachingVariable::name(), ConfigurableHisto::name_, s, Splitter::shortLabel(), splitter_, subHistoMap_, subHistos_, indexGen::title, and v.
Referenced by clone().
00227 : 00228 ConfigurableHisto(t,name,pset) , splitter_(0) { 00229 std::string title=pset.getParameter<std::string>("title"); 00230 00231 //allow for many splitters ... 00232 if (pset.exists("splitters")){ 00233 //you want more than one splitter 00234 std::vector<std::string> splitters = pset.getParameter<std::vector<std::string> >("splitters"); 00235 for (uint s=0;s!=splitters.size();++s){ 00236 const CachingVariable * v=edm::Service<VariableHelperService>()->get().variable(splitters[s]); 00237 const Splitter * splitter = dynamic_cast<const Splitter*>(v); 00238 if (!splitter){ 00239 edm::LogError("SplittingConfigurableHisto")<<"for: "<<name_<<" the splitting variable: "<<splitters[s]<<" is not a Splitter"; 00240 continue; 00241 } 00242 00243 //insert in the map 00244 std::vector<ConfigurableHisto*> & insertedHisto=subHistoMap_[splitter]; 00245 //now configure the histograms 00246 uint mSlots=splitter->maxSlots(); 00247 for (uint i=0;i!=mSlots;++i){ 00248 //--- std::cout<<" slot: "<<i<<std::endl; 00249 const std::string & slabel=splitter->shortLabel(i); 00250 const std::string & label=splitter->label(i); 00251 edm::ParameterSet mPset=pset; 00252 edm::Entry e("string",title+" for "+label,true); 00253 mPset.insert(true,"title",e); 00254 insertedHisto.push_back(new ConfigurableHisto(t,name+slabel ,mPset)); 00255 }//loop on slots 00256 }//loop on splitters 00257 00258 }//if splitters exists 00259 else{ 00260 //single splitter 00261 //get the splitting variable 00262 const CachingVariable * v=edm::Service<VariableHelperService>()->get().variable(pset.getParameter<std::string>("splitter")); 00263 splitter_ = dynamic_cast<const Splitter*>(v); 00264 if (!splitter_){ 00265 edm::LogError("SplittingConfigurableHisto")<<"for: "<<name_<<" the splitting variable: "<<v->name()<<" is not a Splitter"; 00266 } 00267 else{ 00268 //configure the splitted plots 00269 uint mSlots=splitter_->maxSlots(); 00270 for (uint i=0;i!=mSlots;i++){ 00271 const std::string & slabel=splitter_->shortLabel(i); 00272 const std::string & label=splitter_->label(i); 00273 edm::ParameterSet mPset=pset; 00274 edm::Entry e("string",title+" for "+label,true); 00275 mPset.insert(true,"title",e); 00276 subHistos_.push_back(new ConfigurableHisto(t,name+slabel, mPset)); 00277 } 00278 } 00279 } 00280 }//end of ctor
SplittingConfigurableHisto::SplittingConfigurableHisto | ( | const SplittingConfigurableHisto & | master | ) | [inline, private] |
Definition at line 360 of file ConfigurableHisto.h.
References clone(), i, splitter_, subHistoMap_, and subHistos_.
00360 : ConfigurableHisto(master){ 00361 splitter_ = master.splitter_; 00362 if (master.subHistoMap_.size()!=0){ 00363 SubHistoMap::const_iterator i=master.subHistoMap_.begin(); 00364 SubHistoMap::const_iterator i_end=master.subHistoMap_.end(); 00365 for (;i!=i_end;++i){ 00366 const std::vector<ConfigurableHisto*> & masterHistos=i->second; 00367 std::vector<ConfigurableHisto*> & clonedHistos=subHistoMap_[i->first]; 00368 for (uint i=0;i!=masterHistos.size();i++){clonedHistos.push_back(masterHistos[i]->clone());} 00369 } 00370 }else{ 00371 for (uint i=0;i!=master.subHistos_.size();i++){subHistos_.push_back(master.subHistos_[i]->clone());} 00372 } 00373 }
void SplittingConfigurableHisto::book | ( | TFileDirectory * | dir | ) | [inline, virtual] |
Reimplemented from ConfigurableHisto.
Definition at line 282 of file ConfigurableHisto.h.
References ConfigurableHisto::book(), ConfigurableHisto::h(), i, TFileDirectory::make(), CachingVariable::name(), ConfigurableHisto::name_, splitter_, stack_, subHistoMap_, subHistos_, and subHistoStacks_.
00282 { 00283 //book the base histogram 00284 ConfigurableHisto::book(dir); 00285 00286 if (subHistoMap_.size()!=0){ 00287 SubHistoMap::iterator i=subHistoMap_.begin(); 00288 SubHistoMap::iterator i_end=subHistoMap_.end(); 00289 for (;i!=i_end;++i){for (uint h=0;h!=i->second.size();++h){ 00290 i->second[h]->book(dir);} 00291 //book the THStack 00292 std::string sName= name_+"_"+i->first->name(); 00293 std::string sTitle="Stack histogram of "+name_+" for splitter "+i->first->name(); 00294 subHistoStacks_[i->first]= dir->make<THStack>(sName.c_str(),sTitle.c_str()); 00295 } 00296 }else{ 00297 for (uint h=0;h!=subHistos_.size();h++){subHistos_[h]->book(dir);} 00298 //book a THStack 00299 std::string sName= name_+"_"+splitter_->name(); 00300 std::string sTitle="Stack histogram of "+name_+" for splitter "+splitter_->name(); 00301 stack_ = dir->make<THStack>(sName.c_str(),sTitle.c_str()); 00302 } 00303 00304 }
ConfigurableHisto* SplittingConfigurableHisto::clone | ( | void | ) | const [inline, virtual] |
Reimplemented from ConfigurableHisto.
Definition at line 306 of file ConfigurableHisto.h.
References SplittingConfigurableHisto().
Referenced by SplittingConfigurableHisto().
00306 { return new SplittingConfigurableHisto(*this); }
void SplittingConfigurableHisto::complete | ( | ) | [inline] |
Reimplemented from ConfigurableHisto.
Definition at line 340 of file ConfigurableHisto.h.
References ConfigurableHisto::h(), i, Splitter::label(), splitter_, stack_, subHistoMap_, subHistos_, and subHistoStacks_.
00340 { 00341 if (subHistoMap_.size()!=0){ 00342 //fill up the stacks 00343 SubHistoMap::iterator i=subHistoMap_.begin(); 00344 SubHistoMap::iterator i_end=subHistoMap_.end(); 00345 for (;i!=i_end;++i){ 00346 for (uint h=0;h!=i->second.size();h++){ 00347 // if (i->second[h]->h()->Integral==0) continue;// do not add empty histograms. NO, because it will be tough to merge two THStack 00348 subHistoStacks_[i->first]->Add(i->second[h]->h(), i->first->label(h).c_str()); 00349 } 00350 } 00351 00352 }else{ 00353 //fill up the only stack 00354 for (uint i=0;i!=subHistos_.size();i++){ stack_->Add(subHistos_[i]->h(), splitter_->label(i).c_str()); } 00355 } 00356 00357 00358 }
void SplittingConfigurableHisto::fill | ( | const edm::Event & | e | ) | [inline, virtual] |
Reimplemented from ConfigurableHisto.
Definition at line 308 of file ConfigurableHisto.h.
References CachingVariable::compute(), ConfigurableHisto::fill(), i, splitter_, subHistoMap_, and subHistos_.
00308 { 00309 //fill the base histogram 00310 ConfigurableHisto::fill(e); 00311 00312 if (subHistoMap_.size()!=0){ 00313 SubHistoMap::iterator i=subHistoMap_.begin(); 00314 SubHistoMap::iterator i_end=subHistoMap_.end(); 00315 for (;i!=i_end;++i){ 00316 const Splitter * splitter=i->first; 00317 if (!splitter) continue; 00318 if (!splitter->compute(e)) continue; 00319 uint slot=(uint) (*splitter)(e); 00320 if (slot>=i->second.size()){ 00321 edm::LogError("SplittingConfigurableHisto")<<"slot index: "<<slot<<" is bigger than slots size: "<<i->second.size()<<" from variable value: "<<(*splitter)(e); 00322 continue;} 00323 //fill in the proper slot 00324 i->second[slot]->fill(e); 00325 } 00326 } 00327 else{ 00328 //fill the component histograms 00329 if (!splitter_) return; 00330 if (!splitter_->compute(e)){ 00331 return;} 00332 uint slot=(uint) (*splitter_)(e); 00333 if (slot>=subHistos_.size()){ 00334 edm::LogError("SplittingConfigurableHisto")<<"slot index: "<<slot<<" is bigger than slots size: "<< subHistos_.size() <<" from variable value: "<<(*splitter_)(e); 00335 return;} 00336 subHistos_[slot]->fill(e); 00337 } 00338 }
const Splitter* SplittingConfigurableHisto::splitter_ [private] |
Definition at line 380 of file ConfigurableHisto.h.
Referenced by book(), complete(), fill(), and SplittingConfigurableHisto().
THStack* SplittingConfigurableHisto::stack_ [private] |
Definition at line 378 of file ConfigurableHisto.h.
Referenced by book(), complete(), fill(), and SplittingConfigurableHisto().
std::vector<ConfigurableHisto* > SplittingConfigurableHisto::subHistos_ [private] |
Definition at line 381 of file ConfigurableHisto.h.
Referenced by book(), complete(), fill(), and SplittingConfigurableHisto().