CMS 3D CMS Logo

pat::PatKitHelper Class Reference

#include <PhysicsTools/StarterKit/interface/PatKitHelper.h>

List of all members.

Public Member Functions

void addNtupleVar (edm::EDProducer *prod, std::string name, std::string type)
void bookHistos (edm::EDProducer *producer)
void fillHistograms (edm::Event &event, edm::Handle< std::vector< pat::Muon > > &muonHandle, edm::Handle< std::vector< pat::Electron > > &electronHandle, edm::Handle< std::vector< pat::Tau > > &tauHandle, edm::Handle< std::vector< pat::Jet > > &jetHandle, edm::Handle< std::vector< pat::MET > > &METHandle, edm::Handle< std::vector< pat::Photon > > &photonHandle)
PhysicsHistograms::KinAxisLimits getAxisLimits (std::string name)
void getHandles (edm::Event &event, edm::Handle< std::vector< pat::Muon > > &muonHandle, edm::Handle< std::vector< pat::Electron > > &electronHandle, edm::Handle< std::vector< pat::Tau > > &tauHandle, edm::Handle< std::vector< pat::Jet > > &jetHandle, edm::Handle< std::vector< pat::MET > > &METHandle, edm::Handle< std::vector< pat::Photon > > &photonHandle)
 PatKitHelper (edm::ParameterSet const &parameters)
void saveNtuple (edm::Event &event, const std::vector< pat::PhysVarHisto * > &ntvars)
template<class T>
void saveNtupleVar (edm::Event &event, std::string name, T value)
template<class T>
void saveNtupleVec (edm::Event &event, std::string name, const vector< T > &value)
template<class T>
void saveNtupleVec (edm::Event &event, std::string name, const std::vector< T > &invec)
 ~PatKitHelper ()

Public Attributes

edm::Service< TFileServicefs_
pat::PhysVarHistoh_eventNumber_
pat::PhysVarHistoh_runNumber_
std::vector< pat::PhysVarHisto * > ntVars_
edm::ParameterSet parameters_
PhysicsHistogramsphysHistos_
int verboseLevel_


Detailed Description

Definition at line 33 of file PatKitHelper.h.


Constructor & Destructor Documentation

PatKitHelper::PatKitHelper ( edm::ParameterSet const &  parameters  ) 

Definition at line 7 of file PatKitHelper.cc.

00007                                                              :
00008   parameters_( iConfig ),
00009   physHistos_(0),
00010   verboseLevel_(0)
00011 {
00012 }

PatKitHelper::~PatKitHelper (  ) 

Definition at line 15 of file PatKitHelper.cc.

References physHistos_.

00016 {
00017   if ( physHistos_ ) delete physHistos_;
00018 }


Member Function Documentation

void PatKitHelper::addNtupleVar ( edm::EDProducer prod,
std::string  name,
std::string  type 
)

Definition at line 170 of file PatKitHelper.cc.

References GenMuonPlsPt100GeV_cfg::cout, and lat::endl().

Referenced by bookHistos().

