BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmL1ReadEvent.cxx
Go to the documentation of this file.
1/*
2 *====================================================================
3 *
4 * CBM Level 1 Reconstruction
5 *
6 * Authors: I.Kisel, S.Gorbunov
7 *
8 * e-mail : ikisel@kip.uni-heidelberg.de
9 *
10 *====================================================================
11 *
12 * Read Event information to L1
13 *
14 *====================================================================
15 */
16
17#include "CbmKF.h"
18#include "CbmL1.h"
19#include "CbmMCTrack.h"
20#include "CbmMvdHit.h"
21#include "CbmMvdHitMatch.h"
22#include "CbmMvdPoint.h"
23#include "CbmStsCluster.h"
24#include "CbmStsDigi.h"
25#include "CbmStsHit.h"
26#include "CbmStsPoint.h"
27#include "L1Algo/L1Algo.h"
28#include "TDatabasePDG.h"
29
30#include <iostream>
31#include <vector>
32
33using std::cout;
34using std::endl;
35using std::find;
36using std::vector;
37
39{ // used for sort MCPoints for creation of MCTracks
40 int ID; // MCPoint ID
41 double z; // MCPoint z
42 int StsHit; // index of hit in algo->vStsHits
43 int MCPoint; // index of mcPoint in vMCPoints
44 bool eff;
45 static bool compareIDz(const TmpMCPoint& a, const TmpMCPoint& b)
46 {
47 return (a.ID < b.ID) || ((a.ID == b.ID) && (a.z < b.z));
48 }
49};
50
51struct TmpHit
52{ // used for sort Hits before writing in the normal arrays
53 int iStripF, iStripB; // indices of real-strips, sts-strips (one got from detector. They consist from parts with
54 // differen positions, so will be divided before using)
55 int indStripF, indStripB; // indices of L1-strips, indices in TmpStrip arrays
58 int ExtIndex; // index of hit in the TClonesArray array ( negative for MVD )
59 bool isStrip;
60 double u_front, u_back; // positions of strips
61 double du_front, du_back; // AZ - errors of strips
62 double x, y; // position of hit
63 int iMC; // index of MCPoint in the vMCPoints array
64 double strip1, strip2; // AZ-140223 - COGs of clusters
65
66 static bool Compare(const TmpHit& a, const TmpHit& b)
67 {
68 return (a.iStation < b.iStation) || ((a.iStation == b.iStation) && (a.y < b.y));
69 }
70};
71
73{
75 fscal du; // AZ
76 fscal strip; // AZ-140223 - COG of cluster
79 bool isStrip;
80 int effIndex; // used for unefficiency
81};
82
83/// Repack data from Clones Arrays to L1 arrays
85{
86 if (fVerbose >= 10)
87 cout << "ReadEvent: start." << endl;
88 // clear arrays for next event
89 vMCPoints.clear();
90 vMCTracks.clear();
91 vStsHits.clear();
92 vRTracks.clear();
93 vHitMCRef.clear();
94 vHitStore.clear();
95 algo->vStsHits.clear();
96 algo->vStsStrips.clear();
97 algo->vStsStripsB.clear();
98 algo->vStsZPos.clear();
99 algo->vSFlag.clear();
100 algo->vSFlagB.clear();
101#ifdef AZ
102 algo->vAllHitPoints.clear(); // AZ-240223
103#endif
104 if (fVerbose >= 10)
105 cout << "ReadEvent: clear is done." << endl;
106
107 vector<TmpHit> tmpHits;
108 vector<TmpStrip> tmpStrips;
109 vector<TmpStrip> tmpStripsB;
110
111 // -- produce Sts hits from space points --
112
113 for (int i = 0; i < NStation; i++) {
114 algo->StsHitsStartIndex[i] = static_cast<THitI>(-1);
115 algo->StsHitsStopIndex[i] = 0;
116 }
117
118 // for a new definition of the reconstructable track (4 consequtive MC Points):
119 vector<bool> isUsedMvdPoint; // marks, whether Mvd MC Point already in the vMCPoints
120 vector<bool> isUsedStsPoint; // marks, whether Mvd MC Point already in the vMCPoints
121
122 // get MVD hits
123 int nMvdHits = 0;
124 if (listMvdHits) {
125 Int_t nEnt = listMvdHits->GetEntries();
126 Int_t nMC = (listMvdPts) ? listMvdPts->GetEntries() : 0;
127
128 if (listMvdPts) {
129 isUsedMvdPoint.resize(nMC);
130 for (int iMc = 0; iMc < nMC; iMc++)
131 isUsedMvdPoint[iMc] = 0;
132 }
133
134 for (int j = 0; j < nEnt; j++) {
135 TmpHit th;
136 {
138 th.ExtIndex = -(1 + j);
139 th.iStation = mh->GetStationNr() - 1;
140 th.iSector = 0;
141 th.isStrip = 0;
142 th.iStripF = j;
143 th.iStripB = -1;
144 if (th.iStripF < 0)
145 continue;
146 if (th.iStripF >= 0 && th.iStripB >= 0)
147 th.isStrip = 1;
148 if (th.iStripB < 0)
149 th.iStripB = th.iStripF;
150
151 TVector3 pos, err;
152 mh->Position(pos);
153 mh->PositionError(err);
154
155 th.x = pos.X();
156 th.y = pos.Y();
157
158 L1Station& st = algo->vStations[th.iStation];
159 th.u_front = th.x * st.frontInfo.cos_phi[0] + th.y * st.frontInfo.sin_phi[0];
160 th.u_back = th.x * st.backInfo.cos_phi[0] + th.y * st.backInfo.sin_phi[0];
161 }
162 th.iMC = -1;
163 int iMC = -1;
164 // int iMCTr = -1;
165 // if( listMvdHitMatches ){
166 // CbmMvdHitMatch *match = (CbmMvdHitMatch*) listMvdHitMatches->At(j);
167 // if( match){
168 // iMC = match->GetPointId();
169 // iMCTr = match->GetTrackId();
170 // }
171 // }
172 if (listMvdHitMatches) {
174 if (match) {
175 iMC = match->GetPointId();
176 }
177 }
178 if (listMvdPts && iMC >= 0) { // TODO1: don't need this with FairLinks
179 CbmL1MCPoint MC;
180 if (!ReadMCPoint(&MC, iMC, 1)) {
181 MC.iStation = th.iStation;
182 isUsedMvdPoint[iMC] = 1;
183
184 // MC.ID = iMCTr; // because atch->GetPointId() == 0 !!! and ReadMCPoint don't work
185 // MC.z = th.iStation; // for sort in right order
186
187 vMCPoints.push_back(MC);
188 th.iMC = vMCPoints.size() - 1;
189 }
190 } // if listStsPts
191 // if( h.MC_Point >=0 ) // DEBUG !!!!
192 {
193 tmpHits.push_back(th);
194 nMvdHits++;
195 }
196 } // for j
197 } // if listMvdHits
198 if (fVerbose >= 10)
199 cout << "ReadEvent: mvd hits are gotten." << endl;
200
201 // get STS hits
202 int nStsHits = 0;
203 if (listStsHits) {
204 Int_t nEnt = listStsHits->GetEntries();
205 Int_t nMC = (listStsPts) ? listStsPts->GetEntries() : 0;
206
207 if (listStsPts) {
208 isUsedStsPoint.resize(nMC);
209 for (int iMc = 0; iMc < nMC; iMc++)
210 isUsedStsPoint[iMc] = 0;
211 }
212
213 int negF = 0;
214 for (int j = 0; j < nEnt; j++) {
216 if (sh->GetUniqueID())
217 continue; // AZ - skip used hits
218 TmpHit th;
219 {
221 th.ExtIndex = j;
222 th.iStation = NMvdStations + mh->GetStationNr() - 1;
223 th.iSector = mh->GetSectorNr();
224 th.isStrip = 0;
225 th.iStripF = mh->GetDigi(0);
226 th.iStripB = mh->GetDigi(1);
227 if (th.iStripF < 0) {
228 negF++;
229 continue;
230 }
231 if (th.iStripF >= 0 && th.iStripB >= 0)
232 th.isStrip = 1;
233 if (th.iStripB < 0)
234 th.iStripB = th.iStripF;
235
236 th.iStripF += nMvdHits;
237 th.iStripB += nMvdHits;
238
239 TVector3 pos, err;
240 mh->Position(pos);
241 mh->PositionError(err);
242
243 th.x = pos.X();
244 th.y = pos.Y();
245
246 L1Station& st = algo->vStations[th.iStation];
247 th.u_front = th.x * st.frontInfo.cos_phi[0] + th.y * st.frontInfo.sin_phi[0];
248 th.u_back = th.x * st.backInfo.cos_phi[0] + th.y * st.backInfo.sin_phi[0];
249 th.strip1 = mh->GetStrip(0); // AZ-140223
250 th.strip2 = mh->GetStrip(1); // AZ-140223
251
252 // th.x = th.y = 0.0; //AZ
253 // cout << th.iStation << " " << st.frontInfo.cos_phi[0] << " " << st.frontInfo.sin_phi[0] << endl; //AZ
254 // cout << th.x << " " << th.y << " " << th.u_front << " " << th.u_back << endl;
255 // double s2 = st.frontInfo.sigma2[0]; //AZ
256 // cout << st.frontInfo.sigma2 << " " << s2 << " " << sqrt(s2) << " " << 0.04/sqrt(12.) << endl;
257 // th.du_front = sqrt(s2); //AZ - pitch error - for test
258 th.du_front = err.X(); // AZ - cluster error
259 // s2 = st.backInfo.sigma2[0]; //AZ
260 // th.du_back = sqrt(s2); //AZ - pitch error - for test
261 th.du_back = err.Y(); // AZ - cluster error
262 }
263 th.iMC = -1;
264
265 int iMC = sh->GetRefIndex(); // TODO1: don't need this with FairLinks
266 if (listStsPts && iMC >= 0 && iMC < nMC) {
267 CbmL1MCPoint MC;
268 if (!ReadMCPoint(&MC, iMC, 0)) {
269 MC.iStation = th.iStation;
270 vMCPoints.push_back(MC);
271 isUsedStsPoint[iMC] = 1;
272 th.iMC = vMCPoints.size() - 1;
273 }
274 } // if listStsPts
275
276 // if( th.iMC >=0 ) // DEBUG !!!!
277 {
278 tmpHits.push_back(th);
279 nStsHits++;
280 }
281 } // for j
282 } // if listStsHits
283 if (fVerbose >= 10)
284 cout << "ReadEvent: sts hits are gotten." << endl;
285
286 // add MC points, which has not been added yet
287 if (listMvdHits && listMvdPts) {
288 int nMC = listMvdPts->GetEntriesFast();
289 for (int iMC = 0; iMC < nMC; iMC++) {
290 if (!(isUsedMvdPoint[iMC])) {
291 CbmL1MCPoint MC;
292 if (!ReadMCPoint(&MC, iMC, 1)) {
293 MC.iStation = (L1_DYNAMIC_CAST<CbmMvdPoint*>(listMvdPts->At(iMC)))->GetStationNr() - 1;
294 isUsedMvdPoint[iMC] = 1;
295 vMCPoints.push_back(MC);
296 }
297 }
298 }
299 }
300 if (listStsHits && listStsPts) {
301 int nMC = listStsPts->GetEntriesFast();
302 for (int iMC = 0; iMC < nMC; iMC++) {
303 if (!(isUsedStsPoint[iMC])) {
304 CbmL1MCPoint MC;
305 if (!ReadMCPoint(&MC, iMC, 0)) {
306 MC.iStation = -1;
307 L1Station* sta = algo->vStations + NMvdStations;
308 for (int iSt = 0; iSt < NStsStations; iSt++)
309 MC.iStation = (MC.z > sta[iSt].z[0] - 2.5) ? (NMvdStations + iSt) : MC.iStation;
310 isUsedStsPoint[iMC] = 1;
311 vMCPoints.push_back(MC);
312 }
313 }
314 }
315 }
316 // sort hits
317 int nHits = nMvdHits + nStsHits;
318 sort(tmpHits.begin(), tmpHits.end(), TmpHit::Compare);
319
320 // -- create strips --
321 int NStrips = 0, NStripsB = 0;
322 for (int ih = 0; ih < nHits; ih++) {
323 TmpHit& th = tmpHits[ih];
324
325 // try to find the respective front and back strip from the already created
326 th.indStripF = -1;
327 th.indStripB = -1;
328 for (int is = 0; is < NStrips; is++) {
329 TmpStrip& s = tmpStrips[is];
330 if (s.iStation != th.iStation || s.iSector != th.iSector)
331 continue;
332 if (s.iStrip != th.iStripF)
333 continue;
334#ifdef AZ
335 if (fabs(s.strip - th.strip1) > 1.e-4)
336 continue; // AZ-140223
337#else
338 if (fabs(s.u - th.u_front) > 1.e-4)
339 continue;
340#endif
341 th.indStripF = is;
342 }
343 for (int is = 0; is < NStripsB; is++) {
344 TmpStrip& s = tmpStripsB[is];
345 if (s.iStation != th.iStation || s.iSector != th.iSector)
346 continue;
347 if (s.iStrip != th.iStripB)
348 continue;
349#ifdef AZ
350 if (fabs(s.strip - th.strip2) > 1.e-4)
351 continue; // AZ-140223
352#else
353 if (fabs(s.u - th.u_back) > 1.e-4)
354 continue;
355#endif
356 th.indStripB = is;
357 }
358 // create new strips
359 if (th.indStripF < 0) {
360 TmpStrip tmp;
361 tmp.iStation = th.iStation;
362 tmp.iSector = th.iSector;
363 tmp.iStrip = th.iStripF;
364 tmp.u = th.u_front;
365 tmp.du = th.du_front; // AZ
366 tmp.isStrip = th.isStrip;
367 tmp.strip = th.strip1; // AZ-140223
368 tmpStrips.push_back(tmp);
369 th.indStripF = NStrips++;
370 }
371 if (th.indStripB < 0) {
372 TmpStrip tmp;
373 tmp.iStation = th.iStation;
374 tmp.iSector = th.iSector;
375 tmp.iStrip = th.iStripB;
376 tmp.isStrip = th.isStrip;
377 tmp.u = th.u_back;
378 tmp.du = th.du_back; // AZ
379 tmp.strip = th.strip2; // AZ-140223
380 tmpStripsB.push_back(tmp);
381 th.indStripB = NStripsB++;
382 }
383 } // ih
384 // cout << " xxx " << nHits << " " << tmpStrips.size() << " " << tmpStripsB.size() << endl; //AZ-140223
385
386 // -- save strips --
387 // for( int i=0; i<NStrips; i++ ) tmpStrips[i].effIndex = -1;
388 // for( int i=0; i<NStripsB; i++ ) tmpStripsB[i].effIndex = -1;
389
390 // // make unefficiency
391 // if(1){ // space point unefficiency
392 // for( int i=0; i<nHits; i++ ){
393 // TmpHit &th = tmpHits[i];
394 // if( th.indStripF <0 || th.indStripF >= NStrips ) continue;
395 // if( th.indStripB <0 || th.indStripB >= NStripsB ) continue;
396 // if( th.iMC<0 ) continue;
397 // if( gRandom->Uniform(1)>fDetectorEfficiency ){
398 // tmpStrips [th.indStripF].effIndex = -2;
399 // tmpStripsB[th.indStripB].effIndex = -2;
400 // }
401 // }
402 // } else { // strip unefficiency
403 //
404 // for( int i=0; i<NStrips; i++ ){
405 // if( gRandom->Uniform(1)>fDetectorEfficiency ) tmpStrips[i].effIndex = -2;
406 // }
407 //
408 // for( int i=0; i<NStripsB; i++ ){
409 // TmpStrip &ts = tmpStripsB[i];
410 // if( ts.isStrip && gRandom->Uniform(1)>fDetectorEfficiency ) ts.effIndex = -2;
411 // }
412 // }
413
414 // take into account unefficiency and save strips in L1Algo
415 Int_t NEffStrips = 0, NEffStripsB = 0;
416 for (int i = 0; i < NStrips; i++) {
417 TmpStrip& ts = tmpStrips[i];
418 // if( ts.effIndex == -1 ){
419 ts.effIndex = NEffStrips++;
420 char flag = ts.iStation * 4;
421 // algo->vStsStrips.push_back(ts.u);
422 algo->vStsStrips.push_back(L1Strip(ts.u, ts.du)); // AZ
423 algo->vSFlag.push_back(flag);
424 // }
425 }
426 for (int i = 0; i < NStripsB; i++) {
427 TmpStrip& ts = tmpStripsB[i];
428 // if( ts.effIndex == -1 ){
429 ts.effIndex = NEffStripsB++;
430 char flag = ts.iStation * 4;
431 // algo->vStsStripsB.push_back(ts.u);
432 algo->vStsStripsB.push_back(L1Strip(ts.u, ts.du)); // AZ
433 algo->vSFlagB.push_back(flag);
434 // }
435 }
436
437 if (fVerbose >= 10)
438 cout << "ReadEvent: strips are read." << endl;
439
440 // -- save hits --
441 // vector<int> vUnEffHitMCRef;
442 // vector<CbmL1HitStore> vUnEffHitStore;
443 int nEffHits = 0;
444 vector<float> vStsZPos_temp; // temp array for unsorted z positions of detectors segments
445 for (int i = 0; i < nHits; i++) {
446 TmpHit& th = tmpHits[i];
447
449 s.ExtIndex = th.ExtIndex;
450 s.iStation = th.iStation;
451 s.x = th.x;
452 s.y = th.y;
453
454 if (th.indStripF < 0 || th.indStripF >= NStrips)
455 continue;
456 if (th.indStripB < 0 || th.indStripB >= NStripsB)
457 continue;
458
459 TmpStrip& tsF = tmpStrips[th.indStripF];
460 TmpStrip& tsB = tmpStripsB[th.indStripB];
461 // if( tsF.effIndex <0 || tsB.effIndex <0 ){
462 // vUnEffHitStore.push_back(s);
463 // vUnEffHitMCRef.push_back(th.iMC);
464 // continue;
465 // }
466
467 L1StsHit h;
468 h.f = tsF.effIndex;
469 h.b = tsB.effIndex;
470
471 // find and save z positions
472 float z_tmp;
473 int ist = th.iStation;
474 if (ist < NMvdStations) {
476 z_tmp = t.z;
477 } else {
479 z_tmp = mh_m->GetZ();
480 }
481 // h.z = z_tmp;
482
483 unsigned int k;
484 for (k = 0; k < vStsZPos_temp.size(); k++) {
485 if (vStsZPos_temp[k] == z_tmp) {
486 h.iz = k;
487 break;
488 }
489 }
490 if (k == vStsZPos_temp.size()) {
491 h.iz = vStsZPos_temp.size();
492 vStsZPos_temp.push_back(z_tmp);
493 }
494
495 // save hit
496 vStsHits.push_back(CbmL1StsHit(algo->vStsHits.size(), th.ExtIndex));
497 algo->vStsHits.push_back(h);
498
499#ifdef AZ
500 // AZ-240223 - save hit point
501 L1HitPoint hp(fscal(th.x), fscal(th.y), fscal(z_tmp), fscal(th.u_back), fscal(th.u_front), fscal(th.du_back),
502 fscal(th.du_front));
503 algo->vAllHitPoints.push_back(hp);
504#endif
505
506 int sta = th.iStation;
507 if (algo->StsHitsStartIndex[sta] == static_cast<THitI>(-1))
508 algo->StsHitsStartIndex[sta] = nEffHits;
509 nEffHits++;
510 algo->StsHitsStopIndex[sta] = nEffHits;
511
512 vHitStore.push_back(s);
513 vHitMCRef.push_back(th.iMC);
514 }
515 for (int i = 0; i < NStation; i++) {
516 if (algo->StsHitsStartIndex[i] == static_cast<THitI>(-1))
517 algo->StsHitsStartIndex[i] = algo->StsHitsStopIndex[i];
518 }
519
520 // if(0){ // check index z-pos befor sort
521 // for (int k = 0; k < algo->vStsHits.size(); k++){
522 // cout << algo->vStsHits[k].z << " " << vStsZPos_temp[algo->vStsHits[k].iz] << endl;
523 // }
524 // int kk; std::cin >> kk;
525 // }
526
527 if (fVerbose >= 10)
528 cout << "ReadEvent: mvd and sts are saved." << endl;
529
530 // sort z-pos
531 if (vStsZPos_temp.size() != 0) {
532 vector<float> vStsZPos_temp2;
533 vStsZPos_temp2.clear();
534 vStsZPos_temp2.push_back(vStsZPos_temp[0]);
535 vector<int> newToOldIndex;
536 newToOldIndex.clear();
537 newToOldIndex.push_back(0);
538
539 for (unsigned int k = 1; k < vStsZPos_temp.size(); k++) {
540 vector<float>::iterator itpos = vStsZPos_temp2.begin() + 1;
541 vector<int>::iterator iti = newToOldIndex.begin() + 1;
542 for (; itpos < vStsZPos_temp2.end(); itpos++, iti++) {
543 if (vStsZPos_temp[k] < *itpos) {
544 vStsZPos_temp2.insert(itpos, vStsZPos_temp[k]);
545 newToOldIndex.insert(iti, k);
546 break;
547 }
548 }
549 if (itpos == vStsZPos_temp2.end()) {
550 vStsZPos_temp2.push_back(vStsZPos_temp[k]);
551 newToOldIndex.push_back(k);
552 }
553 } // k
554
555 if (fVerbose >= 10)
556 cout << "ReadEvent: z-pos are sorted." << endl;
557
558 // save z-pos
559 for (unsigned int k = 0; k < vStsZPos_temp2.size(); k++)
560 algo->vStsZPos.push_back(vStsZPos_temp2[k]);
561 // correct index of z-pos in hits array
562 int size_nto_tmp = newToOldIndex.size();
563 vector<int> oldToNewIndex;
564 oldToNewIndex.clear();
565 oldToNewIndex.resize(size_nto_tmp);
566 for (int k = 0; k < size_nto_tmp; k++)
567 oldToNewIndex[newToOldIndex[k]] = k;
568
569 int size_hs_tmp = vHitStore.size();
570 for (int k = 0; k < size_hs_tmp; k++)
571 algo->vStsHits[k].iz = oldToNewIndex[algo->vStsHits[k].iz];
572
573 // // check index z-pos
574 // for (int k = 0; k < algo->vStsHits.size(); k++){
575 // fvec z1 = algo->vStsZPos[algo->vStsHits[k].iz];
576 // fvec z2 = algo->vStations[algo->vSFlag[algo->vStsHits[k].f]/4].z;
577 // if (fabs(z1[0] - z2[0]) > 1.0){
578 // cout << z1[0] << " " << z2[0] << endl;
579 // int kk;
580 // std::cin >> k;
581 // }
582 // }
583 }
584
585 if (fVerbose >= 10)
586 cout << "ReadEvent: z-pos are saved." << endl;
587
588 HitMatch();
589
590 if (fVerbose >= 10)
591 cout << "HitMatch is done." << endl;
592
593 // -- sort MC points --
594 vector<TmpMCPoint> vtmpMCPoints;
595 for (unsigned int iMCPoint = 0; iMCPoint < vMCPoints.size(); iMCPoint++) {
596 CbmL1MCPoint& MC = vMCPoints[iMCPoint];
597 TmpMCPoint tmp;
598 tmp.ID = MC.ID;
599 tmp.z = MC.z;
600 // tmp.StsHit = i;
601 tmp.MCPoint = iMCPoint;
602 tmp.eff = 1;
603 vtmpMCPoints.push_back(tmp);
604 }
605
606 // for ( unsigned int i=0; i<vUnEffHitStore.size(); i++ ){
607 // int iMC = vUnEffHitMCRef[i];
608 // if( iMC < 0 ) continue;
609 // CbmL1MCPoint &MC = vMCPoints[iMC];
610 // TmpMCPoint tmp;
611 // tmp.ID = MC.ID;
612 // tmp.z = MC.z;
613 // tmp.StsHit = i;
614 // tmp.MCPoint = &MC;
615 // tmp.eff = 0;
616 // vtmpMCPoints.push_back(tmp);
617 // }
618
619 sort(vtmpMCPoints.begin(), vtmpMCPoints.end(), TmpMCPoint::compareIDz);
620 if (fVerbose >= 10)
621 cout << "MCPoints are sorted." << endl;
622
623 // -- fill vMCTracks array --
624 PrimVtx.MC_ID = 999;
625 {
626 CbmL1Vtx Vtxcurr;
627 int nvtracks = 0, nvtrackscurr = 0;
628 int ID = -10000;
629 for (vector<TmpMCPoint>::iterator i = vtmpMCPoints.begin(); i != vtmpMCPoints.end(); ++i) {
630 if (vMCTracks.empty() || i->ID != ID) { // new track
631 ID = i->ID;
632 CbmL1MCTrack T;
633 T.ID = ID;
634 if (listMCTracks) {
636 int mother_ID = MCTrack->GetMotherId();
637 TVector3 vr;
639 MCTrack->GetStartVertex(vr);
640 MCTrack->Get4Momentum(vp);
641
642 T = CbmL1MCTrack(vMCPoints[i->MCPoint].mass, vMCPoints[i->MCPoint].q, vr, vp, i->ID, mother_ID,
643 vMCPoints[i->MCPoint].pdg);
644 }
645 vMCTracks.push_back(T);
646
647 if (T.mother_ID == -1) { // vertex track
648
649 if (PrimVtx.MC_ID == 999 || fabs(T.z - Vtxcurr.MC_z) > 1.e-7) { // new vertex
650 if (nvtrackscurr > nvtracks) {
651 PrimVtx = Vtxcurr;
652 nvtracks = nvtrackscurr;
653 }
654 Vtxcurr.MC_x = T.x;
655 Vtxcurr.MC_y = T.y;
656 Vtxcurr.MC_z = T.z;
657 Vtxcurr.MC_ID = T.mother_ID;
658 nvtrackscurr = 1;
659 } else
660 nvtrackscurr++;
661 }
662 } // new track
663 vMCTracks.back().Points.push_back(i->MCPoint);
664 // if( i->eff ) vMCTracks.back().StsHits.push_back(i->StsHit);
665 } // for i of tmpMCPoints
666 if (nvtrackscurr > nvtracks)
667 PrimVtx = Vtxcurr;
668 } // fill MC tracks
669 if (fVerbose >= 10)
670 cout << "MCPoints and MCTracks are saved." << endl;
671
672 // calculate the max number of Hits\mcPoints on continuous(consecutive) stations
673 for (vector<CbmL1MCTrack>::iterator it = vMCTracks.begin(); it != vMCTracks.end(); ++it) {
674 it->Init();
675 } // for i vMCTracks
676
677 if (fVerbose && PrimVtx.MC_ID == 999)
678 cout << "No primary vertex !!!" << endl;
679
680 if (fVerbose >= 10)
681 cout << "ReadEvent is done." << endl;
682} // void CbmL1::ReadEvent()
683
684bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, bool MVD)
685{
686 TVector3 xyzI, PI, xyzO, PO;
687 Int_t mcID = -1;
688 if (MVD && listMvdPts) {
690 if (!pt)
691 return 1;
692 pt->Position(xyzI);
693 pt->Momentum(PI);
694 pt->PositionOut(xyzO);
695 pt->MomentumOut(PO);
696 mcID = pt->GetTrackID();
697 } else if (listStsPts) {
699 if (!pt)
700 return 1;
701 pt->Position(xyzI);
702 pt->Momentum(PI);
703 pt->PositionOut(xyzO);
704 pt->MomentumOut(PO);
705 mcID = pt->GetTrackID();
706 }
707 TVector3 xyz = .5 * (xyzI + xyzO);
708 TVector3 P = .5 * (PI + PO);
709 MC->x = xyz.X();
710 MC->y = xyz.Y();
711 MC->z = xyz.Z();
712 MC->px = P.X();
713 MC->py = P.Y();
714 MC->pz = P.Z();
715 MC->xIn = xyzI.X();
716 MC->yIn = xyzI.Y();
717 MC->zIn = xyzI.Z();
718 MC->pxIn = PI.X();
719 MC->pyIn = PI.Y();
720 MC->pzIn = PI.Z();
721 MC->xOut = xyzO.X();
722 MC->yOut = xyzO.Y();
723 MC->zOut = xyzO.Z();
724 MC->pxOut = PO.X();
725 MC->pyOut = PO.Y();
726 MC->pzOut = PO.Z();
727 MC->p = sqrt(fabs(MC->px * MC->px + MC->py * MC->py + MC->pz * MC->pz));
728 MC->ID = mcID;
729 MC->pointId = iPoint;
730
732 if (!MCTrack)
733 return 1;
734 MC->pdg = MCTrack->GetPdgCode();
735 MC->mother_ID = MCTrack->GetMotherId();
736 if (abs(MC->pdg) >= 10000)
737 return 1;
738 MC->q = TDatabasePDG::Instance()->GetParticle(MC->pdg)->Charge() / 3.0;
740
741 return 0;
742}
743
744/// Procedure for match hits and MCPoints.
745/// Read information about correspondence between hits and mcpoints and fill CbmL1MCPoint::hitIds and
746/// CbmL1StsHit::mcPointIds arrays should be called after fill of algo
748{
749 const bool useLinks = 0; // 0 - use HitMatch, one_to_one; 1 - use FairLinks, many_to_many. Set 0 to switch to old
750 // definition of efficiency.
751 // TODO: fix trunk problem with links. Set useLinks = 1
752
753 const int NHits = vStsHits.size();
754 for (int iH = 0; iH < NHits; iH++) {
755 CbmL1StsHit& hit = vStsHits[iH];
756
757 const bool isMvd = (hit.extIndex < 0);
758 if (useLinks && !isMvd) {
759 if (listStsClusters) {
761 const int NLinks = stsHit->GetNLinks();
762 if (NLinks != 2)
763 cout << "HitMatch: Error. Hit wasn't matched with 2 clusters." << endl;
764 // see at 1-st cluster
765 vector<int> stsPointIds; // save here all mc-points matched with first cluster
766 int iL = 0;
767 FairLink link = stsHit->GetLink(iL);
768 CbmStsCluster* stsCluster = L1_DYNAMIC_CAST<CbmStsCluster*>(listStsClusters->At(link.GetIndex()));
769 int NLinks2 = stsCluster->GetNLinks();
770 for (int iL2 = 0; iL2 < NLinks2; iL2++) {
771 FairLink link2 = stsCluster->GetLink(iL2);
772 CbmStsDigi* stsDigi = L1_DYNAMIC_CAST<CbmStsDigi*>(listStsDigi->At(link2.GetIndex()));
773 const int NLinks3 = stsDigi->GetNLinks();
774 for (int iL3 = 0; iL3 < NLinks3; iL3++) {
775 FairLink link3 = stsDigi->GetLink(iL3);
776 int stsPointId = link3.GetIndex();
777 stsPointIds.push_back(stsPointId);
778 } // for mcPoint
779 } // for digi
780 // see at 2-nd cluster
781 iL = 1;
782 link = stsHit->GetLink(iL);
783 stsCluster = L1_DYNAMIC_CAST<CbmStsCluster*>(listStsClusters->At(link.GetIndex()));
784 NLinks2 = stsCluster->GetNLinks();
785 for (int iL2 = 0; iL2 < NLinks2; iL2++) {
786 FairLink link2 = stsCluster->GetLink(iL2);
787 CbmStsDigi* stsDigi = L1_DYNAMIC_CAST<CbmStsDigi*>(listStsDigi->At(link2.GetIndex()));
788 const int NLinks3 = stsDigi->GetNLinks();
789 for (int iL3 = 0; iL3 < NLinks3; iL3++) {
790 FairLink link3 = stsDigi->GetLink(iL3);
791 int stsPointId = link3.GetIndex();
792
793 if (!find(&(stsPointIds[0]), &(stsPointIds[stsPointIds.size()]), stsPointId))
794 continue; // check if first cluster matched with same mc-point
795
796 CbmStsPoint* stsPoint = L1_DYNAMIC_CAST<CbmStsPoint*>(listStsPts->At(stsPointId));
797
798 // find mcPoint in array
799 int mcTrackId = stsPoint->GetTrackID();
800 TVector3 xyzIn, xyzOut;
801 stsPoint->PositionIn(xyzIn);
802 stsPoint->PositionOut(xyzOut);
803 TVector3 xyz = .5 * (xyzIn + xyzOut);
804 double z = xyz.z();
805
806 const int NPoints = vMCPoints.size();
807 int iP;
808 for (iP = 0; iP < NPoints; iP++) {
809 if ((vMCPoints[iP].ID == mcTrackId) && (vMCPoints[iP].z == z))
810 break;
811 };
812
813 if (iP == NPoints) { // No mc-point was found in vMCPoints array.
814 CbmL1MCPoint MC;
815 if (!ReadMCPoint(&MC, stsPointId, 0)) {
816 MC.iStation = vHitStore[hit.hitId].iStation;
817 // algo->GetFStation(algo->vSFlag[algo->vStsHits[hit.hitId].f]);
818 vMCPoints.push_back(MC);
819 } else {
820 continue;
821 }
822 }
823 // check if the hit already matched with the mc-point and save it if this is not the case
824 if (!find(&(hit.mcPointIds[0]), &(hit.mcPointIds[hit.mcPointIds.size()]), iP)) {
825 hit.mcPointIds.push_back(iP);
826 vMCPoints[iP].hitIds.push_back(iH);
827 }
828
829 } // for mcPoint
830 } // for digi
831
832 } // if clusters
833 else
834 {
835 // CbmStsHit *stsHit = L1_DYNAMIC_CAST<CbmStsHit*>( listStsHits->At(hit.extIndex) );
836 // int iP = stsHit->GetRefIndex();
837 int iP = vHitMCRef[iH];
838 if (iP >= 0) {
839 hit.mcPointIds.push_back(iP);
840 vMCPoints[iP].hitIds.push_back(iH);
841 }
842 } // if no clusters
843 } // if useLinks
844 else
845 { // if no use Links or this is mvd hit
846 // int iP = -1; // TODO2
847 // if (isMvd) {
848 // // CbmMvdHitMatch *match = L1_DYNAMIC_CAST<CbmMvdHitMatch*>( listMvdHitMatches->At( -hit.extIndex - 1 )
849 // );
850 // // if( match){
851 // // iP = match->GetPointId();
852 // // }
853 // iP = vHitMCRef[iH];
854 // }
855 // else {
856 // CbmStsHit *stsHit = L1_DYNAMIC_CAST<CbmStsHit*>( listStsHits->At( hit.extIndex ) );
857 // iP = stsHit->GetRefIndex();
858 // }
859
860 int iP = vHitMCRef[iH];
861 if (iP >= 0) {
862 hit.mcPointIds.push_back(iP);
863 vMCPoints[iP].hitIds.push_back(iH);
864 }
865 }
866 if (hit.mcPointIds.size() > 1) { // CHECKME never works!
867 cout << "Hit number " << iH << " has been matched with " << hit.mcPointIds.size() << " mcPoints." << endl;
868 cout << "Hit number " << iH << " " << hit.mcPointIds[0] << " " << vHitMCRef[iH] << endl;
869 }
870 } // for hits
871}
#define L1_DYNAMIC_CAST
Definition CbmL1Def.h:26
unsigned int THitI
Definition L1StsHit.h:6
float fscal
Definition P4_F32vec4.h:232
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
int Int_t
Double_t z
static CbmKF * Instance()
Definition CbmKF.h:34
std::vector< CbmKFTube > vMvdMaterial
Definition CbmKF.h:59
double y
Definition CbmL1.h:44
int ExtIndex
Definition CbmL1.h:42
double x
Definition CbmL1.h:44
int iStation
Definition CbmL1.h:43
vector< int > mcPointIds
Definition CbmL1StsHit.h:22
void HitMatch()
Input Performance.
L1Algo * algo
Definition CbmL1.h:54
vector< CbmL1HitStore > vHitStore
Definition CbmL1.h:95
int NMvdStations
Definition CbmL1.h:143
CbmL1Vtx PrimVtx
Definition CbmL1.h:157
TClonesArray * listMCTracks
Input data.
Definition CbmL1.h:161
vector< CbmL1MCTrack > vMCTracks
Definition CbmL1.h:174
vector< CbmL1MCPoint > vMCPoints
hits with hit-mcpoint match information
Definition CbmL1.h:173
TClonesArray * listMvdHitMatches
Definition CbmL1.h:169
vector< CbmL1StsHit > vStsHits
Used data = Repacked input data.
Definition CbmL1.h:172
bool ReadMCPoint(CbmL1MCPoint *MC, int iPoint, bool MVD)
TClonesArray * listStsClusters
Definition CbmL1.h:164
TClonesArray * listMvdPts
Definition CbmL1.h:167
vector< CbmL1Track > vRTracks
Definition CbmL1.h:57
TClonesArray * listStsPts
Definition CbmL1.h:162
TClonesArray * listMvdHits
Mvd MC points.
Definition CbmL1.h:168
vector< int > vHitMCRef
Definition CbmL1.h:175
TClonesArray * listStsDigi
Sts MC points.
Definition CbmL1.h:163
void ReadEvent()
Read information about hits, mcPoints and mcTracks into L1 classes.
TClonesArray * listStsHits
Definition CbmL1.h:165
friend class CbmL1MCTrack
Definition CbmL1.h:103
int NStation
Definition CbmL1.h:143
int NStsStations
Definition CbmL1.h:143
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
void Get4Momentum(TLorentzVector &momentum) const
Definition CbmMCTrack.h:144
void GetStartVertex(TVector3 &vertex) const
Definition CbmMCTrack.h:149
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
CbmMvdHitMatch header file.
CbmMvdHit.h.
Definition CbmMvdHit.h:26
virtual Int_t GetStationNr() const
Definition CbmMvdHit.h:48
CbmMvdPoint.h.
Definition CbmMvdPoint.h:27
void MomentumOut(TVector3 &mom)
Definition CbmMvdPoint.h:75
void PositionOut(TVector3 &pos)
Definition CbmMvdPoint.h:74
CbmStsCluster.h.
CbmStsDigi.h.
Definition CbmStsDigi.h:32
virtual Int_t GetStationNr() const
Definition CbmStsHit.h:67
Double_t GetStrip(int side) const
Definition CbmStsHit.h:82
Int_t GetSectorNr() const
Definition CbmStsHit.h:68
Int_t GetDigi(Int_t iSide) const
void PositionOut(TVector3 &pos)
Definition CbmStsPoint.h:74
void MomentumOut(TVector3 &mom)
Definition CbmStsPoint.h:75
void PositionIn(TVector3 &pos)
Definition CbmStsPoint.h:73
L1UMeasurementInfo backInfo
Definition L1Station.h:30
L1UMeasurementInfo frontInfo
Definition L1Station.h:30
TZPosI iz
Definition L1StsHit.h:13
TStripI f
Definition L1StsHit.h:12
TStripI b
Definition L1StsHit.h:12
static TDatabasePDG * Instance()
TParticlePDG * GetParticle(const char *name) const
Double_t Charge() const
Double_t Mass() const
Double_t Z() const
Double_t Y() const
Double_t X() const
Double_t z() const
RVec< PromoteType< T > > abs(const RVec< T > &v)
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
int MC_ID
Definition CbmL1Vtx.h:45
double MC_z
Definition CbmL1Vtx.h:44
double MC_y
Definition CbmL1Vtx.h:44
double MC_x
Definition CbmL1Vtx.h:44
contain strips positions and coordinates of hit
Definition L1HitPoint.h:9
double strip1
double u_back
double du_back
double u_front
double du_front
double strip2
static bool Compare(const TmpHit &a, const TmpHit &b)
static bool compareIDz(const TmpMCPoint &a, const TmpMCPoint &b)