Пример #1
0
Файл: adcsum.c Проект: UCNA/main
INT adc_summing(EVENT_HEADER *pheader, void *pevent)
{
  INT          i, n_adc;
  float        *cadc;
  ASUM_BANK    *asum;

  /* look for CADC bank, return if not present */
  n_adc = bk_locate(pevent, "CADC", &cadc);
  if (n_adc == 0)
    return 1;

  /* create ADC sum bank */
  bk_create(pevent, "ASUM", TID_STRUCT, &asum);

  /* sum all channels above threshold */
  asum->sum = 0.f;
  for (i=0 ; i<n_adc ; i++)
    asum->sum += cadc[i];

#ifdef MANA_LITE
 printf("manalite: adc_summing: HBOOK disable\n");
#else
  /* fill sum histo */
  HF1(ADCSUM_ID_BASE, asum->sum, 1.f);
#endif

  /* close calculated bank */
  bk_close(pevent, asum+1);
  
  return SUCCESS;
}
Пример #2
0
INT adc_summing(EVENT_HEADER * pheader, void *pevent)
{
   INT i, j, n_adc;
   float *cadc;
   ASUM_BANK *asum;

   /* look for CADC bank, return if not present */
   n_adc = bk_locate(pevent, "CADC", &cadc);
   if (n_adc == 0)
      return 1;

   /* create ADC sum bank */
   bk_create(pevent, "ASUM", TID_STRUCT, &asum);

   /* sum all channels above threashold */
   asum->sum = 0.f;
   for (i = j = 0; i < n_adc; i++)
      if (cadc[i] > adc_summing_param.adc_threshold) {
         asum->sum += cadc[i];
         j++;
      }

   /* calculate ADC average */
   asum->average = j > 0 ? asum->sum / j : 0;

   /* fill sum histo */
   HF1(ADCSUM_ID_BASE, asum->sum, 1.f);

   /* close calculated bank */
   bk_close(pevent, asum + 1);

   return SUCCESS;
}
Пример #3
0
INT temp_copy(EVENT_HEADER * pheader, void *pevent)
{
   INT end, start, n;
   float *pin;
   float *pout;

   /* look for temp bank */
   n = bk_locate(pevent, "INPT", &pin);
   if (n == 0)
      return 1;

   /* create  bank */
   bk_create(pevent, "TEMP", TID_FLOAT, &pout);

   //set copy bounds indicies
   start =0; end =4; 

   /* copy partial bank*/
   for (INT i = start; i < end; i++) {
	if ( i >= n ) continue;
     	pout[i] = (float) pin[i] ;
	//printf("%d %f\n",i,pout[i]);
   }
	probe1->Fill(pheader->time_stamp,pout[0]);
	probe2->Fill(pheader->time_stamp,pout[1]);
        probe3->Fill(pheader->time_stamp,pout[2]);

   /* close bank */
   bk_close(pevent, pout + (end-start));

   return SUCCESS;
}
Пример #4
0
/*-- event routine -------------------------------------------------*/
INT adc_event(EVENT_HEADER * pheader, void *pevent)
{
   INT i, nwords;
   DWORD *padc;
   float *adc = new float[32*ADCModules];  // NOTE: in Parameters.C there is ADCInit routine that sets size of array ADC to 32*ADCModules
					   // If for some reason you set the nr of ADCs in the config file as smaller than what it really
					   // is then the arrays adc[] and ADC[] will have size of zero
   int adcchan,adcnr;
   extern int adc_counter1, adc_counter2;   // defined; declared in analyzer.c
   int adcnrtest;

   /* look for ADC0 bank, return if not present */
   nwords=bk_locate(pevent, "ADC0", &padc);
   adc_counter1++;
   if (nwords==0){
      adc_counter2++;
      return 1;
   }

   for (i = 0; i < nwords; i++){
        //printf("-------raw data 0x%08x  Nr of words %d \n",padc[i],nwords); 
        if(((padc[i]>>24)&0xff) ==0xfd) {
           if((padc[i]&0xf) ==0) adcnr=0;  // printf(" adc nr 0 \n");}
           if((padc[i]&0xf) ==1) adcnr=1;  // printf(" adc nr 1 \n");}
           if((padc[i]&0xf) ==2) adcnr=2;  // printf(" adc nr 2 \n");} 
           if((padc[i]&0xf) ==3) adcnr=3;  // printf(" adc nr 3 \n");}
           if((padc[i]&0xf) ==4) adcnr=4;  // printf(" adc nr 4 \n");}
	   if((padc[i]&0xf) ==5) adcnr=5;  // printf(" adc nr 5 \n");}
	   if((padc[i]&0xf) ==6) adcnr=6;  // printf(" adc nr 6 \n");}
	   if((padc[i]&0xf) ==7) adcnr=7;  // printf(" adc nr 7 \n");}
	   if((padc[i]&0xf) ==8) adcnr=8;  // printf(" adc nr 8 \n");}
	   //printf("\n-----raw data 0x%08x ->  data %d adcnr %i \n",padc[i],(padc[i]&0x0fff),adcnr); 
	}
	if(((padc[i]>>24)&0x7) ==0){     // if not then they are not data but header words.
	    adcchan=((padc[i])>>16)&0x1f;
            adcchan=adcchan + adcnr*32;
	    if(adcchan<ADCModules*32)   adc[adcchan] =(float)(padc[i]&0x0fff);  // this test necessary to ensure no problems when
										// nr of ADCs were wrongly given in the config file
            //printf("raw data 0x%08x -> chan %d, data %d, adcnr %i, 32*adcnr %d, diff %d\n",padc[i],adcchan,(padc[i]&0x0fff),adcnr,32*adcnr,adcchan-32*adcnr);
          
            /* fill basic ADC histos */
	    if(adcchan<ADCModules*32)   hADC2DModule[adcnr]->Fill(adc[adcchan],adcchan-32*adcnr);
	}

   }
   //adcevtcount=padc[33]&0xfffff;  // take event counter in the trailer, the 34th word, to f-plane to compare to TDC counter 
   for(i=0; i<ADCsize;i++){
       ADC[i] = 0;		    // Clear out the ADC values - should always be resetting the values because 
				    // we have pedestals but it's worth being proper about it.
       if (adc[i] > 0.0) {  
	   ADC[i]=adc[i];                 // if ( adc[i] > (float) adc_param.histogram_threshold )
       }
   }      


//   printf("Got to SUCCESS in adc.c\n");
   return SUCCESS;
}
Пример #5
0
INT adc_summing(EVENT_HEADER * pheader, void *pevent)
{
   INT i, j, n_adc;
   float *cadc;
   ASUM_BANK *asum;

   /* look for CADC bank, return if not present */
   n_adc = bk_locate(pevent, "CADC", &cadc);
   if (n_adc == 0)
      return 1;

   /* create ADC sum bank */
   bk_create(pevent, "ASUM", TID_STRUCT, &asum);

   /* sum all channels above threashold */
   asum->sum = 0.f;
   for (i = j = 0; i < n_adc; i++)
      if (cadc[i] > adc_summing_param.adc_threshold) {
         asum->sum += cadc[i];
         j++;
      }

   /* calculate ADC average */
   asum->average = j > 0 ? asum->sum / j : 0;

   /* evaluate tests */
   SET_TEST(low_sum, asum->sum < 1000);
   SET_TEST(high_sum, asum->sum > 1000);

   /* fill sum histo */
   hAdcSum->Fill(asum->sum, 1);

   /* fill average histo */
   hAdcAvg->Fill(asum->average);

   /* close calculated bank */
   bk_close(pevent, asum + 1);

   return SUCCESS;
}
Пример #6
0
/** 
 * @brief Event routine. 
 * @details This routine is called on every MIDAS event.
 * 
 * @param pheader pointer to MIDAS event header
 * @param pevent  pointer to MIDAS event
 * 
 * @return SUCCESS
 */