00171 {
00172   if      (type == "D") {
00173     producer->produces<double>( name ).setBranchAlias( name );
00174   }
00175   else if (type == "F") {
00176     producer->produces<float>( name ).setBranchAlias( name );
00177   }
00178   else if (type == "I") {
00179     producer->produces<int>( name ).setBranchAlias( name );
00180   }
00181   else if (type == "i") {
00182     producer->produces<unsigned int>( name ).setBranchAlias( name );
00183   }
00184   else if (type == "S") {
00185     producer->produces<short>( name ).setBranchAlias( name );
00186   }
00187   else if (type == "s") {
00188     producer->produces<unsigned short>( name ).setBranchAlias( name );
00189   }
00190   else if (type == "L") {
00191     producer->produces<long>( name ).setBranchAlias( name );
00192   }
00193   else if (type == "l") {
00194     producer->produces<unsigned long>( name ).setBranchAlias( name );
00195   }
00196   else if (type == "vD") {
00197     producer->produces<vector<double> >( name ).setBranchAlias( name );
00198   }
00199   else if (type == "vF") {
00200     producer->produces<vector<float> >( name ).setBranchAlias( name );
00201   }
00202   else if (type == "vI") {
00203     producer->produces<vector<int> >( name ).setBranchAlias( name );
00204   }
00205   else if (type == "vi") {
00206     producer->produces<vector<unsigned int> >( name ).setBranchAlias( name );
00207   }
00208   else if (type == "vS") {
00209     producer->produces<vector<short> >( name ).setBranchAlias( name );
00210   }
00211   else if (type == "vs") {
00212     producer->produces<vector<unsigned short> >( name ).setBranchAlias( name );
00213   }
00214   else if (type == "vL") {
00215     producer->produces<vector<long> >( name ).setBranchAlias( name );
00216   }
00217   else if (type == "vl") {
00218     producer->produces<vector<unsigned long> >( name ).setBranchAlias( name );
00219   }
00220   // &&& else if (type == "p4") {
00221   // &&&   producer->produces<math::XYZTLorentzVector> ( name ).setBranchAlias( name );
00222   // &&& }
00223   else {
00224     std::cout << "PatAnalyzerKit::addNtupleVar (ERROR): "
00225               << "unknown type " << type << std::endl;
00226 
00227     // &&& Throw an exception in order to abort the job!
00228   }
00229 }

void PatKitHelper::bookHistos ( edm::EDProducer producer  ) 

Definition at line 35 of file PatKitHelper.cc.

References addNtupleVar(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), getAxisLimits(), edm::ParameterSet::getParameter(), h_eventNumber_, h_runNumber_, pat::PhysVarHisto::makeTH1(), ntVars_, p, parameters_, physHistos_, and summary.

Referenced by CompositeKit::CompositeKit(), and PatAnalyzerKit::PatAnalyzerKit().

00036 {
00037     // Initialize TFileService
00038   edm::Service<TFileService> fs;
00039   TFileDirectory summary = TFileDirectory( fs->mkdir("summary") );
00040 
00041 
00042   physHistos_ = new PhysicsHistograms ( getAxisLimits("muonAxis"),
00043                                         getAxisLimits("electronAxis"),
00044                                         getAxisLimits("tauAxis"),
00045                                         getAxisLimits("jetAxis"),
00046                                         getAxisLimits("METAxis"),
00047                                         getAxisLimits("photonAxis"),
00048                                         getAxisLimits("trackAxis")
00049                                         );
00050 
00051   // Get list of histograms to enable and disable
00052   string histos_to_disable =
00053     parameters_.getParameter<string>    ("disable");
00054   string histos_to_enable  =
00055     parameters_.getParameter<string>    ("enable");
00056   physHistos_->configure( histos_to_disable, histos_to_enable );
00057 
00058   // PhysicsHistograms takes ownership of the memory for these histograms here
00059   physHistos_->addHisto( h_runNumber_ = 
00060                         new PhysVarHisto( "runNumber", "Run Number",
00061                                           10000, 0, 10000, 
00062                                           &summary ,"", "I") 
00063                         );
00064   physHistos_->addHisto( h_eventNumber_ = 
00065                         new PhysVarHisto( "eventNumber", "Event Number",
00066                                           10000, 0, 10000, 
00067                                           &summary ,"", "I") 
00068                         );
00069 
00070   // Be sure to make the histograms!
00071   h_runNumber_->makeTH1();
00072   h_eventNumber_->makeTH1();
00073 
00074   // &&& Ntuple booking begin
00075 
00076   // Now that we know which variables are in the game, we could also
00077   // decide which ones to ntuplize
00078   string list_of_ntuple_vars =
00079     parameters_.getParameter<std::string>    ("ntuplize");
00080 
00081   if (list_of_ntuple_vars != "") {
00082     //
00083     //--- Collect all PhysVarHistos which need to store ntuple
00084     //--- variables and put them in here.
00085     physHistos_->select( list_of_ntuple_vars, ntVars_ );
00086 
00087     //--- Iterate over the list and "book" them via EDM
00088     std::vector< PhysVarHisto* >::iterator
00089       p    = ntVars_.begin(),
00090       pEnd = ntVars_.end();
00091 
00092     for ( ; p != pEnd; ++p ) {
00093       cout << "Adding ntuple variable " << (*p)->name() << endl;
00094       addNtupleVar( producer, (*p)->name(), (*p)->type() );
00095     }
00096     //
00097   } // end if
00098 
00099 }

