ROOT logo
//Task for Tof clustering for Spline
//*-- Author : Anar Rustamov
//This task adds a flag to HMetaMatch2
//The flag is : isTofCluster.
//+100 --means the cluster was accepted
//-100 --means the cluster was not accepted
#include "hsplinetofclF2.h"
#include "hades.h"
#include "hevent.h"
#include "hcategory.h"
#include "hiterator.h"
#include "hspectrometer.h"
#include "hruntimedb.h"
#include "hmdcdetector.h"
#include "hspecgeompar.h"
#include "tofdef.h"
#include "hmatrixcategory.h"
#include "hmetamatch2.h"
#include "hmdctrackddef.h"
#include "hmdctrackgdef.h"
#include "hmdctrkcand.h"
#include "hlocation.h"
#include "hshowerhitsim.h"
#include "htofhit.h"
#include <iostream>
using namespace std;

ClassImp(HSplineTofClF2)
   
   HSplineTofClF2::HSplineTofClF2()
{
   iterMetaMatch1 = NULL;
   iterMetaMatch2 = NULL;
}

HSplineTofClF2::HSplineTofClF2(const Text_t name[],const Text_t title[],Int_t MODE):
   HReconstructor(name,title) {
   mode=MODE;
   iterMetaMatch1 = NULL;
   iterMetaMatch2 = NULL;
}

HSplineTofClF2::~HSplineTofClF2()
{
    if (iterMetaMatch1) {delete iterMetaMatch1; iterMetaMatch1 = NULL;}
    if (iterMetaMatch2) {delete iterMetaMatch2; iterMetaMatch2 = NULL;}
}

Bool_t HSplineTofClF2::init()
{
   if (!gHades) return kFALSE;
   HRuntimeDb *rtdb=gHades->getRuntimeDb();
   HSpectrometer *spec=gHades->getSetup();
   HEvent *event=gHades->getCurrentEvent();
   if(rtdb && spec && event)
      {
         fCatMetaMatch=event->getCategory(catMetaMatch);
         if(!fCatMetaMatch) return kFALSE;
	 iterMetaMatch1=(HIterator*)fCatMetaMatch->MakeIterator();
	 if(!iterMetaMatch1) return kFALSE;
         iterMetaMatch2=(HIterator*)fCatMetaMatch->MakeIterator();
	 if(!iterMetaMatch2) return kFALSE;
         fCatTrkCand=event->getCategory(catMdcTrkCand);
	 if(!fCatTrkCand) return kFALSE;
	 
      }
   return kTRUE;
}
Bool_t HSplineTofClF2::reinit()
{
   return kTRUE;  
}

Bool_t HSplineTofClF2::finalize()
{
   return kTRUE;
}

Int_t HSplineTofClF2::execute()
{
  
  if(mode==0)
    {
      checkShowerOverlap();
      return unsetTofHitsFromCluster();
    }
  else 
    {
   iterMetaMatch1->Reset();
   step=0;
   while((pMetaMatch1=(HMetaMatch2*)(iterMetaMatch1->Next()))!=0)
      {
//          if((Int_t)(pMetaMatch1->getTofClusterSize())==2)
// 	    {
// 	    //cout<<"tof cluster size is 2"<<endl;
// 	       checkCluster(pMetaMatch1);
// 	    }
	 step++;
      }
   
    }
    return 1;
}

void HSplineTofClF2::checkCluster(HMetaMatch2 *p1)
{
   iterMetaMatch2->Reset();
   step1=0;
   while((pMetaMatch2=(HMetaMatch2*)(iterMetaMatch2->Next()))!=0)
      {
	 if(step1==step) continue;
	 if(condMeta(pMetaMatch2,p1))
	    {
	       if(checkForSeg(p1,pMetaMatch2))
		  {
		    // p1->unsetSplineAccept();
		     //p1->unsetRungeKuttaAccept();
		     
		  }
	    }
	 step1++;
      }
}

Bool_t HSplineTofClF2::condMeta(HMetaMatch2 *p1,HMetaMatch2 *p2)
{
//???    if(p1->getTofHitInd()==p2->getTofHitInd())
//???       return kTRUE;
//???    else 
      return kFALSE;
}

Bool_t HSplineTofClF2::checkForSeg(HMetaMatch2 *p1, HMetaMatch2 *p2)
{
   HMdcTrkCand *tr1 ,*tr2;
   Int_t tr1Ind,tr2Ind;
   tr1Ind=p1->getTrkCandInd();
   tr2Ind=p2->getTrkCandInd();
   if(tr1Ind<0 || tr2Ind<0) return kFALSE;	
   tr1=(HMdcTrkCand*)(fCatTrkCand->getObject(tr1Ind));
   tr2=(HMdcTrkCand*)(fCatTrkCand->getObject(tr2Ind));
   if(!tr1 || !tr2) return kFALSE;
   ind1=tr1->getSeg1Ind();
   ind2=tr1->getSeg2Ind();
   ind3=tr2->getSeg1Ind();
   ind4=tr2->getSeg2Ind();
   if(ind2<0 || ind4<0) return kFALSE;
   if(tr1Ind!=tr2Ind && ind1!=ind3) return kTRUE;
   else return kFALSE;
}

