BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
// 
// Module container that contains the BFS and FFS 
// tracking modules. It gets the ffs and bfs tracks and match them
// when T2 was used in the BFS tracking. If not, to make it very simple
// for now, the BFS is just swimmed back to the vertex through D2 and D1
// Therefore, we don't loose any BFS tracks. Later on, someone would have
// to extend the module match track to T2 - T3 (allowing matching without 
// any magnet). 
// 
//
// The way to use it is:
//    BrFsTrackingModule* fsmod = new BrFfsTrackingModule("name", "title"); 
//    BrBfsTrackingModule* bfsmod = fsmod->GetBfsModule();
//       ...
//    BrFfsTrackingModule* ffsmod = fsmod->GetFfsModule();
//       ...


//____________________________________________________________________
//
// $Id: BrFsTrackingModule.cxx,v 1.6 2002/08/12 16:18:22 ufstasze Exp $
// $Author: ufstasze $
// $Date: 2002/08/12 16:18:22 $
// $Copyright: (C) 2002 BRAHMS Collaboration <brahmlib@rhic.bnl.gov>
//
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>

#ifndef BRAT_BrFsTrackingModule
#include "BrFsTrackingModule.h"
#endif
#ifndef ROOT_TDirectory
#include "TDirectory.h"
#endif
#ifndef WIN32
#include <iostream>
#else
#include <iostream.h>
#endif
#ifndef BRAT_BrRunInfoManager
#include "BrRunInfoManager.h"
#endif
#ifndef BRAT_BrGeometryDbManager
#include "BrGeometryDbManager.h"
#endif
#ifndef BRAT_BrParameterDbManager
#include "BrParameterDbManager.h"
#endif
#ifndef BRAT_BrPathManager
#include "BrPathManager.h"
#endif
#ifndef BRAT_BrBbVertex
#include "BrBbVertex.h"
#endif
#ifndef BRAT_BrPlane3D
#include "BrPlane3D.h"
#endif
#ifndef BRAT_BrLine3D
#include "BrLine3D.h"
#endif
#ifndef BRAT_BrVector3D
#include "BrVector3D.h"
#endif
#ifndef BRAT_BrUnits
#include "BrUnits.h"
#endif

//____________________________________________________________________
ClassImp(BrFsTrackingModule);

//____________________________________________________________________
 BrFsTrackingModule::BrFsTrackingModule()
{
  // Default constructor. DO NOT USE
  SetState(kSetup);

  fFfsModule = 0;
  fBfsModule = 0;

  fT2Vol = 0;
  fT3Vol = 0;
  fD1Vol = 0;
  fD2Vol = 0;
  fH1Par = 0;
  fUseBbVertex = kFALSE;
  fNewT2T3Matching = kTRUE;
}

//____________________________________________________________________
 BrFsTrackingModule::BrFsTrackingModule(const Char_t* name, 
				       const Char_t* title)
  : BrModule(name, title)
{
  // Named Constructor
  SetState(kSetup);

  fFfsModule = new BrFfsTrackingModule("FFS", "FFS Tracking");
  fBfsModule = new BrBfsTrackingModule("BFS", "BFS Tracking");

  fT2Vol = 0;
  fT3Vol = 0;
  fD1Vol = 0;
  fD2Vol = 0;
  fH1Par = 0;
  fUseBbVertex = kFALSE;
  fNewT2T3Matching = kTRUE;

  fMatched1=0;
  fMatched2=0;
}

//____________________________________________________________________
 void BrFsTrackingModule::Init() 
{
  SetState(kInit);

  fFfsModule->Init();
  fBfsModule->Init();
  
  // --- geometry
  BrGeometryDbManager* geodb = BrGeometryDbManager::Instance();
  fT2Vol = (BrDetectorVolume*)geodb->GetDetectorVolume("BrDetectorVolume", "T2");
  fT3Vol = (BrDetectorVolume*)geodb->GetDetectorVolume("BrDetectorVolume", "T3");
  fH1Vol = (BrDetectorVolume*)geodb->GetDetectorVolume("BrDetectorVolume", "TOF1");
  fD1Vol = (BrMagnetVolume*)geodb->GetDetectorVolume("BrMagnetVolume", "D1");
  fD2Vol = (BrMagnetVolume*)geodb->GetDetectorVolume("BrMagnetVolume", "D2");

  // --- parameters
  BrParameterDbManager* pardb = BrParameterDbManager::Instance();
  fH1Par = (BrDetectorParamsTof*)pardb->GetDetectorParameters("BrDetectorParamsTof", "TOF1");

}

