er  dev
ERBeamDetDigitizer.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERBeamDetDigitizer.h"
10 
11 #include "TVector3.h"
12 #include "TGeoMatrix.h"
13 #include "TMath.h"
14 #include "TRandom3.h"
15 
16 #include "FairRootManager.h"
17 #include "FairRuntimeDb.h"
18 #include "FairLogger.h"
19 
20 #include "ERBeamDetSetup.h"
21 #include "ERDetectorList.h"
22 #include "ERSupport.h"
23 
24 using namespace std;
25 
26 //--------------------------------------------------------------------------------------------------
28  : ERDigitizer("ER beamdet digitization")
29 {}
30 //--------------------------------------------------------------------------------------------------
32  : ERDigitizer("ER beamdet digitization ", verbose)
33 {}
34 //--------------------------------------------------------------------------------------------------
36  if (ERTask::Init() != kSUCCESS)
37  return kFATAL;
38  // Get input array
39  FairRootManager* ioman = FairRootManager::Instance();
40  if (!ioman) Fatal("Init", "No FairRootManager");
41  fBeamDetToFPoints = (TClonesArray*) ioman->GetObject("BeamDetToFPoint");
42  fBeamDetMWPCPoints = (TClonesArray*) ioman->GetObject("BeamDetMWPCPoint");
43  if (!fBeamDetToFPoints)
44  Fatal("Init", "Can`t find collection BeamDetToFPoint!");
45  if (!fBeamDetMWPCPoints)
46  Fatal("Init", "Can`t find collection BeamDetMWPCPoint!");
47  // Register output arrays
48  fBeamDetToFDigi1 = new TClonesArray("ERDigi", consts::approx_beamdet_tof_digi_number);
49  fBeamDetToFDigi2 = new TClonesArray("ERDigi", consts::approx_beamdet_tof_digi_number);
50  fBeamDetMWPCDigiX1 = new TClonesArray("ERDigi", consts::approx_beamdet_mwpc_digi_number);
51  fBeamDetMWPCDigiX2 = new TClonesArray("ERDigi", consts::approx_beamdet_mwpc_digi_number);
52  fBeamDetMWPCDigiY1 = new TClonesArray("ERDigi", consts::approx_beamdet_mwpc_digi_number);
53  fBeamDetMWPCDigiY2 = new TClonesArray("ERDigi", consts::approx_beamdet_mwpc_digi_number);
54  ioman->Register("BeamDetToFDigi1", "BeamDetToF Digi", fBeamDetToFDigi1, kTRUE /*write to output*/);
55  ioman->Register("BeamDetToFDigi2", "BeamDetToF Digi", fBeamDetToFDigi2, kTRUE);
56  ioman->Register("BeamDetMWPCDigiX1", "BeamDetMWPC x1 Digi", fBeamDetMWPCDigiX1, kTRUE);
57  ioman->Register("BeamDetMWPCDigiX2", "BeamDetMWPC x2 Digi", fBeamDetMWPCDigiX2, kTRUE);
58  ioman->Register("BeamDetMWPCDigiY1", "BeamDetMWPC y1 Digi", fBeamDetMWPCDigiY1, kTRUE);
59  ioman->Register("BeamDetMWPCDigiY2", "BeamDetMWPC y2 Digi", fBeamDetMWPCDigiY2, kTRUE);
60  return kSUCCESS;
61 }
62 //--------------------------------------------------------------------------------------------------
63 void ERBeamDetDigitizer::Exec(Option_t* opt) {
64  Reset();
65  map<Int_t, vector<Int_t>> pointsToF;
66  for (Int_t iPoint = 0; iPoint < fBeamDetToFPoints->GetEntriesFast(); iPoint++){
68  pointsToF[point->GetToFNb()].push_back(iPoint);
69  }
70  map<Int_t, vector<Int_t> >::iterator itPlate;
71  vector<Int_t>::iterator itToFPoint;
72  for(itPlate = pointsToF.begin(); itPlate != pointsToF.end(); ++itPlate){
73  Float_t edep = 0.; //sum edep in plate
74  Float_t time = numeric_limits<float>::max(); // min time in plate
75  for (itToFPoint = itPlate->second.begin(); itToFPoint != itPlate->second.end(); ++itToFPoint){
76  ERBeamDetTOFPoint* point = (ERBeamDetTOFPoint*)(fBeamDetToFPoints->At(*itToFPoint));
77  edep += point->GetEnergyLoss();
78 
79  if (point->GetTime() < time){
80  time = point->GetTime();
81  }
82  }
84  fElossSigmaToF = edep * fElossSigmaOverElossToF / TMath::Sqrt(edep);
85  }
86  edep = gRandom->Gaus(edep, fElossSigmaToF);
87  if (edep < fToFElossThreshold)
88  continue;
89  time = gRandom->Gaus(time, fTimeSigmaToF);
90  ERDigi *digi = AddToFDigi(edep, time, itPlate->first);
91  itToFPoint = itPlate->second.begin();
92  //for (; itToFPoint != itPlate->second.end(); ++itToFPoint){
93  // digi->AddLink(FairLink("BeamDetToFPoint", *itToFPoint));
94  //}
95  }
96  //Sort the MWPCpoints by MWPC, planes and wires
97  map<Int_t, map<Int_t, map<Int_t, vector<Int_t>>>> points;
98  for (Int_t iPoint = 0; iPoint < fBeamDetMWPCPoints->GetEntriesFast(); iPoint++){
99  auto* point = dynamic_cast<ERBeamDetMWPCPoint*>(fBeamDetMWPCPoints->At(iPoint));
100  points[point->GetMWPCNb()][point->GetPlaneNb()][point->GetWireNb()].push_back(iPoint);
101  }
102  for (auto& mwpc_points : points) {
103  const auto mwpc_nb = mwpc_points.first;
104  for (auto& plane_points : mwpc_points.second) {
105  const auto plane_nb = plane_points.first;
106  for(auto& wire_points : plane_points.second) {
107  const auto wire_nb = wire_points.first;
108  float edep = 0.; //sum edep in wire
109  float time = numeric_limits<float>::max(); // min time in wire
110  for (auto& point_nb : wire_points.second) {
111  auto* point = dynamic_cast<ERBeamDetMWPCPoint*>(fBeamDetMWPCPoints->At(point_nb));
112  edep += point->GetEnergyLoss();
113  if (point->GetTime() < time){
114  time = point->GetTime();
115  }
116  }
117  edep = gRandom->Gaus(edep, fElossSigmaMWPC);
118  if (edep < fMWPCElossThreshold)
119  continue;
120  time = gRandom->Gaus(time, fTimeSigmaMWPC);
121  ERDigi *digi = AddMWPCDigi(edep, time, mwpc_nb, plane_nb, static_cast<ERChannel>(wire_nb));
122  //for (auto tMWPCPoint = itWire->second.begin(); itMWPCPoint != itWire->second.end(); ++itMWPCPoint){
123  // digi->AddLink(FairLink("BeamDetMWPCPoint", *itMWPCPoint));
124  //}
125  }
126  }
127  }
128  /*@TODO: This functionality can be transferred to ERDigitizer if the information
129  about the conformity of the trigger station and the digi collection moves there.*/
130  ERBeamDetSetup* setup = ERBeamDetSetup::Instance();
131  ApplyTrigger(setup->GetToFType(0),fBeamDetToFDigi1);
132  ApplyTrigger(setup->GetToFType(1),fBeamDetToFDigi2);
133 }
134 //--------------------------------------------------------------------------------------------------
136  for (auto* collection : {fBeamDetMWPCDigiX1, fBeamDetMWPCDigiX2,
139  if (collection)
140  collection->Delete();
141  }
142 }
143 //--------------------------------------------------------------------------------------------------
144 ERDigi* ERBeamDetDigitizer::AddMWPCDigi(float edep, float time, Int_t mwpcNb,
145  Int_t planeNb, ERChannel wireNb) {
146  ERDigi *digi;
147  if(mwpcNb == 1) {
148  if(planeNb == 1) {
149  digi = new((*fBeamDetMWPCDigiX1)[fBeamDetMWPCDigiX1->GetEntriesFast()])
150  ERDigi(edep, time, wireNb);
151  } else {
152  digi = new((*fBeamDetMWPCDigiY1)[fBeamDetMWPCDigiY1->GetEntriesFast()])
153  ERDigi(edep, time, wireNb);
154  }
155  }
156  if(mwpcNb == 2) {
157  if(planeNb == 1) {
158  digi = new((*fBeamDetMWPCDigiX2)[fBeamDetMWPCDigiX2->GetEntriesFast()])
159  ERDigi(edep, time, wireNb);
160  } else {
161  digi = new((*fBeamDetMWPCDigiY2)[fBeamDetMWPCDigiY2->GetEntriesFast()])
162  ERDigi(edep, time, wireNb);
163  }
164  }
165  return digi;
166 }
167 //--------------------------------------------------------------------------------------------------
168 ERDigi* ERBeamDetDigitizer::AddToFDigi(float edep, float time, int tofNb) {
169  ERDigi *digi;
170  if(tofNb == 1) {
171  digi = new((*fBeamDetToFDigi1)[fBeamDetToFDigi1->GetEntriesFast()])
172  ERDigi(edep, time, 0);
173  }
174  if(tofNb == 2) {
175  digi = new((*fBeamDetToFDigi2)[fBeamDetToFDigi2->GetEntriesFast()])
176  ERDigi(edep, time, 0);
177  }
178  return digi;
179 }
180 //--------------------------------------------------------------------------------------------------
181 ClassImp(ERBeamDetDigitizer)
Definition: ERDigi.h:15
Float_t fToFElossThreshold
energy losses thershold in ToF
Class for convertion simulation data to format like real detector data.
Float_t fElossSigmaOverElossToF
parameter of spreading energy losses
ERDigi * AddToFDigi(float edep, float time, int tofNb)
Adds a digi to the output Collections.
TClonesArray * fBeamDetToFPoints
input collection of ToF points
virtual void Exec(Option_t *opt)
Defines the transformation actions for all input data (Point) to output data (Digi) for each event...
virtual InitStatus Init()
Definition: ERTask.cxx:31
virtual InitStatus Init()
Defines all input and output object colletions participates in digitization.
Float_t fMWPCElossThreshold
energy losses thershold in MWPC
Float_t fElossSigmaToF
standart deviation of energy losses in ToF
ERDigi * AddMWPCDigi(float edep, float time, int mwpcNb, int planeNb, ERChannel wireNb)
Adds a digi to the output Collections.
Bool_t fSigmaEOverEToFIsSet
true if SetToFElossSigmaOverEloss is set
virtual void Reset()
Resets all output data.
Float_t fElossSigmaMWPC
standart deviation of energy losses in MWPC
TClonesArray * fBeamDetMWPCPoints
input collection of MWPC points
TClonesArray * fBeamDetMWPCDigiY1
output collection of Digi in second gas strip array in first MWPC station
TClonesArray * fBeamDetToFDigi1
output collection of Digi in first plastic
TClonesArray * fBeamDetMWPCDigiY2
output collection of Digi in second gas strip array in second MWPC station
Float_t fTimeSigmaToF
standart deviation of time in ToF
Float_t fTimeSigmaMWPC
standart deviation of time in MWPC
ERBeamDetDigitizer()
Default constructor.
TClonesArray * fBeamDetMWPCDigiX1
output collection of Digi in first gas strip array in first MWPC station
TClonesArray * fBeamDetMWPCDigiX2
output collection of Digi in first gas strip array in second MWPC station
TClonesArray * fBeamDetToFDigi2