Bool_t HSplineTofClF2::checkCandForSameMeta(HMetaMatch2 *pMetaMatch)
{
//   Int_t index=-1;
//???    while((index=pMetaMatch->getNextMMForSameMeta())>=0)
//???       {
//???       pMetaMatch=(HMetaMatch2*)(fCatMetaMatch->getObject(index));
//???       if(!pMetaMatch) return kFALSE;
//???       pMetaMatch->unsetSplineAccept();
//???       pMetaMatch->unsetRungeKuttaAccept();
//???       }
   
   return kTRUE;
}
Int_t  HSplineTofClF2::unsetTofHitsFromCluster()
   
{
//   HMetaMatch2 *pMetaMatch;
//   iterMetaMatch1->Reset();
   
//   while((pMetaMatch=(HMetaMatch2*)(iterMetaMatch1->Next()))!=0)
//      {
//??? 	 if(pMetaMatch->getNumMMForSameMeta()<0) continue;
//??? 	 if(pMetaMatch->getTofClusterSize()==2 && pMetaMatch->getNextMMForTofHit()>=0)
//??? 	    {
//??? 	       if(!checkNextTofHits(pMetaMatch)) continue;
//??? 	    }	
//      }
   return 1;
}
Bool_t  HSplineTofClF2::checkNextTofHits(HMetaMatch2 *pMetaMatch)
   
{
//   Int_t index=-1;
//???    while((index=pMetaMatch->getNextMMForTofHit())>=0)
//???       {
//??? 	 pMetaMatch=(HMetaMatch2*)(fCatMetaMatch->getObject(index));
//??? 	 pMetaMatch->unsetSplineAccept();
//??? 	 pMetaMatch->unsetRungeKuttaAccept();
//??? 	 if(!checkCandForSameMeta(pMetaMatch)) continue;
//???       }
   return kTRUE;
}


