CsI_fill.C

for merging raw data and converting into calibrated - Ivan Muzalevsky, 05/23/2018 11:41 AM

Download (8.89 KB)

 
1
//---------------------------------------------------------
2
Double_t fitf(Double_t *x,Double_t *par) {  // creating fit function
3
  Int_t A,Z;
4
  A = 4; Z = 2;
5
  Double_t fitval = par[4] + par[0]*( x[0]*(1 - (par[1]*A*Z*Z/x[0])*TMath::Log(1 + (1/(par[1]*A*Z*Z/x[0])) ) ) + par[3]*par[1]*A*Z*Z*TMath::Log( (x[0]+par[1]*A*Z*Z)/(A*par[2]+par[1]*A*Z*Z) ) );
6
  return fitval;
7
}
8
//---------------------------------------------------------
9

    
10
void CsI_fill() { 
11
        
12
    // Reading cal parameters 
13
  Float_t parXL1[32], parXL2[32],parYL1[16],parYL2[16],parXR1[32], parXR2[32],parYR1[16],parYR2[16];
14
  //------------------------------------------------------------------------------ 
15
  // for 1 mm Si detector
16
  TString line1;
17
  ifstream myfile1;
18
  Int_t count=-2;
19
  myfile1.open("/home/muzalevsky/work/exp1803/data/siCal/SQX_R.cal");
20
  while (! myfile1.eof() ){
21
    line1.ReadLine(myfile1);
22
    if(count < 0){
23
      count++;
24
      continue;
25
    }
26
    if(line1.IsNull()) break;
27
    sscanf(line1.Data(),"%g %g", parXR1+count,parXR2+count);
28
    count++;
29
  }
30
  cout << endl << " pars for XR strips" << endl;
31
  for(Int_t i=0;i<32;i++) cout << parXR1[i] << " " << parXR2[i] << endl;  
32

    
33
  ifstream myfile2;
34
  TString line2;
35
  count=-2;
36
  myfile2.open("/home/muzalevsky/work/exp1803/data/siCal/SQY_R.cal");
37
  while (! myfile2.eof() ){
38
    line2.ReadLine(myfile2);
39
    if(count < 0){
40
      count++;
41
      continue;
42
    }
43
    if(line2.IsNull()) break;
44
    sscanf(line2.Data(),"%g %g", parYR1+count,parYR2+count);
45
    count++;
46
  }
47

    
48
  cout << endl << " pars for YR strips" << endl;
49
  for(Int_t i=0;i<16;i++) cout << parYR1[i] << " " << parYR2[i] << endl;   
50

    
51
  ifstream myfile3;
52
  TString line3;
53
  count=-2;
54
  myfile3.open("/home/muzalevsky/work/exp1803/data/siCal/SQX_L.cal");
55
  while (! myfile3.eof() ){
56
    line3.ReadLine(myfile3);
57
    if(count < 0){
58
      count++;
59
      continue;
60
    }
61
    if(line3.IsNull()) break;
62
    sscanf(line3.Data(),"%g %g", parXL1+count,parXL2+count);
63
    count++;
64
  }
65

    
66
  cout << endl << " pars for XL strips" << endl;
67
  for(Int_t i=0;i<32;i++) cout << parXL1[i] << " " << parXL2[i] << endl;   
68

    
69
  ifstream myfile4;
70
  TString line4;
71
  count=-2;
72
  myfile4.open("/home/muzalevsky/work/exp1803/data/siCal/SQY_L.cal");
73
  while (! myfile4.eof() ){
74
    line4.ReadLine(myfile4);
75
    if(count < 0){
76
      count++;
77
      continue;
78
    }
79
    if(line4.IsNull()) break;
80
    sscanf(line4.Data(),"%g %g", parYL1+count,parYL2+count);
81
    count++;
82
  }
83

    
84
  cout << endl << " pars for YL strips" << endl;
85
  for(Int_t i=0;i<16;i++) cout << parYL1[i] << " " << parYL2[i] << endl;   
86

    
87
  // get pars for positions of times
88
  cout << endl << " time parameters " << endl;
89
  ifstream myfile5;
90
  TString line5;
91
  Float_t tPx_l1[32],tPx_l2[32];
92
  myfile5.open("/home/muzalevsky/work/exp1803/macro/dataMuzalevsky/exp201803/calib/Csi/tParX_L.clb");
93
  count = -2;
94
  while (! myfile5.eof() ){
95
    line5.ReadLine(myfile5);
96
    if(count < 0){
97
      count++;
98
      continue;
99
    }
100
    if(line5.IsNull()) break;
101
    sscanf(line5.Data(),"%g %g", tPx_l1+count,tPx_l2+count);
102
    count++;
103
  }
104
  cout << endl << " pars for X time positions" << endl;
105
  for(Int_t i=0;i<32;i++) cout << tPx_l1[i] << " " << tPx_l2[i] << endl;      
106

    
107
  ifstream myfile6;
108
  TString line6;
109
  Float_t tPy_l1[16],tPy_l2[16];
110
  myfile6.open("/home/muzalevsky/work/exp1803/macro/dataMuzalevsky/exp201803/calib/Csi/tParY_L.clb");
111
  count = -2;
112
  while (! myfile6.eof() ){
113
    line6.ReadLine(myfile6);
114
    if(count < 0){
115
      count++;
116
      continue;
117
    }
118
    if(line6.IsNull()) break;
119
    sscanf(line6.Data(),"%g %g", tPy_l1+count,tPy_l2+count);
120
    count++;
121
  }
122
  cout << endl << " pars for Y time positions" << endl;
123
  for(Int_t i=0;i<16;i++) cout << tPy_l1[i] << " " << tPy_l2[i] << endl;      
124

    
125
  //------------------------------------------------------------------------------ 
126
        TFile *f[100]; 
127
  TString input_file;
128
  Float_t CsI_R[16],F3[4],tF3[4],F5[4],tF5[4],SQX_R[32],SQY_R[16],SQX_L[32],SQY_L[16],tSQX_R[32],tSQY_R[16],tSQX_L[32],tSQY_L[16],zeroPos,shitf;
129
  TTree*                 t;
130
  UShort_t    NeEvent_CsI_R[16],NeEvent_F3[4],NeEvent_tF3[4],NeEvent_F5[4],NeEvent_tF5[4],NeEvent_SQX_R[32],NeEvent_SQY_R[16],NeEvent_SQX_L[32],NeEvent_SQY_L[16],NeEvent_tSQX_R[32],NeEvent_tSQY_R[16],NeEvent_tSQX_L[32],NeEvent_tSQY_L[16];
131
  TBranch    *b_NeEvent_CsI_R,*b_NeEvent_F3,*b_NeEvent_F5,*b_NeEvent_tF3,*b_NeEvent_tF5,*b_NeEvent_SQX_R,*b_NeEvent_SQY_R,*b_NeEvent_SQX_L,*b_NeEvent_SQY_L,*b_NeEvent_tSQX_R,*b_NeEvent_tSQY_R,*b_NeEvent_tSQX_L,*b_NeEvent_tSQY_L;
132
  Long64_t nentries1;
133
  Int_t maxE,multY_L,multX_L,multY_R,multX_R;
134

    
135
  // Creating outfile,outtree
136
  TFile *fw = new TFile("/home/muzalevsky/work/exp1803/data/exp1804/h5_14/out40cal.root", "RECREATE");
137
  TTree *tw = new TTree("tree", "data");
138
  tw->Branch("CsI_R",&CsI_R,"CsI_R[16]/F");
139
  tw->Branch("F3",&F3,"F3[4]/F");
140
  tw->Branch("F5",&F5,"F5[4]/F");
141
  tw->Branch("tF3",&tF3,"tF3[4]/F");
142
  tw->Branch("tF5",&tF5,"tF5[4]/F");
143
  tw->Branch("SQX_R",&SQX_R,"SQX_R[32]/F");
144
  tw->Branch("SQY_R",&SQY_R,"SQY_R[16]/F");
145
  tw->Branch("SQX_L",&SQX_L,"SQX_L[32]/F");
146
  tw->Branch("SQY_L",&SQY_L,"SQY_L[16]/F");
147
  tw->Branch("tSQX_R",&tSQX_R,"tSQX_R[32]/F");
148
  tw->Branch("tSQY_R",&tSQY_R,"tSQY_R[16]/F");
149
  tw->Branch("tSQX_L",&tSQX_L,"tSQX_L[32]/F");
150
  tw->Branch("tSQY_L",&tSQY_L,"tSQY_L[16]/F");
151
  tw->Branch("multY_L",&multY_L,"multY_L/I");
152
  tw->Branch("multX_L",&multX_L,"multX_L/I");
153

    
154
  for(Int_t n=10;n<50;n++) {
155
    input_file.Form("/media/analysis_nas/exp201804/rootfiles/h5_14_00%d.root",n);                
156
    f[n] = new TFile(input_file.Data());
157
    if (f[n]->IsZombie()) {
158
            cerr << "Input file was not opened " << input_file.Data() << endl;
159
            return 1;
160
    }
161

    
162
          f[n]->GetObject("AnalysisxTree",t);
163
          t->SetMakeClass(1);
164
          t->SetBranchAddress("NeEvent.CsI_R[16]", NeEvent_CsI_R, &b_NeEvent_CsI_R);
165
          t->SetBranchAddress("NeEvent.F3[4]", NeEvent_F3, &b_NeEvent_F3);
166
          t->SetBranchAddress("NeEvent.tF3[4]", NeEvent_tF3, &b_NeEvent_tF3);
167
          t->SetBranchAddress("NeEvent.F5[4]", NeEvent_F5, &b_NeEvent_F5);
168
          t->SetBranchAddress("NeEvent.tF5[4]", NeEvent_tF5, &b_NeEvent_tF5);
169
          t->SetBranchAddress("NeEvent.SQX_R[32]", NeEvent_SQX_R, &b_NeEvent_SQX_R);
170
          t->SetBranchAddress("NeEvent.SQY_R[16]", NeEvent_SQY_R, &b_NeEvent_SQY_R);
171
          t->SetBranchAddress("NeEvent.SQX_L[32]", NeEvent_SQX_L, &b_NeEvent_SQX_L);
172
          t->SetBranchAddress("NeEvent.SQY_L[16]", NeEvent_SQY_L, &b_NeEvent_SQY_L);
173
          t->SetBranchAddress("NeEvent.tSQX_R[32]", NeEvent_tSQX_R, &b_NeEvent_tSQX_R);
174
          t->SetBranchAddress("NeEvent.tSQY_R[16]", NeEvent_tSQY_R, &b_NeEvent_tSQY_R);
175
          t->SetBranchAddress("NeEvent.tSQX_L[32]", NeEvent_tSQX_L, &b_NeEvent_tSQX_L);
176
          t->SetBranchAddress("NeEvent.tSQY_L[16]", NeEvent_tSQY_L, &b_NeEvent_tSQY_L);
177
                
178
          nentries1 = t->GetEntries();
179
    cout << nentries1 << endl;
180
    
181
    maxE = nentries1;
182
    cout<<">>> filling TREE up to "<<maxE<< " event"<<endl;
183
          for (Long64_t jentry=0; jentry<maxE;jentry++) {
184
                  t->GetEntry(jentry);
185
    
186
      // обнуление
187
      for(Int_t i = 0; i<32;i++) {
188
        multY_L = 0;
189
        multX_L = 0;
190
        multY_R = 0;
191
        multX_R = 0;
192
        SQX_R[i]=0.;
193
        SQX_L[i]=0.;
194
        tSQX_R[i]=0.;
195
        tSQX_L[i]=0.;
196
        if(i<16) {
197
          CsI_R[i]=0.;
198
          SQY_R[i]=0.;
199
          SQY_L[i]=0.;
200
          tSQY_R[i]=0.;
201
          tSQY_L[i]=0.;
202
        }
203
        if(i<4){
204
          F3[i] = 0.;
205
          F5[i] = 0.;
206
          tF5[i] = 0.;
207
          tF3[i] = 0.;
208
        }
209
      }
210

    
211
       // selecting nice events
212
      //if( (NeEvent_F5[0]+NeEvent_F3[0]>400) && (NeEvent_F5[0]+NeEvent_F3[0]<750) && (NeEvent_tF5[0]-NeEvent_tF3[0]>640) && (NeEvent_tF5[0]-NeEvent_tF3[0]<750) && 
213
      //    (NeEvent_F5[1]+NeEvent_F3[1]>400) && (NeEvent_F5[1]+NeEvent_F3[1]<750) && (NeEvent_tF5[1]-NeEvent_tF3[1]>640) && (NeEvent_tF5[1]-NeEvent_tF3[1]<750) && 
214
      //    (NeEvent_F5[2]+NeEvent_F3[2]>400) && (NeEvent_F5[2]+NeEvent_F3[2]<750) && (NeEvent_tF5[2]-NeEvent_tF3[2]>640) && (NeEvent_tF5[2]-NeEvent_tF3[2]<750) && 
215
      //    (NeEvent_F5[3]+NeEvent_F3[3]>400) && (NeEvent_F5[3]+NeEvent_F3[3]<750) && (NeEvent_tF5[3]-NeEvent_tF3[3]>640) && (NeEvent_tF5[3]-NeEvent_tF3[3]<750) ) {
216
      //}
217

    
218
      for(Int_t i=0; i<32; i++) {
219
        SQX_R[i] = NeEvent_SQX_R[i]*parXR2[i] + parXR1[i];
220
        SQX_L[i] = NeEvent_SQX_L[i]*parXL2[i] + parXL1[i];
221
        if(SQX_L[i]>1.1) multX_L++; 
222
        if(SQX_R[i]>1.15) multX_R++; 
223
        tSQX_R[i] = NeEvent_tSQX_R[i];
224
        tSQX_L[i] = NeEvent_tSQX_L[i]*tPx_l2[i] + tPx_l1[i];
225
        if(i<16){
226
          CsI_R[i] = NeEvent_CsI_R[i];
227
          SQY_R[i] = NeEvent_SQY_R[i]*parYR2[i] + parYR1[i];
228
          SQY_L[i] = NeEvent_SQY_L[i]*parYL2[i] + parYL1[i];
229
          if(SQY_L[i]>0.85) multY_L++; 
230
          if(SQY_R[i]>1.25) multY_R++; 
231
          tSQY_R[i] = NeEvent_tSQY_R[i];
232
          tSQY_L[i] = NeEvent_tSQY_L[i]*tPy_l2[i] + tPy_l1[i];
233
        }
234
        if(i<4) {
235
          F3[i] = NeEvent_F3[i];
236
          F5[i] = NeEvent_F5[i];
237
          tF3[i] = NeEvent_tF3[i];
238
          tF5[i] = NeEvent_tF5[i];
239
        }
240
      }
241
                  tw->Fill();                        
242
          }//entries
243
  }//nfiles
244
  fw->cd();
245
        tw->Write();
246
        fw->Close();
247
}