//___________________________________________________________________
 Bool_t BrFsTrackingModule::ReadOffsets()
{
  
  Int_t SearchRun = fRunNo+1;
  Int_t r;
  Float_t v[11][8];  
  
  TString offsetFileName = BrPathManager::Instance()->GetParameterDir();
  offsetFileName += "/trackmatch/offsets5361_5972.FS";


  //TString offsetFileName = "/brahms/u/ufstasze/effic/offsets5361_5972.FS";

  do {
    ifstream input(offsetFileName.Data(), ios::in);
    Char_t comment[256];  
    if(!input){
      Abort("ReadOffsets", "Sorry, could not get your file. Check it out!");
      return kFALSE;
    }
    SearchRun--;
    // --------- reading file
    
    input.getline(comment, 256);
    input.getline(comment, 256);
    input.getline(comment, 256);
    input.getline(comment, 256);
  
    do {
      input >> r;
      for(Int_t i=0;i<11;i++){
	input >>v[i][0]>>v[i][1]>>v[i][2]>>v[i][3]
	      >>v[i][4]>>v[i][5]>>v[i][6]>>v[i][7];
      }
      if (input.eof())
	break;
    } while (r != SearchRun);
    input.close();
  }while (r != SearchRun && SearchRun>5361);
  
  if (r != SearchRun) {
    cout<<"Warning in <BrEfficiencyFinderModule::ReadOffsets>:"<<endl;
    cout<<"Sorry, couldn't find run "<<fRunNo<<"-- in file "<<offsetFileName<<endl;
    cout<<"Probably this is a very serious problem and you can not continue"<<endl;
    return kFALSE;
  }
  
  cout<<"BrEficiencyFinderModule::ReadOffsets():"<<endl; 
  cout<<"Offsets requested for run # "<<fRunNo<<endl;
  cout<<"found (and assumed) for run # "<<SearchRun<<endl;
  cout<<"from file "<<offsetFileName<<endl;

  for(Int_t i=0;i<11;i++){
    cout<<v[i][0]<<" "<<v[i][1]<<" "<<v[i][2]<<" "<<v[i][3]<<" "
	<<v[i][4]<<" "<<v[i][5]<<" "<<v[i][6]<<" "<<v[i][7]<<endl;
  }
  
  // T3T2
  fOffset_xT3T2  = v[1][0];
  fSigma_xT3T2   = v[1][1];
  fOffset_yT3T2  = v[1][2]; 
  fSigma_yT3T2   = v[1][3];

  fOffset_axT3T2 = v[1][4];
  fSigma_axT3T2  = v[1][5];
  fOffset_ayT3T2 = v[1][6];
  fSigma_ayT3T2  = v[1][7];  
  
  return kTRUE;
}

