Changeset 12891


Ignore:
Timestamp:
02/15/12 17:23:07 (13 years ago)
Author:
ogrimm
Message:
Added code for automized measurement of dynamic range, not yet tested
Location:
fact/FADctrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fact/FADctrl/FAD.cc

    r11385 r12891  
    4444   {"update", &FAD::cmd_update, false, 1, "<sec>", "Minimum delay between updates to DIM event service"},                 
    4545   {"socketmode", &FAD::cmd_socketmode, true, 1, "<com|daq>", "Choose which Sockets are used for data transmission"},                     
     46   {"dynrange", &FAD::cmd_dynrange, true, 0, "", "Determine dynamic range using calibration DAC"},
    4647   {"exit", &FAD::cmd_exit, false, 0, "", "Exit program"},
    4748   {"help", &FAD::cmd_help, false, 0, "", "Print help"}};
     
    612613
    613614//
     615// Determine dynamic range
     616//
     617void FAD::cmd_dynrange() {
     618
     619  // Set number of events required for measurement
     620  if (Parameter.size()==1 || !ConvertToInt(Parameter[1], &NumEventsRequested) || NumEventsRequested<=0) {
     621        NumEventsRequested = DEFAULT_NUM_CALIB_EVENTS;
     622  }
     623
     624  // Start calibration by setting mode
     625  Mode = dynrange;
     626  Message(INFO, "Starting determination of dynamic range with %d events", NumEventsRequested);
     627}
     628
     629
     630//
    614631// Print status
    615632//
     
    650667        else if (Mode == acalib) PrintMessage("Current mode is ACALIB (3x%d events, slowest board %d has %d events)\n", NumEventsRequested, SlowestBoard, MinCount);
    651668        else if (Mode == datarun) PrintMessage("Current mode is DATARUN (%d events requested, %d events taken)\n", NumEventsRequested, NumEvents);
     669        else if (Mode == dynrange) PrintMessage("Current mode is DYNRANGE (%d events requested)\n", NumEventsRequested);
    652670        return;
    653671  }   
     
    784802  }
    785803 
    786   if (Mode == acalib) {
     804  if (Mode == acalib || Mode == dynrange) {
    787805        Mode = idle;
    788806        Message(INFO, "Mode set to IDLE");
  • fact/FADctrl/FAD.h

    r11289 r12891  
    3131
    3232  public:
    33     enum ModeType {idle, datarun, acalib};
     33    enum ModeType {idle, datarun, acalib, dynrange};
    3434        ModeType Mode;
    3535
     
    8181        void cmd_phase();               void cmd_send();
    8282        void cmd_stop();                void cmd_update();
    83         void cmd_take();
     83        void cmd_take();                void cmd_dynrange();
    8484
    8585    void EnableDomino();
  • fact/FADctrl/FADBoard.cc

    r11458 r12891  
    723723  }
    724724}
     725
     726
     727
     728//
     729// Dynamic range determination
     730//
     731void FADBoard::DynamicRange() {
     732
     733  #if 0
     734  vector<unsigned short> ROICmd;
     735  unsigned short DACCmd[] = {htons(CMD_Write | (BADDR_DAC + 1)), 0, htons(CMD_Write | (BADDR_DAC + 2)), 0, htons(CMD_Write | (BADDR_DAC + 3)), 0, htons(CMD_Execute) };
     736  string Message = string("ACALIBDONE")+Name+"\n";
     737
     738  switch (StateDR) {
     739  // ====== Check if dynamic range measurement should start and initialise =====
     740  case standbye:
     741        if (m->Mode != m->dynrange) break;
     742
     743        // Save initial board status, and set all ROIs to 1024
     744        InitialStatus = GetStatus();
     745
     746        for (unsigned int i=0; i<NChips*NChannels; i++) {
     747          ROICmd.push_back(htons(CMD_Write | (BADDR_ROI + i)));
     748          ROICmd.push_back(htons(NBins));
     749        }
     750        ROICmd.push_back(htons(CMD_Execute));
     751        Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short));
     752
     753        // Start measurement
     754        DAC_DR = 0;
     755        StateDR = setdac;
     756        SetStatus("Starting dynamic range measurement");
     757        break;
     758
     759  // ====== Set calibration DAC =====
     760  case setdac:
     761        // Check for stopping
     762        if (m->Mode != m->dynrange) {
     763          StateDR = cleanup;
     764          break;
     765        }
     766
     767        if (DAC_DR > 66000) {
     768          StateDR = cleanup;
     769          break;
     770        }
     771
     772        // Set new DAC values
     773        DACCmd[1] = htons(DAC_DR);
     774        DACCmd[3] = htons(DAC_DR);
     775        DACCmd[5] = htons(DAC_DR);
     776        Send(DACCmd, sizeof(DACCmd));
     777
     778        StateDR = measure;
     779        break;
     780
     781  // ====== Determine mean and sigma =====
     782  case measure:
     783        // Check for stopping
     784        if (m->Mode != m->dynrange) {
     785          StateDR = cleanup;
     786          break;
     787        }
     788
     789        Mean = 0;
     790        Sigma = 0;
     791        for (unsigned int Chip=0; Chip<NChips; Chip++) {
     792          for (unsigned int Chan=0; Chan<NChannels; Chan++) {
     793                for (int i=0; i<Status.ROI[Chip][Chan]; i++) {
     794                  Mean += Data[Chip][Chan][i];
     795                  Sigma += Data[Chip][Chan][i]*Data[Chip][Chan][i];
     796                }
     797                Mean /= Status.ROI[Chip][Chan];
     798                Sigma = sqrt(Status.ROI[Chip][Chan]/(Status.ROI[Chip][Chan]-1)*(Sigma/Status.ROI[Chip][Chan]-Mean*Mean));               
     799          }
     800        }
     801       
     802        DAC_DR += 1000;
     803
     804        StateDR = setdac;
     805        break;
     806
     807  // ====== Write back original ROI and DAC settings =====
     808  case cleanup:
     809    // ROI values
     810        ROICmd.clear();
     811        for (unsigned int i=0; i<NChips*NChannels; i++) {
     812          ROICmd.push_back(htons(CMD_Write | (BADDR_ROI + i)));
     813          ROICmd.push_back(htons(InitialStatus.ROI[i/NChannels][i%NChannels]));
     814        }
     815        ROICmd.push_back(htons(CMD_Execute));
     816        Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short));
     817
     818        // DAC values
     819        DACCmd[1] = htons(InitialStatus.DAC[1]);
     820        DACCmd[3] = htons(InitialStatus.DAC[2]);
     821        DACCmd[5] = htons(InitialStatus.DAC[3]);
     822        Send(DACCmd, sizeof(DACCmd));
     823       
     824        StateDR = wait;
     825        break;
     826
     827  // ====== Wait for Mode not being idle =====
     828  case wait:
     829        if (m->Mode == m->idle) StateDR = standbye;
     830        break;
     831  }
     832  #endif
     833
  • fact/FADctrl/FADBoard.h

    r11385 r12891  
    9696        void Lock();
    9797        void Unlock();
     98        void DynamicRange();
    9899
    99100        unsigned short Port;
Note: See TracChangeset for help on using the changeset viewer.