BmnRoot
Loading...
Searching...
No Matches
BmnDchHitProducer.cxx
Go to the documentation of this file.
1#include "BmnDchHitProducer.h"
2#include "BmnDchPoint.h"
3#include "BmnDchHit.h"
4#include "CbmMCTrack.h"
5
6#include "FairRootManager.h"
7
8#include "TRandom.h"
9#include "TMath.h"
10#include "TString.h"
11#include "TFile.h"
12#include "TH1F.h"
13#include "TH2F.h"
14
15using std::cout;
16
18
20 FairTask("BmnDchHitProducer"),
21 fBmnPointsArray(nullptr),
22 fMCTracksArray(nullptr),
23 fBmnHitsArray(nullptr),
24 fPlaneTypes(nullptr),
25 hMCtr_ion_dc1(nullptr),
26 hMCtr_ion_dc2(nullptr),
27 hMCtr_ionID_dc1(nullptr),
28 hMCtr_ionID_dc2(nullptr)
29{
30 fInputBranchName = "DCHPoint";
31 fOutputHitsBranchName = "BmnDchHit";
32 fhTestFlnm2 = "test.BmnDCH_MC.root";
33 // fhList2.Add(hSmearing);
34
35 hMCtr_ion_dc1 = new TH1F("hMCHits_ion_dc1", "ion MC hits in DCH1 ", 9, 0, 9);
36 hMCtr_ion_dc2 = new TH1F("hMCHits_ion_dc2", "ion MC hits in DCH2 ", 9, 0, 9);
37 hMCtr_ionID_dc1 = new TH1F("hMCHits_ionID_dc1", "ion MC hits ID in DCH1 ", 10000, 0, 10000);
38 hMCtr_ionID_dc2 = new TH1F("hMCHits_ionID_dc2", "ion MC hits ID in DCH2 ", 10000, 0, 10000);
39 fhList2.Add(hMCtr_ion_dc1);
40 fhList2.Add(hMCtr_ion_dc2);
41 fhList2.Add(hMCtr_ionID_dc1);
42 fhList2.Add(hMCtr_ionID_dc2);
43
44 fPlaneTypes = new TString[fNActivePlanes]{"vb", "va", "ub", "ua" ,"yb", "ya", "xb", "xa"};
45}
46
48 if(fPlaneTypes) {
49 delete [] fPlaneTypes;
50 fPlaneTypes = nullptr;
51 }
52}
53
55
56 //cout << " BmnDchHitProducer::Init() " << endl;
57 rand_gen.SetSeed(5);//needed for repeated simulation
58
59 //Get ROOT Manager
60 FairRootManager* ioman = FairRootManager::Instance();
61
62 fBmnPointsArray = (TClonesArray*)ioman->GetObject(fInputBranchName);
63
64 if (!fBmnPointsArray) {
65 cout << "BmnDchHitProducer::Init(): branch " << fInputBranchName << " not found! Task will be deactivated" << endl;
66 SetActive(kFALSE);
67 return kERROR;
68 }
69
70 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
71
72 fBmnHitsArray = new TClonesArray(fOutputHitsBranchName, 100);
73 ioman->Register(fOutputHitsBranchName, "DCH", fBmnHitsArray, kTRUE);
74
75 return kSUCCESS;
76}
77
78void BmnDchHitProducer::Exec(Option_t* opt) {
79
80 if (!IsActive())
81 return;
82
83 fBmnHitsArray->Delete();
84
85 if (!fBmnPointsArray) {
86 Error("BmnDchHitProducer::Exec()", " !!! Unknown branch name !!! ");
87 return;
88 }
89
90 if (fVerbose) cout << "======================== DCH hit finder exec started ====================" << endl;
91
92 for (Int_t iPoint = 0; iPoint < fBmnPointsArray->GetEntriesFast(); iPoint++) {
93
94 BmnDchPoint* dchPoint = (BmnDchPoint*) fBmnPointsArray->UncheckedAt(iPoint);
95
96 Int_t track_id = dchPoint->GetTrackID();
97 Double_t x = dchPoint->GetX();
98 Double_t y = dchPoint->GetY();
99 Double_t z = dchPoint->GetZ();
100 Double_t px = dchPoint->GetPx();
101 Double_t py = dchPoint->GetPy();
102 Double_t pz = dchPoint->GetPz();
103
104 Int_t currentPlaneNum = dchPoint->GetPlaneNumber();
105 Int_t dchId = (z < 600.)? 1 : 2;//find out which dch the hit is from
106 Double_t pdg = dchPoint->GetPdgId();
107 Double_t charge = px*px +py*py +pz*pz;
108
109 if (dchPoint->GetCharge() == 0)continue;//skip neutral particles
110 if(fabs(px*px +py*py +pz*pz)<.25)continue;//skip low momentum particles
111
112 if(dchId == 1){
113 hMCtr_ionID_dc1->Fill(pdg);
114 }
115 if(dchId == 2){
116 hMCtr_ionID_dc2->Fill(pdg);
117 }
118 //X,Y GLOBAL shifts need to be set from a file for geomety creation (X,y pos.) and center
119 Double_t x_shift = 0.0;
120 Double_t y_shift = 0.0;
121
122 //Convert GLOBAL->LOCAL
123 Double_t x_loc = -(x - x_shift); // x-plane wires (inverted)
124 Double_t y_loc = y - y_shift; // y-plane wires
125 Double_t v_loc = (x_loc + y_loc)/TMath::Sqrt2(); // v-plane wires
126 Double_t u_loc = (y_loc - x_loc)/TMath::Sqrt2(); // u-plane wires
127
128 //current position in wire units
129 Double_t wire_pos = DBL_MAX; //default
130
131 //distance from the center of DCH to the outermost wire
132 Double_t owdist = (fPlaneTypes[currentPlaneNum][1] == 'a') ? 119.0 : 118.5; //119.0 and 118.0 are taken from N.Voytishin's code
133
134 if(fPlaneTypes[currentPlaneNum][0] == 'x') wire_pos = x_loc + owdist;
135 if(fPlaneTypes[currentPlaneNum][0] == 'y') wire_pos = y_loc + owdist;
136 if(fPlaneTypes[currentPlaneNum][0] == 'v') wire_pos = v_loc + owdist;
137 if(fPlaneTypes[currentPlaneNum][0] == 'u') wire_pos = u_loc + owdist;
138
139 //Int_t nearest_wire = (wire_pos - Int_t(wire_pos) < 0.5) ? Int_t(wire_pos) : Int_t(wire_pos) + 1;
140 Int_t nearest_wire;
141 Bool_t left = false; //pos. relative to the nearest wire (left or right)
142 if(wire_pos - Int_t(wire_pos) < 0.5) {
143 nearest_wire = Int_t(wire_pos);
144 left = false;
145 }
146 else {
147 nearest_wire = Int_t(wire_pos) + 1;
148 left = true;
149 }
150
151 //distance from the point to the nearest wire
152 Double_t wdist = TMath::Abs(wire_pos - nearest_wire);
153
154 //sigma error dependent on the distance to the nearest wire
155 Double_t sigm_err = (wdist < 0.02) ? 0.08 : (wdist >= 0.02 && wdist < 0.1) ? 0.06 : (wdist >= 0.1 && wdist < 0.4) ? 0.015 : (wdist >= 0.4 && wdist < 0.41) ? 0.08 : 0.10;
156
157 Double_t dev = rand_gen.Gaus(0, sigm_err);
158 Double_t wdist_smeared = wdist+dev ;
159
160 if(wdist_smeared > .5 ){//return the point if outside of the possible interval
161 // continue;
162 wdist_smeared = 1. - wdist_smeared;
163 dev = -dev;
164 }
165
166 if(wdist_smeared < 0){//return the point if outside of the possible interval
167 // continue;
168 dev = -dev;
169 wdist_smeared = - wdist_smeared;
170 }
171
172 //not needed for further reco for Nikolay's version, can be removed
173 //hit-1 with smearing
174 Double_t x1_smeared;// = -x_loc + x_shift + ;
175 Double_t y1_smeared;// = y_loc + y_shift ;
176 Double_t z1_smeared = z;// + dz1;
177
178 //hit-2 (symmetrical) with smearing
179 Double_t x2_smeared;
180 Double_t y2_smeared;
181 Double_t z2_smeared = z;// + dz2;
182
183
184 if(fPlaneTypes[currentPlaneNum][0] == 'x') {
185 if(left) {
186 x1_smeared = -(x_loc - dev) + x_shift;
187 y1_smeared = y_loc + y_shift;
188 x2_smeared = (x1_smeared - 2*wdist_smeared) + x_shift;
189 y2_smeared = y1_smeared;// + dy2;
190 }
191 else {
192 x1_smeared = -(x_loc + dev) + x_shift;
193 y1_smeared = y_loc + y_shift;
194 x2_smeared = (x1_smeared + 2*wdist_smeared) + x_shift;
195 y2_smeared = y1_smeared;
196 }
197 }
198
199 if(fPlaneTypes[currentPlaneNum][0] == 'y') {
200 if(left) {
201 x1_smeared = -x_loc + x_shift;
202 y1_smeared = y_loc + y_shift - dev;
203 x2_smeared = x1_smeared;
204 y2_smeared = y1_smeared + 2*wdist_smeared + y_shift;
205 }
206 else {
207 x1_smeared = -x_loc + x_shift;
208 y1_smeared = y_loc + y_shift + dev;
209 x2_smeared = x1_smeared;
210 y2_smeared = y1_smeared - 2*wdist_smeared + y_shift;
211 }
212 }
213
214 if(fPlaneTypes[currentPlaneNum][0] == 'v') {
215 if(left) {
216 x1_smeared = -(((v_loc - dev) - u_loc)/TMath::Sqrt2()) + x_shift;
217 y1_smeared = (((v_loc - dev) + u_loc)/TMath::Sqrt2()) + y_shift;
218 x2_smeared = -(((v_loc + 2*wdist_smeared) - u_loc)/TMath::Sqrt2()) + x_shift;
219 y2_smeared = (((v_loc + 2*wdist_smeared) + u_loc)/TMath::Sqrt2()) + y_shift;
220 }
221 else {
222 x1_smeared = -(((v_loc + dev) - u_loc)/TMath::Sqrt2()) + x_shift;
223 y1_smeared = (((v_loc + dev) + u_loc)/TMath::Sqrt2()) + y_shift;
224 x2_smeared = -(((v_loc - 2*wdist_smeared) - u_loc)/TMath::Sqrt2()) + x_shift;
225 y2_smeared = (((v_loc - 2*wdist_smeared) + u_loc)/TMath::Sqrt2()) + y_shift;
226 }
227 }
228
229 if(fPlaneTypes[currentPlaneNum][0] == 'u') {
230 if(left) {
231 x1_smeared = -((v_loc - (u_loc - dev))/TMath::Sqrt2()) + x_shift;
232 y1_smeared = ((v_loc + (u_loc - dev))/TMath::Sqrt2()) + y_shift;
233 x2_smeared = -((v_loc - (u_loc + 2*wdist_smeared))/TMath::Sqrt2()) + x_shift;
234 y2_smeared = ((v_loc + (u_loc + 2*wdist_smeared))/TMath::Sqrt2()) + y_shift;
235 }
236 else {
237 x1_smeared = -((v_loc - (u_loc + dev))/TMath::Sqrt2()) + x_shift;
238 y1_smeared = ((v_loc + (u_loc + dev))/TMath::Sqrt2()) + y_shift;
239 x2_smeared = -((v_loc - (u_loc - 2*wdist_smeared))/TMath::Sqrt2()) + x_shift;
240 y2_smeared = ((v_loc + (u_loc - 2*wdist_smeared))/TMath::Sqrt2()) + y_shift;
241 }
242 }
243
244
245 //Output information for debugging
246 Bool_t info_out =false;
247 if(info_out) {
248 cout << "(x:y:z) = ( " << x << " : " << y << " : " << z << " )\n";
249 cout << " pdg code "<<dchPoint->GetPdgId()<< " \n";
250 cout << " charge "<<dchPoint->GetCharge()<< " \n";
251
252 cout << " currentPlaneNum = " << currentPlaneNum << "\n";
253 cout << " PlaneType = " << fPlaneTypes[currentPlaneNum][0] << "\n";
254 cout << " dev "<<dev<<" wdist_smeared = " <<wdist_smeared<< "\n";
255 cout << " smeared1(x:y:z) = ( " << x1_smeared << " : " << y1_smeared << " : " << z1_smeared << " )\n";
256 cout << " smeared2(x:y:z) = ( " << x2_smeared << " : " << y2_smeared << " : " << z2_smeared << " )\n";
257 cout << " wdist = " << wdist << "\n";
258 cout << " wire_pos = " << wire_pos << "\n";
259 cout << " nearest_wire = " << nearest_wire << "\n";
260 cout << " sigm_err = " << sigm_err << "\n";
261 cout << " left = " << left << "\n";
262 cout << " dchId = " << dchId << "\n";
263
264 cout << "\n";
265 }
266
267 //adding a new hit with probability 90%
268 if(rand_gen.Uniform() <= 1.) {
269 //adding a hit with global x,y,z from sim and wire + smeared distance from wire for further reconstruction
270 BmnDchHit* hit = new ((*fBmnHitsArray)[fBmnHitsArray->GetEntriesFast()])
271 BmnDchHit(0, TVector3(x, y, z), TVector3(sigm_err, sigm_err, 0.0), iPoint);
272
273 currentPlaneNum += (dchId == 1) ? 0 : 8;
274
275 hit->SetDchLayerNumber(currentPlaneNum);
276 hit->SetDchId(dchId-1);
277 hit->SetWirePosition(nearest_wire);
278 hit->SetDrift(wdist_smeared);
279 hit->SetPhi(charge);
280 hit->SetHitId(track_id);
281 }
282 }
283
284 if (fVerbose) cout << "======================== DCH hit finder exec finished ===================" << endl;
285}
286
288
289 if (fVerbose){
290 TFile file(fhTestFlnm2.Data(), "RECREATE");
291 fhList2.Write();
292 file.Close();
293
294 }
295}
TString fhTestFlnm2
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
void SetHitId(Int_t idx)
Definition BmnDchHit.h:69
void SetWirePosition(Double_t v)
Definition BmnDchHit.h:47
void SetPhi(Double_t phi)
Definition BmnDchHit.h:65
void SetDchLayerNumber(UShort_t id)
Definition BmnDchHit.h:60
void SetDrift(Double_t v)
Definition BmnDchHit.h:45
void SetDchId(UChar_t id)
Definition BmnDchHit.h:58
Double_t GetPdgId()
Definition BmnDchPoint.h:42
Int_t GetPlaneNumber()
Definition BmnDchPoint.h:46
Double_t GetCharge()
Definition BmnDchPoint.h:43