//____________________________________________________________________
 void BrFsTrackingModule::DefineHistograms() 
{

  fFfsModule->Book();
  fBfsModule->Book();

  TDirectory* saveDir = gDirectory;
  TDirectory* histDir = gDirectory->mkdir("Tracking_FS");
  histDir->cd();

  fhMatchQ = new TH1F("FfsBfsChi2","Matching quality between ffs and bfs tracks (T2-T3)",
		      100, 0, 20);
  
  fNFsTracks  = new TH1F("hNFsTracks","Number of FS tracks per event",
			 20, -0.5, 19.5);
  fFsStat     = new TH1F("hFsStat", "FS Track type: 0 = no FFS tracks, "
			 "1 = BFS-FFS match, 2 = BFS without FFS match", 
			 7, -0.75, 2.75) ;
  fPathLength = new TH1F("hPathLength", "FS Track path length", 500, 1500, 2000);
  fPhi        = new TH1F("hPhi", "Azimuthal angle (deg.)", 500, -25, 25);
  fTheta      = new TH1F("hTheta", "Polar angle (deg.)", 500, 0, 35);
  fVertex     = new TH2F("hVertex", "Track vertex in BB vertex plane",
			 500, -20, 20, 500, -20, 20);
  fD1Swim     = new TH1F("hD1Status", "Swim status in D1", 5, -0.75, 1.75);
  fPAverage   = new TH1F("hMomentumAverage", "Track Momentum average",
			 500, -20, 20);

  histDir->mkdir("Match_T2_T3");
  histDir->cd("Match_T2_T3");

  fH1SlatDiff = new TH1F("hH1SlatDiff", "Pointed H1 slat diff (BFS - FFS)",
			 20, -9.5, 10.5);

  fDalyAll = new TH1F("hDalyAll", "Slope Y diff (T3 - T2)", 250, -0.2, 0.2);
  fDalxAll = new TH1F("hDalxAll", "Slope X diff (T3 - T2)", 250, -0.2, 0.2);
  fDalzAll = new TH1F("hDalzAll", "Slope Z diff (T3 - T2)", 250, -0.02, 0.02);

  fDyAll = new TH1F("hDyAll", "Slope Y diff (T3 - T2)", 250, -50, 50);
  fDxAll = new TH1F("hDxAll", "Slope X diff (T3 - T2)", 250, -50, 50);
  
  fDalyH1Cut = new TH1F("hDalyH1Cut", "Slope Y diff, H1 slat ok (T3 - T2)", 250, -0.2, 0.2);
  fDalxH1Cut = new TH1F("hDalxH1Cut", "Slope X diff, H1 slat ok (T3 - T2)", 250, -0.2, 0.2);
  fDalzH1Cut = new TH1F("hDalzH1Cut", "Slope Z diff, H1 slat ok (T3 - T2)", 250, -0.02, 0.02);

  fDyH1Cut = new TH1F("hDyH1Cut", "Pos Y diff, H1 slat ok (T3 - T2)", 250, -50, 50);
  fDxH1Cut = new TH1F("hDxH1Cut", "Pos X diff, H1 slat ok (T3 - T2)", 250, -50, 50);

  fhDxT3T2 = new TH2F("DxT3T2","Dx between T3 and T2 tracks versus momentum",
		     100,0,30,200,-20,20);
  fhDyT3T2 = new TH2F("DyT3T2","Dy between T3 and T2 tracks versus momentum",
		     100,0,30,200,-20,20);
  fhDaxT3T2 = new TH2F("DaxT3T2","Dax between T3 and T2 tracks versus momentum",
		      100,0,30,200,-0.1,0.1);
  fhDayT3T2 = new TH2F("DayT3T2","Day between T3 and T2 tracks versus momentum",
		      100,0,30,200,-0.1,0.1);

  gDirectory = saveDir;
}

//____________________________________________________________________
 void BrFsTrackingModule::Begin() 
{
  SetState(kBegin);
  
  fFfsModule->Begin();
  fBfsModule->Begin();
  
  // ------ check spectrometer alignment;
  
  BrRunInfoManager* runMan = BrRunInfoManager::Instance();
  const BrRunInfo* run = runMan->GetCurrentRun();
  
  if (run->GetRunNo() == -1) {
    Abort("Init", "Run number is -1, check it out");
    return;
  }
  fRunNo = run->GetRunNo();
  

  fAlignment = kTRUE;
  if (run->GetFFSAngle() != run->GetBFSAngle())
    fAlignment = kFALSE; 

  if(!fNewT2T3Matching)return;

  if(ReadOffsets())cout<<"offsets from offset file"<<endl;

  // ------ no need to set the fields, they are set in submodules

}


