/[PAMELA software]/tof/flight/ToFNuclei/src/ToFNuclei.cpp
ViewVC logotype

Annotation of /tof/flight/ToFNuclei/src/ToFNuclei.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Fri Dec 28 15:52:46 2018 UTC (6 years ago) by mayorov
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +476 -411 lines
Modified to implement new tracking algorithm output (NB no back :compatibility! Elena

1 pamelats 1.2 //*****************************************************
2 mayorov 1.9 // october 2015: Updated for use in 10th reduction
3     // calibration parameters changed to 10th reduction dEdx
4     //
5 pamelats 1.2 //24-feb-2009: introduced "beta_in" and "Set_Beta":
6     // beta_in is set to 100 by default. If it is not overwritten
7     // by "Set_Beta" (ToFNuclei.h), the code is used as before.
8     // If beta_in was set by the user using "Set_Beta", this beta
9     // is taken for the calculations.
10 pamelats 1.4 //
11 pamelats 1.3 //26-feb-2009: Inserted S115B calibrations from Lucia
12 pamelats 1.2 //
13 pamelats 1.4 //02-apr-2009: bug found in some "if" statements for the
14 pamelats 1.3 // "Layercharge" definition, but only important if ADC=4095
15 pamelats 1.4 //
16     //15-apr-2009: small bug found in the calculation of the PMT
17     // charge, the charge for the PMTs 1,9,28.. was calculated
18     // twice, but the final result was OK
19 pamelats 1.5 //
20     //05-may-2009: bug found in the calculation of the PMT
21     // charge for standalone ToF due to changes made for rev 1.4:
22     // For PMTs 4,8,39,41 (counting 0..47) no charge was calculated
23     // calibration arrays now including correct brackets to avoid
24     // compiler warnings
25 pamelats 1.6 //06-aug-2009: charge_layer_trk_raw and charge_layer_std_raw
26     // added: These are the "raw" values before doing the 2nd-order
27     // correction
28 pamelats 1.2 //*****************************************************
29 pamela 1.1 #include <ToFNuclei.h>
30    
31     //--------------------------------------
32     /**
33     * Default constructor
34     */
35 mayorov 1.9 //ToFNuclei::ToFNuclei(){
36     // Clear();
37     //};
38 pamela 1.1
39 mayorov 1.9 ToFNuclei::ToFNuclei(PamLevel2 *l2p,const char* alg){
40 pamela 1.1 //
41     Clear();
42     //
43     L2 = l2p;
44     //
45 pamelats 1.2 beta_in = 100.;
46     //
47 pamela 1.1 if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
48     //
49     OBT = 0;
50     PKT = 0;
51     atime = 0;
52     //
53     sntr = 0;
54     debug = false;
55 mayorov 1.9 trkAlg = alg;
56 pamela 1.1 //
57     };
58    
59     void ToFNuclei::Clear(){
60     //
61 mocchiut 1.7 ncount_trk = 0;
62 pamela 1.1 charge_trk = 0.;
63     memset (charge_layer_trk,0,6*sizeof(Float_t)); //
64 pamelats 1.6 memset (charge_layer_trk_raw,0,6*sizeof(Float_t)); //
65 pamelats 1.2 memset (charge_PMT_trk,0,48*sizeof(Float_t)); //
66 pamela 1.1 memset (layerinfo_trk,0,6*sizeof(Int_t)); //
67 mocchiut 1.7 ncount_std = 0;
68 pamela 1.1 charge_std = 0.;
69     memset (charge_layer_std,0,6*sizeof(Float_t)); //
70 pamelats 1.6 memset (charge_layer_std_raw,0,6*sizeof(Float_t)); //
71 pamelats 1.2 memset (charge_PMT_std,0,48*sizeof(Float_t)); //
72 pamela 1.1 memset (layerinfo_std,0,6*sizeof(Int_t)); //
73     };
74    
75     void ToFNuclei::Print(){
76     //
77     Process();
78     //
79     printf("========================================================================\n");
80     printf(" OBT: %u PKT: %u ATIME: %u Track %i \n",OBT,PKT,atime,tr);
81     printf(" std : charge %f ncount %d layers %f %f %f %f %f %f \n",charge_std,ncount_std,charge_layer_std[0],charge_layer_std[1],charge_layer_std[2],charge_layer_std[3],charge_layer_std[4],charge_layer_std[5]);
82     printf(" std : layerinfo %d %d %d %d %d %d \n",layerinfo_std[0],layerinfo_std[1],layerinfo_std[2],layerinfo_std[3],layerinfo_std[4],layerinfo_std[5]);
83    
84     printf(" trk : charge %f ncount %d layers %f %f %f %f %f %f \n",charge_trk,ncount_trk,charge_layer_trk[0],charge_layer_trk[1],charge_layer_trk[2],charge_layer_trk[3],charge_layer_trk[4],charge_layer_trk[5]);
85     printf(" trk : layerinfo %d %d %d %d %d %d \n",layerinfo_trk[0],layerinfo_trk[1],layerinfo_trk[2],layerinfo_trk[3],layerinfo_trk[4],layerinfo_trk[5]);
86     printf("========================================================================\n");
87     //
88     };
89    
90     void ToFNuclei::Delete(){
91     Clear();
92     };
93    
94    
95     void ToFNuclei::Process(){
96     Process(0);
97     };
98    
99     void ToFNuclei::Process(Int_t ntr){
100     //
101     if ( !L2 ){
102     printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
103     printf(" ERROR: CaloExample variables not filled \n");
104     return;
105     };
106     //
107     Bool_t newentry = false;
108 mayorov 1.9
109 pamela 1.1 //
110     if ( L2->IsORB() ){
111     if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || ntr != sntr ){
112     newentry = true;
113     OBT = L2->GetOrbitalInfo()->OBT;
114     PKT = L2->GetOrbitalInfo()->pkt_num;
115     atime = L2->GetOrbitalInfo()->absTime;
116     sntr = ntr;
117     };
118     } else {
119     newentry = true;
120     };
121     //
122 mayorov 1.9
123 pamelats 1.2 if ( !newentry ) {
124     return;
125     }
126 pamela 1.1 //
127     tr = ntr;
128     //
129     if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);
130     //
131     // charge_trk = 0.;
132     // memset (charge_layer_trk,0,6*sizeof(Float_t)); //
133     // charge_std = 0.;
134     // memset (charge_layer_std,0,6*sizeof(Float_t)); //
135    
136     Clear();
137    
138 pamelats 1.2 // cout<<"beta_in = "<<beta_in<<endl;
139    
140 pamela 1.1
141 mayorov 1.9 Double_t time;
142    
143     if ( L2->IsORB() ){
144     time = L2->GetOrbitalInfo()->absTime;
145     } else {
146     time = 1153000000.; // simulated data no OrbitalInfo fixed date 15-jul-2006
147     };
148    
149 pamela 1.1
150     //=======================================================================
151     //============== Siegen version 1 ====================
152     //============== track dependent dEdx and beta ====================
153     //=======================================================================
154    
155     //if (L2->GetTrkLevel2()->GetNTracks()!=1) return;
156 mayorov 1.9 //if (L2->GetTrkLevel2()->GetNTracks()==1) {
157    
158     if( L2->GetNTracks(trkAlg)>=1 ){
159 pamelats 1.2 /*
160 pamela 1.1 Float_t PMTsat[48] = {
161     3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37, 3130.05, 3087.07, 3112.22,
162     3102.92, 3080.58, 3092.55, 3087.94, 3125.03, 3094.09, 3143.16,
163     3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53, 3097.11, 3133.53, 3114.73, 3113.01, 3091.19,
164     3097.99, 3033.84, 3134.98, 3081.37, 3111.04, 3066.77, 3108.17,
165     3133, 3111.06, 3052.52, 3140.66, 3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11
166 pamelats 1.2 };
167     */
168    
169     // new values from Napoli dec 2008
170     Float_t PMTsat[48] = {
171     3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
172     3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
173     3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
174     3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
175     3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
176     3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
177    
178     for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
179    
180 pamela 1.1
181 pamelats 1.2 Float_t C0t[48][9] = {
182 mayorov 1.9 {0, 1, 2, 3, 4, 5, 6, 8, 90},
183     {0, 1, 2, 3, 4, 5, 6, 8, 90},
184     {0, 1, 2, 3, 4, 5, 6, 8, 90},
185     {0, 1, 2, 3, 4, 5, 6, 8, 90},
186     {0, 1, 2, 3, 4, 5, 6, 8, 90},
187     {0, 1, 2, 3, 4, 5, 6, 8, 90},
188     {0, 1, 2, 3, 4, 5, 6, 8, 90},
189     {0, 1, 2, 3, 4, 5, 6, 8, 90},
190     {0, 1, 2, 3, 4, 5, 6, 8, 90},
191     {0, 1, 2, 3, 4, 5, 6, 8, 90},
192     {0, 1, 2, 3, 4, 5, 6, 8, 90},
193     {0, 1, 2, 3, 4, 5, 6, 8, 90},
194     {0, 1, 2, 3, 4, 5, 6, 8, 90},
195     {0, 1, 2, 3, 4, 5, 6, 8, 90},
196     {0, 1, 2, 3, 4, 5, 6, 8, 90},
197     {0, 1, 2, 3, 4, 5, 6, 8, 90},
198     {0, 1, 2, 3, 4, 5, 6, 8, 90},
199     {0, 1, 2, 3, 4, 5, 6, 8, 90},
200     {0, 1, 2, 3, 4, 5, 6, 8, 90},
201     {0, 1, 2, 3, 4, 5, 6, 8, 90},
202     {0, 1, 2, 3, 4, 5, 6, 8, 90},
203     {0, 1, 2, 3, 4, 5, 6, 8, 90},
204     {0, 1, 2, 3, 4, 5, 6, 8, 90},
205     {0, 1, 2, 3, 4, 5, 6, 8, 90},
206     {0, 1, 2, 3, 4, 5, 6, 8, 90},
207     {0, 1, 2, 3, 4, 5, 6, 8, 90},
208     {0, 1, 2, 3, 4, 5, 6, 8, 90},
209     {0, 1, 2, 3, 4, 5, 6, 8, 90},
210     {0, 1, 2, 3, 4, 5, 6, 8, 90},
211     {0, 1, 2, 3, 4, 5, 6, 8, 90},
212     {0, 1, 2, 3, 4, 5, 6, 8, 90},
213     {0, 1, 2, 3, 4, 5, 6, 8, 90},
214     {0, 1, 2, 3, 4, 5, 6, 8, 90},
215     {0, 1, 2, 3, 4, 5, 6, 8, 90},
216     {0, 1, 2, 3, 4, 5, 6, 8, 90},
217     {0, 1, 2, 3, 4, 5, 6, 8, 90},
218     {0, 1, 2, 3, 4, 5, 6, 8, 90},
219     {0, 1, 2, 3, 4, 5, 6, 8, 90},
220     {0, 1, 2, 3, 4, 5, 6, 8, 90},
221     {0, 1, 2, 3, 4, 5, 6, 8, 90},
222     {0, 1, 2, 3, 4, 5, 6, 8, 90},
223     {0, 1, 2, 3, 4, 5, 6, 8, 90},
224     {0, 1, 2, 3, 4, 5, 6, 8, 90},
225     {0, 1, 2, 3, 4, 5, 6, 8, 90},
226     {0, 1, 2, 3, 4, 5, 6, 8, 90},
227     {0, 1, 2, 3, 4, 5, 6, 8, 90},
228     {0, 1, 2, 3, 4, 5, 6, 8, 90},
229     {0, 1, 2, 3, 4, 5, 6, 8, 90}} ;
230 pamelats 1.5
231 pamela 1.1
232    
233     Float_t A0t[48][9] = {
234 mayorov 1.9 {0, 0.966862, 6.90746, 13.0828, 27.5276, 37.8862, 46.0339, 59.9999, 8100},
235     {0, 0.89781, 6.27511, 12.0001, 16.3328, 26.9085, 48.9715, 60.0001, 8100},
236     {0, 1.28799, 5.18918, 14.087, 23.9813, 26.9957, 37.3137, 57.6302, 8100},
237     {0, 1.15409, 5.62046, 12.9582, 29.0246, 36.1749, 34.2915, 62.8713, 8100},
238     {0, 1.15346, 6.52882, 13.8033, 23.4424, 32.5014, 35.5784, 49.9999, 8100},
239     {0, 1.06303, 6.30765, 12.6676, 23.5195, 27.4434, 29.3732, 50.6973, 8100},
240     {0, 1.19687, 6.39298, 14.352, 23.7507, 31.3431, 38.2434, 60, 8100},
241     {0, 1.08344, 5.69174, 13.1589, 29.0491, 33.8223, 34.5832, 42.4801, 8100},
242     {0, 1.27778, 6.04128, 12.1344, 20, 29.5231, 40.6637, 70, 8100},
243     {0, 1.1633, 6.24587, 15.3981, 22.6264, 25.4787, 40.9823, 54.3096, 8100},
244     {0, 1.25099, 5.51503, 13.0747, 25.7338, 28.0607, 29.3234, 43.1166, 8100},
245     {0, 1.14791, 5.28525, 11.3329, 22.0258, 29.1518, 31.5672, 48.5941, 8100},
246     {0, 0.989178, 6.46598, 16.008, 27.7832, 38.1067, 51.0926, 83.9029, 8100},
247     {0, 0.791611, 6.25114, 14.4726, 22.3348, 40.498, 38.8456, 76.8415, 8100},
248     {0, 1.08442, 6.22537, 10.786, 13.7616, 22.0316, 34.2567, 70.0001, 8100},
249     {0, 1.06481, 5.81616, 15.9999, 25.0001, 27.7402, 39.9999, 62.4627, 8100},
250     {0, 1.54106, 7.73501, 14.8365, 33.808, 38.6967, 55.3031, 55.1627, 8100},
251     {0, 0.181194, 8.88375, 19.761, 30.0001, 37.5278, 60.0001, 79.9997, 8100},
252     {0, 1.20333, 6.4235, 14.438, 20.6791, 37.59, 43.0118, 84.5498, 8100},
253     {0, 1.38501, 6.33531, 12.6738, 26.5495, 32.5919, 39.7116, 66.775, 8100},
254     {0, 1.2447, 6.41472, 13.1281, 24.5903, 27.8925, 34.4098, 52.9463, 8100},
255     {0, 1.10032, 6.84365, 14.8743, 29.1848, 36.0101, 42.1412, 79.1916, 8100},
256     {0, 1.37387, 6.1759, 12.3971, 26.6771, 34.5125, 38.8504, 67.9609, 8100},
257     {0, 1.26074, 6.44693, 13.4109, 23.0619, 31.6812, 37.3077, 57.2156, 8100},
258     {0, 1.27824, 6.99981, 15.2662, 31.25, 40.268, 40.9496, 83.4595, 8100},
259     {0, 1.27135, 6.1494, 14.6932, 25.7259, 35.6644, 43.8106, 65.4656, 8100},
260     {0, 1.40868, 6.80116, 14.308, 22.7333, 28.8201, 43.6075, 75.1262, 8100},
261     {0, 2.17689, 7.12873, 14.4537, 26.6741, 33.406, 40.8852, 59.659, 8100},
262     {0, 1.8449, 11.9433, 21.2362, 34.4344, 43.4968, 54.9996, 60, 8100},
263     {0, 1.71308, 7.86445, 15.1826, 20.2075, 22.4894, 30, 40, 8100},
264     {0, 2.47299, 6.72486, 15.6655, 25.0002, 29.7029, 31.7548, 45, 8100},
265     {0, 1.73646, 7.28222, 14.6779, 20.0001, 23.1851, 24.6151, 34.9945, 8100},
266     {0, 2.10843, 8.61062, 17.3962, 28.7763, 39.014, 52.9373, 80.1161, 8100},
267     {0, 2.12514, 9.41508, 19.6945, 38.8657, 49.4172, 70.8189, 117.259, 8100},
268     {0, 1.96994, 8.71348, 16.2668, 20.6351, 22.7219, 30.0001, 50, 8100},
269     {0, 1.97711, 9.8935, 20.0511, 28.0006, 34.1434, 45.5466, 49.9974, 8100},
270     {0, 3.02174, 11.9467, 22.1838, 44.8834, 67.8526, 87.5638, 99.9968, 8100},
271     {0, 3.23019, 12.396, 21.1859, 43.4576, 69.1176, 102.143, 129.986, 8100},
272     {0, 3.05255, 11.4421, 22.1753, 39.4975, 57.5947, 75.0661, 109.538, 8100},
273     {0, 3.03561, 11.281, 21.7485, 35.0295, 55.2597, 77.795, 138.547, 8100},
274     {0, 2.74373, 10.8424, 22.9863, 46.0158, 63.3989, 85.9676, 100.002, 8100},
275     {0, 2.91456, 10.4374, 18.7076, 37.4149, 44.8928, 53.9337, 69.9997, 8100},
276     {0, 3.35025, 7.22152, 27.5385, 38.8628, 57.2992, 83.4745, 139.076, 8100},
277     {0, 3.29637, 11.1582, 23.0533, 46.9451, 65.503, 94.1756, 135.554, 8100},
278     {0, 3.17507, 12.3589, 22.0947, 47.3915, 78.6842, 117.078, 121.698, 8100},
279     {0, 3.27437, 12.2762, 22.9416, 48.1462, 72.4744, 117.944, 129.998, 8100},
280     {0, 3.3915, 11.4755, 24.4284, 42.7813, 65.1621, 93.6156, 147.765, 8100},
281     {0, 3.11795, 10.5757, 22.8067, 41.8451, 68.3004, 91.8733, 145.854, 8100} } ;
282 pamelats 1.2
283 pamela 1.1
284     Float_t A1t[48][9] = {
285 mayorov 1.9 {0, -0.445487, -6.83011, -7.76746, -26.8019, -33.6372, -33.4238, -34.3206, 0},
286     {0, -0.154046, -5.11675, -6.68917, -1.29614, -7.64427, -42.6283, -37.5536, 0},
287     {0, -0.926441, -2.41216, -10.4314, -18.6624, -2.56534, -5.91767, -4.52255, 0},
288     {0, -0.669591, -3.17426, -8.41107, -30.2702, -28.1341, -0.952674, -28.7299, 0},
289     {0, -0.650638, -5.55242, -9.21873, -16.4049, -19.1945, -9.79077, -25.7112, 0},
290     {0, -0.357887, -5.01401, -6.99931, -16.2411, -5.48061, 7.12013, -7.63631, 0},
291     {0, -0.638868, -5.04599, -9.72543, -15.2232, -6.64514, 2.25032, 9.31463, 0},
292     {0, -0.357529, -3.33754, -8.25226, -29.5745, -20.183, 1.57311, 29.3872, 0},
293     {0, -0.812946, -4.17262, -5.66565, -4, -4.22773, -0.362511, -15.5266, 0},
294     {0, -0.348653, -4.64069, -14.5046, -9.84901, -0.193718, -12.1145, 16.7739, 0},
295     {0, -0.861006, -3.09587, -8.27656, -22.4036, -8.06958, 8.55529, 16.6237, 0},
296     {0, -0.622119, -2.31927, -3.8959, -14.6788, -11.5365, 4.07618, 13.565, 0},
297     {0, -0.5254, -5.57273, -15.4304, -24.9533, -23.3748, -30.7083, -60.3975, 0},
298     {0, 0.0969597, -4.99926, -12.3993, -14.8107, -37.9522, -10.6047, -50.5152, 0},
299     {0, -0.933961, -5.87726, -3.98088, 2.03266, 1.00194, -13.1254, -37.0729, 0},
300     {0, -0.455788, -5.27479, -18.0196, -27.5684, -14.3756, -30.1785, -37.5799, 0},
301     {0, -1.54773, -9.60851, -13.3097, -42.6674, -40.9163, -58.1322, -19.1456, 0},
302     {0, 4.8413, -11.2091, -20.5107, -26.3785, -10.1217, -32.6092, -38.9083, 0},
303     {0, -0.732962, -5.46743, -11.9727, -11.1357, -31.2803, -22.1011, -75.8073, 0},
304     {0, -1.23536, -5.59948, -9.07015, -28.2917, -22.0218, -18.8519, -34.4378, 0},
305     {0, -0.826823, -5.20145, -8.3843, -19.0111, -7.15699, -3.34332, -9.75121, 0},
306     {0, -0.577046, -6.28584, -11.4426, -28.0901, -21.3916, -12.5135, -61.76, 0},
307     {0, -0.956059, -5.00839, -7.22107, -25.7981, -25.7054, -15.0595, -40.2528, 0},
308     {0, -0.810131, -5.26933, -8.78012, -15.6279, -16.893, -9.72584, -17.8252, 0},
309     {0, -0.860119, -6.88744, -13.564, -35.2424, -35.6772, -14.8418, -77.2316, 0},
310     {0, -0.918947, -4.55685, -11.788, -23.1715, -26.2671, -25.1524, -32.8089, 0},
311     {0, -1.01825, -6.16033, -12.1071, -16.7393, -12.9732, -30.675, -67.521, 0},
312     {0, -2.63702, -7.23262, -12.3963, -29.1537, -26.1829, -24.3426, -35.0455, 0},
313     {0, -2.38232, -17.8376, -18.8801, -24.8636, -24.6509, -36.4698, -8.39844, 0},
314     {0, -1.96152, -8.79052, -11.6813, -4.72686, 4.81693, -4.2978, -8.39844, 0},
315     {0, -4.62994, -2.94981, -13.2937, -16.7482, -6.56193, 6.03485, -0.743217, 0},
316     {0, -2.06572, -7.28882, -11.7746, -5.47966, 0.813888, 10.4071, 20.0873, 0},
317     {0, -2.98167, -10.7673, -18.7865, -29.1646, -34.3681, -46.7229, -64.2386, 0},
318     {0, -3.09488, -12.6801, -23.2807, -50.5952, -50.3281, -77.6809, -127.885, 0},
319     {0, -2.6353, -11.327, -15.1071, -8.63713, -2.76153, -10.9598, -8.39844, 0},
320     {0, -2.69369, -14.0086, -23.0438, -20.243, -14.7684, -26.9053, 17.557, 0},
321     {0, -5.05491, -18.6246, -29.6528, -66.0253, -96.0606, -112.211, -87.435, 0},
322     {0, -5.6635, -19.449, -24.0238, -54.6138, -87.6223, -130.704, -149.534, 0},
323     {0, -5.14866, -17.6404, -30.0265, -53.7582, -74.4213, -88.8939, -107.031, 0},
324     {0, -5.1263, -17.4454, -28.9617, -43.0586, -71.6189, -103.028, -188.977, 0},
325     {0, -4.33081, -16.4979, -32.5261, -73.0454, -91.2755, -118.952, -83.7061, 0},
326     {0, -4.92134, -15.2835, -21.598, -48.8622, -43.3094, -40.5892, -69.4005, 0},
327     {0, -5.92968, -6.72971, -43.7034, -51.7821, -74.8294, -114.17, -209.667, 0},
328     {0, -5.65963, -17.484, -33.7998, -73.0621, -95.5599, -138.248, -182.989, 0},
329     {0, -5.45507, -20.3714, -29.0252, -69.4724, -120.52, -180.644, -117.081, 0},
330     {0, -5.67273, -20.3007, -32.4896, -74.9897, -109.782, -190.237, -146.269, 0},
331     {0, -6.15455, -18.331, -37.7733, -65.3947, -101.823, -146.711, -221.847, 0},
332     {0, -5.2493, -16.0076, -33.4883, -62.4233, -106.247, -139.708, -214.149, 0}};
333 pamelats 1.2
334 pamela 1.1
335     Float_t A2t[48][9] = {
336 mayorov 1.9 {0, 0.603703, 3.86157, 3.70388, 16.0228, 22.6954, 26.319, 44.3508, 0},
337     {0, 0.312779, 2.71821, 3.73851, 1.04468, 6.95408, 32.127, 46.5395, 0},
338     {0, 0.743361, 1.07616, 5.29201, 11.4779, 2.26256, 8.01082, 19.1997, 0},
339     {0, 0.534443, 1.40779, 4.55333, 17.9865, 18.9162, 5.49797, 36.8004, 0},
340     {0, 0.626433, 2.91524, 4.57075, 9.93735, 13.6735, 12.7599, 43.2477, 0},
341     {0, 0.403304, 2.5958, 3.37659, 9.36547, 4.78695, 3, 25.6807, 0},
342     {0, 0.554686, 2.54239, 4.54521, 8.81473, 3.42239, 1.55152, 10.102, 0},
343     {0, 0.40188, 1.53765, 4.26228, 17.2971, 13.2302, 3.44777, 1.44658, 0},
344     {0, 0.686001, 2.0432, 2.49348, 0, 3, 1.5756, 25.2157, 0},
345     {0, 0.123351, 2.27207, 8.01038, 3, 3, 12.2309, 3, 0},
346     {0, 0.73465, 1.47978, 4.24085, 13.1021, 6.44605, 0.681327, 8.34446, 0},
347     {0, 0.578203, 0.912111, 1.41144, 8.98856, 8.75212, 3, 7.95492, 0},
348     {0, 0.654411, 2.97054, 8.56266, 14.2585, 13.2056, 22.2557, 56.2898, 0},
349     {0, 0.194551, 2.5935, 6.94048, 9.31167, 24.9638, 11.8554, 46.4502, 0},
350     {0, 0.927312, 3.54272, 2, 0.557114, 3, 17.0684, 35.3889, 0},
351     {0, 0.528366, 3.31646, 10.7953, 18.5896, 11.9005, 27.3322, 43.338, 0},
352     {0, 0.912506, 5.8462, 7.66762, 25.6121, 29.5684, 42.9147, 38.2599, 0},
353     {0, -7.12979, 6.21087, 11.6741, 17.4818, 6.79753, 26.0391, 58.7369, 0},
354     {0, 0.665521, 2.95822, 6.47192, 7.05822, 20.8593, 18.9282, 65.3209, 0},
355     {0, 1.01894, 3.18477, 5.19886, 18.0916, 15.3677, 17.1022, 37.5697, 0},
356     {0, 0.721677, 2.71689, 4.22996, 11.1311, 6.35347, 8.49712, 27.3577, 0},
357     {0, 0.603829, 3.38297, 5.7368, 16.4073, 14.4175, 13.3666, 61.5047, 0},
358     {0, 0.707386, 2.73555, 3.78417, 15.7034, 17.5119, 14.2389, 42.0363, 0},
359     {0, 0.607098, 2.73084, 4.67754, 9.60779, 12.6869, 12.1505, 31.9974, 0},
360     {0, 0.661681, 3.79845, 7.40469, 21.1087, 23.2647, 14.5452, 68.5165, 0},
361     {0, 0.759887, 2.30697, 6.18542, 14.5154, 18.0736, 21.6141, 40.9744, 0},
362     {0, 0.3993, 3.20066, 6.95586, 10.3351, 10.6496, 25.789, 62.6339, 0},
363     {0, 1.11922, 4.03052, 7.15435, 19.0396, 19.5893, 21.629, 44.3572, 0},
364     {0, 1.67562, 9.80356, 7.57421, 11.7968, 17.3663, 33.0567, 28.6826, 0},
365     {0, 1.40668, 4.83038, 5.51678, 1.37774, 0.515603, 13.2881, 28.6826, 0},
366     {0, 3.26101, 0.0412805, 6.93063, 8.88441, 4.63011, 3, 25.3611, 0},
367     {0, 1.4764, 3.91391, 6.07754, 1.73516, 3, 3, 0, 0},
368     {0, 1.99777, 6.09319, 10.6805, 17.6838, 23.1259, 33.9526, 56.8642, 0},
369     {0, 2.09954, 7.17996, 13.001, 29.8411, 30.6333, 51.8831, 95.4856, 0},
370     {0, 1.80733, 6.5434, 7.91278, 5.34262, 8.17397, 18.3942, 28.6826, 0},
371     {0, 1.85376, 8.04532, 12.3798, 10.2491, 11.3718, 26.4686, 0, 0},
372     {0, 3.17369, 10.6479, 17.0112, 38.8841, 56.9463, 67.0329, 68.4495, 0},
373     {0, 3.57082, 11.0378, 12.2117, 29.7697, 49.3163, 74.7644, 111.901, 0},
374     {0, 3.23427, 10.1924, 17.1503, 31.2101, 44.171, 53.5184, 70.3691, 0},
375     {0, 3.23098, 10.1544, 16.4254, 24.8279, 43.4414, 64.6698, 122.023, 0},
376     {0, 2.73301, 9.65117, 18.883, 44.9873, 56.0859, 74.1037, 59.0439, 0},
377     {0, 3.13644, 8.83143, 12.0223, 28.0669, 24.5783, 24.7598, 68.4073, 0},
378     {0, 3.73914, 3.39684, 25.5464, 30.2677, 45.1122, 71.13, 143.934, 0},
379     {0, 3.47069, 10.3132, 20.0929, 43.0092, 57.7104, 85.0343, 123.773, 0},
380     {0, 3.45366, 12.0263, 15.9729, 39.5061, 71.0447, 107.589, 81.6047, 0},
381     {0, 3.54807, 12.0303, 19.0313, 44.4776, 66.7032, 116.232, 101.634, 0},
382     {0, 3.93093, 10.8482, 22.6813, 39.5255, 64.357, 93.1016, 147.004, 0},
383     {0, 3.30655, 9.37748, 20.0108, 37.5016, 65.6635, 88.695, 142.669, 0}};
384    
385     // S115B failure: 1158700000 // 2006-09-19 21:06:40 UTC
386 pamelats 1.2
387 mayorov 1.9 if (time > 1158700000.) { // if time > 2006-09-19 use special constants for PMT S115B
388     Float_t A0tx1[9] = {0, 1.1633, 6.24587, 9.51267, 15.1138, 14.404, 15.5928, 20.3819, 8100};
389     Float_t A1tx1[9] = {0, -0.348653, -4.64069, -3.15991, -2.33796, 6.02431, 14.7019, 26.2542, 0};
390     Float_t A2tx1[9] = {0, 0.123351, 2.27207, 3.22407, 3, 3, 0.0440895, 0.542518, 0};
391 pamela 1.1
392 mayorov 1.9 for ( Int_t jj=0; jj<9; jj++ ){
393     A0t[9][jj] = A0tx1[jj] ;
394     A1t[9][jj] = A1tx1[jj] ;
395     A2t[9][jj] = A2tx1[jj] ;
396     }
397     } // if time...
398    
399     // 1167605999 31 dec 2006 S11A has problems with the dEdx
400 pamela 1.1
401 mayorov 1.9 if (time > 1167605999 ) {
402     Float_t A0tx2[9] = {0, 1.27778, 6.04128, 18.2621, 29.9833, 40, 48.6853, 70, 8100};
403     Float_t A1tx2[9] = {0, -0.812946, -4.17262, -15.0648, -23.4309, -17.3787, -6.03927, 7.16296, 0};
404     Float_t A2tx2[9] = {0, 0.686001, 2.0432, 7.23452, 13.607, 10.2901, 5.99052, 15.045, 0};
405 pamela 1.1 for ( Int_t jj=0; jj<9; jj++ ){
406 mayorov 1.9 A0t[8][jj] = A0tx2[jj] ;
407     A1t[8][jj] = A1tx2[jj] ;
408     A2t[8][jj] = A2tx2[jj] ;
409 pamela 1.1 }
410     } // if time...
411    
412 mayorov 1.9
413 pamela 1.1 //============================================================================
414    
415     // 2nd-order correction
416 pamelats 1.5 Float_t corr_a[6][4] = {
417     {0.977261, 0.353729, -0.83314, 0.452883},
418     {1.27649, 3.53459, -5.41948, 2.67854},
419     {2.21926, 4.32797, -7.24001, 3.77247},
420     {2.4202, 7.99552,-12.4371, 6.08982},
421     {2.04984, 13.3375, -19.178, 8.86101},
422     {2.63322, 14.8072, -20.911,9.57905} };
423 pamela 1.1
424     //---------------------------------------------------------------------
425    
426     Float_t xv[6],yv[6];
427     Int_t iz;
428     Float_t x1[9],y1[9];
429     Int_t n1 = 9;
430 pamelats 1.2
431     Float_t Layercharge[6] = {1005., 1005., 1005., 1005., 1005., 1005. };
432 pamela 1.1
433     Int_t Layerinfo[6] = {0, 0, 0, 0, 0, 0 };
434    
435 mocchiut 1.8 //Float_t adc[48],adc_c[48],PMTcharge_arr[48];
436     Float_t adc[48],PMTcharge_arr[48];
437 pamelats 1.2
438 pamela 1.1 //------------------------------------------------------------------
439    
440 mayorov 1.9 //PamTrack *track = L2->GetTrack(0);
441     PamTrack *track = L2->GetTrack(0,trkAlg);
442 pamela 1.1 Float_t beta_mean = fabs(track->GetToFTrack()->beta[12]);
443 pamelats 1.2
444     // New!! If "beta_in" != 100. then overwrite beta_mean with beta_in
445     if (beta_in != 100.) beta_mean=beta_in;
446    
447 mocchiut 1.7 //Float_t def = track->GetTrkTrack()->al[4];
448     //Float_t rig = 1./def;
449 pamela 1.1
450     Int_t ncount=0;
451     Float_t charge_chi=1000.;
452    
453 mayorov 1.9 //----------------------------------------------------------------
454    
455     for (Int_t jj=0; jj<6; jj++){
456     xv[jj]=track->GetToFTrack()->xtr_tof[jj];
457     yv[jj]=track->GetToFTrack()->ytr_tof[jj];
458     }
459    
460     //----------------------------------------------------------------
461    
462     Float_t theta,dx,dy,dr;
463    
464     theta=0.;
465     dx=0.;
466     dy=0.;
467     dr=0.;
468    
469     if ((xv[0])<100.) {
470     dx = (xv[0])-(xv[5]);
471     dy = (yv[0])-(yv[5]);
472     dr = sqrt(dx*dx+dy*dy);
473     theta = atan(dr/77.5);
474     }
475    
476    
477     // ratio helium to proton ca. 4
478     Float_t hepratio = 4.;
479    
480 pamela 1.1 //-------------------------------------------------------------
481     //------------------ ToF Charge ------------------------------
482     //-------------------------------------------------------------
483    
484     // fill adc and tdc
485    
486     Int_t ich,jj,kk;
487    
488     for (ich=0; ich<48; ich++) adc[ich] = 4095.;
489 mocchiut 1.8 // for (ich=0; ich<48; ich++) adc_c[ich] = 1000.;
490 pamela 1.1 for (ich=0; ich<48; ich++) PMTcharge_arr[ich] = 1000.;
491    
492 pamelats 1.2
493    
494     if ((beta_mean < 0.05) || (beta_mean > 2.0)) {
495     for (Int_t jj=0; jj<48;jj++) charge_PMT_trk[jj] = 1001.;
496     for (Int_t jj=0; jj<6;jj++) charge_layer_trk[jj] = 1001.;
497 pamelats 1.6 for (Int_t jj=0; jj<6;jj++) charge_layer_trk_raw[jj] = 1001.;
498 mocchiut 1.7 for (Int_t jj=0; jj<6;jj++) layerinfo_trk[jj] = 1001;
499 pamelats 1.2 charge_trk = 1001.;
500     ncount_trk = 0;
501     }
502    
503    
504     if ((beta_mean > 0.05) && (beta_mean < 2.0)) {
505    
506 pamela 1.1 Float_t betahelp = pow(beta_mean, 1.2);
507    
508     //=======================================================================
509    
510     for (Int_t ipmt=0; ipmt<L2->GetToFLevel2()->npmt() ; ipmt++){
511     ToFPMT *tofpmt = L2->GetToFLevel2()->GetToFPMT(ipmt);
512     Int_t pmt_id = tofpmt->pmt_id;
513     adc[pmt_id] = tofpmt->adc ;
514     }
515    
516     //=======================================================================
517     Float_t yl, yh, ym, m, b, chelp, charge;
518    
519     for (Int_t ipmt=0; ipmt<track->GetToFTrack()->npmtadc; ipmt++){
520     Float_t dEdx = track->GetToFTrack()->dedx[ipmt];
521 mayorov 1.9 Int_t pmtadc = track->GetToFTrack()->pmtadc[ipmt];
522    
523     //---------- S115B failure workaround ---------------------------
524     if ((pmtadc==9) && (time > 1158700000)) {
525     Float_t x = adc[9];
526     Float_t adcr = 28.0407 + 0.628929*x - 5.80901e-05*x*x + 3.14092e-08*x*x*x;
527     adcr = adcr * cos(theta);
528     Float_t xpos=yv[0];
529     Float_t xkorr = 3.91621*exp(-0.0129234*xpos) + 7.23454*exp(0.102039*xpos) ;
530     xkorr=xkorr/hepratio;
531     dEdx = adcr/xkorr;
532     }
533     //------------------------------------------------------------------
534    
535 pamela 1.1 ym = dEdx*betahelp;
536 mocchiut 1.8 // Int_t adcflag = track->GetToFTrack()->adcflag[ipmt];
537 pamela 1.1 L2->GetToFLevel2()->GetPMTIndex(pmtadc,jj,kk);
538 mocchiut 1.8 // if (adcflag==0) adc_c[pmtadc] = dEdx;
539 pamela 1.1
540    
541 mocchiut 1.8 // if (adc[pmtadc] == 4095) adc_c[pmtadc] = 0.;
542 pamelats 1.2 if (adc[pmtadc] == 4095) PMTcharge_arr[pmtadc] = 0.;
543    
544 mocchiut 1.8 // if ((adc[pmtadc]>PMTsat[pmtadc]) && (adc[pmtadc]<4095)) adc_c[pmtadc] = 1000.;
545 pamela 1.1
546     if (adc[pmtadc] < PMTsat[pmtadc]) {
547     //----------------------------------------------------------------------------------------
548 mayorov 1.9 //if ((pmtadc!=1) && (pmtadc!=9) && (pmtadc!=28) && (pmtadc!=29) && (pmtadc!=34)) {
549 pamela 1.1
550     for ( Int_t jj=0; jj<9; jj++ ){
551     x1[jj] = A0t[pmtadc][jj]+A1t[pmtadc][jj]*beta_mean+A2t[pmtadc][jj]*beta_mean*beta_mean;
552     y1[jj] = C0t[pmtadc][jj]*C0t[pmtadc][jj] ;
553     }
554    
555     TGraph *gr2 = new TGraph(n1,x1,y1);
556     TSpline3 *spl2 = new TSpline3("grs",gr2); // use a cubic spline
557     chelp = spl2->Eval(ym);
558 pamelats 1.3 if (chelp<0.) chelp=0.0001; //WM new
559 pamela 1.1 charge = TMath::Sqrt(chelp);
560     gr2->Delete();
561     spl2->Delete();
562     PMTcharge_arr[pmtadc] = charge;
563 mayorov 1.9
564     // } // pmtadc != ...
565 pamelats 1.2
566 pamela 1.1 //----------------------------------------------------------------------------------------
567 mayorov 1.9 /*
568 pamela 1.1 if ((pmtadc==1) || (pmtadc==9) || (pmtadc==28) || (pmtadc==29) || (pmtadc==34)) {
569     for ( Int_t jj=0; jj<8; jj++ ){
570     yl = A0t[pmtadc][jj]+A1t[pmtadc][jj]*beta_mean+A2t[pmtadc][jj]*beta_mean*beta_mean;
571     yh = A0t[pmtadc][jj+1]+A1t[pmtadc][jj+1]*beta_mean+A2t[pmtadc][jj+1]*beta_mean*beta_mean;
572     if ((yl<ym)&&(ym<yh)){
573     m = (C0t[pmtadc][jj+1]*C0t[pmtadc][jj+1] - C0t[pmtadc][jj]*C0t[pmtadc][jj]) / (yh - yl);
574     b = (C0t[pmtadc][jj]*C0t[pmtadc][jj]) - m*yl;
575     chelp = m*ym + b;
576 pamelats 1.3 if (chelp<0.) chelp=0.0001; //WM new
577 pamela 1.1 charge= TMath::Sqrt(chelp);
578     PMTcharge_arr[pmtadc] = charge;
579     }
580     } // jj=0..8
581     } // if pmtadc ==....
582 mayorov 1.9 */
583 pamela 1.1 //----------------------------------------------------------------------------------------
584     } // adc < sat
585 pamelats 1.2
586 pamela 1.1 } // ipmt...
587    
588     //====================================================================
589     //================ Find out the hitted ToF paddles ===============
590     //====================================================================
591    
592     Int_t PaddleIdOfTrack[6];
593    
594     PaddleIdOfTrack[0] = L2->GetToFLevel2()->GetPaddleIdOfTrack(xv[0], yv[0], 0, 0.) ;
595     PaddleIdOfTrack[1] = L2->GetToFLevel2()->GetPaddleIdOfTrack(xv[1], yv[1], 1, 0.) ;
596     PaddleIdOfTrack[2] = L2->GetToFLevel2()->GetPaddleIdOfTrack(xv[2], yv[2], 2, 0.) ;
597     PaddleIdOfTrack[3] = L2->GetToFLevel2()->GetPaddleIdOfTrack(xv[3], yv[3], 3, 0.) ;
598     PaddleIdOfTrack[4] = L2->GetToFLevel2()->GetPaddleIdOfTrack(xv[4], yv[4], 4, 0.) ;
599     PaddleIdOfTrack[5] = L2->GetToFLevel2()->GetPaddleIdOfTrack(xv[5], yv[5], 5, 0.) ;
600    
601     //==============================================================
602    
603    
604     Int_t ihelp_a[6] = {0,16,28,32,36,42};
605    
606     for (Int_t ilay=0; ilay<6; ilay ++) {
607     Int_t jj = PaddleIdOfTrack[ilay] ;
608 pamelats 1.2 //Float_t xhelp = 1000.;
609     Float_t xhelp = 1005.;
610 pamela 1.1
611     if (jj == -1) Layerinfo[ilay] = -1;
612    
613     if (jj != -1) {
614     Int_t ih = ihelp_a[ilay] + 2*jj;
615 pamelats 1.3
616     // New WM
617     Int_t igood1=0;
618     Int_t igood2=0;
619     if ((PMTcharge_arr[ih] < 1000.) && (PMTcharge_arr[ih] > 0.)) igood1=1;
620     if ((PMTcharge_arr[ih+1] < 1000.) && (PMTcharge_arr[ih+1] > 0.)) igood2=1;
621    
622     if ((PMTcharge_arr[ih]==0.) && (PMTcharge_arr[ih+1]==0.)) xhelp = 0.;
623     if ((igood1==1)&&(igood2==1)) xhelp = 0.5*(PMTcharge_arr[ih]+PMTcharge_arr[ih+1]) ;
624     if ((igood1==1)&&(igood2==0)) xhelp = PMTcharge_arr[ih];
625     if ((igood2==1)&&(igood1==0)) xhelp = PMTcharge_arr[ih+1];
626    
627    
628     /*
629 pamela 1.1 if ((PMTcharge_arr[ih] < 1000.) && (PMTcharge_arr[ih+1] < 1000.)) xhelp = 0.5*(PMTcharge_arr[ih]+PMTcharge_arr[ih+1]) ;
630     if ((PMTcharge_arr[ih] < 1000.) && (PMTcharge_arr[ih+1]==1000.)) xhelp = PMTcharge_arr[ih] ;
631     if ((PMTcharge_arr[ih]==1000.) && (PMTcharge_arr[ih+1] < 1000.)) xhelp = PMTcharge_arr[ih+1] ;
632 pamelats 1.3 */
633 pamela 1.1 if (adc[ih] == 4095) Layerinfo[ilay] = Layerinfo[ilay] + 1;
634     if (adc[ih+1] == 4095) Layerinfo[ilay] = Layerinfo[ilay] + 1;
635     if ((adc[ih] > PMTsat[ih]) && (adc[ih] < 4095)) Layerinfo[ilay] = Layerinfo[ilay] + 10;
636     if ((adc[ih+1] > PMTsat[ih+1]) && (adc[ih+1] < 4095)) Layerinfo[ilay] = Layerinfo[ilay] + 10;
637     }
638     Layercharge[ilay] = xhelp;
639     } // ilay ...
640    
641    
642    
643     //==========================================================================
644 pamelats 1.6 //============= Layercharge without 2nd-order correction =================
645     //==========================================================================
646    
647     for (Int_t jj=0; jj<6;jj++) charge_layer_trk_raw[jj] = Layercharge[jj];
648    
649     //==========================================================================
650 pamela 1.1 //========================= 2nd-order correction =======================
651     //==========================================================================
652    
653     Float_t xb = beta_mean;
654    
655     for (Int_t ii=0; ii<6; ii++) {
656     Int_t ic = 0;
657     Float_t corr[4] = {1., 0., 0., 0.};
658     for (Int_t iii=1; iii<9; iii++) if (fabs(Layercharge[ii] - iii)<0.50) ic = iii;
659     if ((ic>0)&&(ic<=5)) for (Int_t iii=0; iii<4; iii++) corr[iii] = corr_a[ic-1][iii];
660     if (ic >5) for (Int_t iii=0; iii<4; iii++) corr[iii] = corr_a[5][iii];
661    
662     Float_t c_corr = corr[0]+corr[1]*xb+corr[2]*xb*xb+corr[3]*xb*xb*xb;
663    
664     if ((ic>0)&&(ic<=5)) c_corr = c_corr/(1.*ic) ;
665     if (ic>5) c_corr = c_corr/6. ;
666    
667 pamelats 1.6 //cout<<"beta "<<xb<<" layer "<<ii<<" ic "<<ic<<" => "<<c_corr<<endl;
668     //cout<<xb<<" "<<ic<<" "<<c_corr<<endl;
669    
670 pamela 1.1 Layercharge[ii] = Layercharge[ii]/c_corr;
671    
672     }
673    
674     //==========================================================================
675     //==========================================================================
676    
677 pamelats 1.2
678 pamela 1.1 Int_t icount=0;
679     Float_t charge_mean = 0.;
680     for (Int_t ii=0; ii<6; ii++) {
681     if (Layercharge[ii] < 1000) charge_mean = charge_mean + Layercharge[ii] ;
682     if (Layercharge[ii] < 1000) icount++;
683     }
684     if (icount>0) charge_mean = charge_mean/(1.*icount) ;
685    
686     if (icount>0) {
687    
688     //for (Int_t ii=0; ii<6; ii++) cout<<Layercharge[ii]<<" ";
689     //cout<<endl;
690    
691    
692     vector<float> charge_v;
693     Float_t charge_median = 0.;
694    
695     //////// get the median charge ////////////
696     for(Int_t ii=0;ii<6;ii++) {
697     if (Layercharge[ii] < 1000) charge_v.push_back(Layercharge[ii]);
698     }
699    
700     std::sort(charge_v.begin(),charge_v.end());
701     charge_median = charge_v[(int)(charge_v.size()/2+charge_v.size()%2)-1];
702    
703     //cout<<charge_mean<<" "<<charge_median<<endl;
704    
705     charge_mean = charge_median;
706    
707     } // icount>0
708    
709    
710     //--- Calculate charge for the second time, use residuals of the single
711     //--- measurements to get a chi2 value
712    
713     Float_t w_i_arr[8] = {0.1, 0.15, 0.2, 0.25, 0.30, 0.35, 0.45, 0.50};
714    
715     icount=0;
716     Float_t sw=0.;
717     Float_t sxw=0.;
718     Float_t w_i = 1./0.5;
719     Float_t resmax= 3.0;
720    
721     iz=1;
722     if ((0.0<charge_mean) & (charge_mean<1.5)) iz=1;
723     if ((1.5<charge_mean) & (charge_mean<2.5)) iz=2;
724     if ((2.5<charge_mean) & (charge_mean<3.5)) iz=3;
725     if ((3.5<charge_mean) & (charge_mean<4.5)) iz=4;
726     if ((4.5<charge_mean) & (charge_mean<5.5)) iz=5;
727     if ((5.5<charge_mean) & (charge_mean<6.5)) iz=6;
728     if ((6.5<charge_mean) & (charge_mean<7.5)) iz=7;
729     if ((7.5<charge_mean) & (charge_mean<90.)) iz=8;
730    
731     w_i = 1./w_i_arr[iz-1];
732    
733     for (Int_t jj=0; jj<6;jj++){
734     if (Layercharge[jj] < 1000) {
735     Float_t res = charge_mean - Layercharge[jj] ;
736     if (fabs(res*w_i)<resmax) {
737     icount= icount+1;
738     sxw=sxw + Layercharge[jj]*w_i*w_i ;
739     sw =sw + w_i*w_i ;
740     }
741     }
742     }
743    
744    
745     ncount = icount;
746     if (icount>0) charge_chi=sxw/sw;
747    
748     // cout<<" => "<<icount<<" "<<charge_chi<<endl;
749    
750     //=============================================================
751 pamelats 1.2 // changed 30-01-2009 WM
752 pamela 1.1
753 pamelats 1.2 for (Int_t jj=0; jj<48;jj++) charge_PMT_trk[jj] = PMTcharge_arr[jj];
754 pamela 1.1 for (Int_t jj=0; jj<6;jj++) charge_layer_trk[jj] = Layercharge[jj];
755     for (Int_t jj=0; jj<6;jj++) layerinfo_trk[jj] = Layerinfo[jj];
756     charge_trk = charge_chi;
757     ncount_trk = ncount;
758    
759 pamelats 1.2 } // 0.05 < beta < 2.0
760    
761 pamela 1.1 } // if ntrk == 1
762    
763     //================================================================
764     //============== Siegen version 1 =============
765     //============== standalone dEdx and beta =============
766     //================================================================
767    
768     ToFTrkVar *track = L2->GetToFStoredTrack(-1);
769     // if(!track)return;
770     if(track) {
771    
772 pamelats 1.2 /*
773 pamela 1.1 Float_t PMTsat[48] = {
774     3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37, 3130.05, 3087.07, 3112.22,
775     3102.92, 3080.58, 3092.55, 3087.94, 3125.03, 3094.09, 3143.16,
776     3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53, 3097.11, 3133.53, 3114.73, 3113.01, 3091.19,
777     3097.99, 3033.84, 3134.98, 3081.37, 3111.04, 3066.77, 3108.17,
778     3133, 3111.06, 3052.52, 3140.66, 3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11
779     };
780 pamelats 1.2 */
781    
782     // new values from Napoli dec 2008
783     Float_t PMTsat[48] = {
784     3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
785     3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
786     3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
787     3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
788     3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
789     3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
790    
791     for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
792    
793 mayorov 1.9 // calibration file "charge_fits_10th_std.dat"
794 pamela 1.1
795     Float_t C0t[48][9] = {
796 mayorov 1.9 {0, 1, 2, 3, 4, 5, 6, 8, 90},
797     {0, 1, 2, 3, 4, 5, 6, 8, 90},
798     {0, 1, 2, 3, 4, 5, 6, 8, 90},
799     {0, 1, 2, 3, 4, 5, 6, 8, 90},
800     {0, 1, 2, 3, 4, 5, 6, 8, 90},
801     {0, 1, 2, 3, 4, 5, 6, 8, 90},
802     {0, 1, 2, 3, 4, 5, 6, 8, 90},
803     {0, 1, 2, 3, 4, 5, 6, 8, 90},
804     {0, 1, 2, 3, 4, 5, 6, 8, 90},
805     {0, 1, 2, 3, 4, 5, 6, 8, 90},
806     {0, 1, 2, 3, 4, 5, 6, 8, 90},
807     {0, 1, 2, 3, 4, 5, 6, 8, 90},
808     {0, 1, 2, 3, 4, 5, 6, 8, 90},
809     {0, 1, 2, 3, 4, 5, 6, 8, 90},
810     {0, 1, 2, 3, 4, 5, 6, 8, 90},
811     {0, 1, 2, 3, 4, 5, 6, 8, 90},
812     {0, 1, 2, 3, 4, 5, 6, 8, 90},
813     {0, 1, 2, 3, 4, 5, 6, 8, 90},
814     {0, 1, 2, 3, 4, 5, 6, 8, 90},
815     {0, 1, 2, 3, 4, 5, 6, 8, 90},
816     {0, 1, 2, 3, 4, 5, 6, 8, 90},
817     {0, 1, 2, 3, 4, 5, 6, 8, 90},
818     {0, 1, 2, 3, 4, 5, 6, 8, 90},
819     {0, 1, 2, 3, 4, 5, 6, 8, 90},
820     {0, 1, 2, 3, 4, 5, 6, 8, 90},
821     {0, 1, 2, 3, 4, 5, 6, 8, 90},
822     {0, 1, 2, 3, 4, 5, 6, 8, 90},
823     {0, 1, 2, 3, 4, 5, 6, 8, 90},
824     {0, 1, 2, 3, 4, 5, 6, 8, 90},
825     {0, 1, 2, 3, 4, 5, 6, 8, 90},
826     {0, 1, 2, 3, 4, 5, 6, 8, 90},
827     {0, 1, 2, 3, 4, 5, 6, 8, 90},
828     {0, 1, 2, 3, 4, 5, 6, 8, 90},
829     {0, 1, 2, 3, 4, 5, 6, 8, 90},
830     {0, 1, 2, 3, 4, 5, 6, 8, 90},
831     {0, 1, 2, 3, 4, 5, 6, 8, 90},
832     {0, 1, 2, 3, 4, 5, 6, 8, 90},
833     {0, 1, 2, 3, 4, 5, 6, 8, 90},
834     {0, 1, 2, 3, 4, 5, 6, 8, 90},
835     {0, 1, 2, 3, 4, 5, 6, 8, 90},
836     {0, 1, 2, 3, 4, 5, 6, 8, 90},
837     {0, 1, 2, 3, 4, 5, 6, 8, 90},
838     {0, 1, 2, 3, 4, 5, 6, 8, 90},
839     {0, 1, 2, 3, 4, 5, 6, 8, 90},
840     {0, 1, 2, 3, 4, 5, 6, 8, 90},
841     {0, 1, 2, 3, 4, 5, 6, 8, 90},
842     {0, 1, 2, 3, 4, 5, 6, 8, 90},
843     {0, 1, 2, 3, 4, 5, 6, 8, 90}} ;
844 pamela 1.1
845 pamelats 1.5 Float_t A0t[48][9] = {
846 mayorov 1.9 {0, 0.626244, 5.57075, 13.0829, 27.5278, 37.886, 46.0338, 59.9999, 8100},
847     {0, 0.669967, 6.13887, 12.0001, 16.3328, 26.9085, 48.9715, 60.0001, 8100},
848     {0, 1.07525, 4.95494, 14.0867, 23.9813, 26.9957, 37.3137, 57.6302, 8100},
849     {0, 0.991496, 6.14099, 12.9582, 29.0247, 36.1749, 34.2915, 62.8713, 8100},
850     {0, 0.894996, 5.84777, 13.8033, 23.4423, 32.5014, 35.5784, 49.9998, 8100},
851     {0, 1.1336, 5.59475, 12.6677, 23.5195, 27.4434, 29.3735, 50.6974, 8100},
852     {0, 0.691118, 5.26701, 14.351, 23.7506, 31.3431, 38.2434, 60.0001, 8100},
853     {0, 1.02012, 6.17243, 13.1588, 29.049, 33.8223, 34.5832, 42.4809, 8100},
854     {0, 0.0309897, 7.24482, 16.2425, 35.4099, 44.1408, 55.1932, 70, 8100},
855     {0, 0.65965, -0.44638, 9.51268, 15.1138, 14.4038, 15.5924, 20.3806, 8100},
856     {0, 0.681447, 4.88613, 13.0747, 25.7335, 28.0607, 29.3234, 43.1167, 8100},
857     {0, 1.21702, 6.06734, 11.333, 22.0258, 29.1518, 31.5672, 48.5941, 8100},
858     {0, 0.492463, 6.1436, 16.0077, 27.7831, 38.1067, 51.0924, 83.9029, 8100},
859     {0, 0.83562, 5.31218, 14.4727, 22.3348, 40.4978, 38.8456, 76.8416, 8100},
860     {0, 0.174564, 3.49201, 10.7861, 13.7616, 22.0316, 34.2567, 70.0001, 8100},
861     {0, 1.29945, 3.93137, 15.9999, 24.9999, 27.7403, 39.9996, 62.4627, 8100},
862     {0, 1.33337, 6.4213, 14.8368, 33.8082, 38.6969, 55.3044, 55.1627, 8100},
863     {0, -2.66314, 6.37651, 19.7608, 30.0002, 37.528, 60.0003, 79.9994, 8100},
864     {0, 0.974379, 5.37316, 14.438, 20.6792, 37.5899, 43.0121, 84.549, 8100},
865     {0, 0.980116, 6.6121, 12.6738, 26.5497, 32.5919, 39.7116, 66.775, 8100},
866     {0, 1.26686, 5.57744, 13.1284, 24.5904, 27.8926, 34.4098, 52.9463, 8100},
867     {0, 1.05908, 7.61144, 14.8745, 29.1849, 36.0101, 42.1412, 79.1916, 8100},
868     {0, 1.05984, 6.1965, 12.3971, 26.6773, 34.5123, 38.8503, 67.9607, 8100},
869     {0, 1.07406, 6.15097, 13.4108, 23.062, 31.6812, 37.3077, 57.2156, 8100},
870     {0, 1.27716, 6.50522, 15.266, 31.25, 40.2676, 40.9496, 83.4598, 8100},
871     {0, 1.09161, 6.2145, 14.6937, 25.726, 35.6646, 43.8102, 65.4656, 8100},
872     {0, 1.37356, 7.38264, 14.3081, 22.7334, 28.8201, 43.6075, 75.1262, 8100},
873     {0, 1.94333, 5.62022, 14.4537, 26.6738, 33.4061, 40.8853, 59.6588, 8100},
874     {0, 2.03697, 12.6287, 21.2366, 34.4342, 43.4967, 54.9998, 60, 8100},
875     {0, 1.86647, 7.13185, 15.1822, 20.2075, 22.4894, 30, 40, 8100},
876     {0, 2.18716, 7.9365, 15.6656, 25.0005, 29.7029, 31.755, 45, 8100},
877     {0, 1.79435, 7.24238, 14.6779, 20, 23.1849, 24.6151, 29.9996, 8100},
878     {0, 1.903, 8.60739, 17.3971, 28.7765, 39.0144, 52.9377, 80.1161, 8100},
879     {0, 2.0422, 9.39568, 19.6939, 38.8651, 49.4168, 70.8184, 117.258, 8100},
880     {0, 2.05025, 8.91676, 16.2662, 20.635, 22.7219, 30.0003, 50, 8100},
881     {0, 2.12015, 9.326, 20.0518, 28.0012, 34.1434, 45.5466, 49.9966, 8100},
882     {0, 2.58767, 9.7282, 22.1808, 44.8816, 67.8511, 87.5578, 99.9969, 8100},
883     {0, 3.10718, 11.1535, 21.186, 43.4575, 69.117, 102.142, 129.985, 8100},
884     {0, 3.26593, 12.3316, 22.175, 39.4979, 57.5949, 75.0662, 100, 8100},
885     {0, 2.48401, 7.28773, 19.7467, 30.0293, 45.2555, 60.7865, 100.537, 8100},
886     {0, 2.49424, 7.53288, 11.0001, 14, 18, 22, 30, 8100},
887     {0, 2.79325, 10.4782, 18.7078, 37.416, 44.8931, 53.9337, 69.9999, 8100},
888     {0, 3.34308, 10.753, 27.5373, 38.8625, 57.2984, 83.477, 139.082, 8100},
889     {0, 3.237, 10.5464, 23.0534, 46.944, 60.5023, 70.4994, 80.0005, 8100},
890     {0, 3.357, 10.8631, 22.0952, 47.3909, 78.6842, 117.079, 121.698, 8100},
891     {0, 3.2013, 10.6812, 19.9973, 30, 60.4706, 70.9416, 100.999, 8100},
892     {0, 3.05856, 10.4004, 24.423, 42.78, 65.1617, 93.6214, 147.771, 8100},
893     {0, 3.41072, 11.4925, 22.8054, 41.8445, 68.2985, 91.872, 145.849, 8100}};
894 pamela 1.1
895     Float_t A1t[48][9] = {
896 mayorov 1.9 {0, 0.684247, -4.14554, -11.1094, -24.5129, -38.2756, -41.0959, -19.0501, 0},
897     {0, 0.623673, -4.60109, -4.78271, -0.884499, -3.96897, -46.489, -22.5088, 0},
898     {0, -0.249597, -3.13851, -15.133, -22.6693, -10.2338, -17.5215, -4.78572, 0},
899     {0, 0.0901572, -3.61432, -5.22235, -26.2322, -19.3028, 3.73157, 2.91283, 0},
900     {0, -0.135542, -4.18558, -10.3476, -19.8513, -21.8227, -2.345, -47.9072, 0},
901     {0, -0.528203, -2.78581, -5.76259, -14.4398, -4.65071, 6.9809, 10.9591, 0},
902     {0, 0.738867, -3.05266, -14.0515, -16.8378, -11.685, -2.39992, 9.73815, 0},
903     {0, 0.0240829, -4.06428, -7.4387, -25.1373, -15.4164, 4.23546, 30.1758, 0},
904     {0, 3.76114, -3.88903, -14.2742, -40.7931, -35.2381, -27.9355, 4.64363, 0},
905     {0, 2.53218, 10.3913, -4.60302, -5.07342, -4.32836, 6.74167, 10.6971, 0},
906     {0, 0.734454, -1.34727, -8.2282, -24.7553, -12.4964, -2.70228, 12.3389, 0},
907     {0, -0.607144, -4.88443, -3.87857, -14.385, -14.7764, -0.913896, 9.46744, 0},
908     {0, 1.18779, -4.14515, -13.6006, -23.6426, -21.2445, -30.6746, -14.5969, 0},
909     {0, 0.230348, -3.47996, -13.5497, -13.5157, -42.2043, -18.865, -44.7452, 0},
910     {0, 2.43646, 0.989512, -3.92652, -0.0489174, -5.7052, -13.7881, -34.5402, 0},
911     {0, 0.508931, -1.76998, -20.025, -27.0253, -19.5194, -42.5512, -18.2329, 0},
912     {0, -0.279749, -6.95578, -12.9933, -42.4332, -30.4393, -45.8736, -11.4401, 0},
913     {0, 14.1581, -3.80609, -22.8216, -18.5728, -11.4838, -29.6653, -63.3054, 0},
914     {0, 0.203648, -5.06129, -17.2442, -15.9798, -41.6745, -34.0871, -93.4167, 0},
915     {0, 0.527513, -5.25737, -5.07905, -19.5563, -9.89318, -0.0190118, -12.1354, 0},
916     {0, -0.987681, -4.45351, -10.8727, -22.6132, -11.9238, -8.73394, 0.495203, 0},
917     {0, -0.307322, -7.51125, -9.25771, -22.5488, -18.0782, -8.63964, -35.6685, 0},
918     {0, 0.12121, -5.91873, -8.14844, -26.6183, -27.4172, -17.9023, -45.658, 0},
919     {0, -0.0440127, -4.60804, -8.96586, -14.1608, -16.407, -9.45833, -13.0969, 0},
920     {0, -0.558487, -5.03789, -11.2856, -31.7381, -32.7836, -10.3583, -51.1819, 0},
921     {0, -0.319563, -6.28345, -13.2449, -26.0895, -32.1212, -34.8085, -35.3115, 0},
922     {0, -0.438421, -6.76323, -8.04215, -6.24, -3.51572, -3.26923, -14.7792, 0},
923     {0, -2.29529, -5.92959, -15.9074, -34.9195, -35.4169, -41.1345, -47.2614, 0},
924     {0, -2.8399, -19.7623, -14.4555, -22.8945, -25.4665, -22.8025, -8.39844, 0},
925     {0, -2.3361, -7.44249, -13.7837, -8.14004, -0.0720474, -7.50509, -8.39844, 0},
926     {0, -3.36944, -8.64707, -13.0254, -16.0805, -1.85751, 8.52888, 0.550509, 0},
927     {0, -2.18295, -7.89578, -12.4464, -7.93621, -6.2682, 6.24761, 14.8709, 0},
928     {0, -2.52134, -12.1011, -19.5864, -28.3525, -32.0441, -40.9499, -24.6919, 0},
929     {0, -2.64214, -12.1746, -21.8649, -49.8572, -50.3294, -77.8674, -91.4326, 0},
930     {0, -2.83382, -12.3206, -15.0702, -8.91696, -6.24556, -16.5196, -8.39844, 0},
931     {0, -3.0755, -12.831, -23.0945, -20.8865, -12.8932, -25.4243, 16.5467, 0},
932     {0, -3.89104, -13.1829, -31.3708, -71.7052, -107.284, -129.239, -108.794, 0},
933     {0, -5.37954, -17.0676, -24.4585, -49.6695, -89.3567, -134.941, -113.108, 0},
934     {0, -5.48076, -18.4538, -28.255, -48.7572, -56.4813, -46.2133, -13.7872, 0},
935     {0, -4.056, -9.7058, -32.0134, -48.0418, -82.316, -115.6, -185.798, 0},
936     {0, -3.58506, -8.95175, -7.02082, -3.72388, -8.31816, -3.70441, 8.91556, 0},
937     {0, -4.63926, -15.2966, -20.4456, -49.4273, -33.1319, -30.1151, -94.0042, 0},
938     {0, -5.9137, -16.5116, -42.9632, -48.5685, -70.2161, -104.088, -200.521, 0},
939     {0, -5.74618, -16.3597, -36.3691, -79.8407, -94.9335, -99.0161, -72.8879, 0},
940     {0, -6.07098, -17.0741, -30.4224, -69.8418, -120.675, -166.247, -88.5553, 0},
941     {0, -5.6577, -16.8394, -31.1924, -40.3184, -106.238, -112.924, -117.987, 0},
942     {0, -5.44442, -16.6105, -40.8566, -69.5939, -105.485, -143.841, -192.19, 0},
943     {0, -6.00784, -18.0034, -32.3969, -61.286, -107.103, -136.99, -213.381, 0}};
944 pamelats 1.5
945 pamela 1.1
946     Float_t A2t[48][9] = {
947 mayorov 1.9 {0, -0.256726, 2.27431, 6.43469, 11.8465, 25.5581, 31.0446, 22.2011, 0},
948     {0, -0.27314, 2.41841, 1.96977, 3, 4.1409, 37.5866, 31.8181, 0},
949     {0, 0.210304, 1.9894, 9.90239, 14.4125, 8.40969, 17.111, 11.0446, 0},
950     {0, -0.0897531, 1.31427, 1.38261, 13.8423, 10.7517, 3, 3, 0},
951     {0, 0.254985, 2.18331, 5.68851, 13.1542, 15.3206, 2.48479, 70.3325, 0},
952     {0, 0.403054, 1.07449, 2.02539, 7.53642, 3.53899, 3, 3, 0},
953     {0, -0.402018, 1.49429, 8.52411, 9.06339, 6.43531, 2.47331, 3, 0},
954     {0, 0.0163422, 1.90856, 3.94927, 13.6905, 10.1882, 3, 3, 0},
955     {0, -4.41759, 0.455884, 8.23305, 24.3049, 23.7324, 19.687, 9.34883, 0},
956     {0, -1.61978, -5.94435, 5.09418, 3.5784, 6.69858, 0, 3, 0},
957     {0, -0.406232, 0.261862, 3.87028, 14.9026, 9.15009, 8.09389, 3, 0},
958     {0, 0.450961, 2.79588, 1.475, 8.87168, 13.0701, 7.88346, 7.61453, 0},
959     {0, -0.642696, 1.93851, 7.07521, 13.7185, 12.8763, 23.2823, 7.88003, 0},
960     {0, -0.0242187, 1.90127, 7.67745, 6.80574, 27.4311, 16.7277, 32.2091, 0},
961     {0, -1.4328, -0.863971, 2, 4.44504, 10.57, 17.3062, 27.8696, 0},
962     {0, -0.670537, 1.49585, 12.8631, 16.2047, 14.9903, 36.0699, 16.2393, 0},
963     {0, -0.165185, 4.50708, 7.61307, 25.615, 20.0767, 33.8685, 31.1236, 0},
964     {0, -14.3972, -0.395553, 13.3646, 4.57022, 3, 7.13162, 73.4341, 0},
965     {0, -0.12435, 3.28793, 10.8198, 9.77605, 28.3088, 26.0003, 74.0148, 0},
966     {0, -0.249317, 2.71293, 1.75304, 10.5257, 5.86488, 1.62532, 21.8499, 0},
967     {0, 0.783725, 2.69445, 6.4717, 14.0212, 10.3889, 12.3235, 12.6467, 0},
968     {0, 0.251419, 3.89298, 3.7622, 11.1349, 11.8263, 8.91756, 30.8796, 0},
969     {0, -0.0967801, 3.47969, 4.14906, 15.4672, 17.9873, 14.6814, 40.101, 0},
970     {0, -0.0468341, 2.4518, 5.22592, 8.81726, 13.3005, 12.5642, 26.0746, 0},
971     {0, 0.361255, 2.6057, 5.68184, 18.9758, 23.0597, 13.4065, 42.9283, 0},
972     {0, 0.265048, 3.70422, 6.65035, 15.5919, 21.3769, 27.5229, 32.5316, 0},
973     {0, 0.131408, 3.54343, 4.01437, 3, 7.44138, 6.65706, 3, 0},
974     {0, 1.54593, 3.83503, 9.28219, 22.0934, 23.8119, 29.9772, 35.631, 0},
975     {0, 1.7922, 11.1126, 3.13824, 11.1306, 20.0004, 17.3392, 28.6826, 0},
976     {0, 1.47885, 4.12127, 7.4205, 3.88672, 3.32699, 12.5934, 28.6826, 0},
977     {0, 2.19139, 4.68991, 6.91045, 8.68486, 0.558281, 3, 25.2369, 0},
978     {0, 1.38324, 4.40549, 6.29519, 3.73961, 9.92062, 4.2368, 0, 0},
979     {0, 1.74636, 7.38456, 10.9205, 16.2117, 20.5563, 27.464, 10.1068, 0},
980     {0, 1.73446, 6.69344, 11.6119, 29.1162, 29.9171, 49.9535, 44.2648, 0},
981     {0, 1.77345, 7.29971, 7.85848, 5.92193, 11.9535, 23.2607, 28.6826, 0},
982     {0, 1.96343, 7.39403, 12.4053, 10.7737, 9.40302, 25.2622, 0, 0},
983     {0, 2.42414, 7.27305, 18.273, 42.3329, 63.3642, 76.6873, 68.8465, 0},
984     {0, 3.31282, 9.87776, 12.592, 23.6123, 51.5773, 79.4578, 70.7063, 0},
985     {0, 3.29838, 10.279, 15.8924, 26.8172, 26.854, 12.7043, 3, 0},
986     {0, 2.68146, 6.03602, 20.1606, 30.6191, 57.4667, 82.6249, 123.423, 0},
987     {0, 2.2217, 5.29813, 4.33261, 2.07538, 10.7653, 7.464, 0.349452, 0},
988     {0, 2.95636, 8.77044, 10.8631, 27.8588, 12.2192, 14.0908, 110.101, 0},
989     {0, 3.64161, 9.78281, 24.6906, 26.6128, 41.2993, 61.6105, 148.654, 0},
990     {0, 3.63967, 9.64793, 22.2672, 48.2125, 58.7374, 63.0135, 50.1782, 0},
991     {0, 3.82742, 10.2333, 17.375, 39.2687, 70.7411, 92.8927, 53.55, 0},
992     {0, 3.60427, 9.89206, 20.1062, 24.2838, 70.2791, 74.3114, 68.2462, 0},
993     {0, 3.49785, 10.0213, 25.4603, 42.8919, 66.5058, 87.2153, 118.037, 0},
994     {0, 3.7133, 10.5679, 19.2454, 36.5673, 67.1997, 85.7778, 144.19, 0}};
995 pamela 1.1
996     // S115B failure: 1158700000 // 2006-09-19 21:06:40 UTC
997    
998 pamelats 1.2 if (time < 1158700000.) { // first workaround: just use calibration of PMT S115A
999 pamela 1.1 for ( Int_t jj=0; jj<9; jj++ ){
1000     A0t[9][jj] = A0t[8][jj] ;
1001     A1t[9][jj] = A1t[8][jj] ;
1002     A2t[9][jj] = A2t[8][jj] ;
1003     }
1004     } // if time...
1005    
1006    
1007     // 2nd-order correction
1008     Float_t corr_a[6][4] = {
1009 pamelats 1.5 {0.551894 , 2.24353 , -3.35885 , 1.51401} ,
1010     {0.915691 , 4.83967 , -6.85389 , 3.13679} ,
1011     {1.84338 , 5.63517 , -8.41577 , 4.04055} ,
1012     {1.51216 , 11.3233 , -16.2119 , 7.45008} ,
1013     {1.50481 , 15.2538 , -21.2003 , 9.51127} ,
1014     {1.82038 , 17.5336 , -23.5512 , 10.3036} };
1015 pamela 1.1
1016     //---------------------------------------------------------------------
1017    
1018 mocchiut 1.7 //Float_t xv[6],yv[6];
1019 pamela 1.1 Int_t iz;
1020    
1021     Float_t x1[9],y1[9];
1022     Int_t n1 = 9;
1023    
1024 pamelats 1.2 Float_t Layercharge[6] = {1005., 1005., 1005., 1005., 1005., 1005. };
1025    
1026 pamela 1.1 Int_t Layerinfo[6] = {0, 0, 0, 0, 0, 0 };
1027    
1028 mocchiut 1.8 //Float_t adc[48],adc_c[48],PMTcharge_arr[48];
1029     Float_t adc[48],PMTcharge_arr[48];
1030 pamelats 1.2
1031     Float_t beta_mean = fabs(track->beta[12]);
1032 pamela 1.1
1033 pamelats 1.2 // New!! If "beta_in" != 100. then overwrite beta_mean with beta_in
1034     if (beta_in != 100.) beta_mean=beta_in;
1035 pamela 1.1
1036     Int_t ncount=0;
1037     Float_t charge_chi=1000.;
1038    
1039    
1040     //-------------------------------------------------------------
1041    
1042     // fill adc and tdc
1043    
1044     Int_t ich,jj,kk;
1045    
1046     for (ich=0; ich<48; ich++) adc[ich] = 4095.;
1047 mocchiut 1.8 // for (ich=0; ich<48; ich++) adc_c[ich] = 1000.;
1048 pamela 1.1 for (ich=0; ich<48; ich++) PMTcharge_arr[ich] = 1000.;
1049    
1050 pamelats 1.2
1051     if ((beta_mean < 0.05) || (beta_mean > 2.0)) {
1052     for (Int_t jj=0; jj<48;jj++) charge_PMT_std[jj] = 1001.;
1053     for (Int_t jj=0; jj<6;jj++) charge_layer_std[jj] = 1001.;
1054 pamelats 1.6 for (Int_t jj=0; jj<6;jj++) charge_layer_std_raw[jj] = 1001.;
1055 mocchiut 1.7 for (Int_t jj=0; jj<6;jj++) layerinfo_std[jj] = 1001;
1056 pamelats 1.2 charge_std = 1001.;
1057     ncount_std = 0;
1058     }
1059    
1060    
1061     if ((beta_mean > 0.05) && (beta_mean < 2.0)) {
1062    
1063 pamela 1.1 Float_t betahelp = pow(beta_mean, 1.2);
1064    
1065     //=======================================================================
1066    
1067     for (Int_t ipmt=0; ipmt<L2->GetToFLevel2()->npmt() ; ipmt++){
1068     ToFPMT *tofpmt = L2->GetToFLevel2()->GetToFPMT(ipmt);
1069     Int_t pmt_id = tofpmt->pmt_id;
1070     adc[pmt_id] = tofpmt->adc ;
1071     }
1072    
1073     //=======================================================================
1074    
1075     Float_t yl, yh, ym, m, b, chelp, charge;
1076    
1077    
1078     for (Int_t ipmt=0; ipmt<track->npmtadc; ipmt++){
1079     Float_t dEdx = track->dedx[ipmt];
1080     ym = dEdx*betahelp;
1081     Int_t pmtadc = track->pmtadc[ipmt];
1082 mocchiut 1.8 // Int_t adcflag = track->adcflag[ipmt];
1083 pamela 1.1 L2->GetToFLevel2()->GetPMTIndex(pmtadc,jj,kk);
1084 mocchiut 1.8 // if (adcflag==0) adc_c[pmtadc] = dEdx;
1085 pamelats 1.2
1086 mocchiut 1.8 // if (adc[pmtadc] == 4095) adc_c[pmtadc] = 0.;
1087 pamelats 1.2 if (adc[pmtadc] == 4095) PMTcharge_arr[pmtadc] = 0.;
1088    
1089 mocchiut 1.8 // if ((adc[pmtadc]>PMTsat[pmtadc]) && (adc[pmtadc]<4095)) adc_c[pmtadc] = 1000.;
1090 pamela 1.1
1091     if (adc[pmtadc] < PMTsat[pmtadc]) {
1092    
1093 pamelats 1.4 if ((pmtadc!=4) && (pmtadc!=8) && (pmtadc!=28) && (pmtadc!=31) && (pmtadc!=34) && (pmtadc!=39) && (pmtadc!=41) && (pmtadc!=46)) {
1094 pamela 1.1
1095     for ( Int_t jj=0; jj<9; jj++ ){
1096     x1[jj] = A0t[pmtadc][jj]+A1t[pmtadc][jj]*beta_mean+A2t[pmtadc][jj]*beta_mean*beta_mean;
1097     y1[jj] = C0t[pmtadc][jj]*C0t[pmtadc][jj] ;
1098     // cout<<x1[jj]<<" "<<y1[jj]<<" ";
1099     }
1100     // cout<<endl;
1101    
1102    
1103     TGraph *gr2 = new TGraph(n1,x1,y1);
1104     TSpline3 *spl2 = new TSpline3("grs",gr2); // use a cubic spline
1105     chelp = spl2->Eval(ym);
1106 pamelats 1.3 if (chelp<0.) chelp=0.0001; //WM new
1107 pamela 1.1 charge = TMath::Sqrt(chelp);
1108    
1109     gr2->Delete();
1110     spl2->Delete();
1111     PMTcharge_arr[pmtadc] = charge;
1112     } // pmtadc != ...
1113    
1114 pamelats 1.5 if ((pmtadc==4) || (pmtadc==8) || (pmtadc==28) || (pmtadc==31) || (pmtadc==34) || (pmtadc==39) || (pmtadc==41) || (pmtadc==46)) {
1115 pamela 1.1 for ( Int_t jj=0; jj<8; jj++ ){
1116     yl = A0t[pmtadc][jj]+A1t[pmtadc][jj]*beta_mean+A2t[pmtadc][jj]*beta_mean*beta_mean;
1117     yh = A0t[pmtadc][jj+1]+A1t[pmtadc][jj+1]*beta_mean+A2t[pmtadc][jj+1]*beta_mean*beta_mean;
1118     if ((yl<ym)&&(ym<yh)){
1119     m = (C0t[pmtadc][jj+1]*C0t[pmtadc][jj+1] - C0t[pmtadc][jj]*C0t[pmtadc][jj]) / (yh - yl);
1120     b = (C0t[pmtadc][jj]*C0t[pmtadc][jj]) - m*yl;
1121     chelp = m*ym + b;
1122 pamelats 1.3 if (chelp<0.) chelp=0.0001; //WM new
1123 pamela 1.1 charge= TMath::Sqrt(chelp);
1124     PMTcharge_arr[pmtadc] = charge;
1125     }
1126     } // jj=0..8
1127     } // if pmtadc ==....
1128    
1129     } // adc < sat
1130     } // ipmt...
1131    
1132    
1133     //====================================================================
1134     //============= Check ToF standalone using HitPaddle ===================
1135     //====================================================================
1136    
1137     Int_t PaddleIdOfTrack[6] = {-1, -1, -1, -1, -1, -1};;
1138    
1139     for(jj=0; jj<8; jj++){
1140     Int_t HitPad = L2->GetToFLevel2()->HitPaddle(0,jj);
1141     if (HitPad==1) PaddleIdOfTrack[0] = jj;
1142     }
1143     for(jj=0; jj<6; jj++){
1144     Int_t HitPad = L2->GetToFLevel2()->HitPaddle(1,jj);
1145     if (HitPad==1) PaddleIdOfTrack[1] = jj;
1146     }
1147    
1148    
1149     for(jj=0; jj<2; jj++){
1150     Int_t HitPad = L2->GetToFLevel2()->HitPaddle(2,jj);
1151     if (HitPad==1) PaddleIdOfTrack[2] = jj;
1152     }
1153     for(jj=0; jj<2; jj++){
1154     Int_t HitPad = L2->GetToFLevel2()->HitPaddle(3,jj);
1155     if (HitPad==1) PaddleIdOfTrack[3] = jj;
1156     }
1157    
1158     for(jj=0; jj<3; jj++){
1159     Int_t HitPad = L2->GetToFLevel2()->HitPaddle(4,jj);
1160     if (HitPad==1) PaddleIdOfTrack[4] = jj;
1161     }
1162     for(jj=0; jj<3; jj++){
1163     Int_t HitPad = L2->GetToFLevel2()->HitPaddle(5,jj);
1164     if (HitPad==1) PaddleIdOfTrack[5] = jj;
1165     }
1166    
1167     //==============================================================
1168    
1169    
1170     Int_t ihelp_a[6] = {0,16,28,32,36,42};
1171    
1172     for (Int_t ilay=0; ilay<6; ilay ++) {
1173     Int_t jj = PaddleIdOfTrack[ilay] ;
1174 pamelats 1.2 //Float_t xhelp = 1000.;
1175     Float_t xhelp = 1005.;
1176 pamela 1.1
1177     if (jj == -1) Layerinfo[ilay] = -1;
1178    
1179     if (jj != -1) {
1180     Int_t ih = ihelp_a[ilay] + 2*jj;
1181 pamelats 1.3
1182     // New WM
1183     Int_t igood1=0;
1184     Int_t igood2=0;
1185     if ((PMTcharge_arr[ih] < 1000.) && (PMTcharge_arr[ih] > 0.)) igood1=1;
1186     if ((PMTcharge_arr[ih+1] < 1000.) && (PMTcharge_arr[ih+1] > 0.)) igood2=1;
1187    
1188     if ((PMTcharge_arr[ih]==0.) && (PMTcharge_arr[ih+1]==0.)) xhelp = 0.;
1189     if ((igood1==1)&&(igood2==1)) xhelp = 0.5*(PMTcharge_arr[ih]+PMTcharge_arr[ih+1]) ;
1190     if ((igood1==1)&&(igood2==0)) xhelp = PMTcharge_arr[ih];
1191     if ((igood2==1)&&(igood1==0)) xhelp = PMTcharge_arr[ih+1];
1192    
1193    
1194     /*
1195 pamela 1.1 if ((PMTcharge_arr[ih] < 1000.) && (PMTcharge_arr[ih+1] < 1000.)) xhelp = 0.5*(PMTcharge_arr[ih]+PMTcharge_arr[ih+1]) ;
1196     if ((PMTcharge_arr[ih] < 1000.) && (PMTcharge_arr[ih+1]==1000.)) xhelp = PMTcharge_arr[ih] ;
1197     if ((PMTcharge_arr[ih]==1000.) && (PMTcharge_arr[ih+1] < 1000.)) xhelp = PMTcharge_arr[ih+1] ;
1198 pamelats 1.3 */
1199 pamela 1.1
1200     if (adc[ih] == 4095) Layerinfo[ilay] = Layerinfo[ilay] + 1;
1201     if (adc[ih+1] == 4095) Layerinfo[ilay] = Layerinfo[ilay] + 1;
1202     if ((adc[ih] > PMTsat[ih]) && (adc[ih] < 4095)) Layerinfo[ilay] = Layerinfo[ilay] + 10;
1203     if ((adc[ih+1] > PMTsat[ih+1]) && (adc[ih+1] < 4095)) Layerinfo[ilay] = Layerinfo[ilay] + 10;
1204    
1205    
1206     }
1207     Layercharge[ilay] = xhelp;
1208     } // ilay ...
1209    
1210    
1211     //cout<<"Std: ";
1212     //for (Int_t ilay=0; ilay<6; ilay ++) cout<<Layercharge[ilay]<<" ";
1213    
1214     //==========================================================================
1215 pamelats 1.6 //============= Layercharge without 2nd-order correction =================
1216     //==========================================================================
1217    
1218     for (Int_t jj=0; jj<6;jj++) charge_layer_std_raw[jj] = Layercharge[jj];
1219    
1220     //==========================================================================
1221 pamela 1.1 //========================= 2nd-order correction =======================
1222     //==========================================================================
1223    
1224     Float_t xb = beta_mean;
1225    
1226     for (Int_t ii=0; ii<6; ii++) {
1227     Int_t ic = 0;
1228     Float_t corr[4] = {1., 0., 0., 0.};
1229 pamelats 1.2 //for (Int_t iii=1; iii<9; iii++) if (fabs(Layercharge[ii] - iii)<0.50) ic = iii;
1230     for (Int_t iii=1; iii<10; iii++) if (fabs(Layercharge[ii] - iii)<0.50) ic = iii;
1231 pamela 1.1 if ((ic>0)&&(ic<=5)) for (Int_t iii=0; iii<4; iii++) corr[iii] = corr_a[ic-1][iii];
1232     if (ic >5) for (Int_t iii=0; iii<4; iii++) corr[iii] = corr_a[5][iii];
1233    
1234     Float_t c_corr = corr[0]+corr[1]*xb+corr[2]*xb*xb+corr[3]*xb*xb*xb;
1235    
1236     if ((ic>0)&&(ic<=5)) c_corr = c_corr/(1.*ic) ;
1237     if (ic>5) c_corr = c_corr/6. ;
1238    
1239 pamelats 1.2 //cout<<Layercharge[ii]<<" "<<ic<<" "<<c_corr<<" => ";
1240 pamela 1.1 Layercharge[ii] = Layercharge[ii]/c_corr;
1241 pamelats 1.2 //cout<<Layercharge[ii]<<endl;
1242 pamela 1.1
1243     }
1244    
1245 pamelats 1.2
1246 pamela 1.1 //==========================================================================
1247 pamelats 1.2 //cout<<"In ToFNuclei Std: ";
1248     //for (Int_t ilay=0; ilay<6; ilay ++) cout<<Layercharge[ilay]<<" ";
1249     //cout<<endl;
1250 pamela 1.1 //==========================================================================
1251    
1252    
1253     Int_t icount=0;
1254     Float_t charge_mean = 0.;
1255     for (Int_t ii=0; ii<6; ii++) {
1256     if (Layercharge[ii] < 1000) charge_mean = charge_mean + Layercharge[ii] ;
1257     if (Layercharge[ii] < 1000) icount++;
1258     }
1259     if (icount>0) charge_mean = charge_mean/(1.*icount) ;
1260    
1261 pamelats 1.2 if (icount>0) {
1262    
1263     //for (Int_t ii=0; ii<6; ii++) cout<<Layercharge[ii]<<" ";
1264     //cout<<endl;
1265    
1266    
1267     vector<float> charge_v;
1268     Float_t charge_median = 0.;
1269    
1270     //////// get the median charge ////////////
1271     for(Int_t ii=0;ii<6;ii++) {
1272     if (Layercharge[ii] < 1000) charge_v.push_back(Layercharge[ii]);
1273     }
1274    
1275     std::sort(charge_v.begin(),charge_v.end());
1276     charge_median = charge_v[(int)(charge_v.size()/2+charge_v.size()%2)-1];
1277    
1278     //cout<<charge_mean<<" "<<charge_median<<endl;
1279    
1280     charge_mean = charge_median;
1281    
1282     } // icount>0
1283 pamela 1.1
1284     //--- Calculate charge for the second time, use residuals of the single
1285     //--- measurements to get a chi2 value
1286    
1287     // Float_t w_i_arr[8] = {0.1, 0.15, 0.2, 0.25, 0.30, 0.35, 0.45, 0.50};
1288     Float_t w_i_arr[8] = {0.1, 0.15, 0.2, 0.25, 0.35, 0.40, 0.50, 0.55};
1289    
1290     icount=0;
1291     Float_t sw=0.;
1292     Float_t sxw=0.;
1293     Float_t w_i = 1./0.5;
1294     Float_t resmax= 3.0;
1295    
1296     iz=1;
1297     if ((0.0<charge_mean) & (charge_mean<1.5)) iz=1;
1298     if ((1.5<charge_mean) & (charge_mean<2.5)) iz=2;
1299     if ((2.5<charge_mean) & (charge_mean<3.5)) iz=3;
1300     if ((3.5<charge_mean) & (charge_mean<4.5)) iz=4;
1301     if ((4.5<charge_mean) & (charge_mean<5.5)) iz=5;
1302     if ((5.5<charge_mean) & (charge_mean<6.5)) iz=6;
1303     if ((6.5<charge_mean) & (charge_mean<7.5)) iz=7;
1304     if ((7.5<charge_mean) & (charge_mean<90.)) iz=8;
1305    
1306     w_i = 1./w_i_arr[iz-1];
1307    
1308    
1309     for (Int_t jj=0; jj<6;jj++){
1310     if (Layercharge[jj] < 1000) {
1311     Float_t res = charge_mean - Layercharge[jj] ;
1312     if (fabs(res*w_i)<resmax) {;
1313     icount= icount+1;
1314     sxw=sxw + Layercharge[jj]*w_i*w_i ;
1315     sw =sw + w_i*w_i ;
1316     }
1317     }
1318     }
1319    
1320     if (icount>0) charge_chi=sxw/sw;
1321    
1322     ncount = icount;
1323    
1324     //cout<<" => "<<icount<<" "<<charge_chi<<endl;
1325    
1326    
1327     // charge_tof = charge_chi;
1328    
1329 pamelats 1.2 // changed 30-01-2009 WM
1330 pamela 1.1
1331 pamelats 1.2 for (Int_t jj=0; jj<48;jj++) charge_PMT_std[jj] = PMTcharge_arr[jj];
1332 pamela 1.1 for (Int_t jj=0; jj<6;jj++) charge_layer_std[jj] = Layercharge[jj];
1333     for (Int_t jj=0; jj<6;jj++) layerinfo_std[jj] = Layerinfo[jj];
1334     charge_std = charge_chi;
1335     ncount_std = ncount;
1336    
1337 pamelats 1.2 } // 0.05 < fabs( beta) < 2.0
1338    
1339    
1340 pamela 1.1 } // standalone track found
1341    
1342     }

  ViewVC Help
Powered by ViewVC 1.1.23