forked from eutelescope/eutelescope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEUTelApplyAlignmentProcessor.cc
2353 lines (1960 loc) · 97.3 KB
/
EUTelApplyAlignmentProcessor.cc
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
// Version $Id$
/*
* This source code is part of the Eutelescope package of Marlin.
* You are free to use this source files for your own development as
* long as it stays in a public research context. You are not
* allowed to use it for commercial purpose. You must put this
* header with author names in all development based on this file.
*
*/
#ifdef USE_GEAR
// eutelescope includes ".h"
#include "EUTelGeometryTelescopeGeoDescription.h"
// eutelescope includes ".h"
#include "EUTelApplyAlignmentProcessor.h"
#include "EUTelAlignmentConstant.h"
#include "EUTELESCOPE.h"
#include "EUTelEventImpl.h"
#include "EUTelRunHeaderImpl.h"
#include "EUTelHistogramManager.h"
#include "EUTelExceptions.h"
#include "EUTelVirtualCluster.h"
#include "EUTelFFClusterImpl.h"
#include "EUTelDFFClusterImpl.h"
#include "EUTelBrickedClusterImpl.h"
#include "EUTelSparseClusterImpl.h"
// ROOT includes:
#include "TVector3.h"
#include "TVector2.h"
#include "TMatrix.h"
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
// aida includes ".h"
#include <AIDA/IHistogram3D.h>
#include <AIDA/IHistogram2D.h>
#include <AIDA/ITree.h>
#include <AIDA/IHistogramFactory.h>
#include <marlin/AIDAProcessor.h>
#endif
// marlin includes ".h"
#include "marlin/Processor.h"
#include "marlin/Exceptions.h"
#include "marlin/Global.h"
// gear includes <.h>
#include <gear/GearMgr.h>
#include <gear/SiPlanesParameters.h>
// lcio includes <.h>
#include <UTIL/CellIDEncoder.h>
#include <UTIL/CellIDDecoder.h>
#include <EVENT/LCCollection.h>
#include <EVENT/LCEvent.h>
#include <IMPL/LCCollectionVec.h>
//#include <TrackerHitImpl2.h>
#include <IMPL/TrackerHitImpl.h>
#include <IMPL/TrackImpl.h>
#include <IMPL/TrackerDataImpl.h>
#include <IMPL/LCFlagImpl.h>
#include <Exceptions.h>
// ROOT includes ".h"
#include <TVectorD.h>
#include <TMatrixD.h>
// system includes <>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <algorithm>
#include <memory>
#include <string>
using namespace std;
using namespace lcio;
using namespace marlin;
using namespace eutelescope;
using namespace gear;
#if defined(USE_AIDA) || defined(MARLIN_USE_AIDA)
std::string EUTelApplyAlignmentProcessor::_densityPlotBeforeAlignName = "DensityPlotBeforeAlign";
std::string EUTelApplyAlignmentProcessor::_densityPlotAfterAlignName = "DensityPloAfterAlign";
std::string EUTelApplyAlignmentProcessor::_hitHistoBeforeAlignName = "HitHistoBeforeAlign";
std::string EUTelApplyAlignmentProcessor::_hitHistoAfterAlignName = "HitHistoAfterAlign";
#endif
EUTelApplyAlignmentProcessor::EUTelApplyAlignmentProcessor ()
: Processor("EUTelApplyAlignmentProcessor"),
_conversionIdMap(),
_nRun(0),
_nEvt(0),
_iDUT(0),
_indexDUT(0),
_xPitch(0.0),
_yPitch(0.0),
_rot00(0.0),
_rot01(0.0),
_rot10(0.0),
_rot11(0.0),
internal_inputHitCollectionName(""),
internal_inputCollectionVec(NULL),
internal_referenceHitCollectionName(""),
internal_referenceHitVec(NULL),
_inputHitCollectionName(""),
_inputCollectionVec(NULL),
_alignmentCollectionName(""),
_alignmentCollectionVec(NULL),
_outputHitCollectionName(""),
_outputCollectionVec(NULL),
_applyToReferenceHitCollection(true),
_referenceHitCollectionName(""),
_referenceHitVec(NULL),
_outputReferenceHitCollectionName(""),
_outputReferenceHitVec(NULL),
_correctionMethod(0),
_applyAlignmentDirection(0),
_alignmentCollectionNames(),
_alignmentCollectionSuffixes(),
_hitCollectionNames(),
_hitCollectionSuffixes(),
_refhitCollectionNames(),
_refhitCollectionSuffixes(),
_doGear(false),
_doAlignCollection(false),
_doAlignmentInOneGo(false),
_debugSwitch(false),
_alpha(0.0),
_beta(0.0),
_gamma(0.0),
_printEvents(0),
_iRun(0),
_iEvt(0),
_lookUpTable(),
_fevent(false),
_aidaHistoMap(),
_siPlanesParameters(NULL),
_siPlanesLayerLayout(NULL),
_siPlaneZPosition(NULL),
_orderedSensorIDVec(),
_histogramSwitch(false)
{
// modify processor description
_description =
"Apply to the input hit the alignment corrections";
// first of all we need to register the input collection
registerInputCollection (LCIO::TRACKERHIT, "InputHitCollectionName",
"The name of the input hit collection",
internal_inputHitCollectionName, string ("hit"));
registerInputCollection (LCIO::LCGENERICOBJECT, "AlignmentConstantName",
"Alignment constant from the condition file",
_alignmentCollectionName, string ("dummy"));
registerOutputCollection (LCIO::TRACKERHIT, "OutputHitCollectionName",
"The name of the output hit collection",
_outputHitCollectionName, string("PreAlignedHit"));
registerOptionalParameter("ReferenceCollection","This is the name of the reference hit collection", internal_referenceHitCollectionName, static_cast< string > ( "referenceHit" ) );
registerOptionalParameter("OutputReferenceCollection","This is the name of the modified output reference hit collection", _outputReferenceHitCollectionName, static_cast< string > ( "output_refhit" ) );
registerOptionalParameter("ApplyToReferenceCollection","Do you want the reference hit collection to be corrected by the shifts and tilts from the alignment collection?", _applyToReferenceHitCollection, static_cast< bool > ( true ));
// now the optional parameters
registerProcessorParameter ("CorrectionMethod",
"Available methods are:\n"
" 0 -> shift only \n"
" 1 -> rotation first \n"
" 2 -> shift first ",
_correctionMethod, static_cast<int > (1));
// now the optional parameters
registerProcessorParameter ("ApplyAlignmentDirection",
"Available directions are:\n"
" 0 -> direct \n"
" 1 -> reverse ",
_applyAlignmentDirection, static_cast<int > (0));
// the histogram on / off switch
registerOptionalParameter("HistogramSwitch","Enable or disable histograms",
_histogramSwitch, static_cast< bool > ( 0 ) );
// vector of strings (alignment collections)
EVENT::StringVec _alignmentCollectionSuffixExamples;
_alignmentCollectionSuffixExamples.push_back("alignmentCollectionNames");
registerProcessorParameter ("alignmentCollectionNames",
"List of alignment collections that were applied to the DUT",
_alignmentCollectionSuffixes, _alignmentCollectionSuffixExamples);
// vector of strings (hit collections)
EVENT::StringVec _hitCollectionSuffixExamples;
_hitCollectionSuffixExamples.push_back("hitCollectionNames");
registerProcessorParameter ("hitCollectionNames",
"List of hit collections. First one is INPUT collection, every subsequent corresponds to applying alignment collection",
_hitCollectionSuffixes, _hitCollectionSuffixExamples);
EVENT::StringVec _refhitCollectionSuffixExamples;
_refhitCollectionSuffixExamples.push_back("hitCollectionNames");
registerProcessorParameter ("refhitCollectionNames",
"List of refhit collections. First one is INPUT collection, every subsequent corresponds to applying alignment collection",
_refhitCollectionSuffixes, _refhitCollectionSuffixExamples);
registerOptionalParameter("DoAlignCollection","Implement geometry shifts and rotations as described in alignmentCollectionName ",
_doAlignCollection, static_cast< bool > ( 0 ) );
registerOptionalParameter("DoGear","Implement geometry shifts and rotations as described in GEAR steering file ",
_doGear, static_cast< bool > ( 0 ) );
registerOptionalParameter("DoAlignmentInOneGo","Apply alignment steps in one go. Is supposed to be used for reversealignment in reverse order, like: undoAlignment, undoPreAlignment, undoGear ",
_doAlignmentInOneGo, static_cast< bool > ( 0 ) );
// DEBUG parameters :
// turn ON/OFF debug features
registerOptionalParameter("DEBUG","Enable or disable DEBUG mode ",
_debugSwitch, static_cast< bool > ( 0 ) );
registerOptionalParameter("Alpha","Rotation Angle around X axis",
_alpha, static_cast< double > ( 0.00 ) );
registerOptionalParameter("Beta","Rotation Angle around Y axis",
_beta, static_cast< double > ( 0.00 ) );
registerOptionalParameter("Gamma","Rotation Angle around Z axis",
_gamma, static_cast< double > ( 0.00 ) );
registerOptionalParameter("PrintEvents", "Events number to have DEBUG1 printed outs (default=10)",
_printEvents, static_cast<int> (10) );
}
void EUTelApplyAlignmentProcessor::init() {
// this method is called only once even when the rewind is active
// usually a good idea to
printParameters ();
// set to zero the run and event counters
_iRun = 0;
_iEvt = 0;
// Getting access to geometry description
std::string name("test.root");
geo::gGeometry().initializeTGeoDescription(name,false);
// check if the GEAR manager pointer is not null!
if ( Global::GEAR == 0x0 ) {
streamlog_out ( ERROR4 ) << "The GearMgr is not available, for an unknown reason." << endl;
exit(-1);
}
//_siPlanesParameters = const_cast<SiPlanesParameters* > (&(Global::GEAR->getSiPlanesParameters()));
//_siPlanesLayerLayout = const_cast<SiPlanesLayerLayout*> ( &(_siPlanesParameters->getSiPlanesLayerLayout() ));
//_siPlaneZPosition = new double[ _siPlanesLayerLayout->getNLayers() ];
//for ( int iPlane = 0 ; iPlane < _siPlanesLayerLayout->getNLayers(); iPlane++ ) {
// _siPlaneZPosition[ iPlane ] = _siPlanesLayerLayout->getLayerPositionZ(iPlane);
//}
#if defined(MARLIN_USE_AIDA) || defined(USE_AIDA)
// _histogramSwitch = false;
#endif
_isFirstEvent = true;
_fevent = true;
_referenceHitVec = 0;
// _orderedSensorIDVec.clear();
//for ( int iPlane = 0 ; iPlane < _siPlanesParameters->getSiPlanesNumber() ; ++iPlane ) {
// _orderedSensorIDVec.push_back( _siPlanesLayerLayout->getID( iPlane ) );
//}
_lookUpTable.clear();
}
//..................................................................................
void EUTelApplyAlignmentProcessor::CheckIOCollections(LCEvent* event)
{
EUTelEventImpl * evt = static_cast<EUTelEventImpl*> (event);
if ( _applyToReferenceHitCollection )
{
try{
_referenceHitVec = dynamic_cast < LCCollectionVec * > (event->getCollection( _referenceHitCollectionName));
}
catch(...)
{
if(_iEvt%1000 == 0) streamlog_out ( WARNING2 ) << "_referenceHitCollectionName " << _referenceHitCollectionName.c_str() << " could not be retrieved, creating a dummy one (all elements are null) " << endl;
_referenceHitVec = CreateDummyReferenceHitCollection();
event->addCollection( _referenceHitVec, _referenceHitCollectionName );
}
try
{
_outputReferenceHitVec = dynamic_cast < LCCollectionVec * > (event->getCollection( _outputReferenceHitCollectionName ) );
}
catch(...)
{
_outputReferenceHitVec = CreateDummyReferenceHitCollection();
streamlog_out ( DEBUG5 ) << "NOT found _outputReferenceHitVec [" << _outputReferenceHitCollectionName.c_str() << "] at " << _outputReferenceHitVec << endl;
event->addCollection( _outputReferenceHitVec, _outputReferenceHitCollectionName );
}
}
// ----------------------------------------------------------------------- //
// check input / output collections
_inputCollectionVec = 0 ;
_alignmentCollectionVec = 0 ;
_outputCollectionVec = 0 ;
try
{
_inputCollectionVec = dynamic_cast < LCCollectionVec* > (evt->getCollection(_inputHitCollectionName));
streamlog_out ( DEBUG2 ) << " input ["<< _inputHitCollectionName <<"] collection found on event " << event->getEventNumber() << endl;
streamlog_out ( DEBUG2 ) << " input ["<< _inputHitCollectionName <<"] collection found at " << _inputCollectionVec << endl;
} catch (DataNotAvailableException& e) {
streamlog_out ( DEBUG3 ) << "No input ["<< _inputHitCollectionName <<"] collection found on event " << event->getEventNumber()
<< " in run " << event->getRunNumber() << endl;
}
if( _alignmentCollectionName != "gear" )
{
try
{
_alignmentCollectionVec = dynamic_cast < LCCollectionVec* > (evt->getCollection(_alignmentCollectionName));
streamlog_out ( DEBUG2 ) << "found Alignment ["<< _alignmentCollectionName <<"] collection found on event " << event->getEventNumber() <<
" at " << _alignmentCollectionVec << endl;
} catch (DataNotAvailableException& e) {
streamlog_out ( DEBUG3 ) << "No Alignment ["<< _alignmentCollectionName <<"] collection found on event " << event->getEventNumber()
<< " in run " << event->getRunNumber() << endl;
}
}
try{
_outputCollectionVec = dynamic_cast < LCCollectionVec * > (evt->getCollection(_outputHitCollectionName));
if(_outputCollectionVec == 0)
{
_outputCollectionVec = new LCCollectionVec(LCIO::TRACKERHIT);
evt->addCollection( _outputCollectionVec, _outputHitCollectionName );
streamlog_out ( DEBUG2 ) << " created new " << _outputHitCollectionName << endl;
}
else
{
streamlog_out ( DEBUG2 ) << " opened " << _outputHitCollectionName << endl;
}
}catch(...){
_outputCollectionVec = new LCCollectionVec(LCIO::TRACKERHIT);
evt->addCollection( _outputCollectionVec, _outputHitCollectionName );
streamlog_out ( DEBUG2 ) << " try catch. nevertheless created new " << _outputHitCollectionName << endl;
}
}
void EUTelApplyAlignmentProcessor::processRunHeader (LCRunHeader * runHeader)
{
auto_ptr<EUTelRunHeaderImpl> eutelHeader( new EUTelRunHeaderImpl ( runHeader ) );
eutelHeader->addProcessor( type() );
// increment the run counter
_nRun++ ;
// Decode and print out Run Header information - just a check
int runNr = runHeader->getRunNumber();
// convert to string
char buf[256];
sprintf(buf, "%i", runNr);
std::string runNr_str(buf);
message<MESSAGE6> ( log() << "Processing run header " << _nRun
<< ", run number " << runNr );
const std::string detectorName = runHeader->getDetectorName();
const std::string detectorDescription = runHeader->getDescription();
// const std::vector<std::string> * subDets = runHeader->getActiveSubdetectors();
message<MESSAGE4> ( log() << detectorName << " : " << detectorDescription ) ;
// pick up correct alignment collection
_alignmentCollectionNames.clear();
_hitCollectionNames.clear();
_refhitCollectionNames.clear();
if( _alignmentCollectionSuffixes.size() < 1 )
{
message<ERROR5> ( log() << "You must define at least one Alignmen Collection to start ApplyAlignment Processor" << endl ) ;
throw StopProcessingException(this);
}
else
if( _alignmentCollectionSuffixes.size() == 1 )
{
message<MESSAGE4> ( log() << "Only one Alignment Collection has been specified" << endl ) ;
message<MESSAGE4> ( log() << "Ignore other Suffix collections, proceed with the defaults given by _referenceHitCollectionName and _inputHitCollectionName " <<endl );
_alignmentCollectionNames.push_back( _alignmentCollectionSuffixes[0] );
_refhitCollectionNames.push_back( internal_referenceHitCollectionName );
_hitCollectionNames.push_back( _outputHitCollectionName );
message<MESSAGE4> ( log() << " _alignmentCollectionNames[0] = " << _alignmentCollectionNames[0] << endl);
message<MESSAGE4> ( log() << " _hitCollectionNames[0] = " << _hitCollectionNames[0] << endl);
message<MESSAGE4> ( log() << " _refhitCollectionNames[0] = " << _refhitCollectionNames[0] << endl);
}
else
if(
( _alignmentCollectionSuffixes.size() != _hitCollectionSuffixes.size() )
||
( _alignmentCollectionSuffixes.size() != _refhitCollectionSuffixes.size() )
||
( _hitCollectionSuffixes.size() != _refhitCollectionSuffixes.size() )
)
{
message<ERROR > ( log() << endl );
message<ERROR > ( log() << " ***************************************************************************" );
message<ERROR > ( log() << " *** dont't mess with the steering cards ***" );
message<ERROR > ( log() << " *** ***" );
message<ERROR > ( log() << endl );
for (unsigned i = 0; i < _alignmentCollectionSuffixes.size(); i++)
{
message<ERROR > ( log() << " _alignmentCollectionSuffixes["<<i<<"] : " << _alignmentCollectionSuffixes[i] );
}
for (unsigned i = 0; i < _hitCollectionSuffixes.size(); i++)
{
message< ERROR > ( log() << " _hitCollectionSuffixes["<<i<<"] : " << _hitCollectionSuffixes[i] );
}
for (unsigned i = 0; i < _refhitCollectionSuffixes.size(); i++)
{
message< ERROR > ( log() << " _refhitCollectionSuffixes["<<i<<"] : " << _refhitCollectionSuffixes[i] );
}
message<ERROR > ( log() << endl );
TString ExceptionMessage = " Input collection names are inconsistent in number of elements: \n \n";
ExceptionMessage += " alignment [ "; ExceptionMessage += _alignmentCollectionSuffixes.size(); ExceptionMessage += "]\n";
ExceptionMessage += " hit [ "; ExceptionMessage += _hitCollectionSuffixes.size(); ExceptionMessage += "]\n";
ExceptionMessage += " refhit [ "; ExceptionMessage += _refhitCollectionSuffixes.size(); ExceptionMessage += "]\n";
message<ERROR5> ( log() << ExceptionMessage.Data() );
message<ERROR > ( log() << " *** ***" );
message<ERROR > ( log() << " ***************************************************************************" );
message<ERROR > ( log() << endl );
throw StopProcessingException(this);
}
else
{
for (unsigned i = 0; i < _alignmentCollectionSuffixes.size(); i++)
{
std::string alitemp = _alignmentCollectionSuffixes[i];
_alignmentCollectionNames.push_back(alitemp);
std::string hittemp = _hitCollectionSuffixes[i];
_hitCollectionNames.push_back(hittemp);
std::string reftemp = _refhitCollectionSuffixes[i];
_refhitCollectionNames.push_back(reftemp);
}
}
}
//........................................................................................................................
void EUTelApplyAlignmentProcessor::processEvent (LCEvent * event) {
if( _alignmentCollectionNames.size() <= 0 )
{
streamlog_out ( ERROR5 ) << "Alignment collections are UNDEFINED, the processor can not continue. EXIT " << endl;
throw StopProcessingException(this);
}
else
{
// ----------------------------------------------------------------------- //
// check input / output collections
//...................................................................... //
for (int i = static_cast<int>(_alignmentCollectionNames.size()) -1 ; i >= 0; i-- )
{
// read the first available alignment collection
// CAUTION 1: it might be important to keep the order of alignment collections (if many) given in the opposite direction
// CAUTION 2: to be controled via steering files
//
_alignmentCollectionName = _alignmentCollectionNames.at(i);
if( i == static_cast<int>(_alignmentCollectionNames.size()) -1 )
{
_inputHitCollectionName = internal_inputHitCollectionName ;
_referenceHitCollectionName = internal_referenceHitCollectionName ;
_outputHitCollectionName = _hitCollectionNames.at(i);//_input_inputHitCollectionName + _alignmentCollectionName;
_outputReferenceHitCollectionName = _refhitCollectionNames.at(i);//referenceH_referenceHitCollectionName + _alignmentCollectionName;
}
else
if( i >= 0 )
{
_inputHitCollectionName = _hitCollectionNames.at(i+1);
_outputHitCollectionName = _hitCollectionNames.at(i);//temp + _alignmentCollectionName;
_referenceHitCollectionName = _refhitCollectionNames.at(i+1);
_outputReferenceHitCollectionName = _refhitCollectionNames.at(i);//temp + _alignmentCollectionName;
}
CheckIOCollections(event);
// streamlog_out ( MESSAGE4 ) << "_doAlignmentInOneGo == " << _doAlignmentInOneGo << endl;
if( _doAlignmentInOneGo != true ) // keep for backward compatibility , hopefully to declare OBSOLETE soon
{
if( GetApplyAlignmentDirection() == 0 )
{
if( _doGear )
{
ApplyGear6D(event);
}
if( _doAlignCollection )
{
Direct(event);
}
}
else
if( GetApplyAlignmentDirection() == 1 )
{
if( _doAlignCollection )
{
Reverse(event);
}
if( _doGear )
{
RevertGear6D(event);
}
}
else
{
throw StopProcessingException(this);
}
}
else
if( _doAlignmentInOneGo == true ) // logic from 01.09.2012 . hopefully to declare PRO soon
{
// streamlog_out ( MESSAGE4 ) << "_doAlignmentInOneGo == true " << endl;
if( _alignmentCollectionName == "gear" )
{
if( GetApplyAlignmentDirection() == 1 )
{
RevertGear6D(event);
}
else if( GetApplyAlignmentDirection() == 0 )
{
ApplyGear6D(event);
}
}
else
{
if( GetApplyAlignmentDirection() == 1 )
{
Reverse(event);
}
else if( GetApplyAlignmentDirection() == 0 )
{
Direct(event);
}
}
}
else
{
streamlog_out ( ERROR5 ) << "You MUST specifiy whether you want the alignment to be done in one go or not" << endl;
streamlog_out ( ERROR5 ) << "Check your steering cards!!" << endl;
}
}
if(_fevent)
{
_isFirstEvent = false;
_fevent = false;
}
_iEvt++;
}
if ( _applyToReferenceHitCollection )
{
for( size_t jj = 0 ; jj < _alignmentCollectionNames.size(); jj ++)
{
std::string _colName = _alignmentCollectionNames.at(jj);
LCCollectionVec * ref = static_cast < LCCollectionVec * > (event->getCollection( _colName ));
for( size_t ii = 0 ; ii < static_cast< size_t >(ref->getNumberOfElements()); ii++)
{
streamlog_out( DEBUG5 ) << " check output_refhit at : " << ref << " ";
EUTelReferenceHit* output_refhit = static_cast< EUTelReferenceHit*> ( ref->getElementAt(ii) ) ;
streamlog_out( DEBUG5 ) << " at : " << output_refhit << endl;
streamlog_out( DEBUG5 ) << "CHK sensorID: " << output_refhit->getSensorID( )
<< " x :" << output_refhit->getXOffset( )
<< " y :" << output_refhit->getYOffset( )
<< " z :" << output_refhit->getZOffset( )
<< " alfa :" << output_refhit->getAlpha()
<< " beta :" << output_refhit->getBeta()
<< " gamma:" << output_refhit->getGamma() << endl ;
}
}
}
}
void EUTelApplyAlignmentProcessor::ApplyGear6D( LCEvent *event)
{
UTIL::CellIDDecoder<TrackerHitImpl> hitDecoder ( EUTELESCOPE::HITENCODING );
EUTelEventImpl * evt = static_cast<EUTelEventImpl*> (event);
if ( evt->getEventType() == kEORE )
{
streamlog_out ( DEBUG4 ) << "EORE found: nothing else to do." << endl;
return;
}
else if ( evt->getEventType() == kUNKNOWN )
{
streamlog_out ( WARNING2 ) << "Event number " << evt->getEventNumber() << " in run " << evt->getRunNumber()
<< " is of unknown type. Continue considering it as a normal Data Event." << endl;
}
{
#ifndef NDEBUG
// print out the lookup table
map< int , int >::iterator mapIter = _lookUpTable[ _alignmentCollectionName ].begin();
while ( mapIter != _lookUpTable[ _alignmentCollectionName ].end() )
{
streamlog_out ( DEBUG2 ) << "Sensor ID = " << mapIter->first
<< " is in position " << mapIter->second << endl;
++mapIter;
}
#endif
}
if( _inputCollectionVec == 0 )
{
streamlog_out ( DEBUG5 ) << "EUTelApplyAlignmentProcessor::ApplyGear6D. Skip this event. Input Collection not found. " << endl;
return;
}
for (size_t iHit = 0; iHit < _inputCollectionVec->size(); iHit++)
{
TrackerHitImpl* inputHit = dynamic_cast<TrackerHitImpl*>( _inputCollectionVec->getElementAt(iHit) );
// now we have to understand which layer this hit belongs to.
int sensorID = hitDecoder(inputHit)["sensorID"];
/*
if ( _conversionIdMap.size() != static_cast< unsigned >( _siPlanesParameters->getSiPlanesNumber()) )
{
// first of all try to see if this sensorID already belong to
if ( _conversionIdMap.find( sensorID ) == _conversionIdMap.end() )
{
// this means that this detector ID was not already inserted,
// so this is the right place to do that
for ( int iLayer = 0; iLayer < _siPlanesLayerLayout->getNLayers(); iLayer++ )
{
if ( _siPlanesLayerLayout->getID(iLayer) == sensorID )
{
_conversionIdMap.insert( make_pair( sensorID, iLayer ) );
break;
}
}
}
}
*/
// int layerIndex = _conversionIdMap[sensorID];
// determine z position of the plane
// 20 December 2010 @libov
float z_sensor = geo::gGeometry().siPlaneZPosition(sensorID);
/*
for ( int iPlane = 0 ; iPlane < _siPlanesLayerLayout->getNLayers(); ++iPlane )
{
if (sensorID == _siPlanesLayerLayout->getID( iPlane ) )
{
z_sensor = _siPlanesLayerLayout -> getSensitivePositionZ( iPlane ) + 0.5 * _siPlanesLayerLayout->getSensitiveThickness( iPlane );
break;
}
}
*/
// copy the input to the output, at least for the common part
TrackerHitImpl * outputHit = new TrackerHitImpl;
outputHit->setType( inputHit->getType() );
outputHit->rawHits() = inputHit->getRawHits();
outputHit->setCellID0( inputHit->getCellID0() );
outputHit->setCellID1( inputHit->getCellID1() );
double * inputPosition = const_cast< double * > ( inputHit->getPosition() ) ;
double outputPosition[3] = { 0., 0., 0. };
if ( 1==1 )
{
double telPos[3] = {0., 0., 0.};
double gRotation[3] = { 0., 0., 0.}; // not rotated
if ( _debugSwitch )
{
telPos[0] = 0.;
telPos[1] = 0.;
telPos[2] = 0.;
gRotation[0] = _alpha;
gRotation[1] = _beta ;
gRotation[2] = _gamma;
}
else
{
gRotation[0] = geo::gGeometry().siPlaneZRotation(sensorID); // _siPlanesLayerLayout->getLayerRotationXY(layerIndex); // Euler alpha ;
gRotation[1] = geo::gGeometry().siPlaneYRotation(sensorID); // _siPlanesLayerLayout->getLayerRotationZX(layerIndex); // Euler alpha ;
gRotation[2] = geo::gGeometry().siPlaneXRotation(sensorID); // _siPlanesLayerLayout->getLayerRotationZY(layerIndex); // Euler alpha ;
// input angles are in DEGREEs !!!
// translate into radians
gRotation[0] = gRotation[0] *3.1415926/180.; //
gRotation[1] = gRotation[1] *3.1415926/180.; //
gRotation[2] = gRotation[2] *3.1415926/180.; //
telPos[0] = geo::gGeometry().siPlaneXPosition(sensorID); // _siPlanesLayerLayout->getSensitivePositionX(layerIndex); // mm
telPos[1] = geo::gGeometry().siPlaneYPosition(sensorID); // _siPlanesLayerLayout->getSensitivePositionY(layerIndex); // mm
telPos[2] = geo::gGeometry().siPlaneZPosition(sensorID); // _siPlanesLayerLayout->getSensitivePositionZ(layerIndex); // mm
}
if( _iEvt < _printEvents )
{
if ( _debugSwitch )
{
streamlog_out ( MESSAGE5 ) << "Debugmode ON " << endl;
}
streamlog_out ( DEBUG2 ) << "_applyGear6D " << endl;
streamlog_out ( DEBUG2 ) << " telPos[0] = " << telPos[0] << endl;
streamlog_out ( DEBUG2 ) << " telPos[1] = " << telPos[1] << endl;
streamlog_out ( DEBUG2 ) << " telPos[2] = " << telPos[2] << endl;
streamlog_out ( DEBUG2 ) << " gRotation[0] = " << gRotation[0] << endl;
streamlog_out ( DEBUG2 ) << " gRotation[1] = " << gRotation[1] << endl;
streamlog_out ( DEBUG2 ) << " gRotation[2] = " << gRotation[2] << endl;
}
// rotations first
outputPosition[0] = inputPosition[0];
outputPosition[1] = inputPosition[1];
outputPosition[2] = inputPosition[2] - z_sensor;
_EulerRotation(outputPosition, gRotation);
// then the shifts
// outputPosition[0] = telPos[0];
// outputPosition[1] = telPos[1];
// outputPosition[2] = telPos[2];
outputPosition[2] += z_sensor;
}
else
{
// this hit belongs to a plane whose sensorID is not in the
// alignment constants. So the idea is to eventually advice
// the users if running in DEBUG and copy the not aligned hit
// in the new collection.
// streamlog_out ( DEBUG3 ) << "Sensor ID " << sensorID << " not found. Skipping alignment for hit "
// << iHit << endl;
for ( size_t i = 0; i < 3; ++i )
{
outputPosition[i] = inputPosition[i];
}
}
if ( _iEvt < _printEvents )
{
streamlog_out ( DEBUG2 ) << "ApplyGear: INPUT: Sensor ID " << sensorID << " " << inputPosition[0] << " " << inputPosition[1] << " " << inputPosition[2] << " " << z_sensor << endl;
streamlog_out ( DEBUG2 ) << "ApplyGear: OUTPUT:Sensor ID " << sensorID << " " << outputPosition[0] << " " << outputPosition[1] << " " << outputPosition[2] << " " << z_sensor << endl;
}
outputHit->setPosition( outputPosition ) ;
_outputCollectionVec->push_back( outputHit );
}
}
void EUTelApplyAlignmentProcessor::RevertGear6D( LCEvent *event)
{
UTIL::CellIDDecoder<TrackerHitImpl> hitDecoder ( EUTELESCOPE::HITENCODING );
EUTelEventImpl * evt = static_cast<EUTelEventImpl*> (event);
if ( evt->getEventType() == kEORE )
{
streamlog_out ( DEBUG4 ) << "EORE found: nothing else to do." << endl;
return;
}
else if ( evt->getEventType() == kUNKNOWN )
{
streamlog_out ( WARNING2 ) << "Event number " << evt->getEventNumber() << " in run " << evt->getRunNumber()
<< " is of unknown type. Continue considering it as a normal Data Event." << endl;
}
// ----------------------------------------------------------------------- //
// check input / output collections
// CheckIOCollections(event);
//
// ----------------------------------------------------------------------- //
// if (_fevent)
{
#ifndef NDEBUG
// print out the lookup table
map< int , int >::iterator mapIter = _lookUpTable[ _alignmentCollectionName ].begin();
while ( mapIter != _lookUpTable[ _alignmentCollectionName ].end() )
{
streamlog_out ( DEBUG5 ) << "Sensor ID = " << mapIter->first
<< " is in position " << mapIter->second << endl;
++mapIter;
}
#endif
}
// final check
if( _inputCollectionVec == 0 )
{
streamlog_out ( DEBUG5 ) << "EUTelApplyAlignmentProcessor::RevertGear6D. Skip this event. Input Collection not found. " << endl;
return;
}
// go-go
for (size_t iHit = 0; iHit < _inputCollectionVec->size(); iHit++)
{
TrackerHitImpl* inputHit = dynamic_cast<TrackerHitImpl*>( _inputCollectionVec->getElementAt(iHit) );
// now we have to understand which layer this hit belongs to.
int sensorID = hitDecoder(inputHit)["sensorID"];
/*
if ( _conversionIdMap.size() != static_cast< unsigned >( _siPlanesParameters->getSiPlanesNumber()) )
{
// first of all try to see if this sensorID already belong to
if ( _conversionIdMap.find( sensorID ) == _conversionIdMap.end() )
{
// this means that this detector ID was not already inserted,
// so this is the right place to do that
for ( int iLayer = 0; iLayer < _siPlanesLayerLayout->getNLayers(); iLayer++ )
{
if ( _siPlanesLayerLayout->getID(iLayer) == sensorID )
{
_conversionIdMap.insert( make_pair( sensorID, iLayer ) );
break;
}
}
}
}
int layerIndex = _conversionIdMap[sensorID];
*/
// determine z position of the plane
// 20 December 2010 @libov
/* float z_sensor = 0;
for ( int iPlane = 0 ; iPlane < _siPlanesLayerLayout->getNLayers(); ++iPlane )
{
if (sensorID == _siPlanesLayerLayout->getID( iPlane ) )
{
z_sensor = _siPlanesLayerLayout -> getSensitivePositionZ( iPlane ) + 0.5 * _siPlanesLayerLayout->getSensitiveThickness( iPlane );
break;
}
}
*/
// retrieve the refhit cooridantes (eventual offset of the sensor)
double x_refhit = 0.;
double y_refhit = 0.;
double z_refhit = 0.;
if( !_applyToReferenceHitCollection || _referenceHitVec == 0 )
{
// todo: is this case (no reference vector) treated correctly?
streamlog_out( MESSAGE5 ) << "_referenceHitVec is empty" << endl;
}
else
{
// streamlog_out( MESSAGE5 ) << "reference Hit collection name : " << _referenceHitCollectionName << endl;
for(size_t ii = 0 ; ii < static_cast< size_t >(_referenceHitVec->getNumberOfElements()); ii++)
{
EUTelReferenceHit * refhit = static_cast< EUTelReferenceHit*> ( _referenceHitVec->getElementAt(ii) ) ;
if( sensorID != refhit->getSensorID() )
{
// streamlog_out( MESSAGE5 ) << "Looping through a varity of sensor IDs" << endl;
continue;
}
else
{
x_refhit = refhit->getXOffset();
y_refhit = refhit->getYOffset();
z_refhit = refhit->getZOffset();
if( _iEvt < _printEvents )
{
streamlog_out(DEBUG2) << "Sensor ID and Alignment plane ID match!" << endl;
streamlog_out(DEBUG2) << "x_refhit " << x_refhit << endl;
streamlog_out(DEBUG2) << "y_refhit " << y_refhit << endl;
streamlog_out(DEBUG2) << "z_refhit " << z_refhit << endl;
}
break;
}
}
}
// copy the input to the output, at least for the common part
TrackerHitImpl * outputHit = new TrackerHitImpl;
outputHit->setType( inputHit->getType() );
outputHit->rawHits() = inputHit->getRawHits();
outputHit->setCellID0( inputHit->getCellID0() );
outputHit->setCellID1( inputHit->getCellID1() );
const double * inputPosition = const_cast< const double * > ( inputHit->getPosition() ) ;
double outputPosition[3] = { 0., 0., 0. };
if ( 1==1 )
{
double telPos[3] = {0., 0., 0.};
double gRotation[3] = { 0., 0., 0.}; // not rotated
if ( _debugSwitch )
{
telPos[0] = 0.;
telPos[1] = 0.;
telPos[2] = 0.;
gRotation[0] = _alpha;
gRotation[1] = _beta ;
gRotation[2] = _gamma;
}
else
{
gRotation[0] = geo::gGeometry().siPlaneZRotation(sensorID); // _siPlanesLayerLayout->getLayerRotationXY(layerIndex); // Euler alpha ;
gRotation[1] = geo::gGeometry().siPlaneYRotation(sensorID); // _siPlanesLayerLayout->getLayerRotationZX(layerIndex); // Euler alpha ;
gRotation[2] = geo::gGeometry().siPlaneXRotation(sensorID); // _siPlanesLayerLayout->getLayerRotationZY(layerIndex); // Euler alpha ;
// input angles are in DEGREEs !!!
// translate into radians
gRotation[0] = gRotation[0] *3.1415926/180.; //
gRotation[1] = gRotation[1] *3.1415926/180.; //
gRotation[2] = gRotation[2] *3.1415926/180.; //
telPos[0] = geo::gGeometry().siPlaneXPosition(sensorID); // _siPlanesLayerLayout->getSensitivePositionX(layerIndex); // mm
telPos[1] = geo::gGeometry().siPlaneYPosition(sensorID); // _siPlanesLayerLayout->getSensitivePositionY(layerIndex); // mm
telPos[2] = geo::gGeometry().siPlaneZPosition(sensorID); // _siPlanesLayerLayout->getSensitivePositionZ(layerIndex); // mm
}
if( _iEvt < _printEvents )
{
if ( _debugSwitch )
{
streamlog_out ( MESSAGE5 ) << "Debugmode ON " << endl;
}
streamlog_out ( DEBUG2 ) << "_revertGear6D " << endl;
streamlog_out ( DEBUG2 ) << " telPos[0] = " << telPos[0] << endl;
streamlog_out ( DEBUG2 ) << " telPos[1] = " << telPos[1] << endl;
streamlog_out ( DEBUG2 ) << " telPos[2] = " << telPos[2] << endl;
streamlog_out ( DEBUG2 ) << " gRotation[0] = " << gRotation[0] << endl;
streamlog_out ( DEBUG2 ) << " gRotation[1] = " << gRotation[1] << endl;
streamlog_out ( DEBUG2 ) << " gRotation[2] = " << gRotation[2] << endl;
}
// new implmentation // Rubinskiy 11.11.11
// undo the shifts = go back to the center of the sensor frame (rotations unchanged)
outputPosition[0] = inputPosition[0] - x_refhit;
outputPosition[1] = inputPosition[1] - y_refhit;
outputPosition[2] = inputPosition[2] - z_refhit;
if ( _iEvt < _printEvents )
{
streamlog_out ( DEBUG2 ) << "RevertGear: intermediate: "<<outputPosition[0] << " " <<outputPosition[1] << " " <<outputPosition[2] << endl;
}
TVector3 iCenterOfSensorFrame( outputPosition[0], outputPosition[1], outputPosition[2] );