Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Riccardo Longo
JZCaPA
Commits
5c540742
Commit
5c540742
authored
Jan 23, 2019
by
Yakov Kulinich
Browse files
Changed some class layot
parent
4c25105e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Analysis/include/Analysis.h
View file @
5c540742
...
...
@@ -24,7 +24,6 @@ class Analysis{
public:
Analysis
(
){};
Analysis
(
const
std
::
string
&
){};
virtual
~
Analysis
(
){};
virtual
void
Initialize
(
)
=
0
;
...
...
@@ -32,11 +31,6 @@ class Analysis{
virtual
void
AnalyzeEvent
(
const
std
::
vector
<
TH1
*
>&
)
=
0
;
virtual
void
AnalyzeEvent
(
const
std
::
vector
<
std
::
vector
<
float
>
>&
)
=
0
;
virtual
void
Finalize
(
)
=
0
;
protected:
std
::
string
m_fNameOut
;
TFile
*
m_fOut
;
};
#endif
Analysis/include/DataReader.h
View file @
5c540742
...
...
@@ -28,12 +28,15 @@ class DataReader{
public:
DataReader
(
);
DataReader
(
const
unsigned
int
=
0
,
const
unsigned
int
=
0
);
DataReader
(
const
unsigned
int
=
0
,
const
unsigned
int
=
0
,
const
std
::
string
&
=
""
);
DataReader
(
const
unsigned
int
=
0
,
const
unsigned
int
=
0
,
DataReader
(
const
unsigned
int
=
0
,
const
unsigned
int
=
0
);
DataReader
(
const
unsigned
int
=
0
,
const
unsigned
int
=
0
,
const
std
::
string
&
=
""
);
DataReader
(
const
unsigned
int
=
0
,
const
unsigned
int
=
0
,
const
std
::
string
&
=
""
,
const
unsigned
int
=
0
);
virtual
~
DataReader
();
void
AddAnalysis
(
Analysis
*
);
void
ReadListOfFiles
(
std
::
string
listname
);
void
Initialize
(
);
...
...
@@ -41,7 +44,11 @@ class DataReader{
void
Finalize
(
);
private:
Analysis
*
m_ana
;
// output file
TFile
*
m_fOut
;
// vector of all analysis
std
::
vector
<
Analysis
*
>
m_ana
;
//Number of channels to be read
unsigned
int
m_nCh
;
...
...
Analysis/include/WFAnalysis.h
View file @
5c540742
...
...
@@ -17,7 +17,6 @@ class WFAnalysis : public Analysis{
public
:
WFAnalysis
(
);
WFAnalysis
(
const
std
::
string
&
=
""
);
virtual
~
WFAnalysis
(
);
virtual
void
Initialize
(
);
...
...
Analysis/src/DataReader.cpp
View file @
5c540742
...
...
@@ -19,7 +19,7 @@
#include
<iostream>
#include
"DataReader.h"
#include
"
WF
Analysis.h"
#include
"Analysis.h"
/** @brief Default Constructor for DataReader.
*/
...
...
@@ -63,16 +63,30 @@ DataReader::DataReader( const uint nCh, const uint nSamp,
*/
DataReader
::
DataReader
(
const
uint
nCh
,
const
uint
nSamp
,
const
std
::
string
&
fNameIn
,
const
uint
runNum
)
:
m_nCh
(
nCh
),
m_nSamp
(
nSamp
),
m_
fNameIn
(
fNameIn
),
m_runNumber
(
runNum
)
,
m_ana
(
NULL
),
m_fIn
(
NULL
){
:
m_nCh
(
nCh
),
m_nSamp
(
nSamp
),
m_fNameIn
(
fNameIn
),
m_
runNumber
(
runNum
),
m_readListOfFiles
(
false
),
m_fIn
(
NULL
)
{
}
/** @brief Destructor for DataReader.
*/
DataReader
::~
DataReader
(){
delete
m_fIn
;
for
(
auto
&
ana
:
m_ana
){
delete
ana
;
ana
=
NULL
;
}
}
/** @brief Adds an analysis to vector of analysis
*
* @param1 Pointer to an Analysis.
*
* @return none
*/
void
DataReader
::
AddAnalysis
(
Analysis
*
ana
){
m_ana
.
push_back
(
ana
);
}
...
...
@@ -82,7 +96,7 @@ DataReader::~DataReader(){
*
* @return none
*/
void
DataReader
::
ReadListOfFiles
(
std
::
string
listname
){
void
DataReader
::
ReadListOfFiles
(
std
::
string
listname
){
m_readListOfFiles
=
true
;
m_fListOfFiles
=
listname
;
...
...
@@ -100,12 +114,6 @@ void DataReader::ReadListOfFiles(std::string listname){
*/
void
DataReader
::
Initialize
(){
// If we are reading a list of files, or have no run number
// make default name output.root, otherwise make it
// outputN.root, where N is a run number of a file.
std
::
string
fNameOut
=
m_readListOfFiles
?
"output.root"
:
Form
(
"output%d.root"
,
m_runNumber
);
if
(
m_readListOfFiles
){
// Riccardo - 21/01/2019 - TChain implementation
...
...
@@ -121,12 +129,21 @@ void DataReader::Initialize(){
/** TODO - Add fileChain reading below
*/
}
else
{
m_fIn
=
TFile
::
Open
(
m_fNameIn
.
c_str
()
);
m_fIn
=
TFile
::
Open
(
m_fNameIn
.
c_str
()
);
}
// If we are reading a list of files, or have no run number
// make default name output.root, otherwise make it
// outputN.root, where N is a run number of a file.
std
::
string
fNameOut
=
m_readListOfFiles
?
"output.root"
:
Form
(
"output%d.root"
,
m_runNumber
);
m_fOut
=
new
TFile
(
fNameOut
.
c_str
(),
"RECREATE"
);
m_ana
=
new
WFAnalysis
(
fNameOut
);
m_ana
->
Initialize
();
m_ana
->
SetupHistograms
();
for
(
auto
&
ana
:
m_ana
){
ana
->
Initialize
();
ana
->
SetupHistograms
();
}
}
...
...
@@ -146,16 +163,22 @@ void DataReader::Initialize(){
*/
void
DataReader
::
ProcessEvents
(){
// Raw data to read in as vector of vectors size NxM
// Where N = nCh and M = nSamples per channel.
std
::
vector
<
std
::
vector
<
float
>
>
vWF
;
std
::
vector
<
std
::
vector
<
float
>*
>
pvWF
;
std
::
vector
<
TH1
*
>
vWFH
;
//Buffer histograms for the raw waveforms at each event. They will go to AnalyzeEvent for processing
// Histograms (N of them) for the raw waveforms from each event.
// They will go to AnalyzeEvent for processing
std
::
vector
<
TH1
*
>
vWFH
;
// Resize these to be of size nCh.
vWF
.
resize
(
m_nCh
);
pvWF
.
resize
(
m_nCh
);
vWFH
.
resize
(
m_nCh
);
/** TODO : add reading for list of files */
TTree
*
tree
=
static_cast
<
TTree
*
>
(
m_fIn
->
Get
(
"tree"
)
);
TTree
*
tree
=
static_cast
<
TTree
*
>
(
m_fIn
->
Get
(
"tree"
)
);
// Connect raw data to tree
// For the moment, the only reading implemented is the raw data from each channel.
...
...
@@ -164,9 +187,9 @@ void DataReader::ProcessEvents(){
for
(
uint
ch
=
0
;
ch
<
m_nCh
;
ch
++
){
pvWF
[
ch
]
=
&
vWF
[
ch
];
tree
->
SetBranchAddress
(
Form
(
"RawC%d"
,
ch
),
&
pvWF
[
ch
]
);
vWFH
[
ch
]
=
new
TH1D
(
Form
(
"hWF%d"
,
ch
),
Form
(
"hWF%d;samp;amp"
,
ch
),
m_nSamp
,
0
,
m_nSamp
);
vWFH
[
ch
]
=
new
TH1D
(
Form
(
"hWF%d"
,
ch
),
Form
(
"hWF%d;samp;amp"
,
ch
),
m_nSamp
,
0
,
m_nSamp
);
}
std
::
cout
<<
"File: "
<<
m_fIn
->
GetName
()
<<
" has "
<<
tree
->
GetEntries
()
<<
" events."
<<
std
::
endl
;
...
...
@@ -184,11 +207,13 @@ void DataReader::ProcessEvents(){
}
// End loop over samples in each channel
}
// End loop over channels
// Now call analysis
. With the provided WFAnalysis,
// Now call
all
analysis
and run their AnalyzeEvent.
// Can either send a vector of histos, or a 2D vector
// Of all the data, depending on what you want to do.
m_ana
->
AnalyzeEvent
(
vWFH
);
m_ana
->
AnalyzeEvent
(
vWF
);
for
(
auto
&
ana
:
m_ana
){
ana
->
AnalyzeEvent
(
vWFH
);
ana
->
AnalyzeEvent
(
vWF
);
}
}
// End event loop
for
(
auto
&
h
:
vWFH
){
delete
h
;
}
...
...
@@ -202,11 +227,19 @@ void DataReader::ProcessEvents(){
* @return none
*/
void
DataReader
::
Finalize
(){
if
(
m_fIn
){
m_fIn
->
Close
();
}
m_ana
->
Finalize
();
// enter the output file since
// we will be writing to it now.
m_fOut
->
cd
();
for
(
auto
&
ana
:
m_ana
){
ana
->
Finalize
();
}
m_fOut
->
Close
();
}
Analysis/src/WFAnalysis.cpp
View file @
5c540742
...
...
@@ -11,7 +11,6 @@
* @bug No known bugs.
*/
#include
<TFile.h>
#include
<TH1.h>
#include
<TH2.h>
#include
<TH3.h>
...
...
@@ -23,29 +22,19 @@
/** @brief Default Constructor for WFAnalysis.
*/
WFAnalysis
::
WFAnalysis
(
)
:
WFAnalysis
(
""
){
WFAnalysis
::
WFAnalysis
(
){
}
/** @brief Constructor for WFAnalysis.
*
* @param1 Name of output file
*/
WFAnalysis
::
WFAnalysis
(
const
std
::
string
&
fNameOut
){
m_fNameOut
=
fNameOut
;
}
/** @brief Destructor for WFAnalysis.
*/
WFAnalysis
::~
WFAnalysis
(
){
delete
m_fOut
;
}
/** @brief Initialization method for WFAnalysis
*
*
Create output root file will be written
.
*
Get pointer to output file
.
* Can add other things here that you would
* perhaps not put into the constructor.
* I.e. a TTree, some tools. Etc.
...
...
@@ -54,9 +43,6 @@ WFAnalysis::~WFAnalysis( ){
*/
void
WFAnalysis
::
Initialize
(
){
//Intializes the pointer to the output file
m_fOut
=
new
TFile
(
m_fNameOut
.
c_str
(),
"RECREATE"
);
}
...
...
@@ -118,18 +104,13 @@ void WFAnalysis::AnalyzeEvent( const std::vector< std::vector< float > >& vWF ){
/** @brief Finalize method for WFAnalysis
*
* Write
output file. Write
histograms, TTree if it exists.
* Write histograms, TTree if it exists.
*
* @return none
*/
void
WFAnalysis
::
Finalize
(
){
m_fOut
->
cd
();
// If these exist...
// m_tree->Write();
// m_hist->Write();
m_fOut
->
Close
();
}
Analysis/userFunctions/AnalysisExample.cpp
View file @
5c540742
...
...
@@ -7,6 +7,7 @@
*/
#include
"DataReader.h"
#include
"WFAnalysis.h"
using
namespace
std
;
...
...
@@ -16,14 +17,19 @@ int main(int argc, char *argv[]){
int
nCh
=
20
;
// 5 DRS4 x 4 ch/board - 16 RPD channels
int
nSamp
=
1024
;
// Default number of samples?
int
runNum
=
171
;
// !! Change for your test !!
int
runNum
=
54
;
// !! Change for your test !!
string
fNameIn
=
"TreeZDCBeamTestRun
171
.root"
;
// !! Change for your test !!
string
fNameIn
=
"TreeZDCBeamTestRun
54
.root"
;
// !! Change for your test !!
DataReader
*
r
=
new
DataReader
(
nCh
,
nSamp
,
fNameIn
,
runNum
);
r
->
AddAnalysis
(
new
WFAnalysis
()
);
r
->
Initialize
();
r
->
ProcessEvents
();
r
->
Finalize
();
delete
r
;
return
0
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment