1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliFieldReader.h"
19 #include "AliMagFMaps.h"
25 #include <TMultiGraph.h>
27 #include <TObjString.h>
31 ClassImp(AliFieldReader)
34 //_______________________________________________________________________
35 AliFieldReader::AliFieldReader()
48 //_______________________________________________________________________
49 AliFieldReader::~AliFieldReader()
56 //_______________________________________________________________________
57 void AliFieldReader::Init()
60 // Initialize the reader
63 fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 2);
65 fCatalogue = fopen(fCatalogueName, "r");
68 fHtmlMain = fopen("bmap.html", "w");
69 MakeHtmlHeaderMain(fHtmlMain);
74 void AliFieldReader::ReadMap()
77 // Read the measured dipole field map
80 Float_t zA[450], bxzA[200], byzA[200], bzzA[200], bxzcA[200], byzcA[200], bzzcA[200];
81 Float_t yA[450], bxyA[200], byyA[200], bzyA[200], bxycA[200], byycA[200], bzycA[200];
82 Float_t xA[450], bxxA[200], byxA[200], bzxA[200], bxxcA[200], byxcA[200], bzxcA[200];
87 Float_t xpos, ypos, zpos;
90 Float_t h[3], x[3], b[3];
104 fMap = new TNtuple("Field Map", "Map",
105 "x:y:z:ix:iy:iz:bx:by:bz:bxc:byc:bzc:ifile:ireg:irot:temp:cal", 4000);
112 while ((fgets(fLine, 255, fCatalogue)) != NULL && ifiles <= 2000) {
114 if (strncmp(fLine,"#HEADER", 7) == 0) {
115 iret = sscanf(&fLine[7],"%f", &fZStart);
120 // if (ifiles != 87) continue;
122 iret = sscanf(fLine, "%s", fileName);
123 printf("Reading File %s\n", fileName);
126 TString* tsFile = new TString(fileName);
127 TObjArray * tokens = tsFile->Tokenize(".");
128 const char* runName = (((TObjString*) tokens->At(0))->GetString()).Data();
129 FILE* file = fopen(fileName, "r");
141 TMultiGraph* bxzmg = new TMultiGraph("bxzmg", "B_{x}");
142 TMultiGraph* byzmg = new TMultiGraph("byzmg", "B_{y}");
143 TMultiGraph* bzzmg = new TMultiGraph("bzzmg", "B_{z}");
144 while ((fgets(sLine, 255, file)) != NULL) {
147 if (strncmp(sLine," Current", 8) == 0) {
149 iret = sscanf(&sLine[9],"%f", ¤t);
150 printf("Current %f \n", current);
152 fPolarity = current / 6000.;
154 if (strncmp(sLine," z", 2) == 0) {
157 iret = sscanf(&sLine[3],"%f %f %d", &zmin, &zmax, &nsteps);
158 printf("zmin zmax %13.3f %13.3f %13.3f\n",
159 zmin, zmax, TMath::Abs(zmax - zmin)/Float_t(nsteps));
160 zmax = TMath::Max(zmin, zmax);
161 stepsz = TMath::Abs(zmax - zmin)/Float_t(nsteps);
164 if (strncmp(sLine," X position", 11) == 0)
167 TString* tsLine = new TString(sLine);
168 TObjArray * tokens = tsLine->Tokenize("=");
169 string = ((TObjString*) tokens->At(1))->GetString();
170 iret = sscanf(string.Data(), "%f", &xpos);
171 string = ((TObjString*) tokens->At(2))->GetString();
172 iret = sscanf(string.Data(), "%f", &ypos);
173 string = ((TObjString*) tokens->At(3))->GetString();
174 iret = sscanf(string.Data(), "%d", &iboxpos);
177 printf("This file is for x = %13.3f y = %13.3f Box Position %1d\n", xpos, ypos, iboxpos);
182 if (strncmp(sLine," R Z-pos",8) == 0)
184 iret = sscanf(&sLine[8],"%e", &zpos);
191 if (strncmp(sLine,"C",1) == 0) {
194 iret = sscanf(&sLine[2],"%d %f %f %f %f %d", &ireg, &h[0], &h[1], &h[2], &temp, &ires);
196 // fix for address 115
198 if (ireg == 115) ic115++;
199 if (ic115 == 2 && ireg == 115) ireg = 119;
203 Float_t bx = 0., by = 0., bz = 0.;
204 Int_t jx = fRegMap[ireg][0];
205 Int_t jy = fRegMap[ireg][1];
206 Int_t jz = fRegMap[ireg][2];
212 dx = -0.36 + jx * fDd;
218 dx = 0.36 + jy * fDd;
219 dy = -(-0.36 + jx * fDd);
224 dx = 0.36 - jx * fDd;
230 dx = -0.36 - jy * fDd;
231 dy = -(0.36 - jx * fDd);
238 if (iboxpos == 1 || iboxpos == 3) {
246 Float_t dz = (jz == 0)? fDz/2. : - fDz/2.;
250 Float_t xc = xpos + dx;
251 Float_t yc = ypos + dy;
256 x[2] = - (-zpos * 100. + fZStart + dz);
265 xnt[ 2] = -x[2] / 100.;
266 xnt[ 3] = Float_t (jx);
267 xnt[ 4] = Float_t (jy);
268 xnt[ 5] = Float_t (jz);
275 xnt[12] = Float_t (ifiles);
276 xnt[13] = Float_t (ireg);
277 xnt[14] = Float_t(iboxpos);
279 xnt[16] = Float_t(ires);
287 if (jy != -1 && jz == 1 && jy == 0 && izz == 40){
294 bxycA[jx] = b[0] / 10.;
295 byycA[jx] = b[1] / 10.;
296 bzycA[jx] = b[2] / 10.;
300 if (jy != -1 && jz == 1 && jy == 0 && izz == 1){
307 bxxcA[jx] = b[0] / 10.;
308 byxcA[jx] = b[1] / 10.;
309 bzxcA[jx] = b[2] / 10.;
316 // printf("Field %f %f %f %f %f %f \n", x[0], x[1], x[2], b[0], b[1] , b[2]);
319 bdlc += stepsz * b[0];
325 bxzcA[iz] = b[0] / 10.;
326 byzcA[iz] = b[1] / 10.;
327 bzzcA[iz] = b[2] / 10.;
333 gStyle->SetOptStat(0);
335 sprintf(title, "File#: %5d, X = %13.2f m , Y = %13.2f m, Box Orientation: %2d", ifiles, xpos, ypos, iboxpos);
336 TCanvas* c2 = new TCanvas("c2", title, 1200, 800);
339 TGraph* bxg = new TGraph(iz, zA, bxzA);
340 TGraph* bxcg = new TGraph(iz, zA, bxzcA);
341 bxcg->SetLineColor(2);
345 bxzmg->GetHistogram()->SetXTitle("z[m]");
346 bxzmg->GetHistogram()->SetYTitle("B_{x} [T]");
350 TGraph* byg = new TGraph(iz, zA, byzA);
351 TGraph* bycg = new TGraph(iz, zA, byzcA);
352 bycg->SetLineColor(2);
356 byzmg->GetHistogram()->SetXTitle("z[m]");
357 byzmg->GetHistogram()->SetYTitle("B_{y} [T]");
361 TGraph* bzg = new TGraph(iz, zA, bzzA);
362 TGraph* bzcg = new TGraph(iz, zA, bzzcA);
363 bzcg->SetLineColor(2);
367 bzzmg->GetHistogram()->SetXTitle("z[m]");
368 bzzmg->GetHistogram()->SetYTitle("B_{z} [T]");
373 sprintf(pictFile, "%s.gif", runName);
374 c2->SaveAs(pictFile);
379 sprintf(htmlFile, "%s.html", runName);
380 FILE* chtml = fopen(htmlFile, "w");
381 MakeHtmlHeaderPict(chtml);
382 MakeHtmlPict(chtml, pictFile);
383 MakeHtmlTableEntry(fHtmlMain, fileName, htmlFile, xpos, ypos, iboxpos, bdl, ifiles);
387 printf("Bdl [Tm] %f %f \n", 2. * bdl, 2 * bdlc / 10.);
389 MakeHtmlTrailor(fHtmlMain);
390 TFile* out = new TFile("fmap.root", "recreate");
395 void AliFieldReader::ReadMapSolenoid(){
397 // Read map for solenoid measurement
399 Float_t phiA[450], bzPhiA[200], brPhiA[200], btPhiA[200], bbPhiA[200];
400 Float_t bzcPhiA[200], brcPhiA[200], btcPhiA[200], bbcPhiA[200];
404 Float_t zpos, phipos, skewing, temp;
407 Float_t h[3], x[3], b[3];
412 ReadRegisterMapSolenoid();
413 fMap = new TNtuple("Field Map", "Map",
414 "r:phi:z:br:bt:bz:brc:btc:bzc:ifile:ireg:temp:cal:arm", 4000);
421 while ((fgets(fLine, 255, fCatalogue)) != NULL && ifiles <= 2000) {
423 if (strncmp(fLine,"#HEADER", 7) == 0) {
424 iret = sscanf(&fLine[7],"%f", &fZStart);
430 iret = sscanf(fLine, "%s", fileName);
431 printf("Reading File %s\n", fileName);
434 TString* tsFile = new TString(fileName);
435 TObjArray * tokens = tsFile->Tokenize(".");
436 Int_t n = tokens->GetEntries();
437 char* runName = new char[256];
438 sprintf(runName, "%s", (((TObjString*) tokens->At(0))->GetString()).Data());
440 for (Int_t i = 1; i < n-1; i++)
442 sprintf(runName, "%s.%s",
443 runName, (((TObjString*) tokens->At(i))->GetString()).Data());
446 FILE* file = fopen(fileName, "r");
455 TMultiGraph* bxzmg = new TMultiGraph("bxzmg", "B_{z}");
456 TMultiGraph* byzmg = new TMultiGraph("byzmg", "B_{r}");
457 TMultiGraph* bzzmg = new TMultiGraph("bzzmg", "B_{t}");
458 TMultiGraph* bbmg = new TMultiGraph("bbmg", "|B|");
460 while ((fgets(sLine, 255, file)) != NULL) {
461 if (strncmp(sLine," z", 2) == 0) {
463 iret = sscanf(&sLine[3],"%f %f %d", &zmin, &zmax, &nsteps);
464 printf("zmin zmax %13.3f %13.3f %13.3f\n",
465 zmin, zmax, TMath::Abs(zmax - zmin)/Float_t(nsteps));
467 if (strncmp(sLine," R\tPOSITION NUMBER", 18) == 0)
470 // Current z-position
472 TString* tsLine = new TString(sLine);
473 TObjArray * tokens = tsLine->Tokenize("=");
474 string = ((TObjString*) tokens->At(1))->GetString();
475 iret = sscanf(string.Data(), "%f", &zpos);
476 printf("POSITION NUMBER Z: %f\n", zpos);
482 if (strncmp(sLine," SKEWING ON Z:", 14) == 0)
486 iret = sscanf(&sLine[14],"%f", &skewing);
487 printf("SKEWING ON Z: %f\n", skewing);
491 if (strncmp(sLine,"Phi", 3) == 0)
493 Float_t phiStart, phiStop;
495 iret = sscanf(&sLine[3],"%f %f", &phiStart, &phiStop);
497 printf("phiStart phiStop %f %f\n", phiStart, phiStop);
502 if (strncmp(sLine," R\tPhi-Angle",12) == 0)
504 iret = sscanf(&sLine[12],"%e", &phipos);
510 if (strncmp(sLine,"C",1) == 0) {
513 iret = sscanf(&sLine[2],"%d %f %f %f %f %d", &ireg, &h[0], &h[1], &h[2], &temp, &ical);
516 Int_t ir = fRegMap[ireg][0];
517 Int_t ia = fRegMap[ireg][1];
522 rpos = 0.2295 + ir * 0.16;
524 if (ireg == 81) rpos = 0.2295;
525 if (ireg == 59) rpos = 1.0295;
526 if (ireg == 142) rpos = 2.1495;
527 if (ireg == 180) rpos = 3.1095;
528 if (ireg == 69) rpos = 4.2295;
530 // if (ireg == 55) rpos = 0.2295;
531 //if (ireg == 195) rpos = 1.0295;
532 //if (ireg == 129) rpos = 2.1495;
533 //if (ireg == 167) rpos = 3.1095;
534 //if (ireg == 142) rpos = 4.2295;
537 Float_t phi = phipos;
540 if (phi > 360.) phi -= 360.;
543 phi = - phi * TMath::Pi() / 180.;
544 Float_t xpos = rpos * TMath::Cos(phi);
545 Float_t ypos = rpos * TMath::Sin(phi);
546 x[0] = - xpos * 100.;
548 x[2] = -400. + zpos * 100.;
551 Float_t phi0 = TMath::Pi() - phi;
553 Float_t brc = b[0] * TMath::Cos(phi0) + b[1] * TMath::Sin(phi0);
554 Float_t btc = - b[0] * TMath::Sin(phi0) + b[1] * TMath::Cos(phi0);
561 fMap->Fill(rpos, -phi, -(615.5 - fZStart) / 100. + zpos, h[2], -h[1], h[0], brc, btc, bzc, ifiles, ireg, temp, Float_t(ical), Int_t(ia));
564 printf("Field (Bx, By, Bz) at position %d: %13.3f %13.3f %13.3f %13.3f %13.3f %13.3f %5d\n",
565 ipos, zpos, rpos, phipos, h[0], h[1], h[2], ia);
571 bbPhiA[iA] = TMath::Sqrt(h[0] * h[0] + h[1] * h[1] + h[2] * h[2]);
575 bbcPhiA[iA] = TMath::Sqrt(brc * brc + bzc * bzc + btc * btc);
582 gStyle->SetOptStat(0);
584 sprintf(title, "Z = %13.2f m , Phi = %13.2f m", zpos, phipos);
587 TCanvas* c2 = new TCanvas("c2", title, 1200, 800);
591 TGraph* bzg = new TGraph(iA, phiA, bzPhiA);
592 TGraph* bzcg = new TGraph(iA, phiA, bzcPhiA);
593 bzcg->SetLineColor(2);
597 bxzmg->GetHistogram()->SetXTitle("#phi[rad]");
598 bxzmg->GetHistogram()->SetYTitle("B_{z} [T]");
602 TGraph* brg = new TGraph(iA, phiA, brPhiA);
603 TGraph* brcg = new TGraph(iA, phiA, brcPhiA);
604 brcg->SetLineColor(2);
608 byzmg->SetMaximum(0.03);
609 byzmg->SetMinimum(-0.03);
611 byzmg->GetHistogram()->SetXTitle("#phi[rad]");
612 byzmg->GetHistogram()->SetYTitle("B_{r} [T]");
616 TGraph* btg = new TGraph(iA, phiA, btPhiA);
617 TGraph* btcg = new TGraph(iA, phiA, btcPhiA);
618 btcg->SetLineColor(2);
622 bzzmg->SetMaximum(0.03);
623 bzzmg->SetMinimum(-0.03);
624 bzzmg->GetHistogram()->SetXTitle("#phi[rad]");
625 bzzmg->GetHistogram()->SetYTitle("B_{t} [T]");
630 TGraph* bg = new TGraph(iA, phiA, bbPhiA);
631 TGraph* bcg = new TGraph(iA, phiA, bbcPhiA);
632 bcg->SetLineColor(2);
636 bbmg->GetHistogram()->SetXTitle("#phi[rad]");
637 bbmg->GetHistogram()->SetYTitle("|B| [T]");
644 sprintf(pictFile, "%s.gif", runName);
645 c2->SaveAs(pictFile);
651 sprintf(htmlFile, "%s.html", runName);
652 FILE* chtml = fopen(htmlFile, "w");
653 MakeHtmlHeaderPict(chtml);
654 MakeHtmlPict(chtml, pictFile);
655 MakeHtmlTableEntry(fHtmlMain, fileName, htmlFile, zmin, zmax, ifiles, 0., 0);
659 printf("Bdl [Tm] %f %f \n", 2. * bdl, 2 * bdlc / 10.);
661 MakeHtmlTrailor(fHtmlMain);
662 TFile* out = new TFile("fmap.root", "recreate");
669 void AliFieldReader::MakeHtmlHeaderMain(FILE* file)
672 // Write the header of the heml output
674 fprintf(file,"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
675 fprintf(file, "<html>\n");
676 fprintf(file, "<head>\n");
677 fprintf(file, "<meta http-equiv=\"content-type\"\n");
678 fprintf(file, "content=\"text/html; charset=ISO-8859-1\"\n");
679 fprintf(file, "<title>main.html</title>\n");
680 fprintf(file, "<\\head>\n");
681 fprintf(file, "<body>\n");
682 fprintf(file, "<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\"\n");
683 fprintf(file, "style=\"text-align: left; width: 80;\">\n");
684 fprintf(file, "<tbody>\n");
685 fprintf(file, "<td style=\"vertical-align: top;\">File# <br></td>\n");
686 fprintf(file, "<td style=\"vertical-align: top;\">File Name <br></td>\n");
687 fprintf(file, "<td style=\"vertical-align: top;\">X-Position <br></td>\n");
688 fprintf(file, "<td style=\"vertical-align: top;\">Y-Position <br></td>\n");
689 fprintf(file, "<td style=\"vertical-align: top;\">Box Orientation <br></td>\n");
690 fprintf(file, "<td style=\"vertical-align: top;\">B.dl <br></td>\n");
691 fprintf(file, "<td style=\"vertical-align: top;\">Link to plots <br></td>\n");
695 void AliFieldReader::MakeHtmlHeaderPict(FILE* file)
698 // Write header for picture
700 fprintf(file,"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
701 fprintf(file, "<html>\n");
702 fprintf(file, "<head>\n");
703 fprintf(file, "<meta http-equiv=\"content-type\"\n");
704 fprintf(file, "content=\"text/html; charset=ISO-8859-1\"\n");
705 fprintf(file, "<title>main.html</title>\n");
706 fprintf(file, "</head>\n");
707 fprintf(file, "<body>\n");
710 void AliFieldReader:: MakeHtmlPict(FILE* chtml, char* pictFile)
713 // Write html for including picture
715 fprintf(chtml, "<img src=\"./%s\" alt=\"%s\" style=\"width: 1196px; height: 772px;\">\n",
718 fprintf(chtml, "<br> <br> <br>\n");
719 fprintf(chtml, "<a href=\"./bmap.html\">Back to main page</a><br>\n");
721 fprintf(chtml, "</body>\n");
722 fprintf(chtml, "</header>\n");
726 void AliFieldReader::MakeHtmlTableEntry(FILE* htmlmain, char* fileName, char* htmlFile, Float_t x, Float_t y, Int_t i, Float_t bdl, Int_t ifile)
728 fprintf(htmlmain, "<tr>\n");
730 fprintf(htmlmain, "<td style=\"vertical-align: top;\">%5d</td>\n", ifile);
731 fprintf(htmlmain, "<td style=\"vertical-align: top;\">%s</td>\n", fileName);
734 fprintf(htmlmain, "<td style=\"vertical-align: top;\">%13.2f</td>\n",x);
735 fprintf(htmlmain, "<td style=\"vertical-align: top;\">%13.2f</td>\n",y);
736 fprintf(htmlmain, "<td style=\"vertical-align: top;\">%3d </td>\n",i);
737 fprintf(htmlmain, "<td style=\"vertical-align: top;\">%13.3f</td>\n",bdl);
739 fprintf(htmlmain, "<td style=\"vertical-align: top;\">\n");
740 fprintf(htmlmain, "<span style=\"text-decoration: underline;\"><a href=\"./%s\">gif</a></span></td>\n", htmlFile);
741 fprintf(htmlmain, "</tr>\n");
745 void AliFieldReader::MakeHtmlTrailor(FILE* htmlmain)
748 // Write the html trailor
750 fprintf(htmlmain, "</tbody>\n");
751 fprintf(htmlmain, "</table>\n");
752 fprintf(htmlmain, "</body>\n");
753 fprintf(htmlmain, "</header>\n");
757 void AliFieldReader::ReadRegisterMap()
760 // Read the register map
762 FILE* regmap = fopen("register.map", "r");
764 for (ireg = 0; ireg < 200; ireg++) {
765 fRegMap[ireg][0] = -1;
766 fRegMap[ireg][1] = -1;
767 fRegMap[ireg][2] = -1;
769 for (Int_t iz = 0; iz < 2; iz++) {
770 for (Int_t iy = 2; iy >= 0; iy--) {
771 for (Int_t ix = 0; ix < 10; ix++) {
772 fscanf(regmap, "%d\n", &ireg);
773 printf("Address %5d %5d %5d %5d \n", iz, iy, ix, ireg);
774 fRegMap[ireg][1] = iy;
775 fRegMap[ireg][2] = iz;
777 fRegMap[ireg][0] = ix;
779 fRegMap[ireg][0] = 9 - ix;
785 printf("-> ReadRegisterMap()\n\n");
789 void AliFieldReader::ReadRegisterMapSolenoid()
792 // Read the register map
794 FILE* regmap = fopen("register.map", "r");
798 for (ireg = 0; ireg < 200; ireg++) {
799 fRegMap[ireg][0] = -1;
800 fRegMap[ireg][1] = -1;
801 fRegMap[ireg][2] = -1;
805 for (Int_t ir = 0; ir < 33; ir++) {
806 fscanf(regmap, "%d\n", &ireg);
807 fRegMap[ireg][0] = ir;
808 fRegMap[ireg][1] = 0;
811 for (Int_t ir = 0; ir < 5; ir++) {
812 fscanf(regmap, "%d\n", &ireg);
813 fRegMap[ireg][0] = ir;
814 fRegMap[ireg][1] = 1;