forked from JeffersonLab/SBS-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBSBBShower.cxx
262 lines (216 loc) · 7.42 KB
/
SBSBBShower.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
///////////////////////////////////////////////////////////////////////////////
//
// SBSBBShower
//
///////////////////////////////////////////////////////////////////////////////
#include "SBSBBShower.h"
#include "SBSCalorimeter.h"
#include <iostream>
#include "THaEvData.h"
#include <iomanip>
using namespace std;
ClassImp(SBSBBShower);
/*
* SBSBBShower constructor.
*
* Specify SBSCalorimeter to use both TDC and ADC Multi-samples
*/
SBSBBShower::SBSBBShower( const char* name, const char* description,
THaApparatus* apparatus ) : SBSCalorimeter(name,description,apparatus),
fSearchRegion(0), fSearchRowmin(0), fSearchRowmax(0), fSearchColmin(0),
fSearchColmax(0)
{
SetModeADC(SBSModeADC::kWaveform); //< Multi-function ADC
SetModeTDC(SBSModeTDC::kNone); //< No TDC information
}
//_____________________________________________________________________________
Int_t SBSBBShower::ReadDatabase( const TDatime& date )
{
cout << "******** Detector " << GetName() << " ReadDatabase ********" << endl;
//static const char* const here = "ReadDatabase()";
// Call the parent class ReadDatabase first
Int_t err = SBSCalorimeter::ReadDatabase(date);
if(err) {
return err;
}
fIsInit = false;
FILE* file = OpenFile( date );
if( !file ) return kFileError;
std::vector<Double_t> dxyz;
// Readout components needed by BBShower
DBRequest config_request[] = {
{ "thr_adc", &fThrADC, kDouble, 0, true },
{ "clus_rad", &fClusRadius, kDouble, 0, true },
{ "mc_data", &fMCdata, kInt, 0, true },// flag for MC data
{ "dxdydz", &dxyz, kDoubleV, 3 }, // dx and dy block spacings
{ 0 } ///< Request must end in a NULL
};
err = LoadDB( file, date, config_request, fPrefix );
fclose(file);
if(err) {
return err;
}
fClusBlockRadX = Int_t(fClusRadius/dxyz[0]);
fClusBlockRadY = Int_t(fClusRadius/dxyz[1]);
if(fMaxNclus>1)fMultClus = true;
fIsInit = true;
return 0;
}
Int_t SBSBBShower::DefineVariables( EMode mode )
{
if( mode == kDefine && fIsSetup ) return kOK;
// Initialize parent variables first
Int_t err = SBSCalorimeter::DefineVariables(mode);
std::cout << " SBS BBShower define variables " << err << std::endl;
if(err)
return err;
// Register variables in global list
if(fMCdata){
RVarDef varsmc[] = {
{ "e_m_res", "Energy resolution of main cluster", "fEres" },
{ "x_m_res", "x-position resolution (m) of main cluster", "fXres" },
{ "y_m_res", "y-position resolution (m) of main cluster", "fYres" },
{ "e_res", "Energy resolution of all clusters", "fE_cl_res" },
{ "x_res", "x-position resolution (m) of all clusters", "fX_cl_res" },
{ "y_res", "y-position resolution (m) of all clusters", "fY_cl_res" },
{ 0 }
};
err = DefineVarsFromList( varsmc, mode );
if( err != kOK )
return err;
}
return err;
};
//_____________________________________________________________________________
Int_t SBSBBShower::CoarseProcess(TClonesArray& tracks)
{
// std::cout << "******** Detector " << GetName() << "BBshower Coarse process = " << fCoarseProcessed << std::endl;
// if(fCoarseProcessed) return 0;
// Call the parent's parent class coarse process to start filling out output variables
//std::cout << "SBSGen Coarse process " << std::endl;
SBSGenericDetector::CoarseProcess(tracks);
fCoarseProcessed = 1;
return 0;
}
//_____________________________________________________________________________
Int_t SBSBBShower::FineProcess(TClonesArray& tracks)
{
// Fine Shower processing.
// Call parent's parent class to prepare any other variables
SBSCalorimeter::FineProcess(tracks);
// The parent class already sorted by energy, and the first cluster is the
// one with the highest energy.
// This function now needs to store the MCdata
for (size_t i=0;i<fClusters.size();i++) {
if(fDebug){
cout << " cluster " << i << " E = " << fClusters[i]->GetE() << " "
<< fClusters[i]->GetX() << " " << fClusters[i]->GetY()
<< " " << fClusters[i]->GetMult() << endl;
}
if(fMCdata){
fE_cl_res.push_back(1.0 - fClusters[i]->GetE());
fX_cl_res.push_back(fClusters[i]->GetX());
fY_cl_res.push_back(fClusters[i]->GetY());
}
}
fFineProcessed = 1;
return 0;
}
SBSBBShower::~SBSBBShower()
{
}
void SBSBBShower::LoadMCHitAt( Double_t x, Double_t y, Double_t E )
{
Clear();
SBSCalorimeterCluster *cluster = new SBSCalorimeterCluster(fNclublk);
cluster->SetE(E);
cluster->SetX(x);
cluster->SetY(y);
cluster->SetMult(0);
fClusters.push_back(cluster);
fNclus=fClusters.size();
}
void SBSBBShower::MakeCluster(Int_t nblk_size, SBSElement* blk)
{
SBSCalorimeterCluster* cluster = new SBSCalorimeterCluster(nblk_size,blk);
fClusters.push_back(cluster);
}
void SBSBBShower::MakeCluster(Int_t nblk_size)
{
SBSCalorimeterCluster* cluster = new SBSCalorimeterCluster(nblk_size);
fClusters.push_back(cluster);
}
void SBSBBShower::AddToCluster(Int_t nc,SBSElement* blk)
{
if (nc < (int)fClusters.size()) fClusters[nc]->AddElement(blk);
}
void SBSBBShower::MakeMainCluster(Int_t iclust)
{
//Since we only ever really want one cluster as the "Main" one, let's invoke
//ClearCaloOutput here:
ClearCaloOutput( fMainclus );
// It is assumed that if MakeMainCluster is called for index iclust, then we
// want to set fBestClusterIndex to iclust:
if(!fClusters.empty() && iclust >= 0 && iclust < fClusters.size() ) {
SBSCalorimeterCluster *clus = fClusters[iclust];
fMainclus.e.push_back(clus->GetE());
fMainclus.again.push_back(clus->GetAgain());
fMainclus.atime.push_back(clus->GetAtime());
fMainclus.tdctime.push_back(clus->GetTDCtime());
//fMainclus.e_c.push_back(clus->GetE()*(fConst + fSlope*fAccCharge));
fMainclus.x.push_back(clus->GetX());
fMainclus.y.push_back(clus->GetY());
fMainclus.n.push_back(clus->GetMult());
fMainclus.blk_e.push_back(clus->GetEblk());
//fMainclus.blk_e_c.push_back(clus->GetEblk()*(fConst + fSlope*fAccCharge));
fMainclus.id.push_back(clus->GetElemID());
fMainclus.row.push_back(clus->GetRow());
fMainclus.col.push_back(clus->GetCol());
fBestClusterIndex = iclust;
} else { //Make an "empty" cluster:
fMainclus.e.push_back( 0.0 );
fMainclus.again.push_back( 0.0 );
fMainclus.atime.push_back( -1000.0 );
fMainclus.tdctime.push_back( -1000.0 );
//fMainclus.e_c.push_back( 0.0 );
fMainclus.x.push_back( 0.0 );
fMainclus.y.push_back( 0.0 );
fMainclus.n.push_back( 0 );
fMainclus.blk_e.push_back( 0.0 );
//fMainclus.blk_e_c.push_back( 0.0 );
fMainclus.id.push_back( -1 );
fMainclus.row.push_back( -1 );
fMainclus.col.push_back( -1 );
fBestClusterIndex = -1;
}
//
fNclus=0;
for( const auto& cluster: fClusters ) {
if( cluster->GetMult() > 0 ) fNclus++;
}
//
}
void SBSBBShower::SetSearchRegion(int rowmin, int rowmax, int colmin, int colmax)
{
fSearchRowmin = rowmin;
fSearchRowmax = rowmax;
fSearchColmin = colmin;
fSearchColmax = colmax;
fSearchRegion = true;
fMultClus = false;
}
void SBSBBShower::Clear( Option_t* opt )
{
SBSCalorimeter::Clear(opt);
fEres = fXres = fYres = 0.0;
fE_cl_res.clear();
fX_cl_res.clear();
fY_cl_res.clear();
}
//_____________________________________________________________
SBSElement* SBSBBShower::GetElement(UInt_t i)
{
SBSElement* blk=nullptr;
if(i < fElements.size()) blk = fElements[i];
return blk;
}