void PatKitHelper::fillHistograms ( edm::Event event,
edm::Handle< std::vector< pat::Muon > > &  muonHandle,
edm::Handle< std::vector< pat::Electron > > &  electronHandle,
edm::Handle< std::vector< pat::Tau > > &  tauHandle,
edm::Handle< std::vector< pat::Jet > > &  jetHandle,
edm::Handle< std::vector< pat::MET > > &  METHandle,
edm::Handle< std::vector< pat::Photon > > &  photonHandle 
)

Definition at line 130 of file PatKitHelper.cc.

References PhysicsHistograms::clearVec(), PhysicsHistograms::fillCollection(), ntVars_, physHistos_, and saveNtuple().

Referenced by CompositeKit::produce(), and PatAnalyzerKit::produce().

00138 {
00139   physHistos_->clearVec();
00140   physHistos_->fillCollection(*muonHandle);
00141   physHistos_->fillCollection(*electronHandle);
00142   physHistos_->fillCollection(*tauHandle);
00143   physHistos_->fillCollection(*jetHandle);
00144   physHistos_->fillCollection(*METHandle);
00145   physHistos_->fillCollection(*photonHandle);
00146 
00147 
00148 
00149   // save the list of ntuple varibles to the event record
00150   saveNtuple( event, ntVars_ );
00151 }

PhysicsHistograms::KinAxisLimits PatKitHelper::getAxisLimits ( std::string  name  ) 

Definition at line 20 of file PatKitHelper.cc.

References edm::ParameterSet::getParameter(), and parameters_.

Referenced by bookHistos(), and CompositeKit::CompositeKit().

00021 {
00022   edm::ParameterSet axisLimitsSet = parameters_.getParameter<edm::ParameterSet>(name);
00023   
00024   PhysicsHistograms::KinAxisLimits axisLimits;
00025 
00026   axisLimits.pt1 = axisLimitsSet.getParameter<double>("pt1");
00027   axisLimits.pt2 = axisLimitsSet.getParameter<double>("pt2");
00028   axisLimits.m1  = axisLimitsSet.getParameter<double>("m1");
00029   axisLimits.m2  = axisLimitsSet.getParameter<double>("m2");
00030 
00031   return axisLimits;
00032 }

void PatKitHelper::getHandles ( edm::Event event,
edm::Handle< std::vector< pat::Muon > > &  muonHandle,
edm::Handle< std::vector< pat::Electron > > &  electronHandle,
edm::Handle< std::vector< pat::Tau > > &  tauHandle,
edm::Handle< std::vector< pat::Jet > > &  jetHandle,
edm::Handle< std::vector< pat::MET > > &  METHandle,
edm::Handle< std::vector< pat::Photon > > &  photonHandle 
)

Definition at line 102 of file PatKitHelper.cc.

References edm::ParameterSet::getParameter(), and parameters_.

Referenced by CompositeKit::produce(), and PatAnalyzerKit::produce().

