ROOT logo
//*-- AUTHOR : Dusan Zovinec (23.10.2002)

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// HTofClusterFSim                                                           //
// This class is derived from HTofClusterF and passes track numbers of the   //
// HGeant cluster from hit to cluster level                                  //
///////////////////////////////////////////////////////////////////////////////

#include "htofclusterfsim.h"
#include "hdebug.h"
#include "hades.h"
#include "hspectrometer.h"
#include "htofdetector.h"
#include "hevent.h"
#include "hcategory.h"
#include "hiterator.h"
#include "hlocation.h"
#include "htofhitsim.h"
#include "htofclustersim.h"


#include <vector>
#include <algorithm>
#include <iostream>

ClassImp(HTofClusterFSim)

HTofClusterFSim::~HTofClusterFSim(void) {
}

Bool_t HTofClusterFSim::init(void) {
 // initialization of fHitCat and fClusterCat containers
 initParContainer(gHades->getSetup(),gHades->getRuntimeDb());
 fHitCat =gHades->getCurrentEvent()->getCategory(catTofHit);
  if (!fHitCat) {
    HTofDetector* tof=(HTofDetector*)(gHades->getSetup()->getDetector("Tof"));
    fHitCat=tof->buildMatrixCategory("HTofHitSim",0.5F);
    if (!fHitCat) return kFALSE;
    else gHades->getCurrentEvent()->addCategory(catTofHit,fHitCat,"Tof");
  } else {
    if (fHitCat->getClass()!=HTofHitSim::Class()) {
      Error("HTofClusterFSim::init()","Misconfigured input category");
      return kFALSE;
    }
  }
  iterh = (HIterator*)fHitCat->MakeIterator();

  fClusterCat=gHades->getCurrentEvent()->getCategory(catTofCluster);
  if (!fClusterCat) {
    HTofDetector* tof=(HTofDetector*)(gHades->getSetup()->getDetector("Tof"));
    fClusterCat=tof->buildMatrixCategory("HTofClusterSim",0.5F);
    if (!fClusterCat) return kFALSE;
    else gHades->getCurrentEvent()->addCategory(catTofCluster,fClusterCat,"Tof");
  } else {
    if (fClusterCat->getClass()!=HTofClusterSim::Class()) {
      Error("HTofClusterFSim::init()","Misconfigured output category");
      return kFALSE;
    }
  }
  iterc = (HIterator*)fClusterCat->MakeIterator();

  fActive = kTRUE;
  return kTRUE;
  }


Int_t  HTofClusterFSim::execute() {
// This method executes HTofClusterF::execute() and moreover
// it copies the track numbers from the hit to the cluster level containers

  HTofClusterF::execute();  // do work for real data part

  HTofHitSim *hit=NULL;
  HTofClusterSim *cluster=NULL;

  vector <Int_t> ntrack;
  iterh->Reset();
  iterc->Reset();
  while((cluster = (HTofClusterSim*)iterc->Next()) != NULL) {
    fCLoc[0]=cluster->getSector();
    fCLoc[1]=cluster->getModule();
    fCLoc[2]=cluster->getCell();
    cluster->clear();
    cluster->setNParticipants(1);

    ntrack.clear();
    for(Int_t i = 0; i < cluster->getClusterSize(); i ++){
      hit = (HTofHitSim*)iterh->Next();

      if(find(ntrack.begin(),ntrack.end(),hit->getNTrack1()) == ntrack.end()) ntrack.push_back(hit->getNTrack1());
      if(find(ntrack.begin(),ntrack.end(),hit->getNTrack2()) == ntrack.end()) ntrack.push_back(hit->getNTrack2());

    }
    sort(ntrack.begin(),ntrack.end());

    if(ntrack.size() < 4){  // just copy same track numbers to track1/2
	for(UInt_t i = 0; i < ntrack.size(); i ++){
	    cluster->setNTrack1( ntrack[i] );
	    cluster->setNTrack2( ntrack[i] );
	    cluster->incNParticipants();
	}
    } else {
	// distribute track numbers to track1/2 so that the maximum information is preserved
	for(UInt_t i = 0; i < ntrack.size() && i < 7; i += 2){  // allowed max is 6 (2x3)
	    cluster->setNTrack1( ntrack[i]   );
	    cluster->setNTrack2( ntrack[i+1] );
	    cluster->incNParticipants();              // max here == 3
	}
	if(ntrack.size() == 5 ) { // fill symmetric: use same number twice
	    cluster->setNTrack1( ntrack[4]   );
	    cluster->setNTrack2( ntrack[4] );
	    cluster->incNParticipants();
	}
	if(ntrack.size() > 3 ) {
	    Warning("HTofClusterFSim::execute()","number of track numbers larger than 3! n=%i",(Int_t)ntrack.size());
	}
	if(ntrack.size() > 6 ) {
	    Warning("HTofClusterFSim::execute()","number of track numbers larger than maximum stored tracks! n=%i",(Int_t)ntrack.size());
	}

    }


  }
  return 0;
}

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