-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscopex.cc
2755 lines (2100 loc) · 71.7 KB
/
scopex.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
// Daniel Pitzl, DESY, Sep 2017, May 2019
// telescope analysis with eudaq and ROC4Sens and MOD
// event display
// make scopex
// needs runs.dat
// needs align_24500.dat from tele
// scopex 24500
// scopex -l 99999 24500
// scopex -t 2.2 25200
// scopex -s 24093
// scopex -l 99999 28027
// scopex -s 28037
// scopex 31210 # 3D
// scopex -l 312100 31425
#include "eudaq/FileReader.hh"
#include "eudaq/PluginManager.hh"
#include <TApplication.h>
#include <TSystem.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TH2.h>
#include <sstream> // stringstream
#include <fstream> // filestream
#include <set> // for hotset
#include <map> // colpx
#include <cmath>
#include <sys/time.h> // gettimeofday, timeval
#include <sys/ioctl.h>
using namespace std;
using namespace eudaq;
struct pixel {
int col;
int row;
double adc; // online ph
double ph; // offline dph
double q; // calibrated [ke]
int ord; // readout order
bool big; // module big pixel flag
bool operator < (const pixel & pxObj ) const // row-wise ordering
{
return row < pxObj.row;
}
};
struct cluster {
vector <pixel> vpix;
int size;
int ncol, nrow;
double col, row;
double charge;
bool big;
bool iso;
};
struct triplet {
double xm; // mid point [mm]
double ym;
double zm;
double sx; // slope [rad]
double sy;
bool lk; // linked
double ttdmin; // distance top next track [mm]
};
//------------------------------------------------------------------------------
vector < cluster > getClus( vector <pixel> pb, int fCluCut = 1 ) // 1 = no gap
{
// returns clusters with local coordinates
// next-neighbour topological clustering (allows fCluCut-1 empty pixels)
vector < cluster > v;
if( pb.size() == 0 ) return v;
vector <bool> gone( pb.size() ); // initialized to zero
unsigned seed = 0;
while( seed < pb.size() ) {
// start a new cluster
cluster c;
c.vpix.push_back( pb[seed] );
gone[seed] = 1;
// let it grow as much as possible:
int growing;
do {
growing = 0;
for( unsigned i = 0; i < pb.size(); ++i ) {
if( !gone[i] ){ // unused pixel
for( unsigned int p = 0; p < c.vpix.size(); ++p ) { // vpix in cluster so far
int dr = c.vpix.at(p).row - pb[i].row;
int dc = c.vpix.at(p).col - pb[i].col;
if( ( dr>=-fCluCut) && (dr<=fCluCut)
&& (dc>=-fCluCut) && (dc<=fCluCut) ) {
c.vpix.push_back(pb[i]);
gone[i] = 1;
growing = 1;
break; // important!
}
} // loop over vpix
} // not gone
} // loop over all pix
}
while( growing );
// added all I could. determine position and append it to the list of clusters:
c.size = c.vpix.size();
c.col = 0;
c.row = 0;
double sumQ = 0;
c.big = 0;
c.iso = 1;
int minx = 9999;
int maxx = 0;
int miny = 9999;
int maxy = 0;
for( vector<pixel>::iterator p = c.vpix.begin(); p != c.vpix.end(); ++p ) {
double Qpix = p->q; // calibrated [Vcal]
if( Qpix < 0 ) Qpix = 1; // DP 1.7.2012
sumQ += Qpix;
c.col += (*p).col*Qpix;
c.row += (*p).row*Qpix;
if( p->big ) c.big = 1;
if( p->col > maxx ) maxx = p->col;
if( p->col < minx ) minx = p->col;
if( p->row > maxy ) maxy = p->row;
if( p->row < miny ) miny = p->row;
}
//cout << "(cluster with " << c.vpix.size() << " pixels)" << endl;
if( sumQ > 0 ) {
c.col /= sumQ;
c.row /= sumQ;
}
else {
c.col = (*c.vpix.begin()).col;
c.row = (*c.vpix.begin()).row;
//cout << "GetClus: cluster with non-positive charge" << endl;
}
c.charge = sumQ;
c.ncol = maxx-minx+1;
c.nrow = maxy-miny+1;
v.push_back(c); // add cluster to vector
// look for a new seed = used pixel:
while( ( ++seed < pb.size() ) && gone[seed] );
} // while over seeds
// nothing left, return clusters
return v;
} // getClus
//------------------------------------------------------------------------------
bool kbhit()
{
usleep(1000); // [us]
int byteswaiting;
ioctl( 0, FIONREAD, &byteswaiting );
return byteswaiting > 0;
}
//------------------------------------------------------------------------------
int main( int argc, char * argv[] )
{
cout << "main " << argv[0] << " called with " << argc << " arguments" << endl;
if( argc == 1 ) {
cout << "give run number" << endl;
return 1;
}
// run number = last arg
string runnum( argv[argc-1] );
int run = atoi( argv[argc-1] );
cout << "run " << run << endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// further arguments:
int lev = 900200100; // last event
bool syncmod = 0; // re-sync required ?
for( int i = 1; i < argc; ++i ) {
if( !strcmp( argv[i], "-l" ) )
lev = atoi( argv[++i] ); // last event
if( !strcmp( argv[i], "-m" ) )
syncmod = 1;
} // argc
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// runs.dat:
cout << endl;
int r4srun{0};
string geoFileName( "geo.dat" );
double DUTtilt0 = 19.3;
double DUTturn0 = 19.3;
double pbeam = 4.8;
int chip0 = 110;
string gainFileName( "gain.dat" );
string modgainFileName( "/home/pitzl/psi/dtb/tst400/D4028-ia25-trim40-2016-04-gaincal.dat" );
int weib = 3;
ifstream runsFile( "runs.dat" );
if( runsFile.bad() || ! runsFile.is_open() ) {
cout << "Error opening runs.dat" << endl;
return 1;
}
// can there be instructions between if and else ? no
else {
cout << "read runs from runs.dat" << endl;
string hash( "#" );
string RUN( "run" );
string R4SRUN( "r4srun" );
string GEO( "geo" );
string GeV( "GeV" );
string CHIP( "chip" );
string GAIN( "gain" );
string MODGAIN( "modgain" );
string WEIB( "weib" );
string TILT( "tilt" );
string TURN( "turn" );
bool found = 0;
while( ! runsFile.eof() ) {
string line;
getline( runsFile, line );
if( line.empty() ) continue;
stringstream tokenizer( line );
string tag;
tokenizer >> tag; // leading white space is suppressed
if( tag.substr(0,1) == hash ) // comments start with #
continue;
if( tag == RUN ) {
int ival;
tokenizer >> ival;
if( ival == run ) {
found = 1;
break; // end file reading
}
}
if( tag == R4SRUN ) {
tokenizer >> r4srun;
continue;
}
if( tag == CHIP ) {
tokenizer >> chip0;
continue;
}
if( tag == TILT ) {
tokenizer >> DUTtilt0;
continue;
}
if( tag == TURN ) {
tokenizer >> DUTturn0;
continue;
}
if( tag == GeV ) {
tokenizer >> pbeam;
continue;
}
if( tag == GEO ) {
tokenizer >> geoFileName;
continue;
}
if( tag == GAIN ) {
tokenizer >> gainFileName;
continue;
}
if( tag == MODGAIN ) {
tokenizer >> modgainFileName;
continue;
}
if( tag == weib ) {
tokenizer >> weib;
continue;
}
// anything else on the line and in the file gets ignored
} // while getline runs.dat
if( found )
cout
<< "settings for run " << run << ":" << endl
<< " beam " << pbeam << " GeV" << endl
<< " geo file " << geoFileName << endl
<< " nominal DUT tilt " << DUTtilt0 << " deg" << endl
<< " nominal DUT turn " << DUTturn0 << " deg" << endl
<< " DUT chip " << chip0 << endl
<< " DUT gain file " << gainFileName << endl
<< " MOD gain file " << modgainFileName << endl
<< " Weibull version " << weib << endl
;
else {
cout << "run " << run << " not found in runs.dat" << endl;
return 1;
}
} // runsFile
runsFile.close();
const double fTLU = 384E6; // 384 MHz TLU clock
double fDTB = 39.99679E6; // 40 MHz DTB clock from ddt and ddtvsdt
if( run >= 31148 ) // 4.10.2017
fDTB = 39.99712E6; // ddtvsdt->Fit("pol1") fDTB*(1-slope*1E-3)
if( run >= 31592 ) // 16.12.2017 different DTB
fDTB = 39.996943E6; // ddtvsdt->Fit("pol1") fDTB*(1-slope*1E-3)
if( run >= 31632 ) // Feb 2018
fDTB = 39.996984E6; // ddtvsdt->Fit("pol1") fDTB*(1-slope*1E-3)
if( run >= 32032 ) // Apr 2018
fDTB = 39.997110E6; // 40 MHz DTB clock from ddt and ddtvsdt: fDTB*(1-slope*1E-3)
if( run >= 33511 ) // Sep 2018
fDTB = 39.996810E6; // 40 MHz DTB clock from ddt and ddtvsdt: fDTB*(1-slope*1E-3)
if( run >= 34248 ) // Oct 2018
fDTB = 39.996899E6; // ddtvsdt->Fit("pol1") fDTB*(1-slope*1E-3)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// geometry:
int nx[9]; // x-pixels per plane
int ny[9]; // y-pixels per plane
double sizex[9]; // x size per plane
double sizey[9]; // y size per plane
double ptchx[9]; // x-pixel size
double ptchy[9]; // y-pixel size
double midx[9]; // x mid
double midy[9]; // y mid
double zz[9];
for( int ipl = 0; ipl < 9; ++ipl )
nx[ipl] = 0; // missing plane flag
ifstream geoFile( geoFileName );
cout << endl;
if( geoFile.bad() || ! geoFile.is_open() ) {
cout << "Error opening " << geoFileName << endl;
return 1;
}
cout << "read geometry from " << geoFileName << endl;
{ // open local scope
string hash( "#" );
string plane( "plane" );
string type( "type" );
string sizexs( "sizex" );
string sizeys( "sizey" );
string npixelx( "npixelx" );
string npixely( "npixely" );
string zpos( "zpos" );
int ipl = 0;
string chiptype;
while( ! geoFile.eof() ) {
string line;
getline( geoFile, line );
cout << line << endl;
if( line.empty() ) continue;
stringstream tokenizer( line );
string tag;
tokenizer >> tag; // leading white space is suppressed
if( tag.substr(0,1) == hash ) // comments start with #
continue;
if( tag == plane ) {
tokenizer >> ipl;
continue;
}
if( ipl < 0 || ipl >= 9 ) {
cout << "wrong plane number " << ipl << endl;
continue;
}
if( tag == type ) {
tokenizer >> chiptype;
continue;
}
if( tag == sizexs ) {
double val;
tokenizer >> val;
sizex[ipl] = val;
continue;
}
if( tag == sizeys ) {
double val;
tokenizer >> val;
sizey[ipl] = val;
continue;
}
if( tag == npixelx ) {
int val;
tokenizer >> val;
nx[ipl] = val;
continue;
}
if( tag == npixely ) {
int val;
tokenizer >> val;
ny[ipl] = val;
continue;
}
if( tag == zpos ) {
double val;
tokenizer >> val;
zz[ipl] = val;
continue;
}
// anything else on the line and in the file gets ignored
} // while getline
for( int ipl = 0; ipl < 9; ++ipl ) {
if( nx[ipl] == 0 ) continue; // missing plane flag
ptchx[ipl] = sizex[ipl] / nx[ipl]; // pixel size
ptchy[ipl] = sizey[ipl] / ny[ipl];
midx[ipl] = 0.5 * sizex[ipl]; // mid plane
midy[ipl] = 0.5 * sizey[ipl]; // mid plane
}
} // geo scope
geoFile.close();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// telescope alignment:
int aligniteration = 0;
double alignx[9];
double aligny[9];
double rotx[9];
double roty[9];
ostringstream alignFileName; // output string stream
alignFileName << "align_" << run << ".dat";
ifstream ialignFile( alignFileName.str() );
cout << endl;
if( ialignFile.bad() || ! ialignFile.is_open() ) {
cout << "Error opening " << alignFileName.str() << endl
<< " please do: tele -g " << geoFileName << " " << run << endl
<< endl;
return 1;
}
else {
cout << "read alignment from " << alignFileName.str() << endl;
string hash( "#" );
string iteration( "iteration" );
string plane( "plane" );
string shiftx( "shiftx" );
string shifty( "shifty" );
string rotxvsy( "rotxvsy" );
string rotyvsx( "rotyvsx" );
int ipl = 0;
while( ! ialignFile.eof() ) {
string line;
getline( ialignFile, line );
cout << line << endl;
if( line.empty() ) continue;
stringstream tokenizer( line );
string tag;
tokenizer >> tag; // leading white space is suppressed
if( tag.substr(0,1) == hash ) // comments start with #
continue;
if( tag == iteration )
tokenizer >> aligniteration;
if( tag == plane )
tokenizer >> ipl;
if( ipl < 0 || ipl >= 9 ) {
cout << "wrong plane number " << ipl << endl;
continue;
}
double val;
tokenizer >> val;
if( tag == shiftx )
alignx[ipl] = val;
else if( tag == shifty )
aligny[ipl] = val;
else if( tag == rotxvsy )
rotx[ipl] = val;
else if( tag == rotyvsx )
roty[ipl] = val;
// anything else on the line and in the file gets ignored
} // while getline
} // telescope alignFile
ialignFile.close();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Mimosa hot pixels:
ostringstream hotFileName; // output string stream
hotFileName << "hot_" << run << ".dat";
ifstream ihotFile( hotFileName.str() );
set <int> hotset[9];
if( ihotFile.bad() || ! ihotFile.is_open() ) {
cout << "no " << hotFileName.str() << " (created by tele)" << endl;
}
else {
cout << "read hot pixel list from " << hotFileName.str() << endl;
string hash( "#" );
string plane( "plane" );
string pix( "pix" );
int ipl = 0;
while( ! ihotFile.eof() ) {
string line;
getline( ihotFile, line );
//cout << line << endl;
if( line.empty() ) continue;
stringstream tokenizer( line );
string tag;
tokenizer >> tag; // leading white space is suppressed
if( tag.substr(0,1) == hash ) // comments start with #
continue;
if( tag == plane )
tokenizer >> ipl;
if( ipl < 0 || ipl >= 6 ) {
//cout << "wrong plane number " << ipl << endl;
continue;
}
if( tag == pix ) {
int ix, iy;
tokenizer >> ix;
tokenizer >> iy;
int ipx = ix*ny[ipl]+iy;
hotset[ipl].insert(ipx);
}
} // while getline
} // telescope hotFile
ihotFile.close();
for( int ipl = 0; ipl < 6; ++ipl )
cout << ipl << ": hot " << hotset[ipl].size() << endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// DUT:
const double wt = atan(1.0) / 45.0; // pi/180 deg
bool rot90 = 0; // straight
if( chip0 == 106 ) rot90 = 1;
if( chip0 == 107 ) rot90 = 1;
if( chip0 == 108 ) rot90 = 1;
if( chip0 == 109 ) rot90 = 1;
if( chip0 == 110 ) rot90 = 1;
if( chip0 == 111 ) rot90 = 1;
if( chip0 == 112 ) rot90 = 1;
if( chip0 == 113 ) rot90 = 1;
if( chip0 == 114 ) rot90 = 1;
if( chip0 == 115 ) rot90 = 1;
if( chip0 == 116 ) rot90 = 1;
if( chip0 == 117 ) rot90 = 1;
if( chip0 == 118 ) rot90 = 1;
if( chip0 == 120 ) rot90 = 1; /// irrad
if( chip0 == 124 ) rot90 = 1; /// irrad
if( chip0 == 129 ) rot90 = 1; /// irrad
if( chip0 == 130 ) rot90 = 1; /// irrad
if( chip0 == 136 ) rot90 = 1; /// irrad
if( chip0 == 137 ) rot90 = 1; /// irrad
if( chip0 == 139 ) rot90 = 1;
if( chip0 == 142 ) rot90 = 1;
if( chip0 == 143 ) rot90 = 1;
if( chip0 == 144 ) rot90 = 1;
if( chip0 == 145 ) rot90 = 1;
if( chip0 == 146 ) rot90 = 1;
if( chip0 == 147 ) rot90 = 1;
if( chip0 == 148 ) rot90 = 1;
if( chip0 == 149 ) rot90 = 1;
if( chip0 == 150 ) rot90 = 1;
if( chip0 == 151 ) rot90 = 1;
if( chip0 == 153 ) rot90 = 1;
if( chip0 == 155 ) rot90 = 1;
if( chip0 == 156 ) rot90 = 1;
if( chip0 == 157 ) rot90 = 1;
if( chip0 == 163 ) rot90 = 1;
if( chip0 == 164 ) rot90 = 1;
if( chip0 == 165 ) rot90 = 1;
if( chip0 == 174 ) rot90 = 1;
if( chip0 == 179 ) rot90 = 1;
if( chip0 == 193 ) rot90 = 1;
if( chip0 == 194 ) rot90 = 1; // 4E15 n
if( chip0 == 195 ) rot90 = 1; // 0.6E15 n
if( chip0 == 196 ) rot90 = 1; // 8E15 n
if( chip0 == 197 ) rot90 = 1; // 16E15 n
if( chip0 == 200 ) rot90 = 1; // 16E15 n
if( chip0 == 206 ) rot90 = 1; // p-spray max imp 8E15 n
if( chip0 == 207 ) rot90 = 1; // 16E15 n
if( chip0 == 210 ) rot90 = 1; // FDD 4E15 n
if( chip0 == 211 ) rot90 = 1; // FDD 0.6E15 n
if( chip0 == 216 ) rot90 = 1; // FDD 8E15 n
if( chip0 == 227 ) rot90 = 1;
bool fifty = 0;
if( chip0 == 102 ) fifty = 1;
if( chip0 == 106 ) fifty = 1;
if( chip0 == 111 ) fifty = 1;
if( chip0 == 117 ) fifty = 1;
if( chip0 == 118 ) fifty = 1;
if( chip0 == 119 ) fifty = 1; // irr
if( chip0 == 122 ) fifty = 1; // irr
if( chip0 == 123 ) fifty = 1; // irr
if( chip0 == 126 ) fifty = 1; // irr
if( chip0 == 127 ) fifty = 1; // irr
if( chip0 == 132 ) fifty = 1; // irr
if( chip0 == 133 ) fifty = 1; // irr
if( chip0 == 134 ) fifty = 1; // irr
if( chip0 == 135 ) fifty = 1; // irr
if( chip0 == 139 ) fifty = 1;
if( chip0 == 140 ) fifty = 1;
if( chip0 == 142 ) fifty = 1;
if( chip0 == 143 ) fifty = 1;
if( chip0 == 144 ) fifty = 1;
if( chip0 == 147 ) fifty = 1;
if( chip0 == 149 ) fifty = 1;
if( chip0 == 151 ) fifty = 1;
if( chip0 == 152 ) fifty = 1;
if( chip0 == 155 ) fifty = 1;
if( chip0 == 158 ) fifty = 1;
if( chip0 == 159 ) fifty = 1;
if( chip0 == 160 ) fifty = 1;
if( chip0 == 161 ) fifty = 1; // poly
if( chip0 == 166 ) fifty = 1;
if( chip0 == 172 ) fifty = 1;
if( chip0 == 173 ) fifty = 1;
if( chip0 == 175 ) fifty = 1;
if( chip0 == 176 ) fifty = 1;
if( chip0 == 177 ) fifty = 1;
if( chip0 == 181 ) fifty = 1;
if( chip0 == 182 ) fifty = 1;
if( chip0 == 183 ) fifty = 1;
if( chip0 == 184 ) fifty = 1;
if( chip0 == 185 ) fifty = 1;
if( chip0 == 186 ) fifty = 1;
if( chip0 == 187 ) fifty = 1;
if( chip0 == 191 ) fifty = 1;
if( chip0 == 198 ) fifty = 1; // 8E15 n
if( chip0 == 199 ) fifty = 1; // 0.6E15 n
if( chip0 == 200 ) fifty = 1; // 16E15 n
if( chip0 == 202 ) fifty = 1; // 4E15 n
if( chip0 == 203 ) fifty = 1; // 0.6E15 n
if( chip0 == 204 ) fifty = 1; // 8E15 n
if( chip0 == 212 ) fifty = 1; // FDD 4E15 n
if( chip0 == 214 ) fifty = 1; // FDD 0.6E15 n
if( chip0 == 215 ) fifty = 1; // FDD 8E15 n
if( chip0 == 225 ) fifty = 1;
if( chip0 == 226 ) fifty = 1;
if( chip0 == 229 ) fifty = 1;
if( chip0 == 230 ) fifty = 1;
if( chip0 >= 300 ) fifty = 1; // 3D
double upsignx = 1; // w.r.t. telescope
double upsigny = 1;
if( rot90 ) {
upsignx = -1;
upsigny = 1;
}
if( chip0 == 108 && run >= 32194 ) upsigny = -1; // Apr 2018
if( chip0 == 109 && run >= 32195 ) upsigny = -1; // Apr 2018
if( chip0 == 111 && run >= 32214 ) upsigny = -1; // Apr 2018
if( chip0 == 114 && run >= 32196 ) upsigny = -1; // Apr 2018
if( chip0 == 115 && run >= 32199 ) upsigny = -1; // Apr 2018
if( chip0 == 116 && run >= 32200 ) upsigny = -1; // Apr 2018
if( chip0 == 118 && run >= 32170 ) upsigny = -1; // Apr 2018
if( chip0 == 120 ) upsigny = -1;
if( chip0 == 124 ) upsigny = -1;
if( chip0 == 128 ) upsigny = -1;
if( chip0 == 130 ) upsigny = -1;
if( chip0 == 137 ) upsigny = -1;
if( chip0 == 139 && run >= 32285 ) upsigny = -1; // Apr 2018
if( chip0 == 142 && run >= 32287 ) upsigny = -1; // Apr 2018
if( chip0 == 144 && run >= 32289 ) upsigny = -1; // Apr 2018
if( chip0 == 145 && run >= 32290 ) upsigny = -1; // Apr 2018
if( chip0 == 146 ) upsigny = -1; // Apr 2018
if( chip0 == 147 ) upsigny = -1; // Apr 2018
if( chip0 == 148 && run >= 32292 ) upsigny = -1; // Apr 2018
if( chip0 == 149 && run >= 32293 ) upsigny = -1; // Apr 2018
if( chip0 == 150 && run >= 32294 ) upsigny = -1; // Apr 2018
if( chip0 == 151 && run >= 32295 ) upsigny = -1; // Apr 2018
if( chip0 == 152 && run >= 32296 ) upsigny = -1; // Apr 2018
if( chip0 == 153 ) upsigny = -1; // Apr 2018
if( chip0 == 155 && run >= 32217 ) upsigny = -1; // Apr 2018
if( chip0 == 156 ) upsigny = -1; // Apr 2018
if( chip0 == 157 ) upsigny = -1; // Apr 2018
if( chip0 == 158 && run >= 32307 ) upsigny = -1; // Apr 2018
if( chip0 == 159 && run >= 32308 ) upsigny = -1; // Apr 2018
if( chip0 == 160 && run >= 32309 ) upsigny = -1; // Apr 2018
if( chip0 == 164 ) upsigny = -1; // Apr 2018
if( chip0 == 165 ) upsigny = -1; // Apr 2018
if( chip0 == 166 ) upsigny = -1; // Apr 2018
if( chip0 == 172 ) upsigny = -1; // Apr 2018
if( chip0 == 173 ) upsigny = -1; // Apr 2018
if( chip0 == 174 && run < 33000 ) upsigny = -1; // Apr 2018
if( chip0 == 175 ) upsigny = -1; // Apr 2018
if( chip0 == 176 ) upsigny = -1; // Apr 2018
if( chip0 == 179 ) upsigny = -1; // Apr 2018
if( chip0 == 191 ) upsigny = -1; // Apr 2018
if( chip0 == 193 ) upsigny = -1; // Apr 2018
if( ( chip0 == 174 || chip0 == 179 || chip0 == 193 || chip0 == 109 ||
chip0 == 115 || chip0 == 120 || chip0 == 108 ) &&
run > 33500 ) {
upsignx = 1;
upsigny = 1; // Sep 2018
}
if( chip0 == 133 && run >= 33500 ) { // 50x50 on straight
upsignx =-1;
upsigny = 1; // Sep 2018
}
if( chip0 == 155 && run >= 33737 ) { // 50x50 on rot90
upsignx = 1;
upsigny = 1; // Sep 2018
}
if( ( chip0 == 166 || chip0 == 173 || chip0 == 175 || chip0 == 192 ) &&
run >= 33740 ) { // 50x50 on straight, cable from below
upsignx =-1;
upsigny = 1;
}
if( run >= 34246 ) { // Oct 2018
upsignx = 1;
upsigny = 1;
}
if( !rot90 && run >= 34246 ) { // Oct 2018
upsignx =-1;
upsigny = 1;
}
if( run >= 35200 ) { // Feb 2019, cable from above
upsignx = -1;
upsigny = -1;
}
if( run >= 35600 ) { // Mar 2019: cable from below
upsignx = 1;
upsigny = 1;
}
if( !rot90 && run >= 36200 ) { // Apr 2019: cable from below
upsignx =-1; // why?
upsigny = 1;
}
cout << endl;
cout << "upsignx " << upsignx << endl;
cout << "upsigny " << upsigny << endl;
int iDUT = 7;
int DUTaligniteration = 0;
double DUTalignx = 0.0;
double DUTaligny = 0.0;
double DUTrot = 0.0;
double DUTtilt = DUTtilt0; // [deg]
double DUTturn = DUTturn0; // [deg]
double DUTz = 0.5*( zz[2] + zz[3] );
ostringstream DUTalignFileName; // output string stream
DUTalignFileName << "alignDUT_" << run << ".dat";
ifstream iDUTalignFile( DUTalignFileName.str() );
cout << endl;
if( iDUTalignFile.bad() || ! iDUTalignFile.is_open() ) {
cout << "no " << DUTalignFileName.str() << ", will bootstrap" << endl;
}
else {
cout << "read DUTalignment from " << DUTalignFileName.str() << endl;
string hash( "#" );
string iteration( "iteration" );
string alignx( "alignx" );
string aligny( "aligny" );
string rot( "rot" );
string tilt( "tilt" );
string turn( "turn" );
string dz( "dz" );
while( ! iDUTalignFile.eof() ) {
string line;
getline( iDUTalignFile, line );
cout << line << endl;
if( line.empty() ) continue;
stringstream tokenizer( line );
string tag;
tokenizer >> tag; // leading white space is suppressed
if( tag.substr(0,1) == hash ) // comments start with #
continue;
if( tag == iteration )
tokenizer >> DUTaligniteration;
double val;
tokenizer >> val;
if( tag == alignx )
DUTalignx = val;
else if( tag == aligny )
DUTaligny = val;
else if( tag == rot )
DUTrot = val;
else if( tag == tilt )
DUTtilt = val;
else if( tag == turn )
DUTturn = val;
else if( tag == dz )
DUTz = val + zz[2];
// anything else on the line and in the file gets ignored
} // while getline
} // alignFile
iDUTalignFile.close();
if( DUTaligniteration <= 1 ) {
DUTtilt = DUTtilt0; // from runs.dat
DUTturn = DUTturn0; // from runs.dat
}
if( rot90 )
cout << "DUT 90 degree rotated" << endl;
// normal vector on DUT surface:
// N = ( 0, 0, -1 ) on DUT, towards -z
// transform into tele system:
// tilt alpha around x
// turn omega around y
const double co = cos( DUTturn*wt );
const double so = sin( DUTturn*wt );
const double ca = cos( DUTtilt*wt );
const double sa = sin( DUTtilt*wt );
const double cf = cos( DUTrot );
const double sf = sin( DUTrot );
const double Nx =-ca*so;
const double Ny = sa;
const double Nz =-ca*co;
const double norm = cos( DUTturn*wt ) * cos( DUTtilt*wt ); // length of Nz
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// DUT gain:
double p0[155][160]; // Fermi
double p1[155][160];
double p2[155][160];
double p3[155][160];
ifstream gainFile( gainFileName );
if( ! gainFile ) {
cout << "gain file " << gainFileName << " not found" << endl;
return 1;
}
else {
cout << endl << "using DUT gain file " << gainFileName << endl;
while( ! gainFile.eof() ) {
int icol;
int irow;
gainFile >> icol;
gainFile >> irow;
gainFile >> p0[icol][irow];
gainFile >> p1[icol][irow];
gainFile >> p2[icol][irow];
gainFile >> p3[icol][irow];
} // while
} // gainFile
double ke = 0.037; // Landau peak at 11 ke chip 102 1002.dat
//if( run >= 31148 ) ke = 0.039; // chip 111 1004.dat
if( run >= 31148 ) ke = 0.0426; // chip 111 1004.dat -V0
if( run >= 31163 ) ke = 0.035; // chip 117 1006.dat
if( run >= 31173 ) ke = 0.037; // chip 117
if( run >= 31210 ) ke = 0.068; // chip 332 3D 230 um at 17.2
if( run >= 31237 ) ke = 0.050; // chip 352 3D 230 um at 17.2
if( run >= 31295 ) ke = 0.040; // chip 143 at 11 ke
if( run >= 31304 ) ke = 0.0385; // chip 144 at 11 ke
if( run >= 31309 ) ke = 0.0274; // chip 142 at 11 ke
//if( run >= 31351 ) ke = 0.025; // chip 142 at 11 ke
if( run >= 31351 ) ke = 0.0282; // chip 142 at 11 ke -V0
//if( run >= 31355 ) ke = 0.039; // chip 144 at 11 ke
if( run >= 31355 ) ke = 0.0438; // chip 144 at 11 ke -V0