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