Changeset 99
- Timestamp:
- 08/12/09 12:01:25 (15 years ago)
- Location:
- drsdaq
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
drsdaq/DAQReadout.cc
r92 r99 25 25 {{"board", &DAQReadout::cmd_board, true, "<i> [j] | <all>" ,"Address board i, boards i-j, all boards"}, 26 26 {"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"}, 29 29 {"trigger", &DAQReadout::cmd_trigger, true, "<on|off>", "Hardware trigger on or off"}, 30 30 {"delayed", &DAQReadout::cmd_delayed, true, "<on|off>", "Switch delayed start on or off"}, … … 220 220 // Print current number of events 221 221 void DAQReadout::cmd_events() { 222 if(daq_state != active) PrintMessage("DAQ not active .\n");222 if(daq_state != active) PrintMessage("DAQ not active\n"); 223 223 else PrintMessage("Current number of events: %d (of %d requested)\n", NumEvents, NumEventsRequested); 224 224 } … … 234 234 if(!Match(Param[1],"test")) { 235 235 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"); 237 237 return; 238 238 } … … 244 244 245 245 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"); 247 247 return; 248 248 } … … 333 333 else if (Match(Param[1], "blt64")) Type = 1; 334 334 else { 335 PrintMessage("Unknown type for testing .\n");335 PrintMessage("Unknown type for testing\n"); 336 336 return; 337 337 } … … 448 448 char str[MAX_COM_SIZE]; 449 449 450 if (NParam!= 3 || !atof(Param[1]) || !atof(Param[2])) {450 if (NParam!=2 || !atof(Param[1])) { 451 451 PrintUsage(); 452 return; 453 } 454 if (!IsDRSFreqSet()) { 455 PrintMessage("Set sampling frequency first\n"); 452 456 return; 453 457 } … … 455 459 getcwd(str, sizeof(str)); 456 460 strcat(str,"/calib"); 457 PrintMessage("Writing calibration data to directory '%s'\n",str);458 461 459 462 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()); 465 464 466 465 drs->GetBoard(i)->EnableTcal(1); 467 PrintMessage("Tcal enabled\n");468 469 466 if (drs->GetBoard(i)->GetChipVersion() == 3) drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,21,0,20,0,0,0,0,0); 470 467 else drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,36,110,20,19,40,15,atof(Param[1]),0); 471 468 drs->GetBoard(i)->SetCalibrationDirectory(str); 472 469 473 for (int j=0; j< 2; j++) {470 for (int j=0; j<kNumberOfChips; j++) { 474 471 drs->GetBoard(i)->GetResponseCalibration()->ResetCalibration(); 475 PrintMessage("Calibration reset done.\n");476 472 477 473 while (!drs->GetBoard(i)->GetResponseCalibration()->RecordCalibrationPoints(j)) {} 478 PrintMessage("Record calibration points done.\n"); 474 PrintMessage("Calibration points recorded.\n"); 475 479 476 while (!drs->GetBoard(i)->GetResponseCalibration()->FitCalibrationPoints(j)) {} 480 477 PrintMessage("Calibration points fitted.\n"); 478 481 479 while (!drs->GetBoard(i)->GetResponseCalibration()->OffsetCalibration(j)) {} 482 480 PrintMessage("Offset calibration done.\n"); … … 484 482 if (!drs->GetBoard(i)->GetResponseCalibration()->WriteCalibration(j)) break; 485 483 } 486 drs->GetBoard(i)->Init(); // Reset linear range -0.2 ... 0.8 V487 484 } // Loop over boards 485 PrintMessage("End of calibration\n"); 486 CalibrationRead = false; 488 487 } 489 488 … … 737 736 } 738 737 739 // Check if calibration file has been read740 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 752 738 // Stop DAQ 753 739 void DAQReadout::StopRun() { -
drsdaq/DAQReadout.h
r92 r99 123 123 void HWTrigger(int); 124 124 bool ReadCalibration(); 125 bool IsCalibrationRead();126 125 void ReadCalibratedDRSData(); 127 126 void PrintConfig(int); … … 136 135 137 136 void DAQ(DAQReadout *); 137 138 138 bool Match(const char*, const char*); 139 139 int ParseInput(char*, const char *Param[]); -
drsdaq/HVFeedback.cc
r92 r99 16 16 #include <signal.h> 17 17 18 #define MAX_RETRY 519 18 #define PIXMAP_LOCATION "../config/PixelMap.txt" 20 19 … … 64 63 ReadCard("MaxCmdAckDelay", &fMaxCmdAckDelay, 'I', File); 65 64 ReadCard("DefaultResponse", Response, 'f', File, m->NumBoards*kNumberOfChips*kNumberOfChannels); 65 ReadCard("DefaultTarget", Target, 'f', File, m->NumBoards*kNumberOfChips*kNumberOfChannels); 66 66 fclose(File); 67 67 } … … 115 115 116 116 // 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) 118 118 return false; 119 119 … … 123 123 for (k=0; k<kNumberOfChannels; k++) { 124 124 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; 126 126 Integral /= 2*fIntHalfWidth+1; 127 127 Average[i][j][k] += Integral; … … 129 129 } 130 130 131 // Check if acquired number of event requires action 131 132 if (++Count<NumAverages) return false; 132 133 133 // Acquired number of event requires action134 // Make entry in slow data file 134 135 switch (FBMode) { 135 136 case FB_Active: SlowDataClass->NewEntry("Average"); … … 143 144 } 144 145 146 // Feedback action 145 147 for (i=m->FirstBoard; i<=m->LastBoard; i++) { 146 148 for (j=0; j<kNumberOfChips; j++) { … … 153 155 EffectiveGain = Gain*pow(0.5*(1+(Difference/Sigma[i][j][k]-1)/(Difference/Sigma[i][j][k]+1)),2); 154 156 Correction = -Difference*Response[i][j][k]*EffectiveGain; 157 if (fabs(Correction) > 0.1) Correction = fabs(Correction)/Correction*0.1; // Limit changes to 100 mV 155 158 if(Correction!=0 && Target[i][j][k]!=0 && !PixMap->DRS_to_Pixel(i,j,k).empty()) { 156 159 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); … … 261 264 262 265 // 263 // Set feedback mode and clear averages266 // Get feedback mode 264 267 // 265 268 FBState HVFeedback::GetFBMode() { … … 295 298 void HVFeedback::GetTargets() { 296 299 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 } 300 305 } 301 306 … … 305 310 void HVFeedback::MeasureResponse(float U) { 306 311 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); 320 328 } 321 329 … … 324 332 // 325 333 void 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 } 330 341 } 331 342 … … 336 347 char Textbuffer[MAX_COM_SIZE]; 337 348 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"); 368 378 return false; 369 379 } -
drsdaq/History.txt
r92 r99 48 48 configuration parameters are now mandatory: if one is not found, the 49 49 program terminates. 50 5/8/2009 Streamlined DRS response calibration (removing unnecessary 51 initialisation steps) 52 10/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.