CMS 3D CMS Logo

HPDNoiseMaker.cc

Go to the documentation of this file.
00001 // --------------------------------------------------------
00002 // Engine to store HPD noise events in the library
00003 // Project: HPD noise library
00004 // Author: F.Ratnikov UMd, Jan. 15, 2008
00005 // $Id: HPDNoiseMaker.cc,v 1.2 2008/01/17 23:35:53 fedor Exp $
00006 // --------------------------------------------------------
00007 
00008 #include "SimCalorimetry/HcalSimAlgos/interface/HPDNoiseMaker.h"
00009 
00010 #include "SimCalorimetry/HcalSimAlgos/interface/HPDNoiseData.h"
00011 #include "SimCalorimetry/HcalSimAlgos/interface/HPDNoiseDataCatalog.h"
00012 
00013 
00014 #include "TFile.h"
00015 #include "TTree.h"
00016 #include "TBranch.h"
00017 
00018 #include <iostream>
00019 
00020 HPDNoiseMaker::HPDNoiseMaker (const std::string& fFileName) {
00021   mFile = new TFile (fFileName.c_str(), "RECREATE");
00022   mCatalog = new HPDNoiseDataCatalog ();
00023 }
00024 
00025 HPDNoiseMaker::~HPDNoiseMaker () {
00026   mFile->cd();  
00027   for (size_t i = 0; i < mTrees.size(); ++i) {
00028     mTrees[i]->Write();
00029     delete mTrees[i];
00030   }
00031   mCatalog->Write();
00032   delete mCatalog;
00033   delete mFile;
00034 }
00035 
00036 int HPDNoiseMaker::addHpd (const std::string& fName) {
00037    TDirectory* currentDirectory = gDirectory;
00038    mFile->cd();
00039   mCatalog->addHpd (fName, 0.);
00040   mNames.push_back (fName);
00041   mTrees.push_back (new TTree (fName.c_str(), fName.c_str()));
00042   void* addr = 0;
00043   mTrees.back()->Branch ("HPDNoiseData", "HPDNoiseData", &addr, 32000, 1);
00044    currentDirectory->cd();
00045   return mNames.size();
00046 }
00047 
00048 void HPDNoiseMaker::setRate (const std::string& fName, float fRate) {
00049   mCatalog->setRate (fName, fRate);
00050 }
00051 
00052 void HPDNoiseMaker::newHpdEvent (const std::string& fName, const HPDNoiseData& fData) {
00053   for (size_t i = 0; i < mNames.size(); ++i) {
00054     if (mNames[i] == fName) {
00055       newHpdEvent (i, fData);
00056     }
00057   }
00058 }
00059 
00060 void HPDNoiseMaker::newHpdEvent (size_t i, const HPDNoiseData& fData) {
00061   if (i < mTrees.size()) {
00062     HPDNoiseData* data = (HPDNoiseData*) &fData;
00063     mTrees[i]->GetBranch ("HPDNoiseData")->SetAddress(&data);
00064     mTrees[i]->Fill();
00065   }
00066 }
00067 
00068 unsigned long HPDNoiseMaker::totalEntries (const std::string& fName) const {
00069   for (size_t i = 0; i < mNames.size(); ++i) {
00070     if (mNames[i] == fName) return mTrees[i]->GetEntries ();
00071   }
00072   return 0;
00073 }

Generated on Tue Jun 9 17:46:23 2009 for CMSSW by  doxygen 1.5.4