convert.C

read the digi data - Ivan Muzalevsky, 08/14/2020 05:34 PM

Download (12.8 KB)

 
1
Int_t GetClusterMWPC(TClonesArray *data);
2
void MWPCprojection();
3
Float_t GetPosition(Float_t wire, Float_t wireStep,Float_t planeOffset);
4

    
5
void fillSi(TClonesArray *data,Float_t* amp,Float_t* time,Float_t *par1,Float_t *par2,Int_t *multiplicity, Float_t ampThreshold,Float_t timeThreshold=0);
6
void fillarrayCsI(TClonesArray *data,Float_t* amp,Float_t* time,Float_t *par1,Float_t *par2);
7

    
8
void processCsI_cal();
9

    
10
void zeroVars();
11

    
12
void fillF5(TClonesArray *data);
13
void fillF3(TClonesArray *data);
14
void fillMWPC(TClonesArray *data,Float_t *wire);
15
void readPar(TString fileName,Float_t *par1,Float_t *par2,Int_t size=16);
16

    
17
Int_t GetClusterSi(TClonesArray *data);
18
Int_t GetClusterMult(TClonesArray *data);
19
ERQTelescopeCsIDigi* processCsI(TClonesArray *data);
20

    
21
void fillCsI(ERQTelescopeCsIDigi *data);
22
//outtree vars
23
Int_t trigger; 
24

    
25
Float_t F5,tF5,F3,tF3;
26

    
27
Float_t wirex1,wirex2,wirey1,wirey2;
28
Float_t tMWPC[4];
29

    
30
Float_t fXt,fYt;
31
Float_t x1c, y1c, x2c, y2c;
32

    
33
Int_t nCsI;
34
Float_t aCsI,tCsI,aCsI_cal;
35

    
36
Float_t arCsI[16],trCsI[16];
37

    
38
Float_t DSD_X[32],DSD_Y[32];
39
Float_t tDSD_X[32],tDSD_Y[32];
40

    
41
Float_t SQ20_1[16],SSD1[16],SSD_V1[16];
42
Float_t tSQ20_1[16],tSSD1[16],tSSD_V1[16];
43

    
44

    
45
Float_t SQ20_2[16],SSD2[16],SSD_V2[16];
46
Float_t tSQ20_2[16],tSSD2[16],tSSD_V2[16];
47

    
48
Float_t SQ20_3[16],SSD3[16],SSD_V3[16];
49
Float_t tSQ20_3[16],tSSD3[16],tSSD_V3[16];
50

    
51
Float_t SQ20_4[16],SSD4[16],SSD_V4[16];
52
Float_t tSQ20_4[16],tSSD4[16],tSSD_V4[16];
53

    
54
// Sipars
55
Float_t pSQ201_1[16],pSQ201_2[16];
56
Float_t pSQ202_1[16],pSQ202_2[16];
57
Float_t pSQ203_1[16],pSQ203_2[16];
58
Float_t pSQ204_1[16],pSQ204_2[16];
59

    
60
Float_t pSSD1_1[16],pSSD1_2[16];
61
Float_t pSSD2_1[16],pSSD2_2[16];
62
Float_t pSSD3_1[16],pSSD3_2[16];
63
Float_t pSSD4_1[16],pSSD4_2[16];
64

    
65
Float_t pSSD_V1_1[16],pSSD_V1_2[16];
66
Float_t pSSD_V2_1[16],pSSD_V2_2[16];
67
Float_t pSSD_V3_1[16],pSSD_V3_2[16];
68
Float_t pSSD_V4_1[16],pSSD_V4_2[16];
69

    
70

    
71
Float_t pDSD_X1[32],pDSD_X2[32];
72
Float_t pDSD_Y1[32],pDSD_Y2[32];
73

    
74
Float_t pCsI_1[16],pCsI_2[16];
75

    
76
Float_t *nullPtr = NULL;
77

    
78
//
79
Int_t mult20_1,mult1_1,multv_1;
80
Int_t mult20_2,mult1_2,multv_2;
81
Int_t mult20_3,mult1_3,multv_3;
82
Int_t mult20_4,mult1_4,multv_4;
83

    
84
Int_t multc_x,multc_y,multCsI;
85

    
86
void convert(TString InFile, TString OutFile) {
87

    
88
  TChain *ch = new TChain("er");
89
  ch->Add(InFile.Data());
90
  // ch->Add("/media/ivan/data/exp1904/digi/h7/h7_ct_40*.root");
91
  cout << "Found " << ch->GetEntries() << " entries" << endl;
92

    
93
  // readPar("SSD_20u_1_cal",pSQ201_1,pSQ201_2);
94
  // readPar("SSD_20u_2_cal",pSQ202_1,pSQ202_2);
95
  // readPar("SSD_20u_3_cal",pSQ203_1,pSQ203_2);
96
  // readPar("SSD_20u_4_cal",pSQ204_1,pSQ204_2);
97

    
98
  // readPar("SSD_1m_1_cal",pSSD1_1,pSSD1_2);
99
  // readPar("SSD_1m_2_cal",pSSD2_1,pSSD2_2);
100
  // readPar("SSD_1m_3_cal",pSSD3_1,pSSD3_2);
101
  // readPar("SSD_1m_4_cal",pSSD4_1,pSSD4_2);
102

    
103
  // readPar("SSD_1m_1_v_cal",pSSD_V1_1,pSSD_V1_2);
104
  // readPar("SSD_1m_2_v_cal",pSSD_V2_1,pSSD_V2_2);  
105
  // readPar("SSD_1m_3_v_cal",pSSD_V3_1,pSSD_V3_2);
106
  // readPar("SSD_1m_4_v_cal",pSSD_V4_1,pSSD_V4_2);
107

    
108
  // readPar("DSSD_X",pDSD_X1,pDSD_X2,32);
109
  // readPar("DSSD_Y",pDSD_Y1,pDSD_Y2,32);
110

    
111
  // readPar("empty16",pCsI_1,pCsI_2);
112

    
113
//--------------------------------------------------------------------------------
114
  ERBeamTimeEventHeader* header = new ERBeamTimeEventHeader();
115

    
116
  TClonesArray *v_DSDX_C = new TClonesArray("ERQTelescopeSiDigi");
117
  TClonesArray *v_DSDY_C = new TClonesArray("ERQTelescopeSiDigi");
118
  TClonesArray *v_CsI = new TClonesArray("ERQTelescopeCsIDigi");
119

    
120
  TClonesArray *v_F5 = new TClonesArray("ERBeamDetTOFDigi");
121
  TClonesArray *v_F3 = new TClonesArray("ERBeamDetTOFDigi");  
122

    
123
  TClonesArray *v_MWPCx1 = new TClonesArray("ERBeamDetMWPCDigi");
124
  TClonesArray *v_MWPCy1 = new TClonesArray("ERBeamDetMWPCDigi");  
125
  TClonesArray *v_MWPCx2 = new TClonesArray("ERBeamDetMWPCDigi");
126
  TClonesArray *v_MWPCy2 = new TClonesArray("ERBeamDetMWPCDigi"); 
127

    
128
  TClonesArray *v_SSD_V_1 = new TClonesArray("ERQTelescopeSiDigi");
129
  TClonesArray *v_SSD20_1 = new TClonesArray("ERQTelescopeSiDigi");
130
  TClonesArray *v_SSD_1 = new TClonesArray("ERQTelescopeSiDigi");
131

    
132
  TClonesArray *v_SSD_V_2 = new TClonesArray("ERQTelescopeSiDigi");
133
  TClonesArray *v_SSD20_2 = new TClonesArray("ERQTelescopeSiDigi");
134
  TClonesArray *v_SSD_2 = new TClonesArray("ERQTelescopeSiDigi");
135

    
136
  TClonesArray *v_SSD_V_3 = new TClonesArray("ERQTelescopeSiDigi");
137
  TClonesArray *v_SSD20_3 = new TClonesArray("ERQTelescopeSiDigi");
138
  TClonesArray *v_SSD_3 = new TClonesArray("ERQTelescopeSiDigi");
139

    
140
  TClonesArray *v_SSD_V_4 = new TClonesArray("ERQTelescopeSiDigi");
141
  TClonesArray *v_SSD20_4 = new TClonesArray("ERQTelescopeSiDigi");
142
  TClonesArray *v_SSD_4 = new TClonesArray("ERQTelescopeSiDigi");
143

    
144

    
145
  // setbranchAdress
146
  ch->SetBranchAddress("BeamDetToFDigi2",&v_F5);
147
  ch->SetBranchAddress("BeamDetToFDigi1",&v_F3);
148

    
149
  ch->SetBranchAddress("BeamDetMWPCDigiX1",&v_MWPCx1);
150
  ch->SetBranchAddress("BeamDetMWPCDigiX2",&v_MWPCx2);
151
  ch->SetBranchAddress("BeamDetMWPCDigiY1",&v_MWPCy1);
152
  ch->SetBranchAddress("BeamDetMWPCDigiY2",&v_MWPCy2);  
153

    
154
  ch->SetBranchAddress("EventHeader.",&header);
155

    
156
  TFile *f;
157
  TString cutName;
158

    
159
  // Creating outfile,outtree
160
  TFile *fw = new TFile(OutFile.Data(), "RECREATE");
161
  TTree *tw = new TTree("tree", "data");
162

    
163
  tw->Branch("trigger",&trigger,"trigger/I");
164

    
165
  tw->Branch("F5.",&F5,"F5/F");
166
  tw->Branch("tF5.",&tF5,"tF5/F");
167
  tw->Branch("F3.",&F3,"F3/F");
168
  tw->Branch("tF3.",&tF3,"tF3/F");
169

    
170
  tw->Branch("tMWPC.",&tMWPC,"tMWPC[4]/F");
171
  tw->Branch("wirex1.",&wirex1,"wirex1/F");
172
  tw->Branch("wirex2.",&wirex2,"wirex2/F");
173
  tw->Branch("wirey1.",&wirey1,"wirey1/F");
174
  tw->Branch("wirey2.",&wirey2,"wirey2/F");
175

    
176
  tw->Branch("x1c.",&x1c,"x1c/F"); // position in MWPC in mm
177
  tw->Branch("y1c.",&y1c,"y1c/F");
178
  tw->Branch("x2c.",&x2c,"x2c/F");
179
  tw->Branch("y2c.",&y2c,"y2c/F"); 
180
  tw->Branch("fXt.",&fXt,"fXt/F"); // beam profile at the target plane
181
  tw->Branch("fYt.",&fYt,"fYt/F"); 
182

    
183
  // for(Int_t nentry=0;nentry<ch->GetEntries();nentry++) {
184
  for(Int_t nentry=0;nentry<100;nentry++) {    
185
    if(nentry%1000000==0) cout << "#Event " << nentry << "#" << endl;
186
    ch->GetEntry(nentry);
187
    if(v_MWPCx1->GetEntriesFast()==0) continue;
188
    if(v_MWPCx2->GetEntriesFast()==0) continue;
189
    if(v_MWPCy1->GetEntriesFast()==0) continue;
190
    if(v_MWPCy2->GetEntriesFast()==0) continue;
191

    
192
    if (GetClusterMWPC(v_MWPCx1)!=1) continue;
193
    if (GetClusterMWPC(v_MWPCx2)!=1) continue;
194
    if (GetClusterMWPC(v_MWPCy1)!=1) continue;
195
    if (GetClusterMWPC(v_MWPCy2)!=1) continue;  
196

    
197
    trigger = header->GetTrigger();
198

    
199
    zeroVars();
200

    
201
  // beamdet
202
    fillF5(v_F5);
203
    fillF3(v_F3);
204
  
205
    tMWPC[0] = ((ERBeamDetMWPCDigi*)v_MWPCx1->At(0))->Time();
206
    tMWPC[1] = ((ERBeamDetMWPCDigi*)v_MWPCy1->At(0))->Time();
207
    tMWPC[2] = ((ERBeamDetMWPCDigi*)v_MWPCx2->At(0))->Time();
208
    tMWPC[3] = ((ERBeamDetMWPCDigi*)v_MWPCy2->At(0))->Time();
209

    
210
    fillMWPC(v_MWPCx1,&wirex1);
211
    fillMWPC(v_MWPCy1,&wirey1);
212
    fillMWPC(v_MWPCx2,&wirex2);
213
    fillMWPC(v_MWPCy2,&wirey2);
214

    
215
    MWPCprojection();
216

    
217
    tw->Fill();
218
  }
219

    
220
  fw->cd();
221
  tw->Write();
222
  fw->Close();
223

    
224
  return;
225
}
226

    
227
Int_t GetClusterMWPC(TClonesArray *data) {
228

    
229
  if (!data) return 0;
230

    
231
  Int_t entries = data->GetEntriesFast();
232

    
233
  if (entries<2) return entries;
234

    
235
  Int_t wire1, wire2;
236
  Int_t noclusters = 1;
237

    
238
  for (Int_t i = 1; i < entries; i++) {
239
    //check if entries are in specific order
240
    wire1 = ((ERBeamDetMWPCDigi*)data->At(i))->Channel();
241
    wire2 = ((ERBeamDetMWPCDigi*)data->At(i-1))->Channel();
242

    
243
    //todo number 32 is related to number of wires
244
    // and should be taken from Parameters
245
    if ( abs(wire1 - wire2) > 1 && abs(wire1 - wire2) < 32) {
246
      noclusters++;
247
    }
248
  }
249

    
250
  return noclusters;
251
}
252

    
253
void zeroVars() {
254
  // trigger = -1;
255

    
256
  F5 = 0;
257
  tF5 = 0;
258
  F3 = 0;
259
  tF3 = 0;
260

    
261
  wirex1 = -1;
262
  wirex2 = -1;
263
  wirey1 = -1;
264
  wirey2 = -1;
265
  
266
  for(Int_t i = 0;i<4;i++) {
267
    tMWPC[i] = 0;
268
  }
269

    
270
  x1c = -50;
271
  y1c = -50;
272
  x2c = -50;
273
  y2c = -50;
274

    
275
  fXt = -100;
276
  fYt = -100;
277

    
278
  nCsI = -1;
279
  aCsI = 0;
280
  tCsI = 0;
281

    
282
  for(Int_t i=0;i<16;i++) {
283
    arCsI[i] = 0;
284
    trCsI[i] = 0;
285

    
286
    SQ20_1[i] = 0;
287
    SSD1[i] = 0;
288
    SSD_V1[i] = -10;
289
    tSQ20_1[i] = 0;
290
    tSSD1[i] = 0;
291
    tSSD_V1[i] = -10;
292

    
293
    SQ20_2[i] = 0;
294
    SSD2[i] = 0;
295
    SSD_V2[i] = 0;
296
    tSQ20_2[i] = 0;
297
    tSSD2[i] = -10;
298
    tSSD_V2[i] = -10;
299

    
300
    SQ20_3[i] = 0;
301
    SSD3[i] = 0;
302
    SSD_V3[i] = 0;
303
    tSQ20_3[i] = 0;
304
    tSSD3[i] = -10;
305
    tSSD_V3[i] = -10;
306

    
307
    SQ20_4[i] = 0;
308
    SSD4[i] = 0;
309
    SSD_V4[i] = 0;
310
    tSQ20_4[i] = 0;
311
    tSSD4[i] = -10;
312
    tSSD_V4[i] = -10;
313
  }
314

    
315
  for(Int_t i=0;i<32;i++) {
316
    DSD_X[i] = 0;
317
    DSD_Y[i] = 0;
318
    tDSD_X[i] = 0;
319
    tDSD_Y[i] = 0;
320
  }
321

    
322
}
323

    
324
void fillF5(TClonesArray *data){
325
  if (!data) return;
326
  ERBeamDetTOFDigi *temp_F5 = ((ERBeamDetTOFDigi*)data->At(0));
327
  if(!temp_F5) return;
328

    
329
  F5 = temp_F5->Edep();
330
  tF5 = temp_F5->Time();
331

    
332
  return; 
333
}
334

    
335
void fillF3(TClonesArray *data){
336
  if (!data) return;
337
  ERBeamDetTOFDigi *temp_F3 = ((ERBeamDetTOFDigi*)data->At(0));
338
  if(!temp_F3) return;
339

    
340
  F3 = temp_F3->Edep();
341
  tF3 = temp_F3->Time();
342

    
343
  return; 
344
}
345

    
346
void fillMWPC(TClonesArray *data,Float_t *wire) {
347
  if (!data) return;
348

    
349
  *(wire) = ((ERBeamDetMWPCDigi*)data->At(0))->Channel() + ((ERBeamDetMWPCDigi*)data->At(data->GetEntriesFast()-1))->Channel();
350
  *(wire) = *(wire)/2; 
351

    
352
  return;
353
}
354

    
355
void MWPCprojection() {
356

    
357
  const Float_t fMWPCwireStepX1 = -1.25;
358
  const Float_t fMWPCwireStepY1 = 1.25;   //step between two wires
359
  const Float_t fMWPCwireStepX2 = -1.25;    //step between two wires
360
  const Float_t fMWPCwireStepY2 = 1.25;   //step between two wires
361

    
362
  const Float_t fMWPC1_X_offset = 0;
363
  const Float_t fMWPC1_Y_offset = 0;
364

    
365
  const Float_t fMWPC2_X_offset = 0;
366
  const Float_t fMWPC2_Y_offset = 0;
367

    
368
  const Float_t fMWPCz1 = -815.;  //z coordinate of the center of MWPC1
369
  const Float_t fMWPCz2 = -270.;  //z coordinate of the center of MWPC2
370

    
371
  Float_t xtc, ytc;
372
  //cluster multiplicity equal to 1
373
  x1c = GetPosition(wirex1, fMWPCwireStepX1, fMWPC1_X_offset);
374
  y1c = GetPosition(wirey1, fMWPCwireStepY1, fMWPC1_Y_offset);
375

    
376
  x2c = GetPosition(wirex2, fMWPCwireStepX2, fMWPC2_X_offset);
377
  y2c = GetPosition(wirey2, fMWPCwireStepY2, fMWPC2_Y_offset);
378

    
379
  xtc = x1c - (x2c -x1c)*fMWPCz1/(fMWPCz2-fMWPCz1);
380
  ytc = y1c + (xtc - x1c)*(y2c-y1c)/(x2c-x1c);
381

    
382
  fXt = xtc;
383
  fYt = ytc;
384
}
385

    
386
Float_t GetPosition(Float_t wire, Float_t wireStep,
387
    Float_t planeOffset) {
388
  //TODO: number of wires (16) as parameter
389
  //TODO: omit gRandom
390
  return (wire - 16.5)*wireStep + planeOffset;
391
}
392

    
393
void fillSi(TClonesArray *data,Float_t* amp,Float_t* time,Float_t *par1,Float_t *par2,Int_t *multiplicity, Float_t ampThreshold,Float_t timeThreshold=0) {
394
  if(!data) return;
395
  if(data->GetEntriesFast()==0) return;
396
  Bool_t isCal = kTRUE;
397
  if(par1 == NULL || par2 == NULL) isCal = kFALSE;
398

    
399
  Int_t nCh;
400
  for(Int_t i=0;i<data->GetEntriesFast();i++) { 
401
    nCh = ((ERQTelescopeSiDigi*)data->At(i))->Channel();
402
    // cout << 1000*((ERQTelescopeSiDigi*)data->At(i))->Edep()*(*(par2+nCh)) + (*(par1+nCh)) << " " << nCh << " " << *(par2+nCh) << " " << *(par1+nCh) << endl;
403
    if (isCal) *(amp+nCh) = ((ERQTelescopeSiDigi*)data->At(i))->Edep();
404
    if (!isCal) *(amp+nCh) = ((ERQTelescopeSiDigi*)data->At(i))->Edep();
405
    *(time+nCh) = ((ERQTelescopeSiDigi*)data->At(i))->Time();
406
    if ( isCal && ( *(amp+nCh)<=ampThreshold || *(time+nCh)<=timeThreshold ) ) {
407
      *(amp+nCh) = 0;
408
      *(time+nCh) = 0;
409
      *multiplicity = *multiplicity - 1;
410
    } 
411
  } 
412
}
413

    
414
void fillarrayCsI(TClonesArray *data,Float_t* amp,Float_t* time,Float_t *par1,Float_t *par2) {
415
  if(!data) return;
416
  if(data->GetEntriesFast()==0) return;
417

    
418
  Int_t nCh;
419
  for(Int_t i=0;i<data->GetEntriesFast();i++) {
420
    nCh = ((ERQTelescopeCsIDigi*)data->At(i))->Channel();
421
    *(amp+nCh) = ((ERQTelescopeCsIDigi*)data->At(i))->Edep();
422
    *(time+nCh) = ((ERQTelescopeCsIDigi*)data->At(i))->Time();
423
  }
424
  return;
425
}
426

    
427
void processCsI_cal() {
428

    
429
  for(Int_t i=0;i<16;i++){
430
    if (arCsI[i]>aCsI) {
431
      tCsI = trCsI[i];
432
      nCsI = i;
433
      aCsI = arCsI[i];
434
    }
435
  }
436

    
437
  Int_t nMax = 0;
438
  for(Int_t i=0;i<16;i++){
439
    if (arCsI[i]==aCsI) {
440
      nMax++;
441
    }
442
  }
443

    
444

    
445
  if (nMax!=1) {
446
     cout << " ##ENTRY## " << endl;
447
    for(Int_t i=0;i<16;i++) {
448
      if (arCsI[i]>0 && trCsI[i]>0) cout << i << " " << arCsI[i] << " " << trCsI[i] << endl;
449
    }
450

    
451
    cout << " maximum choice " << endl;
452
    cout << nCsI << " " << aCsI << " " << tCsI << " " << endl;
453
    cout << " nMAX= " << nMax << endl;
454

    
455
    nCsI = -1;
456
    tCsI = 0;
457
    aCsI = 0;
458
  } 
459
 
460
  return;
461
}
462

    
463

    
464
void readPar(TString fileName,Float_t *par1,Float_t *par2,Int_t size=16){
465

    
466
  TString line;
467
  ifstream myfile;
468
  Int_t count=0;
469
  TString file = "/home/ivan/work/macro/h7_1904/parameters/" + fileName + ".cal";
470
  myfile.open(file.Data());
471
  while (! myfile.eof() ){
472
    line.ReadLine(myfile);
473
    // if(count < 0){
474
    //   count++;
475
    //   continue;
476
    // }
477
    if(line.IsNull()) break;
478
    sscanf(line.Data(),"%g %g", par1+count,par2+count);
479
    count++;
480
  }
481
  cout << endl << fileName.Data() << endl;
482
  for(Int_t i=0;i<size;i++) cout << par1[i] << " " << par2[i] << endl;
483

    
484
  return;
485
}
486