Changeset 99


Ignore:
Timestamp:
08/12/09 12:01:25 (15 years ago)
Author:
ogrimm
Message:
Streamlined DRS2 reponse calibration interface, updated HV feedback socket communication
Location:
drsdaq
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/DAQReadout.cc

    r92 r99  
    2525  {{"board", &DAQReadout::cmd_board, true, "<i> [j] | <all>" ,"Address board i, boards i-j, all boards"},
    2626   {"status", &DAQReadout::cmd_status, false, "[daq|drs]", "Show DAQ/DRS status information"},
    27    {"freq", &DAQReadout::cmd_freq, true, "<GHz> [reg]", "Set DRS sampling frequency (regulated)"},
    28    {"calib", &DAQReadout::cmd_calib, true, "<t_f> <c_f>", "Response calibration"},
     27   {"frequency", &DAQReadout::cmd_freq, true, "<GHz> [reg]", "Set DRS sampling frequency (regulated)"},
     28   {"calib", &DAQReadout::cmd_calib, true, "<trig rate> ", "Response calibration"},
    2929   {"trigger", &DAQReadout::cmd_trigger, true, "<on|off>", "Hardware trigger on or off"},
    3030   {"delayed", &DAQReadout::cmd_delayed, true, "<on|off>", "Switch delayed start on or off"},
     
    220220// Print current number of events
    221221void DAQReadout::cmd_events() {
    222   if(daq_state != active) PrintMessage("DAQ not active.\n");
     222  if(daq_state != active) PrintMessage("DAQ not active\n");
    223223  else PrintMessage("Current number of events: %d (of %d requested)\n", NumEvents, NumEventsRequested);
    224224}
     
    234234  if(!Match(Param[1],"test")) {
    235235    if (daq_state==active || NumBoards==0) {
    236       PrintMessage("DAQ is busy or no boards available.\n");
     236      PrintMessage("DAQ is busy or no boards available\n");
    237237      return;
    238238    }
     
    244244   
    245245    if (!CalibrationRead && !ReadCalibration()) {
    246       PrintMessage("Cannot start run if response calibration not read.\n");
     246      PrintMessage("Cannot start run if response calibration not read\n");
    247247      return;
    248248    }
     
    333333  else if (Match(Param[1], "blt64")) Type = 1;
    334334  else {
    335     PrintMessage("Unknown type for testing.\n");
     335    PrintMessage("Unknown type for testing\n");
    336336    return;
    337337  }
     
    448448  char str[MAX_COM_SIZE];
    449449
    450   if (NParam!=3 || !atof(Param[1]) || !atof(Param[2])) {
     450  if (NParam!=2 || !atof(Param[1])) {
    451451    PrintUsage();
     452    return;
     453  }
     454  if (!IsDRSFreqSet()) {
     455    PrintMessage("Set sampling frequency first\n");
    452456    return;
    453457  }
     
    455459  getcwd(str, sizeof(str));
    456460  strcat(str,"/calib");
    457   PrintMessage("Writing calibration data to directory '%s'\n",str);
    458461
    459462  for (int i=FirstBoard; i<=LastBoard; i++) {
    460     drs->GetBoard(i)->Init();
    461     drs->GetBoard(i)->SetFrequency(atof(Param[2]));
    462     drs->GetBoard(i)->SoftTrigger();
    463 
    464     PrintMessage("Creating calibration of board %d (%d)\n", i, drs->GetBoard(i)->GetCMCSerialNumber());
     463    PrintMessage("Creating calibration of board %d (serial number %d)\n", i, drs->GetBoard(i)->GetCMCSerialNumber());
    465464
    466465    drs->GetBoard(i)->EnableTcal(1);
    467     PrintMessage("Tcal enabled\n");
    468 
    469466    if (drs->GetBoard(i)->GetChipVersion() == 3) drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,21,0,20,0,0,0,0,0);
    470467    else drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,36,110,20,19,40,15,atof(Param[1]),0);
    471468    drs->GetBoard(i)->SetCalibrationDirectory(str);
    472469
    473     for (int j=0; j<2; j++) {
     470    for (int j=0; j<kNumberOfChips; j++) {
    474471      drs->GetBoard(i)->GetResponseCalibration()->ResetCalibration();
    475       PrintMessage("Calibration reset done.\n");
    476472
    477473      while (!drs->GetBoard(i)->GetResponseCalibration()->RecordCalibrationPoints(j)) {}
    478       PrintMessage("Record calibration points done.\n");
     474      PrintMessage("Calibration points recorded.\n");
     475
    479476      while (!drs->GetBoard(i)->GetResponseCalibration()->FitCalibrationPoints(j)) {}
    480477      PrintMessage("Calibration points fitted.\n");
     478
    481479      while (!drs->GetBoard(i)->GetResponseCalibration()->OffsetCalibration(j)) {}
    482480      PrintMessage("Offset calibration done.\n");
     
    484482      if (!drs->GetBoard(i)->GetResponseCalibration()->WriteCalibration(j)) break;
    485483    }       
    486     drs->GetBoard(i)->Init(); // Reset linear range -0.2 ... 0.8 V
    487484  } // Loop over boards
     485  PrintMessage("End of calibration\n");
     486  CalibrationRead = false;
    488487}
    489488
     
    737736}
    738737
    739 // Check if calibration file has been read
    740 bool DAQReadout::IsCalibrationRead() {
    741 
    742   for (int i=FirstBoard; i<=LastBoard; i++) {
    743     for (int Chip=0; Chip<kNumberOfChips; Chip++)
    744       if (!(drs->GetBoard(i)->GetResponseCalibration()->IsRead(Chip))) {
    745         PrintMessage("Warning: Response calibration of board %d chip %d not yet read!\n",i,Chip);
    746         return false;
    747       }
    748   }
    749   return true;
    750 }
    751 
    752738// Stop DAQ
    753739void DAQReadout::StopRun() {
  • drsdaq/DAQReadout.h

    r92 r99  
    123123    void HWTrigger(int);
    124124    bool ReadCalibration();
    125     bool IsCalibrationRead();
    126125    void ReadCalibratedDRSData();
    127126    void PrintConfig(int);
     
    136135
    137136void DAQ(DAQReadout *);
     137
    138138bool Match(const char*, const char*);
    139139int ParseInput(char*, const char *Param[]);
  • drsdaq/HVFeedback.cc

    r92 r99  
    1616#include <signal.h>
    1717
    18 #define MAX_RETRY 5
    1918#define PIXMAP_LOCATION "../config/PixelMap.txt"
    2019
     
    6463    ReadCard("MaxCmdAckDelay",      &fMaxCmdAckDelay,    'I', File);
    6564    ReadCard("DefaultResponse",      Response,           'f', File, m->NumBoards*kNumberOfChips*kNumberOfChannels);
     65    ReadCard("DefaultTarget",        Target,             'f', File, m->NumBoards*kNumberOfChips*kNumberOfChannels);
    6666    fclose(File);
    6767  }
     
    115115 
    116116  // Check for LED trigger channel on given channel and if feedback running
    117   if (FBMode==FB_Off || m->WaveForm[fLedTrigBoard][fLedTrigChip][fLedTrigChannel][fLedTrigSample] < fLedTrigThreshold)
     117  if (FBMode==FB_Off || m->WaveForm[fLedTrigBoard][fLedTrigChip][fLedTrigChannel][(fLedTrigSample+m->TriggerCell[fLedTrigBoard][fLedTrigChip])%kNumberOfBins] < fLedTrigThreshold)
    118118    return false;
    119119 
     
    123123      for (k=0; k<kNumberOfChannels; k++) {
    124124        for (Integral=0, q=-fIntHalfWidth; q<=(int) fIntHalfWidth; q++)
    125           Integral += (m->WaveForm[i][j][k][fLedSignalSample+q] - m->WaveForm[i][j][k][fLedBaselineSample+q])*m->BStruct[i].ScaleFactor;
     125          Integral += (m->WaveForm[i][j][k][(fLedSignalSample+q+m->TriggerCell[i][j])%kNumberOfBins] - m->WaveForm[i][j][k][(fLedBaselineSample+q+m->TriggerCell[i][j])%kNumberOfBins])*m->BStruct[i].ScaleFactor;
    126126        Integral /= 2*fIntHalfWidth+1;
    127127        Average[i][j][k] += Integral;
     
    129129      }
    130130
     131  // Check if acquired number of event requires action
    131132  if (++Count<NumAverages) return false;
    132133
    133   // Acquired number of event requires action
     134  // Make entry in slow data file
    134135  switch (FBMode) {
    135136    case FB_Active: SlowDataClass->NewEntry("Average");
     
    143144  }                     
    144145
     146  // Feedback action
    145147  for (i=m->FirstBoard; i<=m->LastBoard; i++) {
    146148    for (j=0; j<kNumberOfChips; j++) {
     
    153155            EffectiveGain = Gain*pow(0.5*(1+(Difference/Sigma[i][j][k]-1)/(Difference/Sigma[i][j][k]+1)),2);
    154156            Correction = -Difference*Response[i][j][k]*EffectiveGain;
     157            if (fabs(Correction) > 0.1) Correction = fabs(Correction)/Correction*0.1;   // Limit changes to 100 mV
    155158            if(Correction!=0 && Target[i][j][k]!=0 && !PixMap->DRS_to_Pixel(i,j,k).empty()) {
    156159              printf("Average of board %d, chip %d, channel %d is %.2f +/- %.2f    Correction %.3f\n",i,j,k,Average[i][j][k],Sigma[i][j][k],Correction);
     
    261264
    262265//
    263 // Set feedback mode and clear averages
     266// Get feedback mode
    264267//
    265268FBState HVFeedback::GetFBMode() {
     
    295298void HVFeedback::GetTargets() {
    296299  for (int i=m->FirstBoard; i<=m->LastBoard; i++)
    297     for (int j=0; j<kNumberOfChips; j++)
    298       for (int k=0; k<kNumberOfChannels; k++)
    299          m->PrintMessage("Board %d, chip %d, channel %d: %.2f\n",i,j,k,Target[i][j][k]);
     300    for (int j=0; j<kNumberOfChips; j++) {
     301      m->PrintMessage("Board %d, chip %d:",i,j);
     302      for (int k=0; k<kNumberOfChannels; k++) m->PrintMessage(" %.2f",Target[i][j][k]);
     303      m->PrintMessage("\n\r");
     304    }
    300305}
    301306
     
    305310void HVFeedback::MeasureResponse(float U) {
    306311
    307   if (U==0) m->PrintMessage("HV Feedback: Error, voltage difference must not non-zero.\n");
    308   else {
    309     for (int i=m->FirstBoard; i<=m->LastBoard; i++)
    310       for (int j=0; j<kNumberOfChips; j++)
    311         for (int k=0; k<kNumberOfChannels-2; k++) {
    312           if(PixMap->DRS_to_Pixel(i,j,k).empty()) m->PrintMessage("Could not find pixel ID of board %d, chip %d, channel %d\n",i,j,k);
    313           else WriteHVCommand("hvdiff %s %f\n",PixMap->DRS_to_Pixel(i,j,k).c_str(), -U/2);
    314         }
    315     DiffVoltage = U;
    316     FBMode = FB_ResponseFirst;
    317     ClearAverages(); 
    318     m->PrintMessage("HV Feedback: Decreasing voltages by %f for response measurement, acquiring data.\n",DiffVoltage/2);
    319   }
     312  if (U==0) {
     313    m->PrintMessage("HV Feedback: Error, voltage difference must not non-zero.\n");
     314    return;
     315  }
     316
     317  for (int i=m->FirstBoard; i<=m->LastBoard; i++)
     318    for (int j=0; j<kNumberOfChips; j++)
     319      for (int k=0; k<kNumberOfChannels; k++) {
     320        if(!PixMap->DRS_to_Pixel(i,j,k).empty()) {
     321          WriteHVCommand("hvdiff %s %f\n",PixMap->DRS_to_Pixel(i,j,k).c_str(), -U/2);
     322        }
     323      }
     324  DiffVoltage = U;
     325  FBMode = FB_ResponseFirst;
     326  ClearAverages(); 
     327  m->PrintMessage("HV Feedback: Decreasing voltages by %f for response measurement, acquiring data.\n",DiffVoltage/2);
    320328}
    321329
     
    324332//
    325333void HVFeedback::GetResponse() {
    326   for (int i=m->FirstBoard; i<=m->LastBoard; i++)
    327     for (int j=0; j<kNumberOfChips; j++)
    328       for (int k=0; k<kNumberOfChannels; k++)
    329          m->PrintMessage("Board %d, chip %d, channel %d: %.3f\n",i,j,k,Response[i][j][k]);
     334  for (int i=m->FirstBoard; i<=m->LastBoard; i++) {
     335    for (int j=0; j<kNumberOfChips; j++) {
     336      m->PrintMessage("Board %d, chip %d:",i,j);
     337      for (int k=0; k<kNumberOfChannels; k++) m->PrintMessage(" %.3f",Response[i][j][k]);
     338      m->PrintMessage("\n\r");
     339    }
     340  }
    330341}
    331342
     
    336347  char Textbuffer[MAX_COM_SIZE];
    337348  fd_set SelectDescriptor;
    338   int RetryCount=0;
    339  
    340   do {
    341     va_list ArgumentPointer;  va_start(ArgumentPointer, Format);
    342     vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
    343 
    344     // Write command to socket
    345     if(write(SocketDescriptor, Textbuffer, strlen(Textbuffer)+1)!=(int) strlen(Textbuffer)+1) {
    346       m->PrintMessage("Error: Could not write (entire) command to HV socket (%s)\n", strerror(errno));
    347       return false;
    348     }
    349 
    350     // Wait for command acknowledge from hvcontrol program
    351     FD_ZERO(&SelectDescriptor);   FD_SET(SocketDescriptor, &SelectDescriptor);
    352     struct timeval WaitTime = {fMaxCmdAckDelay, 0};
    353     if (select(((int) SocketDescriptor)+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
    354       m->PrintMessage("Error with select() in command acknowledge (%s)\n", strerror(errno));
    355       return false;
    356     }
    357     if (!FD_ISSET(SocketDescriptor, &SelectDescriptor)) { // Time-out expired
    358       m->PrintMessage("Time-out of %d seconds expired before receiving acknowledge from HV socket.\n", fMaxCmdAckDelay);
    359       return false;
    360     }
    361     if (read(SocketDescriptor, Textbuffer, MAX_COM_SIZE) == -1) {
    362       m->PrintMessage("Error reading acknowledge from HV socket (%s)\n", strerror(errno));
    363       return false;
    364     }
    365   } while (strstr(Textbuffer,"WC ok")==NULL && ++RetryCount<=MAX_RETRY);
    366   if(RetryCount==MAX_RETRY) {
    367     m->PrintMessage("Could not set high voltage after %d tries.\n", MAX_RETRY);
     349 
     350  va_list ArgumentPointer;  va_start(ArgumentPointer, Format);
     351  vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
     352
     353  // Write command to socket
     354  if(write(SocketDescriptor, Textbuffer, strlen(Textbuffer)+1)!=(int) strlen(Textbuffer)+1) {
     355    m->PrintMessage("Error: Could not write (entire) command to HV socket (%s)\n", strerror(errno));
     356    return false;
     357  }
     358
     359  // Wait for command acknowledge from hvcontrol program
     360  FD_ZERO(&SelectDescriptor);   FD_SET(SocketDescriptor, &SelectDescriptor);
     361  struct timeval WaitTime = {fMaxCmdAckDelay, 0};
     362  if (select(((int) SocketDescriptor)+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
     363    m->PrintMessage("Error with select() in command acknowledge (%s)\n", strerror(errno));
     364    return false;
     365  }
     366 
     367  // Evaluate response
     368  if (!FD_ISSET(SocketDescriptor, &SelectDescriptor)) { // Time-out
     369    m->PrintMessage("Time-out of %d seconds expired before receiving acknowledge from HV socket.\n", fMaxCmdAckDelay);
     370    return false;
     371  }
     372  if (read(SocketDescriptor, Textbuffer, MAX_COM_SIZE) == -1) { // Could not read
     373    m->PrintMessage("Error reading acknowledge from HV socket (%s)\n", strerror(errno));
     374    return false;
     375  }
     376  if (strncmp(Textbuffer, "OK", 2) != 0) { // ERROR response
     377    m->PrintMessage("Did not received OK from hvcontrol.\n");
    368378    return false;
    369379  }
  • drsdaq/History.txt

    r92 r99  
    4848            configuration parameters are now mandatory: if one is not found, the
    4949            program terminates.
     505/8/2009    Streamlined DRS response calibration (removing unnecessary
     51            initialisation steps)
     5210/8/2009   Socket interface to hvcontrol only checks, if first reponse starts with
     53            'OK', otherwise assumes command to hvcontrol failed.
Note: See TracChangeset for help on using the changeset viewer.