Skip to content
Snippets Groups Projects
THcScintillatorPlane.cxx 48.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	Double_t timec_pos,timec_neg;
            timec_pos=tdc_pos;
            timec_neg=tdc_neg;
    
    	if(btdcraw_pos) {
    	  if(fTofUsingInvAdc) {
    	    timec_pos = tdc_pos*fScinTdcToTime
    	      - fHodoPosInvAdcOffset[index]
    	      - fHodoPosInvAdcAdc[index]/TMath::Sqrt(TMath::Max(20.0,adc_pos));
    	  } else {		// Old style
    	    timec_pos = tdc_pos*fScinTdcToTime - fHodoPosPhcCoeff[index]*
    	      TMath::Sqrt(TMath::Max(0.0,adc_pos/fHodoPosMinPh[index]-1.0))
    	      - fHodoPosTimeOffset[index];
    	  }
    
    	if(btdcraw_neg) {
    	  if(fTofUsingInvAdc) {
    	    timec_neg = tdc_neg*fScinTdcToTime
    	      - fHodoNegInvAdcOffset[index]
    	      - fHodoNegInvAdcAdc[index]/TMath::Sqrt(TMath::Max(20.0,adc_neg));
    	  } else {		// Old style
    	    timec_neg = tdc_neg*fScinTdcToTime - fHodoNegPhcCoeff[index]*
    	      TMath::Sqrt(TMath::Max(0.0,adc_neg/fHodoNegMinPh[index]-1.0))
    	      - fHodoNegTimeOffset[index];
    	  }
    
            ((THcHodoHit*) fHodoHits->At(fNScinHits))->SetPaddleCenter(fPosCenter[index]);
    
    	((THcHodoHit*) fHodoHits->At(fNScinHits))->SetCorrectedTimes(timec_pos,timec_neg,
    								     timec_pos,timec_neg,
    								     0.0);
    
    	//Define GoodTdcTimeCorr and GoodTdcTimeTOFCorr (a second time, since when only 1pmt fires, we cannot get TOFCorr)
    	fGoodPosTdcTimeCorr.at(padnum-1) = timec_pos;
    	fGoodNegTdcTimeCorr.at(padnum-1) = timec_neg;
    
    	fGoodPosTdcTimeTOFCorr.at(padnum-1) = timec_pos;
    	fGoodNegTdcTimeTOFCorr.at(padnum-1) = timec_neg;
    
          }
          fNScinHits++;		// One or more good time counter
    
    
          //	fTotNumGoodNegTdcHits++;
          //	fTotNumGoodTdcHits++;
    
          //	fNumGoodNegTdcHits.at(npad) = npad + 1;
    
    
          //   	fTotNumGoodPosTdcHits++;
          //	fTotNumGoodTdcHits++;
    
          //	fNumGoodPosTdcHits.at(npad) = npad + 1;
    
    
    
    Zafar's avatar
    Zafar committed
      //  cout << "THcScintillatorPlane: ihit = " << ihit << endl;
    
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
    //_____________________________________________________________________________
    Int_t THcScintillatorPlane::AccumulatePedestals(TClonesArray* rawhits, Int_t nexthit)
    {
    
    Mark Jones's avatar
    Mark Jones committed
      /*! \brief Extract the data for this plane from raw hit list THcRawHodoHit, accumulating into arrays for calculating pedestals.
    
    Mark Jones's avatar
    Mark Jones committed
       * - Loop through raw data for scintillator plane
       */
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
      Int_t nrawhits = rawhits->GetLast()+1;
      // cout << "THcScintillatorPlane::AcculatePedestals " << fPlaneNum << " " << nexthit << "/" << nrawhits << endl;
    
      Int_t ihit = nexthit;
      while(ihit < nrawhits) {
    
        THcRawHodoHit* hit = (THcRawHodoHit *) rawhits->At(ihit);
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
        if(hit->fPlane > fPlaneNum) {
          break;
        }
        Int_t element = hit->fCounter - 1; // Should check if in range
    
        Int_t adcpos = hit->GetRawAdcHitPos().GetPulseIntRaw();
        Int_t adcneg = hit->GetRawAdcHitNeg().GetPulseIntRaw();
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
    
        if(adcpos <= fPosPedLimit[element]) {
          fPosPedSum[element] += adcpos;
          fPosPedSum2[element] += adcpos*adcpos;
          fPosPedCount[element]++;
          if(fPosPedCount[element] == fMinPeds/5) {
    	fPosPedLimit[element] = 100 + fPosPedSum[element]/fPosPedCount[element];
          }
        }
        if(adcneg <= fNegPedLimit[element]) {
          fNegPedSum[element] += adcneg;
          fNegPedSum2[element] += adcneg*adcneg;
          fNegPedCount[element]++;
          if(fNegPedCount[element] == fMinPeds/5) {
    	fNegPedLimit[element] = 100 + fNegPedSum[element]/fNegPedCount[element];
          }
        }
        ihit++;
      }
    
      fNPedestalEvents++;
    
      return(ihit);
    }
    
    //_____________________________________________________________________________
    void THcScintillatorPlane::CalculatePedestals( )
    {
    
      /*! \brief   Calculate pedestals from arrays made in THcScintillatorPlane::AccumulatePedestals
       *
       * - Calculate pedestals from arrays made in THcScintillatorPlane::AccumulatePedestals
       * - In old fortran ENGINE code, a comparison was made between calculated pedestals and the pedestals read in by the FASTBUS modules for zero supression. This is not implemented.
       */
    
      for(UInt_t i=0; i<fNelem;i++) {
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
        // Positive tubes
        fPosPed[i] = ((Double_t) fPosPedSum[i]) / TMath::Max(1, fPosPedCount[i]);
        fPosThresh[i] = fPosPed[i] + 15;
    
        // Negative tubes
        fNegPed[i] = ((Double_t) fNegPedSum[i]) / TMath::Max(1, fNegPedCount[i]);
        fNegThresh[i] = fNegPed[i] + 15;
    
    
        //    cout <<"Pedestals "<< i+1 << " " << fPosPed[i] << " " << fNegPed[i] << endl;
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
      }
      //  cout << " " << endl;
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
    }
    
    //_____________________________________________________________________________
    void THcScintillatorPlane::InitializePedestals( )
    {
    
      /*! \brief   called by THcScintillatorPlane::ReadDatabase
       *
       * - Initialize variables used in  THcScintillatorPlane::AccumulatePedestals and THcScintillatorPlane::CalculatePedestals
       * - Minimum number of pedestal events needed for calculation, fMinPeds, hadrcoded to 500
       */
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
      fNPedestalEvents = 0;
      fMinPeds = 500; 		// In engine, this is set in parameter file
      fPosPedSum = new Int_t [fNelem];
      fPosPedSum2 = new Int_t [fNelem];
      fPosPedLimit = new Int_t [fNelem];
      fPosPedCount = new Int_t [fNelem];
      fNegPedSum = new Int_t [fNelem];
      fNegPedSum2 = new Int_t [fNelem];
      fNegPedLimit = new Int_t [fNelem];
      fNegPedCount = new Int_t [fNelem];
    
      fPosPed = new Double_t [fNelem];
      fNegPed = new Double_t [fNelem];
      fPosThresh = new Double_t [fNelem];
      fNegThresh = new Double_t [fNelem];
    
      for(UInt_t i=0;i<fNelem;i++) {
    
    Stephen A. Wood's avatar
    Stephen A. Wood committed
        fPosPedSum[i] = 0;
        fPosPedSum2[i] = 0;
        fPosPedLimit[i] = 1000;	// In engine, this are set in parameter file
        fPosPedCount[i] = 0;
        fNegPedSum[i] = 0;
        fNegPedSum2[i] = 0;
        fNegPedLimit[i] = 1000;	// In engine, this are set in parameter file
        fNegPedCount[i] = 0;
      }
    }
    
    //____________________________________________________________________________
    ClassImp(THcScintillatorPlane)
    ////////////////////////////////////////////////////////////////////////////////