17 #include "FairRunAna.h"
18 #include "FairRootManager.h"
19 #include "FairEventHeader.h"
21 #include "TClonesArray.h"
31 return 1/
sqrt(2*
TMath::Pi()*rms*rms)*
exp(-0.5*((x-mean_value)/rms)*((x-mean_value)/rms));
40 for(
size_t i = 0;
i < values.size();
i++)
45 return average/double(values.size());
55 for(
size_t i = 0;
i < values.size();
i++)
57 average += (values[
i]-mean_value)*(values[
i]-mean_value);
60 average =
sqrt(1/(
double(values.size())-1)*average);
87 LOG(INFO) <<
"PndDiscTaskPID::ReInit()";
95 LOG(INFO) <<
"PndDiscTaskPID::Init()";
98 FairRootManager* io_manager = FairRootManager::Instance();
101 LOG(FATAL) <<
"FairRootManager instance is NULL !!!";
106 tclarr_digits = (TClonesArray*) io_manager->GetObject(
"DiscDigitizedHit");
109 LOG(ERROR) <<
"Branch " <<
branch_name_digits.Data() <<
" is not accessible through FairRootManager.";
117 LOG(ERROR) <<
"No DiscPatternPrediction collection registered with FairRootManager";
125 LOG(ERROR) <<
"No DiscRealTracks collection registered with FairRootManager";
131 io_manager->Register(
"DiscPID",
137 static bool recon_initialized =
false;
138 if(recon_initialized)
return kSUCCESS;
154 std::cout <<
"Number of particles: " << particles << std::endl;
157 std::vector<std::vector<std::vector<int> > > pixel_prediction;
158 std::vector<std::vector<std::vector<double> > > time_prediction;
159 std::vector<std::vector<std::vector<double> > > dtime;
162 std::vector<std::vector<int> > pixel_hit;
163 std::vector<std::vector<double> > tdc_time;
166 std::vector<double>
x0,
y0,px,py,
pz,
p;
168 std::vector<double>
t;
170 std::vector<std::vector<double > > mean_time;
171 std::vector<std::vector<double > > deviation_time;
174 for(
int nparticle = 0; nparticle < particles; nparticle++)
176 pixel_prediction.push_back(std::vector<std::vector<int> >());
177 time_prediction.push_back(std::vector<std::vector<double> >());
178 dtime.push_back(std::vector<std::vector<double> >());
179 mean_time.push_back(std::vector<double>());
180 deviation_time.push_back(std::vector<double>());
181 pixel_hit.push_back(std::vector<int>());
182 tdc_time.push_back(std::vector<double>());
184 for(
int nhypo = 0; nhypo < 3; nhypo++)
186 pixel_prediction[nparticle].push_back(std::vector<int>());
187 time_prediction[nparticle].push_back(std::vector<double>());
188 dtime[nparticle].push_back(std::vector<double>());
192 for(
int i = 0;
i < particles;
i++)
196 double time = particle_mc_point->GetTime();
201 for(
int i = 0;
i < entries;
i++)
208 double time = recon_result->
time;
210 pixel_prediction[
particle][hypothesis].push_back(pixel);
211 time_prediction[
particle][hypothesis].push_back(time);
218 for(
int i = 0;
i < particles;
i++)
220 for(
int j = 0; j < digits; j++)
225 int sensor_id = 27*detector_id + sensor_mc_point->
GetReadoutID();
229 for(
int k = 0; k < 3; k++)
231 double propagation = tdc - t[
i];
232 double dt = propagation - time_prediction[
i][k][sensor_id];
233 if(dt < 3 && dt > -3)
235 dtime[
i][k].push_back(dt);
239 dtime[
i][k].push_back(-1);
245 for(
int k = 0; k < 3; k++)
247 mean_time[
i].push_back(
mean(dtime[
i][k]));
248 deviation_time[
i].push_back(
deviation(mean_time[
i][k],dtime[
i][k]));
249 std::cout <<
"Mean time difference: " << mean_time[
i][k] <<
", deviation: " << deviation_time[
i][k] << std::endl;
251 std::cout << std::endl;
256 for(
int i = 0;
i < particles;
i++)
258 double prob[3] = {0};
260 for(
int j = 0; j < digits; j++)
265 int sensor_id = 27*detector_id + sensor_mc_point->
GetReadoutID();
269 for(
int k = 0; k < 3; k++)
274 if(pixel_prediction[
i][0][sensor_id] != -1 && dtime[
i][0][j] != -1 && pixel_prediction[
i][1][sensor_id] != -1 && dtime[
i][1][j] != -1 && pixel_prediction[
i][2][sensor_id] != -1 && dtime[
i][2][j] != -1)
276 if((pixel - pixel_prediction[
i][0][sensor_id] < 5 && pixel - pixel_prediction[
i][0][sensor_id] > -5) || (pixel - pixel_prediction[
i][1][sensor_id] < 5 && pixel - pixel_prediction[
i][1][sensor_id] > -5) || (pixel - pixel_prediction[
i][2][sensor_id] < 5 && pixel - pixel_prediction[
i][2][sensor_id] > -5))
280 prob[k] +=
log(
gauss(pixel,pixel_prediction[
i][k][sensor_id],4));
286 std::cout << std::endl;
287 std::cout <<
"Log Likelihood: " << std::endl;
288 std::cout <<
"Pion: " << (prob[0]) << std::endl;
289 std::cout <<
"Kaon: " << (prob[1]) << std::endl;
290 std::cout <<
"Proton: " << (prob[2]) << std::endl << std::endl;
298 if(prob[0] < prob[1] && prob[0] < prob[2])
300 pid_result->
pion = 1;
301 pid_result->
kaon = 0;
305 if(prob[1] < prob[0] && prob[1] < prob[2])
307 pid_result->
pion = 0;
308 pid_result->
kaon = 1;
312 if(prob[2] < prob[0] && prob[2] < prob[1])
314 pid_result->
pion = 0;
315 pid_result->
kaon = 0;
322 std::cout <<
"PndDiscTaskPID::Exec" << std::endl;
TClonesArray * tclarr_recon_results
friend F32vec4 exp(const F32vec4 &a)
const Int_t & GetReadoutID() const
friend F32vec4 sqrt(const F32vec4 &a)
TClonesArray * tclarr_pid_results
results of reconstruction (pattern matching)
virtual ~PndDiscTaskPID()
TClonesArray * tclarr_digits
friend F32vec4 log(const F32vec4 &a)
TClonesArray * tclarr_particles_in
const Double_t & GetTdcTime() const
double deviation(double mean, std::vector< double > values)
virtual void Exec(Option_t *opt)
virtual InitStatus ReInit()
TString folder_name_digits
Folder name for digits.
virtual void FinishEvent()
virtual void FinishTask()
double gauss(int x, double mean, double rms)
const Int_t & GetDetectorID() const
TString branch_name_digits
Branch name where digitized hits are stored.
const Int_t & GetPixelNumber() const
virtual InitStatus Init()
double mean(std::vector< double > values)