//____________________________________________________________________
 void BrFsTrackingModule::Event(BrEventNode* inNode, BrEventNode* outNode)
{
  // Per event method
  SetState(kEvent);

  fFfsModule->Event(inNode, outNode);
  fBfsModule->Event(inNode, outNode);

  // ---- get track tables:

  BrDataTable* ffsTab = outNode->GetDataTable("FfsTracks");
  BrDataTable* bfsTab = outNode->GetDataTable("BfsTracks");
  
  if (!bfsTab) {
    Debug(5, "Event", "No BFS tracks");
    return;
  }
  
  // ---- prepare output table
  BrDataTable* fsTab = new BrDataTable("FsTracks");
  
  // FIXE ME: if FFS and BFS not aligned, I will still build
  // some FS tracks but only with BFS. The reason is due to some
  // poor design of the global tracking in general, therefore I 
  // need this hack. One should revise the whole stuff after QM2002   
  
  if (!fAlignment) {
    BuildFsFromBfs(bfsTab, fsTab);
    outNode->AddDataTable(fsTab);
    return;
  }
  
  // --- check BB vtx
  Float_t z0 = 0;
  if (fUseBbVertex) {
    BrBbVertex* vtx = (BrBbVertex*)inNode->GetObject("BB Vertex");
    if (!vtx) vtx = (BrBbVertex*)outNode->GetObject("BB Vertex");
    if (vtx) z0 = vtx->GetZ0();
  }
    
  // ---- if no FFS track to match
  Int_t nffs = 0;
  if (ffsTab) nffs = ffsTab->GetEntries();
  if (nffs == 0) {
    for (Int_t i = 0; i < bfsTab->GetEntries(); i++) {
      BrBfsTrack* trk = (BrBfsTrack*)bfsTab->At(i);
      if (trk->T2WasUsed())
	SwimTrackBack(trk, fsTab, fT2Vol, z0);
      else
	SwimTrackBack(trk, fsTab, fT3Vol, z0);
    }
  }
  else {
    // ---- loop over bfs tracks and check if T2 was used
    Bool_t ffsChecked[nffs];
    for (Int_t ffs = 0; ffs < nffs; ffs++) 
      ffsChecked[ffs] = kFALSE;
    
    for (Int_t i = 0; i < bfsTab->GetEntries(); i++) {
      BrBfsTrack* bfst = (BrBfsTrack*)bfsTab->At(i);
      
      // --- if T2 was not used, the simplest for now is 
      // to swim back the track without matching T2 and T3
      // Note: we should have a more flexible ModuleMatchTrack 
      // that could match any local tracks, magnet(s) or not in between.  
      if (!bfst->T2WasUsed()) {

	Bool_t T2T3Match;

	if(fNewT2T3Matching)T2T3Match = CheckT2T3Match(bfst, ffsTab, fsTab);
	else T2T3Match = CheckT2T3MatchNew(bfst, ffsTab, fsTab);

	if (!T2T3Match)SwimTrackBack(bfst, fsTab, fT3Vol, z0);

	//if(T2T3Match)fMatched1++;
	//if(T2T3Match2)fMatched2++;
	//if(fMatched1%100==0)cout<<"Matched: "<<fMatched1<<" "<<fMatched2<<endl;

      }
      
      // if T2 was used, compare only T2 track IDs 
      else { 
	// loop over ffs tracks
	for (Int_t j = 0; j < ffsTab->GetEntries(); j++) {
	  if (ffsChecked[j])
	    continue;
	  
	  BrFfsTrack* ffst = (BrFfsTrack*)ffsTab->At(j);
	  if (T2TracksCompare(bfst, ffst, fsTab))
	    ffsChecked[j] = kTRUE;
	}
      }
    }
  }


  if (fsTab->GetEntries()) {
    outNode->AddDataTable(fsTab);
    if (HistOn()) {
      fNFsTracks->Fill(fsTab->GetEntries());
      for (Int_t i = 0; i < fsTab->GetEntries(); i++) {
	BrFsTrack* t = (BrFsTrack*)fsTab->At(i);
	if (!nffs)
	  fFsStat->Fill(0);
	else {
	  if (t->GetFfsTrackId() >= 0)
	    fFsStat->Fill(1);
	  else 
	    fFsStat->Fill(2);
	}
	
	fPathLength->Fill(t->GetPathLength());
	fTheta->Fill(t->GetTheta()/BrUnits::degree);
	fPhi->Fill(t->GetPhi()/BrUnits::degree);
	fD1Swim->Fill(t->GetD1Status());
	fVertex->Fill(t->GetTrackVertex()[0], t->GetTrackVertex()[1]);
	fPAverage->Fill(t->GetMomentum());
      }
    }
  }
  else
    delete fsTab;
}

