ROOT logo
//*-- AUTHOR Bjoern Spruck
//*-- created : 24.03.06
// Modified for Wall by M.Golubeva 01.11.2006

using namespace std;
#include "hwallonehitf.h"
#include "hwallonehit.h"
#include "hwallrefwinpar.h"
#include "hwalldetector.h"
#include "hwallcalibrater.h"
#include "walldef.h"
#include "hwallraw.h"
#include "hwallcal.h"
#include "hwallcalpar.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 
////////////////////////////////////////////////////////////////
//
//  HWallHitFinder: select one hit from 4 cal hits
//
////////////////////////////////////////////////////////////////


void HWallOneHitF::initParContainer() {

  pWallRefWinPar = (HWallRefWinPar *)gHades->getRuntimeDb()
                                         ->getContainer("WallRefWinPar");
}

HWallOneHitF::HWallOneHitF(void)
{
   fCalCat        = 0;
   fOneHitCat     = 0;
   pWallRefWinPar = 0;
   iter           = 0;
   fLoc.set(1,-1);
}

HWallOneHitF::HWallOneHitF(const Text_t *name,const Text_t *title) :
   HReconstructor(name,title)
{
   fCalCat        = 0;
   fOneHitCat     = 0;
   pWallRefWinPar = 0;
   iter           = 0;
   fLoc.set(1,-1);
}

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

void HWallOneHitF::fillHit(HWallOneHit *hit, HWallCal *cal) {
}

Bool_t HWallOneHitF::init(void)
{
   initParContainer();

   HWallDetector* wall = (HWallDetector *)gHades->getSetup()->getDetector("Wall");

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

   fCalCat = gHades->getCurrentEvent()->getCategory(catWallCal);
   if (!fCalCat) return kFALSE;
   
   fOneHitCat = wall->buildCategory(catWallOneHit);
   if (!fOneHitCat) return kFALSE;
   else
   gHades->getCurrentEvent()->addCategory(catWallOneHit,fOneHitCat,"Wall");

   pWallRefWinPar = (HWallRefWinPar*)gHades->getRuntimeDb()->getContainer("WallRefWinPar");
   if (!pWallRefWinPar) return kFALSE;

   iter = (HIterator *)fCalCat->MakeIterator(); //change to cal when it will be created

   return kTRUE;
}

Int_t HWallOneHitF::execute(void)
{
   HWallCal *cal=0;
   HWallOneHit* hit = NULL;
   fLoc.set(1,-1);

   Float_t calTime,hitTime=-400;
   Float_t calADC,hitAdc=-400;

   // 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 ((cal = (HWallCal *)iter->Next()) != 0) {
      Int_t m = cal->getNHits(); // channel hit multiplicty

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

      fLoc[0] = cal->getCell();
      if(fLoc[0] == -1) continue;

      Float_t lower = pWallRefWinPar->getRefWinLow();
      Float_t upper = pWallRefWinPar->getRefWinHigh();

      for(Int_t i = 0; i < m; i ++){
	  hitTime = -400;
	  hitAdc  = -400;
	  calTime = cal->getTime(i+1);
	  calADC  = cal->getAdc(i+1);

	  if(calADC >= 0.0){
	      if(calTime >= lower && calTime <= upper) {
		  hitTime = calTime;
		  hitAdc  = calADC;
		  break;
	      }
	  }
      }

      hit = (HWallOneHit*) fOneHitCat->getSlot(fLoc);
      if(hit != NULL) {
	  hit = new(hit) HWallOneHit;
	  hit->setTime(hitTime);
	  hit->setCharge(hitAdc);
	  hit->setAddress(fLoc[0]);
	  fillHit(hit,cal);
      }
   }

  return 0;
}

