-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathController.cxx
More file actions
2207 lines (2116 loc) · 70.2 KB
/
Controller.cxx
File metadata and controls
2207 lines (2116 loc) · 70.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file Controller.h
/// @author ruben.shahoyan@cern.ch, michael.lettrich@cern.ch
/// @since 2021-02-01
/// @brief Steering class for the global alignment
#include "Align/Controller.h"
#include "Align/AlignConfig.h"
#include "Framework/Logger.h"
#include "Align/utils.h"
#include "Align/AlignmentPoint.h"
#include "Align/AlignableDetector.h"
#include "Align/AlignableVolume.h"
#include "Align/AlignableDetectorITS.h"
//#include "Align/AlignableDetectorTPC.h"
//#include "Align/AlignableDetectorTRD.h"
//#include "Align/AlignableDetectorTOF.h"
#include "Align/EventVertex.h"
#include "Align/ResidualsControllerFast.h"
#include "Align/GeometricalConstraint.h"
#include "Align/DOFStatistics.h"
//#include "AliTrackerBase.h"
//#include "AliESDCosmicTrack.h"
//#include "AliESDtrack.h"
//#include "AliESDEvent.h"
//#include "AliESDVertex.h"
//#include "AliRecoParam.h"
//#include "AliCDBRunRange.h"
//#include "AliCDBManager.h"
//#include "AliCDBEntry.h"
#include "MathUtils/Utils.h"
#include <TMath.h>
#include <TString.h>
#include <TROOT.h>
#include <TSystem.h>
#include <TRandom.h>
#include <TH1F.h>
#include <TList.h>
#include <cstdio>
#include <TGeoGlobalMagField.h>
#include "CommonUtils/NameConf.h"
#include "DataFormatsParameters/GRPObject.h"
using namespace TMath;
using namespace o2::align::utils;
using namespace o2::dataformats;
using namespace o2::globaltracking;
using std::ifstream;
namespace o2
{
namespace align
{
void Controller::ProcStat::print() const
{
// TODO RS
// const Char_t* Controller::sStatClName[Controller::kNStatCl] = {"Inp: ", "Acc: "};
// const Char_t* Controller::sStatName[Controller::kMaxStat] =
// {"runs", "Ev.Coll", "Ev.Cosm", "Trc.Coll", "Trc.Cosm"};
}
const Char_t* Controller::sMPDataExt = ".mille";
const Char_t* Controller::sDetectorName[Controller::kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "HMPID"}; //RSREM
//const int Controller::mgkSkipLayers[Controller::kNLrSkip] = {AliGeomManager::kPHOS1, AliGeomManager::kPHOS2,
// AliGeomManager::kMUON, AliGeomManager::kEMCAL}; TODO(milettri, shahoian): needs detector IDs previously stored in AliGeomManager
const int Controller::sSkipLayers[Controller::kNLrSkip] = {0, 0, 0, 0}; // TODO(milettri, shahoian): needs AliGeomManager - remove this line after fix.
const Char_t* Controller::sHStatName[Controller::kNHVars] = {
"Runs", "Ev.Inp", "Ev.VtxOK", "Tr.Inp", "Tr.2Fit", "Tr.2FitVC", "Tr.2PrMat", "Tr.2ResDer", "Tr.Stored", "Tr.Acc", "Tr.ContRes"};
//________________________________________________________________
Controller::Controller(DetID::mask_t detmask)
: mDetMask(detmask)
{
// def c-tor
// SetOutCDBRunRange(); FIXME(milettri): needs OCDB
init();
// run config macro if provided
if (!getInitDOFsDone()) {
initDOFs();
}
if (!getNDOFs()) {
LOG(fatal) << "No DOFs found, initialization failed";
}
}
//________________________________________________________________
Controller::~Controller()
{
// d-tor
if (mMPRecFile) {
closeMPRecOutput();
}
if (mMille) {
closeMilleOutput();
}
if (mResidFile) {
closeResidOutput();
}
//
for (int i = 0; i < DetID::nDetectors; i++) {
delete mDetectors[i];
}
delete mHistoStat;
//
}
//________________________________________________________________
void Controller::init()
{
if (mDetMask[DetID::ITS]) {
addDetector(new AlignableDetectorITS(this));
}
mVtxSens = std::make_unique<EventVertex>(this);
}
//________________________________________________________________
void Controller::process(const RecoContainer& recodata)
{
/*
auto creator = [](auto& _tr, GTrackID _origID, float t0, float terr) {
if (!_origID.includesDet(DetID::ITS)) {
return true; // just in case this selection was not done on RecoContainer filling level
}
if constexpr (isITSTrack<decltype(_tr)>()) {
t0 += halfROFITS; // ITS time is supplied in \mus as beginning of ROF
terr *= hw2ErrITS; // error is supplied as a half-ROF duration, convert to \mus
}
// for all other tracks the time is in \mus with gaussian error
if constexpr (std::is_base_of_v<o2::track::TrackParCov, std::decay_t<decltype(_tr)>>) {
if (terr < maxTrackTimeError) {
tracks.emplace_back(TrackWithTimeStamp{_tr, {t0, terr}});
gids.emplace_back(_origID);
}
}
return true;
};
recoData.createTracksVariadic(creator); // create track sample considered for vertexing
*/
}
//________________________________________________________________
void Controller::initDetectors()
{
// init all detectors geometry
//
if (getInitGeomDone()) {
return;
}
//
//
mAlgTrack = std::make_unique<AlignmentTrack>();
mRefPoint = std::make_unique<AlignmentPoint>();
//
int dofCnt = 0;
// special fake sensor for vertex constraint point
// it has special T2L matrix adjusted for each track, no need to init it here
mVtxSens = std::make_unique<EventVertex>(this);
mVtxSens->setInternalID(1);
mVtxSens->prepareMatrixL2G();
mVtxSens->prepareMatrixL2GIdeal();
dofCnt += mVtxSens->getNDOFs();
//
for (auto id = DetID::First; id <= DetID::Last; id++) {
auto* det = getDetector(id);
if (det) {
dofCnt += det->initGeom();
}
}
if (!dofCnt) {
LOG(fatal) << "No DOFs found";
}
//
//
for (auto id = DetID::First; id <= DetID::Last; id++) {
auto* det = getDetector(id);
if (!det || det->isDisabled()) {
continue;
}
det->cacheReferenceOCDB();
}
//
assignDOFs();
LOG(info) << "Booked " << dofCnt << " global parameters";
//
setInitGeomDone();
//
}
//________________________________________________________________
void Controller::initDOFs()
{
// scan all free global parameters, link detectors to array of params
//
if (getInitDOFsDone()) {
LOG(info) << "initDOFs was already done, just reassigning " << getNDOFs() << "DOFs arrays/labels";
assignDOFs();
return;
}
const auto& conf = AlignConfig::Instance();
mNDOFs = 0;
int ndfAct = 0;
assignDOFs();
int nact = 0;
mVtxSens->initDOFs();
for (auto id = DetID::First; id <= DetID::Last; id++) {
AlignableDetector* det = getDetector(id);
if (det && !det->isDisabled()) {
det->initDOFs();
nact++;
ndfAct += det->getNDOFsTot();
}
}
for (int i = 0; i < NTrackTypes; i++) {
if (nact < conf.minDetAcc[i]) {
LOG(fatal) << nact << " detectors are active, while " << conf.minDetAcc[i] << " in track are asked";
}
}
LOG(info) << mNDOFs << " global parameters " << mNDet << " detectors, " << ndfAct << " in " << nact << " active detectors";
addAutoConstraints();
setInitDOFsDone();
}
//________________________________________________________________
void Controller::assignDOFs()
{
// add parameters/labels arrays to volumes. If the Controller is read from the file, this method need
// to be called (of initDOFs should be called)
//
int ndfOld = -1;
if (mNDOFs > 0) {
ndfOld = mNDOFs;
}
mNDOFs = 0;
//
// reserve
int ndofTOT = mVtxSens->getNDOFs();
for (auto id = DetID::First; id <= DetID::Last; id++) {
AlignableDetector* det = getDetector(id);
if (!det) {
continue;
}
ndofTOT += det->getNDOFsTot();
}
mGloParVal.clear();
mGloParErr.clear();
mGloParLab.clear();
mOrderedLbl.clear();
mLbl2ID.clear();
mGloParVal.reserve(ndofTOT);
mGloParErr.reserve(ndofTOT);
mGloParLab.reserve(ndofTOT);
mOrderedLbl.reserve(ndofTOT);
mLbl2ID.reserve(ndofTOT);
mVtxSens->assignDOFs();
for (auto id = DetID::First; id <= DetID::Last; id++) {
AlignableDetector* det = getDetector(id);
if (!det) {
continue;
}
mNDOFs += det->assignDOFs();
}
LOG(info) << "Assigned parameters/labels arrays for " << mNDOFs << " DOFs";
if (ndfOld > -1 && ndfOld != mNDOFs) {
LOG(error) << "Recalculated NDOFs=" << mNDOFs << " not equal to saved NDOFs=" << ndfOld;
}
//
// build Lbl <-> parID table
/* FIXME RS TODO
Sort(mNDOFs, mGloParLab, mLbl2ID, false); // sort in increasing order
for (int i = mNDOFs; i--;) {
mOrderedLbl[i] = mGloParLab[mLbl2ID[i]];
}
*/
//
}
//_________________________________________________________
void Controller::addDetector(AlignableDetector* det)
{
// add detector constructed externally to alignment framework
mDetectors[det->getDetID()] = det;
mNDet++;
}
//_________________________________________________________
bool Controller::checkDetectorPattern(DetID::mask_t patt) const
{
//validate detector pattern
return ((patt & mObligatoryDetPattern[mTracksType]) == mObligatoryDetPattern[mTracksType]) &&
patt.count() >= AlignConfig::Instance().minDetAcc[mTracksType];
}
//_________________________________________________________
bool Controller::checkDetectorPoints(const int* npsel) const
{
//validate detectors pattern according to number of selected points
int ndOK = 0;
for (auto id = DetID::First; id <= DetID::Last; id++) {
AlignableDetector* det = getDetector(id);
if (!det || det->isDisabled(mTracksType)) {
continue;
}
if (npsel[id] < det->getNPointsSel(mTracksType)) {
if (det->isObligatory(mTracksType)) {
return false;
}
continue;
}
ndOK++;
}
return ndOK >= AlignConfig::Instance().minDetAcc[mTracksType];
}
//FIXME(milettri): needs AliESDtrack
////_________________________________________________________
//uint32_t Controller::AcceptTrack(const AliESDtrack* esdTr, bool strict) const
//{
// // decide if the track should be processed
// AlignableDetector* det = 0;
// uint32_t detAcc = 0;
// if (mFieldOn && esdTr->Pt() < mPtMin[mTracksType]){
// return 0;}
// if (Abs(esdTr->Eta()) > mEtaMax[mTracksType]){
// return 0;}
// //
// for (auto id=DetID::First; id<=DetID::Last; id++) {
//
// if (!(det = getDetector(id)) || det->isDisabled(mTracksType)){
// continue;}
// if (!det->AcceptTrack(esdTr, mTracksType)) {
// if (strict && det->isObligatory(mTracksType)){
// return 0;}
// else
// continue;
// }
// //
// detAcc |= 0x1 << idet;
// }
// if (numberOfBitsSet(detAcc) < mMinDetAcc[mTracksType]){
// return 0;}
// return detAcc;
// //
//}
//FIXME(milettri): needs AliESDtrack
////_________________________________________________________
//uint32_t Controller::AcceptTrackCosmic(const AliESDtrack* esdPairCosm[kNCosmLegs]) const
//{
// // decide if the pair of tracks making cosmic track should be processed
// uint32_t detAcc = 0, detAccLeg;
// for (int i = kNCosmLegs; i--;) {
// detAccLeg = AcceptTrack(esdPairCosm[i], mCosmicSelStrict); // missing obligatory detectors in one leg might be allowed
// if (!detAccLeg){
// return 0;}
// detAcc |= detAccLeg;
// }
// if (mCosmicSelStrict){
// return detAcc;}
// //
// // for non-stric selection check convolution of detector presence
// if (!checkDetectorPattern(detAcc)){
// return 0;}
// return detAcc;
// //
//}
//FIXME(milettri): needs AliESDEvent
////_________________________________________________________
//void Controller::SetESDEvent(const AliESDEvent* ev)
//{
// // attach event to analyse
// fESDEvent = ev;
// // setup magnetic field if needed
// if (fESDEvent &&
// (!TGeoGlobalMagField::Instance()->GetField() ||
// !smallerAbs(fESDEvent->GetMagneticField() - AliTrackerBase::GetBz(), 5e-4))) {
// fESDEvent->InitMagneticField();
// }
//}
//FIXME(milettri): needs AliESDEvent
////_________________________________________________________
//bool Controller::ProcessEvent(const AliESDEvent* esdEv)
//{
// // process event
// const int kProcStatFreq = 100;
// static int evCount = 0;
// if (!(evCount % kProcStatFreq)) {
// ProcInfo_t procInfo;
// gSystem->GetProcInfo(&procInfo);
// LOG(info) << "ProcStat: CPUusr:" << int(procInfo.fCpuUser) << " CPUsys:" << int(procInfo.fCpuSys) << " RMem:" << int(procInfo.fMemResident / 1024) << " VMem:" << int(procInfo.fMemVirtual / 1024);
// }
// evCount++;
// //
// SetESDEvent(esdEv);
// //
// if (esdEv->getRunNumber() != getRunNumber()){
// SetRunNumber(esdEv->getRunNumber());
// }
// //
// setCosmic(esdEv->GetEventSpecie() == AliRecoParam::kCosmic ||
// (esdEv->GetNumberOfCosmicTracks() > 0 && !esdEv->GetPrimaryVertexTracks()->GetStatus()));
// //
// fillStatHisto(kEvInp);
// //
//#if DEBUG > 2
// LOG << "Processing event " << esdEv->GetEventNumberInFile() << " of ev.specie " << esdEv->GetEventSpecie() << " -> Ntr: " << esdEv->GetNumberOfTracks() << " NtrCosm: " << esdEv->GetNumberOfCosmicTracks();
//#endif
// //
// setFieldOn(Abs(esdEv->GetMagneticField()) > kAlmost0Field);
// if (!isCosmic() && !CheckSetVertex(esdEv->GetPrimaryVertexTracks())){
// return false;}
// fillStatHisto(kEvVtx);
// //
// int ntr = 0, accTr = 0;
// if (isCosmic()) {
// mStat[kInpStat][kEventCosm]++;
// ntr = esdEv->GetNumberOfCosmicTracks();
// fillStatHisto(kTrackInp, ntr);
// for (int itr = 0; itr < ntr; itr++) {
// accTr += ProcessTrack(esdEv->GetCosmicTrack(itr));
// }
// if (accTr){
// mStat[kAccStat][kEventCosm]++;}
// } else {
// mStat[kInpStat][kEventColl]++;
// ntr = esdEv->GetNumberOfTracks();
// fillStatHisto(kTrackInp, ntr);
// for (int itr = 0; itr < ntr; itr++) {
// // int accTrOld = accTr;
// accTr += ProcessTrack(esdEv->GetTrack(itr));
// /*
// if (accTr>accTrOld && mCResid) {
// int ndf = mCResid.getNPoints()*2-5;
// if (mCResid.getChi2()/ndf>20 || !mCResid.getKalmanDone()
// || mCResid.getChi2K()/ndf>20) {
// printf("BAD FIT for %d\n",itr);
// }
// mCResid.Print("er");
// }
// */
// }
// if (accTr){
// mStat[kAccStat][kEventColl]++;}
// }
// //
// fillStatHisto(kTrackAcc, accTr);
// //
// if (accTr) {
// LOG(info) << "Processed event " << esdEv->GetEventNumberInFile() << " of ev.specie " << esdEv->GetEventSpecie() << " -> Accepted: " << accTr << " of " << ntr << " tracks";
// }
// return true;
//}
//FIXME(milettri): needs AliESDtrack
//_________________________________________________________
//bool Controller::ProcessTrack(const AliESDtrack* esdTr)
//{
// // process single track
// //
// mStat[kInpStat][kTrackColl]++;
// fESDTrack[0] = esdTr;
// fESDTrack[1] = 0;
// //
// int nPnt = 0;
// const AliESDfriendTrack* trF = esdTr->GetFriendTrack();
// if (!trF){
// return false;}
// const AliTrackPointArray* trPoints = trF->GetTrackPointArray();
// if (!trPoints || (nPnt = trPoints->GetNPoints()) < 1){
// return false;}
// //
// uint32_t detAcc = AcceptTrack(esdTr);
// if (!detAcc){
// return false;}
// //
// resetDetectors();
// mAlgTrack->Clear();
// //
// // process the track points for each detector,
// AlignableDetector* det = 0;
// for (auto id=DetID::First; id<=DetID::Last; id++) {
// if (!(detAcc & (0x1 << idet))){ // RS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// continue;}
// det = getDetector(id);
// if (det->ProcessPoints(esdTr, mAlgTrack) < det->getNPointsSel(kColl)) {
// detAcc &= ~(0x1 << idet); // did not survive, suppress detector in the track
// if (det->isObligatory(kColl)){
// return false;}
// }
// if (numberOfBitsSet(detAcc) < mMinDetAcc[kColl]){
// return false;} // abandon track
// }
// //
// if (mAlgTrack->getNPoints() < getMinPoints()){
// return false;}
// // fill needed points (tracking frame) in the mAlgTrack
// mRefPoint->setContainsMeasurement(false);
// mRefPoint->setContainsMaterial(false);
// mAlgTrack->addPoint(mRefPoint); // reference point which the track will refer to
// //
// mAlgTrack->copyFrom(esdTr);
// if (!getFieldOn()){
// mAlgTrack->imposePtBOff(mDefPtBOff[utils::kColl]);}
// mAlgTrack->setFieldON(getFieldOn());
// mAlgTrack->sortPoints();
// //
// // at this stage the points are sorted from maxX to minX, the latter corresponding to
// // reference point (e.g. vertex) with X~0. The mAlgTrack->getInnerPointID() points on it,
// // hence mAlgTrack->getInnerPointID() is the 1st really measured point. We will set the
// // alpha of the reference point to alpha of the barrel sector corresponding to this
// // 1st measured point
// int pntMeas = mAlgTrack->getInnerPointID() - 1;
// if (pntMeas < 0) { // this should not happen
// mAlgTrack->Print("p meas");
// LOG(fatal) << "AlignmentTrack->getInnerPointID() cannot be 0";
// }
// // do we want to add the vertex as a measured point ?
// if (!addVertexConstraint()) { // no constrain, just reference point w/o measurement
// mRefPoint->setXYZTracking(0, 0, 0);
// mRefPoint->setAlphaSens(sector2Alpha(mAlgTrack->getPoint(pntMeas)->getAliceSector()));
// } else
// fillStatHisto(kTrackFitInpVC);
// //
// fillStatHisto(kTrackFitInp);
// if (!mAlgTrack->iniFit()){
// return false;}
// fillStatHisto(kTrackProcMatInp);
// if (!mAlgTrack->processMaterials()){
// return false;}
// mAlgTrack->defineDOFs();
// //
// fillStatHisto(kTrackResDerInp);
// if (!mAlgTrack->calcResidDeriv()){
// return false;}
// //
// if (!storeProcessedTrack(mMPOutType & ~kContR)){
// return false;} // store derivatives for MP
// //
// if (getProduceControlRes() && // need control residuals, ignore selection fraction if this is the
// (mMPOutType == kContR || gRandom->Rndm() < mControlFrac)) { // output requested
// if (!testLocalSolution() || !storeProcessedTrack(kContR)){
// return false;}
// }
// //
// fillStatHisto(kTrackStore);
// //
// mStat[kAccStat][kTrackColl]++;
// //
// return true;
//}
//FIXME(milettri): needs AliESDVertex
////_________________________________________________________
//bool Controller::CheckSetVertex(const AliESDVertex* vtx)
//{
// // vertex selection/constraint check
// if (!vtx) {
// fVertex = 0;
// return true;
// }
// int ncont = vtx->GetNContributors();
// if (mVtxMinCont > 0 && mVtxMinCont > ncont) {
//#if DEBUG > 2
// LOG(info) << "Rejecting event with " << % d << " vertex contributors (min " << % d << " asked)", ncont, mVtxMinCont);
//#endif
// return false;
// }
// if (mVtxMaxCont > 0 && ncont > mVtxMaxCont) {
//#if DEBUG > 2
// LOG(info) << "Rejecting event with " << % d << " vertex contributors (max " << % d << " asked)", ncont, mVtxMaxCont);
//#endif
// return false;
// }
// fVertex = (ncont >= mVtxMinContVC) ? vtx : 0; // use vertex as a constraint
// return true;
//}
//FIXME(milettri): needs AliESDCosmicTrack
////_________________________________________________________
//bool Controller::ProcessTrack(const AliESDCosmicTrack* cosmTr)
//{
// // process single cosmic track
// //
// mStat[kInpStat][kTrackCosm]++;
// int nPnt = 0;
// fESDTrack[0] = 0;
// fESDTrack[1] = 0;
// //
// for (int leg = kNCosmLegs; leg--;) {
// const AliESDtrack* esdTr =
// fESDEvent->GetTrack(leg == kCosmLow ? cosmTr->GetESDLowerTrackIndex() : cosmTr->GetESDUpperTrackIndex());
// const AliESDfriendTrack* trF = esdTr->GetFriendTrack();
// if (!trF){
// return false;}
// const AliTrackPointArray* trPoints = trF->GetTrackPointArray();
// if (!trPoints || (nPnt += trPoints->GetNPoints()) < 1){
// return false;}
// //
// fESDTrack[leg] = esdTr;
// }
// //
// uint32_t detAcc = AcceptTrackCosmic(fESDTrack);
// if (!detAcc){
// return false;}
// //
// resetDetectors();
// mAlgTrack->Clear();
// mAlgTrack->setCosmic(true);
// //
// // process the track points for each detector,
// // fill needed points (tracking frame) in the mAlgTrack
// mRefPoint->setContainsMeasurement(false);
// mRefPoint->setContainsMaterial(false);
// mAlgTrack->addPoint(mRefPoint); // reference point which the track will refer to
// //
// AlignableDetector* det = 0;
// int npsel[kNDetectors] = {0};
// for (int nPleg = 0, leg = kNCosmLegs; leg--;) {
// for (auto id=DetID::First; id<=DetID::Last; id++) {
// if (!(detAcc & (0x1 << idet))){
// continue;}
// det = getDetector(id);
// //
// // upper leg points marked as the track going in inverse direction
// int np = det->ProcessPoints(fESDTrack[leg], mAlgTrack, leg == kCosmUp);
// if (np < det->getNPointsSel(Cosm) && mCosmicSelStrict &&
// det->isObligatory(Cosm))
// return false;
// npsel[id] += np;
// nPleg += np;
// }
// if (nPleg < getMinPoints()){
// return false;}
// }
// // last check on legs-combined patter
// if (!checkDetectorPoints(npsel)){
// return false;}
// //
// mAlgTrack->copyFrom(cosmTr);
// if (!getFieldOn()){
// mAlgTrack->imposePtBOff(mDefPtBOff[utils::Cosm]);}
// mAlgTrack->setFieldON(getFieldOn());
// mAlgTrack->sortPoints();
// //
// // at this stage the points are sorted from maxX to minX, the latter corresponding to
// // reference point (e.g. vertex) with X~0. The mAlgTrack->getInnerPointID() points on it,
// // hence mAlgTrack->getInnerPointID() is the 1st really measured point. We will set the
// // alpha of the reference point to alpha of the barrel sector corresponding to this
// // 1st measured point
// int pntMeas = mAlgTrack->getInnerPointID() - 1;
// if (pntMeas < 0) { // this should not happen
// mAlgTrack->Print("p meas");
// LOG(fatal) << "AlignmentTrack->getInnerPointID() cannot be 0";
// }
// mRefPoint->setAlphaSens(sector2Alpha(mAlgTrack->getPoint(pntMeas)->getAliceSector()));
// //
// fillStatHisto(kTrackFitInp);
// if (!mAlgTrack->iniFit()){
// return false;}
// //
// fillStatHisto(kTrackProcMatInp);
// if (!mAlgTrack->processMaterials()){
// return false;}
// mAlgTrack->defineDOFs();
// //
// fillStatHisto(kTrackResDerInp);
// if (!mAlgTrack->calcResidDeriv()){
// return false;}
// //
// if (!storeProcessedTrack(mMPOutType & ~kContR)){
// return false;} // store derivatives for MP
// //
// if (getProduceControlRes() && // need control residuals, ignore selection fraction if this is the
// (mMPOutType == kContR || gRandom->Rndm() < mControlFrac)) { // output requested
// if (!testLocalSolution() || !storeProcessedTrack(kContR)){
// return false;}
// }
// //
// fillStatHisto(kTrackStore);
// mStat[kAccStat][kTrackCosm]++;
// return true;
//}
//_________________________________________________________
bool Controller::storeProcessedTrack(int what)
{
// write alignment track
bool res = true;
if ((what & kMille)) {
res &= fillMilleData();
}
if ((what & kMPRec)) {
res &= fillMPRecData();
}
if ((what & kContR)) {
res &= fillControlData();
}
//
return res;
}
//_________________________________________________________
bool Controller::fillMilleData()
{
// store MP2 data in Mille format
if (!mMille) {
mMille = std::make_unique<Mille>(fmt::format("{}{}", mMPDatFileName, sMPDataExt).c_str());
}
//
if (!mAlgTrack->getDerivDone()) {
LOG(error) << "Track derivatives are not yet evaluated";
return false;
}
int np(mAlgTrack->getNPoints()), nDGloTot(0); // total number global derivatives stored
int nParETP(mAlgTrack->getNLocExtPar()); // numnber of local parameters for reference track param
int nVarLoc(mAlgTrack->getNLocPar()); // number of local degrees of freedom in the track
float *buffDL(nullptr), *buffDG(nullptr); // faster acces arrays
int* buffI(nullptr);
//
const int* gloParID(mAlgTrack->getGloParID()); // IDs of global DOFs this track depends on
for (int ip = 0; ip < np; ip++) {
AlignmentPoint* pnt = mAlgTrack->getPoint(ip);
if (pnt->containsMeasurement()) {
int gloOffs = pnt->getDGloOffs(); // 1st entry of global derivatives for this point
int nDGlo = pnt->getNGloDOFs(); // number of global derivatives (number of DOFs it depends on)
if (!pnt->isStatOK()) {
pnt->incrementStat();
}
// check buffer sizes
{
if (mMilleDBuffer.GetSize() < nVarLoc + nDGlo) {
mMilleDBuffer.Set(100 + nVarLoc + nDGlo);
}
if (mMilleIBuffer.GetSize() < nDGlo) {
mMilleIBuffer.Set(100 + nDGlo);
}
buffDL = mMilleDBuffer.GetArray(); // faster acces
buffDG = buffDL + nVarLoc; // faster acces
buffI = mMilleIBuffer.GetArray(); // faster acces
}
// local der. array cannot be 0-suppressed by Mille construction, need to reset all to 0
//
for (int idim = 0; idim < 2; idim++) { // 2 dimensional orthogonal measurement
memset(buffDL, 0, nVarLoc * sizeof(float));
const double* deriv = mAlgTrack->getDResDLoc(idim, ip); // array of Dresidual/Dparams_loc
// derivatives over reference track parameters
for (int j = 0; j < nParETP; j++) {
buffDL[j] = (isZeroAbs(deriv[j])) ? 0 : deriv[j];
}
//
// point may depend on material variables within these limits
int lp0 = pnt->getMinLocVarID(), lp1 = pnt->getMaxLocVarID();
for (int j = lp0; j < lp1; j++) {
buffDL[j] = (isZeroAbs(deriv[j])) ? 0 : deriv[j];
}
//
// derivatives over global params: this array can be 0-suppressed, no need to reset
int nGlo(0);
deriv = mAlgTrack->getDResDGlo(idim, gloOffs);
const int* gloIDP(gloParID + gloOffs);
for (int j = 0; j < nDGlo; j++) {
if (!isZeroAbs(deriv[j])) {
buffDG[nGlo] = deriv[j]; // value of derivative
buffI[nGlo++] = getGloParLab(gloIDP[j]); // global DOF ID + 1 (Millepede needs positive labels)
}
}
mMille->mille(nVarLoc, buffDL, nGlo, buffDG, buffI,
mAlgTrack->getResidual(idim, ip), Sqrt(pnt->getErrDiag(idim)));
nDGloTot += nGlo;
//
}
}
if (pnt->containsMaterial()) { // material point can add 4 or 5 otrhogonal pseudo-measurements
memset(buffDL, 0, nVarLoc * sizeof(float));
int nmatpar = pnt->getNMatPar(); // residuals (correction expectation value)
// const float* expMatCorr = pnt->getMatCorrExp(); // expected corrections (diagonalized)
const float* expMatCov = pnt->getMatCorrCov(); // their diagonalized error matrix
int offs = pnt->getMaxLocVarID() - nmatpar; // start of material variables
// here all derivatives are 1 = dx/dx
for (int j = 0; j < nmatpar; j++) { // mat. "measurements" don't depend on global params
int j1 = j + offs;
buffDL[j1] = 1.0; // only 1 non-0 derivative
//mMille->mille(nVarLoc,buffDL,0,buffDG,buffI,expMatCorr[j],Sqrt(expMatCov[j]));
// expectation for MS effect is 0
mMille->mille(nVarLoc, buffDL, 0, buffDG, buffI, 0, Sqrt(expMatCov[j]));
buffDL[j1] = 0.0; // reset buffer
}
} // material "measurement"
} // loop over points
//
if (!nDGloTot) {
LOG(info) << "Track does not depend on free global parameters, discard";
mMille->kill();
return false;
}
mMille->end(); // store the record
return true;
}
//_________________________________________________________
bool Controller::fillMPRecData()
{
LOG(fatal) << __PRETTY_FUNCTION__ << " is disabled";
//FIXME(milettri): needs AliESDEvent
// // store MP2 in MPRecord format
// if (!mMPRecord){
// initMPRecOutput();}
// //
// mMPRecord->Clear();
// if (!mMPRecord->fillTrack(mAlgTrack, mGloParLab)){
// return false;}
// mMPRecord->SetRun(mRunNumber);
// mMPRecord->setTimeStamp(fESDEvent->GetTimeStamp());
// uint32_t tID = 0xffff & uint(fESDTrack[0]->GetID());
// if (isCosmic()){
// tID |= (0xffff & uint(fESDTrack[1]->GetID())) << 16;}
// mMPRecord->setTrackID(tID);
// mMPRecTree->Fill();
return true;
}
//_________________________________________________________
bool Controller::fillControlData()
{
LOG(fatal) << __PRETTY_FUNCTION__ << " is disabled";
//FIXME(milettri): needs AliESDEvent
// // store control residuals
// if (!mCResid){
// initResidOutput();}
// //
// int nps, np = mAlgTrack->getNPoints();
// nps = (!mRefPoint->containsMeasurement()) ? np - 1 : np; // ref point is dummy?
// if (nps < 0){
// return true;}
// //
// mCResid.Clear();
// if (!mCResid.fillTrack(mAlgTrack, mDoKalmanResid)){
// return false;}
// mCResid.setRun(mRunNumber);
// mCResid.setTimeStamp(fESDEvent->GetTimeStamp());
// mCResid.setBz(fESDEvent->GetMagneticField());
// uint32_t tID = 0xffff & uint(fESDTrack[0]->GetID());
// if (isCosmic()){
// tID |= (0xffff & uint(fESDTrack[1]->GetID())) << 16;}
// mCResid.setTrackID(tID);
// //
// mResidTree->Fill();
// fillStatHisto(kTrackControl);
// //
return true;
}
//_________________________________________________________
void Controller::setRunNumber(int run)
{
if (run == mRunNumber) {
return;
} // nothing to do
//
acknowledgeNewRun(run);
}
//_________________________________________________________
void Controller::acknowledgeNewRun(int run)
{
LOG(warning) << __PRETTY_FUNCTION__ << " yet incomplete";
o2::base::GeometryManager::loadGeometry();
o2::base::PropagatorImpl<double>::initFieldFromGRP();
std::unique_ptr<o2::parameters::GRPObject> grp{o2::parameters::GRPObject::loadFrom()};
//FIXME(milettri): needs AliESDEvent
// // load needed info for new run
// if (run == mRunNumber){
// return;} // nothing to do
// if (run > 0) {
// mStat[kAccStat][kRun]++;
// }
// if (mRunNumber > 0){
// fillStatHisto(kRunDone);}
// mRunNumber = run;
// LOG(info) << "Processing new run " << mRunNumber;
// //
// // setup magnetic field
// if (fESDEvent &&
// (!TGeoGlobalMagField::Instance()->GetField() ||
// !smallerAbs(fESDEvent->GetMagneticField() - AliTrackerBase::GetBz(), 5e-4))) {
// fESDEvent->InitMagneticField();
// }
// //
// if (!mUseRecoOCDB) {
// LOG(warning) << "Reco-time OCDB will NOT be preloaded";
// return;
// }
// LoadRecoTimeOCDB();
// //
// for (auto id=DetID::First; id<=DetID::Last; id++) {
// AlignableDetector* det = getDetector(id);
// if (!det->isDisabled()){
// det->acknowledgeNewRun(run);}
// }
// //
// // bring to virgin state
// // CleanOCDB();
// //
// // LoadRefOCDB(); //??? we need to get back reference OCDB ???
// //
// mStat[kInpStat][kRun]++;
// //
}
// FIXME(milettri): needs OCDB
////_________________________________________________________
//bool Controller::LoadRecoTimeOCDB()
//{
// // Load OCDB paths used for the reconstruction of data being processed
// // In order to avoid unnecessary uploads, the objects are not actually
// // loaded/cached but just added as specific paths with version
// LOG(info) << "Preloading Reco-Time OCDB for run " << mRunNumber << " from ESD UserInfo list";
// //
// CleanOCDB();
// //
// if (!mRecoOCDBConf.IsNull() && !gSystem->AccessPathName(mRecoOCDBConf.c_str(), kFileExists)) {
// LOG(info) << "Executing reco-time OCDB setup macro " << mRecoOCDBConf.c_str();
// gROOT->ProcessLine(Form(".x %s(%d)", mRecoOCDBConf.c_str(), mRunNumber));
// if (AliCDBManager::Instance()->IsDefaultStorageSet()){
// return true;}
// LOG(fatal) << "macro " << mRecoOCDBConf.c_str() << " failed to configure reco-time OCDB";
// } else
// LOG(warning) << "No reco-time OCDB config macro" << mRecoOCDBConf.c_str() << " is found, will use ESD:UserInfo";
// //
// if (!mESDTree){
// LOG(fatal) << "Cannot preload Reco-Time OCDB since the ESD tree is not set";}
// const TTree* tr = mESDTree; // go the the real ESD tree
// while (tr->GetTree() && tr->GetTree() != tr)
// tr = tr->GetTree();
// //
// const TList* userInfo = const_cast<TTree*>(tr)->GetUserInfo();
// TMap* cdbMap = (TMap*)userInfo->FindObject("cdbMap");
// TList* cdbList = (TList*)userInfo->FindObject("cdbList");
// //
// if (!cdbMap || !cdbList) {
// userInfo->Print();
// LOG(fatal) << "Failed to extract cdbMap and cdbList from UserInfo list";
// }
// //
// return PreloadOCDB(mRunNumber, cdbMap, cdbList);
//}
//____________________________________________
void Controller::Print(const Option_t* opt) const
{
// print info
TString opts = opt;
opts.ToLower();
printf("%5d DOFs in %d detectors\n", mNDOFs, mNDet);
if (getMPAlignDone()) {
printf("ALIGNMENT FROM MILLEPEDE SOLUTION IS APPLIED\n");
}
//
for (auto id = DetID::First; id <= DetID::Last; id++) {
AlignableDetector* det = getDetector(id);
if (!det) {
continue;
}
det->Print(opt);
}
if (!opts.IsNull()) {
printf("\nSpecial sensor for Vertex Constraint\n");
mVtxSens->Print(opt);
}
//
if (mRefRunNumber >= 0) {
printf("(%d)", mRefRunNumber);