CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HPDNoiseMaker.cc
Go to the documentation of this file.
1 // --------------------------------------------------------
2 // Engine to store HPD noise events in the library
3 // Project: HPD noise library
4 // Author: F.Ratnikov UMd, Jan. 15, 2008
5 // --------------------------------------------------------
6 
8 
11 
12 
13 #include "TFile.h"
14 #include "TTree.h"
15 #include "TBranch.h"
16 
17 #include <iostream>
18 
20  mFile = new TFile (fFileName.c_str(), "RECREATE");
22 }
23 
25  for (size_t i = 0; i < mTrees.size(); ++i) {
26  mTrees[i]->Write();
27  delete mTrees[i];
28  }
30  delete mCatalog;
31  delete mFile;
32 }
33 
35  TDirectory* currentDirectory = gDirectory;
36  mFile->cd();
37  mCatalog->addHpd (fName, 0., 0.,0.,0.);
38  mNames.push_back (fName);
39  mTrees.push_back (new TTree (fName.c_str(), fName.c_str()));
40  HPDNoiseData* addr = 0;
41  TBranch* newBranch = mTrees.back()->Branch (HPDNoiseData::branchName(), HPDNoiseData::className(), &addr, 32000, 1);
42  if (!newBranch) {
43  std::cerr << "HPDNoiseMaker::addHpd-> Can not make branch HPDNoiseData to the tree " << fName << std::endl;
44  }
45  currentDirectory->cd();
46  return mNames.size();
47 }
48 
49 void HPDNoiseMaker::setRate (const std::string& fName, float fDischargeRate,
50  float fIonFeedbackFirstPeakRate, float fIonFeedbackSecondPeakRate, float fElectronEmissionRate) {
51  mCatalog->setRate (fName, fDischargeRate, fIonFeedbackFirstPeakRate, fIonFeedbackSecondPeakRate, fElectronEmissionRate);
52 }
53 
55  for (size_t i = 0; i < mNames.size(); ++i) {
56  if (mNames[i] == fName) {
57  newHpdEvent (i, fData);
58  }
59  }
60 }
61 
62 void HPDNoiseMaker::newHpdEvent (size_t i, const HPDNoiseData& fData) {
63  if (i < mTrees.size()) {
64  HPDNoiseData* data = (HPDNoiseData*) &fData;
65  TBranch* branch = mTrees[i]->GetBranch (HPDNoiseData::branchName());
66  if (branch) {
67  branch->SetAddress(&data);
68  mTrees[i]->Fill();
69  }
70  else {
71  std::cerr << "HPDNoiseMaker::newHpdEvent-> Can not find branch " << HPDNoiseData::branchName()
72  << " in the tree" << std::endl;
73  }
74  }
75 }
76 
77 unsigned long HPDNoiseMaker::totalEntries (const std::string& fName) const {
78  for (size_t i = 0; i < mNames.size(); ++i) {
79  if (mNames[i] == fName) return mTrees[i]->GetEntries ();
80  }
81  return 0;
82 }
int i
Definition: DBlmapReader.cc:9
HPDNoiseDataCatalog * mCatalog
Definition: HPDNoiseMaker.h:41
void setRate(const std::string &fName, float fDischargeRate, float fIonFeedbackFirstPeakRate, float fIonFeedbackSecondPeakRate, float fElectronEmissionRate)
set discharge/IonFeedback/Electron emission noise rates
std::vector< std::string > mNames
Definition: HPDNoiseMaker.h:40
HPDNoiseMaker(const std::string &fFileName)
std::vector< TTree * > mTrees
Definition: HPDNoiseMaker.h:39
static const char * objectName()
object name
static const char * className()
class name
Definition: HPDNoiseData.h:34
static const char * branchName()
branch name
Definition: HPDNoiseData.h:36
unsigned long totalEntries(const std::string &mName) const
get number of stored events by HPD index
void addHpd(const std::string &fName, float fDischargeRate, float fIonFeedbackFirstPeakRate, float fIonFeedbackSecondPeakRate, float fElectronEmissionRate)
add new HPD instance to the catalog
void newHpdEvent(const std::string &mName, const HPDNoiseData &mData)
add new HPD noise event by HPD name
void setRate(const std::string &fName, float fDischargeRate, float fIonFeedbackFirstPeakRate, float fIonFeedbackSecondPeakRate, float fElectronEmissionRate)
set noise rate for the instance by using different processes
int addHpd(const std::string &fName)
define new HPD instance