test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HPDNoiseReader.cc
Go to the documentation of this file.
1 // --------------------------------------------------------
2 // Engine to read HPD noise events from the library
3 // Project: HPD noise library
4 // Author: F.Ratnikov UMd, Jan. 15, 2008
5 // --------------------------------------------------------
6 
8 
9 #include "TFile.h"
10 #include "TTree.h"
11 #include "TBranch.h"
12 
13 #include <iostream>
14 
17 
19  mFile = new TFile (fFileName.c_str(), "READ");
20  mBuffer = new HPDNoiseData ();
22  mFile->GetObject (HPDNoiseDataCatalog::objectName(), catalog);
23  if (catalog) {
24  // initiate trees
25  const std::vector<std::string> names = catalog->allNames();
26  for (size_t i = 0; i < names.size(); ++i) {
27  TTree* tree = (TTree*) mFile->Get (names[i].c_str());
28  if (tree) {
29  mTrees.push_back (tree);
30  mDischargeRate.push_back (catalog->getDischargeRate (i));
33  mElectronEmissionRate.push_back(catalog->getElectronEmissionRate(i));
34  mCurrentEntry.push_back (0);
35  }
36  else {
37  std::cerr << "HPDNoiseReader::HPDNoiseReader-> Can not open tree " << names[i] << " in file " << fFileName << std::endl;
38  }
39  }
40  }
41  else {
42  std::cerr << "HPDNoiseReader::HPDNoiseReader-> Can not open catalog infile " << fFileName << std::endl;
43  }
44 }
45 
47  for (size_t i = 0; i < mTrees.size(); ++i) {
48  delete mTrees[i];
49  }
50  delete mFile;
51  delete mBuffer;
52 }
53 
54 
55 std::vector<std::string> HPDNoiseReader::allNames () const {
56  std::vector<std::string> result;
57  for (size_t i = 0; i < mTrees.size(); ++i) result.push_back (mTrees[i]->GetName ());
58  return result;
59 }
60 
62  for (size_t i = 0; i < mTrees.size(); ++i) {
63  if (std::string (mTrees[i]->GetName ()) == fName) return i;
64  }
65  return -1;
66 }
67 
68 float HPDNoiseReader::dischargeRate (Handle fHandle) const {
69  if (!valid (fHandle)) return 0;
70  return mDischargeRate[fHandle];
71 }
73  if (!valid (fHandle)) return 0;
74  return mIonFeedbackFirstPeakRate[fHandle];
75 }
77  if (!valid (fHandle)) return 0;
78  return mIonFeedbackSecondPeakRate[fHandle];
79 }
80 float HPDNoiseReader::emissionRate (Handle fHandle) const {
81  if (!valid (fHandle)) return 0;
82  return mElectronEmissionRate[fHandle];
83 }
84 
85 unsigned long HPDNoiseReader::totalEntries (Handle fHandle) const {
86  if (!valid (fHandle)) return 0;
87  return mTrees[fHandle]->GetEntries ();
88 }
89 
90 void HPDNoiseReader::grabEntry (Handle fHandle, unsigned long fEntry) {
91  if (!valid (fHandle)) return;
92  TBranch* branch = mTrees[fHandle]->GetBranch (HPDNoiseData::branchName());
93  branch->SetAddress (&mBuffer);
94  branch->GetEntry (fEntry);
95  mCurrentEntry [fHandle] = fEntry;
96 }
97 
98 void HPDNoiseReader::getEntry (Handle fHandle, HPDNoiseData** fData) {
99  if (!valid (fHandle)) return;
100  unsigned int entry = mCurrentEntry [fHandle];
101  if (++entry >= totalEntries (fHandle)) entry = 0; // roll over
102  grabEntry (fHandle, entry);
103  *fData = mBuffer;
104 }
105 
106 void HPDNoiseReader::getEntry (Handle fHandle, unsigned long fEntry, HPDNoiseData** fData) {
107  grabEntry (fHandle, fEntry);
108  *fData = mBuffer;
109 }
110 
int i
Definition: DBlmapReader.cc:9
static const HistoName names[]
float getElectronEmissionRate(size_t i) const
get thermal electron emission noise rate for the HPD instance
float dischargeRate(Handle fHandle) const
discharge rate for the instance
Handle getHandle(const std::string &fName)
get handle to access data for one HPD instance
std::vector< float > mElectronEmissionRate
unsigned long totalEntries(Handle fHandle) const
total number of noise events for the HPD instance in the library
tuple result
Definition: mps_fire.py:84
static const char * objectName()
object name
float ionFeedbackSecondPeakRate(Handle fHandle) const
bool valid(Handle fHandle) const
test if handle is valid
float emissionRate(Handle fHandle) const
ithermal/field emission rate for the instance
std::vector< float > mIonFeedbackSecondPeakRate
HPDNoiseReader(const std::string &fFileName)
float getIonFeedbackSecondPeakRate(size_t i) const
float getIonFeedbackFirstPeakRate(size_t i) const
get ion feedback noise rate for the HPD instance
HPDNoiseData * mBuffer
const std::vector< std::string > & allNames() const
all HPD instance names
static const char * branchName()
branch name
Definition: HPDNoiseData.h:36
std::vector< float > mIonFeedbackFirstPeakRate
std::vector< std::string > allNames() const
all HPD instances in the library
std::pair< double, double > fEntry
Definition: CrossSection.h:40
float getDischargeRate(size_t i) const
get noise rate for the HPD instance
float ionFeedbackFirstPeakRate(Handle fHandle) const
ionfeedback rate for the instance
void getEntry(Handle fHandle, HPDNoiseData **fData)
retrive one entry from the sequentially
list entry
Definition: mps_splice.py:62
std::vector< TTree * > mTrees
std::vector< size_t > mCurrentEntry
void grabEntry(Handle fHandle, unsigned long fEntry)
std::vector< float > mDischargeRate