ClassImp(HWallOneHitF)
 hwallonehitf.cc:1
 hwallonehitf.cc:2
 hwallonehitf.cc:3
 hwallonehitf.cc:4
 hwallonehitf.cc:5
 hwallonehitf.cc:6
 hwallonehitf.cc:7
 hwallonehitf.cc:8
 hwallonehitf.cc:9
 hwallonehitf.cc:10
 hwallonehitf.cc:11
 hwallonehitf.cc:12
 hwallonehitf.cc:13
 hwallonehitf.cc:14
 hwallonehitf.cc:15
 hwallonehitf.cc:16
 hwallonehitf.cc:17
 hwallonehitf.cc:18
 hwallonehitf.cc:19
 hwallonehitf.cc:20
 hwallonehitf.cc:21
 hwallonehitf.cc:22
 hwallonehitf.cc:23
 hwallonehitf.cc:24
 hwallonehitf.cc:25
 hwallonehitf.cc:26
 hwallonehitf.cc:27
 hwallonehitf.cc:28
 hwallonehitf.cc:29
 hwallonehitf.cc:30
 hwallonehitf.cc:31
 hwallonehitf.cc:32
 hwallonehitf.cc:33
 hwallonehitf.cc:34
 hwallonehitf.cc:35
 hwallonehitf.cc:36
 hwallonehitf.cc:37
 hwallonehitf.cc:38
 hwallonehitf.cc:39
 hwallonehitf.cc:40
 hwallonehitf.cc:41
 hwallonehitf.cc:42
 hwallonehitf.cc:43
 hwallonehitf.cc:44
 hwallonehitf.cc:45
 hwallonehitf.cc:46
 hwallonehitf.cc:47
 hwallonehitf.cc:48
 hwallonehitf.cc:49
 hwallonehitf.cc:50
 hwallonehitf.cc:51
 hwallonehitf.cc:52
 hwallonehitf.cc:53
 hwallonehitf.cc:54
 hwallonehitf.cc:55
 hwallonehitf.cc:56
 hwallonehitf.cc:57
 hwallonehitf.cc:58
 hwallonehitf.cc:59
 hwallonehitf.cc:60
 hwallonehitf.cc:61
 hwallonehitf.cc:62
 hwallonehitf.cc:63
 hwallonehitf.cc:64
 hwallonehitf.cc:65
 hwallonehitf.cc:66
 hwallonehitf.cc:67
 hwallonehitf.cc:68
 hwallonehitf.cc:69
 hwallonehitf.cc:70
 hwallonehitf.cc:71
 hwallonehitf.cc:72
 hwallonehitf.cc:73
 hwallonehitf.cc:74
 hwallonehitf.cc:75
 hwallonehitf.cc:76
 hwallonehitf.cc:77
 hwallonehitf.cc:78
 hwallonehitf.cc:79
 hwallonehitf.cc:80
 hwallonehitf.cc:81
 hwallonehitf.cc:82
 hwallonehitf.cc:83
 hwallonehitf.cc:84
 hwallonehitf.cc:85
 hwallonehitf.cc:86
 hwallonehitf.cc:87
 hwallonehitf.cc:88
 hwallonehitf.cc:89
 hwallonehitf.cc:90
 hwallonehitf.cc:91
 hwallonehitf.cc:92
 hwallonehitf.cc:93
 hwallonehitf.cc:94
 hwallonehitf.cc:95
 hwallonehitf.cc:96
 hwallonehitf.cc:97
 hwallonehitf.cc:98
 hwallonehitf.cc:99
 hwallonehitf.cc:100
 hwallonehitf.cc:101
 hwallonehitf.cc:102
 hwallonehitf.cc:103
 hwallonehitf.cc:104
 hwallonehitf.cc:105
 hwallonehitf.cc:106
 hwallonehitf.cc:107
 hwallonehitf.cc:108
 hwallonehitf.cc:109
 hwallonehitf.cc:110
 hwallonehitf.cc:111
 hwallonehitf.cc:112
 hwallonehitf.cc:113
 hwallonehitf.cc:114
 hwallonehitf.cc:115
 hwallonehitf.cc:116
 hwallonehitf.cc:117
 hwallonehitf.cc:118
 hwallonehitf.cc:119
 hwallonehitf.cc:120
 hwallonehitf.cc:121
 hwallonehitf.cc:122
 hwallonehitf.cc:123
 hwallonehitf.cc:124
 hwallonehitf.cc:125
 hwallonehitf.cc:126
 hwallonehitf.cc:127
 hwallonehitf.cc:128
 hwallonehitf.cc:129
 hwallonehitf.cc:130
 hwallonehitf.cc:131
 hwallonehitf.cc:132
 hwallonehitf.cc:133
 hwallonehitf.cc:134
 hwallonehitf.cc:135
 hwallonehitf.cc:136
 hwallonehitf.cc:137
 hwallonehitf.cc:138
 hwallonehitf.cc:139
 hwallonehitf.cc:140
 hwallonehitf.cc:141
 hwallonehitf.cc:142
 hwallonehitf.cc:143
 hwallonehitf.cc:144
 hwallonehitf.cc:145
 hwallonehitf.cc:146
 hwallonehitf.cc:147
 hwallonehitf.cc:148
 hwallonehitf.cc:149
 hwallonehitf.cc:150
 hwallonehitf.cc:151
 hwallonehitf.cc:152
 hwallonehitf.cc:153
 hwallonehitf.cc:154