Newer
Older
/**
\class THcBCMCurrent
\ingroup PhysMods
\brief Read BCM current from scalers and compare to thresholds
This physics module does:
- Read average BCM beam current values from scaler parameter file.
- Write the values into bcm#.AvgCurrent for each event
- Compare the current values with the threshold and
set event flags (BCM1 and BCM2 only)
You can set the threshold using SetCurrentCut
instead of gBCM_Current_threshold
*/
#include "THcParmList.h"
#include "THcGlobals.h"
#include "THcHitList.h"
#include "THcBCMCurrent.h"
using namespace std;
THcBCMCurrent::THcBCMCurrent(const char* name,
const char* description) :
THaPhysicsModule(name, description)
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
fBCM1avg = 0;
fBCM2avg = 0;
fBCM4aavg = 0;
fBCM4bavg = 0;
fBCM17avg = 0;
}
//__________________________________________________
THcBCMCurrent::~THcBCMCurrent()
{
DefineVariables (kDelete);
delete [] fiBCM1; fiBCM1 = NULL;
delete [] fiBCM2; fiBCM2 = NULL;
delete [] fiBCM4a; fiBCM4a = NULL;
delete [] fiBCM4b; fiBCM4b = NULL;
delete [] fiBCM17; fiBCM17 = NULL;
delete [] fEvtNum; fEvtNum = NULL;
}
//__________________________________________________
THaAnalysisObject::EStatus THcBCMCurrent::Init( const TDatime& date )
{
if( THaPhysicsModule::Init( date ) != kOK )
return fStatus;
return fStatus = kOK;
}
//__________________________________________________
Int_t THcBCMCurrent::ReadDatabase( const TDatime& date )
{
DBRequest list1[] = {
{"num_scal_reads", &fNscaler, kInt},
{"gBCM_Current_threshold", &fThreshold, kDouble},
{"gBCM_Current_threshold_index", &fBCMIndex, kInt},
gHcParms->LoadParmValues((DBRequest*)&list1);
fiBCM1 = new Double_t[fNscaler];
fiBCM2 = new Double_t[fNscaler];
fiBCM4a = new Double_t[fNscaler];
fiBCM4b = new Double_t[fNscaler];
fiBCM17 = new Double_t[fNscaler];
fEvtNum = new Int_t[fNscaler];
{"scal_read_bcm1_current", fiBCM1, kDouble, (UInt_t) fNscaler},
{"scal_read_bcm2_current", fiBCM2, kDouble, (UInt_t) fNscaler},
{"scal_read_bcm4a_current", fiBCM4a, kDouble, (UInt_t) fNscaler},
{"scal_read_bcm4b_current", fiBCM4b, kDouble, (UInt_t) fNscaler},
{"scal_read_bcm17_current", fiBCM17, kDouble, (UInt_t) fNscaler},
{"scal_read_event", fEvtNum, kInt, (UInt_t) fNscaler},
{0}
};
gHcParms->LoadParmValues((DBRequest*)&list2);
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
BCMInfo binfo;
for(int i=0; i<fNscaler; i++)
{
binfo.bcm1_current = fiBCM1[i];
binfo.bcm2_current = fiBCM2[i];
binfo.bcm4a_current = fiBCM4a[i];
binfo.bcm4b_current = fiBCM4b[i];
binfo.bcm17_current = fiBCM17[i];
BCMInfoMap.insert( std::make_pair(fEvtNum[i], binfo) );
}
return kOK;
}
//__________________________________________________
Int_t THcBCMCurrent::DefineVariables( EMode mode )
{
if( mode == kDefine && fIsSetup ) return kOK;
fIsSetup = ( mode == kDefine );
RVarDef vars[] = {
{"CurrentFlag", "BCM current flag for good event", "fBCMflag"},
{"bcm1.AvgCurrent", "BCM1 average beam current", "fBCM1avg"},
{"bcm2.AvgCurrent", "BCM2 average beam current", "fBCM2avg"},
{"bcm4a.AvgCurrent", "BCM4a average beam current", "fBCM4aavg"},
{"bcm4b.AvgCurrent", "BCM4b average beam current", "fBCM4bavg"},
{"bcm17.AvgCurrent", "BCM17 average beam current", "fBCM17avg"},
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
{ 0 }
};
return DefineVarsFromList(vars, mode);
}
//__________________________________________________
Int_t THcBCMCurrent::Process( const THaEvData& evdata )
{
if( !IsOK() ) return -1;
int fEventNum = evdata.GetEvNum();
BCMInfo binfo;
Int_t fGetScaler = GetAvgCurrent( fEventNum, binfo );
if(fGetScaler != kOK)
{
fBCM1avg = 0;
fBCM2avg = 0;
fBCM4aavg = 0;
fBCM4bavg = 0;
fBCM17avg = 0;
}
else
{
fBCM1avg = binfo.bcm1_current;
fBCM2avg = binfo.bcm2_current;
fBCM4aavg = binfo.bcm4a_current;
fBCM4bavg = binfo.bcm4b_current;
fBCM17avg = binfo.bcm17_current;
}
switch (fBCMIndex)
{
case BCM1 :
fBCMflag = ( fBCM1avg < fThreshold )?0:1;
break;
case BCM2:
fBCMflag = ( fBCM2avg < fThreshold )?0:1;
break;
case BCM4A:
fBCMflag = ( fBCM4aavg < fThreshold )?0:1;
break;
case BCM4B:
fBCMflag = ( fBCM4bavg < fThreshold )?0:1;
break;
case BCM17:
fBCMflag = ( fBCM17avg < fThreshold )?0:1;
break;
default:
fBCMflag = 0;
break;
}
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
return kOK;
}
//__________________________________________________
Int_t THcBCMCurrent::GetAvgCurrent( Int_t fevn, BCMInfo &bcminfo )
{
map<int, BCMInfo>::iterator it, next;
it = BCMInfoMap.find(fevn);
if( it != BCMInfoMap.end() )
{
bcminfo.bcm1_current = it->second.bcm1_current;
bcminfo.bcm2_current = it->second.bcm2_current;
bcminfo.bcm4a_current = it->second.bcm4a_current;
bcminfo.bcm4b_current = it->second.bcm4b_current;
bcminfo.bcm17_current = it->second.bcm17_current;
return kOK;
}
else
{
next = BCMInfoMap.upper_bound(fevn);
if( next != BCMInfoMap.end() )
{
bcminfo.bcm1_current = next->second.bcm1_current;
bcminfo.bcm2_current = next->second.bcm2_current;
bcminfo.bcm4a_current = next->second.bcm4a_current;
bcminfo.bcm4b_current = next->second.bcm4b_current;
bcminfo.bcm17_current = next->second.bcm17_current;
return kOK;
}
return kOK+1;
}
return kOK+1;
}
//__________________________________________________
ClassImp(THcBCMCurrent)