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 // $Id: HPDNoiseMaker.cc,v 1.5 2008/08/04 22:07:08 fedor Exp $
6 // --------------------------------------------------------
7 
9 
12 
13 
14 #include "TFile.h"
15 #include "TTree.h"
16 #include "TBranch.h"
17 
18 #include <iostream>
19 
20 HPDNoiseMaker::HPDNoiseMaker (const std::string& fFileName) {
21  mFile = new TFile (fFileName.c_str(), "RECREATE");
23 }
24 
26  for (size_t i = 0; i < mTrees.size(); ++i) {
27  mTrees[i]->Write();
28  delete mTrees[i];
29  }
31  delete mCatalog;
32  delete mFile;
33 }
34 
35 int HPDNoiseMaker::addHpd (const std::string& fName) {
36  TDirectory* currentDirectory = gDirectory;
37  mFile->cd();
38  mCatalog->addHpd (fName, 0., 0.,0.,0.);
39  mNames.push_back (fName);
40  mTrees.push_back (new TTree (fName.c_str(), fName.c_str()));
41  HPDNoiseData* addr = 0;
42  TBranch* newBranch = mTrees.back()->Branch (HPDNoiseData::branchName(), HPDNoiseData::className(), &addr, 32000, 1);
43  if (!newBranch) {
44  std::cerr << "HPDNoiseMaker::addHpd-> Can not make branch HPDNoiseData to the tree " << fName << std::endl;
45  }
46  currentDirectory->cd();
47  return mNames.size();
48 }
49 
50 void HPDNoiseMaker::setRate (const std::string& fName, float fDischargeRate,
51  float fIonFeedbackFirstPeakRate, float fIonFeedbackSecondPeakRate, float fElectronEmissionRate) {
52  mCatalog->setRate (fName, fDischargeRate, fIonFeedbackFirstPeakRate, fIonFeedbackSecondPeakRate, fElectronEmissionRate);
53 }
54 
55 void HPDNoiseMaker::newHpdEvent (const std::string& fName, const HPDNoiseData& fData) {
56  for (size_t i = 0; i < mNames.size(); ++i) {
57  if (mNames[i] == fName) {
58  newHpdEvent (i, fData);
59  }
60  }
61 }
62 
63 void HPDNoiseMaker::newHpdEvent (size_t i, const HPDNoiseData& fData) {
64  if (i < mTrees.size()) {
65  HPDNoiseData* data = (HPDNoiseData*) &fData;
66  TBranch* branch = mTrees[i]->GetBranch (HPDNoiseData::branchName());
67  if (branch) {
68  branch->SetAddress(&data);
69  mTrees[i]->Fill();
70  }
71  else {
72  std::cerr << "HPDNoiseMaker::newHpdEvent-> Can not find branch " << HPDNoiseData::branchName()
73  << " in the tree" << std::endl;
74  }
75  }
76 }
77 
78 unsigned long HPDNoiseMaker::totalEntries (const std::string& fName) const {
79  for (size_t i = 0; i < mNames.size(); ++i) {
80  if (mNames[i] == fName) return mTrees[i]->GetEntries ();
81  }
82  return 0;
83 }
int i
Definition: DBlmapReader.cc:9
HPDNoiseDataCatalog * mCatalog
Definition: HPDNoiseMaker.h:42
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:41
HPDNoiseMaker(const std::string &fFileName)
std::vector< TTree * > mTrees
Definition: HPDNoiseMaker.h:40
static const char * objectName()
object name
static const char * className()
class name
Definition: HPDNoiseData.h:35
static const char * branchName()
branch name
Definition: HPDNoiseData.h:37
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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