//_______________________________________________________________________
 Bool_t BrFsTrackingModule::CheckT2T3Match(BrBfsTrack* bfst, 
					  BrDataTable* ffstab, 
					  BrDataTable* fsTab)
{
  // private

  // loop over ffs tracks and check how T2 and T3 match (which H1 slat do they
  // point, how do the track lines compare before and after the H1 pointed slat check)
  // if they point to the same slat, build an fs track
  // DO: too simple criterium and no check if the slat is pointed by more than 2 tracks

  BrVector3D t3pos = bfst->GetProjOnTof1();
  BrVector3D t3dir = bfst->GetFrontDetectorTrack()->GetAlpha();
  BrVector3D gT3dir; fT3Vol->LocalToGlobal(t3dir, gT3dir, 1);
  
  for (Int_t i = 0; i < ffstab->GetEntries(); i++) {
    BrFfsTrack* ffst = (BrFfsTrack*)ffstab->At(i);
    if (ffst->GetStatus() != BrMatchedTrack::kOk)
      continue;

    Int_t dslat = bfst->GetTof1PointedSlat() - ffst->GetPointedSlat();
    BrVector3D t2pos = ffst->GetProjOnTof();

    BrVector3D t2dir = ffst->GetBackTrack()->GetAlpha();
    BrVector3D gT2dir; fT2Vol->LocalToGlobal(t2dir, gT2dir, 1);

    // slope and position comparison 
    if (HistOn()) {
      fH1SlatDiff->Fill(dslat);

      fDalxAll->Fill(gT3dir[0] - gT2dir[0]);
      fDalyAll->Fill(gT3dir[1] - gT2dir[1]);
      fDalzAll->Fill(gT3dir[2] - gT2dir[2]);
      fDxAll->Fill(t3pos[0] - t2pos[0]);
      fDyAll->Fill(t3pos[1] - t2pos[1]);
    }

    // matching criterium
    if (dslat == 0) {
      BrFsTrack* fst = new BrFsTrack();
      fst->SetTrackId(bfst->GetTrackId());
      fst->SetBfsTrack(bfst);
      fst->SetFfsTrack(ffst);
      fst->SetMomentum((bfst->GetMomentum()+ffst->GetMomentum())/2.);
      fst->SetTrackVertex(ffst->GetTrackVertex());
      fst->SetPathLength(bfst->GetPathLength() + ffst->GetPathLength());
      fst->SetTheta(ffst->GetTheta());
      fst->SetPhi(ffst->GetPhi());
      fst->SetProjOnTof2(bfst->GetProjOnTof());
      fst->SetProjOnTof1(ffst->GetProjOnTof());
      fst->SetTof2Slat(bfst->GetPointedSlat());
      fst->SetTof1Slat(ffst->GetPointedSlat());
      fst->SetBfsTrackId(bfst->GetTrackId());
      fst->SetFfsTrackId(ffst->GetTrackId());
      fst->SetD1Status(ffst->GetD1SwimStatus());

      fsTab->Add(fst);

      if (HistOn()) {
	fDalxH1Cut->Fill(gT3dir[0] - gT2dir[0]);
	fDalyH1Cut->Fill(gT3dir[1] - gT2dir[1]);
	fDalzH1Cut->Fill(gT3dir[2] - gT2dir[2]);
	fDxH1Cut->Fill(t3pos[0] - t2pos[0]);
	fDyH1Cut->Fill(t3pos[1] - t2pos[1]);
      }
      return kTRUE;
    }
  }

  return kFALSE;
}

