Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:14:40

0001 
0002 #include <usmData.h>
0003 
0004   // Generic tile plots
0005 TH2 * tcs = new TH2F("tcs","Clear side", 11, 0.5, 11.5, 9, 2., 20.);  
0006 TH2 * tfs = new TH2F("tfs","Fiber side", 11, 0.5, 11.5, 9, 2., 20.);
0007 TH2 * fcr = new TH2F("fcr","Ratio Fiber-to-Clear", 11, 0.5, 11.5, 9, 2., 20.);
0008 TH1 * AtoB = new TH1F("AtoB","Reproducibility of measurements", 20, -0.5, 0.5);
0009 TH1 * AtoB1cs = new TH1F("AtoB1cs","Ratio of Before-After mesurements in the last(away from SiPM) row (Clear)", 20, 0.5, 1.5);
0010 TH1 * AtoB2cs = new TH1F("AtoB2cs","Ratio of Before-After mesurements in the first(close to SiPM) row (Clear)", 20, 0.5, 1.5);
0011 TH1 * AtoBtcs = new TH1F("AtoBtcs","Ratio of Before-After mesurements in the first&last rows (Clear)", 20, 0.5, 1.5);
0012 TH1 * AtoB1fs = new TH1F("AtoB1fs","Ratio of Before-After mesurements in the last(away from SiPM) row) (Fiber)", 20, 0.5, 1.5);
0013 TH1 * AtoB2fs = new TH1F("AtoB2fs","Ratio of Before-After mesurements in the first(close to SiPM) row (Fiber)", 20, 0.5, 1.5);
0014 TH1 * AtoBtfs = new TH1F("AtoBtfs","Ratio of Before-After mesurements in the first&last rows (Fiber)", 20, 0.5, 1.5);
0015 
0016 
0017 TH2 * tcsn = new TH2F("tcsn","Normalized A: LED on Clear side", 11, 0.5, 11.5, 9, 2., 20.);  
0018 //tcsn -> SetMaximum(5.);
0019 TH2 * tfsn = new TH2F("tfsn","Normalized A: LED on Fiber side", 11, 0.5, 11.5, 9, 2., 20.);
0020 //tfsn -> SetMaximum(5.);
0021 TH2 * fcrn = new TH2F("fcrn","Ratio Fiber-to-Clear (both normalized)", 11, 0.5, 11.5, 9, 2., 20.);
0022 //fcrn -> SetMaximum(5.);
0023 //  Amplitudes and ratios away and over the fiber
0024 TH1 * cs_all = new TH1F("cs_all","Normalized A: LED on Clear side",  40, 0., 3.);
0025 TH1 * cs_off = new TH1F("cs_off","Off-fiber A: clear(black) & fiber(red) sides", 40, 0., 3.);
0026 TH1 * cs_onf = new TH1F("cs_onf","Norm. amp. on fiber, clear side",  40, 0., 3.);
0027 TH1 * fs_off = new TH1F("fs_off","Norm. amp. off fiber, fiber side", 40, 0., 3.);
0028 TH1 * fs_onf = new TH1F("fs_onf","Norm. amp. on fiber, fiber side",  40, 0., 3.);
0029 TH1 * rfc_off = new TH1F("rfc_off","Norm. amp. Ratio: off fiber", 40, 0., 3.);
0030 TH1 * rfc_onf = new TH1F("rfc_onf","Norm. amp. Ratio: on fiber",  40, 0., 3.);
0031 
0032  
0033 TProfile * tavsdnfcs = new TProfile("tavsdnfcs","Amp vs Dist from exit - no fiber - clear side", 20,0.,20.,0.,2000.,"");
0034 TProfile * tavsdfcs  = new TProfile("tavsdfcs", "Amp vs Dist from exit - fiber - clear side", 20,0.,20.,0.,2000.,"");
0035 TProfile * tavsdnffs = new TProfile("tavsdnffs","Amp vs Dist from exit - no fiber - fiber side", 20,0.,20.,0.,2000.,"");
0036 TProfile * tavsdffs  = new TProfile("tavsdffs", "Amp vs Dist from exit - fiber - fiber side", 20,0.,20.,0.,2000.,"");
0037 
0038   // DATA
0039   // Clear side: lines 1-11
0040   // line 12 - Y-positions
0041   // Fiber side : lines 13-23
0042   // col 0 - R(Y=3) =  meas(A)/mes(B)
0043   // col 1 - meas(B)
0044   // col 2 - X (1-11, step 1)
0045   // col 3 - meas(Y=3)
0046   // col 4 - meas(Y=5)
0047   // col .....
0048   // col 11- meas(Y=19) - A
0049   // col 12- meas(Y=19) - B
0050   // col 13- R(Y=19) =  meas(A)/mes(B)
0051   // col 14-16 Comments
0052 
0053 Double_t fiber[11][9];
0054 Int_t    tileId;
0055 TString  token;  TString Item;
0056 TString  Tokens[24][20];
0057 Double_t value[24][20];
0058 Double_t tData[2][11][9];    //   Measurements on both sides of the tile
0059 Double_t cData[2][11][2];    //   Control data (repeated measurements) in the first and last Y-rows
0060 Double_t xValue[2][11], yValue[9];
0061 Double_t csNorm(0.), fsNorm(0.);  // normalization coefficients for the clear and fiber sides
0062 Int_t    X, Y, loc, line, pos;
0063 
0064 // length along the fiber  (from exit along decreasing Y then to small X then to large Y and then to the exit)
0065 Double_t tPath(Int_t x, Int_t y){
0066   // computes travel path to exit point (9,9)
0067   Double_t dx = abs(x-exitX); Double_t dy = abs(y-exitY);
0068   return sqrt(dx*dx+dy*dy);
0069 }
0070 
0071 void init(){
0072   for(Y = 0; Y<9;  Y++) {for (X = 0; X<11; X++) fiber[X][Y] = 0.;}
0073   for(Y = 0; Y<20; Y++) {for (X = 0; X<24; X++) value[X][Y] = 0.;}
0074   for(int side =0; side<2; side++) {
0075     for(Y = 0; Y<9;  Y++) {for (X = 0; X<11; X++) tData[side][X][Y] = 0.;}
0076     for(Y = 0; Y<2;  Y++) {for (X = 0; X<11; X++) cData[side][X][Y] = 0.;}
0077     for(X = 0; X<11; X++) xValue[side][X] = 0.;
0078   }
0079   for (Y = 0; Y<9;  Y++) yValue[Y]    = 0.;
0080 }
0081 
0082 
0083 
0084 void tile(TString tDcsv){
0085   init();
0086   //  Data are structured into lines with carriage returns ending those lines
0087   //  Each line is 20 positions full with few last missing in some (comments)
0088   Int_t   from = 0; Int_t nTok = 0; Int_t nCom = 0; Int_t lCom = 0; Int_t lItem = 0;
0089   while ((lCom=tDcsv.Index(",",lItem))>=0||(nCom==0)) {
0090     Int_t cr = tDcsv.Index("\n",lItem);
0091     if(cr>=0&&cr<lCom) lCom = cr;
0092     Item = tDcsv(lItem, lCom-lItem);
0093     //  if item length is nonzero - check for carriage return (EOL)
0094     //    Int_t cr = Item.First("\n");
0095     //    if(cr!=TString::kNPOS) Item.Remove(cr);
0096     line = nCom/20;
0097     pos  = nCom%20;
0098     Tokens[line][pos] = Item;
0099     // if Item is numeric - convert it to Double_t
0100     if(Tokens[line][pos].IsFloat()) value[line][pos] = Tokens[line][pos].Atof();
0101     //    std::cout<<"Item  "<<nCom<<"  lItem="<<lItem<<"  lCom="<<lCom<<"  line="<<line<<"  pos="<<pos<<"   Item="<<Item<<"  Value="<<value[line][pos]<<std::endl;
0102     if(cr==lCom)   {
0103       //      cout<<"CR found nCom = "<<nCom<<endl;
0104       nCom = ((nCom/20)+1)*20; 
0105     } else     nCom++;
0106     lItem = lCom+1;
0107   }
0108   tileId =  Tokens[0][0].Atoi();
0109   cout<<"tileID = "<<tileId<<endl;
0110   if(tileId>1) for(loc=0; loc<99; loc++) dam[loc] = 0;
0111   // Rearranging tile data
0112   int nEntCs(0), nEntFs(0);
0113   for(Y = 0; Y < 9; Y++) {
0114     pos = Y + 3; 
0115     yValue[Y] = value[12][pos];
0116     for (X = 0; X < 11; X++) {
0117       //  clear side
0118       line = 11-X;
0119       loc  = Y*11 + X;
0120       tData[0][X][Y] = value[line][pos];
0121       if(Y==0)  {
0122     xValue[0][X] = value[line][2];
0123     // repeated (control)  measurements 
0124     cData[0][X][0] = value[line][1];
0125     cData[0][X][1] = value[line][12];
0126     // normalization for clear side
0127     if(!fib[loc]&&tData[0][X][0]>0.) {nEntCs++; csNorm += tData[0][X][0];}
0128       }
0129       //  fiber side
0130       line = 12+X+1;
0131       loc  = Y*11 + X;
0132       tData[1][X][Y] = value[line][pos];
0133       if(Y==0)  {
0134     xValue[1][X]   = value[line][2];
0135     cData[1][X][0] = value[line][1];
0136     cData[1][X][1] = value[line][12];
0137     if(!fib[loc]&&tData[1][X][0]>0.) {nEntFs++; fsNorm += tData[1][X][0];}
0138       }
0139     }
0140   }
0141   cout<<"Norm cs "<<nEntCs<<"/"<<csNorm<<"  Norm fs "<<nEntFs<<"/"<<fsNorm<<endl;
0142   if(nEntCs) csNorm /= Double_t(nEntCs);
0143   csNorm *= tScale[tileId-1];
0144   if(nEntFs) fsNorm /= Double_t(nEntFs);
0145   fsNorm *= tScale[tileId-1];
0146   cout<<"Norm cs "<<nEntCs<<"/"<<csNorm<<"  Norm fs "<<nEntFs<<"/"<<fsNorm<<endl;
0147 
0148   // Presentation
0149   Double_t xExit = value[3][2];        //  91mm
0150   Double_t yExit = value[12][11];      // 196mm
0151   Double_t dx, dy, d;
0152   //  cout<<"xExit = "<<xExit<<"  yExit = "<<yExit<<endl;
0153   for(Y = 0; Y < 9; Y++) {
0154     // distance to exit
0155     pos = Y + 3; 
0156     // clear side
0157     for (X = 0; X < 11; X++) {
0158       line = 11-X;
0159       loc  = Y*11 + X;
0160       dx   = xValue[0][X] - xExit;  dy = yValue[Y]- yExit;
0161       Double_t d  = sqrt(dx*dx+dy*dy);
0162       //      cout<<X<<"  "<<Y<<"  "<<xValue[0][X]<<"  "<< yValue[Y]<<" tData "<< tData[0][X][Y]<<endl;
0163       //      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;
0164       if(!dam[loc]) tcs -> Fill(xValue[0][X], yValue[Y], tData[0][X][Y]);
0165       if(!dam[loc]&&csNorm>0.) tcsn -> Fill(xValue[0][X], yValue[Y], tData[0][X][Y]/csNorm);
0166       if(!dam[loc]&&!fib[loc])  tavsdnfcs -> Fill(d, tData[0][X][Y]);
0167       if(!dam[loc]&&fib[loc])   tavsdfcs  -> Fill(d, tData[0][X][Y]); 
0168     }
0169     //  fiber side
0170     for (X = 0; X<11; X++) {
0171       line = 12+X+1;
0172       loc  = Y*11 + X;
0173       dx   = xValue[1][X] - xExit;  dy = yValue[Y]- yExit;
0174       Double_t d  = sqrt(dx*dx+dy*dy);
0175       //      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;
0176       if(/*!dam[loc]*/) tfs -> Fill(xValue[1][X],yValue[Y], tData[1][X][Y]);
0177       if(/*!dam[loc]&&*/fsNorm>0.) tfsn -> Fill(xValue[1][X],yValue[Y], tData[1][X][Y]/fsNorm);
0178       if(!dam[loc]&&!fib[loc])     tavsdnffs -> Fill(d, tData[1][X][Y]); 
0179       if(!dam[loc]&&fib[loc])      tavsdffs  -> Fill(d, tData[1][X][Y]); 
0180     }
0181 
0182     for (X = 0; X<11; X++) {
0183       //  clear to fiber raw ratio
0184       loc  = Y*11 + X;
0185       if(tData[0][X][Y]>0.&&tData[1][X][Y]>0.) {
0186     Double_t fcrat  = tData[1][X][Y]/tData[0][X][Y];
0187     if(!dam[loc])   fcr -> Fill(xValue[1][X],yValue[Y], fcrat);
0188     if(!dam[loc]&&csNorm>0.&&fsNorm>0.) fcrn -> Fill(xValue[1][X],yValue[Y], fcrat/(fsNorm/csNorm));
0189       }
0190       Double_t repr(0);
0191       if(Y==0) {
0192     //  reproducibility of measurements
0193     if(cData[0][X][0]>0.&&tData[0][X][0]>0.) {
0194       repr   = 2.*(tData[0][X][0]-cData[0][X][0])/(tData[0][X][0]+cData[0][X][0]);
0195       AtoB    -> Fill(repr);
0196       AtoB1cs -> Fill(tData[0][X][0]/cData[0][X][0]);
0197       AtoBtcs -> Fill(tData[0][X][0]/cData[0][X][0]);
0198     }
0199     if(cData[0][X][1]>0.&&tData[0][X][8]>0.) {
0200       repr   = 2.*(tData[0][X][8]-cData[0][X][1])/(tData[0][X][8]+cData[0][X][1]);
0201       AtoB    -> Fill(repr);
0202       AtoB2cs -> Fill(tData[0][X][8]/cData[0][X][1]);
0203       AtoBtcs -> Fill(tData[0][X][8]/cData[0][X][1]);
0204     }
0205     if(cData[1][X][0]>0.&&tData[1][X][0]>0.) {
0206       repr   = 2.*(tData[1][X][0]-cData[1][X][0])/(tData[1][X][0]+cData[1][X][0]);
0207       AtoB    -> Fill(repr);
0208       AtoB1fs -> Fill(tData[1][X][0]/cData[1][X][0]);
0209       AtoBtfs -> Fill(tData[1][X][0]/cData[1][X][0]);
0210     }
0211     if(cData[1][X][1]>0.&&tData[1][X][8]>0.) {        
0212       repr   = 2.*(tData[1][X][8]-cData[1][X][1])/(tData[1][X][8]+cData[1][X][1]);
0213       AtoB    -> Fill(repr);
0214       AtoB    -> Fill(tData[1][X][8]/cData[1][X][1]);
0215       AtoB2fs -> Fill(tData[1][X][8]/cData[1][X][1]);
0216       AtoBtfs -> Fill(tData[1][X][8]/cData[1][X][1]);
0217     }
0218       }
0219     }
0220   }
0221   for (X = 0; X < 11; X++) {
0222     for (Y = 0; Y < 9;  Y++) {
0223       loc  = Y*11 + X;
0224       Double_t vacsn = tcsn -> GetBinContent(X, Y);
0225       Double_t vafsn = tfsn -> GetBinContent(X, Y);
0226       Double_t vfcrn = fcrn -> GetBinContent(X, Y);
0227       if(vacsn>0.) cs_all ->Fill(vacsn);
0228       if(fib[loc]) {
0229     if(vacsn>0.) cs_onf ->Fill(vacsn);
0230     if(vafsn>0.) fs_onf ->Fill(vafsn);
0231     if(vfcrn>0.) rfc_onf->Fill(vfcrn);
0232       } else {
0233     if(vacsn>0.) cs_off ->Fill(vacsn);
0234     if(vafsn>0.) fs_off ->Fill(vafsn);
0235     if(vfcrn>0.) rfc_off->Fill(vfcrn);
0236       }
0237 
0238     }
0239   }
0240 
0241 }
0242 
0243 TCanvas  *tMap(NULL), * tDQ(NULL);
0244 void plot(){
0245   //  Tile Response Map
0246   if((tMap = (TCanvas *)(gROOT->FindObject("tMAP")))) delete tMap;
0247   tMap = new TCanvas("tMap","Tile Response Map",200, 10, 600, 500);
0248   //  Tile Data Quality (sequential measurements)
0249   tMap -> Divide(2,2,0.05,0.05,0);
0250   tMap -> cd(1);
0251   gStyle ->SetOptStat(0);
0252   tcsn -> Draw("lego2");
0253   tMap -> cd(2);
0254   tfsn -> Draw("colz");
0255   //tMap -> cd(3);
0256   //fcrn -> Draw("lego2");
0257   tMap -> cd(3);
0258   //cs_off -> SetLineColor(2);
0259   gStyle ->SetOptStat(111);
0260   cs_all -> SetMaximum(20);
0261   cs_all -> SetLineColor(1);
0262   cs_all -> SetLineWidth(2);
0263   cs_all -> Draw();
0264   //cs_onf -> Draw("same");
0265   tMap -> cd(4);
0266   gStyle ->SetOptStat(0);
0267   cs_off -> SetMaximum(20);
0268   cs_off -> SetLineColor(1);
0269   cs_off -> SetLineWidth(2);
0270   cs_off -> Draw();
0271   fs_off -> SetLineColor(2);
0272   fs_off -> SetLineWidth(2);
0273   fs_off -> Draw("same");
0274   //  tMap -> cd(6);
0275   //  rfc_off -> SetLineColor(2);
0276   //  rfc_off -> Draw();
0277   //  rfc_onf -> Draw("same");
0278 
0279   if((tDQ  = (TCanvas *)(gROOT->FindObject("tDQ"))))  delete tDQ;
0280   if(!tDQ)  tDQ = new TCanvas("tDQ","Tile Data Quality",  160, 10, 400, 300);
0281   gStyle -> SetOptStat(0);
0282   AtoB  -> SetLineWidth(2);
0283   AtoB  -> Draw();
0284   //  AtoBtcs -> Draw("same");
0285 
0286 }
0287 ;