selection.C

beam reconstruction - Ivan Muzalevsky, 08/14/2020 05:35 PM

Download (4.08 KB)

 
1
#include "/home/muzalevskii/work/macro/h7_1904/cuts/scripts/create_cuts.C"
2
#include "/home/muzalevskii/work/macro/h7_1904/cuts/scripts/create_IDs.C"
3

    
4
void calculateBeam();
5
void zeroVars();
6

    
7
//outtree vars
8
Int_t trigger; 
9

    
10
Float_t tF5,F5,tF3,F3;
11

    
12
Float_t tMWPC;
13
Float_t wirex1,wirex2,wirey1,wirey2;
14

    
15
// reconstructed
16
Float_t fXt,fYt;
17
Float_t x1c, y1c, x2c, y2c;
18

    
19
TLorentzVector he8;
20

    
21
void selection(TString InFile, TString OutFile) {
22

    
23
  TChain *ch = new TChain("tree");
24
  // TString inPutFileName;
25
  // inPutFileName.Form("/mnt/data/exp1904/analysed/cal/h7/h7_ct_%d_cal.root",nFile);
26
  // inPutFileName.Form("/mnt/data/exp1904/ERanalysis/tests/reco/test_convert.root",nFile);
27
  ch->Add(InFile.Data());
28

    
29

    
30
  cout << ch->GetEntries() << endl;
31
  //--------------------------------------------------------------------------------
32
  ch->SetBranchAddress("trigger",&trigger);
33

    
34
  ch->SetBranchAddress("F5.",&F5);
35
  ch->SetBranchAddress("tF5.",&tF5);
36
  ch->SetBranchAddress("F3.",&F3);
37
  ch->SetBranchAddress("tF3.",&tF3);
38

    
39
  ch->SetBranchAddress("tMWPC.",&tMWPC);
40
  ch->SetBranchAddress("wirex1.",&wirex1);
41
  ch->SetBranchAddress("wirex2.",&wirex2);
42
  ch->SetBranchAddress("wirey1.",&wirey1);
43
  ch->SetBranchAddress("wirey2.",&wirey2);
44

    
45
  ch->SetBranchAddress("x1c.",&x1c); // position in MWPC in mm
46
  ch->SetBranchAddress("y1c.",&y1c);
47
  ch->SetBranchAddress("x2c.",&x2c);
48
  ch->SetBranchAddress("y2c.",&y2c); 
49
  ch->SetBranchAddress("fXt.",&fXt); // beam profile at the target plane
50
  ch->SetBranchAddress("fYt.",&fYt);
51

    
52
  // TString outPutFileName;
53
  // outPutFileName.Form("/media/ivan/data/exp1904/analysed/novPars/beamDiagnostics/selected/h7_ct_%d_cut_newPars.root",nFile);
54
  // outPutFileName.Form("/mnt/data/exp1904/analysed/selected/h7/h7_ct_%d_cut.root",nFile);
55
  // outPutFileName.Form("temp1.root");
56
  // outPutFileName.Form("/mnt/data/exp1904/ERanalysis/tests/selected/selected.root",nFile);
57

    
58
  TFile *fw = new TFile(OutFile.Data(), "RECREATE");
59
  // TFile *fw = new TFile("test.root", "RECREATE");
60
  TTree *tw = new TTree("tree", "data");
61

    
62
  tw->Branch("trigger.",&trigger,"trigger/I");
63

    
64
  tw->Branch("F5.",&F5,"F5/F");
65
  tw->Branch("tF5.",&tF5,"tF5/F");
66
  tw->Branch("F3.",&F3,"F3/F");
67
  tw->Branch("tF3.",&tF3,"tF3/F");
68

    
69
  tw->Branch("tMWPC.",&tMWPC,"tMWPC/F");
70
  tw->Branch("wirex1.",&wirex1,"wirex1/F");
71
  tw->Branch("wirex2.",&wirex2,"wirex2/F");
72
  tw->Branch("wirey1.",&wirey1,"wirey1/F");
73
  tw->Branch("wirey2.",&wirey2,"wirey2/F");
74
 
75
  tw->Branch("x1c.",&x1c,"x1c/F");
76
  tw->Branch("y1c.",&y1c,"y1c/F");
77
  tw->Branch("x2c.",&x2c,"x2c/F");
78
  tw->Branch("y2c.",&y2c,"y2c/F"); 
79
  tw->Branch("fXt.",&fXt,"fXt/F");
80
  tw->Branch("fYt.",&fYt,"fYt/F"); 
81

    
82
  tw->Branch("he8","TLorentzVector",&he8);
83

    
84
  for(Int_t nentry=0;nentry<ch->GetEntries();nentry++) { 
85
  // for(Int_t nentry=0;nentry<10;nentry++) {     
86
    if(nentry%1000000==0) cout << "#ENTRY " << nentry << "#" << endl;
87

    
88
    ch->GetEntry(nentry);
89

    
90

    
91
    zeroVars();
92

    
93
    calculateBeam();
94

    
95
    tw->Fill();
96
  }
97
  fw->cd();
98
  tw->Write();
99
  fw->Close();
100

    
101
  return;
102
}
103

    
104
void zeroVars() {
105

    
106
  he8.SetXYZT(0,0,0,0);
107

    
108
}
109

    
110
void calculateBeam() {
111

    
112
  TVector3 dir;
113
  dir.SetXYZ(fXt-x1c,fYt-y1c,815.);
114
  // dir.SetXYZ(x2c-x1c,y2c-y1c,545.);  
115
  Double_t phi = dir.Phi();
116
  Double_t theta = dir.Theta();
117

    
118
  Double_t len = dir.Mag();
119

    
120
  Double_t mass = 8.406868788;
121

    
122
  Double_t velocity = 12320./(tF5-tF3 + 68.475);
123
  Double_t beta = sqrt(1 - (velocity*velocity/(299.792458*299.792458) ) );
124
  Double_t kinEnergy = mass*((1/beta) - 1);
125

    
126
  // cout << tF5-tF3 + 68.475 << " " << 1000*kinEnergy << endl;;
127

    
128
  // velocity = 12320./(tF5-tF3 + 68.475);
129
  // beta = sqrt(1 - (velocity*velocity/(299.792458*299.792458) ) );
130
  // kinEnergy = mass*((1/beta) - 1);
131

    
132
  // cout << 1000*kinEnergy << " ";
133

    
134
  // velocity = 12320./(tF5-tF3 + 68.475+1);
135
  // beta = sqrt(1 - (velocity*velocity/(299.792458*299.792458) ) );
136
  // kinEnergy = mass*((1/beta) - 1);
137

    
138
  // cout << 1000*kinEnergy << endl;
139

    
140
  Double_t momentum = sqrt(kinEnergy*kinEnergy + 2*kinEnergy*mass);
141

    
142
  momentum = TMath::Abs(momentum);
143

    
144
  he8.SetXYZM(momentum*TMath::Sin(theta)*TMath::Cos(phi), momentum*TMath::Sin(theta)*TMath::Sin(phi), momentum*TMath::Cos(theta) ,mass);
145

    
146
  return;
147
}