//_______________________________________________________________________
 Bool_t BrFsTrackingModule::CheckT2T3MatchNew(BrBfsTrack* bfst, 
					     BrDataTable* ffstab, 
					     BrDataTable* fsTab)
{
  // loop over ffs tracks and check how T2 and T3 match
  
  BrPlane3D Plane(0,0,0, 0,1,0, 1,0,0);
  
  BrMatchedTrack* mtcFront = bfst->GetBfsFrontTrack();
  Float_t amomentum = TMath::Abs(bfst->GetMomentum());            
  BrDetectorTrack* t3track = mtcFront->GetFrontTrack();
  BrLine3D T2Line(fT3Vol->LocalToGlobal(t3track->GetTrackLine()));
  
  BrLine3D t2Line(fT2Vol->GlobalToLocal(T2Line));    
  BrVector3D projT3T2(Plane.GetIntersectionWithLine(t2Line));
  
  Float_t ax_T3T2 = t2Line.GetDirection()[0]/t2Line.GetDirection()[2];
  Float_t ay_T3T2 = t2Line.GetDirection()[1]/t2Line.GetDirection()[2];
  Float_t x0_T3T2 = projT3T2.GetX();
  Float_t y0_T3T2 = projT3T2.GetY();
  
  Int_t Nmatched=0;
  Int_t isave[10];
  Float_t matchQsave[10];
  for (Int_t i = 0; i < ffstab->GetEntries(); i++) {
    BrFfsTrack* ffst = (BrFfsTrack*)ffstab->At(i);
    if (ffst->GetStatus() != BrMatchedTrack::kOk)
      continue;
    
    BrDetectorTrack* t2track = ffst->GetBackTrack();
    Float_t ax_T2 = t2track->GetAlpha()[0];
    Float_t ay_T2 = t2track->GetAlpha()[1];
    Float_t x0_T2 = t2track->GetPos()[0];
    Float_t y0_T2 = t2track->GetPos()[1];  

    fhDxT3T2  -> Fill(amomentum,x0_T3T2-x0_T2);
    fhDaxT3T2 -> Fill(amomentum,ax_T3T2-ax_T2);
    fhDyT3T2  -> Fill(amomentum,y0_T3T2-y0_T2);
    fhDayT3T2 -> Fill(amomentum,ay_T3T2-ay_T2);

    Float_t Dx0 = x0_T3T2-x0_T2-fOffset_xT3T2;
    Float_t Dax = ax_T3T2-ax_T2-fOffset_axT3T2;
    Float_t Dy0 = y0_T3T2-y0_T2-fOffset_yT3T2;
    Float_t Day = ay_T3T2-ay_T2-fOffset_ayT3T2;

    if(TMath::Abs(Dx0) < 4.0*fSigma_xT3T2 &&
       TMath::Abs(Dax) < 4.0*fSigma_axT3T2 &&
       TMath::Abs(Dy0) < 4.0*fSigma_yT3T2 &&
       TMath::Abs(Day) < 4.0*fSigma_ayT3T2
       ){
      isave[Nmatched] = i;
      matchQsave[Nmatched] =
	Dx0*Dx0/(fSigma_xT3T2*fSigma_xT3T2)   + 
	Dax*Dax/(fSigma_axT3T2*fSigma_axT3T2) +
	Dy0*Dy0/(fSigma_yT3T2*fSigma_yT3T2)   +
	Day*Day/(fSigma_ayT3T2*fSigma_ayT3T2);
      Nmatched++;
    }
  }
  
  if(Nmatched==0)return kFALSE;
  
  // if we are here means that we find one or more ffs tracks that match to bfs  

  BrFfsTrack* ffst; 
  if (Nmatched==1) {
    fhMatchQ->Fill(matchQsave[0]/4.0);
    ffst = (BrFfsTrack*)ffstab->At(isave[0]);
  }else{
    // if Nmatched is grether that 1 select the one with the best matchQ
    Float_t matchQmin = 2*matchQsave[0];
    Int_t ibest = 0; 
    for(Int_t i=0;i<Nmatched;i++){
      if(matchQsave[i]<matchQmin){
	ibest = isave[i];
	matchQmin = matchQsave[i];
      }
    }
    cout<<"More than 1 ffs match to bfs!!! "<<Nmatched<<endl;
    cout<<"Selected the one with the best match quality = "<<matchQmin<<endl;
    fhMatchQ->Fill(matchQsave[ibest]/4.0);
    ffst = (BrFfsTrack*)ffstab->At(ibest);
  }
  
  BrFsTrack* fst = new BrFsTrack();
  fst->SetTrackId(bfst->GetTrackId());
  fst->SetBfsTrack(bfst);
  fst->SetFfsTrack(ffst);
  fst->SetMomentum((bfst->GetMomentum()+ffst->GetMomentum())/2.);
  fst->SetTrackVertex(ffst->GetTrackVertex());
  fst->SetPathLength(bfst->GetPathLength() + ffst->GetPathLength());
  fst->SetTheta(ffst->GetTheta());
  fst->SetPhi(ffst->GetPhi());
  fst->SetProjOnTof2(bfst->GetProjOnTof());
  fst->SetProjOnTof1(ffst->GetProjOnTof());
  fst->SetTof2Slat(bfst->GetPointedSlat());
  fst->SetTof1Slat(bfst->GetPointedSlat());
  fst->SetBfsTrackId(bfst->GetTrackId());
  fst->SetFfsTrackId(ffst->GetTrackId());
  fst->SetD1Status(ffst->GetD1SwimStatus());
  
  fsTab->Add(fst);
  
  return kTRUE;
}

