9#include "trg/ecl/modules/trgeclTimingCal/TrgEclTimingCalibration.h"
27 "0 : Raw data 1 : Simulation data", 0);
30 "0 : Beam data 1 : Cosmic ray data", 0);
33 "0 : Not using 3D bhabha veto bit 1 : Using 3D bhabha veto bit ", 1);
36 "Reference TCID. Default setting : 184", 184);
39 "A TC energy calibration factor (GeV/ADC), default 0.00525", 0.00525);
42 "Number of TC cut : Events will be used < ntc", 999);
45 "High energy cut", 9999.0);
48 "Low energy cut", 0.0);
51 "Flag including FWD end cap", 1);
54 "Flag including Barrel", 1);
57 "Flag including BWD end cap", 1);
66 "iteration chisq cut", 1000.0);
130 if (nEvtStore <= 0)
return;
131 if (TRGECLEvtStore[0] -> getCheckSum() != 0)
return;
132 if (TRGECLEvtStore[0] -> get3DBhabhaV() != 1)
return;
138 if (nEvtStore <= 0)
return;
139 if (
TRGECLTrg[0] -> get3DBhabha() != 1)
return;
159 if (ntc < 2 || ntc >
cut_ntc)
return 0;
160 for (
int itc = 0; itc < ntc; itc++) {
161 TCId.push_back(TCHit[itc]->getTCId());
162 TCEnergy.push_back(TCHit[itc]->getEnergyDep());
163 TCTiming.push_back((
double) TCHit[itc]->getTimeAve());
168 if (ntc < 2 || ntc >
cut_ntc)
return 0;
169 for (
int itc = 0; itc < ntc; itc++) {
170 if (TCHit[itc] -> getChecksum() != 0)
return 0;
171 if (!(TCHit[itc] -> getHitWin() == 3 || TCHit[itc] -> getHitWin() == 4))
continue;
172 TCId.push_back(TCHit[itc]->getTCId());
174 TCTiming.push_back((
double) TCHit[itc]->getTCTime());
183 int flag_event_used = 0;
184 int ntc =
TCId.size();
186 for (
int itc1 = 0; itc1 < ntc; itc1++) {
189 int m_TCID1 =
TCId[itc1] - 1;
192 for (
int itc2 = itc1 + 1; itc2 < ntc; itc2++) {
193 int m_TCID2 =
TCId[itc2] - 1;
199 double sigma2 = 5.0 * 5.0;
204 _Matrix[m_TCID1][m_TCID2] += (-1.0 / sigma2);
205 _Matrix[m_TCID2][m_TCID1] += (-1.0 / sigma2);
207 _Matrix[m_TCID1][m_TCID1] += (1.0 / sigma2);
208 _Matrix[m_TCID2][m_TCID2] += (1.0 / sigma2);
211 Chisq1[m_TCID1][m_TCID2] += (1.0 / sigma2);
212 Chisq1[m_TCID2][m_TCID1] += (1.0 / sigma2);
216 double Vector_component = 0;
227 Vector_component /= sigma2;
228 _Vector[m_TCID1] += Vector_component;
229 _Vector[m_TCID2] += -Vector_component;
231 Chisq2[m_TCID1][m_TCID2] += -2.0 * Vector_component;
232 Chisq2[m_TCID2][m_TCID1] += 2.0 * Vector_component;
234 Chisq3[m_TCID1][m_TCID2] += Vector_component * Vector_component * sigma2;
235 Chisq3[m_TCID2][m_TCID1] += Vector_component * Vector_component * sigma2;
244 return flag_event_used;
253 const int nTC_tot = 576;
254 TMatrixDSym mat_A(575);
255 mat_A.ResizeTo(575, 575, 0.0);
260 for (
int i = 0; i < 576; i++) {
261 if (i ==
TC_ref - 1)
continue;
263 if (i >
TC_ref - 1) indexi = i - 1;
265 for (
int j = 0; j < 576; j++) {
266 if (j ==
TC_ref - 1)
continue;
268 if (j >
TC_ref - 1) indexj = j - 1;
269 mat_A[indexi][indexj] =
_Matrix[i][j];
285 for (
int i = 0; i < 576; i++) {
294 TVectorD x = lu.Solve(vec_b, b_solve);
298 for (
int i = 0; i < nTC_tot; i++) {
308 for (
int i = 0; i < nTC_tot; i++) {
318 for (
int iTCID = 0; iTCID < 576; iTCID++) {
335 for (
int i = 0; i < 576; i++) {
341 _Matrix.ResizeTo(576, 576, 0.0);
343 for (
int i = 0; i < 576; i++) {
345 for (
int j = 0; j < 576; j++) {
354 for (
int i = 0; i < 576; i++) {
355 Chisq1[i].assign(576, 0.0);
356 Chisq2[i].assign(576, 0.0);
357 Chisq3[i].assign(576, 0.0);
362 for (
int i = 0; i < 576; i++) {
367 for (
int i = 0; i < 80; i++) {
372 for (
int i = 80; i < 512; i++) {
377 for (
int i = 512; i < 576; i++) {
389 TFile* tf =
new TFile(fname,
"RECREATE");
390 TTree* tr =
new TTree(
"tree",
"TC time calibration result");
391 vector<double> time_offset;
392 vector<double> time_offset_err;
394 vector<double> chisq;
396 time_offset.resize(576);
397 time_offset_err.resize(576);
401 double timeoffsetave = 0.0;
402 tr -> Branch(
"TCID", &TCID);
403 tr -> Branch(
"TimeOffset", &time_offset);
404 tr -> Branch(
"TimeOffAve", &timeoffsetave);
405 tr -> Branch(
"TimeOffsetErr", &time_offset_err);
406 tr -> Branch(
"Chisq", &chisq);
407 tr -> Branch(
"Nevent", &Nevent);
409 tr -> Branch(
"Matrix", &
_Matrix);
410 tr -> Branch(
"Vector", &
_Vector);
411 tr -> Branch(
"ChisqComponent1", &
Chisq1);
412 tr -> Branch(
"ChisqComponent2", &
Chisq2);
413 tr -> Branch(
"ChisqComponent3", &
Chisq3);
416 for (
int i = 0; i < 576; i++) {
424 timeoffsetave /= 576.0;
445 for (
int i = 0; i < 576; i++) {
447 std::vector<double> offsetdiff;
448 offsetdiff.assign(576, 0.0);
449 for (
int j = 0; j < 576; j++) {
450 if (i == j || (
b_Inc_TC[j] ==
false && j !=
TC_ref - 1))
continue;
456 for (
int i = 0; i < 576; i++) {
466 TFile* tf =
new TFile(str_fname_tmp,
"READ");
467 auto tr = (TTree*) tf -> Get(
"tree");
468 vector<double>* TimeOffset_tmp = 0;
469 tr -> SetBranchAddress(
"TimeOffset", &TimeOffset_tmp);
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
int nevt_selected
The number of selected events.
std::vector< double > tcal_result_err
Time offset error.
std::vector< double > TCEnergy
TC energy.
void InitParams()
Parameters initialization.
void Save_Result()
Save time offset and chisq as a root file.
std::vector< std::vector< double > > Chisq1
chisq component1
TVectorD _Vector
Vector component.
std::vector< double > tcal_result
Time offset calibration result.
int fIteration
Flag iteration 0 : first calbiration 1 : iteration.
int fSimulation
Flag simulation 0 : real data 1 : simulation data.
virtual void initialize() override
initialize function
std::string str_timeoffset_fname
Input time offset file name (iteration mode)
std::vector< ROOT::Math::XYZVector > TCPosition
TC position from TRGECLMap (cosmic calibration)
int nevt_read
The number of read events.
virtual void event() override
Event function.
virtual void endRun() override
End Run function.
std::vector< bool > b_Exclude_TC
Flag TC excluded.
void Calculate_Chisq()
Calculate chisq based on time offset obtained from "Solve_Matrix" function.
void GetTimeOffset()
Get previous time offsets (iteration mode)
double TCEnergyCalibrationConstant
ADC to GeV energy conversion factor.
double cut_chisq
TC chisq cut (iteration mode)
void Set_TCposition()
Set TC position from TRGECLMap.
virtual void terminate() override
Terminate function.
double cut_high_energy
TC energy cut upper limit.
double cut_low_energy
TC energy cut lower limit.
int cut_ntc
The number of TC cut.
std::vector< double > TCTiming
TC time.
TRGECLTimingCalModule()
Constructor.
std::string str_default_name
Default output root file name.
std::vector< int > Nevent_TC
The number of uesed TC hit (TC by TC)
virtual void beginRun() override
Begin Run function.
int Solve_Matrix()
Solve matrix.
int ReadData()
Fill data from.
int fInclude_FWD
Flag include forward endcap 0 : exclude FWD 1 : include FWD.
std::vector< double > TimeOffset
Time offset Input time offset (iteration mode)
int fInclude_BWD
Flag include backward endcap 0 : exclude BWD 1 : include BWD.
int fInclude_BR
Flag include barrel 0 : exclude BR 1 : include BR.
int f3Dbhabha_veto
Flag 3D bhabha veto 0 : not use 1 : use.
int FillMatrix()
Fill matrix and vector components.
virtual ~TRGECLTimingCalModule()
Destructor.
void TRGECLTimingCalClear()
Clear vector every event.
std::vector< bool > b_Inc_TC
Flag TC included.
int TC_ref
Reference TC whose time offset set to be 0.
std::vector< std::vector< double > > Chisq3
chisq component3
std::vector< double > chisq_result
Chisq values based on time offset obtained from "Solve_Matrix" function.
int FlagMatrixSolved
Flag matrix solved (0 : not solved 1 : solved)
std::vector< std::vector< double > > Chisq2
chisq component2
std::vector< int > TCId
Trigger Cell TCID.
std::string str_ofilename
Output root file name.
TMatrixDSym _Matrix
Matrix Marix component.
int fCalType
Calibration type 0 : beam 1 : cosmic.
ROOT::Math::XYZVector getTCPosition(int)
TC position (cm)
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.