BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnMwpcHitProducer.cxx
Go to the documentation of this file.
1// Author: Vasilisa Lenivenko <vasilisa@jinr.ru> 2021-03-11
3
4#include "BmnHit.h"
5#include "BmnMwpcHit.h"
6#include "BmnMwpcPoint.h"
7#include "CbmMCTrack.h"
8#include "FairHit.h"
9#include "FairMCPoint.h"
10#include "FairRootManager.h"
11#include "TCanvas.h"
12#include "TFile.h"
13#include "TGeoManager.h"
14
15using namespace std;
16using namespace TMath;
17
19 : //(Int_t num = 1) :
20 fEventNo(0)
21 , fBmnMwpcPointsArray(nullptr)
22 , fBmnPointsArray(nullptr)
23 , fBmnMwpcDigitsArray(nullptr)
24 , fMCTracksArray(nullptr)
25 , fBmnMwpcHitsArray(nullptr)
26 , fBmnHitsArray(nullptr)
28 , hY_vsX2(nullptr)
29 , hY_vsX3(nullptr)
30 , hY_vsX_pl0(nullptr)
31 , hY_vsX_pl1(nullptr)
32 , hY_vsX_pl2(nullptr)
33 , hY_vsX_star2(nullptr)
34 , hY_vsX_star3(nullptr)
35{
36 fInputBranchName = "MWPCPoint";
37 fOutputHitsBranchName = "BmnMwpcHit";
38 fMwpcNum = 1;
39 fRunType = "points";
40 TString str;
41 str.Form("%d", fMwpcNum);
42 fInputMCBranchName = TString("MWPC") + str + TString("Point");
43 fInputDigiBranchName = TString("bmn_mwpc_digit");
44}
45
47
49{
50 if (fDebug)
51 cout << " BmnMwpcHitProducer::Init() " << endl;
52
53 rand_gen.SetSeed(5);
54 FairRootManager* ioman = FairRootManager::Instance();
55 fBmnPointsArray = (TClonesArray*)ioman->GetObject(fInputBranchName);
56 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
58 ioman->Register(fOutputHitsBranchName, "MWPC", fBmnHitsArray, kTRUE);
59
60 //--some hists--
61 if (fDebug) {
62 hY_vsX2 = new TH2D("Y_vsX2", "Y_vsX2", 140, -35, 35, 140, -35, 35);
63 fList.Add(hY_vsX2);
64 hY_vsX3 = new TH2D("Y_vsX3", "Y_vsX3", 140, -35, 35, 140, -35, 35);
65 fList.Add(hY_vsX3);
66 hY_vsX_star2 = new TH2D("Y_vsX_star2", "Y_vsX_star2", 140, -35, 35, 140, -35, 35);
68 hY_vsX_star3 = new TH2D("Y_vsX_star3", "Y_vsX_star3", 140, -35, 35, 140, -35, 35);
70 hY_vsX_pl0 = new TH2D("Y_vsX_pl0", "Y_vsX_pl0", 140, -35, 35, 140, -35, 35);
71 fList.Add(hY_vsX_pl0);
72 hY_vsX_pl1 = new TH2D("Y_vsX_pl1", "Y_vsX_pl1", 140, -35, 35, 140, -35, 35);
73 fList.Add(hY_vsX_pl1);
74 hY_vsX_pl2 = new TH2D("Y_vsX_pl2", "Y_vsX_pl2", 140, -35, 35, 140, -35, 35);
75 fList.Add(hY_vsX_pl2);
76 }
77
78 return kSUCCESS;
79}
80
82{
83 if (fDebug)
84 cout << endl;
85 if (fDebug)
86 cout << "BmnMwpcHitProducer::Exec() started!" << endl;
87 if (fDebug)
88 printf("Event number: %d\n", fEventNo++);
89
90 fBmnHitsArray->Delete();
91 if (!fBmnPointsArray) {
92 Error("BmnDchHitProducer::Exec()", " !!! Unknown branch name !!! ");
93 return;
94 }
95
97
98 if (fDebug)
99 cout << "======================== BmnMwpcHitProducer::Exec() finished ========================" << endl;
100}
101
103{
104
105 Double_t err[3] = {0.25 / Sqrt(12), 0.25 / Sqrt(12), 0.}; // Uncertainties of coordinates
106 // some consts
107 Double_t dw = 0.25; // [cm] // wires step
108 Double_t kMiddlePl = 47.25; // Center of wires plane
109 Double_t kCheaksize = 12. + 0.5 * dw; // 20.78;/?
110 Double_t a_side = 4 * Sqrt(3) + 0.5 * dw;
111 Double_t ShiftX[4];
112 Double_t ShiftY[4];
113 // shift for run7
114 ShiftX[2] = -0.271 - 0.5;
115 ShiftY[2] = -6.038 + 4.5;
116
117 ShiftX[3] = -0.234 - 0.5;
118 ShiftY[3] = -6.140 + 4.5;
119
120 Int_t Nmc_tracks = 0;
121 Int_t Id_curr = -1;
122 Int_t Ch_curr = -1;
123 Int_t plNumf = -1;
124 Int_t plNuml = -1;
125 Double_t xf = -999.;
126 Double_t yf = -999.;
127 Double_t zf = -999.;
128 Double_t xl = -999.;
129 Double_t yl = -999.;
130 Double_t zl = -999.;
131
132 Double_t xi[6], yi[6], zi[6];
133
134 for (Int_t i = 0; i < fBmnPointsArray->GetEntriesFast(); i++) { // read
135 BmnMwpcPoint* point = (BmnMwpcPoint*)fBmnPointsArray->UncheckedAt(i);
136
137 Int_t IsPrimary = point->GetIsPrimary();
138 Int_t charge = point->GetCharge();
139 Int_t pdg = point->GetPdgId();
140 Double_t Pz = point->GetPz();
141
142 if (charge == 0)
143 continue; // qgsm
144 // if (charge != 18) continue;//ion carbon
145 // if (fDebug) cout<<" charge "<<charge<<endl;
146 if (IsPrimary == 0)
147 continue;
148 if (Pz < 0.1)
149 continue; // tmp
150 Int_t track_id = point->GetTrackID();
151 if (track_id != Id_curr) {
152 Id_curr = track_id;
153 Ch_curr = -1;
154 if (fDebug)
155 cout << " ----" << endl;
156 }
157
158 Double_t x = point->GetX();
159 Double_t y = point->GetY();
160 Double_t z = point->GetZ();
161
162 Int_t ChId = -1;
163 if (z < -847.)
164 ChId = 0;
165 if (z > -756. && z < -750.)
166 ChId = 1;
167 if (z > -360. && z < -354.)
168 ChId = 2;
169 if (z > -211.)
170 ChId = 3;
171
172 if (ChId == 2 && fDebug)
173 hY_vsX2->Fill(x, y);
174 if (ChId == 3 && fDebug)
175 hY_vsX3->Fill(x, y);
176
177 if (Ch_curr != ChId) {
178 Ch_curr = ChId;
179 plNumf = -1;
180 plNuml = -1;
181 }
182
183 if (fDebug)
184 cout << "=== track_id " << track_id << " ChId " << ChId << " xmc " << x << " y " << y << " z " << z
185 << " Pz " << Pz << endl;
186 //---
187 TGeoNode* curNode = gGeoManager->FindNode(x, y, z);
188 TString nameNode = TString(curNode->GetName());
189 // if (fDebug) cout<<" nameNode "<<nameNode<<endl;
190 Short_t planeNum = TString(nameNode(Int_t(nameNode.Length() - 1), 1)).Atoi();
191 Int_t time_wire = 70;
192 if (ChId == 2 && planeNum == 0 && fDebug)
193 hY_vsX_pl0->Fill(x, y);
194 if (ChId == 2 && planeNum == 1 && fDebug)
195 hY_vsX_pl1->Fill(x, y);
196 if (ChId == 2 && planeNum == 2 && fDebug)
197 hY_vsX_pl2->Fill(x, y);
198
199 if (plNumf < 0) {
200 plNumf = planeNum;
201 plNuml = planeNum + 3;
202 xf = x;
203 yf = y;
204 zf = z;
205 }
206
207 if (plNumf > -1 && plNuml == planeNum) {
208 if (ChId == 2)
209 Nmc_tracks++;
210 xl = x;
211 yl = y;
212 zl = z;
213
214 Double_t Ax = (xf - xl) / (zf - zl);
215 Double_t Ay = (yf - yl) / (zf - zl);
216
217 for (Int_t ipl = 0; ipl < 6; ipl++) {
218 xi[ipl] = Ax * (ipl - plNumf) + xf;
219 yi[ipl] = Ay * (ipl - plNumf) + yf;
220 if (fDebug)
221 cout << " xi[" << ipl << "] " << xi[ipl] << " yi[" << ipl << "] " << yi[ipl] << " z "
222 << zf + ipl - plNumf;
223 xi[ipl] += ShiftX[ChId]; // shift to the chamber center
224 yi[ipl] += ShiftY[ChId];
225 zi[ipl] = zf + ipl - plNumf;
226 // if (fDebug) cout<<" shift to the chamber center xmc "<<xi[ipl]<<" y "<<xi[ipl]<<endl;
227
228 Double_t wire_pos = -1.; // default
229 Double_t hit_coord;
230
231 if (ipl == 2 || ipl == 5) { //--x---//if (planeNum == 0 || planeNum == 3 )
232 hit_coord = xi[ipl];
233 if (fDebug)
234 cout << " -- x --" << hit_coord << " y " << yi[ipl] << endl;
235 if (fabs(yi[ipl]) > a_side)
236 continue; // cheak perpendicular coord size//wire lenght
237 }
238 if (ipl == 0 || ipl == 3) { //--v---//if (planeNum == 1 || planeNum == 4 )
239 hit_coord = 0.5 * (xi[ipl] - Sqrt(3) * yi[ipl]);
240 Double_t v_t = (Sqrt(3) * xi[ipl] + yi[ipl]) * 0.5;
241 if (fDebug)
242 cout << " -- v --" << hit_coord << " v_t " << v_t << endl;
243 if (fabs(v_t) > a_side)
244 continue; // cheak perpendicular coord size//wire lenght
245 }
246 if (ipl == 1 || ipl == 4) { //--u---//if (planeNum == 2 || planeNum == 5 )
247 hit_coord = 0.5 * (xi[ipl] + Sqrt(3) * yi[ipl]);
248 Double_t u_t = (Sqrt(3) * xi[ipl] - yi[ipl]) * 0.5;
249 if (fDebug)
250 cout << " -- u --" << hit_coord << " u_t " << u_t << endl;
251 if (fabs(u_t) > a_side)
252 continue; // cheak perpendicular coord size//wire lenght
253 }
254
255 // if (fDebug) cout<<" hit_coord "<<hit_coord<<" kCheaksize "<<kCheaksize<<endl;
256 if (fabs(hit_coord) > kCheaksize)
257 continue; // check hexagon coord size
258
259 if (ipl == 1 || ipl == 2 || ipl == 3) { // if (planeNum == 0 || planeNum == 1 || planeNum == 5)
260 hit_coord = -hit_coord; // reading direction changing
261 }
262
263 //--wire calculation--
264 wire_pos = (hit_coord + kMiddlePl * dw) / dw;
265
266 // current position in wire units
267 Int_t nearest_wire = Int_t(wire_pos);
268 // Double_t wdist = TMath::Abs(wire_pos - nearest_wire);
269 // sigma error dependent on the distance to the nearest wire
270 // Double_t sigm_err = wdist;
271
272 if (fDebug)
273 cout << " Ch " << ChId << " track_id " << track_id << " xmc " << x << " y " << y << " pl " << ipl
274 << " XUV " << hit_coord << " wire " << wire_pos << " nearest " << nearest_wire << endl;
275 // if (fDebug) cout<<" ----"<<endl;
276 if (nearest_wire < 0 || nearest_wire > 95)
277 continue;
278 if (fDebug && ChId == 2)
279 hY_vsX_star2->Fill(xi[ipl], yi[ipl]);
280 if (fDebug && ChId == 3)
281 hY_vsX_star3->Fill(xi[ipl], yi[ipl]);
282
283 //------
284
285 //---faile for Goran---
286 // if (pdg == PDG_B11 ){//if (pdg == PDG_Li7 || pdg == PDG_He4 ){
287 if (fDebug)
288 cout << " pdg " << pdg << endl;
289 //|| pdg == PDG_Li7 || pdg == PDG_Li8 || pdg == PDG_He4 || pdg == PDG_Be9 || pdg == PDG_H2){
290
291 if (rand_gen.Uniform() <= .9) {
292 BmnMwpcHit* hit1 = new ((*fBmnHitsArray)[fBmnHitsArray->GetEntriesFast()])
293 BmnMwpcHit(0, TVector3(xi[ipl], yi[ipl], zi[ipl]), TVector3(err[0], err[1], 0.0), i);
294
295 hit1->SetMwpcId(ChId);
296 hit1->SetWireNumber(nearest_wire);
297 hit1->SetHitId(track_id);
298 hit1->SetWireTime(time_wire);
299 hit1->SetPlaneId(ipl);
300 hit1->SetPdgId(pdg);
301 }
302 // }// if (pdg == PDG_B11
303 /*
304 BmnMwpcHit* hit2 = new ((*fBmnHitsArray)[fBmnHitsArray->GetEntriesFast()])
305 BmnMwpcHit(0, TVector3(point->GetX(), point->GetY(), z), TVector3(err[0], err[1], 0.0), i);
306
307 hit1->SetMwpcId(ChId);
308 hit1->SetWireNumber(not_so_near);
309 hit1->SetHitId(track_id);
310 hit1->SetWireTime(time_wire);
311 hit1->SetPlaneId(planeNum);
312 */
313
314 plNumf = -1;
315 plNuml = -1;
316 } // ipl
317 } // if (plNumf > 0 && plNuml > 0){
318 } // i//read
319 if (fDebug)
320 cout << " Nmc_tracks " << Nmc_tracks << endl;
321
322 return kBMNSUCCESS;
323} // exec
324
329
331{
332 if (fDebug) {
333 printf("BmnMwpcHitProducer: write hists to file... ");
334 fOutputFileName = "hMWPCHitProducer_run1.root";
335 cout << fOutputFileName << endl;
336 TFile file(fOutputFileName, "RECREATE");
337 fList.Write();
338 file.Close();
339 }
340}
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
int Int_t
short Short_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Error(const char *location, const char *msgfmt,...)
R__EXTERN TGeoManager * gGeoManager
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
BmnMwpcHitProducer()
Default constructor.
TClonesArray * fBmnMwpcPointsArray
Input array of MWPC Points.
virtual void Exec(Option_t *opt)
Virtual method Exec.
TClonesArray * fBmnHitsArray
Output array of Hits.
TClonesArray * fBmnMwpcDigitsArray
Input array of MWPC Digits.
TClonesArray * fBmnPointsArray
Input array of Points.
virtual InitStatus Init()
Virtual method Init.
TClonesArray * fBmnMwpcHitsArray
Output array of MWPC Hits.
virtual void Finish()
Virtual method Finish.
virtual ~BmnMwpcHitProducer()
Destructor.
TClonesArray * fMCTracksArray
Input array of MC Tracks.
void SetMwpcId(Short_t id)
Definition BmnMwpcHit.h:46
void SetWireTime(Int_t time_wire)
Definition BmnMwpcHit.h:56
void SetPlaneId(Int_t plane_id)
Definition BmnMwpcHit.h:57
void SetWireNumber(Int_t wire_num)
Definition BmnMwpcHit.h:55
void SetPdgId(Int_t pdg_id)
Definition BmnMwpcHit.h:58
void SetHitId(Int_t idx)
Definition BmnMwpcHit.h:48
Double_t GetCharge()
Double_t GetPdgId()
Int_t GetIsPrimary()
void Close(Option_t *option="") override
const char * GetName() const override
Ssiz_t Length() const
Int_t Atoi() const
void Form(const char *fmt,...)
Double_t Sqrt(Double_t x)
Definition json.hpp:4446