//_______________________________________________________________________
 void BrFsTrackingModule::BuildFsFromBfs(BrDataTable* bfs, BrDataTable* fs)
{
  // private

  // Copy BFS information from BFS track to FS track
  // this is done for practical convenience (TOF2 calibration, PID)
  // but should only be temp. hopefully

  for (Int_t i = 0; i < bfs->GetEntries(); i++) {
    BrBfsTrack* bt = (BrBfsTrack*)bfs->At(i);
    BrFsTrack* ft  = new BrFsTrack();

    ft->SetTrackId(bt->GetTrackId());
    ft->SetMomentum(bt->GetMomentum());
    ft->SetTrackVertex(bt->GetTrackVertex());
    ft->SetPathLength(bt->GetPathLength());
    ft->SetTheta(bt->GetTheta());
    ft->SetPhi(bt->GetPhi());
    ft->SetProjOnTof2(bt->GetProjOnTof());
    ft->SetTof2Slat(bt->GetPointedSlat());
    ft->SetBfsTrackId(bt->GetTrackId());
    ft->SetBfsTrack(bt);

    fs->Add(ft);
  }

  if (HistOn()) {
    fNFsTracks->Fill(fs->GetEntries());
    for (Int_t i = 0; i < fs->GetEntries(); i++) {
      BrFsTrack* t = (BrFsTrack*)fs->At(i);
      fFsStat->Fill(0);
      fPathLength->Fill(t->GetPathLength());
      fTheta->Fill(t->GetTheta()/BrUnits::degree);
      fPhi->Fill(t->GetPhi()/BrUnits::degree);
      fD1Swim->Fill(t->GetD1Status());
      fVertex->Fill(t->GetTrackVertex()[0], t->GetTrackVertex()[1]);
      fPAverage->Fill(t->GetMomentum());
    }
  }
}

//____________________________________________________________________
 Bool_t BrFsTrackingModule::T2TracksCompare(BrBfsTrack*  bfst,
					   BrFfsTrack*  ffst,
					   BrDataTable* tab)
{
  // private

  // checking if the T2 track is common to both tracks

  Int_t id1 = bfst->GetFrontDetectorTrack()->GetID();
  Int_t id2 = ffst->GetBackTrack()->GetID();

  if (ffst->GetStatus() != BrMatchedTrack::kOk)
    return kFALSE;
  
  if (id1 != id2)
    return kFALSE;

  BrFsTrack* fst = new BrFsTrack();
  fst->SetBfsTrack(bfst);
  fst->SetFfsTrack(ffst);
  fst->SetBfsTrackId(bfst->GetTrackId());
  fst->SetFfsTrackId(ffst->GetTrackId());
  fst->SetMomentum((bfst->GetMomentum()+ffst->GetMomentum())/2.);
  fst->SetPathLength(bfst->GetPathLength() + ffst->GetPathLength());
  fst->SetTrackVertex(ffst->GetTrackVertex());
  fst->SetTof1Proj(ffst->GetProjOnTof());
  fst->SetTof2Proj(bfst->GetProjOnTof());
  fst->SetTof1Slat(ffst->GetPointedSlat());
  fst->SetTof2Slat(bfst->GetPointedSlat());
  fst->SetD1Status(ffst->GetD1SwimStatus());
  fst->SetTrackId(bfst->GetTrackId()); // FIXE ME: temp hack
  fst->SetPhi(ffst->GetPhi());
  fst->SetTheta(ffst->GetTheta());

  tab->Add(fst);
  return kTRUE;
}


