Newer
Older
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField);
float distance = helix.getDistanceToPoint(pos,dcut);
debug() << "AssignSiHitsToTracks : distance = " << distance << " cut = " << dcut << endmsg;
if (distance<dcut) {
TrackHitPair * trkHitPair =
new TrackHitPair(trkExt,trkHitExt,distance);
pairs.push_back(trkHitPair);
flagTrack[trkExt] = true;
flagHit[trkHitExt] = true;
}
}
}
}
int nPairs = int(pairs.size());
debug() << "AssignSiHitsToTracks : Number of track hit pairs to try = " << nPairs << endmsg;
if (nPairs>0) {
SortingTrackHitPairs(pairs);
for (int iP=0;iP<nPairs;++iP) {
TrackHitPair * trkHitPair = pairs[iP];
TrackExtended * trkExt = trkHitPair->getTrackExtended();
TrackerHitExtended * trkHitExt =
trkHitPair->getTrackerHitExtended();
if (flagTrack[trkExt] && flagHit[trkHitExt]) {
// get the hits already assigned to the track
TrackerHitExtendedVec hitsInTrack = trkExt->getTrackerHitExtendedVec();
int nTotH = int(hitsInTrack.size());
int nHitsInFit = 0;
for (int iTH=0;iTH<nTotH;++iTH) {
TrackerHitExtended * hitInTrack = hitsInTrack[iTH];
// count the number of hits used in the fit
if (hitInTrack->getUsedInFit()) {
nHitsInFit++;
}
}
int iHitInFit = 0;
// add the previously used hits from the track to the vectors
ConstTrackerHitVec trkHits;
for (int iHit=0;iHit<nTotH;++iHit) {
TrackerHitExtended * hitInTrack = hitsInTrack[iHit];
if (hitInTrack->getUsedInFit()) {
edm4hep::ConstTrackerHit hit = hitInTrack->getTrackerHit();
iHitInFit++;
if(hit.isAvailable()) {
trkHits.push_back(hit);
}
else{
throw EVENT::Exception( std::string("FullLDCTrackingAlg::AssignSiHitsToTracks: TrackerHit pointer == NULL ") ) ;
}
}
}
// add the hit to be attached to the vectors
edm4hep::ConstTrackerHit remainHit = trkHitExt->getTrackerHit();
iHitInFit++;
trkHits.push_back(remainHit);
double chi2_D;
int ndf;
if( trkHits.size() < 3 ) return ;
// sort the hits in R
std::vector< std::pair<float, edm4hep::ConstTrackerHit> > r2_values;
r2_values.reserve(trkHits.size());
for (ConstTrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) {
edm4hep::ConstTrackerHit h = *it;
float r2 = h.getPosition()[0]*h.getPosition()[0]+h.getPosition()[1]*h.getPosition()[1];
r2_values.push_back(std::make_pair(r2, *it));
}
sort(r2_values.begin(),r2_values.end());
trkHits.clear();
trkHits.reserve(r2_values.size());
for (std::vector< std::pair<float, edm4hep::ConstTrackerHit> >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) {
trkHits.push_back(it->second);
}
debug() << "AssignSiHitsToTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << endmsg;
MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack();
TrackState pre_fit ;
pre_fit.D0 = trkExt->getD0();
pre_fit.phi = trkExt->getPhi();
pre_fit.Z0 = trkExt->getZ0();
pre_fit.omega = trkExt->getOmega();
pre_fit.tanLambda = trkExt->getTanLambda();
float ref[3];
ref[0]=ref[1]=ref[2]=0.0;
pre_fit.referencePoint = ref;
pre_fit.location = 1/*lcio::TrackState::AtIP*/;
// setup initial dummy covariance matrix
std::array<float,15> covMatrix;
for (unsigned icov = 0; icov<covMatrix.size(); ++icov) {
covMatrix[icov] = 0;
}
covMatrix[0] = ( _initialTrackError_d0 ); //sigma_d0^2
covMatrix[2] = ( _initialTrackError_phi0 ); //sigma_phi0^2
covMatrix[5] = ( _initialTrackError_omega ); //sigma_omega^2
covMatrix[9] = ( _initialTrackError_z0 ); //sigma_z0^2
covMatrix[14] = ( _initialTrackError_tanL ); //sigma_tanl^2
pre_fit.covMatrix = covMatrix;
int error = MarlinTrk::createFit( trkHits, marlin_trk, &pre_fit, _bField, IMarlinTrack::backward , _maxChi2PerHit );
if ( error != IMarlinTrack::success ) {
debug() << "FullLDCTrackingAlg::AssignSiHitsToTracks: creation of fit fails with error " << error << endmsg;
delete marlin_trk ;
continue ;
}
std::vector<std::pair<edm4hep::ConstTrackerHit , double> > outliers ;
marlin_trk->getOutliers(outliers);
float outlier_pct = outliers.size()/float(trkHits.size());
debug()<< "FullLDCTrackingAlg::AssignSiHitsToTracks: percentage of outliers " << outlier_pct << endmsg;
if ( outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) {
debug() << "FullLDCTrackingAlg::AssignSiHitsToTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << _maxAllowedPercentageOfOutliersForTrackCombination << endmsg;
delete marlin_trk ;
continue ;
}
edm4hep::Vector3d point(0.,0.,0.); // nominal IP
int return_code = 0;
TrackState trkState ;
return_code = marlin_trk->propagate(point, trkState, chi2_D, ndf ) ;
delete marlin_trk ;
if ( error != IMarlinTrack::success ) {
debug() << "FullLDCTrackingAlg::AssignSiHitsToTracks: propagate to IP fails with error " << error << endmsg;
continue ;
}
if ( ndf < 0 ) {
debug() << "FullLDCTrackingAlg::AssignSiHitsToTracks: Fit failed : NDF is less that zero " << ndf << endmsg;
continue ;
}
float chi2Fit = chi2_D/float(ndf);
if ( chi2Fit > _chi2FitCut ) {
debug() << "FullLDCTrackingAlg::AssignSiHitsToTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << endmsg;
continue ;
}
// note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0
trkExt->setOmega(trkState.omega);
trkExt->setTanLambda(trkState.tanLambda);
trkExt->setPhi(trkState.phi);
trkExt->setD0(trkState.D0);
trkExt->setZ0(trkState.Z0);
float cov[15];
for (int i = 0 ; i<15 ; ++i) {
cov[i] = trkState.covMatrix[i];
}
trkExt->setCovMatrix(cov);
trkExt->setChi2(chi2_D);
trkExt->setNDF(ndf);
trkExt->addTrackerHitExtended( trkHitExt );
trkHitExt->setTrackExtended( trkExt );
trkHitExt->setUsedInFit( true );
flagTrack[trkExt] = false;
flagHit[trkHitExt] = false;
debug() << "AssignSiHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " << trkExt << endmsg;
}
}
for (int iP=0;iP<nPairs;++iP) {
TrackHitPair * trkHitPair = pairs[iP];
delete trkHitPair;
}
pairs.clear();
}
}
/*
void FullLDCTrackingAlg::PrintOutMerging(TrackExtended * firstTrackExt, TrackExtended * secondTrackExt, int iopt) {
// iopt = 1 merged Si and TPC merging
// iopt = 2 merged Si and TPC using forced merging
// iopt = 3 merged TPC segments merging
// iopt = 4 merged Comb Si and TPC merging
// iopt = 5 merged Comb TPC and TPC merging
// iopt = 6 unmerged TPC and Si segments ( when using soft merging)
// iopt = 7 unmerged TPC and Si segments ( when using forced merging)
// iopt = 8 unmerged Comb and TPC
// iopt = 9 unmerged TPC segments
char strg[200];
try {
Track * firstTrack = firstTrackExt->getTrack();
Track * secondTrack = secondTrackExt->getTrack();
std::string firstColName = _TPCTrackMCPCollName;
std::string secondColName = _TPCTrackMCPCollName;
if (iopt==1) {
secondColName = _SiTrackMCPCollName;
}
else if (iopt==2) {
secondColName = _SiTrackMCPCollName;
}
else if (iopt==3) {
secondColName = _TPCTrackMCPCollName;
}
else if (iopt==4) {
secondColName = _SiTrackMCPCollName;
}
else if (iopt==5) {
secondColName = _TPCTrackMCPCollName;
}
else if (iopt==6) {
secondColName = _SiTrackMCPCollName;
}
else if (iopt==7) {
secondColName = _SiTrackMCPCollName;
}
else if (iopt==8) {
secondColName = _SiTrackMCPCollName;
}
else {
secondColName = _TPCTrackMCPCollName;
}
// get the relation collections, this should be done only once for each event ...
LCCollection * firstCol = _evt->getCollection(firstColName.c_str());
LCCollection * secondCol = _evt->getCollection(secondColName.c_str());
// get navigators
LCRelationNavigator firstNav(firstCol);
LCRelationNavigator secondNav(secondCol);
// get the MCParticles with the greatest weight for the first track
LCObjectVec firstVec = firstNav.getRelatedToObjects(firstTrack);
FloatVec firstWeights = firstNav.getRelatedToWeights(firstTrack);
LCObject * firstMCP = NULL;
float firstWght = 0;
int nObj = firstVec.size();
for (int iObj=0;iObj<nObj;++iObj) {
if (firstWeights[iObj]>firstWght) {
firstWght = firstWeights[iObj];
firstMCP = firstVec[iObj];
}
}
// get the MCParticles with the greatest weight for the second track
LCObjectVec secondVec = secondNav.getRelatedToObjects(secondTrack);
FloatVec secondWeights = secondNav.getRelatedToWeights(secondTrack);
LCObject * secondMCP = NULL;
float secondWght = 0;
nObj = secondVec.size();
for (int iObj=0;iObj<nObj;++iObj) {
if (secondWeights[iObj]>secondWght) {
secondWght = secondWeights[iObj];
secondMCP = secondVec[iObj];
}
}
// get the track parameters for both tracks and get the 3-momentum using the HelixClass
float d0First = firstTrackExt->getD0();
float z0First = firstTrackExt->getZ0();
float omegaFirst = firstTrackExt->getOmega();
float tanLFirst = firstTrackExt->getTanLambda();
float phi0First = firstTrackExt->getPhi();
float d0Second = secondTrackExt->getD0();
float z0Second = secondTrackExt->getZ0();
float omegaSecond = secondTrackExt->getOmega();
float tanLSecond = secondTrackExt->getTanLambda();
float phi0Second = secondTrackExt->getPhi();
HelixClass firstHelix;
firstHelix.Initialize_Canonical(phi0First,d0First,z0First,omegaFirst,tanLFirst,_bField);
float pxFirst = firstHelix.getMomentum()[0];
float pyFirst = firstHelix.getMomentum()[1];
float pzFirst = firstHelix.getMomentum()[2];
HelixClass secondHelix;
secondHelix.Initialize_Canonical(phi0Second,d0Second,z0Second,omegaSecond,tanLSecond,_bField);
float pxSecond = secondHelix.getMomentum()[0];
float pySecond = secondHelix.getMomentum()[1];
float pzSecond = secondHelix.getMomentum()[2];
// get the momentum differences
float dPx = pxFirst + pxSecond;
float dPy = pyFirst + pySecond;
float dPz = pzFirst + pzSecond;
float dPplus = sqrt(dPx*dPx+dPy*dPy+dPz*dPz);
dPx = pxFirst - pxSecond;
dPy = pyFirst - pySecond;
dPz = pzFirst - pzSecond;
float dPminus = sqrt(dPx*dPx+dPy*dPy+dPz*dPz);
// get momentum for each track
float pFirst = sqrt(pxFirst * pxFirst+ pyFirst* pyFirst+ pzFirst*pzFirst);
float pSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond+pzSecond*pzSecond);
float ptFirst = sqrt(pxFirst * pxFirst+ pyFirst* pyFirst);
float ptSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond);
const float sigmaPOverPFirst = sqrt( firstTrackExt->getCovMatrix()[5])/fabs(omegaFirst);
const float sigmaPOverPSecond = sqrt(secondTrackExt->getCovMatrix()[5])/fabs(omegaSecond);
const float sigmaPFirst = pFirst*sigmaPOverPFirst;
const float sigmaPSecond = pSecond*sigmaPOverPSecond;
float den = pFirst;
if (pSecond<pFirst)
den = pSecond;
dPplus = dPplus/den;
dPminus = dPminus/den;
// now check if this was a Erroneous merger ...
if (firstMCP!=secondMCP && iopt < 6) {
if (iopt==1) {
streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=1) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
else if (iopt==2) {
streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
else if (iopt==3) {
streamlog_out(DEBUG4) << "Erroneous merging of TPC segments (iopt=3) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << endmsg;
}
else if (iopt==4) {
streamlog_out(DEBUG4) << "Erroneous merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << endmsg;
}
else {
streamlog_out(DEBUG4) << "Erroneous merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << endmsg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",firstWght);
streamlog_out(DEBUG4) << strg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",secondWght);
streamlog_out(DEBUG4) << strg;
streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << endmsg;
TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true);
if(combinedTrack != NULL){
streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << endmsg;
delete combinedTrack->getGroupTracks();
delete combinedTrack;
}else{
streamlog_out(DEBUG4) << "Could not combine track " << endmsg;
}
streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << endmsg;
streamlog_out(DEBUG4) << endmsg;
}
// ... or if it was an incorrect TPC to TPC rejection ...
else if (firstMCP==secondMCP && ( (iopt==8) || (iopt==9) ) ) {
float deltaOmega = _dOmegaForMerging;
float deltaAngle = _angleForMerging;
if (iopt==8) {
streamlog_out(DEBUG4) << "Unmerged TPC and Comb segments (iopt=8) --->" << endmsg;
}
else {
streamlog_out(DEBUG4) << "Unmerged TPC segments (iopt=9) --->" << endmsg;
}
float qFirst = PIOVER2 - atan(tanLFirst);
float qSecond = PIOVER2 - atan(tanLSecond);
float dOmega = fabs((omegaFirst-omegaSecond)/omegaSecond);
float angle = (cos(phi0First)*cos(phi0Second)+sin(phi0First)*sin(phi0Second))*
sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond);
angle = acos(angle);
streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega
<< " AngleCut = " << deltaAngle
<< " dOmega = " << dOmega
<< " angle = " << angle << endmsg;
streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << endmsg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",firstWght);
streamlog_out(DEBUG4) << strg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",secondWght);
streamlog_out(DEBUG4) << strg;
streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << endmsg;
TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true);
if(combinedTrack != NULL){
streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << endmsg;
delete combinedTrack->getGroupTracks();
delete combinedTrack;
}else{
streamlog_out(DEBUG4) << "Could not combine track " << endmsg;
}
streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << endmsg;
streamlog_out(DEBUG4) << endmsg;
}
// ... or if it was an incorrect TPC to Si rejection ...
else if (firstMCP==secondMCP && ( (iopt == 6) || (iopt == 7) ) ) {
float deltaOmega = _dOmegaForMerging;
float deltaAngle = _angleForMerging;
if (iopt ==6) {
streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=6) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
else {
streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=7) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
deltaOmega = _dOmegaForForcedMerging;
deltaAngle = _angleForForcedMerging;
}
float qFirst = PIOVER2 - atan(tanLFirst);
float qSecond = PIOVER2 - atan(tanLSecond);
float dOmega = fabs((omegaFirst-omegaSecond)/omegaSecond);
float angle = (cos(phi0First)*cos(phi0Second)+sin(phi0First)*sin(phi0Second))*
sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond);
angle = acos(angle);
streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega
<< " AngleCut = " << deltaAngle
<< " dOmega = " << dOmega
<< " angle = " << angle << endmsg;
streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << endmsg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",firstWght);
streamlog_out(DEBUG4) << strg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",secondWght);
streamlog_out(DEBUG4) << strg;
streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << endmsg;
TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true);
if(combinedTrack != NULL){
streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << endmsg;
delete combinedTrack->getGroupTracks();
delete combinedTrack;
}else{
streamlog_out(DEBUG4) << "Could not combine track " << endmsg;
}
streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << endmsg;
streamlog_out(DEBUG4) << endmsg;
}
// ... or if it was an correct merger ...
else if (firstMCP==secondMCP && iopt < 6 && _debug > 3) {
// return;
if (iopt==1) {
streamlog_out(DEBUG4) << "Correctly combining Si and TPC segments (iopt=1) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
else if (iopt==2) {
streamlog_out(DEBUG4) << "Correctly merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
else if (iopt==3) {
streamlog_out(DEBUG4) << "Correctly merging of TPC segments (iopt=3) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << endmsg;
}
else if (iopt==4) {
streamlog_out(DEBUG4) << "Correctly merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << endmsg;
}
else {
streamlog_out(DEBUG4) << "Correctly merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << endmsg;
}
streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << endmsg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",firstWght);
streamlog_out(DEBUG4) << strg;
sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ",
pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond);
streamlog_out(DEBUG4) << strg;
sprintf(strg," %5.3f\n",secondWght);
streamlog_out(DEBUG4) << strg;
streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << endmsg;
TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true);
if(combinedTrack != NULL){
streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << endmsg;
}else{
streamlog_out(DEBUG4) << "Could not combine track " << endmsg;
}
delete combinedTrack->getGroupTracks();
delete combinedTrack;
streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << endmsg;
streamlog_out(DEBUG4) << endmsg;
}
}
catch( ... ){};
}
*/
/*
void FullLDCTrackingAlg::GeneralSorting(int * index, float * val, int direct, int nVal) {
// Sorting of index vector in ascending (0) /descending (!=0) order of val
float valOne, valTwo, valTemp;
int indTemp;
for (int i=0; i<nVal; ++i) {
index[i] = i;
}
for (int i = 0 ; i < nVal-1; i++) {
for (int j = 0; j < nVal-i-1; j++) {
valOne = val[j];
valTwo = val[j+1];
bool order = valOne > valTwo;
if (direct>0)
order = valOne <= valTwo;
if( order )
{
valTemp = val[j];
val[j] = val[j+1];
val[j+1] = valTemp;
indTemp = index[j];
index[j] = index[j+1];
index[j+1] = indTemp;
}
}
}
}
*/
int FullLDCTrackingAlg::SegmentRadialOverlap(TrackExtended* first, TrackExtended* second){
int nTrkGrpFirst = 0;
int nTrkGrpSecond = 0;
ConstTrackerHitVec hitvecFirst;
ConstTrackerHitVec hitvecSecond;
GroupTracks * groupFirst = first->getGroupTracks();
GroupTracks * groupSecond = second->getGroupTracks();
if(groupFirst!=NULL){
TrackExtendedVec tracksInGroupFirst = groupFirst->getTrackExtendedVec();
nTrkGrpFirst = int(tracksInGroupFirst.size());
for (int iTrkGrp=0;iTrkGrp<nTrkGrpFirst;++iTrkGrp) {
TrackExtended * trkGrp = tracksInGroupFirst[iTrkGrp];
TrackerHitExtendedVec hitVec = trkGrp->getTrackerHitExtendedVec();
for(unsigned int i =0; i<hitVec.size(); ++i){
hitvecFirst.push_back(hitVec[i]->getTrackerHit());
}
}
}
if(groupSecond!=NULL){
TrackExtendedVec tracksInGroupSecond = groupSecond->getTrackExtendedVec();
nTrkGrpSecond = int(tracksInGroupSecond.size());
for (int iTrkGrp=0;iTrkGrp<nTrkGrpSecond;++iTrkGrp) {
TrackExtended * trkGrp = tracksInGroupSecond[iTrkGrp];
TrackerHitExtendedVec hitVec =
trkGrp->getTrackerHitExtendedVec();
for(unsigned int i=0;i<hitVec.size();++i){
hitvecSecond.push_back(hitVec[i]->getTrackerHit());
}
}
}
int nhitsFirst = (int)hitvecFirst.size();
int nhitsSecond = (int)hitvecSecond.size();
int count = 0;
for(int i =0;i<nhitsFirst;++i){
float xi = (float)hitvecFirst[i].getPosition()[0];
float yi = (float)hitvecFirst[i].getPosition()[1];
float ri = sqrt(xi*xi+yi*yi);
if(ri < _tpc_inner_r || ri > _tpc_pad_height)continue;
for(int j =0;j<nhitsSecond;++j){
float xj = (float)hitvecSecond[j].getPosition()[0];
float yj = (float)hitvecSecond[j].getPosition()[1];
float rj = sqrt(xj*xj+yj*yj);
if(fabs(ri-rj)<_tpc_pad_height/2.0)count++;
}
}
return count;
}
/*
veto merger if the momentum of either track is less than 2.5 GeV
or if following a full fit the NDF+10 of the combined tracks is less than the NDF_first + NDF_second
NOTE: This function will try a full fit using CombineTracks if the momentum of both tracks is greater than VetoMergeMomentumCut
*/
bool FullLDCTrackingAlg::VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt){
debug() << "FullLDCTrackingAlg::VetoMerge called for " << firstTrackExt << " and " << secondTrackExt << endmsg;
const float d0First = firstTrackExt->getD0();
const float z0First = firstTrackExt->getZ0();
const float omegaFirst = firstTrackExt->getOmega();
const float tanLFirst = firstTrackExt->getTanLambda();
const float phi0First = firstTrackExt->getPhi();
const float d0Second = secondTrackExt->getD0();
const float z0Second = secondTrackExt->getZ0();
const float omegaSecond = secondTrackExt->getOmega();
const float tanLSecond = secondTrackExt->getTanLambda();
const float phi0Second = secondTrackExt->getPhi();
HelixClass firstHelix;
firstHelix.Initialize_Canonical(phi0First,d0First,z0First,omegaFirst,tanLFirst,_bField);
const float pxFirst = firstHelix.getMomentum()[0];
const float pyFirst = firstHelix.getMomentum()[1];
const float pzFirst = firstHelix.getMomentum()[2];
HelixClass secondHelix;
secondHelix.Initialize_Canonical(phi0Second,d0Second,z0Second,omegaSecond,tanLSecond,_bField);
const float pxSecond = secondHelix.getMomentum()[0];
const float pySecond = secondHelix.getMomentum()[1];
const float pzSecond = secondHelix.getMomentum()[2];
const float pFirst = sqrt(pxFirst*pxFirst+pyFirst*pyFirst+pzFirst*pzFirst);
const float pSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond+pzSecond*pzSecond);
if(pFirst<_vetoMergeMomentumCut || pSecond<_vetoMergeMomentumCut) {
debug() << "FullLDCTrackingAlg::VetoMerge do not veto as below momentum cut of 2.5 : pFirst = " << pFirst << " pSecond = " << pSecond << endmsg;
return false;
}
bool veto = false;
bool testCombinationOnly=true;
TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt,_maxAllowedPercentageOfOutliersForTrackCombination,testCombinationOnly);
if(combinedTrack!=NULL){
//SJA:FIXME hardcoded cut: here the check is that no more than 7 hits have been rejected in the combined fit.
if( combinedTrack->getNDF()+15 < firstTrackExt->getNDF() + secondTrackExt->getNDF()+5 ) {
debug() << "FullLDCTrackingAlg::VetoMerge fails NDF cut " << endmsg;
veto=true ;
}
delete combinedTrack->getGroupTracks();
delete combinedTrack;
}
else {
debug() << "FullLDCTrackingAlg::VetoMerge fails CombineTracks(firstTrackExt,secondTrackExt,true) test" << endmsg;
veto = true;
}
if(SegmentRadialOverlap(firstTrackExt,secondTrackExt)>10) {
debug() << "FullLDCTrackingAlg::VetoMerge fails SegmentRadialOverlap test " << endmsg;
veto=true;
}
return veto;
}
StatusCode FullLDCTrackingAlg::finalize() {
delete _encoder ;
return StatusCode::SUCCESS;
}
void FullLDCTrackingAlg::setupGearGeom(){
auto _gear = service<IGearSvc>("GearSvc");
gearMgr = _gear->getGearMgr();
_bField = gearMgr->getBField().at( gear::Vector3D( 0.,0.,0.) ).z() ;
//-- VXD Parameters--
_nLayersVTX = 0 ;
const gear::VXDParameters* pVXDDetMain = 0;
const gear::VXDLayerLayout* pVXDLayerLayout = 0;
try{
debug() << " filling VXD parameters from gear::SITParameters " << endmsg;
pVXDDetMain = &(gearMgr->getVXDParameters());
pVXDLayerLayout = &(pVXDDetMain->getVXDLayerLayout());
_nLayersVTX = pVXDLayerLayout->getNLayers();
}
catch( ... ){
debug() << " ### gear::VXDParameters Not Present in GEAR FILE" << endmsg;
}
//-- SIT Parameters--
_nLayersSIT = 0 ;
const gear::ZPlanarParameters* pSITDetMain = 0;
const gear::ZPlanarLayerLayout* pSITLayerLayout = 0;
try{
debug() << " filling SIT parameters from gear::SITParameters " << endmsg;
pSITDetMain = &(gearMgr->getSITParameters());
pSITLayerLayout = &(pSITDetMain->getZPlanarLayerLayout());
_nLayersSIT = pSITLayerLayout->getNLayers();
}
catch( ... ){
debug() << " ### gear::SITParameters Not Present in GEAR FILE" << endmsg;
}
if( _nLayersSIT == 0 ){
// try the old LOI style key value pairs as defined in the SSit03 Mokka drive
try{
debug() << " FullLDCTrackingAlg - Simple Cylinder Based SIT using parameters defined by SSit03 Mokka driver " << endmsg;
// SIT
const gear::GearParameters& pSIT = gearMgr->getGearParameters("SIT");
const EVENT::DoubleVec& SIT_r = pSIT.getDoubleVals("SITLayerRadius" ) ;
const EVENT::DoubleVec& SIT_hl = pSIT.getDoubleVals("SITSupportLayerHalfLength" ) ;
_nLayersSIT = SIT_r.size() ;
if (_nLayersSIT != SIT_r.size() || _nLayersSIT != SIT_hl.size()) {
fatal() << "FullLDCTrackingAlg Miss-match between DoubleVec and nlayers exit(1) called from file " << __FILE__ << " line " << __LINE__ << endmsg;
exit(1);
}
}
catch( ... ){
debug() << " ### gear::SIT Parameters from as defined in SSit03 Not Present in GEAR FILE" << endmsg;
}
}
//-- SET Parameters--
_nLayersSET = 0 ;
const gear::ZPlanarParameters* pSETDetMain = 0;
const gear::ZPlanarLayerLayout* pSETLayerLayout = 0;
try{
debug() << " filling SET parameters from gear::SETParameters " << endmsg;
pSETDetMain = &(gearMgr->getSETParameters());
pSETLayerLayout = &(pSETDetMain->getZPlanarLayerLayout());
_nLayersSET = pSETLayerLayout->getNLayers();
}
catch( ... ){
debug() << " ### gear::SETParameters Not Present in GEAR FILE" << endmsg;
}
if( _nLayersSET == 0 ){
// try the old LOI style key value pairs as defined in the SSet02 Mokka drive
try{
debug() << " FullLDCTrackingAlg - Simple Cylinder Based SET using parameters defined by SSet02 Mokka driver " << endmsg;
// SET
const gear::GearParameters& pSET = gearMgr->getGearParameters("SET");
const EVENT::DoubleVec& SET_r = pSET.getDoubleVals("SETLayerRadius" ) ;
const EVENT::DoubleVec& SET_hl = pSET.getDoubleVals("SETSupportLayerHalfLength" ) ;
_nLayersSET = SET_r.size() ;
if (_nLayersSET != SET_r.size() || _nLayersSET != SET_hl.size()) {
fatal() << "FullLDCTrackingAlg Miss-match between DoubleVec and nlayers exit(1) called from file " << __FILE__ << " line " << __LINE__ << endmsg;
exit(1);
}
}
catch( ... ){
debug() << " ### gear::SET Parameters from as defined in SSet02 Not Present in GEAR FILE" << endmsg;
}
}
//-- FTD Parameters--
_petalBasedFTDWithOverlaps = false;
_nLayersFTD = 0;
try{
debug() << " filling FTD parameters from gear::FTDParameters " << endmsg;
const gear::FTDParameters& pFTD =gearMgr->getFTDParameters();
const gear::FTDLayerLayout& ftdlayers = pFTD.getFTDLayerLayout() ;
_nLayersFTD = ftdlayers.getNLayers() ;
for (unsigned int disk=0; disk < _nLayersFTD; ++disk) {
_zLayerFTD.push_back( ftdlayers.getSensitiveZposition(disk, 0, 1) ); // front petal even numbered
if ( ftdlayers.getNPetals(disk) > 0) {
_zLayerFTD.push_back( ftdlayers.getSensitiveZposition(disk, 1, 1) ); // front petal odd numbered
_petalBasedFTDWithOverlaps = true;
}
}
// SJA: Here we increase the size of _nlayersFTD as we are treating the
_nLayersFTD =_zLayerFTD.size() ;
}
catch( ... ){
debug() << " ### gear::FTDParameters Not Present in GEAR FILE" << endmsg;
}
if( _nLayersFTD == 0 ){
// FTD
try{
debug() << " FullLDCTrackingAlg - Simple Disc Based FTD using parameters defined by SFtd05 Mokka driver " << endmsg;
const gear::GearParameters& pFTD = gearMgr->getGearParameters("FTD");
const EVENT::DoubleVec* pFTD_z = NULL;
pFTD_z = &pFTD.getDoubleVals("FTDZCoordinate" ) ;
_nLayersFTD = pFTD_z->size();
for (unsigned int i = 0; i<_nLayersFTD; ++i) {
_zLayerFTD.push_back((*pFTD_z)[i]);
}
}
catch( ... ){
debug() << " ### gear::FTD Parameters as defined in SFtd05 Not Present in GEAR FILE" << endmsg;
}
}
}