Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeFDCConstraintsFile.C
Go to the documentation of this file.
1 void MakeFDCConstraintsFile(TString rootFile = "hd_root.root"){
2 
3  // Select constraints
4  bool constrainPackageZ = false;
5  bool constrainPackageZTogether = false;
6  bool constrainWireCathodeAlignment = false;
7  bool constraint0 = false;
8 
9  ofstream outfile;
10  outfile.open("FDCConstraints.txt");
11 
12  if(constrainPackageZ){
13  for (unsigned int i=1; i<=4; i++){
14  outfile << "Constraint 0.0" << endl;
15  for (unsigned int j=1;j<=6;j++){
16  int indexOffset = 100000 + ((i-1)*6+j)*1000;
17  outfile << indexOffset+5 << " 1.0" << endl;
18  }
19  }
20  }
21 
22  if(constrainPackageZTogether){
23  for (unsigned int i=1; i<=4; i++){
24  for (unsigned int j=2;j<=6;j++){
25  outfile << "Constraint 0.0" << endl;
26  int indexOffset = 100000 + ((i-1)*6+j)*1000;
27  outfile << 100000 + ((i-1)*6+1)*1000 + 5<< " 1.0 " << endl;
28  outfile << indexOffset+5 << " -1.0" << endl;
29  }
30  }
31  }
32 
33  if(constraint0){
34  //t0
35  outfile <<"Constraint 0.0" << endl;
36  for (unsigned int i=1; i<=24; i++){
37  int indexOffset = 100000 + i*1000;
38  for(unsigned int j=901; j<=996;j++){
39  outfile << indexOffset + j << " 1.0 " << endl;
40  }
41  }
42  }
43 
44  for (unsigned int i=1; i<=24; i++){
45  int indexOffset = 100000 + i*1000;
46  int histIndex = i*1000;
47 
48  double angleOffset = ((i-1)%6)*TMath::Pi()/3.;
49  outfile << "Measurement 0.0 0.02" << endl;
50  outfile << indexOffset+1 << " " << sin(angleOffset) << endl;
51  outfile << indexOffset+100 << " " << sin(angleOffset+TMath::Pi()/2.) << endl;
52  outfile << "Measurement 0.0 0.02" << endl;
53  outfile << indexOffset+1 << " " << cos(angleOffset) << endl;
54  outfile << indexOffset+100 << " " << cos(angleOffset+TMath::Pi()/2.) << endl;
55  }
56 
57  if(constrainWireCathodeAlignment){
58  // Here we need to existing values to write the constraint
59  TFile *file = TFile::Open(rootFile);
60  TProfile *hFDCConstants;
61  file->GetObject("AlignmentConstants/FDCAlignmentConstants",hFDCConstants);
62 
63  for (unsigned int i=1; i<=24; i++){
64  // If this is true the cathode pitch is constrained such that the average pitch is unchanged
65  // but each of the sections can float. If this is false, the pitch is adjusted the same ammount for
66  // each foil.
67  bool averagePitch = true;
68 
69  int indexOffset = 100000 + i*1000;
70  int histIndex = i*1000;
71  double phiu = TMath::DegToRad()*75.0;
72  double phiv = TMath::Pi()-phiu;
73 
74  phiu+=hFDCConstants->GetBinContent(histIndex+103);
75  phiv+=hFDCConstants->GetBinContent(histIndex+104);
76 
77  double pu1 = hFDCConstants->GetBinContent(histIndex+200);
78  double pu2 = hFDCConstants->GetBinContent(histIndex+202);
79  double pu3 = hFDCConstants->GetBinContent(histIndex+204);
80 
81  double pv1 = hFDCConstants->GetBinContent(histIndex+205);
82  double pv2 = hFDCConstants->GetBinContent(histIndex+207);
83  double pv3 = hFDCConstants->GetBinContent(histIndex+209);
84 
85  double pu = (48.*(pu1+pu3)+96.*pu2)/192.; // Average strip pitch
86  double pv = (48.*(pv1+pv3)+96.*pv2)/192.; // Average strip pitch
87 
88  double sinphiu = sin(phiu);
89  double sinphiv = sin(phiv);
90  double sinphiumphiv = sin(phiu-phiv);
91  double cosphiumphiv = cos(phiu-phiv);
92 
93  if(averagePitch){
94  //Avg = 0
95  outfile << "Constraint 0.0" << endl;
96  outfile << indexOffset + 200 << " 48.0 " << endl;
97  outfile << indexOffset + 202 << " 96.0 " << endl;
98  outfile << indexOffset + 204 << " 48.0 " << endl;
99  outfile << "Constraint 0.0" << endl;
100  outfile << indexOffset + 205 << " 48.0 " << endl;
101  outfile << indexOffset + 207 << " 96.0 " << endl;
102  outfile << indexOffset + 209 << " 48.0 " << endl;
103  }
104  else{
105  //Equal
106  outfile << "Constraint 0.0" << endl;
107  outfile << indexOffset + 200 << " 1.0 " << endl;
108  outfile << indexOffset + 202 << " -1.0 " << endl;
109  outfile << "Constraint 0.0" << endl;
110  outfile << indexOffset + 200 << " 1.0 " << endl;
111  outfile << indexOffset + 204 << " -1.0 " << endl;
112  outfile << "Constraint 0.0" << endl;
113  outfile << indexOffset + 205 << " 1.0 " << endl;
114  outfile << indexOffset + 207 << " -1.0 " << endl;
115  outfile << "Constraint 0.0" << endl;
116  outfile << indexOffset + 205 << " 1.0 " << endl;
117  outfile << indexOffset + 209 << " -1.0 " << endl;
118  }
119  // Constrain Wire/cathode alignmnet
120  outfile << "Constraint 0.0" << endl;
121  //outfile << "Measurement 0.0 0.00001" << endl;
122  outfile << indexOffset + 200 << " " << sinphiv << endl;
123  outfile << indexOffset + 205 << " " << sinphiu <<endl;
124  outfile << indexOffset + 103 << " " << -1*(pv+pu*cosphiumphiv)*sinphiv/sinphiumphiv << endl;
125  outfile << indexOffset + 104 << " " << (pu+pv*cosphiumphiv)*sinphiu/sinphiumphiv << endl;
126  outfile << "Constraint 0.0" << endl;
127  //outfile << "Measurement 0.0 0.00001" << endl;
128  outfile << indexOffset + 200 << " " << sinphiv << endl;
129  outfile << indexOffset + 205 << " " << -sinphiu <<endl;
130  outfile << indexOffset + 103 << " " << (pv-pu*cosphiumphiv)*sinphiv/sinphiumphiv << endl;
131  outfile << indexOffset + 104 << " " << (pu-pv*cosphiumphiv)*sinphiu/sinphiumphiv << endl;
132  }
133  }
134 
135  outfile.close();
136 }
137 
138 
TFile * outfile
Definition: tw_corr.C:46
double sin(double)
void MakeFDCConstraintsFile(TString rootFile="hd_root.root")