//_______________________________________________________________________
 void BrFsTrackingModule::SwimTrackBack(BrBfsTrack* bfst, 
				       BrDataTable* tab, 
				       BrDetectorVolume* bkvol,
				       Float_t z0) 
{
  // private 
  // swim bfs track back to vertex

  // Path length:
  Float_t length = bfst->GetPathLength(); // from H2 to H1

  // ---- swimming front track line to D2 front plane
  BrPlane3D d2ExP = fD2Vol->GetEffectiveEdgeExitPlane();

  BrLine3D line = bfst->GetFrontDetectorTrack()->GetTrackLine();
  BrLine3D gLine = bkvol->LocalToGlobal(line);
  line = fD2Vol->GlobalToLocal(gLine);
  // H1 to D2 exit path
  BrVector3D d2Exit = d2ExP.GetIntersectionWithLine(line);
  BrVector3D gD2Exit; fD2Vol->LocalToGlobal(d2Exit, gD2Exit, 0);
  length += (gD2Exit - bfst->GetTrackVertex()).Norm();

  BrLine3D line2 = fD2Vol->SwimBack(line, bfst->GetMomentum()); 

  // ---- swimming then through D1
  BrPlane3D d1ExP = fD1Vol->GetEffectiveEdgeExitPlane();
  gLine = fD2Vol->LocalToGlobal(line2);

  // D2 exit to D2 entrance path
  length += (gLine.GetOrigin() - gD2Exit).Norm();

  // D2 entrance to D1 exit path
  line  = fD1Vol->GlobalToLocal(gLine);
  BrVector3D d1Exit = d1ExP.GetIntersectionWithLine(line);
  BrVector3D gD1Exit; fD1Vol->LocalToGlobal(d1Exit, gD1Exit, 0);
  length += (gD1Exit - gLine.GetOrigin()).Norm();

  line2 = fD1Vol->SwimBack(line, bfst->GetMomentum());
  gLine = fD1Vol->LocalToGlobal(line2);

  // D1 exit to D1 entrance path
  length += (gLine.GetOrigin() - gD1Exit).Norm();

  // ---- project to plane transverse to beam-line at Z = Z0
  BrVector3D vtx (0, 0, z0);
  BrVector3D norm(0, 0, 1);
  BrPlane3D  vtxPlane(vtx, norm);

  // D1 entrance to z0:
  length += (vtx - gLine.GetOrigin()).Norm();

  BrVector3D trkVtx = vtxPlane.GetIntersectionWithLine(gLine);
  
  BrVector3D vtx2D1 = gLine.GetOrigin() - vtx;
  Float_t   phi = (Float_t)TMath::ATan(vtx2D1[1] / vtx2D1[0]);
  Float_t    xt = (Float_t)sqrt(vtx2D1[0]*vtx2D1[0] + vtx2D1[1]*vtx2D1[1]);
  Float_t theta = (Float_t)TMath::ATan(xt / vtx2D1[2] );

  // ---- D1 swim status
  Bool_t swimStatus;
  if(TMath::Abs(bfst->GetMomentum()) < 1000)
    swimStatus = fD1Vol->GetSwimStatus(line2, line);
  else
    swimStatus=kFALSE;

  // ---- create new FS Track 

  BrFsTrack* fst = new BrFsTrack();
  fst->SetBfsTrack(bfst);
  fst->SetFfsTrack(0);
  fst->SetBfsTrackId(bfst->GetTrackId());
  fst->SetFfsTrackId(-1);
  fst->SetMomentum(bfst->GetMomentum());
  fst->SetPathLength(length);
  fst->SetTrackVertex(trkVtx);
  fst->SetTof1Proj(bfst->GetProjOnTof1());
  fst->SetTof2Proj(bfst->GetProjOnTof());
  fst->SetTof1Slat(bfst->GetTof1PointedSlat());
  fst->SetTof2Slat(bfst->GetPointedSlat());
  fst->SetD1Status(swimStatus);
  fst->SetTrackId(bfst->GetTrackId()); // FIXE ME: temp hack
  fst->SetPhi(phi);
  fst->SetTheta(theta);

  tab->Add(fst);
}

//____________________________________________________________________
 void BrFsTrackingModule::Finish() 
{
  SetState(kFinish);

  fFfsModule->Finish();
  fBfsModule->Finish();
}

//____________________________________________________________________
 void BrFsTrackingModule::Print(Option_t* option) const
{
  // Print module information
  // See BrModule::Print for options.
  // In addition this module defines the Option:
  // <fill in here>
  
  TString opt(option);
  opt.ToLower(); 
  
  BrModule::Print(option); 
  if (opt.Contains("d")) { 
    cout << endl 
         << "  Original author: Djamel Ouerdane" << endl
         << "  Last Modifications: " << endl 
         << "    $Author: ufstasze $" << endl  
         << "    $Date: 2002/08/12 16:18:22 $"   << endl 
         << "    $Revision: 1.6 $ " << endl  
         << endl 
         << "-------------------------------------------------" << endl;
    fFfsModule->Print(option);
    fBfsModule->Print(option);
  }
}

//____________________________________________________________________
//
// $Log: BrFsTrackingModule.cxx,v $
// Revision 1.6  2002/08/12 16:18:22  ufstasze
// Added BrPathManager to support path name to the offsetfile needed for the new Ffs-Bfs matching
//
// Revision 1.5  2002/08/08 15:34:21  ufstasze
// Added new method CheckT2T3MatchNew. It checks whether bfs matches to ffs by checking the correlation between T2 and T3 track in dx, dy, dax and day
//
// Revision 1.4  2002/07/13 12:26:30  ouerdane
// fixed a small error in CheckT2T3Match (H1 pointed slat was wrong)
//
// Revision 1.3  2002/04/10 14:34:09  ekman
// checked that the FFS match status is kOk before combining with BFS
//
// Revision 1.2  2002/04/10 14:27:51  ekman
// There was a Fill() outside if(HistOn()) {... Bad!
//
// Revision 1.1  2002/04/09 02:07:40  ouerdane
// module matching FFS and BFS. If no FFS match, swim BFS back to vertex
//
//

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS