forked from pitzl/tele-scope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quad3D.cc
3064 lines (2412 loc) · 96.9 KB
/
quad3D.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, 2016
// read, analyze, and plot eudaq data from 4 CMS pixel modules
// eudecoder
// quad -l 59999 185
// D C B A <-- beam
#include <sstream> // stringstream
#include <fstream> // filestream
#include <iomanip>
#include "eudaq/FileReader.hh"
#include "eudaq/PluginManager.hh"
#include <TFile.h>
#include <TH1D.h>
#include <TH2D.h>
#include <TProfile.h>
#include <TProfile2D.h>
#include <TF1.h>
#include "GblTrajectory.h"
#include <TMatrixD.h>
#include <TMath.h>
#include "MilleBinary.h"
using namespace std;
using namespace gbl;
using namespace eudaq;
struct pixel {
int col;
int row;
int adc;
double cal;
bool big;
int roc;
};
struct cluster {
vector <pixel> vpix;
int roc;
int size;
int sumA; // DP
double charge;
double col,row;
bool big;
int ncol, nrow;
};
// globals:
pixel pb[66560]; // global declaration: vector of pixels with hit
int fNHit; // global
double phi; // will be assigned value in searchRunList function
double tilt = 19.3;
double turn = 27.7;
double pi = 4*atan(1);
double wt = 180/pi;
//------------------------------------------------------------------------------
// inverse decorrelated Weibull PH -> large Vcal DAC
double PHtoVcal( double ph, double a0, double a1, double a2, double a3, double a4, double a5, int mod )
{
// modph2ps decorrelated: ph = a4 - a3*exp(-t^a2), t = a0 + q/a1
//return ph; // test !!
double Ared = ph - a4; // a4 is asymptotic maximum
if( Ared >= 0 ) {
Ared = -0.1; // avoid overflow
}
// large Vcal = ( (-ln(-(A-a4)/a3))^1/a2 - a0 )*a1
if( a3 < 1E-9 ) {
//cout << "PHtoVcal zero a3 " << a3 << endl;
return ph;
}
else if( -Ared > a3 ) {
//cout << "PHtoVcal small a3 " << a3 << " " << -Ared << " mod " << mod << endl;
return ph;
}
double vc =
a1 * ( pow( -log( -Ared / a3 ), 1/a2 ) - a0 );
if( vc > 999 )
cout << "overflow " << vc << ", Ared " << Ared << ", a3 " << a3 << endl;
if( vc != vc ) {
cout << "PHtoVcal NaN at "
<< " " << a0
<< " " << a1
<< " " << a2
<< " " << a3
<< " " << a4
<< " " << a5
<< endl;
return ph;
}
return vc * a5; // small Vcal
//return vc; // large Vcal
}
//------------------------------------------------------------------------------
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.sumA = 0;
c.charge = 0;
c.size = c.vpix.size();
c.col = 0;
c.row = 0;
double sumQ = 0;
c.big = 0;
int minx = 999;
int maxx = 0;
int miny = 999;
int maxy = 0;
bool sameRoc = true;
int prevRoc = 0;
int npx = 0;
for( vector<pixel>::iterator p = c.vpix.begin(); p != c.vpix.end(); ++p ) {
c.sumA += p->adc; // Aout
double Qpix = p->cal; // calibrated [Vcal]
if( Qpix < 0 ) Qpix = 1; // DP 1.7.2012
c.charge += Qpix;
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;
if( npx > 0 && prevRoc != p->roc) sameRoc = false;
prevRoc = p->roc;
npx++;
}
if(sameRoc){
c.roc = prevRoc;
}else{
c.roc = -1;
}
//cout << "(cluster with " << c.vpix.size() << " pixels)" << endl;
if( (!c.charge) == 0 ) {
c.col /= sumQ;
c.row /= sumQ;
}
else {
c.col = (*c.vpix.begin()).col;
c.row = (*c.vpix.begin()).row;
cout << "GetClus: cluster with zero charge" << endl;
}
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;
}
//------------------------------------------------------------------------------
vector <double> global2Local3D ( double x, double y, double z, double mod, double phi )
{
// Function converts global coordinates to local module coordinates
double costilt = cos(tilt/wt);
double sintilt = sin(tilt/wt);
double costurn = cos(turn/wt);
double sinturn = sin(turn/wt);
double cosphi = cos(phi/wt);
double sinphi = sin(phi/wt);
// inverse phi rotation
double x3 = cosphi*x - sinphi*z;
double y3 = y;
double z3 = sinphi*x + cosphi*z;
// inverse Z translation
z3 += 48 - 32*mod;
// inverse omega turn
double x2 = costurn*x3 - sinturn*z3;
double y2 = y3;
double z2 = sinturn*x3 + costurn*z3;
// inverse alpha tilt
double x1 = x2;
double y1 = costilt*y2 - sintilt*z2;
double z1 = sintilt*y2 + costilt*z2;
// return local coordinates
return {x1,y1,z1};
}
//------------------------------------------------------------------------------
TMatrixD Jac5( double ds ) // for GBL
{
/*
straight line, no B-field
track =
q/p, x', y', x, y
0, 1, 2, 3, 4
*/
TMatrixD jac(5, 5);
jac.UnitMatrix();
jac[3][1] = ds; // x = xp * ds
jac[4][2] = ds; // y = yp * ds
return jac;
}
//------------------------------------------------------------------------------
Double_t landau_gauss_peak(TH1* h);
//------------------------------------------------------------------------------
bool isFiducial( double x, double y)
{
bool ffiducial = true;
if(y < -(8.1-0.3-0.06) || y > (8.1-0.3-0.06)
|| x < -(32.4-0.45-0.06) || x > (32.4-0.45-0.06)) ffiducial = false;
return ffiducial;
}
//------------------------------------------------------------------------------
int searchRunlist(int runnr, double &momentum, int *modName, bool &CCSuppressed){
ifstream runlistFile( "runlist-quad3D.dat" );
cout << endl;
if( runlistFile.bad() || ! runlistFile.is_open() ) {
cout << "runlist-quad3D.dat could not be found." << endl;
return -1;
}
else {
cout << "Reading runlist." << endl;
int currentRunnr;
double currentMomentum;
int currentModNames[4];
int currentCCSuppressed = 0;
while( ! runlistFile.eof() ) {
currentCCSuppressed = 0;
string line;
getline( runlistFile, line );
if( line.empty() ) continue;
if( line.at(0) == '#' ) continue;
stringstream thisline(line);
thisline >> currentRunnr >> currentMomentum >> phi;
for(int mod = 0; mod < 4; mod++){
thisline >> currentModNames[mod];
}
thisline >> currentCCSuppressed;
if(!(currentRunnr && currentModNames[0] && currentModNames[1] && currentModNames[2] && currentModNames[3])){
continue; // No correct data in runlist
}
if(currentRunnr == runnr){
cout << "Found entry in runlist:" << endl;
cout << line << endl;
momentum = currentMomentum;
for(int mod = 0; mod < 4; mod++){
modName[mod] = currentModNames[mod];
}
CCSuppressed = currentCCSuppressed;
runlistFile.close();
return 1;
}
}
cout << "Run " << runnr << " not found in runlist-quad3D.dat. Please add it." << endl;
runlistFile.close();
return -2;
}
}
//------------------------------------------------------------------------------
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] );
// Searching for entry in runlist
double p;
int modName[4];
bool CCSupressed = false;
bool writeEfficiency = false;
if(searchRunlist(run, p, modName, CCSupressed) < 0){
exit(0);
}
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
for( int i = 1; i < argc; ++i ) {
if( !strcmp( argv[i], "-l" ) )
lev = atoi( argv[++i] );
// Suppress conversion factor correction
if( !strcmp( argv[i], "-c" ) )
CCSupressed = true;
if( !strcmp( argv[i], "-e" ) )
writeEfficiency = true;
} // argc
// alignments:
double dz = 22.5; // [mm] projected z spacing
if( run > 150 )
dz = 40.0;
int aligniteration = 0;
double alignx[4];
double aligny[4];
double fx[4];
double fy[4];
double tx[4];
double ty[4];
for( int ipl = 0; ipl < 4; ++ipl ) {
alignx[ipl] = 0;
aligny[ipl] = 0;
fx[ipl] = 0;
fy[ipl] = 0;
tx[ipl] = 0;
ty[ipl] = 0;
}
ostringstream alignFileName; // output string stream
alignFileName << "align_" << run << ".dat";
ifstream ialignFile( alignFileName.str() );
cout << endl;
if( ialignFile.bad() || ! ialignFile.is_open() ) {
cout << "no " << alignFileName.str() << ", will bootstrap" << endl;
cout << endl;
}
else {
cout << "read alignment from " << alignFileName.str() << endl;
string Hash( "#" );
string Iteration( "iteration" );
string Plane( "plane" );
string Alignx( "alignx" );
string Aligny( "aligny" );
string Rx( "fx" );
string Ry( "fy" );
string Tx( "tx" );
string Ty( "ty" );
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 >= 4 ) {
//cout << "wrong plane number " << ipl << endl;
continue;
}
double val;
tokenizer >> val;
if( tag == Alignx )
alignx[ipl] = val;
else if( tag == Aligny )
aligny[ipl] = val;
else if( tag == Rx )
fx[ipl] = val;
else if( tag == Ry )
fy[ipl] = val;
else if( tag == Tx )
tx[ipl] = val;
else if( tag == Ty )
ty[ipl] = val;
// anything else on the line and in the file gets ignored
} // while getline
} // alignFile
ialignFile.close();
// for GBL:
double resx = 9.9E-3; // [mm] col hit resolution
double resy = 7.7E-3; // [mm] row hit resolution
// X0 Si = 21.82/2.33 = 9.365 cm
// X0 Al = 24.01/2.70 = 8.89 cm
// X0 Cu = 12.86/8.96 = 1.435 cm
// X0 air = 36.62/1.204E-3 = 304 m
double X0Si = ( 0.3 + 0.175 + 3.0 ) / 94; // Sensor + ROC + Alu
// measurement = residual
TVectorD meas(2);
meas.Zero(); // ideal
TVectorD measPrec(2); // precision = 1/resolution^2
measPrec[0] = 1.0 / resx / resx;
measPrec[1] = 1.0 / resy / resy;
TMatrixD proL2m( 2, 2 ); // measurement projection matrix
proL2m.UnitMatrix();
// scatter:
TVectorD scat(2);
scat.Zero(); // mean is zero
double tetSi = 0.0136 * sqrt(X0Si) / p * ( 1 + 0.038*log(X0Si) );
// pair matching cuts:
double bicutx = 5E-3*dz; // [mm]
double bicuty = 5E-3*dz; // [mm]
// triplet linking cuts:
double tricutx = 0.06; // [mm]
double tricuty = 0.06; // [mm]
if( tricutx < 3*dz*tetSi ) {
tricutx = 3*dz*tetSi;
tricuty = 3*dz*tetSi;
}
cout << "\nlinking cuts " << tricutx << ", " << tricuty << " mm\n" << endl;
TVectorD wscatSi(2);
wscatSi[0] = 1.0 / ( tetSi * tetSi ); // weight
wscatSi[1] = 1.0 / ( tetSi * tetSi );
// global labels for Pede:
vector<int> labelsA( 6 );
labelsA[0] = 1; // dx
labelsA[1] = 2; // dy
labelsA[2] = 3; // fx
labelsA[3] = 4; // fy
labelsA[4] = 5; // tx
labelsA[5] = 6; // ty
vector<int> labelsB( 6 );
labelsB[0] = 7; // dx
labelsB[1] = 8; // dy
labelsB[2] = 9; // fx
labelsB[3] = 10; // fy
labelsB[4] = 11; // tx
labelsB[5] = 12; // ty
vector<int> labelsC( 6 );
labelsC[0] = 13; // dx
labelsC[1] = 14; // dy
labelsC[2] = 15; // fx
labelsC[3] = 16; // fy
labelsC[4] = 17; // tx
labelsC[5] = 18; // ty
vector<int> labelsD( 6 );
labelsD[0] = 19; // dx
labelsD[1] = 20; // dy
labelsD[2] = 21; // fx
labelsD[3] = 22; // fy
labelsD[4] = 23; // tx
labelsD[5] = 24; // ty
MilleBinary * mille = new MilleBinary( "mille.bin" );
// Landau peak cuts: Mon 27.7.2015
double qL = 20; // [ke]
double qR = 36; // [ke]
string gainFileName[4];
double ke[4][16];
for(int mod = 0; mod < 4; mod++){
for(int roc = 0; roc < 16; roc++){
ke[mod][roc] = -1.;
}
}
const int A = 0;
const int B = 1;
const int C = 2;
const int D = 3;
// Get gaincal files
if( run >= 435 ) { // 2016 May
stringstream gainstream;
for(int mod = 0; mod < 4; mod++){
gainstream << "gaincal/D" << modName[mod] << "-tb24-gaincal.dat";
gainFileName[mod] = gainstream.str();
gainstream.str("");
}
}
// Get ke (conversion small Vcal -> e-)
double norm = 1*TMath::Cos(0.3368485)*TMath::Cos(0.4852015);
ostringstream conversionFileName; // output string stream
conversionFileName << "conversion_" << run << ".dat";
ifstream conversionFile( conversionFileName.str() );
cout << endl;
if( conversionFile.bad() || ! conversionFile.is_open() ) {
cout << "no " << conversionFileName.str() << ", will bootstrap" << endl;
cout << endl;
}else{
int modNr;
int rocNr;
double keVal;
while(conversionFile >> modNr >> rocNr >> keVal){
ke[modNr][rocNr] = keVal;
}
}
for(int mod = 0; mod < 4; mod++){
for(int roc = 0; roc < 16; roc++){
if(ke[mod][roc] < 0.) ke[mod][roc] = 0.045;
}
}
cout << "Roc-wise conversion factors:";
for(int mod = 0; mod < 4; mod++){
cout << endl << modName[mod] << ":\t";
for(int roc = 0; roc < 16; roc++){
cout << setprecision(4) << ke[mod][roc] << " ";
}
}
cout << endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// gain parameters for mod roc col row:
double ****p0 = new double ***[4];
for( int i = 0; i < 4; ++i )
p0[i] = new double **[16];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
p0[i][j] = new double *[52];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
for( int k = 0; k < 52; ++k )
p0[i][j][k] = new double[80];
double ****p1 = new double ***[4];
for( int i = 0; i < 4; ++i )
p1[i] = new double **[16];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
p1[i][j] = new double *[52];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
for( int k = 0; k < 52; ++k )
p1[i][j][k] = new double[80];
double ****p2 = new double ***[4];
for( int i = 0; i < 4; ++i )
p2[i] = new double **[16];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
p2[i][j] = new double *[52];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
for( int k = 0; k < 52; ++k )
p2[i][j][k] = new double[80];
double ****p3 = new double ***[4];
for( int i = 0; i < 4; ++i )
p3[i] = new double **[16];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
p3[i][j] = new double *[52];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
for( int k = 0; k < 52; ++k )
p3[i][j][k] = new double[80];
double ****p4 = new double ***[4];
for( int i = 0; i < 4; ++i )
p4[i] = new double **[16];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
p4[i][j] = new double *[52];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
for( int k = 0; k < 52; ++k )
p4[i][j][k] = new double[80];
double ****p5 = new double ***[4];
for( int i = 0; i < 4; ++i )
p5[i] = new double **[16];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
p5[i][j] = new double *[52];
for( int i = 0; i < 4; ++i )
for( int j = 0; j < 16; ++j )
for( int k = 0; k < 52; ++k )
p5[i][j][k] = new double[80];
bool haveGain[4] = {0};
for( int mod = 0; mod < 4; ++mod ) {
if( gainFileName[mod].length( ) > 0 ) {
ifstream gainFile( gainFileName[mod].c_str() );
if( gainFile ) {
haveGain[mod] = 1;
cout << "gain " << mod << ": " << gainFileName[mod] << endl;
int roc;
int col;
int row;
double a0, a1, a2, a3, a4, a5;
while( gainFile >> roc ) {
gainFile >> col;
gainFile >> row;
gainFile >> a0;
gainFile >> a1;
gainFile >> a2;
gainFile >> a3;
gainFile >> a4;
gainFile >> a5;
p0[mod][roc][col][row] = a0;
p1[mod][roc][col][row] = a1;
p2[mod][roc][col][row] = a2;
p3[mod][roc][col][row] = a3;
p4[mod][roc][col][row] = a4;
p5[mod][roc][col][row] = a5;
}
} // gainFile open
} // gainFileName
} // mod
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// (re-)create root file:
ostringstream fname; // output string stream
fname << "quad-" << run << ".root";
TFile* histoFile = new TFile( fname.str( ).c_str( ), "RECREATE" );
// book histos:
TH1D hcol[4];
TH1D hrow[4];
TH1D hpxq[4];
TH2D * hmap[4];
TH1D hnpx[4];
TH1D hsiz[4];
TH1D hclq[4];
TH1D hclq0[4];
TH1D hclq0r[4][16];
TH1D hclq0g[4];
TH1D hncol[4];
TH1D hnrow[4];
TH1D heffRoc[4];
TH2D * hxy[4];
TH2D * hxylocal[4];
TProfile effvsRoc[4];
TH1D hncl[4];
for( int mod = 0; mod < 4; ++mod ) {
char modtos;
switch( mod ) {
case 0: modtos = 'A'; break;
case 1: modtos = 'B'; break;
case 2: modtos = 'C'; break;
case 3: modtos = 'D'; break;
default:modtos = 'X';
}
hncl[mod] = TH1D( Form( "ncl%c", modtos ),
Form( "plane %c cluster per event;cluster;plane %c events", modtos, modtos ),
51, -0.5, 50.5 );
hcol[mod] = TH1D( Form("col%c", modtos),
Form("%c col;col;%c pixels", modtos, modtos),
416, -0.5, 415.5 );
hrow[mod] = TH1D( Form("row%c",modtos),
Form("%c row;row;%c pixels",modtos,modtos),
160, -0.5, 159.5 );
hpxq[mod] = TH1D( Form("pxq%c",modtos),
Form("%c pixel charge;pixel q [ke];%c pixels",modtos,modtos),
100, 0, 25 );
hmap[mod] = new TH2D( Form("pxmap%c",modtos),
Form("%c pixel map;column;row;%c pixels",modtos,modtos),
416, -0.5, 415.5, 160, -0.5, 159.5 );
hnpx[mod] = TH1D( Form("npx%c",modtos),
Form("%c pixel per event;pixels;%c events",modtos,modtos),
51, -0.5, 50.5 );
hsiz[mod] = TH1D( Form("clsz%c",modtos),
Form("%c cluster size;pixels/cluster;%c clusters",modtos,modtos),
51, -0.5, 50.5 );
hclq[mod] = TH1D( Form("clq%c",modtos),
Form("%c cluster charge;cluster charge [ke];%c clusters",modtos,modtos),
100, 0, 100 );
hclq0[mod] = TH1D( Form("clq0%c",modtos),
Form("%c normalized cluster charge;norm. cluster charge [ke];%c clusters",modtos,modtos),
100, 0, 100 );
for( int roc = 0; roc < 16; ++roc ) {
hclq0r[mod][roc] = TH1D( Form("clq0%c%d",modtos,roc),
Form("%c, ROC %d, normalized cluster charge;norm. cluster charge [ke];%c clusters",modtos,roc,modtos),
100, 0, 100 );
}
hclq0g[mod] = TH1D( Form("clq0%cg",modtos),
Form("%c, between ROCs, normalized cluster charge;norm. cluster charge [ke];%c clusters",modtos,modtos),
100, 0, 100 );
hncol[mod]= TH1D( Form("ncol%c",modtos),
Form("%c cluster size;columns/cluster;%c clusters",modtos,modtos),
21, -0.5, 20.5 );
hnrow[mod]= TH1D( Form("nrow%c",modtos),
Form("%c cluster size;rows/cluster;%c clusters",modtos,modtos),
21, -0.5, 20.5 );
heffRoc[mod]= TH1D( Form("effRoc%c",modtos),
Form("eff%c per ROC;efficiency;ROCs",modtos),
25, 0.995, 1.0);
effvsRoc[mod]= TProfile( Form("eff%cvsRoc",modtos),
Form("eff%c vs ROC;ROC;eff %c",modtos,modtos),
16,-0.5,15.5, -1, 2);
hxy[mod] = new
TH2D( Form( "xy%c", modtos ),
Form( "back view;x [mm];y [mm];%c clusters", modtos ),
432, -32.4, 32.4, 162, -8.1, 8.1 );
hxylocal[mod] = new
TH2D( Form( "xy%c_LOCAL", modtos ),
Form( "back view;x [mm];y [mm];%c clusters LOCAL", modtos ),
432, -32.4, 32.4, 162, -8.1, 8.1 );
} // module planes
TH2D * hzy = new
TH2D( "zy", "side view (beam from right: A B C D) ;-z [mm];y [mm];clusters",
1400, -70.0, 70.0, 162, -8.1, 8.1 );
TH2D * hxz = new
TH2D( "xz", "top view (beam downwards: A B C D);x [mm];-z [mm];clusters",
800, -40, 40, 1400, -70.0, 70.0 );
TH2D * hzylocal = new
TH2D( "zy_local", "side view (beam from right: A B C D) ;-z [mm];y [mm];clusters",
1400, -70.0, 70.0, 162, -8.1, 8.1 );
TH2D * hxzlocal = new
TH2D( "xz_local", "top view (beam downwards: A B C D);x [mm];-z [mm];clusters",
800, -40, 40, 1400, -70.0, 70.0 );
TH2D hxxAB( "xxAB", "A vs B;col B;col A;clusters",
432, -32.4, 32.4, 432, -32.4, 32.4 );
TH2D hyyAB( "yyAB", "A vs B;row B;row A;clusters",
162, -8.1, 8.1, 162, -8.1, 8.1 );
TH1D hdxAB( "dxAB", "Ax-Bx;x-x [mm];cluster pairs", 200, -5, 5 );
TH1D hdyAB( "dyAB", "Ay-By;y-y [mm];cluster pairs", 200, -5, 5 );
TH1D hdxcAB( "dxcAB", "Ax-Bx;x-x [mm];cluster pairs", 200, -1, 1 );
TH1D hdycAB( "dycAB", "Ay-By;y-y [mm];cluster pairs", 200, -1, 1 );
TProfile dxvsxAB( "dxvsxAB", "A-B dx vs x;x [mm];A-B <dx>",
216, -32.4, 32.4, -1, 1 );
TProfile dxvsyAB( "dxvsyAB", "A-B dx vs y;y [mm];A-B <dx>",
81, -8.1, 8.1, -1, 1 );
TProfile dyvsxAB( "dyvsxAB", "A-B dy vs x;x [mm];A-B <dy>",
216, -32.4, 32.4, -1, 1 );
TProfile dyvsyAB( "dyvsyAB", "A-B dy vs y;y [mm];A-B <dy>",
81, -8.1, 8.1, -1, 1 );
TProfile mABvst( "mABvst", "AB matches vs time;trigger;AB matches",
200, 0E6, 2E6, -1, 2 );
TH2D hxxCB( "xxCB", "C vs B;col B;col C;clusters",
432, -32.4, 32.4, 432, -32.4, 32.4 );
TH2D hyyCB( "yyCB", "C vs B;row B;row C;clusters",
162, -8.1, 8.1, 162, -8.1, 8.1 );
TH1D hdxCB( "dxCB", "Cx-Bx;x-x [mm];cluster pairs", 200, -5, 5 );
TH1D hdyCB( "dyCB", "Cy-By;y-y [mm];cluster pairs", 200, -5, 5 );
TH1D hdxcCB( "dxcCB", "Cx-Bx;x-x [mm];cluster pairs", 200, -1, 1 );
TH1D hdycCB( "dycCB", "Cy-By;y-y [mm];cluster pairs", 200, -1, 1 );
TProfile dxvsxCB( "dxvsxCB", "C-B dx vs x;x [mm];C-B <dx>",
216, -32.4, 32.4, -1, 1 );
TProfile dxvsyCB( "dxvsyCB", "C-B dx vs y;y [mm];C-B <dx>",
81, -8.1, 8.1, -1, 1 );
TProfile dyvsxCB( "dyvsxCB", "C-B dy vs x;x [mm];C-B <dy>",
216, -32.4, 32.4, -1, 1 );
TProfile dyvsyCB( "dyvsyCB", "C-B dy vs y;y [mm];C-B <dy>",
81, -8.1, 8.1, -1, 1 );
TProfile mCBvst( "mCBvst", "CB matches vs time;trigger;CB matches",
200, 0E6, 2E6, -1, 2 );
TH2D hxxDB( "xxDB", "D vs B;col B;col D;clusters",
432, -32.4, 32.4, 432, -32.4, 32.4 );
TH2D hyyDB( "yyDB", "D vs B;row B;row D;clusters",
162, -8.1, 8.1, 162, -8.1, 8.1 );
TH1D hdxDB( "dxDB", "Dx-Bx;x-x [mm];cluster pairs", 200, -5, 5 );
TH1D hdyDB( "dyDB", "Dy-By;y-y [mm];cluster pairs", 200, -5, 5 );
TH1D hdxcDB( "dxcDB", "Dx-Bx;x-x [mm];cluster pairs", 200, -1, 1 );
TH1D hdycDB( "dycDB", "Dy-By;y-y [mm];cluster pairs", 200, -1, 1 );
TProfile dxvsxDB( "dxvsxDB", "D-B dx vs x;x [mm];D-B <dx>",
216, -32.4, 32.4, -1, 1 );
TProfile dxvsyDB( "dxvsyDB", "D-B dx vs y;y [mm];D-B <dx>",
81, -8.1, 8.1, -1, 1 );
TProfile dyvsxDB( "dyvsxDB", "D-B dy vs x;x [mm];D-B <dy>",
216, -32.4, 32.4, -1, 1 );
TProfile dyvsyDB( "dyvsyDB", "D-B dy vs y;y [mm];D-B <dy>",
81, -8.1, 8.1, -1, 1 );
TProfile mDBvst( "mDBvst", "DB matches vs time;trigger;DB matches",
200, 0E6, 2E6, -1, 2 );
// triplets ACB:
TH1D hdxACB( "dxACB", "ACB dx;x-x [mm];ACBs", 200, -1, 1 );
TH1D hdyACB( "dyACB", "ACB dy;y-y [mm];ACBs", 200, -1, 1 );
TH1D hdxcACB( "dxcACB", "ACB dx;x-x [um];ACBs", 200, -200, 200 );
TH1D hdycACB( "dycACB", "ACB dy;y-y [um];ACBs", 200, -200, 200 );
TH1D hdxciACB( "dxciACB", "ACB dx;x-x [um];isolated ACBs",
200, -200, 200 );
TH1D hdyciACB( "dyciACB", "ACB dy;y-y [um];isolated ACBs",
200, -200, 200 );
TH1D hdycfACB( "dycfACB", "ACB dy;y-y [um];inner ACBs",
200, -200, 200 );
TH1D hdycfqACB( "dycfqACB", "ACB dy;y-y [um];Landau peak inner ACBs",
200, -200, 200 );
TProfile dxvsxACB( "dxvsxACB",
"ACB dx vs x;x [mm];ACB <dx>",
216, -32.4, 32.4, -1, 1 );
TProfile dxvsyACB( "dxvsyACB",
"ACB dx vs y;y [mm];ACB <dx>",
81, -8.1, 8.1, -1, 1 );
TProfile dyvsxACB( "dyvsxACB",
"ACB dy vs x;x [mm];ACB <dy>",
216, -32.4, 32.4, -1, 1 );
TProfile dyvsyACB( "dyvsyACB",
"ACB dy vs y;y [mm];ACB <dy>",
81, -8.1, 8.1, -1, 1 );
TProfile madyvsyACB( "madyvsyACB",
"ACB mady vs y;y [mm];ACB MAD(y) [um]",
81, -8.1, 8.1, 0, 100 );
TH2D * hmapACB;
hmapACB = new TH2D( "mapACB",
"ACBplet map;ACBplet col;ACBplet row;ACBplets",
8*54, -4*8.1, 4*8.1, 2*81, -8.1, 8.1 );
TH1D htxACB( "txACB", "tri angle ACB x;tri angle ACB x [mrad];ACB triplets", 100, -10, 10 );
TH1D htyACB( "tyACB", "tri angle ACB y;tri angle ACB y [mrad];ACB triplets", 100, -10, 10 );
// linked D:
TH1D hsizD3( "clszD3", "D cluster size;pixels/cluster;D3 clusters",
51, -0.5, 50.5 );
TH1D hclqD3( "clqD3", "D cluster charge;cluster charge [ke];D3 clusters",
100, 0, 100 );