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