00110 {
00111   
00112   edm::InputTag muonName     = parameters_.getParameter<edm::InputTag>("muonSrc"    );
00113   edm::InputTag electronName = parameters_.getParameter<edm::InputTag>("electronSrc");
00114   edm::InputTag tauName      = parameters_.getParameter<edm::InputTag>("tauSrc"     );
00115   edm::InputTag jetName      = parameters_.getParameter<edm::InputTag>("jetSrc"     );
00116   edm::InputTag METName      = parameters_.getParameter<edm::InputTag>("METSrc"     );
00117   edm::InputTag photonName   = parameters_.getParameter<edm::InputTag>("photonSrc"  );
00118 
00119   
00120 
00121   event.getByLabel(muonName     , muonHandle);
00122   event.getByLabel(electronName , electronHandle);
00123   event.getByLabel(tauName      , tauHandle);
00124   event.getByLabel(jetName      , jetHandle);
00125   event.getByLabel(METName      , METHandle);
00126   event.getByLabel(photonName   , photonHandle);
00127 }

void PatKitHelper::saveNtuple ( edm::Event event,
const std::vector< pat::PhysVarHisto * > &  ntvars 
)

Definition at line 238 of file PatKitHelper.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), p, and verboseLevel_.

Referenced by fillHistograms().

00240 {
00241   //  Ntuplization
00242 
00243   if ( verboseLevel_ > 0 )
00244     cout << "About to save ntuple" << endl;
00245   if ( ntvars.size() ) {
00246 
00247     //--- Iterate over the list and "fill" them via EDM
00248     std::vector< PhysVarHisto* >::const_iterator
00249       p    = ntvars.begin(),
00250       pEnd = ntvars.end();
00251 
00252     for ( ; p != pEnd; ++p ) {
00253 
00254       if      ((*p)->type() == "D") {
00255         saveNtupleVar<double>( event, (*p)->name(), (*p)->value() );
00256       }
00257       else if ((*p)->type() == "F") {
00258         saveNtupleVar<float>( event, (*p)->name(), (*p)->value() );
00259       }
00260       else if ((*p)->type() == "I") {
00261         saveNtupleVar<int>( event, (*p)->name(), static_cast<int>((*p)->value()) );
00262       }
00263       else if ((*p)->type() == "i") {
00264         saveNtupleVar<unsigned int>( event, (*p)->name(), static_cast<unsigned int>((*p)->value()) );
00265       }
00266       else if ((*p)->type() == "S") {
00267         saveNtupleVar<short>( event, (*p)->name(), static_cast<short>((*p)->value()) );
00268       }
00269       else if ((*p)->type() == "s") {
00270         saveNtupleVar<unsigned short>( event, (*p)->name(), static_cast<unsigned short>((*p)->value()) );
00271       }
00272       else if ((*p)->type() == "L") {
00273         saveNtupleVar<long>( event, (*p)->name(), static_cast<long>((*p)->value()) );
00274       }
00275       else if ((*p)->type() == "l") {
00276         saveNtupleVar<unsigned long>( event, (*p)->name(), static_cast<unsigned long>((*p)->value()) );
00277       }
00278       else if ((*p)->type() == "vD") {
00279         vector<double> retvec;
00280         (*p)->vec( retvec );
00281         saveNtupleVec<double>( event, (*p)->name(), retvec );
00282       }
00283       else if ((*p)->type() == "vF") {
00284         vector<float> retvec;
00285         (*p)->vec( retvec );
00286         saveNtupleVec<float>( event, (*p)->name(), retvec );
00287       }
00288       else if ((*p)->type() == "vI") {
00289         vector<int> retvec;
00290         (*p)->vec( retvec );
00291         saveNtupleVec<int>( event, (*p)->name(), retvec );
00292       }
00293       else if ((*p)->type() == "vi") {
00294         vector<unsigned int> retvec;
00295         (*p)->vec( retvec );
00296         saveNtupleVec<unsigned int>( event, (*p)->name(), retvec );
00297       }
00298       else if ((*p)->type() == "vS") {
00299         vector<short> retvec;
00300         (*p)->vec( retvec );
00301         saveNtupleVec<short>( event, (*p)->name(), retvec );
00302       }
00303       else if ((*p)->type() == "vs") {
00304         vector<unsigned short> retvec;
00305         (*p)->vec( retvec );
00306         saveNtupleVec<unsigned short>( event, (*p)->name(), retvec );
00307       }
00308       else if ((*p)->type() == "vL") {
00309         vector<long> retvec;
00310         (*p)->vec( retvec );
00311         saveNtupleVec<long>( event, (*p)->name(), retvec );
00312       }
00313       else if ((*p)->type() == "vl") {
00314         vector<unsigned long> retvec;
00315         (*p)->vec( retvec );
00316         saveNtupleVec<unsigned long>( event, (*p)->name(), retvec );
00317       }
00318       // &&& else if (type == "p4") {
00319       // &&&   produces<math::XYZTLorentzVector> ( name ).setBranchAlias( name );
00320       // &&& }
00321       else {
00322         std::cout << "PatAnalyzerKit::addNtupleVar (ERROR): "
00323                   << "unknown type " << std::endl;
00324 
00325         // &&& Throw an exception in order to abort the job!
00326       }
00327 
00328 
00329       (*p)->clearVec(); // Clear ntuple cache here as well
00330 
00331     }
00332     //
00333   } // end if
00334 }

