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