Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
usm.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file usm.C
1 
2 #include <usmData.h>
3 
4  // Generic tile plots
5 TH2 * tcs = new TH2F("tcs","Clear side", 11, 0.5, 11.5, 9, 2., 20.);
6 TH2 * tfs = new TH2F("tfs","Fiber side", 11, 0.5, 11.5, 9, 2., 20.);
7 TH2 * fcr = new TH2F("fcr","Ratio Fiber-to-Clear", 11, 0.5, 11.5, 9, 2., 20.);
8 TH1 * AtoB = new TH1F("AtoB","Reproducibility of measurements", 20, -0.5, 0.5);
9 TH1 * AtoB1cs = new TH1F("AtoB1cs","Ratio of Before-After mesurements in the last(away from SiPM) row (Clear)", 20, 0.5, 1.5);
10 TH1 * AtoB2cs = new TH1F("AtoB2cs","Ratio of Before-After mesurements in the first(close to SiPM) row (Clear)", 20, 0.5, 1.5);
11 TH1 * AtoBtcs = new TH1F("AtoBtcs","Ratio of Before-After mesurements in the first&last rows (Clear)", 20, 0.5, 1.5);
12 TH1 * AtoB1fs = new TH1F("AtoB1fs","Ratio of Before-After mesurements in the last(away from SiPM) row) (Fiber)", 20, 0.5, 1.5);
13 TH1 * AtoB2fs = new TH1F("AtoB2fs","Ratio of Before-After mesurements in the first(close to SiPM) row (Fiber)", 20, 0.5, 1.5);
14 TH1 * AtoBtfs = new TH1F("AtoBtfs","Ratio of Before-After mesurements in the first&last rows (Fiber)", 20, 0.5, 1.5);
15 
16 
17 TH2 * tcsn = new TH2F("tcsn","Normalized A: LED on Clear side", 11, 0.5, 11.5, 9, 2., 20.);
18 //tcsn -> SetMaximum(5.);
19 TH2 * tfsn = new TH2F("tfsn","Normalized A: LED on Fiber side", 11, 0.5, 11.5, 9, 2., 20.);
20 //tfsn -> SetMaximum(5.);
21 TH2 * fcrn = new TH2F("fcrn","Ratio Fiber-to-Clear (both normalized)", 11, 0.5, 11.5, 9, 2., 20.);
22 //fcrn -> SetMaximum(5.);
23 // Amplitudes and ratios away and over the fiber
24 TH1 * cs_all = new TH1F("cs_all","Normalized A: LED on Clear side", 40, 0., 3.);
25 TH1 * cs_off = new TH1F("cs_off","Off-fiber A: clear(black) & fiber(red) sides", 40, 0., 3.);
26 TH1 * cs_onf = new TH1F("cs_onf","Norm. amp. on fiber, clear side", 40, 0., 3.);
27 TH1 * fs_off = new TH1F("fs_off","Norm. amp. off fiber, fiber side", 40, 0., 3.);
28 TH1 * fs_onf = new TH1F("fs_onf","Norm. amp. on fiber, fiber side", 40, 0., 3.);
29 TH1 * rfc_off = new TH1F("rfc_off","Norm. amp. Ratio: off fiber", 40, 0., 3.);
30 TH1 * rfc_onf = new TH1F("rfc_onf","Norm. amp. Ratio: on fiber", 40, 0., 3.);
31 
32 
33 TProfile * tavsdnfcs = new TProfile("tavsdnfcs","Amp vs Dist from exit - no fiber - clear side", 20,0.,20.,0.,2000.,"");
34 TProfile * tavsdfcs = new TProfile("tavsdfcs", "Amp vs Dist from exit - fiber - clear side", 20,0.,20.,0.,2000.,"");
35 TProfile * tavsdnffs = new TProfile("tavsdnffs","Amp vs Dist from exit - no fiber - fiber side", 20,0.,20.,0.,2000.,"");
36 TProfile * tavsdffs = new TProfile("tavsdffs", "Amp vs Dist from exit - fiber - fiber side", 20,0.,20.,0.,2000.,"");
37 
38  // DATA
39  // Clear side: lines 1-11
40  // line 12 - Y-positions
41  // Fiber side : lines 13-23
42  // col 0 - R(Y=3) = meas(A)/mes(B)
43  // col 1 - meas(B)
44  // col 2 - X (1-11, step 1)
45  // col 3 - meas(Y=3)
46  // col 4 - meas(Y=5)
47  // col .....
48  // col 11- meas(Y=19) - A
49  // col 12- meas(Y=19) - B
50  // col 13- R(Y=19) = meas(A)/mes(B)
51  // col 14-16 Comments
52 
53 Double_t fiber[11][9];
54 Int_t tileId;
55 TString token; TString Item;
56 TString Tokens[24][20];
57 Double_t value[24][20];
58 Double_t tData[2][11][9]; // Measurements on both sides of the tile
59 Double_t cData[2][11][2]; // Control data (repeated measurements) in the first and last Y-rows
60 Double_t xValue[2][11], yValue[9];
61 Double_t csNorm(0.), fsNorm(0.); // normalization coefficients for the clear and fiber sides
62 Int_t X, Y, loc, line, pos;
63 
64 // length along the fiber (from exit along decreasing Y then to small X then to large Y and then to the exit)
65 Double_t tPath(Int_t x, Int_t y){
66  // computes travel path to exit point (9,9)
67  Double_t dx = abs(x-exitX); Double_t dy = abs(y-exitY);
68  return sqrt(dx*dx+dy*dy);
69 }
70 
71 void init(){
72  for(Y = 0; Y<9; Y++) {for (X = 0; X<11; X++) fiber[X][Y] = 0.;}
73  for(Y = 0; Y<20; Y++) {for (X = 0; X<24; X++) value[X][Y] = 0.;}
74  for(int side =0; side<2; side++) {
75  for(Y = 0; Y<9; Y++) {for (X = 0; X<11; X++) tData[side][X][Y] = 0.;}
76  for(Y = 0; Y<2; Y++) {for (X = 0; X<11; X++) cData[side][X][Y] = 0.;}
77  for(X = 0; X<11; X++) xValue[side][X] = 0.;
78  }
79  for (Y = 0; Y<9; Y++) yValue[Y] = 0.;
80 }
81 
82 
83 
84 void tile(TString tDcsv){
85  init();
86  // Data are structured into lines with carriage returns ending those lines
87  // Each line is 20 positions full with few last missing in some (comments)
88  Int_t from = 0; Int_t nTok = 0; Int_t nCom = 0; Int_t lCom = 0; Int_t lItem = 0;
89  while ((lCom=tDcsv.Index(",",lItem))>=0||(nCom==0)) {
90  Int_t cr = tDcsv.Index("\n",lItem);
91  if(cr>=0&&cr<lCom) lCom = cr;
92  Item = tDcsv(lItem, lCom-lItem);
93  // if item length is nonzero - check for carriage return (EOL)
94  // Int_t cr = Item.First("\n");
95  // if(cr!=TString::kNPOS) Item.Remove(cr);
96  line = nCom/20;
97  pos = nCom%20;
98  Tokens[line][pos] = Item;
99  // if Item is numeric - convert it to Double_t
100  if(Tokens[line][pos].IsFloat()) value[line][pos] = Tokens[line][pos].Atof();
101  // std::cout<<"Item "<<nCom<<" lItem="<<lItem<<" lCom="<<lCom<<" line="<<line<<" pos="<<pos<<" Item="<<Item<<" Value="<<value[line][pos]<<std::endl;
102  if(cr==lCom) {
103  // cout<<"CR found nCom = "<<nCom<<endl;
104  nCom = ((nCom/20)+1)*20;
105  } else nCom++;
106  lItem = lCom+1;
107  }
108  tileId = Tokens[0][0].Atoi();
109  cout<<"tileID = "<<tileId<<endl;
110  if(tileId>1) for(loc=0; loc<99; loc++) dam[loc] = 0;
111  // Rearranging tile data
112  int nEntCs(0), nEntFs(0);
113  for(Y = 0; Y < 9; Y++) {
114  pos = Y + 3;
115  yValue[Y] = value[12][pos];
116  for (X = 0; X < 11; X++) {
117  // clear side
118  line = 11-X;
119  loc = Y*11 + X;
120  tData[0][X][Y] = value[line][pos];
121  if(Y==0) {
122  xValue[0][X] = value[line][2];
123  // repeated (control) measurements
124  cData[0][X][0] = value[line][1];
125  cData[0][X][1] = value[line][12];
126  // normalization for clear side
127  if(!fib[loc]&&tData[0][X][0]>0.) {nEntCs++; csNorm += tData[0][X][0];}
128  }
129  // fiber side
130  line = 12+X+1;
131  loc = Y*11 + X;
132  tData[1][X][Y] = value[line][pos];
133  if(Y==0) {
134  xValue[1][X] = value[line][2];
135  cData[1][X][0] = value[line][1];
136  cData[1][X][1] = value[line][12];
137  if(!fib[loc]&&tData[1][X][0]>0.) {nEntFs++; fsNorm += tData[1][X][0];}
138  }
139  }
140  }
141  cout<<"Norm cs "<<nEntCs<<"/"<<csNorm<<" Norm fs "<<nEntFs<<"/"<<fsNorm<<endl;
142  if(nEntCs) csNorm /= Double_t(nEntCs);
143  csNorm *= tScale[tileId-1];
144  if(nEntFs) fsNorm /= Double_t(nEntFs);
145  fsNorm *= tScale[tileId-1];
146  cout<<"Norm cs "<<nEntCs<<"/"<<csNorm<<" Norm fs "<<nEntFs<<"/"<<fsNorm<<endl;
147 
148  // Presentation
149  Double_t xExit = value[3][2]; // 91mm
150  Double_t yExit = value[12][11]; // 196mm
151  Double_t dx, dy, d;
152  // cout<<"xExit = "<<xExit<<" yExit = "<<yExit<<endl;
153  for(Y = 0; Y < 9; Y++) {
154  // distance to exit
155  pos = Y + 3;
156  // clear side
157  for (X = 0; X < 11; X++) {
158  line = 11-X;
159  loc = Y*11 + X;
160  dx = xValue[0][X] - xExit; dy = yValue[Y]- yExit;
161  Double_t d = sqrt(dx*dx+dy*dy);
162  // cout<<X<<" "<<Y<<" "<<xValue[0][X]<<" "<< yValue[Y]<<" tData "<< tData[0][X][Y]<<endl;
163  // std::cout<<"X/Y/loc/dam/fib/line/pos/V/tData "<<X<<"/"<<xValue[0][X]<<" "<<Y<<"/"<<yValue[Y]<<" "<<loc<<" D/F "<<dam[loc]<<"/"<<fib[loc]<<" "<<line<<" "<<pos<<" "<<value[line][pos]<<" tD "<<tData[0][X][Y]<<std::endl;
164  if(!dam[loc]) tcs -> Fill(xValue[0][X], yValue[Y], tData[0][X][Y]);
165  if(!dam[loc]&&csNorm>0.) tcsn -> Fill(xValue[0][X], yValue[Y], tData[0][X][Y]/csNorm);
166  if(!dam[loc]&&!fib[loc]) tavsdnfcs -> Fill(d, tData[0][X][Y]);
167  if(!dam[loc]&&fib[loc]) tavsdfcs -> Fill(d, tData[0][X][Y]);
168  }
169  // fiber side
170  for (X = 0; X<11; X++) {
171  line = 12+X+1;
172  loc = Y*11 + X;
173  dx = xValue[1][X] - xExit; dy = yValue[Y]- yExit;
174  Double_t d = sqrt(dx*dx+dy*dy);
175  // std::cout<<"X/Y/loc/dam/fib/line/pos/V "<<X<<" "<<Y<<" "<<loc<<" D/F "<<dam[loc]<<"/"<<fib[loc]<<" "<<line<<" "<<pos<<" "<<value[line][pos]<<std::endl;
176  if() tfs -> Fill(xValue[1][X],yValue[Y], tData[1][X][Y]);
177  if(fsNorm>0.) tfsn -> Fill(xValue[1][X],yValue[Y], tData[1][X][Y]/fsNorm);
178  if(!dam[loc]&&!fib[loc]) tavsdnffs -> Fill(d, tData[1][X][Y]);
179  if(!dam[loc]&&fib[loc]) tavsdffs -> Fill(d, tData[1][X][Y]);
180  }
181 
182  for (X = 0; X<11; X++) {
183  // clear to fiber raw ratio
184  loc = Y*11 + X;
185  if(tData[0][X][Y]>0.&&tData[1][X][Y]>0.) {
186  Double_t fcrat = tData[1][X][Y]/tData[0][X][Y];
187  if(!dam[loc]) fcr -> Fill(xValue[1][X],yValue[Y], fcrat);
188  if(!dam[loc]&&csNorm>0.&&fsNorm>0.) fcrn -> Fill(xValue[1][X],yValue[Y], fcrat/(fsNorm/csNorm));
189  }
190  Double_t repr(0);
191  if(Y==0) {
192  // reproducibility of measurements
193  if(cData[0][X][0]>0.&&tData[0][X][0]>0.) {
194  repr = 2.*(tData[0][X][0]-cData[0][X][0])/(tData[0][X][0]+cData[0][X][0]);
195  AtoB -> Fill(repr);
196  AtoB1cs -> Fill(tData[0][X][0]/cData[0][X][0]);
197  AtoBtcs -> Fill(tData[0][X][0]/cData[0][X][0]);
198  }
199  if(cData[0][X][1]>0.&&tData[0][X][8]>0.) {
200  repr = 2.*(tData[0][X][8]-cData[0][X][1])/(tData[0][X][8]+cData[0][X][1]);
201  AtoB -> Fill(repr);
202  AtoB2cs -> Fill(tData[0][X][8]/cData[0][X][1]);
203  AtoBtcs -> Fill(tData[0][X][8]/cData[0][X][1]);
204  }
205  if(cData[1][X][0]>0.&&tData[1][X][0]>0.) {
206  repr = 2.*(tData[1][X][0]-cData[1][X][0])/(tData[1][X][0]+cData[1][X][0]);
207  AtoB -> Fill(repr);
208  AtoB1fs -> Fill(tData[1][X][0]/cData[1][X][0]);
209  AtoBtfs -> Fill(tData[1][X][0]/cData[1][X][0]);
210  }
211  if(cData[1][X][1]>0.&&tData[1][X][8]>0.) {
212  repr = 2.*(tData[1][X][8]-cData[1][X][1])/(tData[1][X][8]+cData[1][X][1]);
213  AtoB -> Fill(repr);
214  AtoB -> Fill(tData[1][X][8]/cData[1][X][1]);
215  AtoB2fs -> Fill(tData[1][X][8]/cData[1][X][1]);
216  AtoBtfs -> Fill(tData[1][X][8]/cData[1][X][1]);
217  }
218  }
219  }
220  }
221  for (X = 0; X < 11; X++) {
222  for (Y = 0; Y < 9; Y++) {
223  loc = Y*11 + X;
224  Double_t vacsn = tcsn -> GetBinContent(X, Y);
225  Double_t vafsn = tfsn -> GetBinContent(X, Y);
226  Double_t vfcrn = fcrn -> GetBinContent(X, Y);
227  if(vacsn>0.) cs_all ->Fill(vacsn);
228  if(fib[loc]) {
229  if(vacsn>0.) cs_onf ->Fill(vacsn);
230  if(vafsn>0.) fs_onf ->Fill(vafsn);
231  if(vfcrn>0.) rfc_onf->Fill(vfcrn);
232  } else {
233  if(vacsn>0.) cs_off ->Fill(vacsn);
234  if(vafsn>0.) fs_off ->Fill(vafsn);
235  if(vfcrn>0.) rfc_off->Fill(vfcrn);
236  }
237 
238  }
239  }
240 
241 }
242 
243 TCanvas *tMap(NULL), * tDQ(NULL);
244 void plot(){
245  // Tile Response Map
246  if((tMap = (TCanvas *)(gROOT->FindObject("tMAP")))) delete tMap;
247  tMap = new TCanvas("tMap","Tile Response Map",200, 10, 600, 500);
248  // Tile Data Quality (sequential measurements)
249  tMap -> Divide(2,2,0.05,0.05,0);
250  tMap -> cd(1);
251  gStyle ->SetOptStat(0);
252  tcsn -> Draw("lego2");
253  tMap -> cd(2);
254  tfsn -> Draw("colz");
255  //tMap -> cd(3);
256  //fcrn -> Draw("lego2");
257  tMap -> cd(3);
258  //cs_off -> SetLineColor(2);
259  gStyle ->SetOptStat(111);
260  cs_all -> SetMaximum(20);
261  cs_all -> SetLineColor(1);
262  cs_all -> SetLineWidth(2);
263  cs_all -> Draw();
264  //cs_onf -> Draw("same");
265  tMap -> cd(4);
266  gStyle ->SetOptStat(0);
267  cs_off -> SetMaximum(20);
268  cs_off -> SetLineColor(1);
269  cs_off -> SetLineWidth(2);
270  cs_off -> Draw();
271  fs_off -> SetLineColor(2);
272  fs_off -> SetLineWidth(2);
273  fs_off -> Draw("same");
274  // tMap -> cd(6);
275  // rfc_off -> SetLineColor(2);
276  // rfc_off -> Draw();
277  // rfc_onf -> Draw("same");
278 
279  if((tDQ = (TCanvas *)(gROOT->FindObject("tDQ")))) delete tDQ;
280  if(!tDQ) tDQ = new TCanvas("tDQ","Tile Data Quality", 160, 10, 400, 300);
281  gStyle -> SetOptStat(0);
282  AtoB -> SetLineWidth(2);
283  AtoB -> Draw();
284  // AtoBtcs -> Draw("same");
285 
286 }
287 ;