-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalyzer.cxx
3295 lines (3004 loc) · 139 KB
/
Analyzer.cxx
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
/*
Copyright:
2010 daid KAHL, OTA shinsuke, HASHIMOTO takashi, YAMAGUCHI hidetoshi
2011, 2012, 2013 daid KAHL
This file is part of crabat
crabat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
crabat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with crabat. If not, see <http://www.gnu.org/licenses/>.
In order to publish results obtained from crabat or any
future derivative software, the authors must make reference
to the paper describing it (in preparation): D. Kahl et al.
``Algorithms for Active Target Data Analysis'' 2013. This is an
additional term to the license as stipulated in section 7b.
Publication includes, but is not limited to: books, peer-
reviewed journals, conference proceedings, annual reports, etc.
*/
/**
@file Analyzer.cxx
@author daid
@version 1.0
@brief Analyzer for the run data.
@details Takes the Chain and loops over all entries.\n
Fill histograms, do physics.
@date 07 Nov 2011 18:57:28
*/
//////////////////////////////////////
// analyze the data here!
/////////////////////////////////////
// If run from ROOT, exit with message
#if defined (__CINT__)
{
cout << "This is C++ code, not a ROOT macro!" << endl;
cout << "To continue, run:" << endl;
cout << "make" << endl;
cout << "./run" << endl;
gApplication->Terminate();
}
#endif
#define Analyzer_cxx
#include "Analyzer.h" // all other headers are here
#include "Calibration.cxx"
#include "Analyzer_config.cxx"
TF1 *finter_f1, *finter_f2;
double finter(double *x, double*par) {
return TMath::Abs(finter_f1->EvalPar(x,par) - finter_f2->EvalPar(x,par));
}
extern "C" { // removed for now since we don't use it. Uncomment Makefile to enable
void enewzsub_(int *z1, float *m1, float *e, char matter1[33], int *unit_pressure, float *pressure, float *temperature, int *unit_thick, float *thick1, float *aft_ene);
}
Bool_t gate_30s=false,gate_29p=false,gate_17f=false;
Bool_t proton_beam=false;
Bool_t ribeam_ssd=false;
Bool_t goodRF_30s=false, goodPpacX_30s=false;
Bool_t goodRF_29p=false, goodPpacX_29p=false;
Bool_t goodRF_17f=false, goodPpacX_17f=false;
// for individual pulse analysis of selected cases
int pulsetrack=0;
int pulsetrack1a=0;
int pulsetrack2a=0;
int pulsetrack3a=0;
bool specialtrack=false;
bool event=false;
int eventcounter=0;
// peak finding rebin size
const int rebin=4;
double hg_peak_left[8]={};
int hg_peak_left_counter[8]={};
double hg_peak_right[8]={};
int hg_peak_right_counter[8]={};
int hg_peak_holder[2]={};
double centerprojsum=0.;
int ytestcounter=0;
double ypointscounter=0;
double XpadBcalib[2];
double XpadCcalib[2];
const float padsize = 4.; // pad size mm
//const float padsize = (196./48.); // pad size mm
//scattering location declarations
bool scatter_event = false;
int nPointsB=2, nPointsP=0;
double padsHitC_double;
double zppac=0.;
double zmstpc=0.;
int padcpoints=0;
double chi2min[4], chi2nu[4];
double xmin=83.,xmed,xmax,xmedbest;
double chi2minGlobal[2];
int pxmedlow=3;
int pxmedhigh;
double tempx[2],tempy[2];
int temppoint=0;
int junk=0;
double dE[2];
int temppe;
double tempxe[2],tempee[2];
float pad_scatter_tmp;
int pad_scatter;
double dEpadBsum = 36.9; // 17.3 um mylar; 6.8 um kapton; 194 torr, 213 K 82.75+4 = 86.75 mm HeCO2
int gate_30s_bragg = 0;
double dEpadB_gate_30s[2][48]={{
0.,
8154.85,
7544.33,
7591.57,
7518.22,
7561.07,
7463.77,
7507.3,
7681.71,
7951.29,
7950.4,
8094.47,
8084.42,
7825.75,
7731.6 ,
7643.41,
7515.75,
0.,
6848.76,
6728.66,
6117.14,
5803.94,
5509.24,
5142.19,
0.,
0.,
0.,
3426.48,
2366.12,
1697.44,
1329.89,
1117.92,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
927.907,
974.823,
893.893,
787.807,
0.,
0.,
0.,
0.
},{
0.,
13216.7,
12614.3,
12901.2,
13172.6,
13674.1,
13593.8,
13767.1,
14184.2,
14541.5,
14449.2,
14702.9,
14776.1,
14665.1,
14692.5,
14711.2,
14462.7,
0.,
13436.9,
13598.2,
13208.9,
13114.2,
13186.8,
13316.5,
0.,
0.,
0.,
14397.6,
13594,
13771.6,
13264.5,
12836.2,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
5477.22,
5169.21,
4925.92,
4841.45,
0.,
0.,
0.,
0.
}};
KVNucleus *beam = new KVNucleus;
KVNucleus *target = new KVNucleus;
KVNucleus *recoil = new KVNucleus;
KV2Body reaction;
/**
* @brief Loops over the TChain and entries
* @details Oh my god there are so many details here.
*/
void Analyzer::Loop(Int_t run,
Bool_t flag_raw, Bool_t flag_detail,
Bool_t flag_ssd, Bool_t flag_strip,
Bool_t flag_ppac,
Bool_t flag_tpc)
{
beam->Set("30S");
target->Set("4He");
recoil->Set("4He");
KV2Body reaction;
reaction.SetProjectile(beam);
reaction.SetTarget(target);
reaction.SetOutgoing(recoil);
// initalize the variables for matter and energy loss enewzsub
//SOLID TARGET PROTOTYPE - A mylar foil (so-called beam stopper)
char matter_mylar[34] = "mylar"; // Matter the beam passes through, as defined in SNKE_MATTER.INC -- case insensitive
int unit_pressure_mylar = 0 ; // Not used for solid target; set as 0
float pressure_mylar = 0 ; // Not used for solid target; set as 0
float temperature_mylar = 0 ; // Not used for solid target; set as 0
int unit_thick_mylar = 1; // Define the units of thickness: 1=mm ; 2=mg/cm^2
float thick_mylar = 0.0025 ; // Define the value of the thickness.
//GAS TARGET PROTOTYPE - Active target fill gas
char * matter_gas;
matter_gas = new char[34];
strcpy (matter_gas, "heco2");
int unit_pressure_gas = 1 ; // Define the units of pressure: 1=Torr ; 2=mbar ; 3=atm. If you change here, the program handles the rest.
float pressure_gas=194; // Gas pressure (Torr with above line as I set it) -- This is input by user.
float temperature_gas = 280 ; // Define temperature of the target in Kelvin
int unit_thick_gas = 1; // Define the units of thickness: 1=mm ; 2=mg/cm^2
// CHANGE FOR YOUR EXPERIMENTAL CASE THE DISTANCE FROM THE TPC ENTRANCE WINDOW TO 0 DEGREE SSD!
//float thick_gas = 393.5; // This variable is case-by-case. It is currently set to mm units. // used this to get p 116 fits
// this is the proper distance, but no account for the foil bowing etc 27 Aug 2012 15:39:29
float thick_gas = 0; // This variable is case-by-case. It is currently set to mm units.
//This part just fixes the name length of the matter to 32 characters for FORTRAN
for(int j=0;j<33;j++)
if(matter_mylar[j]=='\0')
{
matter_mylar[j]=' ';
matter_mylar[j+1]='\0';
}
for(int i=0;i<33;i++)
if(matter_gas[i]=='\0')
{
matter_gas[i]=' ';
matter_gas[i+1]='\0';
}
int z_alpha = recoil->GetZ();
float m_alpha = recoil->GetA();
float e_alpha_send, e_alpha_return;
double energy_alpha_calc;
bool geo_verbose = false;
bool geo_draw = false;
// variable parameters for plotting
// always define each time you plot
float geo_xmin=-200.; // minimum input for plotting
float geo_xmax=200.; // maximum input for plotting
float Z0=0.; // Z geo_intercept
TF1 *fint = new TF1("fint",finter,geo_xmin,geo_xmax,0);
double p[2]; // temp to extract fit parameters
// basic constants of field cage
const float xCageSize=278.;
const float zCageSize=295.;
const float SsdFootDepth=30.;
const float SsdMountWidth=252.;
const int npCageFoot=4;
const int handMarkerStyle=24;
const float handMarkerSize=0.75;
const int handMarkerColor=4;
const int stripMarkerStyle=33;
const float stripMarkerSize=1.5;
const int stripMarkerColor=1;
// data from Vol 4, p. 88
// 45 is back of foot to front of field cage
// thus these data are in the cage's own reference
Float_t zCageFoot[npCageFoot]={45.,85.,145.,35.};
Float_t zeCageFoot[npCageFoot]={};
// beam axis reference
Float_t xCageFoot[npCageFoot]={6.,9.,15.,16.5};
// cage's own reference
//Float_t x[npCageFoot]={-6.,-9.,-15.,-16.5};
Float_t xeCageFoot[npCageFoot]={};
// SET Z REFERENCE FRAME FOR ENTIRE MACRO
// zReference:
// 27.75 beginning of pad 0 Vol 5 p.4
// 0 beginning of field cage is Z=0
// -35 inner wall
// -55 entrance window
const float zReference=-55.;
zCageFoot[0]-=zReference;
TCanvas *c1;
if (geo_draw) c1 = new TCanvas("c1","c1",700,800);
for (int i=0;i<npCageFoot;i++){
if (i!=0) zCageFoot[i]+=zCageFoot[i-1]; // get the full depth, not the foot spacing
zeCageFoot[i]=0.1; // assume the production error is 100 um
xeCageFoot[i]=0.5; // assume ability to use a ruler is 0.5 mm precision
if (geo_verbose) cout << "zCageFoot[" << i << "]: " << zCageFoot[i] << endl;
}
TGraphErrors *gCageCenter;
gCageCenter = new TGraphErrors(npCageFoot,xCageFoot,zCageFoot,xeCageFoot,zeCageFoot);
gCageCenter->SetMarkerColor(kBlue);
gCageCenter->SetMarkerStyle(20);
gCageCenter->SetMarkerSize(1);
//YOUR TITLE & LABELS GO HERE!!!
gCageCenter->SetTitle("Active Target Geometry By Laser Alignment");
//gCageCenter->SetTitle("Field Cage Rotation By Laser Alignment");
gCageCenter->GetYaxis()->SetTitle("Z position (mm)");
gCageCenter->GetYaxis()->SetTitleOffset(1.35);
gCageCenter->GetXaxis()->CenterTitle(true);
gCageCenter->GetXaxis()->SetTitle("X position (mm)");
gCageCenter->GetYaxis()->CenterTitle(true);
gCageCenter->GetXaxis()->SetLimits(geo_xmin,geo_xmax);
gCageCenter->GetYaxis()->SetRangeUser(-10,400);
gCageCenter->SetMarkerStyle(handMarkerStyle);
gCageCenter->SetMarkerSize(handMarkerSize);
gCageCenter->SetMarkerColor(handMarkerColor);
if (geo_draw) gCageCenter->Draw("AP9");
TF1 *fLinear;
fLinear = new TF1("fLinear","pol1");
fLinear->SetLineWidth(1);
fLinear->SetLineColor(3);
fLinear->SetNpx(1000);
gCageCenter->Fit("fLinear","Q");
fLinear->GetParameters(&p[0]);
const Float_t CageSlope=p[1];
const float CageSlopeInv = -1/CageSlope;
const Float_t CageX0=-p[0]/p[1];
const Float_t CageZ0=p[0];
if (geo_verbose) cout << "Field Cage Parameters\nCageZ0: " << CageZ0 << "\nCageX0: " << CageX0 << endl;
if (geo_verbose) cout << "\nCageSlope: " << CageSlope << "CageSlopeInv: " << CageSlopeInv << endl;
TF1 *fCageCenter = new TF1("fCageCenter","[0]+x*[1]",-1000.,1000.);
fCageCenter->SetParameters(CageZ0,CageSlope);
fCageCenter->SetNpx(1000);
fCageCenter->SetLineWidth(2);
fCageCenter->SetLineColor(2);
//draw at the end to put overtop of bridge
//fCageCenter->Draw("SAME9");
TF1 *fCageCenterInv = new TF1("fCageCenterInv","(x-[0])/[1]");
fCageCenterInv->SetParameters(CageZ0,CageSlope);
float xCageCenter=fCageCenterInv->Eval((zCageSize/2.)-zReference); // center of FC in X
if (geo_verbose) cout << "center of field cage (X):" << xCageCenter << endl;
float zCageCenter=fCageCenter->Eval(xCageCenter);
Z0 = zCageCenter-(CageSlopeInv*xCageCenter);
TF1 *fCageCenterOrthogonal = new TF1("fCageCenterOrthogonal","[0]+x*[1]",-1000.,1000.);
fCageCenterOrthogonal->SetParameters(Z0,CageSlopeInv);
//fCageCenterOrthogonal->Draw("SAME9");
// SSD LEFT POSITION BY INTERCEPTION
float xSsdLOffsetTpc[3]={-22.,-20.,-18.}; // -13 should be -18 as shown here. Otherwise the data point cannot fit at all
float xCageSsdLFoot[3];
float zCageSsdLFoot[3];
TF1 *fCageFoot[npCageFoot];
if (geo_verbose) cout << "xSsdL\tzSsdL" << endl;
for (int i=0;i<npCageFoot-1;i++){
//cout << "Iteration: " << i << endl;
fCageFoot[i] = new TF1("fCageFoot","[0]+x*[1]",geo_xmin,geo_xmax);
fCageFoot[i]->SetLineWidth(1);
Z0 = zCageFoot[i]-(CageSlopeInv*xCageFoot[i]);
// arbitrary propagation of error >_<
//cout << "fLinear->Eval(x[i]): " << fLinear->Eval(x[i]) << endl;
//float Z0 = fLinear->Eval(x[i])+((1/CageSlope)*x[i]);
fCageFoot[i]->SetParameters(Z0,CageSlopeInv);
fCageFoot[i]->SetLineColor(3);
if (geo_draw) fCageFoot[i]->Draw("9LSAME");
xCageSsdLFoot[i]=-(((xCageSize+30)/2)-xCageFoot[i]-xSsdLOffsetTpc[i]);
//zSsdL[i]=
zCageSsdLFoot[i]=fCageFoot[i]->Eval(xCageSsdLFoot[i]);
//cout << xCageSsdLFoot[i] << "\t" << zCageSsdLFoot[i] << endl ;
}
// FRONT OF CHAMBER WALL BY INTERCEPTION
float wall_rotation=CageSlopeInv+(2./308.); // chamber wall is slightly less rotated
//cout << "X CageSlope wall by beam axis: " << wall_rotation << endl;
TF1 *fChamberWallIn = new TF1("fChamberWallIn","[0]+x*[1]",geo_xmin,geo_xmax);
fChamberWallIn->SetParameters(-zReference-35.,wall_rotation);
fChamberWallIn->SetLineWidth(2);
fChamberWallIn->SetLineColor(1);
fChamberWallIn->SetLineStyle(2);
if (geo_draw) fChamberWallIn->Draw("9LSAME");
TF1 *fChamberWallOut = new TF1("fChamberWallOut","[0]+x*[1]",geo_xmin,geo_xmax);
fChamberWallOut->SetParameters(-zReference-55.,wall_rotation);
fChamberWallOut->SetLineWidth(2);
fChamberWallOut->SetLineColor(1);
fChamberWallOut->SetLineStyle(2);
if (geo_draw) fChamberWallOut->Draw("9LSAME");
const int npSsdLFoot=6;
float xSsdLFoot[npSsdLFoot],zSsdLFoot[npSsdLFoot],xeSsdLFoot[npSsdLFoot],zeSsdLFoot[npSsdLFoot];
for (int i=0;i<npSsdLFoot;i++){
xeSsdLFoot[i]=0.5; // assume ability to use a ruler is 0.5 mm precision
zeSsdLFoot[i]=0.5; // assume the production error is 100 um
//zSsdLErr[i]+=0.1; // assume the production error is 100 um
}
//cout << "Foot 0 left " << fCageFoot[0]->Eval(-148) << endl;
//cout << "Wall left " << fChamberWall->Eval(-148) << endl;
//cout << "Foot 0 left to wall: " << fCageFoot[0]->Eval(-148.)-fChamberWall->Eval(-148.) << endl;
xSsdLFoot[0]=-173;
zSsdLFoot[0]=fChamberWallIn->Eval(xSsdLFoot[0])+21.;
//cout << "SSD L foot X\tZ" << endl;
//cout << xSsdLFoot[0] << "\t" << zSsdLFoot[0] << endl;
float thetaSsdLFoot=(TMath::Pi()/2)-asin(6./SsdFootDepth);
xSsdLFoot[2]=-168.5;
zSsdLFoot[2]=(zCageSize+36.-SsdMountWidth)*sin(thetaSsdLFoot)+zSsdLFoot[0];
xSsdLFoot[4]=-157.;
zSsdLFoot[4]=zCageSize*sin(thetaSsdLFoot)+zSsdLFoot[0];
//cout << xSsdLFoot[4] << "\t" << zSsdLFoot[4] << endl;
// SSD Left foot determination
for (int i=0;i<npCageFoot-1;i++){
zSsdLFoot[i*2+1]=zCageSsdLFoot[i];
xSsdLFoot[i*2+1]=xCageSsdLFoot[i];
}
if (geo_verbose) cout << "Data for plotting: " << endl;
for (int i=0;i<npSsdLFoot;i++){ if (geo_verbose) cout << xSsdLFoot[i] << "\t" << zSsdLFoot[i] << endl;}
TGraphErrors *gSsdLFoot = new TGraphErrors(npSsdLFoot,xSsdLFoot,zSsdLFoot,xeSsdLFoot,zeSsdLFoot);
gSsdLFoot->SetMarkerColor(handMarkerColor);
gSsdLFoot->SetMarkerStyle(handMarkerStyle);
gSsdLFoot->SetMarkerSize(handMarkerSize);
if (geo_draw) gSsdLFoot->Draw("9PSAME");
gSsdLFoot->Fit("fLinear","Q");
fLinear->GetParameters(&p[0]);
// SSD 3a (left, d/s) strip determination
float SsdLDetOffset=p[0]+(9.4/(sin(TMath::Pi()/2-atan(p[1])))); // 13 - 3.6 = 9.4 (spacer - frame) online II p. 160
float SsdLDetSlope=p[1];
//cout << "SsdLDetOffset: " << SsdLDetOffset << endl;
//this is the downstream edge of the mount
//xSsdL[2]=-168.5;
float zSsdLCenter=(zCageSize+36.-(SsdMountWidth/2.))*sin(thetaSsdLFoot)+zSsdLFoot[0];
//cout << "zSsdLCenterL " << zSsdLCenter << endl;
// it really should be something like this, fix later for presentation
//geo_xmin=xPadR[i]+xCageCenter+CageSlopeInv*(234./2.);
//geo_xmax=xPadR[i]+xCageCenter-CageSlopeInv*(234./2.);
//geo_xmin=fCageCenterInv->Eval(zSsdLCenter)+CageSlopeInv*(SsdMountWidth/2.);
//geo_xmax=fCageCenterInv->Eval(zSsdLCenter)-CageSlopeInv*(SsdMountWidth/2.);
geo_xmin = -1000;
geo_xmax = 1000;
TF1 *fSsdL = new TF1("fSsdL","[0]+x*[1]",geo_xmin,geo_xmax);
TF1 *fSsdLInv = new TF1("fSsdLInv","(x-[0])/[1]",geo_xmin,geo_xmax);
fSsdL->SetParameters(SsdLDetOffset,SsdLDetSlope);
fSsdLInv->SetParameters(SsdLDetOffset,SsdLDetSlope);
fSsdL->SetLineColor(1);
fSsdL->SetLineWidth(1);
fSsdL->SetNpx(1000);
//fSsdL->Draw("L9SAME");
//cout << "X of center: " << fSsdLInv->Eval(zSsdLCenter) << endl;
const float SsdBridgeWidth=12.4; // logbook 4 p 152 has 6.2 from SSD frame
const float SsdStripWidth=(90.6/8.);
const int nStrips=8;
// depth in its own frame
float StripSsdL[8]; // have never used notation like "Strip 0" always starts "Strip 1"
// absolute positions
float xStripSsdL[8];
float zStripSsdL[8];
//cout << endl << "LEFT SSD" << endl;
StripSsdL[7]=zSsdLCenter+((SsdBridgeWidth/2.)+0.5*SsdStripWidth);
//cout << "Strip 7: " << StripSsdL[7] << endl;
for (int i=6;i>-1;i--){ // looping backward is strange but this is how we count the strips going out from center...
StripSsdL[i]=StripSsdL[i+1]+SsdStripWidth;
//cout << "Strip " << i << ": " << StripSsdL[i] << endl;
}
for (int i=0;i<8;i++){
zStripSsdL[i]=StripSsdL[i]*sin(atan(SsdLDetSlope));
//cout << "Strip Z" << i << ": " << zStripSsdL[i] << endl;
xStripSsdL[i]=fSsdLInv->Eval(zStripSsdL[i]);
}
TGraph *gStripsL = new TGraph(nStrips,xStripSsdL,zStripSsdL);
gStripsL->SetMarkerColor(stripMarkerColor);
gStripsL->SetMarkerStyle(stripMarkerStyle);
gStripsL->SetMarkerSize(stripMarkerSize);
if (geo_draw) gStripsL->Draw("PSAME9");
// SSD 1a (center, right) strip determination
const int npSsdCFoot=1;
float xSsdCFoot[npSsdCFoot],zSsdCFoot[npSsdCFoot],xeSsdCFoot[npSsdCFoot],zeSsdCFoot[npSsdCFoot];
xSsdCFoot[0]=(146.5-131.5)/2.; // vol 4 p 152
zSsdCFoot[0]=zCageFoot[3]+14.; // online vol 2 p 160 //
TGraphErrors *gSsdCFoot = new TGraphErrors(npSsdCFoot,xSsdCFoot,zSsdCFoot,xeSsdCFoot,zeSsdCFoot);
gSsdCFoot->SetMarkerColor(handMarkerColor);
gSsdCFoot->SetMarkerStyle(handMarkerStyle);
gSsdCFoot->SetMarkerSize(handMarkerSize);
if (geo_draw) gSsdCFoot->Draw("9PSAME");
geo_xmin=-1*(131.5-((xCageSize-SsdMountWidth)/2));
geo_xmax=(146.5-((xCageSize-SsdMountWidth)/2));
TF1 *fSsdCFoot = new TF1("fSsdCFoot","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = zSsdCFoot[0]+((1/CageSlope)*xSsdCFoot[0]);
fSsdCFoot->SetParameters(Z0,CageSlopeInv);
fSsdCFoot->SetLineColor(3);
fSsdCFoot->SetLineWidth(1);
if (geo_draw) fSsdCFoot->Draw("L9SAME");
float zSsdC=zSsdCFoot[0]+13.-3.6; // online vol 2 p 160 nominally 368.4 from the wall
float xSsdC=fCageCenterInv->Eval(zSsdC)-fCageCenterInv->Eval(zSsdCFoot[0])+xSsdCFoot[0]; // roughly 8, see vol 4 p 152
//cout << endl << "CENTER SSD" << endl;
geo_xmin=-1*(131.5-((xCageSize-SsdMountWidth)/2));
geo_xmax=(146.5-((xCageSize-SsdMountWidth)/2));
TF1 *fSsdC = new TF1("fSsdC","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = zSsdC+((1/CageSlope)*xSsdC);
fSsdC->SetParameters(Z0,CageSlopeInv);
fSsdC->SetLineColor(1);
fSsdC->SetLineWidth(1);
//fSsdC->Draw("L9SAME");
float StripSsdC[8]; // have never used notation like "Strip 0" always starts "Strip 1"
float xStripSsdC[8];
float xErrStripSsdC[8];
float zStripSsdC[8];
float zErrStripSsdC[8];
StripSsdC[7]=xSsdC+(SsdBridgeWidth/2.)+0.5*SsdStripWidth;
//cout << "Strip 7: " << StripSsdC[7] << endl;
for (int i=6;i>-1;i--){ // looping backward is strange but this is how we count the strips going out from center...
StripSsdC[i]=StripSsdC[i+1]+SsdStripWidth;
//cout << "Strip " << i << ": " << StripSsdC[i] << endl;
}
for (int i=0;i<8;i++){
xStripSsdC[i]=StripSsdC[i]*cos(atan(CageSlopeInv));
xErrStripSsdC[i]=xStripSsdC[i]-((90.6/8.)*0.5);
//cout << "Strip X" << i << ": " << xStripSsdC[i] << endl;
zStripSsdC[i]=fSsdC->Eval(xStripSsdC[i]);
zErrStripSsdC[i]=fSsdC->Eval(xErrStripSsdC[i]);
}
TGraph *gStripsC = new TGraph(nStrips,xStripSsdC,zStripSsdC);
gStripsC->SetMarkerColor(stripMarkerColor);
gStripsC->SetMarkerStyle(stripMarkerStyle);
gStripsC->SetMarkerSize(stripMarkerSize);
if (geo_draw) gStripsC->Draw("P9SAME9");
// Beam GEM
// start: 35 + 27.75
// end : + 192
float PadB[48],zPadB[48],xPadB[48];
PadB[0]=-zReference+27.75+2.;
for (int i=1;i<48;i++){
PadB[i]=PadB[i-1]+4.;
}
TF1 *fPadB[48];
for (int i=0;i<48;i++){
zPadB[i]=PadB[i]*sin(atan(CageSlope));
xPadB[i]=fCageCenterInv->Eval(zPadB[i]);
geo_xmin=xPadB[i]-(110./2.);
geo_xmax=xPadB[i]+(110./2.);
fPadB[i] = new TF1("fPadB","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = zPadB[i]-(CageSlopeInv*xPadB[i]);
//Z0 = fc_center->Eval(x[i])+((1/CageSlope)*x[i]);
fPadB[i]->SetParameters(Z0,CageSlopeInv);
fPadB[i]->SetLineColor(1);
fPadB[i]->SetLineWidth(1);
fPadB[i]->SetNpx(1000);
if (geo_draw) fPadB[i]->Draw("L9SAME");
}
// Central GEM
// start : +15.5
// end : +32
float PadC[8],zPadC[8],xPadC[8];
PadC[0]=-zReference+27.75+192.+15.5+2.;
for (int i=1;i<8;i++){
PadC[i]=PadC[i-1]+4.;
}
TF1 *fPadC[8];
TF1 *fPadCBridge[8];
for (int i=0;i<8;i++){
zPadC[i]=PadC[i]*sin(atan(CageSlope));
xPadC[i]=fCageCenterInv->Eval(zPadC[i]);
geo_xmin=xPadC[i]-(110./2.);
geo_xmax=xPadC[i]+(110./2.);
fPadC[i] = new TF1("fPadC","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = zPadC[i]-(CageSlopeInv*xPadC[i]);
//Z0 = fc_center->Eval(x[i])+((1/CageSlope)*x[i]);
fPadC[i]->SetParameters(Z0,CageSlopeInv);
fPadC[i]->SetLineColor(1);
fPadC[i]->SetLineWidth(1);
fPadC[i]->SetNpx(1000);
if (geo_draw) fPadC[i]->Draw("L9SAME");
geo_xmin=xPadC[i]-(40./2.);
geo_xmax=xPadC[i]+(40./2.);
fPadCBridge[i] = new TF1("fPadCBridge","[0]+x*[1]",geo_xmin,geo_xmax);
fPadCBridge[i]->SetParameters(Z0,CageSlopeInv);
fPadCBridge[i]->SetLineColor(0);
fPadCBridge[i]->SetLineWidth(7);
fPadCBridge[i]->SetNpx(1000);
if (geo_draw) fPadCBridge[i]->Draw("L9SAME");
}
// need to draw this here to put it over the bridge
if (geo_draw) fCageCenter->Draw("SAMEL9");
//Side GEM
//
geo_xmin=-1000.;
geo_xmax=1000;
TF1 *fPadSideMax = new TF1("fPadSideMax","[0]+x*[1]",geo_xmin,geo_xmax);
Z0=-zReference+zCageSize/2.+234./2.;
fPadSideMax->SetParameters(Z0,CageSlopeInv);
fPadSideMax->SetNpx(1000);
//fPadSideMax->Draw("L9SAME");
TF1 *fPadSideMin = new TF1("fPadSideMin","[0]+x*[1]",geo_xmin,geo_xmax);
Z0=-zReference+zCageSize/2.-234./2.;
fPadSideMin->SetParameters(Z0,CageSlopeInv);
fPadSideMin->SetNpx(1000);
//fPadSideMin->Draw("L9SAME");
// Left GEM
// 110/2 + 21.5 + 2 from center of FC to center of inner most pad
float PadL[8],zPadL[8],xPadL[8];
// pad distance X from center in its own frame
PadL[0]=-1.*((110./2.)+21.5+2.);
// add the field cage offset -- by this method we don't need it
//padL[0]+=xCageCenter; //
//cout << "padL[0]: " << PadL[0] << endl;
for (int i=1;i<8;i++){
PadL[i]=PadL[i-1]-4.;
//cout << "PadL[" << i << "]: " << PadL[i] << endl;
}
TF1 *fPadL[8];
for (int i=0;i<8;i++){
//for (int i=0;i<1;i++){
// pad distance X from center in rotated frame
xPadL[i] = PadL[i];
// don't need it?!?!
xPadL[i] = PadL[i]*cos(atan(CageSlopeInv));
//cout << "xPadL[" << i << "]: " << xPadL[i] << endl;
geo_xmin=-500;
geo_xmax=500;
TF1 *fTemp = new TF1("fTemp","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = CageZ0-(xPadL[i]/(sin(TMath::Pi()/2-atan(CageSlope))));
fTemp->SetParameters(Z0,CageSlope);
finter_f1=fTemp;
finter_f2=fPadSideMin;
geo_xmin=fint->GetMinimumX();
finter_f2=fPadSideMax;
geo_xmax=fint->GetMinimumX();
//geo_xmin=xPadL[i]+xCageCenter+CageSlopeInv*(234./2.);
//geo_xmax=xPadL[i]+xCageCenter-CageSlopeInv*(234./2.);
//cout << "geo_xmin: " << geo_xmin << endl;
//cout << "geo_xmax: " << geo_xmax << endl;
fPadL[i] = new TF1("fPadL","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = CageZ0-(xPadL[i]/(sin(TMath::Pi()/2-atan(CageSlope))));
fPadL[i]->SetParameters(Z0,CageSlope);
fPadL[i]->SetLineColor(1);
fPadL[i]->SetLineWidth(1);
fPadL[i]->SetNpx(1000);
if (geo_draw) fPadL[i]->Draw("L9SAME");
if (geo_verbose) cout << "Left pad " << i << " minimum Z: " << fPadL[i]->Eval(geo_xmin) << endl;
}
// Right GEM
float PadR[8],zPadR[8],xPadR[8];
// pad distance X from center in its own frame
PadR[0]=((110./2.)+21.5+2.);
if (geo_verbose) cout << "padR[0]: " << PadR[0] << endl;
for (int i=1;i<8;i++){
PadR[i]=PadR[i-1]+4.;
if (geo_verbose) cout << "PadR[" << i << "]: " << PadR[i] << endl;
}
TF1 *fPadR[8];
for (int i=0;i<8;i++){
//for (int i=0;i<1;i++){
// pad distance X from center in rotated frame
xPadR[i] = PadR[i];
if (geo_verbose) cout << "xPadR[" << i << "]: " << xPadR[i] << endl;
geo_xmin=-500;
geo_xmax=500;
TF1 *fTemp = new TF1("fTemp","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = CageZ0-(xPadR[i]/(sin(TMath::Pi()/2-atan(CageSlope))));
fTemp->SetParameters(Z0,CageSlope);
finter_f1=fTemp;
finter_f2=fPadSideMin;
geo_xmin=fint->GetMinimumX();
finter_f2=fPadSideMax;
geo_xmax=fint->GetMinimumX();
//geo_xmin=xPadR[i]+xCageCenter+CageSlopeInv*(234./2.);
//geo_xmax=xPadR[i]+xCageCenter-CageSlopeInv*(234./2.);
//geo_xmin=-1000.;geo_xmax=1000.;
if (geo_verbose) cout << "geo_xmin: " << geo_xmin << endl;
if (geo_verbose) cout << "geo_xmax: " << geo_xmax << endl;
fPadR[i] = new TF1("fPadR","[0]+x*[1]",geo_xmin,geo_xmax);
Z0 = CageZ0-(xPadR[i]/(sin(TMath::Pi()/2-atan(CageSlope))));
fPadR[i]->SetParameters(Z0,CageSlope);
fPadR[i]->SetLineColor(1);
fPadR[i]->SetLineWidth(1);
fPadR[i]->SetNpx(1000);
if (geo_draw) fPadR[i]->Draw("L9SAME");
}
// check various geo_interceptions
ofstream fileout_c;
fileout_c.open("geometry_hg_c.dat", ios::out);
//fileout_c.open("geometry_hg_c.dat", ios::out | ios::app);
ofstream fileout_l;
fileout_l.open("geometry_hg_l.dat", ios::out);
//fileout_l.open("geometry_hg_l.dat", ios::out | ios::app);
//CHANGE THESE
// choose which GEM
for (int PadIntercept=0;PadIntercept<2;PadIntercept++){ // 0->Central; 1->Left
// strip number 1 to 8
//int StripGate=7;
for (int StripGate=1;StripGate<9;StripGate++){
if (geo_verbose) cout << "Strip " << StripGate << endl;
float xAlpha[2],xErrAlpha[2],zAlpha[2],zErrAlpha[2];
xAlpha[0]=0.;
zAlpha[0]=-zReference-(35.+14.);
if (PadIntercept==0){
xAlpha[1]=xStripSsdC[StripGate-1];
xErrAlpha[1]=xErrStripSsdC[StripGate-1];
zAlpha[1]=zStripSsdC[StripGate-1];
zErrAlpha[1]=zErrStripSsdC[StripGate-1];
}
if (PadIntercept==1){
xAlpha[1]=xStripSsdL[StripGate-1];
zAlpha[1]=zStripSsdL[StripGate-1];
}
TGraph *gAlpha = new TGraph(2,xAlpha,zAlpha);
gAlpha->SetLineColor(kRed);
gAlpha->SetLineWidth(2);
//gAlpha->Draw();
gAlpha->Fit("fLinear","Q");
fLinear->GetParameters(&p[0]);
geo_xmin=-250;
geo_xmax=150;
TF1 *fAlpha = new TF1("fAlpha","[0]+x*[1]",geo_xmin,geo_xmax);
fAlpha->SetParameters(p[0],p[1]);
fAlpha->SetLineColor(kRed);
fAlpha->SetLineWidth(2);
fAlpha->SetNpx(1000);
//fAlpha->Draw("SAME");
/*
if (StripGate==4 && PadIntercept==0){
//fAlpha->Draw("SAME");
float length;
length = sqrt((zAlpha[1]-zAlpha[0])**2 + (xAlpha[1]-zAlpha[0])**2);
cout << "LENGTH: " << length << endl;
}
*/
TGraph *gAlphaErr = new TGraph(2,xErrAlpha,zErrAlpha);
gAlphaErr->SetLineColor(kRed);
gAlphaErr->SetLineWidth(2);
//gAlphaErr->Draw();
gAlphaErr->Fit("fLinear","Q");
fLinear->GetParameters(&p[0]);
geo_xmin=-250;
geo_xmax=150;
TF1 *fAlphaErr = new TF1("fAlphaErr","[0]+x*[1]",geo_xmin,geo_xmax);
fAlphaErr->SetParameters(p[0],p[1]);
fAlphaErr->SetLineColor(kRed);
fAlphaErr->SetLineWidth(2);
fAlphaErr->SetNpx(1000);
//fAlphaErr->Draw("SAME");
float geo_intercept;
float xErrEval[8];
for (int i=0;i<8;i++){
//double xint = fint->GetMinimumX();
if (PadIntercept==0) {
finter_f1=fAlpha;
finter_f2=fPadC[i];
geo_intercept = fint->GetMinimumX();
if (geo_verbose) cout << "Pad " << i << " " << geo_intercept << endl;
fileout_c << geo_intercept << "\t" ;
finter_f1=fAlphaErr;
xErrEval[i]=geo_intercept-(fint->GetMinimumX());
}
if (PadIntercept==1){
finter_f1=fAlpha;
finter_f2=fPadL[i];
geo_intercept=fPadL[i]->Eval(fint->GetMinimumX());
if (geo_verbose) cout << "Pad " << i << " " << geo_intercept << endl;
fileout_l << geo_intercept << "\t" ;
}
}
if (PadIntercept==0) fileout_c << endl;
for (int i=0;i<8;i++){
if (PadIntercept==0) {
fileout_c << xErrEval[i] << "\t" ;
}
}
if (PadIntercept==0) fileout_c << endl;
if (PadIntercept==1) fileout_l << endl;
} //StripGate
} // PadIntercept
fileout_c.close();
fileout_l.close();
cout << "Analyzer::Loop processing run number " << run << endl;
if (fChain == 0) return;
//Fast function returns kBigNumber when it is TChain
//Long64_t nentries = fChain->GetEntriesFast(); // I think this caused segfault -- daid
Long64_t nentries = fChain->GetEntries();
cout << "Entries: " << nentries << endl;
Long64_t nbytes = 0, nb = 0;
//Fancy color palette
gStyle->SetPalette(1,0);
TCutG *cutg = new TCutG("mycut",6);
cutg->SetPoint(0,177.011,33.2405);
cutg->SetPoint(1,1733.76,33.1139);
cutg->SetPoint(2,4286.21,1.97468);
cutg->SetPoint(3,3709.34,2.10127);
cutg->SetPoint(4,153.305,29.443);
cutg->SetPoint(5,153.305,33.1139);
cutg->SetPoint(6,177.011,33.2405);
//Calibration params
Calibration *ssd_strip_calib=new Calibration("ssd_strip_calib.dat",97);//12x8
Calibration *ssd_padE_calib=new Calibration("ssd_padE_calib.dat",19);
Calibration *ssd_pad1a_calib=new Calibration("ssd_1a_calib.dat",9);
Calibration *ssd_padT_calib=new Calibration("ssd_padT_calib.dat",19);
Calibration *ppac_calib=new Calibration("ppac_calib.dat",10);
Calibration *rf_calib=new Calibration("rf_calib.dat",2);
Calibration *rf_ds_calib=new Calibration("rf_delay_calib.dat",2);
Calibration *beam_x_left_calib=new Calibration("beam_x_left_calib.dat",48);
Calibration *beam_x_right_calib=new Calibration("beam_x_right_calib.dat",48);
Calibration *hg_xc_calib=new Calibration("hg_xc_calib.dat",48);
Calibration *hg_x_left_calib=new Calibration("hg_x_left_calib.dat",48);
Calibration *hg_x_right_calib=new Calibration("hg_x_right_calib.dat",48);
Calibration *hg_center_calib=new Calibration("hg_center_calib.dat",8);
Calibration *beam_y_delay_calib1=new Calibration("beam_y_delay_calib1.dat",48);
Calibration *beam_y_delay_calib2=new Calibration("beam_y_delay_calib2.dat",48);
Calibration *beam_y_calib1=new Calibration("beam_y_calib1.dat",48);
Calibration *beam_y_calib2=new Calibration("beam_y_calib2.dat",48);
TDetector MSTPC;
vector<vector<Short_t> > tpc_ch=MSTPC.TDetector::SetTpcMap();
vector<vector<Double_t> > padBgain=MSTPC.TDetector::SetTpcBgain();
vector<Double_t> padXBgeo=MSTPC.TDetector::SetGeoXB();
vector<Double_t> padXCgeo=MSTPC.TDetector::SetGeoXC();
if (flag_detail){
if (flag_strip){
ssd_strip_calib->ScanFile();
ssd_strip_calib->ShowEntries();
}
if (flag_ssd){
ssd_padE_calib->ScanFile();
ssd_padE_calib->ShowEntries();
ssd_pad1a_calib->ScanFile();
ssd_pad1a_calib->ShowEntries();
ssd_padT_calib->ScanFile();
ssd_padT_calib->ShowEntries();
}
if (flag_ppac){
ppac_calib->ScanFile();
ppac_calib->ShowEntries();
// PPAC downscale coincidence delay (nearly 805 ns, but here in ch)
//there should be no need for these data? 07 Dec 2011 01:01:38
trig_dly_ppac[0][0]=8246.;
trig_dly_ppac[0][1]=8244.;
trig_dly_ppac[0][2]=8244.;
trig_dly_ppac[0][3]=8242.;
trig_dly_ppac[1][0]=8247.;
trig_dly_ppac[1][1]=8246.;
trig_dly_ppac[1][2]=8250.;
trig_dly_ppac[1][3]=8248.;
rf_calib->ScanFile();
rf_calib->ShowEntries();
rf_ds_calib->ScanFile();
rf_ds_calib->ShowEntries();
SetRF();
}
if (flag_tpc){
beam_x_right_calib->ScanFile();
beam_x_right_calib->ShowEntries();
beam_x_left_calib->ScanFile();
beam_x_left_calib->ShowEntries();
beam_y_delay_calib1->ScanFile();
beam_y_delay_calib1->ShowEntries();
beam_y_delay_calib2->ScanFile();
beam_y_delay_calib2->ShowEntries();
beam_y_calib1->ScanFile();
beam_y_calib1->ShowEntries();
beam_y_calib2->ScanFile();
beam_y_calib2->ShowEntries();
hg_xc_calib->ScanFile();
hg_xc_calib->ShowEntries();
hg_x_right_calib->ScanFile();
hg_x_right_calib->ShowEntries();
hg_x_left_calib->ScanFile();
hg_x_left_calib->ShowEntries();
hg_center_calib->ScanFile();
hg_center_calib->ShowEntries();
}
} // end if: flag_detail
//int ssdTime[18] = {0};
for (int i=0;i<6;i++) ssd_evts[i]=0;
static const UShort_t PpacSepZ = SetPpacSepZ();
// target projection function
// PPACa set as 0 position
fTargetX = new TF1("fTargetX","[0]+((x/[2])*([1]-[0]))",0,1000);
// PPACb set as 0 -- idential results if we use the target position which subtracts [2] for calling
// or we could make perfectly identical results if we summed that into the function itself
//fTargetX = new TF1("fTargetX","[0]+((x+[2])*(([1]-[0])/[2]))",0,1000);
fTargetX->SetParNames("PPACaX","PPACbX","PPAC Separation");
fTargetY = new TF1("fTargetY","[0]+((x/[2])*([1]-[0]))",0,1000);
fTargetY->SetParNames("PPACaY","PPACbY","PPAC Separation");