ShowScan416(char *fname) { /* Wire Scanner MD data analysis script for new electronics (installed on 416 - situation Nov 2008) author: M. Sapinski CERN/BE/BI exmaple: .x ShowScan416.C("DATA_416/BWSINJ_-_SPS.BWS.41677.H_ROT_-_ALL_-_Logging_-_2008.10.23-04.06.08.txt") */ // for proper gauss-fitting the pedestal should be subtracted. Double_t pedestal=0.0045; // **************************************** // data from Ana // Double_t coarseWireResistance=2; // kOhm - fot 416H Double_t coarseWireResistance=3.6; // kOhm - fot 416V // (unsigned int vvv ?) Double_t wireTestV=1638/coarseWireResistance + 2047.5; Double_t curr=(2*wireTestV/4095-1)*2500; gROOT->Macro("gra.C"); ifstream fin; fin.open(fname); if(!fin.good()) {cout << "file error" < !!! // this is where it starts: // WS temperature data (scan IN): tempDataSet1 // WS temperature data (scan OUT): tempDataSet2 // WS data itself (scan IN): projDataSet1 if(aLine.Contains("projDataSet1")) { getInData=true; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getInData && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s1nr[s1count],&s1amp[s1count]); // cout << "inscan data: "; // cout << aLine.Data() << " in sig:" << s1amp[s1count] << endl; // printf("inscan data: %s in sig: %f\n",aLine.Data(),s1amp[s1count]); s1amp[s1count]-=pedestal; if(s1amp[s1count]>maxplot) maxplot=s1amp[s1count]; s1count++; } // WS data itself (scan IN): projDataSet2 if(aLine.Contains("projDataSet2")) { getInData=false; getOutData=true; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getOutData && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s2nr[s2count],&s2amp[s2count]); // cout << "outscan data: " << aLine.Data() << " out sig:" << s2amp[s2count] << endl; // printf("outscan data: %s out sig: %f\n",aLine.Data(),s2amp[s2count]); s2amp[s2count]-=pedestal; if(s2amp[s2count]>maxplot) maxplot=s2amp[s2count]; s2count++; } if(aLine.Contains("peripherals")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(aLine.Contains("bunchSelection")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } // WS potenitiometer position (scan IN): potPosRawSet1 if(aLine.Contains("potPosRawSet1")) { getInData=false; getOutData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } // WS potenitiometer position (scan OUT): potPosRawSet2 if(aLine.Contains("potPosRawSet2")) { getInData=false; getOutData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } // WS resistence measurement (scan IN): resistenceSet1 if(aLine.Contains("resistenceSet1")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=true; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getResistenceIn && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s1res_nr[s1res_count],&s1resis[s1res_count]); // printf("inscan resistence: %s : %f\n",aLine.Data(),s1resis[s1res_count]); // if(s2amp[s2count]>maxplot) maxplot=s2amp[s2count]; s1res_count++; } // WS resistence measurement (scan OUT): resistenceSet2 if(aLine.Contains("resistenceSet2")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=true; getInTemporary=false; getOutTemporary=false; } if(getResistenceOut && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s2res_nr[s2res_count],&s2resis[s2res_count]); // printf("out resistence: %s : %f\n",aLine.Data(),s2resis[s2res_count]); // if(s2amp[s2count]>maxplot) maxplot=s2amp[s2count]; s2res_count++; } // WS temparature (calibrated?) (scan IN): temperatureSet1 if(aLine.Contains("temperatureSet1")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=true; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getInTemp && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s1temp_nr[s1temp_count],&s1temp[s1temp_count]); // printf("in temperature: %s : %f\n",aLine.Data(),s1temp[s1temp_count]); s1temp_count++; } // WS temparature (calibrated?) (scan OUT): temperatureSet2 if(aLine.Contains("temperatureSet2")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=true; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getOutTemp && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s2temp_nr[s2temp_count],&s2temp[s2temp_count]); // printf("out resistence: %s : %f\n",aLine.Data(),s2temp[s2temp_count]); s2temp_count++; } // WS logging (scan IN): logDataSet1 if(aLine.Contains("logDataSet1")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } // WS logging (scan OUT): logDataSet2 if(aLine.Contains("logDataSet2")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } // WS position (scan IN?): projPositionSet2 if(aLine.Contains("projPositionSet2")) { getInData=false; getOutData=false; getInPos=false; getOutPos=true; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getOutPos && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s2pot_nr[s2pos_count],&s2pot[s2pos_count]); // printf("inscan pos nr %d data: %s in pos: %d\n",s2pos_count,aLine.Data(),s2pot[s2pos_count]); if(s2pos_count%2==0) { // even positions s2potEven[s2posCEven]=s2pot[s2pos_count]; s2posCEven++; } if(s2pos_count%2==1) { // odd positions s2potOdd[s2posCOdd]=s2pot[s2pos_count]; s2posCOdd++; } s2pos_count++; } // WS position (scan OUT?): projPositionSet1 if(aLine.Contains("projPositionSet1")) { getInData=false; getOutData=false; getInPos=true; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=false; } if(getInPos && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %lf",&s1pot_nr[s1pos_count],&s1pot[s1pos_count]); // cout << "nr: " << s1pos_count << " inscan data: " << aLine.Data() << " sig:" << s1pot[s1pos_count] << endl << endl; // printf("inscan pos nr %d data: %s in pos: %d\n",s1pos_count,aLine.Data(),s1pot[s1pos_count]); if(s1pos_count%2==0) { // even positions s1potEven[s1posCEven]=s1pot[s1pos_count]; s1posCEven++; } if(s1pos_count%2==1) { // odd positions s1potOdd[s1posCOdd]=s1pot[s1pos_count]; s1posCOdd++; } s1pos_count++; } // scan IN, temporary data set, see page 684 of logbook. if(aLine.Contains("tempDataSet1")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=true; getOutTemporary=false; } Int_t temp1,temp2; if(getInTemporary && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %d\n",&temp1,&temp2); // printf("Line: %s\n",aLine.Data()); // printf("inscan temp line: %d value: %d\n",s1templinecount,temp2); if(teststart1) { if(temp2<1000) s1first_therm=true; // detection what the first value is: teststart1=false; } if(s1first_therm && s1templinecount%2==0) { // cout << "x" << endl; s1Therm_nr[s1ThermCount]=temp1; s1Therm[s1ThermCount]=1.0*temp2; s1ThermCount++; } if(s1first_therm && s1templinecount%2==1) { s1Res_nr[s1ResCount]=temp1; // s1Res[s1ResCount]=1.00*temp2; // ADC counts s1Res[s1ResCount]=(2500.0*temp2/4095.0)/curr; // kOhm // cout << "xx Res: " << s1Res[s1ResCount] << endl; s1ResCount++; } if(!s1first_therm && s1templinecount%2==1) { s1Therm_nr[s1ThermCount]=temp1; s1Therm[s1ThermCount]=1.00*temp2; // cout << "xxx Therm: " << s1Therm[s1ThermCount] << endl; s1ThermCount++; } if(!s1first_therm && s1templinecount%2==0) { s1Res_nr[s1ResCount]=temp1; // s1Res[s1ResCount]=1.00*temp2; // ADC counts s1Res[s1ResCount]=(2500.0*temp2/4095.0)/curr; // kOhm // cout << "xxxx Res: " << s1Res[s1ResCount] << endl; s1ResCount++; } cout << endl; s1templinecount++; } // end of getline! if(aLine.Contains("tempDataSet2")) { getInData=false; getOutData=false; getInPos=false; getOutPos=false; getInTemp=false; getOutTemp=false; getResistenceIn=false; getResistenceOut=false; getInTemporary=false; getOutTemporary=true; } if(getOutTemporary && aLine.Contains("line")) { sscanf(aLine.Data(),"line%d %d\n",&temp1,&temp2); // printf("Line: %s\n",aLine.Data()); // printf("outscan temp line: %d value: %d\n",s2templinecount,temp2); if(teststart2) { if(temp2<1000) s2first_therm=true; // detection what the first value is: teststart2=false; } if(s2first_therm && s2templinecount%2==0) { s2Therm_nr[s2ThermCount]=temp1; s2Therm[s2ThermCount]=1.0*temp2; s2ThermCount++; } if(s2first_therm && s2templinecount%2==1) { s2Res_nr[s2ResCount]=temp1; // s2Res[s2ResCount]=1.00*temp2; // ADC counts s2Res[s2ResCount]=(2500.0*temp2/4095.0)/curr; // kOhm // cout << "xx Res: " << s2Res[s2ResCount] << endl; s2ResCount++; } if(!s2first_therm && s2templinecount%2==1) { s2Therm_nr[s2ThermCount]=temp1; s2Therm[s2ThermCount]=1.00*temp2; // cout << "xxx Therm: " << s2Therm[s2ThermCount] << endl; s2ThermCount++; } if(!s2first_therm && s2templinecount%2==0) { s2Res_nr[s2ResCount]=temp1; // s2Res[s2ResCount]=1.00*temp2; // ACD s2Res[s2ResCount]=(2500.0*temp2/4095.0)/curr; // kOhm // cout << "xxxx Res: " << s2Res[s2ResCount] << endl; s2ResCount++; } cout << endl; s2templinecount++; } // end of getline! /* if(aLine.Contains("")) inscan=false; if(TString(aLine(0,3)).IsFloat()) { // cout << "Float: "; // cout << aLine << endl; if(inscan) { sscanf(aLine.Data(),"%d %lf %lf %d\n", &s1nr[s1count],&s1pot[s1count],&s1rul[s1count],&s1amp[s1count]); s1amp_f[s1count]=Double_t(s1amp[s1count]); if(s1amp_f[s1count]>maxplot) maxplot=s1amp_f[s1count]; s1count++; } else { sscanf(aLine.Data(),"%d %lf %lf %d\n", &s2nr[s2count],&s2pot[s2count],&s2rul[s2count],&s2amp[s2count]); s2amp_f[s2count]=Double_t(s2amp[s2count]); if(s2amp_f[s2count]>maxplot) maxplot=s2amp_f[s2count]; s2count++; } // end of if(inscan) } // end of if(IsFloat) */ } // end of while loop fin.close(); // cross-check: cout << "ampli points: " << s1count << " pot points: " << s1pos_count << endl; TGraph *grIn = new TGraph(s1count,s1pot,s1amp); grIn->SetLineColor(kBlue); grIn->SetLineWidth(2); cout << " ===================================== " << endl; cout << " fitting IN: " << endl; grIn->Fit("gaus","","",-15000.,15000.); // Double_t maxIn=grIn->GetMaximum(); cout << "sigma/err IN = " << gaus->GetParameter(2) << " " << gaus->GetParError(2) << endl; TGraph *grOut = new TGraph(s2count,s2pot,s2amp); grOut->SetLineColor(kRed); grOut->SetLineWidth(2); cout << " ===================================== " << endl; cout << " fitting OUT: " << endl; grOut->Fit("gaus","","",-30000.,10000.); cout << "sigma/err OUT = " << gaus->GetParameter(2) << " " << gaus->GetParError(2) << endl; // Double_t maxOut=grOut->GetMaximum(); // Double_t maxGr=max(maxIn,maxOut); Double_t potent0=-200000.; Double_t potent1=200000.; gStyle->SetOptFit(1); c1=new TCanvas("c1","scans",1,1,800,600); TH1F *hr = c1->DrawFrame(potent0,0.,potent1,1.1*maxplot); hr->SetXTitle("Potent position [#mum]"); hr->SetYTitle("Amplitude"); TMultiGraph *mgr = new TMultiGraph(); mgr->Add(grIn,"lp"); // grIn->Fit(gaus); mgr->Add(grOut,"lp"); // grOut->Fit(gaus); TPaveText *t = new TPaveText(potent0,0.95*maxplot,potent1,1.05*maxplot); t->AddText(fname); t->Draw(); mgr->Draw(); // ----------------------------------------------------- // temperature // ----------------------------------------------------- /* c2=new TCanvas("c2","temperature",1,1,800,600); TH1F *hr = c2->DrawFrame(potent0,0.,potent1,3000.); hr->SetXTitle("Potent position"); hr->SetYTitle("Temperature"); TGraph *grInTemp = new TGraph(s1temp_count,s1pot,s1temp); grInTemp->SetLineColor(kBlue); grInTemp->SetLineWidth(2); TGraph *grOutTemp = new TGraph(s2temp_count,s2pot,s2temp); grOutTemp->SetLineColor(kRed); grOutTemp->SetLineWidth(2); TMultiGraph *mgrTemp = new TMultiGraph(); mgrTemp->Add(grInTemp,"lp"); mgrTemp->Add(grOutTemp,"lp"); mgrTemp->Draw(); */ // ----------------------------------------------------- // resistance // ----------------------------------------------------- /* c3=new TCanvas("c3","resistence",1,1,800,600); TH1F *hr = c3->DrawFrame(potent0,0.,potent1,300.); hr->SetXTitle("Potent position"); hr->SetYTitle("Resistance"); TGraph *grInResis = new TGraph(s1res_count,s1pot,s1resis); grInResis->SetLineColor(kBlue); grInResis->SetLineWidth(2); TGraph *grOutResis = new TGraph(s2res_count,s2pot,s2resis); grOutResis->SetLineColor(kRed); grOutResis->SetLineWidth(2); TMultiGraph *mgrResis = new TMultiGraph(); mgrResis->Add(grInResis,"lp"); mgrResis->Add(grOutResis,"lp"); mgrResis->Draw(); */ // ----------------------------------------------------- // new resistance (ADC - convert ot kOhms) // ----------------------------------------------------- c4=new TCanvas("c4","new resistence",1,1,800,600); TH1F *hr = c4->DrawFrame(potent0,0.,potent1,4.); hr->SetXTitle("Potent position [#mum]"); hr->SetYTitle("Resistance [k#Omega]"); TGraph *grInResNew = new TGraph(s1ResCount,s1potEven,s1Res); grInResNew->SetLineColor(kBlue); grInResNew->SetLineWidth(2); TGraph *grOutResNew = new TGraph(s2ResCount,s2potEven,s2Res); grOutResNew->SetLineColor(kRed); grOutResNew->SetLineWidth(2); TMultiGraph *mgrResNew = new TMultiGraph(); mgrResNew->Add(grInResNew,"lp"); mgrResNew->Add(grOutResNew,"lp"); mgrResNew->Draw(); // ----------------------------------------------------- // new thermionic emission (arbitraty units (ADC)) // ----------------------------------------------------- c5=new TCanvas("c5","new thermionic",1,1,800,600); TH1F *hr = c5->DrawFrame(potent0,0.,potent1,300.); hr->SetXTitle("Potent position"); hr->SetYTitle("Thermionic emission (ADC counts)"); TGraph *grInThermNew = new TGraph(s1ThermCount,s1potOdd,s1Therm); grInThermNew->SetLineColor(kBlue); grInThermNew->SetLineWidth(2); TGraph *grOutThermNew = new TGraph(s2ThermCount,s2potOdd,s2Therm); grOutThermNew->SetLineColor(kRed); grOutThermNew->SetLineWidth(2); TMultiGraph *mgrThermNew = new TMultiGraph(); mgrThermNew->Add(grInThermNew,"lp"); mgrThermNew->Add(grOutThermNew,"lp"); mgrThermNew->Draw(); // ----------------------------------------------------- // new all together // ----------------------------------------------------- TCanvas *c6 = new TCanvas("c6","new alltogether",1,1,800,1200); c6->Divide(1,3); c6->cd(1); cout << "pad number: " << gPad->GetNumber() << endl; TH1F *hr1 = c6->GetPad(1)->DrawFrame(potent0,0.,potent1,1.1*maxplot); cout << "are we here yet?" << endl; hr1->SetXTitle("Potent position [#mum]"); hr1->SetYTitle("Amplitude"); TMultiGraph *Mgr = new TMultiGraph(); Mgr->Add(grIn,"lp"); Mgr->Add(grOut,"lp"); Mgr->Draw(); // // here is the problem - the following 3 lines make disappear the graph before: TPaveText *tt = new TPaveText(0.05,0.90,0.95,1.0,"NDC"); tt->AddText(fname); tt->Draw(); // c6->Update(); cout << "first drawing done" << endl; c6->cd(2); TH1F *hr2 = c6->GetPad(2)->DrawFrame(potent0,0.,potent1,4.); hr2->SetXTitle("Potent position [#mum]"); hr2->SetYTitle("Resistance [k#Omega]"); c6->GetPad(2)->SetTicks(1,1); TMultiGraph *MgrResNew = new TMultiGraph(); MgrResNew->Add(grInResNew,"lp"); MgrResNew->Add(grOutResNew,"lp"); MgrResNew->Draw(); cout << "second drawing done" << endl; c6->cd(3); TH1F *hr3 = c6->GetPad(3)->DrawFrame(potent0,0.,potent1,300.); hr3->SetXTitle("Potent position"); hr3->SetYTitle("Thermionic emission (ADC counts)"); TMultiGraph *MgrThermNew = new TMultiGraph(); MgrThermNew->Add(grInThermNew,"lp"); MgrThermNew->Add(grOutThermNew,"lp"); MgrThermNew->Draw(); cout << "third drawing done" << endl; c6->cd(); }