//Script/program to check the cards status changing when ramping the voltage, and find the corresponding voltage. //input: TIMBER file (usually .csv but extension doesn't matter) //output: txt file w array of voltage thresholds for all cards //to be exectuted in ROOT as "testHV.C" (script) or "testHV.C++" (program) //by Aurélien Marsili #include #include "TString.h" #include "TTree.h" #include "TGraph.h" #include "TMultiGraph.h" #include "TAxis.h" #include "TLegend.h" #include "TCanvas.h" #include "TROOT.h" void ReadBitsLine(TString myStr, Int_t *BitsArrayAfter, Int_t &Date, Int_t &dTime); void Comparison(Int_t *BitsArrayAfter, Int_t *BitsArrayBefore, Int_t ResultArray[2][8][128], Int_t Parity, Int_t Col, Int_t dTime, Int_t Position, Int_t &Marker); void ReadVoltsLine(TString myStr, Int_t &VoltageBuffer, Int_t &Date, Int_t &dTime); void FindVoltage(TTree *voltree, Int_t Position, Int_t ResultArray[2][8][128]); void testHV2(){ //buffer variables fo I/O TString myStr; ifstream mystream; TString myFilename; // = "TIMBER_DATA_SR5_20080630.csv"; // = "TIMBER_DATA_SR5_TOTAL_20080630.csv"; // ="TIMBER_DATA_SR8_BLMR_20080613"; TString playStr; TString pNum; cout << "File Name? (with extension...)" <> myFilename; // ="TIMBER_DATA_SR8_BLMR_20080613"; //myFilename += ".csv"; Int_t Date = 33333333; Int_t dTime = 999999; //Int_t SecNum; Int_t BitsArrayBefore[16]; Int_t BitsArrayAfter[16]; Int_t ResultArray[2][8][128]; // {L,C,R,E}{timestamp,voltage} [4 variables * {0 to 1, 1 to 0}] [32 cards] //Int_t Voltage[][2]; Int_t VoltageBuffer; Int_t Voltage; Int_t tTime; Int_t Marker = 0; Int_t Parity = 0; //will change (0 or 1) depending on the parity: even/odd cards. A=>1, B=>0. Int_t Col = -1; Int_t GetVolt=0; TTree *voltreeL =new TTree ("voltreeL","voltage and timestamp, left crate"); voltreeL->Branch("tTime", &tTime,"tTime/I"); voltreeL->Branch("Voltage", &Voltage,"mV/I"); TTree *voltreeC =new TTree ("voltreeC","voltage and timestamp, center crate"); voltreeC->Branch("tTime", &tTime,"tTime/I"); voltreeC->Branch("Voltage", &Voltage,"mV/I"); TTree *voltreeR =new TTree ("voltreeR","voltage and timestamp, right crate"); voltreeR->Branch("tTime", &tTime,"tTime/I"); voltreeR->Branch("Voltage", &Voltage,"mV/I"); TTree *voltreeE =new TTree ("voltreeE","voltage and timestamp, extra crate"); voltreeE->Branch("tTime", &tTime,"tTime/I"); voltreeE->Branch("Voltage", &Voltage,"mV/I"); //initialisation for(Int_t k=0; k<16; k++) { BitsArrayBefore[k] = 0; BitsArrayAfter[k] = 0; } for (Int_t p=0; p<4; p++) { for(Int_t i=0; i<32; i++) { for (Int_t j=0; j<8; j++) { ResultArray[0][j][i+32*p] = 0; ResultArray[1][j][i+32*p] = 0; } } } mystream.open(myFilename); if (!mystream.good()) { cout << "opening pb" << endl; exit(-1); } Int_t Position = -1; //fonction: ReadLine while (mystream.good()) { //test: try with first serie of data //for (Int_t line=0; line<120; line++) { myStr.ReadToDelim(mystream);//get first line if (myStr.Contains("VARIABLE")) { cout << myStr << endl; //cout << "String contains 'Variable'" << endl; playStr = myStr(21,1); pNum = myStr(14,3); if (playStr.Contains("L")) Position = 0; if (playStr.Contains("C")) Position = 1; if (playStr.Contains("R")) Position = 2; if (playStr.Contains("E")) Position = 3; if (myStr.Contains("DAC_RST_A")) { GetVolt = 0; Col = 4; Parity = 0; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("DAC_RST_B")) { GetVolt = 0; Col = 4; Parity = 1; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("GOH_RST_A")) { GetVolt = 0; Col = 6; Parity = 0; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("GOH_RST_B")) { GetVolt = 0; Col = 6; Parity = 1; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("HV_OK_A")) { GetVolt = 0; Col = 0; Parity = 0; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("HV_OK_B")) { GetVolt = 0; Col = 0; Parity = 1; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("TEST_CFC_A")) { GetVolt = 0; Col = 2; Parity = 0; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("TEST_CFC_B")) { GetVolt = 0; Col = 2; Parity = 1; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; } if (myStr.Contains("HV_1_VOLT_VALUE")) { GetVolt = 1; myStr.ReadToDelim(mystream); if (myStr.Contains("Timestamp")) { cout << myStr << endl; myStr.ReadToDelim(mystream); } else cout << "Error when reading header" << endl; }//enf of if if (Col == -1) cout << "error with column" << endl; /* cout << myStr << endl; } else cout << "Error when reading header" << endl; for (Int_t VoltageCounter = 0; VoltageCounter<3574; VoltageCounter++) { myStr.ReadToDelim(mystream); cout << "c" << myStr << endl; } //cout << "Voltage counter: " << VoltageCounter << endl; } */ } //end of if VARIABLE if (myStr.Contains("2008") && GetVolt == 0) { ReadBitsLine(myStr, BitsArrayAfter, Date, dTime); Comparison(BitsArrayAfter, BitsArrayBefore, ResultArray, Parity, Col, dTime, Position, Marker); }// end of if if (myStr.Contains("2008") && GetVolt == 1) { ReadVoltsLine(myStr, VoltageBuffer, Date, dTime); Voltage = VoltageBuffer; tTime = dTime; //cout << dTime << " " << Voltage << endl; //Voltage[step][0] = dTime; //Voltage[step][1] = VoltageBuffer; if (Position == 0) voltreeL->Fill(); if (Position == 1) voltreeC->Fill(); if (Position == 2) voltreeR->Fill(); if (Position == 3) voltreeE->Fill(); if (Position == -1) cout << "ERROR with crate position" << endl; }// end of if // if (myStr.Contains("2008") && GetVolt == 1) { // cout << myStr << endl; // } }//end of while //voltree->Show(10); //test /* myStr.ReadToDelim(mystream); // drop second line cout << "header: " << myStr << endl; cout << myStr << endl; //myStr */ //end of test. To implement: check for correct date (=> is integer?) /* for (Int_t l=0; l<30; l++) { myStr.ReadToDelim(mystream); ReadBitsLine(myStr, BitsArrayAfter, Date, dTime); Comparison(BitsArrayAfter, BitsArrayBefore, ResultArray, Parity, Col, dTime, Marker); } // end of for */ /* //display test cout << " date Time "; for(Int_t k=0; k<10; k++){ cout << " " << k+1;} for(Int_t k=10; k<16; k++){ cout << k+1;} cout << endl << "b " <SetStyle("Plain"); TGraph *GR[8]; // =new TGraph(31); TMultiGraph *mGR0 =new TMultiGraph(); TMultiGraph *mGR1 =new TMultiGraph(); TMultiGraph *mGR2 =new TMultiGraph(); for(Int_t v=0; v<4; v++) { GR[2*v] =new TGraph(128); GR[2*v+1] =new TGraph(128); for (Int_t i=0; i<128; i++) { GR[2*v]->SetPoint(i,i+1,ResultArray[1][2*v][i]); GR[2*v+1]->SetPoint(i,i+1,ResultArray[1][2*v+1][i]); } //end for i(31) mGR0->Add(GR[2*v]); mGR1->Add(GR[2*v+1]); mGR2->Add(GR[2*v+1]); mGR2->Add(GR[2*v]); } // end for v(8) GR[0]->SetLineColor(2); //red GR[1]->SetLineColor(2); GR[2]->SetLineColor(3); //light green GR[3]->SetLineColor(3); GR[4]->SetLineColor(4); //blue GR[5]->SetLineColor(4); GR[6]->SetLineColor(1); //black GR[7]->SetLineColor(1); GR[0]->SetMarkerColor(2); //red GR[1]->SetMarkerColor(2); GR[2]->SetMarkerColor(3); //light green GR[3]->SetMarkerColor(3); GR[4]->SetMarkerColor(4); //blue GR[5]->SetMarkerColor(4); GR[6]->SetMarkerColor(1); //black GR[7]->SetMarkerColor(1); for (Int_t i=0; i<8; i++) { GR[i]->SetMarkerStyle(5); //cross } TCanvas *Can0 =new TCanvas("Can0","time vs card number, 0 to 1",20,20,1200,900); mGR0->Draw("alp"); mGR0->SetTitle("0 to 1 (On)"); mGR0->GetYaxis()->SetTitle("Voltage [mV]"); mGR0->GetXaxis()->SetTitle("Card Number"); TLegend *leg1 =new TLegend (0.6,0.4,0.8,0.15); leg1->AddEntry(GR[0],"HV_OK","l"); leg1->AddEntry(GR[2],"TEST_CFC","l"); leg1->AddEntry(GR[4],"DAC_RST","l"); leg1->AddEntry(GR[6],"GOH_RST","l"); leg1->SetFillColor(0); leg1->Draw(); Can0->SetGrid(); Can0->Modified(); TCanvas *Can1 =new TCanvas("Can1","time vs card number, 1 to 0",40,40,1200,900); mGR1->Draw("alp"); mGR1->SetTitle("1 to 0 (Off)"); mGR1->GetYaxis()->SetTitle("Voltage [mV]"); mGR1->GetXaxis()->SetTitle("Card Number"); TLegend *leg2 =new TLegend (0.6,0.4,0.8,0.15); leg2->AddEntry(GR[1],"HV_OK","l"); leg2->AddEntry(GR[3],"TEST_CFC","l"); leg2->AddEntry(GR[5],"DAC_RST","l"); leg2->AddEntry(GR[7],"GOH_RST","l"); leg2->SetFillColor(0); leg2->Draw(); Can1->SetGrid(); Can1->Modified(); TCanvas *Can2 =new TCanvas("Can2","time vs card number, all values",60,60,1200,900); mGR2->Draw("alp"); //mGR2->SetTitle("Off"); mGR2->GetYaxis()->SetTitle("Voltage [mV]"); mGR2->GetXaxis()->SetTitle("Card Number"); TLegend *leg3 =new TLegend (0.6,0.4,0.8,0.15); leg3->AddEntry(GR[1],"HV_OK","l"); leg3->AddEntry(GR[3],"TEST_CFC","l"); leg3->AddEntry(GR[5],"DAC_RST","l"); leg3->AddEntry(GR[7],"GOH_RST","l"); leg3->SetFillColor(0); leg3->Draw(); Can2->SetGrid(); Can2->Modified(); Can2->SaveAs("Graph_testHV_" + pNum + ".pdf"); cout << endl << "end" << endl; } // end of main void FindVoltage(TTree *voltree, Int_t Position, Int_t ResultArray[2][8][128]) { //Find corresponding voltage Int_t Entries; Int_t Validation = 0; Int_t Buff1 = 0; Int_t Buff2 = 0; Int_t BuffV = 0; Entries = voltree->GetEntries(); Int_t tTime; Int_t Voltage; voltree->SetBranchAddress("tTime", &tTime); voltree->SetBranchAddress("Voltage", &Voltage); //voltree->Print(); for (Int_t k=0; k<32; k++) { for (Int_t i=0; i<8; i++) { Validation = 0; for (Int_t e=0; eGetEntry(e); if (ResultArray[0][i][k+32*Position] == tTime) { ResultArray[1][i][k+32*Position] = Voltage; Validation = 1; //cout << tTime << " " << Voltage << endl; }//end of if } //end of for (Entries) //cout << Validation; if (Validation == 0 && ResultArray[0][i][k+32*Position] != 0) { cout << "Missing timestamp" << endl; // at:" << ResultArray[0][i][k+32*Position] << endl; for (Int_t e=0; eGetEntry(e); Buff1 = tTime; BuffV = Voltage; voltree->GetEntry(e+1); Buff2 = tTime; //if one timestamp is missing, find the one before and the one after, and take the voltage before. if ((Buff1 > ResultArray[0][i][k+32*Position] && Buff2 < ResultArray[0][i][k+32*Position]) || (Buff1 < ResultArray[0][i][k+32*Position] && Buff2 > ResultArray[0][i][k+32*Position])) { ResultArray[1][i][k+32*Position] = BuffV; Validation = 1; cout << tTime << " " << Voltage << endl; } } } } // end of for (8) } // end of for }// end of FindVoltage() void ReadBitsLine(TString myStr, Int_t *BitsArrayAfter, Int_t &Date, Int_t &dTime) { Int_t Year; Int_t Month; Int_t Day; Int_t Hours; Int_t Minutes; Int_t Seconds; if (!myStr.Contains("2008")) { cout << "ERROR! Wrong line: does not contain 2008" << endl; cout << myStr << endl; //break; } //else cout << "gagne" << endl; //to do: ROOT format for date //TTimeStamp Timestamp; Int_t milliseconds = 3; sscanf(myStr.Data(),"%d-%d-%d %d:%d:%d.%d",&Year,&Month,&Day,&Hours,&Minutes,&Seconds,&milliseconds); //23 chars (without last comma) //Timestamp.Set(Year,Month,Day,Hours,Mins,Seconds,0,0,0);//LOCAL_TIME, not UTC. Date = 10000*Year + 100*Month + Day; dTime = 10000*Hours + 100*Minutes + Seconds; //for display (human readable: hhmmss) //SecNum = 3600*Hours + 60*Minutes + Seconds; //for plots (number of seconds -- comtinuous) //cout << dTime << " "; //<< endl; // << milliseconds + 2 << " "; TString myStr2 =myStr(23,myStr.Length()-23); //with comma //cout << "myStr: " << myStr << endl; //cout << "myStr2: " << myStr2 << endl; //sscanf(myStr2.Data(),",%d",&BitsArrayAfter[0]); //cout << BitsArrayAfter[0] << endl; Int_t buffer; for (Int_t n=0; n<16; n++) { sscanf(myStr2.Data(),",%d",&buffer); //cout << buffer << " " ; BitsArrayAfter[n] = buffer; //cout << BitsArrayAfter[n] << " " ; //n++; if (n>15) cout << "stupid error: wrong BitsArrayAfter index" << endl; myStr2 =myStr2(2,myStr2.Length()-2); //cout << myStr2 << endl; } //cout << endl; } //end of fonction ReadBitsLine void ReadVoltsLine(TString myStr, Int_t &VoltageBuffer, Int_t &Date, Int_t &dTime) { Int_t Year; Int_t Month; Int_t Day; Int_t Hours; Int_t Minutes; Int_t Seconds; if (!myStr.Contains("2008")) { cout << "ERROR! Wrong line: does not contain 2008" << endl; cout << myStr << endl; } //to do: ROOT format for date //TTimeStamp Timestamp; Int_t milliseconds = 3; sscanf(myStr.Data(),"%d-%d-%d %d:%d:%d.%d,%d",&Year,&Month,&Day,&Hours,&Minutes,&Seconds,&milliseconds,&VoltageBuffer); //23 chars (without last comma) //Timestamp.Set(Year,Month,Day,Hours,Mins,Seconds,0,0,0);//LOCAL_TIME, not UTC. Date = 10000*Year + 100*Month + Day; dTime = 10000*Hours + 100*Minutes + Seconds; //for display (human readable: hhmmss) //SecNum = 3600*Hours + 60*Minutes + Seconds; //for plots (number of seconds -- comtinuous) } //end of fonction ReadBitsLine void Comparison(Int_t *BitsArrayAfter, Int_t *BitsArrayBefore, Int_t ResultArray[2][8][128], Int_t Parity, Int_t Col, Int_t dTime, Int_t Position, Int_t &Marker) { //comparison for(Int_t k=0; k<16; k++) { //front montant if (BitsArrayBefore[k] == 0 && BitsArrayAfter[k] == 1) { ResultArray[0][Col][2*k + Parity + 32*Position] = dTime; cout << dTime << " Card " << 2*k + Parity + 1 + 32 * Position << " "; for (Int_t i=0; i<16; i++) { cout << BitsArrayAfter[i] << " "; } cout << endl; } } for(Int_t k=0; k<16; k++) { //front descendant if (BitsArrayBefore[k] == 1 && BitsArrayAfter[k] == 0) { ResultArray[0][Col + 1][2*k + Parity + 32 * Position] = dTime; cout << dTime << " Card " << 2*k + Parity + 1 + 32 * Position<< " "; for (Int_t i=0; i<16; i++) { cout << BitsArrayAfter[i] << " "; } cout << endl; } } //check that all cards are 1 if (Marker == 0 && BitsArrayAfter[0]==1 && BitsArrayAfter[1]==1 && BitsArrayAfter[2]==1 && BitsArrayAfter[3]==1 && BitsArrayAfter[4]==1 && BitsArrayAfter[5]==1 && BitsArrayAfter[6]==1 && BitsArrayAfter[7]==1 && BitsArrayAfter[8]==1 && BitsArrayAfter[9]==1 && BitsArrayAfter[10]==1 && BitsArrayAfter[11]==1 && BitsArrayAfter[12]==1 && BitsArrayAfter[13]==1 && BitsArrayAfter[14]==1 && BitsArrayAfter[15]==1) { //if (Marker == 0 && CompBit == 1) { Marker = 1; // all cards have status 1. cout << " ==== All card have status 1 ====" << endl << endl; } //check that all cards are 0, but weren't all at 1 if (Marker == 0 && BitsArrayAfter[0]==0 && BitsArrayAfter[1]==0 && BitsArrayAfter[2]==0 && BitsArrayAfter[3]==0 && BitsArrayAfter[4]==0 && BitsArrayAfter[5]==0 && BitsArrayAfter[6]==0 && BitsArrayAfter[7]==0 && BitsArrayAfter[8]==0 && BitsArrayAfter[9]==0 && BitsArrayAfter[10]==0 && BitsArrayAfter[11]==0 && BitsArrayAfter[12]==0 && BitsArrayAfter[13]==0 && BitsArrayAfter[14]==0 && BitsArrayAfter[15]==0) { Marker = 0; cout << " = All cards have status 0, but did not all have status 1 =" << endl << endl; } //check that all cards are 0 if (Marker == 1 && BitsArrayAfter[0]==0 && BitsArrayAfter[1]==0 && BitsArrayAfter[2]==0 && BitsArrayAfter[3]==0 && BitsArrayAfter[4]==0 && BitsArrayAfter[5]==0 && BitsArrayAfter[6]==0 && BitsArrayAfter[7]==0 && BitsArrayAfter[8]==0 && BitsArrayAfter[9]==0 && BitsArrayAfter[10]==0 && BitsArrayAfter[11]==0 && BitsArrayAfter[12]==0 && BitsArrayAfter[13]==0 && BitsArrayAfter[14]==0 && BitsArrayAfter[15]==0) { Marker = 0; cout << " ==== All card are back to status 0 ====" << endl << endl; } //fill BitsArrayBefore[] for(Int_t k=0; k<16; k++) { BitsArrayBefore[k] = BitsArrayAfter[k]; } }//end of fonction Comparison