1414
1515#include " TMath.h"
1616#include " TRandom.h"
17+ #include < TH1F.h>
1718#include < algorithm>
1819#include < cassert>
1920#include < iostream>
@@ -23,15 +24,25 @@ using namespace o2::fit;
2324
2425ClassImp (Digitizer);
2526
26- void Digitizer::process (const std::vector<o2::t0::HitType>* hits, o2::t0::Digit* digit)
27-
27+ double get_time (const std::vector<double >& times, double signal_width)
2828{
29- // parameters constants TO DO: move to class
29+ TH1F hist (" time_histogram" , " " , 1000 , -0.5 * signal_width, 0.5 * signal_width);
30+ auto signalForm = [](double x) {
31+ return -(exp (-0.83344945 * x) - exp (-0.45458 * x));
32+ };
33+ for (auto time : times)
34+ for (int bin = hist.FindBin (time); bin < hist.GetSize (); ++bin)
35+ if (hist.GetBinCenter (bin) > time)
36+ hist.AddBinContent (bin, signalForm (hist.GetBinCenter (bin) - time));
37+ double maximum{ hist.GetMaximum () };
38+ int binfound{ hist.FindFirstBinAbove (maximum * 0.4 ) };
39+ // std::cout<<"@@@@@!!! max "<<maximum<<" binfound "<<binfound<<" return "<<hist.GetBinCenter(binfound)<<std::endl;
40+ return hist.GetBinCenter (binfound);
41+ }
3042
31- constexpr Float_t C_side_cable_cmps = 2.877 ; // ns
32- constexpr Float_t A_side_cable_cmps = 11.08 ; // ns
33- constexpr Float_t signal_width = 5 .; // time gate for signal, ns
43+ void Digitizer::process (const std::vector<o2::t0::HitType>* hits, o2::t0::Digit* digit, std::vector<std::vector<double >>& channel_times)
3444
45+ {
3546 auto sorted_hits{ *hits };
3647 std::sort (sorted_hits.begin (), sorted_hits.end (), [](o2::t0::HitType const & a, o2::t0::HitType const & b) {
3748 return a.GetTrackID () < b.GetTrackID ();
@@ -46,23 +57,24 @@ void Digitizer::process(const std::vector<o2::t0::HitType>* hits, o2::t0::Digit*
4657 for (int i = 0 ; i < parameters.mMCPs ; ++i)
4758 channel_data.emplace_back (o2::t0::ChannelData{ i, 0 , 0 , 0 });
4859 }
60+ if (channel_times.size () == 0 )
61+ channel_times.resize (parameters.mMCPs );
4962 Int_t parent = -10 ;
5063 assert (digit->getChDgData ().size () == parameters.mMCPs );
5164 for (auto & hit : sorted_hits) {
65+ if (hit.GetEnergyLoss () > 0 )
66+ continue ;
5267 Int_t hit_ch = hit.GetDetectorID ();
53- Double_t hit_time = hit.GetTime ();
54- Bool_t is_A_side = (hit_ch <= 4 * parameters.NCellsA );
68+ Bool_t is_A_side = (hit_ch < 4 * parameters.NCellsA );
5569 Float_t time_compensate = is_A_side ? A_side_cable_cmps : C_side_cable_cmps;
70+ Double_t hit_time = hit.GetTime () - time_compensate;
5671
57- Bool_t is_hit_in_signal_gate = (hit_time > time_compensate - signal_width * .5 ) &&
58- (hit_time < time_compensate + signal_width * .5 );
59-
60- Double_t hit_time_corr = hit_time - time_compensate /* + mBC_clk_center + mEventTime*/ ;
72+ Bool_t is_hit_in_signal_gate = (abs (hit_time) < parameters.mSignalWidth * .5 );
6173
6274 if (is_hit_in_signal_gate) {
6375 channel_data[hit_ch].numberOfParticles ++;
64- channel_data[hit_ch].QTCAmpl += hit.GetEnergyLoss ();
65- channel_data [hit_ch].CFDTime += hit_time_corr ;
76+ channel_data[hit_ch].QTCAmpl += hit.GetEnergyLoss (); // for FV0
77+ channel_times [hit_ch].push_back (hit_time) ;
6678 }
6779
6880 // charge particles in MCLabel
@@ -98,7 +110,7 @@ void Digitizer::computeAverage(o2::t0::Digit& digit)
98110}
99111
100112// ------------------------------------------------------------------------
101- void Digitizer::smearCFDtime (o2::t0::Digit* digit)
113+ void Digitizer::smearCFDtime (o2::t0::Digit* digit, std::vector<std::vector< double >> const & channel_times )
102114{
103115 // smeared CFD time for 50ps
104116 std::vector<o2::t0::ChannelData> mChDgDataArr ;
@@ -108,7 +120,8 @@ void Digitizer::smearCFDtime(o2::t0::Digit* digit)
108120 Float_t amp = d.QTCAmpl ;
109121 int numpart = d.numberOfParticles ;
110122 if (amp > parameters.mCFD_trsh_mip ) {
111- Double_t smeared_time = gRandom ->Gaus (cfd, 0.050 ) + parameters.mBC_clk_center + mEventTime ;
123+ // Double_t smeared_time = gRandom->Gaus(cfd, 0.050) + parameters.mBC_clk_center + mEventTime;
124+ double smeared_time = get_time (channel_times[mcp], parameters.mSignalWidth ) + parameters.mBC_clk_center + mEventTime ;
112125 mChDgDataArr .emplace_back (o2::t0::ChannelData{ mcp, smeared_time, amp, numpart });
113126 }
114127 }
0 commit comments