forked from pitzl/tele-scope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtele.cc
1448 lines (1117 loc) · 39.7 KB
/
tele.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, Feb 2016
// telescope analysis with eudaq
// triplet pre-alignment
// make tele
// tele -l 9999 13117 # empty telescope Jan 2015, narrow triplet
// tele -g geo_2015_04x.dat 19037 # tilted DUT 504
// tele -g geo_2015_07b.dat 20833 # 66k tilted DUT 504
// tele -g geo_2015_07b.dat 20842 # 521k tilted DUT 504
// tele -g geo_2016_03a.dat 23133
// tele -g geo_2016_03b.dat 23407
#include "eudaq/FileReader.hh"
#include "eudaq/PluginManager.hh"
#include <TFile.h>
#include <TH1I.h>
#include <TH2D.h>
#include <TProfile.h>
#include <TProfile2D.h>
#include <TF1.h>
#include <sstream> // stringstream
#include <fstream> // filestream
#include <map>
#include <set>
using namespace std;
using namespace eudaq;
struct pixel {
int col;
int row;
};
struct cluster {
vector <pixel> vpix;
int size;
int ncol, nrow;
double col, row;
};
struct triplet {
double xm;
double ym;
double zm;
double sx;
double sy;
};
// globals:
pixel pb[999]; // global declaration: vector of pixels with hit
int fNHit; // global
//------------------------------------------------------------------------------
vector<cluster> getClus()
{
// returns clusters with local coordinates
// decodePixels should have been called before to fill pixel buffer pb
// simple clusterization
// cluster search radius fCluCut ( allows fCluCut-1 empty pixels)
const int fCluCut = 1; // clustering: 1 = no gap (15.7.2012)
//const int fCluCut = 2;
vector<cluster> v;
if( fNHit == 0 ) return v;
int* gone = new int[fNHit];
for( int i = 0; i < fNHit; ++i )
gone[i] = 0;
int seed = 0;
while( seed < fNHit ) {
// 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( int i = 0; i < fNHit; ++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;
int minx = 999;
int maxx = 0;
int miny = 999;
int maxy = 0;
for( vector<pixel>::iterator p = c.vpix.begin(); p != c.vpix.end(); ++p ) {
c.col += (*p).col;
c.row += (*p).row;
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;
c.col /= c.size;
c.row /= c.size;
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 < fNHit) && gone[seed] );
} // while over seeds
// nothing left, return clusters
delete gone;
return v;
}
//------------------------------------------------------------------------------
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;
FileReader * reader;
if( run < 100 )
reader = new FileReader( runnum.c_str(), "data/run0000$2R$X");
else if( run < 1000 )
reader = new FileReader( runnum.c_str(), "data/run000$3R$X");
else if( run < 10000 )
reader = new FileReader( runnum.c_str(), "data/run00$4R$X");
else if( run < 100000 )
reader = new FileReader( runnum.c_str(), "data/run0$5R$X");
else
reader = new FileReader( runnum.c_str(), "data/run$6R$X");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// further arguments:
int lev = 999222111; // last event
string geoFileName( "geo.dat" );
for( int i = 1; i < argc; ++i ) {
if( !strcmp( argv[i], "-l" ) )
lev = atoi( argv[++i] ); // last event
if( !strcmp( argv[i], "-g" ) )
geoFileName = argv[++i];
} // argc
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// geometry:
int nx[6]; // x-pixels per plane
int ny[6]; // y-pixels per plane
double sizex[6]; // x size per plane
double sizey[6]; // y size per plane
double ptchx[6]; // x-pixel size
double ptchy[6]; // y-pixel size
double midx[6]; // x mid
double midy[6]; // y mid
double zz[6];
for( int ipl = 0; ipl < 6; ++ipl )
nx[ipl] = 0; // missing plane flag
ifstream geoFile( geoFileName );
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 >= 6 ) {
//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 < 6; ++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();
// for profile plots:
//double drng = 0.1; // narrow spacing
double drng = 0.2; // wide spacing
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// hot pixels:
ostringstream hotFileName; // output string stream
hotFileName << "hot_" << run << ".dat";
ifstream ihotFile( hotFileName.str() );
set <int> hotset[6];
if( ihotFile.bad() || ! ihotFile.is_open() ) {
cout << "Error opening " << hotFileName.str() << endl;
}
// can there be instructions between if and else ? no!
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
} // hotFile
ihotFile.close();
for( int ipl = 0; ipl < 6; ++ipl )
cout << ipl << ": hot " << hotset[ipl].size() << endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// alignments:
int aligniteration = 0;
double alignx[6];
double aligny[6];
double alignz[6];
double rotx[6];
double roty[6];
for( int ipl = 0; ipl < 6; ++ipl ) {
alignx[ipl] = 0.000; // [mm] same sign as dxAB
aligny[ipl] = 0.000; // [mm] same sign as dy
alignz[ipl] = 0.000; // [mm]
rotx[ipl] = 0.0000; // [rad] rot, same sign dxvsy
roty[ipl] = 0.0000; // [rad] rot, opposite sign dyvsx
}
ostringstream alignFileName; // output string stream
alignFileName << "align_" << run << ".dat";
ifstream ialignFile( alignFileName.str() );
if( ialignFile.bad() || ! ialignFile.is_open() ) {
cout << "Error opening " << alignFileName.str() << endl;
}
// can there be instructions between if and else ? no!
else {
cout << "read alignment from " << alignFileName.str() << endl;
string hash( "#" );
string iteration( "iteration" );
string plane( "plane" );
string shiftx( "shiftx" );
string shifty( "shifty" );
string shiftz( "shiftz" );
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 >= 6 ) {
//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 == shiftz ) {
alignz[ipl] = val;
zz[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
} // alignFile
ialignFile.close();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// (re-)create root file:
ostringstream rootFileName; // output string stream
rootFileName << "tele" << run << ".root";
TFile* histoFile = new TFile( rootFileName.str( ).c_str( ), "RECREATE" );
// book histos:
TH1I hnpx[6];
TH1I hcol0[6];
TH1I hrow0[6];
TH1I hcol[6];
TH1I hrow[6];
TH1I hncl[6];
TH1I hsiz[6];
TH1I hncol[6];
TH1I hnrow[6];
TH1I hdx[6];
TH1I hdy[6];
TH1I hdxc[6];
TH1I hdyc[6];
TProfile dxvsy[6];
TProfile dyvsx[6];
for( int ipl = 0; ipl < 6; ++ipl ) {
hnpx[ipl] = TH1I( Form( "npx%i", ipl ),
Form( "%i pixel per event;pixels;%i events", ipl, ipl ),
200, 0, 200 );
hcol0[ipl] = TH1I( Form( "allcol%i", ipl ),
Form( "%i all col;col;%i all pixels", ipl, ipl ),
max( 52, nx[ipl]/4 ), 0, max( 52, nx[ipl]/4 ) );
hrow0[ipl] = TH1I( Form( "allrow%i", ipl ),
Form( "%i all row;row;%i all pixels", ipl, ipl ),
max( 80, ny[ipl]/2 ), 0, max( 80, ny[ipl]/2 ) );
hcol[ipl] = TH1I( Form( "col%i", ipl ),
Form( "%i col;col;%i pixels", ipl, ipl ),
max( 52, nx[ipl]/4 ), 0, max( 52, nx[ipl]/4 ) );
hrow[ipl] = TH1I( Form( "row%i", ipl ),
Form( "%i row;row;%i pixels", ipl, ipl ),
max( 80, ny[ipl]/2 ), 0, max( 80, ny[ipl]/2 ) );
hncl[ipl] = TH1I( Form( "ncl%i", ipl ),
Form( "plane %i cluster per event;cluster;plane %i events", ipl, ipl ),
51, -0.5, 50.5 );
hsiz[ipl] = TH1I( Form( "clsz%i", ipl ),
Form( "%i cluster size;pixels/cluster;%i clusters", ipl, ipl ),
51, -0.5, 50.5 );
hncol[ipl] = TH1I( Form( "ncol%i", ipl ),
Form( "%i cluster size x;columns/cluster;%i clusters", ipl, ipl ),
21, -0.5, 20.5 );
hnrow[ipl] = TH1I( Form( "nrow%i", ipl ),
Form( "%i cluster size y;rows/cluster;%i clusters", ipl, ipl ),
21, -0.5, 20.5 );
hdx[ipl] = TH1I( Form( "dx%im", ipl ),
Form( "%i-m dx;%i-m dx [mm];cluster pairs", ipl, ipl ),
100, -1, 1 );
hdy[ipl] = TH1I( Form( "dy%im", ipl ),
Form( "%i-m dy;%i-m dy [mm];cluster pairs", ipl, ipl ),
100, -1, 1 );
hdxc[ipl] = TH1I( Form( "dxc%im", ipl ),
Form( "%i-m dx;%i-m dx [mm];cluster pairs", ipl, ipl ),
100, -1, 1 );
hdyc[ipl] = TH1I( Form( "dyc%im", ipl ),
Form( "%i-m dy;%i-m dy [mm];cluster pairs", ipl, ipl ),
100, -1, 1 );
dxvsy[ipl] = TProfile( Form( "dx%imvsy", ipl ),
Form( "%i-m dx vs y;y [mm];<%i-m dx> [mm]", ipl, ipl ),
100, -midy[ipl], midy[ipl], -drng, drng );
dyvsx[ipl] = TProfile( Form( "dy%imvsx", ipl ),
Form( "%i-m dy vs x;x [mm];<%i-m dy> [mm]", ipl, ipl ),
100, -midx[ipl], midx[ipl], -drng, drng );
} // planes
TH1I hdxCA[2];
TH1I hdyCA[2];
TH1I htridx[2];
TH1I htridy[2];
TH1I htridxc[2];
TH1I htridyc[2];
TH1I htridxs1[2];
TH1I htridxs2[2];
TH1I htridxs3[2];
TH1I htridxs4[2];
TH1I htridxs5[2];
TH1I htridxc1[2];
TH1I htridxc2[2];
TH1I htridxc3[2];
TH1I htridxc4[2];
TH1I htridxc5[2];
TProfile tridxvsx[2];
TProfile tridxvsy[2];
TProfile tridyvsx[2];
TProfile tridyvsy[2];
TProfile tridxvstx[2];
TProfile tridyvsty[2];
for( int itd = 0; itd < 2; ++itd ) {
string tri("tri");
string dri("dri");
string std(tri);
if( itd )
std = dri;
hdxCA[itd] = TH1I( Form( "%sdxCA", std.c_str() ),
Form( "%splet dx CA;%splet dx CA [mm];C-A pairs",
std.c_str(), std.c_str() ),
100, 1, 1 );
hdyCA[itd] = TH1I( Form( "%sdyCA", std.c_str() ),
Form( "%splet dy CA;%splet dy CA [mm];C-A pairs",
std.c_str(), std.c_str() ),
100, 1, 1 );
htridx[itd] = TH1I( Form( "%sdx", std.c_str() ),
Form( "%splet dx;%splet dx [mm];%splets", std.c_str(), std.c_str(), std.c_str() ),
100, -0.1, 0.1 );
htridy[itd] = TH1I( Form( "%sdy", std.c_str() ),
Form( "%splet dy;%splet dy [mm];%splets", std.c_str(), std.c_str(), std.c_str() ),
100, -0.1, 0.1 );
htridxc[itd] = TH1I( Form( "%sdxc", std.c_str() ),
Form( "%splet dx;%splet dx [mm];%splets", std.c_str(), std.c_str(), std.c_str() ),
100, -0.1, 0.1 );
htridyc[itd] = TH1I( Form( "%sdyc", std.c_str() ),
Form( "%splet dy;%splet dy [mm];%splets", std.c_str(), std.c_str(), std.c_str() ),
100, -0.1, 0.1 );
htridxs1[itd] = TH1I( Form( "%sdxs1", std.c_str() ),
Form( "%splet dx 1-px;1-px %splet dx [mm];1-px %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxs2[itd] = TH1I( Form( "%sdxs2", std.c_str() ),
Form( "%splet dx 2-px;2-px %splet dx [mm];2-px %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxs3[itd] = TH1I( Form( "%sdxs3", std.c_str() ),
Form( "%splet dx 3-px;3-px %splet dx [mm];3-px %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxs4[itd] = TH1I( Form( "%sdxs4", std.c_str() ),
Form( "%splet dx 4-px;4-px %splet dx [mm];4-px %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxs5[itd] = TH1I( Form( "%sdxs5", std.c_str() ),
Form( "%splet dx 5-px;5-px %splet dx [mm];5-px %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxc1[itd] = TH1I( Form( "%sdxc1", std.c_str() ),
Form( "%splet dx 1-col;1-col %splet dx [mm];1-col %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxc2[itd] = TH1I( Form( "%sdxc2", std.c_str() ),
Form( "%splet dx 2-col;2-col %splet dx [mm];2-col %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxc3[itd] = TH1I( Form( "%sdxc3", std.c_str() ),
Form( "%splet dx 3-col;3-col %splet dx [mm];3-col %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxc4[itd] = TH1I( Form( "%sdxc4", std.c_str() ),
Form( "%splet dx 4-col;4-col %splet dx [mm];4-col %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
htridxc5[itd] = TH1I( Form( "%sdxc5", std.c_str() ),
Form( "%splet dx 5-col;5-col %splet dx [mm];5-col %splets",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.05, 0.05 );
tridxvsy[itd] = TProfile( Form( "%sdxvsy", std.c_str() ),
Form( "%splet dx vs y;%splet yB [mm];<%splets #Deltax> [mm]",
std.c_str(), std.c_str(), std.c_str() ),
100, -midy[itd], midy[itd], -0.05, 0.05 );
tridyvsx[itd] = TProfile( Form( "%sdyvsx", std.c_str() ),
Form( "%splet dy vs x;%splet xB [mm];<%splets #Deltay> [mm]",
std.c_str(), std.c_str(), std.c_str() ),
100, -midx[itd], midx[itd], -0.05, 0.05 );
tridxvsx[itd] = TProfile( Form( "%sdxvsx", std.c_str() ),
Form( "%splet dx vs x;%splet xB [mm];<%splets #Deltax> [mm]",
std.c_str(), std.c_str(), std.c_str() ),
100, -midx[itd], midx[itd], -0.05, 0.05 );
tridyvsy[itd] = TProfile( Form( "%sdyvsy", std.c_str() ),
Form( "%splet dy vs y;%splet yB [mm];<%splets #Deltay> [mm]",
std.c_str(), std.c_str(), std.c_str() ),
100, -midy[itd], midy[itd], -0.05, 0.05 );
tridxvstx[itd] =
TProfile( Form( "%sdxvstx", std.c_str() ),
Form( "%splet dx vs tx;%splet slope x [rad];<%splets #Deltax> [mm]",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.002, 0.002, -0.05, 0.05 );
tridyvsty[itd] =
TProfile( Form( "%sdyvsty", std.c_str() ),
Form( "%splet dy vs ty;%splet slope y [rad];<%splets #Deltay> [mm]",
std.c_str(), std.c_str(), std.c_str() ),
100, -0.002, 0.002, -0.05, 0.05 );
} // triplets and driplets
TH1I hntri = TH1I( "ntri", "triplets per event;triplets;events", 21, -0.5, 20.5 );
TH1I hndri = TH1I( "ndri", "driplets per event;driplets;events", 21, -0.5, 20.5 );
TH1I hexdx[6];
TH1I hexdy[6];
TH1I hexdxc[6];
TH1I hexdyc[6];
TProfile exdxvsy[6];
TProfile exdyvsx[6];
TProfile exdxvstx[6];
TProfile exdyvsty[6];
for( int ipl = 3; ipl < 6; ++ipl ) {
hexdx[ipl] = TH1I( Form( "exdx%i", ipl ),
Form( "ex dx %i;dx tri - plane %i [mm];triplet - cluster pairs", ipl, ipl ),
100, -1, 1 );
hexdy[ipl] = TH1I( Form( "exdy%i", ipl ),
Form( "ex dy %i;dy tri - plane %i [mm];triplet - cluster pairs", ipl, ipl ),
100, -1, 1 );
hexdxc[ipl] = TH1I( Form( "exdxc%i", ipl ),
Form( "ex dx %i;dx tri - plane %i [mm];triplet - cluster pairs", ipl, ipl ),
100, -1, 1 );
hexdyc[ipl] = TH1I( Form( "exdyc%i", ipl ),
Form( "ex dy %i;dy tri - plane %i [mm];triplet - cluster pairs", ipl, ipl ),
100, -1, 1 );
exdxvsy[ipl] = TProfile( Form( "exdxvsy%i", ipl ),
Form( "ex dx vs y %i;y at %i [mm];<#Deltax> [mm]", ipl, ipl ),
100, -midy[ipl], midy[ipl], -0.5, 0.5 );
exdyvsx[ipl] = TProfile( Form( "exdyvsx%i", ipl ),
Form( "ex dy vs x %i;x at %i [mm];<#Deltay> [mm]", ipl, ipl ),
100, -midx[ipl], midx[ipl], -0.5, 0.5 );
exdxvstx[ipl] =
TProfile( Form( "exdxvstx%i", ipl ),
Form( "dx vs tx at %i;slope x [rad];<#Deltax> at %i [mm]", ipl, ipl ),
100, -0.002, 0.002, -0.5, 0.5 );
exdyvsty[ipl] =
TProfile( Form( "exdyvsty%i", ipl ),
Form( "dy vs ty at %i;slope y [rad];<#Deltay> at %i [mm]", ipl, ipl ),
100, -0.002, 0.002, -0.5, 0.5 );
} // ipl
// dripets - triplets
TH1I hsixdx = TH1I( "sixdx", "six dx;dx [mm];triplet-driplet pairs", 100, -5, 5 );
TH1I hsixdy = TH1I( "sixdy", "six dy;dy [mm];triplet-driplet pairs", 100, -5, 5 );
TH1I hsixdxc = TH1I( "sixdxc", "six dx;dx [mm];triplet-driplet pairs", 100, -1, 1 );
TH1I hsixdyc = TH1I( "sixdyc", "six dy;dy [mm];triplet-driplet pairs", 100, -1, 1 );
TProfile sixdxvsy =
TProfile( "sixdxvsy",
"six #Deltax vs y;yB [mm];<driplet - triplet #Deltax> [mm]",
100, -5, 5, -0.5, 0.5 );
TProfile sixdyvsx =
TProfile( "sixdyvsx",
"six #Deltay vs x;xB [mm];<driplet - triplet #Deltay> [mm]",
200, -10, 10, -0.5, 0.5 );
TProfile sixdxvstx =
TProfile( "sixdxvstx",
"six #Deltax vs slope x;slope x [rad];<driplet - triplet #Deltax> [mm]",
100, -0.002, 0.002, -0.5, 0.5 );
TProfile sixdyvsty =
TProfile( "sixdyvsty",
"six #Deltay vs slope y;slope y [rad];<driplet - triplet #Deltay> [mm]",
100, -0.002, 0.002, -0.5, 0.5 );
TH1I hsixdslpx =
TH1I( "sixdslpx",
"driplet slope x - triplet slope x;driplet slope x - triplet slope x;driplet-triplet pairs",
100, -0.0025, 0.0025 );
TH1I hsixdslpy =
TH1I( "sixdslpy",
"driplet slope y - triplet slope y;driplet slope y - triplet slope y;driplet-triplet pairs",
100, -0.0025, 0.0025 );
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// event loop:
int event_nr = 0;
uint64_t evTLU0 = 0;
const double fTLU = 384E6; // 384 MHz TLU clock
map < int, int > pxmap[6];
do {
// Get next event:
DetectorEvent evt = reader->GetDetectorEvent();
if( evt.IsBORE() )
eudaq::PluginManager::Initialize(evt);
bool ldbg = 0;
if( event_nr < 1 )
ldbg = 1;
if( lev < 100 )
ldbg = 1;
uint64_t evTLU = evt.GetTimestamp(); // 384 MHz = 2.6 ns
if( event_nr < 2 ) // BORE has older time
evTLU0 = evTLU;
double evsec = (evTLU - evTLU0) / fTLU;
if( event_nr < 10 )
cout<<"Processing event " << event_nr << " time " << evsec << endl;
else if( event_nr < 100 && event_nr%10 == 0 )
cout<<"Processing event " << event_nr << " time " << evsec << endl;
else if( event_nr < 1000 && event_nr%100 == 0 )
cout<<"Processing event " << event_nr << " time " << evsec << endl;
else if( event_nr%1000 == 0 )
cout<<"Processing event " << event_nr << " time " << evsec << endl;
StandardEvent sevt = eudaq::PluginManager::ConvertToStandard(evt);
vector <cluster> cl[6];
for( size_t iplane = 0; iplane < sevt.NumPlanes(); ++iplane) {
const eudaq::StandardPlane &plane = sevt.GetPlane(iplane);
std::vector<double> pxl = plane.GetPixels<double>();
if( ldbg ) std::cout << "PLANE " << plane.ID() << ": ";
// /home/pitzl/eudaq/main/include/eudaq/CMSPixelHelper.hh
int ipl = plane.ID();
if( ipl >= 6 ) continue; // only telescope here
int npx = 0;
for( size_t ipix = 0; ipix < pxl.size(); ++ipix ) {
if( ldbg )
std::cout << plane.GetX(ipix)
<< " " << plane.GetY(ipix)
<< " " << plane.GetPixel(ipix) << " ";
int ix = plane.GetX(ipix); // col pixel index
int iy = plane.GetY(ipix); // row pixel index
hcol0[ipl].Fill( ix );
hrow0[ipl].Fill( iy );
int ipx = ix*ny[ipl] + iy;
if( pxmap[ipl].count(ipx) )
++pxmap[ipl][ipx];
else
pxmap[ipl].insert( make_pair( ipx, 1 ) );
// fill pixel block for clustering:
if( hotset[ipl].count(ipx) ) continue; // skip hot
hcol[ipl].Fill( ix );
hrow[ipl].Fill( iy );
pb[npx].col = ix;
pb[npx].row = iy;
++npx;
if( npx == 999 ) {
cout << "pixel buffer overflow in plane " << ipl
<< ", event " << event_nr
<< endl;
break;
}
} // pix
hnpx[ipl].Fill(npx);
if( ldbg ) std::cout << std::endl;
// clustering:
fNHit = npx; // for cluster search
cl[ipl] = getClus();
if( ldbg ) cout << "A clusters " << cl[ipl].size() << endl;
hncl[ipl].Fill( cl[ipl].size() );
for( vector<cluster>::iterator cA = cl[ipl].begin(); cA != cl[ipl].end(); ++cA ) {
hsiz[ipl].Fill( cA->size );
hncol[ipl].Fill( cA->ncol );
hnrow[ipl].Fill( cA->nrow );
}
} // planes
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// cluster pair correlations:
for( int itd = 0; itd < 2; ++itd ) { // triplets 0-1-2 and driplets 3-4-5
int im = 1; // mid plane triplet
int ibeg = 0;
int iend = 2;
if( itd == 1 ) {
im = 4; // mid plane driplet
ibeg = 3;
iend = 5;
}
for( vector<cluster>::iterator cA = cl[im].begin(); cA != cl[im].end(); ++cA ) {
double xA = cA->col*ptchx[im] - alignx[im];
double yA = cA->row*ptchy[im] - aligny[im];
double xmid = xA - midx[im];
double ymid = yA - midy[im];
xA = xmid - ymid*rotx[im];
yA = ymid + xmid*rotx[im];
for( int ipl = ibeg; ipl <= iend; ++ipl ) {
if( ipl == im ) continue;
for( vector<cluster>::iterator cB = cl[ipl].begin(); cB != cl[ipl].end(); ++cB ) {
double xB = cB->col*ptchx[ipl] - alignx[ipl];
double yB = cB->row*ptchy[ipl] - aligny[ipl];
double xmid = xB - midx[ipl];
double ymid = yB - midy[ipl];
xB = xmid - ymid*rotx[ipl];
yB = ymid + xmid*roty[ipl];
double dx = xB - xA;
double dy = yB - yA;
double dz = zz[ipl] - zz[im]; // signed
hdx[ipl].Fill( dx );
hdy[ipl].Fill( dy );
if( abs(dy) < 0.003 * abs(dz) ) { // beam divergence
hdxc[ipl].Fill( dx );
dxvsy[ipl].Fill( yB, dx );
}
if( abs(dy) < 0.003 * abs(dz) ) { // beam divergence
hdyc[ipl].Fill( dy );
dyvsx[ipl].Fill( xB, dy );
}
} // clusters
} // ipl
} // cl mid
} // upstream and downstream internal correlations
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// triplets 1 vs 2-0:
// driplets 4 vs 5-3:
vector <triplet> triplets;
vector <triplet> driplets;
double tricut = 0.05; // [mm]
for( int itd = 0; itd < 2; ++itd ) { // triplets 0-1-2 and driplets 3-4-5
int im = 1; // mid plane triplet
int ib = 0;
int ie = 2;
if( itd == 1 ) {
im = 4; // mid plane driplet
ib = 3;
ie = 5;
}
for( vector<cluster>::iterator cA = cl[ib].begin(); cA != cl[ib].end(); ++cA ) {
double xA = cA->col*ptchx[ib] - alignx[ib];
double yA = cA->row*ptchy[ib] - aligny[ib];
double xmid = xA - midx[ib];
double ymid = yA - midy[ib];
xA = xmid - ymid*rotx[ib];
yA = ymid + xmid*roty[ib];
double zA = zz[ib];
for( vector<cluster>::iterator cC = cl[ie].begin(); cC != cl[ie].end(); ++cC ) {
double xC = cC->col*ptchx[ie] - alignx[ie];
double yC = cC->row*ptchy[ie] - aligny[ie];
double xmid = xC - midx[ie];
double ymid = yC - midy[ie];
xC = xmid - ymid*rotx[ie];
yC = ymid + xmid*roty[ie];
double zC = zz[ie];
double dx2 = xC - xA;
double dy2 = yC - yA;
double dz02 = zC - zA;
hdxCA[itd].Fill( dx2 );
hdyCA[itd].Fill( dy2 );