INT module_event(EVENT_HEADER * pheader, void *pevent)
{
   WORD *pdata;

   // clear old data
   /*for (unsigned int iboard=1; iboard<=SIS3350_NUMBER_OF_BOARDS; iboard++)	 
       for (unsigned int ichannel=1; ichannel<=SIS_3350_CH; ichannel++)
	 {	     
	   //trace[iboard][ichannel] = 0;
	 }
   */
   
   
   // Loop over all SIS3350 MODULES in the experiment
   for (unsigned int i_board=1; i_board<=SIS3350_NUMBER_OF_BOARDS; i_board++)
     {
       char bank_name[8];
       sprintf(bank_name,"SF%02d",i_board-1);
     
       unsigned int bank_len = bk_locate(pevent, bank_name, &pdata);
       if ( bank_len == 0 ) 
	 {
	   /** \todo handle errors */
	   printf("ERROR! Cannot find bank [%s]\n",bank_name);
	   continue;
	 }
       printf("bank [%s] size %d\n",bank_name,bank_len);
       Int_t np = gr_bk_size[i_board]->GetN();
       gr_bk_size[i_board]->SetPoint(np,pheader->serial_number,bank_len);


       // loop over all ADC words 
       unsigned int iw = 0;  // data counter
       while ( iw < bank_len )
	 {
	   
	   for(unsigned int k=0;k<SIS_3350_CH;k++){
	     //unsigned int j = 0;
	     //WORD *adc = pdata+iw;
	     int adc = pdata[iw++];

	     for(int j=0;j<vme_trace_length;j++)
	       {
		 //br_sis.trace[k][j] = (UShort_t)pdata[iw++];
		 br_sis.trace[k][j] = (UShort_t)adc;
		 h2_wf[i_board-1][k]->Fill(j+1,adc);
	       }	   
	     
	     
	     br_sis.timestamp = 0;
	     br_sis.is_bad_event = 0;
	     t->Fill();
	   }
	   
	   //iw += vme_trace_length;
	 }
       /*
	 for(int i_ch=0;i_ch<4;i_ch++){
	 int j = 0;
	 WORD *adc = pdata++;
	 while ( j < vme_trace_length)
	 {
       br_sis.trace[i_ch][j] = adc[j];
       j++;
       }
       }
       br_sis.timestamp = 0;
       br_sis.is_bad_event = 0;
       t->Fill();*/
     }
   
   return SUCCESS;
}
Пример #7
0
INT MMuPC1AnalysisC(EVENT_HEADER *pheader, void *pevent)
{
  /* ############################################### */
  // Open up the bank "HITS" (contains CAEN & COMP hits by parameter #)
  channel_hit *hit_bank;
  int hit_bank_size = bk_locate(pevent, "HITS", (DWORD *) &hit_bank);
  hit_bank_size = hit_bank_size * sizeof(DWORD) / sizeof(channel_hit);
  if(hit_bank == NULL) {
    fprintf(stderr, "MMuPC1AnalysisC: Could not find bank HITS.\n");
    return !SUCCESS;
  }

  /* ############################################### */

  // Initialize the "previous hit" indices
  int prev_hit_index_muPC1_Xwire[kMuPC1NumXWires+1];
  for (int j=1; j<=kMuPC1NumXWires; j++) {
    prev_hit_index_muPC1_Xwire[j] = -1;
  }
  int prev_hit_index_muPC1_Ywire[kMuPC1NumYWires+1];
  for (int j=1; j<=kMuPC1NumYWires; j++) {
    prev_hit_index_muPC1_Ywire[j] = -1;
  }

  // Loop over hits within hit_bank and fill muPC1 raw data histograms
  for (int i=0; i<hit_bank_size; i++) {
    int par = hit_bank[i].parameter;

    // Xwires
    if ((par >= 4001) && (par <= (4000+kMuPC1NumXWires))) {
      int wire = (par-4000);
      // tdiffs between successive Xwire hits, per wire
      if (prev_hit_index_muPC1_Xwire[wire] >= 0) {
	muPC1_Xwire_successive_tdiffs->Fill((hit_bank[i].time -
					     hit_bank[prev_hit_index_muPC1_Xwire[wire]].time),
					    wire);
      }
      prev_hit_index_muPC1_Xwire[wire] = i;
      // 2D Xwire hits vs. time
      //      muPC1_XwireVStime_2D->Fill(hit_bank[i].time, wire);
    }

    // Ywires
    if ((par >= 4051) && (par <= (4050+kMuPC1NumYWires))) {
      int wire = (par-4050);
      // tdiffs between successive Ywire hits, per wire
      if (prev_hit_index_muPC1_Ywire[wire] >= 0) {
	muPC1_Ywire_successive_tdiffs->Fill((hit_bank[i].time -
					     hit_bank[prev_hit_index_muPC1_Ywire[wire]].time),
					    wire);
      }
      prev_hit_index_muPC1_Ywire[wire] = i;
      // 2D Ywire hits vs. time
      //      muPC1_YwireVStime_2D->Fill(hit_bank[i].time, wire);
    }
  }

  /* ############################################### */

  return SUCCESS;
}
Пример #8
0
/*-- event routine -------------------------------------------------*/
INT epics_event(EVENT_HEADER * pheader, void *pevent)
{
   INT n, i;
   DWORD *pepics;

   // look for midas bank 
   n = bk_locate(pevent, "Beamline", &pepics);   // n = number of data words in epics bank
   if (n == 0)  return 1;
   //printf("number of data words in epics bank = %d \n",n);

   /*   
   printf("                                    readout %d:",counter);
   */   

   /*
   for(int i=0; i<n;i++){
     //printf(" %d ",pepics[i]);
     printf("epics nr= %d  ,  value= %d \n",i,pepics[i]);
   }
   */
   //printf("%d  ,  %d \n",pepics[0],pepics[9]);


   //  This causes problems; analyzer crash  ??
   /*
   for (i = 0; i < n; i++) {  
     //epics[i]=pepics[i]-oldepics[i];  // The following is valid for epicss NOT cleared after every event    
     //oldepics[i]=pepics[i];            // The following is valid for epicss NOT cleared after every event    
     epics[i]=pepics[i];     //  This valid if the epicss are cleared after every readout.
   }
   */


   for(int i=0; i<n;i++){
     if(pepics[i]>5000) pepics[i]=5000;
   }

   /*
   for(int j = 0; j <pepics[0]; j++) {
     hTriggerU->Fill(counter);
   }
   for(int j = 0; j <pepics[9] ; j++) {
     hTriggerI->Fill(counter);
   }
   for(int j = 0; j <pepics[1]; j++) {
     hPulserU->Fill(counter);
   }
   for(int j = 0; j <pepics[10] ; j++) {
     hPulserI->Fill(counter);
   }
   for(int j = 0; j <pepics[2]; j++) {
     hCIU->Fill(counter);
   }
   for(int j = 0; j <pepics[11] ; j++) {
     hCII->Fill(counter);
   }
   for(int j = 0; j <pepics[3]; j++) {
     hClockU->Fill(counter);
   }
   for(int j = 0; j <pepics[12] ; j++) {
     hClockI->Fill(counter);
   }

   for(int j = 0; j <pepics[4] ; j++) {
     hBLM1->Fill(counter);
   }
   for(int j = 0; j <pepics[5] ; j++) {
     hBLM2->Fill(counter);
   }
   for(int j = 0; j <pepics[6] ; j++) {
     hBLM3->Fill(counter);
   }
   for(int j = 0; j <pepics[7] ; j++) {
     hBLM4->Fill(counter);
   }
   for(int j = 0; j <pepics[8] ; j++) {
     hBLM5->Fill(counter);
   }
   */

   //printf("counter = %d \n",counter);
   counter += 1;
   if(counter==7200) counter=1;  // after 7200sec start filling the spectrum from chan0



   return SUCCESS;
}
Пример #9
0
INT envi_copy(EVENT_HEADER * pheader, void *pevent)
{

    INT end, start, n;
    float *pin;
    float *pout;

    /* look for envi bank */
    n = bk_locate(pevent, "INPT", &pin);
    if (n == 0)
        return 1;

    /* create  bank */
    bk_create(pevent, "TEMP", TID_FLOAT, &pout);

    //set copy bounds indicies
    start =0;
    end =11;

    /* copy partial bank*/
    for (INT i = start; i < end; i++) {
        if ( i >= n ) continue;
        pout[i] = (float) pin[i] ;
        //printf("%d %f\n",i,pout[i]);

    }

    probe1->Fill(pout[0]);
    probe2->Fill(pout[1]);
    probe3->Fill(pout[2]);
    probe4->Fill(pout[3]);
    probe5->Fill(pout[4]);
    probe6->Fill(pout[5]);
    probe7->Fill(pout[6]);
    probe8->Fill(pout[7]);

    capac1->Fill(pout[8]);
    capac2->Fill(pout[9]);
    capac3->Fill(pout[10]);
    capac4->Fill(pout[11]);

    /* close bank */
    bk_close(pevent, pout + (end-start));

    gData->tStamp = pheader->time_stamp;
    gData->p1val = pout[0];
    gData->p2val = pout[1];
    gData->p3val = pout[2];
    gData->p4val = pout[3];
    gData->p5val = pout[4];
    gData->p6val = pout[5];
    gData->p7val = pout[6];
    gData->p8val = pout[7];
    gData->c1val = pout[8];
    gData->c2val = pout[9];
    gData->c3val = pout[10];
    gData->c4val = pout[11];

    fEventTree->Fill();

    return SUCCESS;
}