BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
// 
// Class BrTofAdcGapCalModule
//
// Calibration of the Adc Gap and Gap Start
// At present this module is ONLY useful for reading an asciifile
// and then committing the data to the DB (possibly also loading
// from file).
// The code is plainly stolen from the BrTofScintCalModule
// with minor modifications.
// 
//____________________________________________________________________
//
// $Id: BrTofAdcGapCalModule.cxx,v 1.1 2002/03/20 19:34:10 videbaek Exp $
// $Author: videbaek $
// $Date: 2002/03/20 19:34:10 $
// $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov>
//
#ifndef BRAT_BrTofAdcGapCalModule
#include "BrTofAdcGapCalModule.h"
#endif
#ifndef ROOT_TDirectory
#include "TDirectory.h"
#endif
#ifndef ROOT_TH1
#include "TH1.h"
#endif
#ifndef ROOT_TH2
#include "TH2.h"
#endif
#ifndef ROOT_TNtuple
#include "TNtuple.h"
#endif
#ifndef WIN32
#include <iostream>
#include <iomanip>
#include <fstream>
#else
#include <iomanip.h>
#include <fstream.h>
#include <iostream.h>
#endif
#ifndef BRAT_BrDataTable
#include "BrDataTable.h"
#endif
#ifndef BRAT_BrTofDig
#include "BrTofDig.h"
#endif
#ifndef BRAT_BrGeometryDbManager
#include "BrGeometryDbManager.h"
#endif
#ifndef BRAT_BrParameterDbManager
#include "BrParameterDbManager.h"
#endif
#ifndef BRAT_BrRunInfoManager
#include "BrRunInfoManager.h"
#endif

//____________________________________________________________________
ClassImp(BrTofAdcGapCalModule);

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


}

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

}

//____________________________________________________________________
 void BrTofAdcGapCalModule::SetDefaultParameters(){

}

//____________________________________________________________________
 void BrTofAdcGapCalModule::DefineHistograms()
{
  // Define histograms. They are:
  // <fill in here>

  if (GetState() != kInit) {
    Stop("DefineHistograms", "Must be called after Init"); 
    return;  
  }

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

  gDirectory = saveDir;
}

//____________________________________________________________________
 void BrTofAdcGapCalModule::Init()
{
  // Job-level initialisation
  SetState(kInit);
  
  //---------------
  // base class initialization (register calibration parameters)
  BrTofCalModule::Init();

  // FIXE ME: have to declare geo stuff
  Int_t nSlats = fParamsTof->GetNoSlats();
  BrCalibration::EAccessMode mode = BrCalibration::kRead;
  
  // check if we want to load adc gain cal from ascii file
  
  if (fLoadAscii) {
    mode = BrCalibration::kTransitional;
    fCalibration->Use("topGap", mode, nSlats);
    fCalibration->Use("topGapStart", mode, nSlats);
    fCalibration->Use("botGap", mode, nSlats);
    fCalibration->Use("botGapStart", mode, nSlats);
  }
  
  else 
    {
      // if we want to save them (ascii or DB)
      if (fSaveAscii || fCommitAscii) {
	mode = BrCalibration::kWrite;
	fCalibration->Use("topGap", mode, nSlats);
	fCalibration->Use("topGapStart", mode, nSlats);
	fCalibration->Use("botGap", mode, nSlats);
	fCalibration->Use("botGapStart", mode, nSlats);
      }
    }
}

//____________________________________________________________________
 void BrTofAdcGapCalModule::Begin()
{
  // Run-level initialisation
  SetState(kBegin);
  
  if (fLoadAscii) {
    ReadAscii();
    return;
  }
  
}

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

  if (fCommitAscii || fLoadAscii)
    return;

  // FIXE ME:
  // have to select adc values above pedestal.
  // otherwise just require valid hit but nothing else
  // Just get statistics enough to pickup the gap in the region ~3500 - 4100
  // 
}

//____________________________________________________________________
 void BrTofAdcGapCalModule::End()
{
  // Run-level finalisation
  SetState(kEnd);

}

