BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
// 
// 
// 

//____________________________________________________________________
//
// $Id: BrTpcSequencePPModule.cxx,v 1.3 2002/01/03 19:53:34 cholm Exp $
// $Author: cholm $
// $Date: 2002/01/03 19:53:34 $
// $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov>
//
#ifndef BRAT_BrTpcSequencePPModule
#include "BrTpcSequencePPModule.h"
#endif

#ifndef ROOT_TDirectory
#include "TDirectory.h"
#endif
#ifndef WIN32
#include <iostream>
#include <iomanip>
#else
#include <iostream.h>
#include <iomanip.h>
#endif
#ifndef BRAT_BrParameterDbManager
#include "BrParameterDbManager.h"
#endif
#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif
#ifndef BRAT_BrTableNames
#include "BrTableNames.h"
#endif

//____________________________________________________________________

ClassImp(BrTpcSequencePPModule);

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

  // set default values
  SetMinSeqLength();   
  SetPadCutLow();   
  SetPadCutHigh();  
  SetTimeCutLow();  
  SetTimeCutHigh(); 
  SetMinAdc();      
}
//____________________________________________________________________
 BrTpcSequencePPModule::BrTpcSequencePPModule(const Char_t* name, const Char_t* title)
: BrModule(name, title)
{
  // Named Constructor
  SetState(kSetup);

  // set default values
  SetMinSeqLength();   
  SetPadCutLow();   
  SetPadCutHigh();  
  SetTimeCutLow();  
  SetTimeCutHigh(); 
  SetMinAdc();      
}

//____________________________________________________________________
 void BrTpcSequencePPModule::ApplyTimeAndAdcCuts(BrTpcSequence *seq, 
						TObjArray *outTable)
{
  // This method takes a sequence as input. It removes the part of the
  // sequence below and above the fTimeCutLow and fTimeCutHigh and the
  // bins where the Adc values are below fAdcMin
  // 
  // The algorithm used is to define an array of shorts called split
  // For each bin in the valid range a number is given to groups of
  // consecutive bins with adc values above fAdcMin. After stepping
  // thorugh the whole sequence new sequences are mnade if the
  // sequence is at least as long as fMinSeqLength
  //
  // Ex :
  //
  //  Input sequence
  //  Row :   7 Pad :  41
  //  Time :  18  19  20  21  22  23  24  25  26  27
  //  Adc :  152 192  67  55  38  16   5   2   1  -1
  //          ^   ^
  //          ___\_____ ignored because of time cut
  //  Split array : 
  //                   1   1   1   1   1   1   1   0
  //
  //  New sequences : 
  //  Row :   7 Pad :  41
  //  Time :  20  21  22  23  24  25  26
  //  Adc :   67  55  38  16   5   2   1
  //
  // To get ouput like this set the debuglevel to 20
  
  Bool_t keepOld = kTRUE;
  
  const Int_t startTime = seq->GetTime();
  const Int_t stopTime = startTime + seq->GetNseq() - 1;

  if(startTime > fTimeCutHigh || stopTime < fTimeCutLow) {
    
    fSeqTable->DeleteObject(seq);
    return;
  }

  Int_t start = 0;
  if(startTime < fTimeCutLow) {
    
    start = fTimeCutLow-startTime;
    keepOld = kFALSE;
  }
  
  Int_t stop = stopTime-startTime;
  if(stopTime > fTimeCutHigh) {
    
    stop = fTimeCutHigh-startTime;
    keepOld = kFALSE;
  }

  const Int_t nTimeBins = stop-start+1;
  Short_t *split  = new Short_t[nTimeBins];
  Short_t splitNo   = 0; // splitNo tells how many new sequences
  Bool_t makingNewSequence = kFALSE;
  
  for(Int_t i = start; i < stop+1; i++) {
    
    if(seq->GetAdc(i) > fMinAdc) {
	
      if(!makingNewSequence) {
	
	++splitNo;
	makingNewSequence = kTRUE;
      }
      
      split[i-start] = splitNo;
      
    } else {
      
      keepOld = kFALSE;
      
      if(makingNewSequence) 
	makingNewSequence = kFALSE;
      
      split[i-start] = 0;
      
    }
  }
  
  if(keepOld == kTRUE) {
      
    outTable->Add(seq);
    delete [] split;
    return;
  }
  
  if(DebugLevel() > 20) {
    
    cout << "Original : " << endl;
    seq->Print();

    cout << "Split : " << endl << "     ";
  
    for(Int_t i = 0; i < nTimeBins; i++) {
    
      cout << setw(4) << split[i];
    }

    cout << endl << endl << "New sequences : " << endl;
  }
  
  // make the new sequences and add them if they are long enough
  for(Int_t j = 1; j <= splitNo; j++ ) {

    // find start and number of time bins.
    Int_t newStart = 1000;
    Int_t newStop  = 0;

    for( Int_t k = 0; k < nTimeBins; k++ ) {

      if(split[k] == j ) {

	if( newStart > k )
	  newStart = k;

	if( newStop < k )
	  newStop = k;
      }
    }

    const Int_t newSeqLength = newStop-newStart+1;

    if(newSeqLength < fMinSeqLength)
      continue;

    BrTpcSequence *newSeq = new BrTpcSequence(newSeqLength);
    newSeq->SetRow(seq->GetRow());
    newSeq->SetPad(seq->GetPad());
    newSeq->SetTime(newStart + start + startTime);

    for( Int_t k = 0; k < newStop-newStart+1; k++ ){

      newSeq->SetAdc(k, seq->GetAdc(start + newStart + k));
    }

    if(DebugLevel() > 20)
      newSeq->Print();

    outTable->Add( newSeq );
  }
  
  delete [] split;
  fSeqTable->DeleteObject(seq);

}

