Repository navigation
Expand file tree
/
Copy pathdrei_reader.cc_bckp
More file actions
3469 lines (2741 loc) · 128 KB
/
Copy pathdrei_reader.cc_bckp
File metadata and controls
3469 lines (2741 loc) · 128 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Daniel Pitzl (DESY) Sep 2017
// Jan 2018: version for openMP (faster)
// 3 x R4S, 25x100 or 50x50 on rot90 PCB
// drei 338
// drei -l 99999 866
// drei -p 1.2 876
// drei -p 6 885
// drei -p 4.8 998
// drei -p 6.0 -l 81000 1010
// drei -p 6.0 -l 546000 1019
// drei -p 6.0 1020 (2.1M)
// drei -p 5.6 -f 1024 (50x50)
// ****************************use flag: '-p beamEnergy' to change the beam energy! ***********************************
// drei 1757
// drei -f 1842 ************* -f is the option for 50x50 **********************
// drei -f 1894
#include <cstdlib> // atoi
#include <iostream> // cout
#include <iomanip> // setw
#include <string> // strings
#include <sstream> // stringstream
#include <fstream> // files
#include <vector>
#include <list>
#include <cmath>
#include <time.h> // clock_gettime
#include <sched.h> // getcpu
#include <sys/resource.h>
#include <unistd.h>
#include <TFile.h>
#include <TH1.h>
#include <TH2.h>
#include <TProfile.h>
#include <TProfile2D.h>
#include <TF1.h>
#include <TCanvas.h>
#include <TStyle.h>
#include "./drei_reader.h"
bool PRINT = true;
bool DOALIGNMENT = false;
bool DPHCUT = false;
bool DEBUG = false;
//------------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
//std::ios_base::sync_with_stdio( false ); // faster read ?
cout << "main " << argv[0] << " called with " << argc << " arguments" << endl;
if( argc == 1 ) {
cout << "give run number" << endl;
return 1;
}
// file name = last argument:
string runnum( argv[argc-1] );
int run = atoi( argv[argc-1] );
// further arguments:
int Nev = 20*1000*1000;
// bool fifty = 0;
int alignversion = 1;
for( int i = 1; i < argc; ++i ) {
if( !strcmp( argv[i], "-l" ) )
Nev = atoi( argv[++i] );
// if( !strcmp( argv[i], "-p" ) )
// beamEnergy = atof( argv[++i] );
// if( !strcmp( argv[i], "-f" ) )
// fifty = 1;
if( !strcmp( argv[i], "-a" ) )
alignversion = atoi( argv[++i] );
} // argc
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//ALIGN
//read from ALIGN file, now containing also calibration, pitch, beam energy, etc.
string alignpath = "align/";
int aligniteration = 0;
double alignxA = 0.0; // [mm] same sign as dx
double alignyA = 0.0; // [mm] same sign as dy
double alignfA = 0.0; // [rad] same sign dxvsy
double alignxC = 0.0; // [mm] same sign as dx
double alignyC = 0.0; // [mm] same sign as dy
double alignfC = 0.0; // [rad] same sign dxvsy
string gainA = "a ";
string gainB = "b ";
string gainC = "c ";
double keA = 0.0;
double keB = 0.0;
double keC = 0.0;
int pitch = 0;
double ptchc = 0.0;// 0.100; // [mm] col size
double ptchr = 0.0;//0.025; // [mm] row size
double beamEnergy = -1.0; // [GeV]
double qL = 0;
double qR = 0;
double qLB = 0;
double qRB = 0;
double Tsunami[DreiMasterPlanes];
double dphcut[DreiMasterPlanes];
double dx3corr;
string alignFileName = "0";
if(alignversion == 1)
alignFileName = alignpath+"align_" + runnum + ".dat";
if(alignversion == 2)
alignFileName = alignpath+"align_v2_" + runnum + ".dat";
if(alignversion == 3)
alignFileName = alignpath+"align_v3_" + runnum + ".dat";
ifstream alignFile( alignFileName );
cout << endl;
if( alignFile.bad() || ! alignFile.is_open() ) {
cout << "no " << alignFileName << ", will bootstrap" << endl;
}
else {
cout << "read alignment from " << alignFileName << endl;
string HASH( "#" );
string ITER( "iteration" );
string ALXA( "alignxA" );
string ALYA( "alignyA" );
string ALFA( "alignfA" );
string ALXC( "alignxC" );
string ALYC( "alignyC" );
string ALFC( "alignfC" );
string GAINA( "gainA" );
string GAINB( "gainB" );
string GAINC( "gainC" );
string KEA( "keA" );
string KEB( "keB" );
string KEC( "keC" );
string BEAMENERGY( "beamEnergy" );
string PITCH( "pitch" );
string QL( "qL" );
string QR( "qR" );
string QLB( "qLB" );
string QRB( "qRB" );
string TSUNAMIA( "TsunamiA" );
string TSUNAMIB( "TsunamiB" );
string TSUNAMIC( "TsunamiC" );
string DPHCUTA( "dphcutA" );
string DPHCUTB( "dphcutB" );
string DPHCUTC( "dphcutC" );
string DX3C( "dx3c" );
while( ! alignFile.eof() ) {
string line;
getline( alignFile, 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 == ITER )
tokenizer >> aligniteration;
if( tag == ALXA )
tokenizer >> alignxA;
else if( tag == ALYA )
tokenizer >> alignyA;
else if( tag == ALFA )
tokenizer >> alignfA;
else if( tag == ALXC )
tokenizer >> alignxC;
else if( tag == ALYC )
tokenizer >> alignyC;
else if( tag == ALFC )
tokenizer >> alignfC;
else if( tag == GAINA )
tokenizer >> gainA;
else if( tag == GAINB )
tokenizer >> gainB;
else if( tag == GAINC )
tokenizer >> gainC;
else if( tag == KEA )
tokenizer >> keA;
else if( tag == KEB )
tokenizer >> keB;
else if( tag == KEC )
tokenizer >> keC;
else if( tag == BEAMENERGY )
tokenizer >> beamEnergy;
else if( tag == PITCH )
tokenizer >> pitch;
else if( tag == QL )
tokenizer >> qL;
else if( tag == QR )
tokenizer >> qR;
else if( tag == QLB )
tokenizer >> qLB;
else if( tag == QRB )
tokenizer >> qRB;
else if( tag == TSUNAMIA )
tokenizer >> Tsunami[0];
else if( tag == TSUNAMIB )
tokenizer >> Tsunami[1];
else if( tag == TSUNAMIC )
tokenizer >> Tsunami[2];
else if( tag == DPHCUTA )
tokenizer >> dphcut[0];
else if( tag == DPHCUTB )
tokenizer >> dphcut[1];
else if( tag == DPHCUTC )
tokenizer >> dphcut[2];
else if( tag == DX3C )
tokenizer >> dx3corr;
// anything else on the line and in the file gets ignored
} // while getline
alignFile.close();
} // alignFile
double cfA = cos(alignfA);
double sfA = sin(alignfA);
double cfC = cos(alignfC);
double sfC = sin(alignfC);
if(PRINT) cout << "Gains " << gainA << " " << gainB << " " << gainC << endl;
if(PRINT) cout << " alignfA " << alignfA << endl;
ke[A] = keA; // Landau peak at 11 ke
ke[B] = keB; // Landau peak at 11 ke
ke[C] = keC; // Landau peak at 11 ke
getGain( gainA, p0, p1, p2, p3, 0);
getGain( gainB, p0, p1, p2, p3, 1);
getGain( gainC, p0, p1, p2, p3, 2);
if(pitch == 25)
{
ptchc = 0.100; // [mm] col size
ptchr = 0.025; // [mm] row size
}
if(pitch == 50)
{
fifty = true;
ptchc = 0.050;
ptchr = 0.050;
}
double beamDivergenceScaled = 5/beamEnergy; // 5sigma/energy
//----------------------------------------------------------------------------------
// (re-)create root file:
TString fileName;
fileName.Form( "/home/zoiirene/Output/drei-r%i_irene.root", run );
if(DPHCUT)
{
int i_dph = (int) dphcut[1];
// stringstream stream;
//stream << fixed << setprecision(3) << dphcut[1];
//string s = stream.str();
fileName.Form( "/home/zoiirene/Output/drei-r%i_irene_dphcut%i.root", run,i_dph);
}
TFile * histoFile = new TFile( fileName, "RECREATE" ); //Form( "/home/zoiirene/Output/drei-r%i_irene.root", run ), "RECREATE" );
// book histos:
if(PRINT) cout << "***** going to book hists ***********" << endl;
bookHists();
histoMap raw = bookControlHists("raw",histoFile);
histoMap dxCAcut = bookControlHists("dxCAcut",histoFile);
histoMap beforeCorrections = bookControlHists("beforeCorrections",histoFile);
if(PRINT) cout << "hists booking whit new method"<<endl;
histoMap nocuts = bookControlHists("nocuts",histoFile);
if(PRINT) cout << " booked! " <<endl;
if(PRINT)
{
bool found = false;
auto it = nocuts.find("xA_nocuts");
if(it != nocuts.end())
{
found = true;
std::cout<<it->first<<" :: "<<it->second->GetEntries()<<std::endl;
it++;
}
cout << "hists cuts " << found << endl;
}
histoMap straightTracksY = bookControlHists("straightTracksY",histoFile);
histoMap straightTracksY_isoAandC = bookControlHists("straightTracksY_isoAandC",histoFile);
histoMap straightTracksY_isoAandCandB = bookControlHists("straightTracksY_isoAandCandB",histoFile);
histoMap straightTracksY_isoAandCandB_straightTracksX = bookControlHists("straightTracksY_isoAandCandB_straightTracksX",histoFile);
histoMap straightTracksY_isoAandCandB_chargerAandC = bookControlHists("straightTracksY_isoAandCandB_chargerAandC",histoFile);
histoMap straightTracksY_isoAandCandB_chargerAandCandB = bookControlHists("straightTracksY_isoAandCandB_chargerAandCandB",histoFile);
histoMap straightTracksY_isoAandCandB_chargeAandC = bookControlHists("straightTracksY_isoAandCandB_chargeAandC",histoFile);
histoMap straightTracksY_isoAandCandB_chargeAandCandB = bookControlHists("straightTracksY_isoAandCandB_chargeAandCandB",histoFile);
histoMap hitsOnTrack = bookControlHists("hitsOnTrack",histoFile);
if(PRINT) cout << hdxAB->GetTitle() << " entries " << hdxAB->GetEntries() << endl;
const double log10 = log(10);
string ADD {"A"}; // added flag
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
time_t s0 = ts.tv_sec; // seconds since 1.1.1970
long f0 = ts.tv_nsec; // nanoseconds
clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ); // sum of threads time
time_t t0 = ts.tv_sec; // seconds
long n0 = ts.tv_nsec; // nanoseconds
double zeit1 = 0;
double zeit2 = 0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Read and process the run for each plane in parallel:
list < vector < cluster > > evlistA;
list < vector < cluster > > evlistB;
list < vector < cluster > > evlistC;
//#pragma omp sections // test, not parallel
/* oneplane function: for each plane
- Read data file & assemble pixel hits
- Skip noisy events with more than 400 hits
- Tsunami correction
- Common mode correction (column-wise)
- in roc coordinates
- we read along one column
- a roi is 7 pixels long
- we find the pixel with the highest and lowest row index in one column
- we assume there is no significant charge in these pixels
- we take the average pulse height of these two pixels and subtract it from those in between dph_i = ph_i - (ph_up + ph_low)/2
- Continue analysis if dph> dphcut
- for each sample we use the cut yielding the best resolution
- 25 vs 50
- Conversion from ADC to ke (updated for Vcal offset correction - as Finn)
- Clustering for events with less than 50 hits (speeding)
- From a seed pixel add to it all adjacent pixels with a hit
- Evaluating the cluster isolation
*/
#pragma omp parallel sections
{
#pragma omp section
{
if(PRINT) cout << "A " << sched_getcpu() << endl << flush; // changes
if(PRINT) cout << "***** Plane A ***********" << endl;
evlistA = oneplane( A, runnum, Nev, fifty, Tsunami[A],dphcut[A] );
} //omp section
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// B:
#pragma omp section
{
if(PRINT) cout << "B " << sched_getcpu() << endl << flush; // different from A
if(PRINT) cout << "***** Plane B ***********" << endl;
evlistB = oneplane( B, runnum, Nev, fifty, Tsunami[B],dphcut[B] );
} // omp section
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// C:
#pragma omp section
{
if(PRINT)cout << "C " << sched_getcpu() << endl << flush; // different from A and B
if(PRINT) cout << "***** Plane C ***********" << endl;
evlistC = oneplane( C, runnum, Nev, fifty, Tsunami[C],dphcut[C] );
} // omp section
} // omp parallel sections
clock_gettime( CLOCK_REALTIME, &ts );
time_t s2 = ts.tv_sec; // seconds since 1.1.1970
long f2 = ts.tv_nsec; // nanoseconds
zeit1 += s2 - s0 + ( f2 - f0 ) * 1e-9; // read and cluster
clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ); // sum threads
time_t t9 = ts.tv_sec; // seconds
long n9 = ts.tv_nsec; // nanoseconds
cout << "time " << zeit1 << " s"
<< " (sum threads " << t9 - t0 + ( n9 - n0 ) * 1e-9 << " s)"
<< endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// loop over events, correlate planes:
auto evA = evlistA.begin();
auto evB = evlistB.begin();
auto evC = evlistC.begin();
auto evinfoA = infoA.begin();
auto evinfoB = infoB.begin();
auto evinfoC = infoC.begin();
unsigned iev = 0;
uint64_t prevtimeA = 0;
uint64_t prevtimeB = 0;
uint64_t prevtimeC = 0;
if(PRINT) cout << "***** CLUSTERS CORRELATION ***********" << endl;
cout << endl << "tracking ev" << flush;
/////// Big Loop on the event ///////
for( ; evinfoB != infoB.end() && evA != evlistA.end() && evB != evlistB.end() && evC != evlistC.end(); ++evinfoA, ++evinfoB, ++evinfoC, ++evA, ++evB, ++evC )
{
if(PRINT) cout << "################# EVENT " << iev << endl;
vector <cluster> vclA = *evA;
vector <cluster> vclB = *evB;
vector <cluster> vclC = *evC;
++iev;
if( iev%10000 == 0 )
cout << " " << iev << flush;
if( evinfoA->filled == ADD ) cout << endl << "ev " << iev << " added A" << endl;
if( evinfoB->filled == ADD ) cout << endl << "ev " << iev << " added B" << endl;
if( evinfoC->filled == ADD ) cout << endl << "ev " << iev << " added C" << endl;
uint64_t dtA = evinfoA->evtime - prevtimeA;
prevtimeA = evinfoA->evtime;
uint64_t dtB = evinfoB->evtime - prevtimeB;
prevtimeB = evinfoB->evtime;
uint64_t dtC = evinfoC->evtime - prevtimeC;
prevtimeC = evinfoC->evtime;
if( iev > 1 && dtB > 0 ) // added events have same time
hdt->Fill( log(dtB/40e6) / log10 ); // MHz -> s
long ddtAB = dtA - dtB;
long ddtCB = dtC - dtB;
long ddtCA = dtC - dtA;
if( iev > 1 && dtB > 0 )
{
hddtAB->Fill( ddtAB );
hddtCB->Fill( ddtCB );
hddtCA->Fill( ddtCA );
ddtvsdtAB->Fill( log(dtB/40e6) / log10, ddtAB );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//////////////// A-B cluster correlations: //////////////////////////
cout << "entering AB correlation loop " << endl;
int nm = 0;
for( vector<cluster>::iterator cA = vclA.begin(); cA != vclA.end(); ++cA )
{
double xA = xcoordinate(0, cA, alignxA, ptchc, ptchr);
double yA = ycoordinate(0, cA, alignyA, ptchc, ptchr);
double xAr = xA*cfA - yA*sfA;
double yAr = xA*sfA + yA*cfA;
hxA->Fill( xAr );
hyA->Fill( yAr );
if( cA->iso )
{
hxAi->Fill( xAr );
hyAi->Fill( yAr );
hclqAi->Fill( cA->q );
}
for( vector<cluster>::iterator cB = vclB.begin(); cB != vclB.end(); ++cB )
{
double xB = xcoordinate(1, cB, 0, ptchc, ptchr);
double yB = ycoordinate(1, cB, 0, ptchc, ptchr);
hxxAB->Fill( xAr, xB );
hyyAB->Fill( yAr, yB );
double dx = xAr - xB;
double dy = yAr - yB;
if( cA->q > qL && cA->q < qR && cB->q > qLB && cB->q < qRB && cA->iso && cB->iso )
{
hdxAB->Fill( dx );
if(PRINT) cout << hdxAB->GetTitle() << " entries " << hdxAB->GetEntries() << endl;
hdyAB->Fill( dy );
dxvsxAB->Fill( xB, dx );
dxvsyAB->Fill( yB, dx );
}
hdxvsev->Fill( iev, dx );
if( fabs( dx ) < straightTracks * beamDivergenceScaled + 0.020 && fabs( dy ) < straightTracks * beamDivergenceScaled + 0.100 )
++nm;
} // clusters
} // cl
nmvsevAB->Fill( iev, nm );
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// B-C cluster correlations:
cout << "entering BC correlation loop " << endl;
nm = 0;
for( vector<cluster>::iterator cB = vclB.begin(); cB != vclB.end(); ++cB )
{
double xB = xcoordinate(1, cB, 0, ptchc, ptchr);
double yB = ycoordinate(1, cB, 0, ptchc, ptchr);
hxB->Fill( xB );
hyB->Fill( yB );
if( cB->iso )
{
hxBi->Fill( xB );
hyBi->Fill( yB );
hclqBi->Fill( cB->q );
}
for( vector<cluster>::iterator cC = vclC.begin(); cC != vclC.end(); ++cC )
{
double xC = xcoordinate(2, cC, alignxC, ptchc, ptchr);
double yC = ycoordinate(2, cC, alignyC, ptchc, ptchr);
double xCr = xC*cfC - yC*sfC;
double yCr = xC*sfC + yC*cfC;
hxC->Fill( xCr );
hyC->Fill( yCr );
if( cC->iso )
{
hxCi->Fill( xCr );
hyCi->Fill( yCr );
hclqCi->Fill( cC->q );
}
hxxCB->Fill( xB, xCr );
hyyCB->Fill( yB, yCr );
double dx = xCr - xB;
double dy = yCr - yB;
if( cC->q > qL && cC->q < qR && cB->q > qLB && cB->q < qRB && cC->iso && cB->iso )
{
hdxCB->Fill( dx );
hdyCB->Fill( dy );
dxvsxCB->Fill( xB, dx );
dxvsyCB->Fill( yB, dx );
}
if( fabs( dx ) < straightTracks * beamDivergenceScaled + 0.020 && fabs( dy ) < straightTracks * beamDivergenceScaled + 0.100 )
++nm;
} // clusters B
} // cl C
nmvsevCB->Fill( iev, nm );
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//filling hists for resolution studies
cout << " filling hists for resolution studies! " << endl;
for( vector<cluster>::iterator cC = vclC.begin(); cC != vclC.end(); ++cC )
{
double xC = xcoordinate(2, cC, alignxC, ptchc, ptchr);
double yC = ycoordinate(2, cC, alignyC, ptchc, ptchr);
double xCr = xC*cfC - yC*sfC;
double yCr = xC*sfC + yC*cfC;
for( vector<cluster>::iterator cA = vclA.begin(); cA != vclA.end(); ++cA )
{
double xA = xcoordinate(0, cA, alignxA, ptchc, ptchr);
double yA = ycoordinate(0, cA, alignyA, ptchc, ptchr);
double xAr = xA*cfA - yA*sfA;
double yAr = xA*sfA + yA*cfA;
double dxCA = xCr - xAr;
double dyCA = yCr - yAr;
if( fabs( dxCA ) > straightTracks * beamDivergenceScaled + 0.02 ) continue; // includes beam divergence: +-5 sigma
if( fabs( dyCA ) > straightTracks * beamDivergenceScaled + 0.1 ) continue; // [mm]
double xavg = 0.5 * ( xAr + xCr );
double yavg = 0.5 * ( yAr + yCr );
for( vector<cluster>::iterator cB = vclB.begin(); cB != vclB.end(); ++cB )
{
double xB = xcoordinate(1, cB, 0, ptchc, ptchr);
double yB = ycoordinate(1, cB, 0, ptchc, ptchr);
double dx3 = xB - xavg;
double dy3 = yB - yavg;
dx3 = dx3 - dx3corr*xavg; // from -dx3vsx.Fit("pol1")
dx3vsx->Fill( xB, dx3 ); // turn
dx3vsy->Fill( yB, dx3 );
if(fabs( dx3 ) < 0.07 && fabs( dy3 ) < 0.15 && cA->iso && cB->iso && cC->iso)
{
hclqAiii->Fill(cA->q);
hclqBiii->Fill(cB->q);
hclqCiii->Fill(cC->q);
hclphAiii->Fill(cA->sum);
hclphBiii->Fill(cB->sum);
hclphCiii->Fill(cC->sum);
}
}
}
}
cout << " done filling hists for resolution studies! "<< endl;
// ---------------------------------------
/////// A-C cluster correlations: ///////////
cout << "entering AC correlation loop " << endl;
nm = 0;
for( vector<cluster>::iterator cC = vclC.begin(); cC != vclC.end(); ++cC )
{
double xC = xcoordinate(2, cC, alignxC, ptchc, ptchr);
double yC = ycoordinate(2, cC, alignyC, ptchc, ptchr);
double xCr = xC*cfC - yC*sfC;
double yCr = xC*sfC + yC*cfC;
double etaC = eta(cC);
for( vector<cluster>::iterator cA = vclA.begin(); cA != vclA.end(); ++cA )
{
double xA = xcoordinate(0, cA, alignxA, ptchc, ptchr);
double yA = ycoordinate(0, cA, alignyA, ptchc, ptchr);
double xAr = xA*cfA - yA*sfA;
double yAr = xA*sfA + yA*cfA;
hxxCA->Fill( xAr, xCr );
hyyCA->Fill( yAr, yCr );
double dxCA = xCr - xAr;
double dyCA = yCr - yAr;
double dxyCA = sqrt( dxCA*dxCA + dyCA*dyCA );
hdxCA->Fill( dxCA );
hdyCA->Fill( dyCA );
// NB until I initialize cB, I am using cA instead!!!!
fillControlHists(raw,"raw",0,0,cA,cA,cC,0,0,0,iev,0,0,xAr,yAr,xCr,yCr,dxCA,0,0,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if(PRINT) cout << " tracks condition " << fabs( dxCA ) << " vs " << straightTracks * beamDivergenceScaled + 0.02 << endl;
if( fabs( dxCA ) > straightTracks * beamDivergenceScaled + 0.02 ) continue; // includes beam divergence: +-5 sigma
fillControlHists(dxCAcut,"dxCAcut",0,0,cA,cA,cC,0,0,0,iev,0,0,xAr,yAr,xCr,yCr,dxCA,0,0,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if(PRINT) cout << " dyCA " << dyCA << endl;
hdyCAc->Fill( dyCA );
dyvsyCA->Fill( yAr, dyCA );
if( fabs( dyCA ) > straightTracks * beamDivergenceScaled + 0.1 ) continue; // [mm]
++nm;
dxvsyCA->Fill( yAr, dxCA );
dxvsxCA->Fill( xAr, dxCA ); // linear trend in run 392, 403: acceptance and beam divergence ?
double xavg = 0.5 * ( xAr + xCr );
double yavg = 0.5 * ( yAr + yCr );
// double xmod = fmod( xavg + 8, 0.05 ); // [mm] 0..0.05
double xmod = fmod( xavg + 8.0125, 0.025 ); // [mm] 0..0.05
if( fifty )
xmod = fmod( xavg + 8.025, 0.05 ); // [mm] 0..0.05
double etaA = eta(cA);
int eff[999] = {0};
for( vector<cluster>::iterator cB = vclB.begin(); cB != vclB.end(); ++cB )
{
double xB = xcoordinate(1, cB, 0, ptchc, ptchr);
double yB = ycoordinate(1, cB, 0, ptchc, ptchr);
double etaB = eta(cB);
int rowmin = 999;
int rowmax = 0;
int colmin = 999;
int colmax = 0;
for( int ipx = 0; ipx < cB->size; ++ipx )
{
int row = cB->vpix[ipx].row;
if( row < rowmin ) rowmin = row;
if( row > rowmax ) rowmax = row;
int col = cB->vpix[ipx].col;
if( col < colmin ) colmin = col;
if( col > colmax ) colmax = col;
}
int nrowB = rowmax-rowmin+1;
int ncolB = colmax-colmin+1;
// triplet residual:
double dx3 = xB - xavg;
double dy3 = yB - yavg;
fillControlHists(beforeCorrections,"beforeCorrections",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
dx3 = dx3 - dx3corr*xavg; // from -dx3vsx.Fit("pol1")
double dxy = sqrt( dx3*dx3 + dy3*dy3 );
fillControlHists(nocuts,"nocuts",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if(PRINT) cout << "nocuts" << endl;
if( fabs( dy3 ) < straightTracks * beamDivergenceScaled + 0.05 )
{ // cut on y, look at x, see madx3vsy
fillControlHists(straightTracksY,"straightTracksY",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if( cA->iso && cC->iso )
{
fillControlHists(straightTracksY_isoAandC,"straightTracksY_isoAandC",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if( cB->iso )
{
fillControlHists(straightTracksY_isoAandCandB,"straightTracksY_isoAandCandB",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if(PRINT) cout << "isoAandCandB done" << endl;
if( fabs( dxCA ) < straightTracks * beamDivergenceScaled )
{ // track angle
fillControlHists(straightTracksY_isoAandCandB_straightTracksX,"straightTracksY_isoAandCandB_straightTracksX",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
}//fabs( dxCA ) < straightTracks * beamDivergenceScaled
if( (cA->q <= qR) && (cC->q <= qR))
{
if(PRINT) cout << "cA->q " << cA->q << " >= qR " << qR << " && cC->q " << cC->q << " >= qR " << endl;
if(PRINT) cout << "straightTracksY_isoAandCandB_chargerAandC going to be done" << endl;
fillControlHists(straightTracksY_isoAandCandB_chargerAandC,"straightTracksY_isoAandCandB_chargerAandC",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if(PRINT) cout << "straightTracksY_isoAandCandB_chargerAandC going done" << endl;
if( ( cB->q <= qRB) && ( cA->q <= qR) && ( cC->q <= qR))
{
fillControlHists(straightTracksY_isoAandCandB_chargerAandCandB,"straightTracksY_isoAandCandB_chargerAandCandB",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
}// ( cB->q >= qRB) && ( cA->q >= qR) && ( cC->q >= qR)
if( ( cA->q >= qL || cA->q <= qR) && ( cC->q >= qL || cC->q <= qR))
{
fillControlHists(straightTracksY_isoAandCandB_chargeAandC,"straightTracksY_isoAandCandB_chargeAandC",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
if( (cB->q >= qLB || cB->q <= qRB) && ( cA->q >= qL || cA->q <= qR) && ( cC->q >= qL || cC->q <= qR))
{
fillControlHists(straightTracksY_isoAandCandB_chargeAandCandB,"straightTracksY_isoAandCandB_chargeAandCandB",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
}//(cB->q <= qLB || cB->q >= qRB) && ( cA->q <= qL || cA->q >= qR) && ( cC->q <= qL || cC->q >= qR)
}//( cA->q <= qL || cA->q >= qR) && ( cC->q <= qL || cC->q >= qR)
}//(cA->q >= qR) && (cC->q >= qR)
}//iso B
}//iso A and C
} // cut dy (fabs( dy3 ) < straightTracks * beamDivergenceScaled + 0.05)
if(PRINT) cout << " done with hist filling my way " << endl;
if(PRINT) cout << " filling hists on track " << endl;
if( fabs( dx3 ) < 0.07 && fabs( dy3 ) < 0.15 && cA->iso && cB->iso && cC->iso) // hit on track
{
if(PRINT) cout << " it is on track " << endl;
fillControlHists(hitsOnTrack,"hitsOnTrack",dx3,dy3,cA,cB,cC,nrowB,ncolB,xmod,iev,xB,yB,xAr,yAr,xCr,yCr,dxCA,etaA,etaB,etaC,histoFile,fileName,hclphAiii,hclphBiii,hclphCiii,hclqAiii,hclqBiii,hclqCiii);
} // linked, iso (hit on track)
if(PRINT) cout << " end of selections! " << endl;
for( int iw = 1; iw < 999; ++iw )
if( dxy < iw*0.010 )
eff[iw] = 1; // eff
if(PRINT) cout << " hist filling 14 " << endl;
} // clusters B
if(PRINT) cout << " hist filling 15 " << endl;
if( fabs( dyCA ) > straightTracks*beamDivergenceScaled ) continue; // clean reference "tracks"
if( evinfoB->filled == ADD ) continue; // padded event in B
if( evinfoB->skip ) continue; // fat event in B
if( cA->iso == 0 ) continue;
if( cC->iso == 0 ) continue;
effvsxy->Fill( xavg, yavg, eff[50] );
if( yavg > -3.7 && yavg < 3.5 )
effvsx->Fill( xavg, eff[50] );
if( xavg > -3.3 && xavg < 3.6 )
effvsy->Fill( yavg, eff[50] );
if( xavg > -3.3 && xavg < 3.6 &&
yavg > -3.7 && yavg < 3.5 ) {
for( int iw = 1; iw < 999; ++iw )
effvsdxy->Fill( iw*0.010+0.005, eff[iw] );
effvsxm->Fill( xmod*1E3, eff[50] ); // bias dot
effvsev->Fill( iev, eff[50] );
effvsiev->Fill( iev%200, eff[50] );
//effvsmpxA->Fill( pbA.size(), eff[50] );
effvsqA->Fill( cA->q, eff[50] );
effvstxy->Fill( dxyCA, eff[50] ); // flat
} // fiducial x, y
} // clusters A
} // cl C
nmvsevCA->Fill( iev, nm );
// task: track correlations, intersects
} // events
///////// end of the big loop on the events!!! //////////////////
cout << endl;
if(PRINT) cout << " after big loop on events!!!************************" << endl;
if(PRINT)cout << hdxAB->GetTitle() << " entries " << hdxAB->GetEntries() << endl;
if(PRINT)cout << hdt->GetTitle() << " entries " << hdt->GetEntries() << endl;
clock_gettime( CLOCK_REALTIME, &ts );
time_t s3 = ts.tv_sec; // seconds since 1.1.1970
long f3 = ts.tv_nsec; // nanoseconds
zeit2 += s3 - s2 + ( f3 - f2 ) * 1e-9; // read and cluster
cout << "time " << zeit2 << " s" << endl;
if(PRINT)cout << hdxAB->GetTitle() << " entries " << hdxAB->GetEntries() << endl;
if(PRINT)cout << hdt->GetTitle() << " entries " << hdt->GetEntries() << endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
clock_gettime( CLOCK_REALTIME, &ts );
time_t s9 = ts.tv_sec; // seconds since 1.1.1970
long f9 = ts.tv_nsec; // nanoseconds
cout << "full time " << s9 - s0 + ( f9 - f0 ) * 1e-9 << " s"
<< " (read and cluster " << zeit1 << " s, tracking " << zeit2 << " s)"
<< endl;
if(PRINT)cout << hdxAB->GetTitle() << " entries " << hdxAB->GetEntries() << endl;
if(PRINT)cout << hdt->GetTitle() << " entries " << hdt->GetEntries() << endl;
rusage usage;
getrusage( RUSAGE_SELF, &usage );
cout << endl << "resource usage:"
<< endl << "time " << usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1E-6 << " s"
<< endl << "max resident set size " << usage.ru_maxrss << " kB"
<< endl << "file inputs " << usage.ru_inblock
<< endl << "file ouputs " << usage.ru_oublock
<< endl << "page faults without I/O " << usage.ru_minflt
<< endl << "page faults with I/O " << usage.ru_majflt
<< endl << "voluntary context switches " << usage.ru_nvcsw
<< endl << "involuntary context switches " << usage.ru_nivcsw
<< endl;
if(PRINT) cout << " going to write the hist file" << endl;
histoFile->Write();
if(PRINT) cout << " wrote the hist file" << endl;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// alignment fits:
if(DOALIGNMENT)
{
cout << "**************** alignment iteration " << aligniteration << endl;
cout << "******* ALIGNA A ********" << endl;
double newalignxA = alignxA;
if(PRINT) cout << " newalignxA " << newalignxA << " alignxA " << alignxA << endl;
if(PRINT) cout << hdxAB->GetTitle() << " entries " << hdxAB->GetEntries() << endl;
if( hdxAB->GetEntries() > 999 )
{
cout << "******* A x ********" << endl;
newalignxA += alignx(hdxAB,"A",runnum,aligniteration);
}
else
cout << " not enough statistics" << endl;
// y:
double newalignyA = alignyA;
if(PRINT) cout << endl << hdyAB->GetTitle() << " entries " << hdyAB->GetEntries() << endl;
if( hdyAB->GetEntries() > 999 ) {
//cout << " y correction " << hdyAB->GetMean() << endl;
cout << "******* A y ********" << endl;
newalignyA += aligny(hdyAB,"A",runnum,aligniteration);
}
else
cout << " not enough statistics" << endl;
// dxvsy -> -rot
double newalignfA = alignfA;
if(PRINT) cout << endl << dxvsyAB->GetTitle() << " entries " << dxvsyAB->GetEntries() << endl;
if( aligniteration > 0 && dxvsyAB->GetEntries() > 999 ) {
cout << "******* A angle ********" << endl;
newalignfA += alignangle(dxvsyAB,"A",runnum,aligniteration);
}
else
cout << " not enough" << endl;
// C:
cout << "******* ALIGNA C ********" << endl;
double newalignxC = alignxC;
if(PRINT) cout << endl << hdxCB->GetTitle() << " entries " << hdxCB->GetEntries() << endl;
if( hdxCB->GetEntries() > 999 ) {
cout << "******* C x ********" << endl;
newalignxC += alignx(hdxCB,"C",runnum,aligniteration);