template<class T>
void PatKitHelper::saveNtupleVar ( edm::Event event,
std::string  name,
value 
) [inline]

Definition at line 339 of file PatKitHelper.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and verboseLevel_.

00341 {
00342   std::auto_ptr<T> aptr( new T (value ) );
00343   if ( verboseLevel_ > 0 )
00344     cout << "Putting variable " << name << " with value " << value << " in event" << endl;
00345   event.put( aptr, name );
00346 }

template<class T>
void pat::PatKitHelper::saveNtupleVec ( edm::Event event,
std::string  name,
const vector< T > &  value 
) [inline]

Definition at line 351 of file PatKitHelper.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, and verboseLevel_.

00353 {
00354   std::auto_ptr<vector<T> > aptr( new vector<T> ( value ) );
00355   if ( verboseLevel_ > 0 ) {
00356     cout << "Putting variable " << name << " with values : " << endl;
00357     typename vector<T>::const_iterator i = aptr->begin(), iend = aptr->end();
00358     for ( ; i != iend; ++i ) {
00359       cout << *i << " ";
00360     }
00361     cout << endl;
00362   }
00363   event.put( aptr, name );
00364 }

template<class T>
void pat::PatKitHelper::saveNtupleVec ( edm::Event event,
std::string  name,
const std::vector< T > &  invec 
) [inline]


Member Data Documentation

edm::Service<TFileService> pat::PatKitHelper::fs_

Definition at line 96 of file PatKitHelper.h.

pat::PhysVarHisto* pat::PatKitHelper::h_eventNumber_

Definition at line 105 of file PatKitHelper.h.

Referenced by bookHistos().

pat::PhysVarHisto* pat::PatKitHelper::h_runNumber_

Definition at line 104 of file PatKitHelper.h.

Referenced by bookHistos().

std::vector< pat::PhysVarHisto* > pat::PatKitHelper::ntVars_

Definition at line 99 of file PatKitHelper.h.

Referenced by bookHistos(), and fillHistograms().

edm::ParameterSet pat::PatKitHelper::parameters_

Definition at line 90 of file PatKitHelper.h.

Referenced by bookHistos(), getAxisLimits(), and getHandles().

PhysicsHistograms* pat::PatKitHelper::physHistos_

Definition at line 93 of file PatKitHelper.h.

Referenced by bookHistos(), fillHistograms(), and ~PatKitHelper().

int pat::PatKitHelper::verboseLevel_

Definition at line 87 of file PatKitHelper.h.

Referenced by saveNtuple(), saveNtupleVar(), and saveNtupleVec().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:49:43 2009 for CMSSW by  doxygen 1.5.4