//____________________________________________________________________
 void BrTpcSequencePPModule::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();

  // Make histograms here 

  gDirectory = saveDir;
}

//____________________________________________________________________
 void BrTpcSequencePPModule::Init()
{
  // Job-level initialisation
  SetState(kInit);

  BrParameterDbManager* gParamDb = BrParameterDbManager::Instance();
  fTpcParams = (BrDetectorParamsTPC*)
    gParamDb->GetDetectorParameters("BrDetectorParamsTPC", GetName());
}

//____________________________________________________________________
 void BrTpcSequencePPModule::Event(BrEventNode* inNode, BrEventNode* outNode)
{
  // Tme event methods modifies the sequence table in the in node, and
  // therefore has no special output.   
  // 
  // The strategy is :
  // a) throw away sequences in pad strictly less (greater) than 
  // pad low (high) cut
  // b) remove 0 (default) and negative values from sequences by
  // cutting them in pieces
  //  ( -1, 0, 10, 12, 8, 6, 0, 5, 3, 0, 10, 20, 10, 5 )
  //   ==>
  //  ( 10, 12, 8, 6 )     &&  ( 10, 20, 10, 5 )
  //  ( 5, 3 ) is not kept with default parameters since it is only 2 long.
  // c) remove the part of the sequences that has time < fCutOffTime
  // since a lot of noise was observed there with real data
  SetState(kEvent);
  
    if(DebugLevel()>2)
    cout << "Entering " << GetName() 
	 << "BrTpcClusterModule Event()" << endl;
  
  fSeqTable = 
    inNode->GetDataTable(Form("%s %s", BRTABLENAMES kTPCSequence, GetName()));
  
  if(fSeqTable == 0) {
    
    if(DebugLevel() > 0 ) 
      Warning("Event", "BrDataTable %s %s not found in this event!",
	      BRTABLENAMES kTPCSequence, GetName());
    
    return;
  }
  
  TObjArray modifiedSequences(5);

  const Int_t nSeq = fSeqTable->GetEntries();
  
  for(Int_t i = 0; i < nSeq; i++) {
    
    BrTpcSequence *seq = (BrTpcSequence*)fSeqTable->At(i);
    
    // test pad and length 
    if(seq->GetPad() < fPadCutLow || seq->GetPad() > fPadCutHigh ||
       !fTpcParams->IsPadActive(seq->GetRow(), seq->GetPad()) ||
       seq->GetNseq() < fMinSeqLength) {
      
      fSeqTable->DeleteObjectAt(i);
      continue;
    }
    
    ApplyTimeAndAdcCuts(seq, &modifiedSequences);
    
    const Int_t nModSeq = modifiedSequences.GetEntriesFast();
      
    for(Int_t j = 0; j < nModSeq; j++) {
	
      BrTpcSequence *newSeq = (BrTpcSequence*)modifiedSequences.At(j);
      if(newSeq != seq)
	fSeqTable->Add(newSeq);
    }
    
    modifiedSequences.Clear();
  }
  
  fSeqTable->Compress();
}

//____________________________________________________________________
 void BrTpcSequencePPModule::Print(Option_t* option) const
{
  // Print module information
  // See BrModule::Print for options.
  // In addition this module defines the Option:
  // d - print original author and who, when modified last

  TString opt(option);
  opt.ToLower(); 
  
  BrModule::Print(option); 
  if (opt.Contains("d")) 
    cout << endl 
         << "  Original author: Peter H.L. Christiansen" << endl
         << "  Last Modifications: " << endl 
         << "    $Author: cholm $" << endl  
         << "    $Date: 2002/01/03 19:53:34 $"   << endl 
         << "    $Revision: 1.3 $ " << endl  
         << endl 
         << "-------------------------------------------------" << endl;
  
  cout << "MinSeqLength : " << setw(8) << fMinSeqLength << endl   
       << "PadCutLow    : " << setw(8) << fPadCutLow << endl   
       << "PadCutHigh   : " << setw(8) << fPadCutHigh << endl  
       << "TimeCutLow   : " << setw(8) << fTimeCutLow << endl  
       << "TimeCutHigh  : " << setw(8) << fTimeCutHigh << endl 
       << "MinAdc       : " << setw(8) << fMinAdc << endl;
  
}

//____________________________________________________________________
//
// $Log: BrTpcSequencePPModule.cxx,v $
// Revision 1.3  2002/01/03 19:53:34  cholm
// Prepared to use BrTableNames class (or perhaps BrDetectorList) for table names
//
// Revision 1.2  2001/10/12 10:59:16  pchristi
// Instead of just checking for dead pads the PP module now instead checks that
// the pad is active. This makes a difference for simulated data only.
//
// Revision 1.1  2001/07/06 10:20:43  pchristi
// Added a new version of the tpc sequence preprocessor. It is more flexible and less messy (I hope).
//
//

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