SND@LHC Software
Loading...
Searching...
No Matches
MuFilterHit.cxx
Go to the documentation of this file.
1#include "MuFilterHit.h"
2#include "MuFilter.h"
3#include "ShipUnit.h"
4#include "TROOT.h"
5#include "FairRunSim.h"
6#include "TGeoNavigator.h"
7#include "TGeoManager.h"
8#include "TGeoBBox.h"
9#include <TRandom.h>
10#include <iomanip>
11
12Double_t speedOfLight = TMath::C() *100./1000000000.0 ; // from m/sec to cm/ns
13// ----- Default constructor -------------------------------------------
15 : SndlhcHit()
16{
17 flag = true;
18 for (Int_t i=0;i<16;i++){fMasked[i]=kFALSE;}
19}
20// ----- Standard constructor ------------------------------------------
22 : SndlhcHit(detID)
23{
24 flag = true;
25 for (Int_t i=0;i<16;i++){fMasked[i]=kFALSE;}
26}
27MuFilterHit::MuFilterHit(Int_t detID,Int_t nP,Int_t nS)
28 : SndlhcHit(detID,nP,nS)
29{
30 flag = true;
31 for (Int_t i=0;i<16;i++){
32 fMasked[i]=kFALSE;
33 signals[i] = -999;
34 times[i] = -999;
35 fDaqID[i] = -1;
36 }
37}
38
39
40// ----- constructor from MuFilterPoint ------------------------------------------
41MuFilterHit::MuFilterHit(Int_t detID, std::vector<MuFilterPoint*> V)
42 : SndlhcHit()
43{
44 MuFilter* MuFilterDet = dynamic_cast<MuFilter*> (gROOT->GetListOfGlobals()->FindObject("MuFilter"));
45 // get parameters from the MuFilter detector for simulating the digitized information
46 nSiPMs = MuFilterDet->GetnSiPMs(detID);
47 nSides = MuFilterDet->GetnSides(detID);
48
49 Float_t timeResol = MuFilterDet->GetConfParF("MuFilter/timeResol");
50
51 Float_t attLength=0;
52 Float_t siPMcalibration=0;
53 Float_t siPMcalibrationS=0;
54 Float_t propspeed =0;
55 if (floor(detID/10000)==3) {
56 if (nSides==2){attLength = MuFilterDet->GetConfParF("MuFilter/DsAttenuationLength");}
57 else {attLength = MuFilterDet->GetConfParF("MuFilter/DsTAttenuationLength");}
58 siPMcalibration = MuFilterDet->GetConfParF("MuFilter/DsSiPMcalibration");
59 propspeed = MuFilterDet->GetConfParF("MuFilter/DsPropSpeed");
60 }
61 else {
62 if (floor(detID/10000)==1 && nSides==1){
63 // top readout with mirror on bottom
64 attLength = 2*MuFilterDet->GetConfParF("MuFilter/VandUpAttenuationLength");
65 }
66 else {attLength = MuFilterDet->GetConfParF("MuFilter/VandUpAttenuationLength");}
67 siPMcalibration = MuFilterDet->GetConfParF("MuFilter/VandUpSiPMcalibration");
68 siPMcalibrationS = MuFilterDet->GetConfParF("MuFilter/VandUpSiPMcalibrationS");
69 propspeed = MuFilterDet->GetConfParF("MuFilter/VandUpPropSpeed");
70 }
71
72 for (unsigned int j=0; j<16; ++j){
73 signals[j] = -1;
74 times[j] =-1;
75 }
76 LOG(DEBUG) << "detid "<<detID<< " size "<<nSiPMs<< " side "<<nSides;
77
78 fDetectorID = detID;
79 Float_t signalLeft = 0;
80 Float_t signalRight = 0;
81 Float_t earliestToAL = 1E20;
82 Float_t earliestToAR = 1E20;
83 for(auto p = std::begin(V); p!= std::end(V); ++p) {
84
85 Double_t signal = (*p)->GetEnergyLoss();
86
87 // Find distances from MCPoint centre to ends of bar
88 TVector3 vLeft,vRight;
89 TVector3 impact((*p)->GetX(),(*p)->GetY() ,(*p)->GetZ() );
90 MuFilterDet->GetPosition(fDetectorID,vLeft, vRight);
91 Double_t distance_Left = (vLeft-impact).Mag();
92 Double_t distance_Right = (vRight-impact).Mag();
93 // Simple model: divide signal between nSides
94 signalLeft+=signal/nSides*TMath::Exp(-distance_Left/attLength);
95 signalRight+=signal/nSides*TMath::Exp(-distance_Right/attLength);
96
97 // for the timing, find earliest particle and smear with time resolution
98 Double_t ptime = (*p)->GetTime();
99 Double_t t_Left = ptime + distance_Left/propspeed;
100 Double_t t_Right = ptime + distance_Right/propspeed;
101 if ( t_Left <earliestToAL){earliestToAL = t_Left ;}
102 if ( t_Right <earliestToAR){earliestToAR = t_Right ;}
103 }
104 // shortSiPM = {3,6,11,14,19,22,27,30,35,38,43,46,51,54,59,62,67,70,75,78}; - counting from 1!
105 // In the SndlhcHit class the 'signals' array starts from 0.
106 for (unsigned int j=0; j<nSiPMs; ++j){
107 if ( floor(detID/10000)==2 && (j==2 or j==5)){ // only US has small SiPMs
108 signals[j] = signalLeft/float(nSiPMs) * siPMcalibrationS; // most simplest model, divide signal individually. Small SiPMS special
109 times[j] = gRandom->Gaus(earliestToAL, timeResol);
110 }else{
111 signals[j] = signalLeft/float(nSiPMs) * siPMcalibration; // most simplest model, divide signal individually.
112 times[j] = gRandom->Gaus(earliestToAL, timeResol);
113 }
114 if (nSides>1){
115 signals[j+nSiPMs] = signalRight/float(nSiPMs) * siPMcalibration; // most simplest model, divide signal individually.
116 times[j+nSiPMs] = gRandom->Gaus(earliestToAR, timeResol);
117 }
118 }
119 flag = true;
120 for (Int_t i=0;i<16;i++){fMasked[i]=kFALSE;}
121 LOG(DEBUG) << "signal created";
122}
123
124// ----- Destructor ----------------------------------------------------
126// -------------------------------------------------------------------------
127
128// ----- Public method GetEnergy -------------------------------------------
130{
131 // to be calculated from digis and calibration constants, missing!
132 Float_t E = 0;
133 for (unsigned int j=0; j<nSiPMs; ++j){
134 E+=signals[j];
135 if (nSides>1){ E+=signals[j+nSiPMs];}
136 }
137 return E;
138}
139
141 if ( (GetSystem()==3&&fDetectorID%1000>59) ||
142 (GetSystem()==1&&GetPlane()==2) ) {
143 return kTRUE;
144 }
145 else{return kFALSE;}
146}
147
149 if (i%8==2 || i%8==5) {return kTRUE;}
150 else{return kFALSE;}
151}
152
153// ----- Public method Get List of signals -------------------------------------------
154std::map<Int_t,Float_t> MuFilterHit::GetAllSignals(Bool_t mask,Bool_t positive)
155{
156 std::map<Int_t,Float_t> allSignals;
157 for (unsigned int s=0; s<nSides; ++s){
158 for (unsigned int j=0; j<nSiPMs; ++j){
159 unsigned int channel = j+s*nSiPMs;
160 if (signals[channel]<-900){continue;}
161 if (signals[channel]> 0 || !positive){
162 if (!fMasked[channel] || !mask){
163 allSignals[channel] = signals[channel];
164 }
165 }
166 }
167 }
168 return allSignals;
169}
170
171// ----- Public method Get List of time measurements -------------------------------------------
172std::map<Int_t,Float_t> MuFilterHit::GetAllTimes(Bool_t mask)
173{
174 std::map<Int_t,Float_t> allTimes;
175 for (unsigned int s=0; s<nSides; ++s){
176 for (unsigned int j=0; j<nSiPMs; ++j){
177 unsigned int channel = j+s*nSiPMs;
178 if (signals[channel]> 0){
179 if (!fMasked[channel] || !mask){
180 allTimes[channel] = times[channel];
181 }
182 }
183 }
184 }
185 return allTimes;
186}
187
188// ----- Public method Get time difference mean Left - mean Right -----------------
189Float_t MuFilterHit::GetDeltaT(Bool_t mask)
190// based on mean TDC measured on Left and Right
191{
192 Float_t mean[] = {0,0};
193 Int_t count[] = {0,0};
194 Float_t dT = -999.;
195 for (unsigned int s=0; s<nSides; ++s){
196 for (unsigned int j=0; j<nSiPMs; ++j){
197 unsigned int channel = j+s*nSiPMs;
198 if (signals[channel]> 0){
199 if (!fMasked[channel] || !mask){
200 mean[s] += times[channel];
201 count[s] += 1;
202 }
203 }
204 }
205 }
206 if (count[0]>0 && count[1]>0) {
207 dT = mean[0]/count[0] - mean[1]/count[1];
208 }
209 return dT;
210}
211Float_t MuFilterHit::GetFastDeltaT(Bool_t mask)
212// based on fastest (earliest) TDC measured on Left and Right
213{
214 Float_t first[] = {1E20,1E20};
215 Float_t dT = -999.;
216 for (unsigned int s=0; s<nSides; ++s){
217 for (unsigned int j=0; j<nSiPMs; ++j){
218 unsigned int channel = j+s*nSiPMs;
219 if (signals[channel]> 0){
220 if (!fMasked[channel] || !mask){
221 if (times[channel]<first[s]) {first[s] = times[channel];}
222 }
223 }
224 }
225 }
226 if (first[0]<1E10 && first[1]<1E10) {
227 dT = first[0] - first[1];
228 }
229 return dT;
230}
231
232
233// ----- Public method Get mean time -----------------
234Float_t MuFilterHit::GetImpactT(Bool_t mask)
235{
236 Float_t mean[] = {0,0};
237 Int_t count[] = {0,0};
238 Float_t dT = -999.;
239 Float_t dL;
240 MuFilter* MuFilterDet = dynamic_cast<MuFilter*> (gROOT->GetListOfGlobals()->FindObject("MuFilter"));
241 if (GetSystem()==3) {
242 dL = MuFilterDet->GetConfParF("MuFilter/DownstreamBarX") / MuFilterDet->GetConfParF("MuFilter/DsPropSpeed");}
243 else if (GetSystem()==2) {
244 dL = MuFilterDet->GetConfParF("MuFilter/UpstreamBarX") / MuFilterDet->GetConfParF("MuFilter/VandUpPropSpeed");}
245 else {
246 dL = MuFilterDet->GetConfParF("MuFilter/VetoBarX") / MuFilterDet->GetConfParF("MuFilter/VandUpPropSpeed");}
247
248 for (unsigned int s=0; s<nSides; ++s){
249 for (unsigned int j=0; j<nSiPMs; ++j){
250 unsigned int channel = j+s*nSiPMs;
251 if (signals[channel]> 0){
252 if (!fMasked[channel] || !mask){
253 mean[s] += times[channel];
254 count[s] += 1;
255 }
256 }
257 }
258 }
259 if (count[0]>0 && count[1]>0) {
260 dT = (mean[0]/count[0] + mean[1]/count[1])/2.*ShipUnit::snd_TDC2ns - dL/2.; // TDC to ns = 6.25
261 }
262 return dT;
263}
264
265// ----- Public method Get position of impact point along the bar -----------------
266Float_t MuFilterHit::GetImpactXpos(Bool_t mask, Bool_t isMC)
267{
268 if ( nSides!=2 ){
269 return -999.;
270 }
271 Float_t dT = GetDeltaT(mask);
272 if (dT==-999.){
273 return -999.;
274 }
275
276 MuFilter* MuFilterDet = dynamic_cast<MuFilter*> (gROOT->GetListOfGlobals()->FindObject("MuFilter"));
277 Float_t bar_length = MuFilterDet->GetConfParF("MuFilter/UpstreamBarX");
278 Float_t signal_speed = MuFilterDet->GetConfParF("MuFilter/VandUpPropSpeed");
279 if (GetSystem()==3) {
280 signal_speed = MuFilterDet->GetConfParF("MuFilter/DsPropSpeed");
281 bar_length = MuFilterDet->GetConfParF("MuFilter/DownstreamBarX");
282 }
283 else if (GetSystem()==2) {
284 bar_length = MuFilterDet->GetConfParF("MuFilter/UpstreamBarX");
285 }
286 else {
287 bar_length = MuFilterDet->GetConfParF("MuFilter/VetoBarX");
288 }
289 double timeConversion = 1.;
290 if (!isMC) timeConversion = ShipUnit::snd_TDC2ns;
291 return 0.5*(bar_length + dT*timeConversion*signal_speed);
292}
293
294std::map<TString,Float_t> MuFilterHit::SumOfSignals(Bool_t mask)
295{
296/* use cases, for Veto and DS small/large ignored
297 sum of signals left large SiPM: LL
298 sum of signals right large SiPM: RL
299 sum of signals left small SiPM: LS
300 sum of signals right small SiPM: RS
301 sum of signals left and right:
302*/
303 Float_t theSumL = 0;
304 Float_t theSumR = 0;
305 Float_t theSumLS = 0;
306 Float_t theSumRS = 0;
307 for (unsigned int s=0; s<nSides; ++s){
308 for (unsigned int j=0; j<nSiPMs; ++j){
309 unsigned int channel = j+s*nSiPMs;
310 if (signals[channel]> 0){
311 if (!fMasked[channel] || !mask){
312 if (s==0 and !isShort(j)){theSumL+= signals[channel];}
313 if (s==0 and isShort(j)){theSumLS+= signals[channel];}
314 if (s==1 and !isShort(j)){theSumR+= signals[channel];}
315 if (s==1 and isShort(j)){theSumRS+= signals[channel];}
316 }
317 }
318 }
319 }
320 std::map<TString,Float_t> sumSignals;
321 sumSignals["SumL"]=theSumL;
322 sumSignals["SumR"]=theSumR;
323 sumSignals["SumLS"]=theSumLS;
324 sumSignals["SumRS"]=theSumRS;
325 sumSignals["Sum"]=theSumL+theSumR;
326 sumSignals["SumS"]=theSumLS+theSumRS;
327 return sumSignals;
328}
329
330// ----- Public method Print -------------------------------------------
332{
333 std::cout << "-I- MuFilterHit: MuFilter hit " << " in detector " << fDetectorID;
334
335 if ( floor(fDetectorID/10000)==3&&fDetectorID%1000>59) {
336 std::cout << " with vertical bars"<<std::endl;
337 std::cout << "top digis:";
338 for (unsigned int j=0; j<nSiPMs; ++j){
339 std::cout << signals[j] <<" ";
340 }
341 }else{
342 std::cout << " with horizontal bars"<<std::endl;
343 for (unsigned int s=0; s<nSides; ++s){
344 if (s==0) {std::cout << "left digis:";}
345 else {std::cout << "right digis:";}
346 for (unsigned int j=0; j<nSiPMs; ++j){
347 std::cout << signals[j] <<" ";
348 }
349 }
350 }
351std::cout << std::endl;
352}
353// -------------------------------------------------------------------------
354
356
Double_t speedOfLight
Float_t SumOfSignals(char *opt, Bool_t mask=kTRUE)
Float_t GetImpactXpos(Bool_t mask=kTRUE, Bool_t isMC=kFALSE)
Float_t GetEnergy()
std::map< Int_t, Float_t > GetAllTimes(Bool_t mask=kTRUE)
Float_t GetDeltaT(Bool_t mask=kTRUE)
int GetPlane()
Definition MuFilterHit.h:43
virtual ~MuFilterHit()
Float_t fMasked[16]
Definition MuFilterHit.h:49
bool isShort(Int_t)
int GetSystem()
Definition MuFilterHit.h:42
bool isVertical()
Float_t flag
flag
Definition MuFilterHit.h:48
std::map< Int_t, Float_t > GetAllSignals(Bool_t mask=kTRUE, Bool_t positive=kTRUE)
void Print() const
Float_t GetFastDeltaT(Bool_t mask=kTRUE)
Float_t GetImpactT(Bool_t mask=kTRUE)
Int_t GetnSides(Int_t detID)
Definition MuFilter.cxx:715
void GetPosition(Int_t id, TVector3 &vLeft, TVector3 &vRight)
Definition MuFilter.cxx:639
Int_t GetnSiPMs(Int_t detID)
Definition MuFilter.cxx:708
Float_t GetConfParF(TString name)
Definition MuFilter.h:46
Int_t nSiPMs
Definition SndlhcHit.h:73
Float_t times[16]
SiPM signal.
Definition SndlhcHit.h:76
Int_t fDetectorID
Detector unique identifier.
Definition SndlhcHit.h:72
Int_t fDaqID[16]
SiPM time.
Definition SndlhcHit.h:77
Int_t nSides
number of SiPMs per side
Definition SndlhcHit.h:74
Float_t signals[16]
number of sides
Definition SndlhcHit.h:75
ClassImp(ecalContFact) ecalContFact