CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/SimCalorimetry/HcalSimAlgos/src/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.5 2008/08/04 22:07:08 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   for (size_t i = 0; i < mTrees.size(); ++i) {
00027     mTrees[i]->Write();
00028     delete mTrees[i];
00029   }
00030   mFile->WriteObject (mCatalog, HPDNoiseDataCatalog::objectName ());
00031   delete mCatalog;
00032   delete mFile;
00033 }
00034 
00035 int HPDNoiseMaker::addHpd (const std::string& fName) {
00036   TDirectory* currentDirectory = gDirectory;
00037   mFile->cd();
00038   mCatalog->addHpd (fName, 0., 0.,0.,0.);
00039   mNames.push_back (fName);
00040   mTrees.push_back (new TTree (fName.c_str(), fName.c_str()));
00041   HPDNoiseData* addr = 0;
00042   TBranch* newBranch = mTrees.back()->Branch (HPDNoiseData::branchName(), HPDNoiseData::className(), &addr, 32000, 1);
00043   if (!newBranch) {
00044     std::cerr << "HPDNoiseMaker::addHpd-> Can not make branch HPDNoiseData to the tree " << fName << std::endl;
00045   }
00046   currentDirectory->cd();
00047   return mNames.size();
00048 }
00049 
00050 void HPDNoiseMaker::setRate (const std::string& fName, float fDischargeRate, 
00051                              float fIonFeedbackFirstPeakRate, float fIonFeedbackSecondPeakRate, float fElectronEmissionRate) {
00052   mCatalog->setRate (fName, fDischargeRate, fIonFeedbackFirstPeakRate, fIonFeedbackSecondPeakRate, fElectronEmissionRate);
00053 }
00054 
00055 void HPDNoiseMaker::newHpdEvent (const std::string& fName, const HPDNoiseData& fData) {
00056   for (size_t i = 0; i < mNames.size(); ++i) {
00057     if (mNames[i] == fName) {
00058       newHpdEvent (i, fData);
00059     }
00060   }
00061 }
00062 
00063 void HPDNoiseMaker::newHpdEvent (size_t i, const HPDNoiseData& fData) {
00064   if (i < mTrees.size()) {
00065     HPDNoiseData* data = (HPDNoiseData*) &fData;
00066     TBranch* branch = mTrees[i]->GetBranch (HPDNoiseData::branchName());
00067     if (branch) {
00068       branch->SetAddress(&data);
00069       mTrees[i]->Fill();
00070     }
00071     else {
00072       std::cerr << "HPDNoiseMaker::newHpdEvent-> Can not find branch " << HPDNoiseData::branchName() 
00073                 << " in the tree" << std::endl;
00074     }
00075   }
00076 }
00077 
00078 unsigned long HPDNoiseMaker::totalEntries (const std::string& fName) const {
00079   for (size_t i = 0; i < mNames.size(); ++i) {
00080     if (mNames[i] == fName) return mTrees[i]->GetEntries ();
00081   }
00082   return 0;
00083 }