//____________________________________________________________________
 void BrTofAdcGapCalModule::Finish()
{
  // Job-level finalisation
  SetState(kFinish);

  // if load ascii mode
  if (fLoadAscii) 
    return;
  
  // if commit mode
  if (fCommitAscii) {
    ReadAscii();
    return;
  }

  // Insert code to evaluate Gap.
  //
  if (fSaveAscii)
    SaveAscii();


}

//____________________________________________________________________
 void BrTofAdcGapCalModule::SaveAscii() 
{

  // save calibration into ascii file
  
  BrRunInfoManager* runMan = BrRunInfoManager::Instance();
  const BrRunInfo*     run = runMan->GetCurrentRun();
  if (run->GetRunNo() == -1) {
    Failure("SaveToFile", "RunInfo has run number = -1");
    return;
  }
  
  BrTofCalModule::SaveAscii();
  
  ofstream file(fCalibFile.Data(), ios::out);
  
  file << "****************************************** " << endl;
  file << "*  Calibration for Tof detector " << GetName() << endl;
  file << "*  Gap and GapStart     " << endl;
  file << "*  Used events from run " << run->GetRunNo() << endl;
  file << "****************************************** " <<endl;
  file << "*" << endl;    
  file << "* slat  |  topGap topStart botGap botStart " << endl;
  file << "* -----------------------------" << endl << endl;
  
  for (Int_t i = 0; i < fParamsTof->GetNoSlats(); i++) {
    Int_t slat = i + 1;
    file << setw(4) << slat << setw(15) 
	 << setw(15) << fCalibration->GetTopAdcGap(slat) 
	 << setw(15) << fCalibration->GetTopAdcGapStart(slat) 
	 << setw(15) << fCalibration->GetBotAdcGap(slat) 
	 << setw(15) << fCalibration->GetBotAdcGapStart(slat) 
	 << endl;
  }
  
  file << "* ------------------------------------" << endl << endl;
  
}

//____________________________________________________________________
 void BrTofAdcGapCalModule::ReadAscii() 
{
  
  BrTofCalModule::ReadAscii();
  
  ifstream file(fCalibFile.Data(), ios::in);
  
  if (!file) {
    Failure("ReadFromFile", "File %s was not found", fCalibFile.Data());
    return;
  }
  
  Float_t topGap, topGapStart, botGap, botGapStart;
  Int_t slat;
  Char_t comment[256];
  
  file.getline(comment, 256);
  while(comment[0] == '*') {
    file.getline(comment, 256);
    if (DebugLevel() > 5)
      cout << comment << endl;
  } 

  for (Int_t i = 1; i <= fParamsTof->GetNoSlats(); i++) {
    file >> slat >> topGap >> topGapStart >> botGap >> botGapStart;
    if (DebugLevel() > 5) 
      cout << setw(4) << slat << setw(12) << topGap << setw(12)<< topGapStart << setw(12)<< botGap << setw(12)<< botGapStart << endl;
        
    fCalibration->SetTopAdcGap(slat, topGap); 
    fCalibration->SetTopAdcGapStart(slat, topGapStart); 
    fCalibration->SetBotAdcGap(slat, botGap); 
    fCalibration->SetBotAdcGapStart(slat, botGapStart); 
  }

  fCalibration->SetComment("topGap",
                           "Generated by BrTofAdcGapCalModule: "
                           "reading from file so far");
  fCalibration->SetComment("botGap",
                           "Generated by BrTofAdcGapCalModule: "
                           "reading from file so far");
  fCalibration->SetComment("topGapStart",
                           "Generated by BrTofAdcGapCalModule: "
                           "reading from file so far");
  fCalibration->SetComment("botGapStart",
                           "Generated by BrTofAdcGapCalModule: "
                           "reading from file so far");
}

//____________________________________________________________________
 void BrTofAdcGapCalModule::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: Flemming Videbaek" << endl
         << "  Last Modifications: " << endl 
         << "    $Author: videbaek $" << endl  
         << "    $Date: 2002/03/20 19:34:10 $"   << endl 
         << "    $Revision: 1.1 $ " << endl  
         << endl 
         << "-------------------------------------------------" << endl;
}

//____________________________________________________________________
//
// $Log: BrTofAdcGapCalModule.cxx,v $
// Revision 1.1  2002/03/20 19:34:10  videbaek
// Added new module to be able to store Gap constants in DB. The module
// could later be coded to actually evaluate the Gap and position.
//
//

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