void HSplineTofClF2::checkShowerOverlap()
{
//   HMetaMatch2 *pMetaMatch,*pMetaMatch1;
//   Int_t index;
//   Int_t firstCandIndex;
//   iterMetaMatch1->Reset();
//   while((pMetaMatch=(HMetaMatch2*)(iterMetaMatch1->Next()))!=0)
//      {

//???         firstCandIndex=pMetaMatch->getFirstMMForSameTrCnd();
//??? 	if(firstCandIndex==-1) continue;
//??? 		       
//??? 	 if(pMetaMatch->getNumMMForSameTrCnd()<0) continue;
//??? 
//??? 	 while((index=pMetaMatch->getNextMMForSameTrCnd())>=0)
//??? 	   {
//??? 	     if(pMetaMatch->getTofHitInd()>=0)
//??? 	       {
//??? 		 index=pMetaMatch->getNextMMForSameTrCnd();
//??? 		 if(index>=0)
//??? 		   {
//??? 		     pMetaMatch=(HMetaMatch2*)(fCatMetaMatch->getObject(index));  
//??? 		     if(pMetaMatch->getShowerHitInd()>=0)
//??? 		     {
//??? 		     pMetaMatch->unsetSplineAccept();
//??? 		     pMetaMatch->unsetRungeKuttaAccept();
//??? 		     }
//??? 		     
//??? 		   }
//??? 	       }
//??? 	     else if(pMetaMatch->getShowerHitInd()>=0)
//??? 		{
//??? 		
//??? 	          pMetaMatch1=pMetaMatch;	
//??? 		  index=pMetaMatch->getNextMMForSameTrCnd();
//??? 		  if(index>=0)
//??? 		    {
//??? 		      pMetaMatch=(HMetaMatch2*)(fCatMetaMatch->getObject(index));  
//??? 		      if(pMetaMatch->getTofHitInd()>=0)
//??? 		      {
//??? 		      pMetaMatch1->unsetSplineAccept();
//??? 		      pMetaMatch1->unsetRungeKuttaAccept();
//??? 		      }
//??? 		      
//??? 		    }
//??? 		}
//??? 	      
//??? 	   }
	 
	 
//      }
}

	 
 hsplinetofclF2.cc:1
 hsplinetofclF2.cc:2
 hsplinetofclF2.cc:3
 hsplinetofclF2.cc:4
 hsplinetofclF2.cc:5
 hsplinetofclF2.cc:6
 hsplinetofclF2.cc:7
 hsplinetofclF2.cc:8
 hsplinetofclF2.cc:9
 hsplinetofclF2.cc:10
 hsplinetofclF2.cc:11
 hsplinetofclF2.cc:12
 hsplinetofclF2.cc:13
 hsplinetofclF2.cc:14
 hsplinetofclF2.cc:15
 hsplinetofclF2.cc:16
 hsplinetofclF2.cc:17
 hsplinetofclF2.cc:18
 hsplinetofclF2.cc:19
 hsplinetofclF2.cc:20
 hsplinetofclF2.cc:21
 hsplinetofclF2.cc:22
 hsplinetofclF2.cc:23
 hsplinetofclF2.cc:24
 hsplinetofclF2.cc:25
 hsplinetofclF2.cc:26
 hsplinetofclF2.cc:27
 hsplinetofclF2.cc:28
 hsplinetofclF2.cc:29
 hsplinetofclF2.cc:30
 hsplinetofclF2.cc:31
 hsplinetofclF2.cc:32
 hsplinetofclF2.cc:33
 hsplinetofclF2.cc:34
 hsplinetofclF2.cc:35
 hsplinetofclF2.cc:36
 hsplinetofclF2.cc:37
 hsplinetofclF2.cc:38
 hsplinetofclF2.cc:39
 hsplinetofclF2.cc:40
 hsplinetofclF2.cc:41
 hsplinetofclF2.cc:42
 hsplinetofclF2.cc:43
 hsplinetofclF2.cc:44
 hsplinetofclF2.cc:45
 hsplinetofclF2.cc:46
 hsplinetofclF2.cc:47
 hsplinetofclF2.cc:48
 hsplinetofclF2.cc:49
 hsplinetofclF2.cc:50
 hsplinetofclF2.cc:51
 hsplinetofclF2.cc:52
 hsplinetofclF2.cc:53
 hsplinetofclF2.cc:54
 hsplinetofclF2.cc:55
 hsplinetofclF2.cc:56
 hsplinetofclF2.cc:57
 hsplinetofclF2.cc:58
 hsplinetofclF2.cc:59
 hsplinetofclF2.cc:60
 hsplinetofclF2.cc:61
 hsplinetofclF2.cc:62
 hsplinetofclF2.cc:63
 hsplinetofclF2.cc:64
 hsplinetofclF2.cc:65
 hsplinetofclF2.cc:66
 hsplinetofclF2.cc:67
 hsplinetofclF2.cc:68
 hsplinetofclF2.cc:69
 hsplinetofclF2.cc:70
 hsplinetofclF2.cc:71
 hsplinetofclF2.cc:72
 hsplinetofclF2.cc:73
 hsplinetofclF2.cc:74
 hsplinetofclF2.cc:75
 hsplinetofclF2.cc:76
 hsplinetofclF2.cc:77
 hsplinetofclF2.cc:78
 hsplinetofclF2.cc:79
 hsplinetofclF2.cc:80
 hsplinetofclF2.cc:81
 hsplinetofclF2.cc:82
 hsplinetofclF2.cc:83
 hsplinetofclF2.cc:84
 hsplinetofclF2.cc:85
 hsplinetofclF2.cc:86
 hsplinetofclF2.cc:87
 hsplinetofclF2.cc:88
 hsplinetofclF2.cc:89
 hsplinetofclF2.cc:90
 hsplinetofclF2.cc:91
 hsplinetofclF2.cc:92
 hsplinetofclF2.cc:93
 hsplinetofclF2.cc:94
 hsplinetofclF2.cc:95
 hsplinetofclF2.cc:96
 hsplinetofclF2.cc:97
 hsplinetofclF2.cc:98
 hsplinetofclF2.cc:99
 hsplinetofclF2.cc:100
 hsplinetofclF2.cc:101
 hsplinetofclF2.cc:102
 hsplinetofclF2.cc:103
 hsplinetofclF2.cc:104
 hsplinetofclF2.cc:105
 hsplinetofclF2.cc:106
 hsplinetofclF2.cc:107
 hsplinetofclF2.cc:108
 hsplinetofclF2.cc:109
 hsplinetofclF2.cc:110
 hsplinetofclF2.cc:111
 hsplinetofclF2.cc:112
 hsplinetofclF2.cc:113
 hsplinetofclF2.cc:114
 hsplinetofclF2.cc:115
 hsplinetofclF2.cc:116
 hsplinetofclF2.cc:117
 hsplinetofclF2.cc:118
 hsplinetofclF2.cc:119
 hsplinetofclF2.cc:120
 hsplinetofclF2.cc:121
 hsplinetofclF2.cc:122
 hsplinetofclF2.cc:123
 hsplinetofclF2.cc:124
 hsplinetofclF2.cc:125
 hsplinetofclF2.cc:126
 hsplinetofclF2.cc:127
 hsplinetofclF2.cc:128
 hsplinetofclF2.cc:129
 hsplinetofclF2.cc:130
 hsplinetofclF2.cc:131
 hsplinetofclF2.cc:132
 hsplinetofclF2.cc:133
 hsplinetofclF2.cc:134
 hsplinetofclF2.cc:135
 hsplinetofclF2.cc:136
 hsplinetofclF2.cc:137
 hsplinetofclF2.cc:138
 hsplinetofclF2.cc:139
 hsplinetofclF2.cc:140
 hsplinetofclF2.cc:141
 hsplinetofclF2.cc:142
 hsplinetofclF2.cc:143
 hsplinetofclF2.cc:144
 hsplinetofclF2.cc:145
 hsplinetofclF2.cc:146
 hsplinetofclF2.cc:147
 hsplinetofclF2.cc:148
 hsplinetofclF2.cc:149
 hsplinetofclF2.cc:150
 hsplinetofclF2.cc:151
 hsplinetofclF2.cc:152
 hsplinetofclF2.cc:153
 hsplinetofclF2.cc:154
 hsplinetofclF2.cc:155
 hsplinetofclF2.cc:156
 hsplinetofclF2.cc:157
 hsplinetofclF2.cc:158
 hsplinetofclF2.cc:159
 hsplinetofclF2.cc:160
 hsplinetofclF2.cc:161
 hsplinetofclF2.cc:162
 hsplinetofclF2.cc:163
 hsplinetofclF2.cc:164
 hsplinetofclF2.cc:165
 hsplinetofclF2.cc:166
 hsplinetofclF2.cc:167
 hsplinetofclF2.cc:168
 hsplinetofclF2.cc:169
 hsplinetofclF2.cc:170
 hsplinetofclF2.cc:171
 hsplinetofclF2.cc:172
 hsplinetofclF2.cc:173
 hsplinetofclF2.cc:174
 hsplinetofclF2.cc:175
 hsplinetofclF2.cc:176
 hsplinetofclF2.cc:177
 hsplinetofclF2.cc:178
 hsplinetofclF2.cc:179
 hsplinetofclF2.cc:180
 hsplinetofclF2.cc:181
 hsplinetofclF2.cc:182
 hsplinetofclF2.cc:183
 hsplinetofclF2.cc:184
 hsplinetofclF2.cc:185
 hsplinetofclF2.cc:186
 hsplinetofclF2.cc:187
 hsplinetofclF2.cc:188
 hsplinetofclF2.cc:189
 hsplinetofclF2.cc:190
 hsplinetofclF2.cc:191
 hsplinetofclF2.cc:192
 hsplinetofclF2.cc:193
 hsplinetofclF2.cc:194
 hsplinetofclF2.cc:195
 hsplinetofclF2.cc:196
 hsplinetofclF2.cc:197
 hsplinetofclF2.cc:198
 hsplinetofclF2.cc:199
 hsplinetofclF2.cc:200
 hsplinetofclF2.cc:201
 hsplinetofclF2.cc:202
 hsplinetofclF2.cc:203
 hsplinetofclF2.cc:204
 hsplinetofclF2.cc:205
 hsplinetofclF2.cc:206
 hsplinetofclF2.cc:207
 hsplinetofclF2.cc:208
 hsplinetofclF2.cc:209
 hsplinetofclF2.cc:210
 hsplinetofclF2.cc:211
 hsplinetofclF2.cc:212
 hsplinetofclF2.cc:213
 hsplinetofclF2.cc:214
 hsplinetofclF2.cc:215
 hsplinetofclF2.cc:216
 hsplinetofclF2.cc:217
 hsplinetofclF2.cc:218
 hsplinetofclF2.cc:219
 hsplinetofclF2.cc:220
 hsplinetofclF2.cc:221
 hsplinetofclF2.cc:222
 hsplinetofclF2.cc:223
 hsplinetofclF2.cc:224
 hsplinetofclF2.cc:225
 hsplinetofclF2.cc:226
 hsplinetofclF2.cc:227
 hsplinetofclF2.cc:228
 hsplinetofclF2.cc:229
 hsplinetofclF2.cc:230
 hsplinetofclF2.cc:231
 hsplinetofclF2.cc:232
 hsplinetofclF2.cc:233
 hsplinetofclF2.cc:234
 hsplinetofclF2.cc:235
 hsplinetofclF2.cc:236
 hsplinetofclF2.cc:237
 hsplinetofclF2.cc:238
 hsplinetofclF2.cc:239
 hsplinetofclF2.cc:240
 hsplinetofclF2.cc:241
 hsplinetofclF2.cc:242
 hsplinetofclF2.cc:243
 hsplinetofclF2.cc:244
 hsplinetofclF2.cc:245
 hsplinetofclF2.cc:246
 hsplinetofclF2.cc:247
 hsplinetofclF2.cc:248
 hsplinetofclF2.cc:249