-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanip_table.h
1321 lines (1039 loc) · 39.8 KB
/
manip_table.h
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
//#include <TString.h>
//#include <TObjString.h>
//#include <TObject.h>
// interensting - needs this else doesnot compile..... Whaaaauuuuu
// moreover - no TString TObjString needed anymore if TChain declared
#include <TChain.h>
// ............. waste.......
//#include <TROOT.h>
//#include <TFile.h>
//#include <TSelector.h>
//-------------tminuit-----fit
#include <TMinuit.h>
//---- tgraph plot
#include <TH2F.h>
#include <TLine.h>
#include <TMarker.h>
#include <TPad.h>
#include <TStyle.h>
#include <TPaveText.h> // for histogram title
#include <TCanvas.h>
//#include <TExec.h>
/*
*
* manip_table.h
*
* - manipulations and evaluations of strings - reactions
* - projectile/ejectile identification
* - interpret variables inside the table
*/
/*
* specific language
* #define var T=11.8 replace all T with 11.8
* #free var dmylar can fit all dmylar
*/
/****************************************************************/
/* # sample.txt ---- file with definitions */
/* # definitions of variables and assignement of variables */
/* #define var T=11.8 */
/* #define var dmylar=12.0 */
/* #define var angd1=0.0 */
/* #define var de1a=0.2 */
/* #define var de1b=382.0 */
/* # calibration for dE1 */
/* #define var pde1_1=1.0 */
/* #define var pde1_0=0.0 */
/* ############################ */
/* # */
/* # all variables are fixed by default */
/* # */
/* #free var dmylar */
/* # */
/* # */
/* # */
/* # all the defined variables will be replaced by the numbers */
/****************************************************************/
bool DDEBUG = true; //lowercase
TCanvas *CANVMAIN;
// this is maximum lines in the table = maximum number of points - #definitions...
const int MAXLINES=1000;
const int MAXLINELENGTH=200; // 113 is usual for 14 items
//
/*******************************************************
* line[] keeps all the file in memory
*/
TString line[MAXLINES];
int linecolor[MAXLINES];
TCanvas* linecanv[MAXLINES]; //every line has a potential canvas
char legend[1500]="";
char legend2[1500]="";
TString colornames[10]={"black","red","green","blue","yellow","magenta","cyan","dgreen","dblue","white"};
TString alllosstables;
// main structure--------------------------------------
typedef struct{
int i;
int ap,zp, at,zt, ae,ze, ar,zr;
char losstab_proj[25];
char losstab_ejec[25];
char losstab_ejec_au[25]; //detector layers
char losstab_ejec_si[25];
char losstab_ejec_al[25];
double k,dk;
int kine; // what kinematics 1 or 2?
double T,Exc,ang;
double tck; // thickness of the foil (mylar)
double ly1,ly2;//detector layers
double p3,p2,p1,p0;
double E,dE;
double sidepth;// implantation depth in Si
} TSnrfit;
TSnrfit sr[MAXLINES];
#include "pb_basic.c"
// free_vars_step contains -1 or step
double free_vars_step[MAXVARIABLES];
int varnamefreelast=0;
int minuit_freevars, minuit_ndata;
// TGraphErrors - data to display :
const int MAXPOINTS=1000;
int tg_nmax;
double
tg_p1[MAXPOINTS],
tg_p0[MAXPOINTS],
tg_x[MAXPOINTS],
tg_xdep[MAXPOINTS],
tg_y[MAXPOINTS],
tg_dx[MAXPOINTS],
tg_dy[MAXPOINTS];
const double angle_error=0.1; // error of setting the angle ==0.1 degree
/******************************************************************
*
* readout_reac_file
*
* can be extremely slow, this runs only once.....
* prepares all the variables and it's values
*
* keeps the flie in memory
*/
//VERSION 2 int readout_reac_file(const char* filename){
int readout_reac_file(const char* filename, int ACTI=0 ){ //actual i for recursion
FILE * pFile;
int i, j , idest, imax=0;
TString token, token2;
char mystring[MAXLINELENGTH]; // temporary during readout
pFile = fopen ( filename ,"r");printf("+ ... opening...%s\n",filename);
if (pFile==NULL) { printf("! ... cannot open %s,STOP\n", filename ); return 1;}
i=ACTI;
while ((i<MAXLINES)&&( feof(pFile)==0) ){
if ( fgets (mystring , MAXLINELENGTH , pFile) ==NULL){
// mystring remains unchanged at the end, NULL is returned
// line[i]="\0";
line[i]=" ";
}else{
line[i]=mystring;
}
// line[i].ReplaceAll('\n','\0');
line[i].ReplaceAll('\n',' ');
int lastlen=line[i].Length();
if (DDEBUG){
if ( line[i].Data()[0]!='#'){
printf(" %02d/ %s /%02d/\n", i, line[i].Data() , lastlen );
}
}
if ( lastlen==0 ){
break;
}
// one space in place of sever spaces - easier to parse later
// also = will serve as token ==> removing spaces around
// e.g. if length < 4 ==> cannot be data "9 1"
// printf("line# %3d\n", i );
line[i].ToLower(); // necessary to BASIC & FOR lookup_table2
do {
lastlen=line[i].Length(); // again
// play with spaces ... reduce ... eliminate
line[i].ReplaceAll(" "," ");
line[i].ReplaceAll(" "," ");
line[i].ReplaceAll(" "," ");
//no spaces at the end of line (will append =)
if ( (line[i].Length()>0)&&(line[i].First('#')>=0) ){
line[i].Remove(line[i].First('#'), line[i].Length()-line[i].First('#'));
}
if ( (line[i].Length()>0)&&(line[i].First(' ')==0) ){
// printf("Lead1 /%s/\n", line[i].Data() );
// line[i].Strip(TString::kLeading);
line[i].Remove(0,1);
// line[i].Prepend("1111");
// printf("Lead2 /%s/\n", line[i].Data() );
}
// printf("LAST /%d : %d/\n", line[i].Last(' ') , line[i].Length() );
if ( (line[i].Last(' ')>0)&&(line[i].Last(' ')==line[i].Length()-1) ){
// printf("Trail1 /%s/\n", line[i].Data() );
// line[i].Strip(TString::kTrailing);
line[i].Remove( line[i].Length()-1,1);
// printf("Trail2 /%s/\n", line[i].Data() );
// line[i]=line[i](0,line[i].Length()-1) ;
}
// I use "=" IN DEFINITIONS
// line[i].ReplaceAll(" #","#"); // comment can start at any column
line[i].ReplaceAll(" =","=");
line[i].ReplaceAll("= ","=");
if (line[i].Length()<4){ line[i]=""; }
// printf(" replacing spaces %d -> %d\n", lastlen, line[i].Length() ) ;
// lastlen=line[i].Length();
}while( lastlen!=line[i].Length() );
//--------------------------------------------------- do while END
//if (DDEBUG){printf("D... checking for keyword %s","\n");}
//----------------------------------------------- check for keywords
if (line[i].Length()>=0){//same i if not problem with include-//-include
//------------NEW
if ( line[i].Index("define var")==0){
printf("i ... %s DEFINEVAR\n", line[i].Data() ); line[i].Append("=");
}
if ( line[i].Index("free var")==0){
printf("i ... %s FREEVAR\n", line[i].Data() ); line[i].Append("=");
}
if ( line[i].Index("spectrum")==0){
printf("i ... %s SPECTRUM\n", line[i].Data() ); line[i].Append("=");
}
/*
if ( line[i].Index("spectrum")==0){
printf("i ... %s\n", line[i].Data() ); line[i].Append("=");
TObjArray *tars= line[i].Tokenize("=");
TString tokeny2;
tokeny2= ((TObjString*)(tars->At(1)))->GetString();//value=name of spe
printf("+ ... ... searching for TH1F /%s/\n", tokeny2.Data() );
TH1F*hde=(TH1F*)gDirectory->Get( tokeny2.Data() );
if (hde!=NULL){
printf("i ... ... TH1F /%s/ found\n", tokeny2.Data() );
tokeny2.Prepend("canv");
TCanvas *c=new TCanvas( tokeny2.Data() , tokeny2.Data() );
printf("+ ... ... creating canvas %s\n", tokeny2.Data() );
c->Draw(); c->cd();
hde->Draw();
c->SetLogy();
c->SetGridy();
c->SetGridx();
}else{ printf("i ... ... TH1F /%s/ NOT found\n", tokeny2.Data() ); }
printf("+ ... opening canvas and spectrum %s\n", token2.Data() );
//i--; // this will remove completely the trace of include
tars->Delete();
}// spectrum=
*/
if ( line[i].Index("include")==0){
printf("i ... %s ", line[i].Data() ); line[i].Append("=");
TObjArray *tar= line[i].Tokenize("=");
TString token, token2;
token2= ((TObjString*)(tar->At(1)))->GetString();//value
printf("+ ... including file /%s/ at line %d\n", token2.Data() , i );
//i--; // this will remove completely the trace of include
i=readout_reac_file( token2.Data() , i+1 );
i++;line[i]="include return";
tar->Delete();
}// include=
if (line[i].Length()==0){
i=i-1;
}// empty line --- remove line /problem at include-include/
if (line[i].Index("#")==0){
i=i-1;
}//starts with # --- remove line
// printf ("%s\n", line[i].Data() );
i=i+1;
imax=i;
}//length>3 else just continue with the same i
else{ line[i]="";}// last line
}//while i<MAXLINES
printf("+ ... closing.../%s/ at line %d\n", filename, i );
fclose (pFile);
//------------------readount done -------------
if (ACTI==0){
printf("i ... REVIEW of %s+includes:\n",filename );
for (i=0;i<imax;i++){
printf ("%02d/ %s\n", i, line[i].Data() );
}
} //ACTI==0
else{
return imax-1; // this is for the recursion ....
}
//------------------readount done -------------
//................ SECOND ROUND ............ free vars first
// **** create table of variables ********
/* free vars must be first in the table.
* clear namespace and start with freevars
*/
init_namespace();
i=0;
printf("+ ... preparing free vars%s\n"," ---------------------------------------------- ");
while( line[i].Length()>0 ){
if (line[i].Index("free var ")==0 ){//free var
TObjArray *tar= line[i].Tokenize("=");
//printf(" %d) /%s/\n", tar->GetEntries(), line[i].Data() ); // must be3
token= ((TObjString*)(tar->At(0)))->GetString();
// at 1 is 'step'
token2= ((TObjString*)(tar->At(2)))->GetString();
token.Remove(0,9);// remove the #text
if (token.Length()>11){
printf("maximum variables' name length is 12 /%s/\n",
token.Data() ); return 1;}
j=lookup_table_tk( token.Data() );//variable's position
tar->Delete();
free_vars_step[j]=token2.Atof();// fill the value
printf(" ... free var /%s/\t @%02d has step %11.5lf /%s/\n",
token.Data() , j, free_vars_step[j], line[i].Data() );
line[i]=""; // NEW DELETE-NO MORE NEEDED_PUZZLES 14element
}//free var
i++;
}//while
//....................... THIRD ROUND ......................
// now we have namespace with all the free variables allocated.
varnamefreelast=varnamelast;
// for (int i=0;i<varnamelast;i++){printf("%s=%lf\n", varname[i],variables[i]);}
printf("i ... number of free vars= %d\n", varnamefreelast );
//============================================================END FREE VAR
minuit_freevars=varnamefreelast;
/* =======================
* REORDER REORDER lines, clear comments, other values into name table
*/
printf("+ ... reordering for minuit (%d)\n", varnamefreelast );
i=0; idest=0;// i is source line, j is destination line
int colorstack=1;
if ( colorstack-1<10 ){
sprintf(legend,"%s=%s ",colornames[colorstack-1].Data(),filename);
} else{
sprintf(legend," %s ",filename);
}
// while( line[i].Length()>0 ){
while( i<imax ){
printf ("%3d->%3d %s", i,idest,line[i].Data() );
// NEW: put data lines
// ...+whatever not KEYWORD and non empty=> push to idest.
//------------------ spectrum....quite new thing:if TH1=>canvas;cd()
if (line[i].Index("spectrum")==0 ){
TObjArray *tars= line[i].Tokenize("=");
TString tokeny2;
tokeny2= ((TObjString*)(tars->At(1)))->GetString();//value
printf("+ ... ... searching for TH1F /%s/ in gDir\n", tokeny2.Data() );
TH1F*hde=(TH1F*)gDirectory->Get( tokeny2.Data() );
if (hde!=NULL){
printf("i ... ... TH1F /%s/ found\n", tokeny2.Data() );
tokeny2.Prepend("canv");
linecanv[i]=(TCanvas*)gROOT->GetListOfCanvases()->FindObject( tokeny2.Data() );
if ( linecanv[i]==NULL){
printf("+ ... ... creating canvas %s\n", tokeny2.Data() );
linecanv[i]=new TCanvas( tokeny2.Data() , tokeny2.Data() );
}else{ printf("+ ... ... existing canvas %s\n", tokeny2.Data() );}
linecanv[i]->Draw();linecanv[i]->cd();hde->Draw();
linecanv[i]->SetLogy();linecanv[i]->SetGridy();linecanv[i]->SetGridx();
for (int j=i;j<MAXLINES;j++){
linecanv[j]=linecanv[i]; // all following lines have this canvas.
}
}else{ printf("i ... ... TH1F /%s/ NOT found\n", tokeny2.Data() ); }
tars->Delete();
line[i]="";
} //if spectrum
//---------------- color plays...and now also spectrum
if (line[i].Index("include=")==0){
if (colorstack<0){colorstack=-colorstack;}
colorstack++;
// printf("### %s ### \n",line[i].Data() );
TObjArray *tarx= line[i].Tokenize("=");
TString tokenx2=((TObjString*)(tarx->At(1)))->GetString();
tarx->Delete();
sprintf(legend2,"%s",legend);
if ( colorstack-1<10 ){ // maybe avoids the crash....
sprintf(legend,"%s / %s=%s",legend2,colornames[colorstack-1].Data(),tokenx2.Data() );
}else{
sprintf(legend,"%s / %s",legend2,tokenx2.Data() );
}
}//-------------if include-fill colorstack,legend for later linecolor
if (line[i].Index("include return")==0){colorstack=-colorstack;}
//================= if not KEYWORD => put data to the queue
if (
(line[i].Index("define var")!=0)&&
(line[i].Index("free var")!=0)&&
(line[i].Index("include")!=0)&&
(line[i].Index("spectrum")!=0)&&
( line[i].Length()>0)
){
line[idest]=line[i].Data();
linecanv[idest]=linecanv[i]; //one spectrum=>all lines have canvas
if (colorstack>0){linecolor[idest]=colorstack;}else{linecolor[idest]=1;}
idest++;
if (linecanv[i]!=NULL){
linecanv[i]->cd();
int col=1;
TObjArray *tarz=line[i].Tokenize(" ");
TString tokenz=((TObjString*)(tarz->At(0)))->GetString();
printf("\np ... printing MARKER at %s=%f", tokenz.Data() ,atof(tokenz.Data() ));
tarz->Delete();
TMarker *m=new TMarker( atof(tokenz.Data() ) , 3., 20 );
if (colorstack>0){m->SetMarkerColor(colorstack);}
m->Draw();
}// linecanv[i] ok
}//=============== data to queue ==========================
//insert the variable into the table: FIXED size 12 of "#define var "
if (line[i].Index("define var ")==0 ){
TObjArray *tar= line[i].Tokenize("=");
printf("%d\n", tar->GetEntries() );
token= ((TObjString*)(tar->At(0)))->GetString();//var
token2= ((TObjString*)(tar->At(1)))->GetString();//value
token.Remove(0,11);// remove the #text, varname remains
j=lookup_table_tk( token.Data() );//variable's position
tar->Delete();
variables[j]=token2.Atof();// fill the value
// printf("\t... var /%s/ @%02d contains %11.5lf\n",
// token.Data() , j, variables[j] );
line[i]=""; //NEW DELETE LINE-NO MORE NEEDED-PUZZLES 14element
}else{//define var
printf("%s\n","");
}//define var
i=i+1;// next
}// while line[i] contains something/reordering---------done ---
minuit_ndata=(idest);
printf("i ... number of data for minuit = %3d\n", minuit_ndata );
printf("i ... number of vars for minuit = %3d\n", varnamefreelast );
printf("i ... number of defined variables= %3d\n", varnamelast );
/*
* no we have namespace with all the free variables allocated.
*/
// for (int i=0;i<varnamelast;i++){printf("%s=%lf\n", varname[i],variables[i]);}
printf("-------------- readout calibration file ended -----------------------------------%s\n", "");
line[idest]=""; // last line ""
return 0;
}//readout_reac_file
/***********************************************************************
*
* analyze the reaction description and material
*
* in principle - we need 2 tables to load
*/
int parse_reaction_and_material(int iline, const char* react, const char* mat){
TString reactS,proj,tgt1,ejec,remn,kine12;
TString losstable;
int kine;
// printf("parsing material %s and %s\n", react, mat );
reactS=react;
TObjArray *tar=reactS.Tokenize("_");
//
proj= ((TObjString*)(tar->At(0)))->GetString();
tgt1= ((TObjString*)(tar->At(1)))->GetString();
ejec= ((TObjString*)(tar->At(2)))->GetString();
remn= ((TObjString*)(tar->At(3)))->GetString();
kine=1;
if (tar->GetEntries() >4 ){
kine12= ((TObjString*)(tar->At(4)))->GetString();
if (kine12.CompareTo("k2")==0){ kine=2; }
}//if kine12 defined
// printf("%4s %4s %4s %4s %4s \n",proj.Data(),tgt1.Data(), ejec.Data(), remn.Data(), kine12.Data() );
//alllosstables="";
//----------------------------------- structure
int * azp, *azt, *aze, *azr;
azp=(int*)getAZ( proj.Data() );
azt=(int*)getAZ( tgt1.Data() );
aze=(int*) getAZ( ejec.Data() );
azr=(int*) getAZ( remn.Data() );
printf("%3d %3d/ %3d %3d/ %3d %3d/ %3d %3d\n", azp[0],azp[1], azt[0],azt[1], aze[0],aze[1], azr[0],azr[1] );
sr[iline].i=iline;
sr[iline].ap=azp[0]; sr[iline].zp=azp[1];
sr[iline].at=azt[0]; sr[iline].zt=azt[1];
sr[iline].ae=aze[0]; sr[iline].ze=aze[1];
sr[iline].ar=azr[0]; sr[iline].zr=azr[1];
sr[iline].kine= kine;// kinematics 1 or 2
//---------------------------------- loss
losstable=proj.Data();
losstable.Append("_in_");
losstable.Append( mat );
losstable.Append(".los");
sprintf( sr[iline].losstab_proj, "%s", losstable.Data() );
losstable.Append(" ");
// printf("%s ---> %s\n", losstable.Data(), alllosstables.Data() );
if ( alllosstables.Index(losstable.Data())<0){
alllosstables.Append( losstable.Data() );
}
losstable=ejec.Data();
losstable.Append("_in_");
losstable.Append( mat );
losstable.Append(".los");
sprintf( sr[iline].losstab_ejec, "%s", losstable.Data() );
losstable.Append(" ");
// printf("%s -2-> %s\n", losstable.Data(), alllosstables.Data() );
if ( alllosstables.Index(losstable.Data())<0){
alllosstables.Append( losstable.Data() );
}
/********
* specialy in Au and Si for detectors 1/3
*/
losstable=ejec.Data();
losstable.Append("_in_");
losstable.Append( "au" );
losstable.Append(".los");
sprintf( sr[iline].losstab_ejec_au, "%s", losstable.Data() );
losstable.Append(" ");
// printf("%s -2-> %s\n", losstable.Data(), alllosstables.Data() );
if ( alllosstables.Index(losstable.Data())<0){
alllosstables.Append( losstable.Data() );
}
/*
* specialy in Au and Si for detectors 2/3
*/
losstable=ejec.Data();
losstable.Append("_in_");
losstable.Append( "si" );
losstable.Append(".los");
sprintf( sr[iline].losstab_ejec_si, "%s", losstable.Data() );
losstable.Append(" ");
// printf("%s -2-> %s\n", losstable.Data(), alllosstables.Data() );
if ( alllosstables.Index(losstable.Data())<0){
alllosstables.Append( losstable.Data() );
}
/*
* specialy in Au and Si for detectors 3/3
*/
losstable=ejec.Data();
losstable.Append("_in_");
losstable.Append( "al" );
losstable.Append(".los");
sprintf( sr[iline].losstab_ejec_si, "%s", losstable.Data() );
losstable.Append(" ");
// printf("%s -2-> %s\n", losstable.Data(), alllosstables.Data() );
if ( alllosstables.Index(losstable.Data())<0){
alllosstables.Append( losstable.Data() );
}
//printf("losstables==%s,%s\n",losstable.Data(),losstable2.Data());
// if (load_losses_table( losstable.Data())!=0){return 1;}
// if (load_losses_table( losstable2.Data())!=0){return 1;}
// load_losses_table( losstable2.Data() );
return 0;
}//parse_reaction_and_material
/***********************************************
* interpolate the fixed variables in the table, leave the free
* only lines with data
* fill in the structure[i]
* prepare and load losstables
*
* in principle - it is reasobale to interpolate
* column #5-#14 i.e. i=4...13
*
*
*/
int interpolate_varnames_in_table(){
int i=0, j, look1, look2, acceptedlines=0;
TString token, tok, tok2;
//
alllosstables="";
look1=varnamelast;
while( line[i].Length()>0 ){
// if (line[i].Index("#")!=0 ){// not comment
TObjArray *tar=line[i].Tokenize(" ");
if (tar->GetEntries() != 14 ){ printf("data have not 14 collumns.stop%s\n","");return 1;}
if (tar->GetEntries() == 14 ){
acceptedlines++;
//------- go through all the tokens and print -----
for (int k=0;k<tar->GetEntries();k++){
if ( (k!=2)&&(k!=3) ){
tok= ((TObjString*)(tar->At(k)))->GetString();
if ( tok.IsFloat() ){
// printf(" %7.2f", tok.Atof() );
if (k== 0){ sr[i].k = tok.Atof() ; }
if (k== 1){ sr[i].dk = tok.Atof() ; }
if (k== 4){ sr[i].Exc= tok.Atof() ; }
if (k== 5){ sr[i].T = tok.Atof() ; }
if (k== 6){ sr[i].tck= tok.Atof() ; }
if (k== 7){ sr[i].ang= tok.Atof() ; }
if (k== 8){ sr[i].ly1= tok.Atof() ; }
if (k== 9){ sr[i].ly2= tok.Atof() ; }
if (k==10){ sr[i].p3 = tok.Atof() ; }
if (k==11){ sr[i].p2 = tok.Atof() ; }
if (k==12){ sr[i].p1 = tok.Atof() ; }
if (k==13){ sr[i].p0 = tok.Atof() ; }
}else{// IS NOT FLOAT.........=> variable
// replace fixed parameters here and treat the formulea
char expr[120];
//done tok.ToLower(); // NECESSARY FOR lookup_table2
sprintf( expr, "%s" , tok.Data() ) ;
if ( (strpbrk( expr , "+" )!=NULL)||
(strpbrk( expr , "-" )!=NULL)||
(strpbrk( expr , "*" )!=NULL)||
(strpbrk( expr , "/" )!=NULL)
){
printf("FORMula=%s\n" , tok.Data() );
}else{//lookup_table2_isform==1
j=lookup_table_tk( tok.Data() ); // key point - the NAME
if (varnamelast>look1){
printf("! ... PROBLEM - undefined variable /%s/ %d>%d=TOTAL\n", tok.Data(), varnamelast, look1 );
return 9999;
}
if (free_vars_step[j]<=0.0){
// printf(" %7.2f", variables[j] );
char ch[40]; sprintf( ch, "%lf", variables[j] );
line[i].Replace( line[i].Index(varname[j]), strlen(varname[j]),ch );
if (k== 4){ sr[i].Exc= variables[j] ; }
if (k== 5){ sr[i].T = variables[j] ; }
if (k== 6){ sr[i].tck= variables[j] ; }
if (k== 7){ sr[i].ang= variables[j] ; }
if (k== 8){ sr[i].ly1= variables[j] ; }
if (k== 9){ sr[i].ly2= variables[j] ; }
if (k==10){ sr[i].p3 = variables[j] ; }
if (k==11){ sr[i].p2 = variables[j] ; }
if (k==12){ sr[i].p1 = variables[j] ; }
if (k==13){ sr[i].p0 = variables[j] ; }
}//else{//free/fixed
//printf(" %7s", varname[j] );
//}//free/fixed
//if (k==13) {printf("%s\n","");}//new line at te last
}//lookup_table2_isform==1
}//if else lfoat
}// not k 2 nor k 3 (reaction and medium)
}// for all tar
}// MUST be 14 entries, else skip
tok = ((TObjString*)(tar->At(2)))->GetString();
tok2= ((TObjString*)(tar->At(3)))->GetString();
int r=parse_reaction_and_material( i, tok.Data(), tok2.Data() );
if (r!=0){ return 1;}
delete tar; // manual says I must delete it
// }//if line is LIVE == not commented
/***********************************************************************/
/* else{//this stage removes all commented lines that are FIXED */
/* if (line[i].Index("#define var ")==0){ */
/* TObjArray *tar= line[i].Tokenize("="); */
/* token= ((TObjString*)(tar->At(0)))->GetString();//var */
/* token.Remove(0,12);// remove the #text, varname remains */
/* tar->Delete(); */
/* }//#defined var */
/***********************************************************************/
//}// it was commented..... remove FIXED
i=i+1;// next
}// while line[i] contains something-------------done ---
// printf( "%d lines from the original table accepted\n", acceptedlines );
/*
* check if something didnt go wrong.....
*/
look2=varnamelast;
if (look1 != look2){
printf("%s\n","Problem, some table items were treated as variables but they were not present in lookup table....and they were added to it. stop please.\n\n ");
return 1;
}// varnamelast changed
i=0; printf("----------------------------------------%s\n","");
printf("\ni ... INTERPOLATED values TABLE:%s\n"," ------------------------------------------- ");
while( line[i].Length()>0){printf("%2d %s\n",i,line[i].Data() );i++;}
i=0; printf("----------------------------------------%s\n\n","");
// alllosstables
printf("\nx ... list of ALLLOSS TABLES:\n%s\n", alllosstables.Data() );
if (load_losses_table_all( alllosstables )!=0){return 1;}
printf("---------------------------------------------------%s\n","");
/*
* last printout of variable table
*/
printf("i ... list of variable's space%s:\n", "" );
for (int i=0;i<varnamelast;i++){
if (i<varnamefreelast){
printf("%14s=%19.7lf (%lf)\n",varname[i],variables[i],free_vars_step[i] );
}else{
printf("%14s=%19.7lf \n",varname[i],variables[i] );
}
}
return 0;
}//interpolate_varnames_in_table
/***********************************************
*
* do_kinematics
*
* fill the remaining variables
* (printout)
* compute loss in 50% of thickness of the tgt layer
*
*
*
*/
double do_kinematics(int sverbo){
int verbo=sverbo;
double DE=0.0;
double CHI2=0.0;
int i=0, k=0;
TString token, tok, tok2;
double TKE, TKE_ae, TKE_in, TKE_out, TKE_IN_SI; //TKE angle error
double SLICE=0.1; // 0.1um was in ver.1
int verb=0; // 0..no, 3.. max
int look1, look2;
look1=varnamelast;
while( line[i].Length()>0 ){
TObjArray *tar=line[i].Tokenize(" ");
// start with 4 (Exc., T, ...)
for (k=4;k<tar->GetEntries();k++){
tok= ((TObjString*)(tar->At(k)))->GetString();
if ( tok.IsFloat()==1 ){
}else{//all done for float-do for string
double variablesj;
char expr[120];
sprintf( expr, "%s" , tok.Data() ) ;
variablesj=lookup_table2( expr );
/* if (lookup_table2_isform( expr )==1){ */
/* printf("FORM=%s\n" , tok.Data() ); */
/* }else{//lookup_table2_isform==1 */
/* j=lookup_table( tok.Data() ); */
/* variablesj=variables[j]; */
/* } */
// variables[j];
if (k== 4){ sr[i].Exc= variablesj ; }
if (k== 5){ sr[i].T = variablesj ; }
if (k== 6){ sr[i].tck= variablesj ; }
if (k== 7){ sr[i].ang= variablesj ; }
if (k== 8){ sr[i].ly1= variablesj ; }
if (k== 9){ sr[i].ly2= variablesj ; }
if (k==10){ sr[i].p3 = variablesj ; }
if (k==11){ sr[i].p2 = variablesj ; }
if (k==12){ sr[i].p1 = variablesj ; }
if (k==13){ sr[i].p0 = variablesj ; }
}//tok is not float
}//for all k
tar->Delete();
if (verbo!=0){
//-----------------------------PRINTOUT BEGIN
if (i==0)
printf("azp azt aze azr, (kinem) k dk, Exc T thickness ang, /layer1 layer2/ <p3 p2 p1 p0>%s\n","");
printf("%3d %3d,%3d %3d,%3d %3d,%3d %3d,(%1d) %9.3lf %9.3lf, %9.3lf %9.3lf %9.3lf, %9.3lf /%9.3lf %9.3lf/ < %9.3lf %9.3lf %9.5lf %9.5lf > \n",
sr[i].ap, sr[i].zp, sr[i].at, sr[i].zt,
sr[i].ae, sr[i].ze, sr[i].ar, sr[i].zr,
sr[i].kine,
sr[i].k,sr[i].dk,
sr[i].Exc, sr[i].T, sr[i].tck, sr[i].ang,
sr[i].ly1, sr[i].ly2,
sr[i].p3, sr[i].p2, sr[i].p1, sr[i].p0 //,
// sr[i].losstab_proj,
//sr[i].losstab_ejec
);
}// verbo ==0
//-----------------------------PRINTOUT END
//------------------loose in 50%-----------BEGIN
// TKE=loose_E( sr[i].T , sr[i].losstab_proj , 0.5*sr[i].tck , SLICE, verb );
//===== 1 ======
if (sr[i].tck<0.){sr[i].tck= -sr[i].tck;}
TKE=loose_E( sr[i].T , sr[i].losstab_proj , 0.5*sr[i].tck , SLICE, 0 );
// if (verbo!=0){ printf("TKE=%11.5f(mid) ", TKE ); }
//
// ---------------- KINEMATICS --------------
//
// extra evaluated angle error-else it is too stick to angle
//
//===== 2 ======
TKE_ae=angular_E3( sr[i].ap, sr[i].zp, sr[i].at, sr[i].zt,
sr[i].ae, sr[i].ze, sr[i].ar, sr[i].zr,
TKE, sr[i].ang-angle_error, sr[i].kine, sr[i].Exc,
verb );
TKE =angular_E3( sr[i].ap, sr[i].zp, sr[i].at, sr[i].zt,
sr[i].ae, sr[i].ze, sr[i].ar, sr[i].zr,
TKE, sr[i].ang, sr[i].kine, sr[i].Exc,
verb );
TKE_ae= (TKE-TKE_ae)* (TKE-TKE_ae) ; //contains an error fronm angle ^2
// if (verbo!=0){ printf("%11.5f(ejec)", TKE );}
//
//Ap,Zp, At,Zt, Ae,Ze, Ar,Zr, TKE , ang , sol , Exc ,verb );// sol 1/2, excE
// TKE=t3a;
//------------------loose in 50%-----------END
//===== 3 ======
double extendl= sr[i].ang/180*3.1415926;
extendl=1.0/cos(extendl) * sr[i].tck;
TKE=loose_E( TKE , sr[i].losstab_ejec , 0.5*extendl , SLICE, 0 );
if (TKE<0){ verbo=3; return -1.0; }
// if (verbo!=0){ printf("%11.5f(full)", TKE );}
// ....DETECTOR......
//
// GOLDEN LAYER ===== now it is 1st SILICON =========
//
//===== 4 ====== NEWly SILICON dE detector
double dTKE=TKE; //before dE
if (sr[i].ly1>0){
TKE=loose_E( TKE , sr[i].losstab_ejec_si , sr[i].ly1 , SLICE, 0 );
if (TKE<0){ verbo=3; return -1.0; }
// if (verbo!=0){ printf("%11.5f(au)", TKE );}
// Si LAYER
}
dTKE=dTKE-TKE; // (positive) loss in the dE
TKE_in=TKE; // before final
//===== 5 ====== final detector DO I NEED TO HAVE EXTRA INPUT?
/*
* SI LAYER
*/
TKE_out=loose_E( TKE , sr[i].losstab_ejec_si , sr[i].ly2 , SLICE, 0 );
TKE_IN_SI = TKE_in - TKE_out; // Energy deposited in the detector
//===== FINAL VALUES : ======
if (TKE_out==0.0){// find implantation depth
TKE_out=loose_E( TKE ,sr[i].losstab_ejec_si , sr[i].ly2 , -SLICE, 0 );
sr[i].sidepth=TKE_out;
}// stopped
else{ sr[i].sidepth=sr[i].ly2; }
// if (verbo!=0){ printf("%11.5f(si) (in Si=%11.5f)\n", TKE_out, TKE_IN_SI );}
// stop here.....
/*
* e , de from linear dependence
*/
sr[i].E = TKE_IN_SI + dTKE ; // NEWly : total energy dE+E
//to je kravina
// sr[i].dE= TKE_IN_SI * sr[i].p1* sr[i].dk ;// preliminary linear dependence
/*
* preliminary linear dependence
* combined with angular error influence
*/
sr[i].dE= sqrt( (TKE_ae)+ pow( sr[i].p1 * sr[i].dk,2.0) ) ;
// sr[i].dE= TKE * sr[i].dk/sr[i].k ; // not this...
/*
* need to weight....
*/
DE= sr[i].E -
( sr[i].p3*sr[i].k*sr[i].k*sr[i].k
+sr[i].p2*sr[i].k*sr[i].k
+sr[i].p1*sr[i].k
+sr[i].p0 );
CHI2=CHI2+ DE*DE/sr[i].dE/sr[i].dE;
//TGraphErrors - fill in the global fields:
if (i<MAXPOINTS){
tg_x[i] =sr[i].k;
tg_xdep[i] =sr[i].sidepth;
tg_y[i] =sr[i].E;
tg_dx[i]=sr[i].dk;
tg_dy[i]=sr[i].dE;
tg_p1[i]=sr[i].p1;
tg_p0[i]=sr[i].p0;
tg_nmax=i+1;