//*-- AUTHOR Bjoern Spruck
//*-- created : 24.03.06

using namespace std;
#include "hhododetector.h"
#include "hhodocalibrater.h"
#include "hododef.h"
#include "hhodoraw.h"
#include "hhodocal.h"
#include "hhodocalpar.h"
#include "hhodorefhitpar.h"
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hevent.h"
#include "hcategory.h"
#include <iostream>
#include <iomanip>

//_HADES_CLASS_DESCRIPTION 
////////////////////////////////////////////////////////////////
//
//  HHodoCalibrater: perform global correction on the data
//
////////////////////////////////////////////////////////////////


 HHodoCalibrater::HHodoCalibrater(void)
{
   rawCat=0;
   calCat=0;
   iter=0;
   calpar=0;
}

 HHodoCalibrater::HHodoCalibrater(Text_t *name,Text_t *title) :
   HReconstructor(name,title)
{
   rawCat=0;
   calCat=0;
   iter=0;
   calpar=0;
}

 HHodoCalibrater::~HHodoCalibrater(void)
{
   if (iter) delete iter;
   iter=0;
}

 Bool_t HHodoCalibrater::init(void)
{
   HHodoDetector *hodo;
   hodo=(HHodoDetector *)gHades->getSetup()->getDetector("Hodo");

   if(!hodo){
      Error("init","No Hodo Det. found.");
      return kFALSE;
   }

   // Categories
   rawCat=hodo->buildCategory(catHodoRaw);
   if (!rawCat) return kFALSE;
   calCat=hodo->buildCategory(catHodoCal);
   if (!calCat) return kFALSE;

   // Parameters
   calpar=(HHodoCalPar*)gHades->getRuntimeDb()->getContainer("HodoCalPar");
   if (!calpar) return kFALSE;
   refhit=(HHodoRefHitPar*)gHades->getRuntimeDb()->getContainer("HodoRefHitPar");
   if (!refhit) return kFALSE;

   iter=(HIterator *)rawCat->MakeIterator();
   loc.set(2,0,0);
   fActive=kTRUE;

   return kTRUE;
}

 Int_t HHodoCalibrater::execute(void)
{
   HHodoRaw *raw=0;
   HHodoCal *cal=0;
   Int_t mod=0, strip=0;

   Float_t rawTime;
   Float_t rawADC;

   // Do the calibration here

   // Multiplicity checks i would postphone to hitfinder...

   // But how do we handle cases with tdc channel mult>4?
   // same question applies to what to do if hits were rejected by TDC itself -> see unpacker
   // maybe this should go to the raw category...

   //Fill cal category
   iter->Reset();
   while ((raw=(HHodoRaw *)iter->Next())!=0) {
      Int_t m;// channel hit multiplicty

      m=raw->getNHits();
      if(m<=0) continue;// No Hits -> forget it

      raw->getAddress(mod,strip);
      loc[0] = mod; loc[1] = strip;

      cal=(HHodoCal*)calCat->getSlot(loc);
      if (cal) {
         cal=new (cal) HHodoCal;
         if ( !cal ) return EXIT_FAILURE;

         cal->setAddress(mod,strip);// What happens if no hit is filled in? At least mod and strip are !=-1

         HHodoCalParChan &pPar=(*calpar)[mod][strip];

         HHodoRefHitParMod &pRefHit=(*refhit)[mod];
         Float_t lower, upper;
         lower=pRefHit.getHitLow();// Misuse ... rename function and variable
         upper=pRefHit.getHitHigh();

         if(m>raw->getMaxMult()) m=raw->getMaxMult();

         for(Int_t i=0; i<m; i++){
            rawTime  = raw->getTime(i+1);
            rawADC  = raw->getADC(i+1);
            if(rawADC>=0.0){
               // This throws away hits without trailing data... (spikes?)
               Float_t adc, time;
               time=pPar.getTDCSlope()*(rawTime+pPar.getTDCOffset());// First add/substract, then multiply
               if(time>=lower && time<=upper){// Time window after calibration
                  adc= pPar.getADCSlope()*(rawADC +pPar.getADCOffset());// In start it is done the other way around
                  cal->setTimeAdc(time,adc);
               }
               // How to do "double-hit" time shift?
               // Is it really needed for the beamtime?
               // Think about it
            }
         }
         // dont fill multiplicity information here
         // maybe set an overflow flag if necessary...
         // idea behind it... high multiplicity might come from spikes AFTER the signal
         // -> not of interest
      }
   }

   return EXIT_SUCCESS;
}

ClassImp(HHodoCalibrater)


ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.