CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Attributes

HistoAnalyzer< C > Class Template Reference

#include <HistoAnalyzer.h>

Inheritance diagram for HistoAnalyzer< C >:
edm::EDAnalyzer

List of all members.

Public Member Functions

 HistoAnalyzer (const edm::ParameterSet &)
 constructor from parameter set
 ~HistoAnalyzer ()
 destructor

Protected Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 process an event

Private Attributes

edm::InputTag src_
 label of the collection to be read in
bool usingWeights_
 Do we weight events?
std::vector< ExpressionHisto
< typename C::value_type > * > 
vhistograms
 vector of the histograms
edm::InputTag weights_
 label of the weight collection (can be null for weights = 1)

Detailed Description

template<typename C>
class HistoAnalyzer< C >

Creates histograms defined in config file

Author:
: Benedikt Hegner, DESY

Template parameters:

Definition at line 22 of file HistoAnalyzer.h.


Constructor & Destructor Documentation

template<typename C >
HistoAnalyzer< C >::HistoAnalyzer ( const edm::ParameterSet par)

constructor from parameter set

Definition at line 45 of file HistoAnalyzer.h.

References end, estimatePileup::hist, bookConverter::histograms, ExpressionHisto< T >::initialize(), and HistoAnalyzer< C >::vhistograms.

                                                            : 
  src_(par.template getParameter<edm::InputTag>("src")),
  usingWeights_(par.exists("weights")),
  weights_(par.template getUntrackedParameter<edm::InputTag>("weights", edm::InputTag("fake")))
{
   edm::Service<TFileService> fs;
   std::vector<edm::ParameterSet> histograms = 
                                   par.template getParameter<std::vector<edm::ParameterSet> >("histograms");
   std::vector<edm::ParameterSet>::const_iterator it = histograms.begin();
   std::vector<edm::ParameterSet>::const_iterator end = histograms.end();

   // create the histograms from the given parameter sets 
   for (; it!=end; ++it)
   {
      ExpressionHisto<typename C::value_type>* hist = new ExpressionHisto<typename C::value_type>(*it);
      hist->initialize(*fs);
      vhistograms.push_back(hist);
   }   

}
template<typename C >
HistoAnalyzer< C >::~HistoAnalyzer ( )

destructor

Definition at line 67 of file HistoAnalyzer.h.

References end.

{
   // delete all histograms and clear the vector of pointers
   typename std::vector<ExpressionHisto<typename C::value_type>* >::iterator it = vhistograms.begin(); 
   typename std::vector<ExpressionHisto<typename C::value_type>* >::iterator end = vhistograms.end();
   for (;it!=end; ++it){
     (*it)->~ExpressionHisto<typename C::value_type>();
   }
   vhistograms.clear(); 
}

Member Function Documentation

template<typename C >
void HistoAnalyzer< C >::analyze ( const edm::Event iEvent,
const edm::EventSetup  
) [protected, virtual]

process an event

Implements edm::EDAnalyzer.

Definition at line 79 of file HistoAnalyzer.h.

References coll, HTMLExport::elem(), end, edm::Event::getByLabel(), i, and CommonMethods::weight().

{
   edm::Handle<C> coll;
   iEvent.getByLabel( src_, coll);
   double weight = 1.0;
   if (usingWeights_) { 
       edm::Handle<double> weightColl;
       iEvent.getByLabel( weights_, weightColl ); 
       weight = *weightColl;
   }

   typename std::vector<ExpressionHisto<typename C::value_type>* >::iterator it = vhistograms.begin();
   typename std::vector<ExpressionHisto<typename C::value_type>* >::iterator end = vhistograms.end(); 

   for (;it!=end; ++it){
      uint32_t i = 0;
      for( typename C::const_iterator elem=coll->begin(); elem!=coll->end(); ++elem, ++i ) {
         if (!(*it)->fill( *elem, weight, i )) {
            break;
         }
      }
   }
}

Member Data Documentation

template<typename C >
edm::InputTag HistoAnalyzer< C >::src_ [private]

label of the collection to be read in

Definition at line 35 of file HistoAnalyzer.h.

template<typename C >
bool HistoAnalyzer< C >::usingWeights_ [private]

Do we weight events?

Definition at line 37 of file HistoAnalyzer.h.

template<typename C >
std::vector<ExpressionHisto<typename C::value_type>* > HistoAnalyzer< C >::vhistograms [private]

vector of the histograms

Definition at line 41 of file HistoAnalyzer.h.

Referenced by HistoAnalyzer< C >::HistoAnalyzer().

template<typename C >
edm::InputTag HistoAnalyzer< C >::weights_ [private]

label of the weight collection (can be null for weights = 1)

Definition at line 39 of file HistoAnalyzer.h.