Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ApplyFDCOffsets.C
Go to the documentation of this file.
1 // Script to get current values of the offsets from the alignment root file, and shift them according to the MILLEPEDE result.
2 #include <map>
3 #include <fstream>
4 #include <iostream>
5 #include <string>
6 #include "TProfile.h"
7 #include "TFile.h"
8 
9 using namespace std;
10 
11 void ApplyFDCOffsets(TString rootFile = "hd_root.root", TString pedeOutFile = "millepede.res"){
12 
13  TFile *file = TFile::Open(rootFile);
14  TProfile *hFDCConstants;
15  file->GetObject("AlignmentConstants/FDCAlignmentConstants",hFDCConstants);
16 
17  ifstream pedeResult;
18  pedeResult.open(pedeOutFile.Data());
19 
20  map < int, double> resultMap;
21 
22  bool firstLine = true;
23  string line;
24  while (getline(pedeResult,line)){
25  if (firstLine){
26  firstLine = false;
27  continue;
28  }
29  int index; double value;
30  istringstream iss(line);
31  iss >> index >> value;
32 
33  resultMap[index]=value;
34  }
35 
36  // Cell offsets
37  // Indices are 101001, 101100 etc...
38  ofstream outFile;
39  outFile.open("cell_offsets.txt");
40  for (unsigned int i = 1; i<=24; i++){
41  int histIndex = i*1000;
42  int pedeIndex = 100000 + i*1000;
43  outFile << resultMap[pedeIndex + 1] + hFDCConstants->GetBinContent(histIndex+1) << " " ;
44  outFile << resultMap[pedeIndex + 100] + hFDCConstants->GetBinContent(histIndex+100) << endl ;
45  }
46  outFile.close();
47 
48  // Cathode Offsets
49  // Indices are 101, 102, 103, 104
50  outFile.open("cathode_alignment.txt");
51  for (unsigned int i = 1; i<=24; i++){
52  int histIndex = i*1000;
53  int pedeIndex = 100000 + i*1000;
54  outFile << resultMap[pedeIndex + 103] + hFDCConstants->GetBinContent(histIndex+103) << " " ;//dPhiU
55  outFile << resultMap[pedeIndex + 101] + hFDCConstants->GetBinContent(histIndex+101) << " " ;//dU
56  outFile << resultMap[pedeIndex + 104] + hFDCConstants->GetBinContent(histIndex+104) << " " ;//dPhiV
57  outFile << resultMap[pedeIndex + 102] + hFDCConstants->GetBinContent(histIndex+102) << endl ;//dV
58  }
59  outFile.close();
60 
61  // Strip Pitches
62  // Indices are 200...209
63  outFile.open("strip_pitches.txt");
64  for (unsigned int i = 1; i<=24; i++){
65  int histIndex = i*1000;
66  int pedeIndex = 100000 + i*1000;
67  outFile << resultMap[pedeIndex + 200] + hFDCConstants->GetBinContent(histIndex+200) << " " ;
68  outFile << resultMap[pedeIndex + 201] + hFDCConstants->GetBinContent(histIndex+201) << " " ;
69  outFile << resultMap[pedeIndex + 202] + hFDCConstants->GetBinContent(histIndex+202) << " " ;
70  outFile << resultMap[pedeIndex + 203] + hFDCConstants->GetBinContent(histIndex+203) << " " ;
71  outFile << resultMap[pedeIndex + 204] + hFDCConstants->GetBinContent(histIndex+204) << " " ;
72  outFile << resultMap[pedeIndex + 205] + hFDCConstants->GetBinContent(histIndex+205) << " " ;
73  outFile << resultMap[pedeIndex + 206] + hFDCConstants->GetBinContent(histIndex+206) << " " ;
74  outFile << resultMap[pedeIndex + 207] + hFDCConstants->GetBinContent(histIndex+207) << " " ;
75  outFile << resultMap[pedeIndex + 208] + hFDCConstants->GetBinContent(histIndex+208) << " " ;
76  outFile << resultMap[pedeIndex + 209] + hFDCConstants->GetBinContent(histIndex+209) << endl;
77  }
78  outFile.close();
79 
80  // Wire Alignment
81  // Indices are 2
82  outFile.open("wire_alignment.txt");
83  for (unsigned int i = 1; i<=24; i++){
84  int histIndex = i*1000;
85  int pedeIndex = 100000 + i*1000;
86  outFile << "0.0 0.0 " << resultMap[pedeIndex + 5] + hFDCConstants->GetBinContent(histIndex+5) << endl;
87  }
88  outFile.close();
89 
90  outFile.open("cell_rotations.txt");
91  for (unsigned int i = 1; i<=24; i++){
92  int histIndex = i*1000;
93  int pedeIndex = 100000 + i*1000;
94  outFile << resultMap[pedeIndex + 2] + hFDCConstants->GetBinContent(histIndex+2) << " " ;
95  outFile << resultMap[pedeIndex + 3] + hFDCConstants->GetBinContent(histIndex+3) << " " ;
96  outFile << resultMap[pedeIndex + 4] + hFDCConstants->GetBinContent(histIndex+4) << endl;
97  }
98  outFile.close();
99 
100  for (unsigned int i = 1; i<=4; i++){
101  outFile.open(Form("t0_package%i.txt",i));
102  for (unsigned int j=1; j<=6;j++){
103  for (unsigned int k = 1; k<= 96; k++){
104  int histIndex = ((i-1)*4+j)*1000 + 900;
105  int pedeIndex = 100000 + histIndex;
106  outFile << hFDCConstants->GetBinContent(histIndex+k) - resultMap[pedeIndex + k]<< " " ;
107  }
108  outFile << endl;
109  }
110  outFile.close();
111  }
112  //gains
113  for (unsigned int i = 1; i<=4; i++){
114  outFile.open(Form("gains_package%i.txt",i));
115  for (unsigned int j=1; j<=6;j++){
116  for (unsigned int k = 1; k<= 216; k++){
117  int histIndex = ((i-1)*4+j)*1000 + 300;
118  int pedeIndex = 100000 + histIndex;
119  outFile << resultMap[pedeIndex + k] + hFDCConstants->GetBinContent(histIndex+k) << " " ;
120  }
121  outFile << endl;
122  for (unsigned int k = 1; k<= 216; k++){
123  int histIndex = ((i-1)*4+j)*1000 + 600;
124  int pedeIndex = 100000 + histIndex;
125  outFile << resultMap[pedeIndex + k] + hFDCConstants->GetBinContent(histIndex+k) << " " ;
126  }
127  outFile << endl;
128  }
129  outFile.close();
130  }
131 }
TFile * outFile
Definition: FitGains.C:15
static char index(char c)
Definition: base64.cpp:115
void ApplyFDCOffsets(TString rootFile="hd_root.root", TString pedeOutFile="millepede.res")