• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/cosy-jan12/go4/STS/TSTSHiterizer.cxx (r4864/r3090)

Go to the documentation of this file.
00001 /*
00002  * TSTSHiterizer.cxx
00003  *
00004  *  Created on: Jan 9, 2012
00005  *      Author: isorokin
00006  */
00007 
00008 #include "TSTSHiterizer.h"
00009 #include "TMath.h"
00010 
00011 TSTSHiterizer::TSTSHiterizer( Int_t det )
00012 {
00013         fDetector = det;
00014         fTimeTolerance = kDefTimeTolerance;
00015         fTimeWindow = kDefTimeWindow;
00016         fLatestClusterTime = 0;
00017 }
00018 
00019 TSTSHiterizer::~TSTSHiterizer()
00020 {
00021 }
00022 
00023 
00024 void TSTSHiterizer::ClearClustBuffers()
00025 {
00026     fClusters[TSTSTopology::kPSide].clear();
00027     fClusters[TSTSTopology::kNSide].clear();
00028 }
00029 
00030 
00031 
00032 Bool_t TSTSHiterizer::Match( const TSTSCluster & clust1, const TSTSCluster & clust2) const
00033 {
00034     Long64_t diff = clust1.GetTime() - clust2.GetTime();
00035     return TMath::Abs( diff ) <= fTimeTolerance;
00036 }
00037 
00038 
00039 
00040 /*
00041  * In triggered mode the method must be called only when all clusters are fed in.
00042  */
00043 void TSTSHiterizer::ReconstructHits( Bool_t noTrigger )
00044 {
00045     while( IsClusterBuffersFilled( noTrigger ) ) {
00046         TSTSTopology::ESTSSide oldestClusterSide = GetOldesetClusterSide();
00047         const TSTSCluster & oldestCluster = fClusters[oldestClusterSide].front();
00048         TSTSTopology::ESTSSide oppositeSide = TSTSTopology::OppositeSide( oldestClusterSide );
00049         std::deque<TSTSCluster>::iterator oppSideIter = fClusters[oppositeSide].begin();
00050         while( 1 ) {
00051             if( oppSideIter == fClusters[oppositeSide].end() ) {
00052                 break;
00053             }
00054             if( oppSideIter->GetTime() - oldestCluster.GetTime() > fTimeTolerance  ) {
00055                 break;
00056             }
00057             if( Match( oldestCluster, * oppSideIter) ) {
00058                 CreateHit( oldestCluster, oldestClusterSide, * oppSideIter, oppositeSide );
00059             }
00060             oppSideIter++;
00061         }
00062         fClusters[oldestClusterSide].pop_front();
00063     }
00064 
00065     const Bool_t clearClustBuffersBetweenEvents = kTRUE;
00066     if( clearClustBuffersBetweenEvents ) {
00067         if( ! noTrigger ) {
00068             ClearClustBuffers();
00069         }
00070     }
00071 }
00072 
00073 
00074 
00075 void TSTSHiterizer::CheckTimeWindowSufficient( Long64_t newClustTime )
00076 {
00077     if( fLatestClusterTime - newClustTime + fTimeTolerance > fTimeWindow ) {
00078         fTimeWindow = fTimeWindow * 2;
00079         printf( "Error in TSTSHiterizer: Time window is too small. Increasing by factor of 2. New value is %lld. Happened at time %lld\n", fTimeWindow, newClustTime );
00080     }
00081     if( newClustTime > fLatestClusterTime ) {
00082         fLatestClusterTime = newClustTime;
00083     }
00084 }
00085 
00086 
00087 
00088 void TSTSHiterizer::InsertClusterSorted(TSTSTopology::ESTSSide side, const TSTSCluster & cluster)
00089 {
00090     if( fClusters[side].size() == 0 ) {
00091         fClusters[side].push_back( cluster );
00092     }
00093     else {
00094         for( std::deque<TSTSCluster>::iterator it = fClusters[side].end(); it != fClusters[side].begin(); it-- ) {
00095             if( cluster.GetTime() > ( it - 1 )->GetTime() ) {
00096                 fClusters[side].insert( it, cluster );
00097                 return;
00098             }
00099         }
00100     }
00101 }
00102 
00103 
00104 
00105 
00106 void TSTSHiterizer::FeedCluster( const TSTSCluster & cluster, TSTSTopology::ESTSSide side )
00107 {
00108     CheckTimeWindowSufficient( cluster.GetTime() );
00109     InsertClusterSorted( side, cluster );
00110 }
00111 
00112 
00113 
00114 void TSTSHiterizer::CreateHit( const TSTSCluster & clust1, TSTSTopology::ESTSSide side1, const TSTSCluster & clust2, TSTSTopology::ESTSSide side2)
00115 {
00116     if( side1 == TSTSTopology::kPSide ) {
00117         fHits.push_back( TSTSHit( clust1, clust2 ) );
00118     }
00119     else {
00120         fHits.push_back( TSTSHit( clust2, clust1 ) );
00121     }
00122 }
00123 
00124 
00125 
00126 /*
00127  * Assumes that the cluster buffers fClusters are not empty
00128  */
00129 Bool_t TSTSHiterizer::IsClusterBuffersContainSufficientTimeInterval() const
00130 {
00131     TSTSTopology::ESTSSide oldestClustSide = GetOldesetClusterSide();
00132     TSTSTopology::ESTSSide oppositeSide = TSTSTopology::OppositeSide( oldestClustSide );
00133     return fClusters[oppositeSide].back().GetTime() - fClusters[oldestClustSide].front().GetTime() > fTimeWindow;
00134 }
00135 
00136 
00137 
00138 Bool_t TSTSHiterizer::IsClusterBuffersFilled( Bool_t noTrigger ) const {
00139     if( fClusters[TSTSTopology::kPSide].size() == 0 ) return kFALSE;
00140     if( fClusters[TSTSTopology::kNSide].size() == 0 ) return kFALSE;
00141     if( noTrigger ) {
00142         if( ! IsClusterBuffersContainSufficientTimeInterval() ) return kFALSE;
00143     }
00144     return kTRUE;
00145 }
00146 
00147 
00148 
00149 void TSTSHiterizer::PrintBuffers() const
00150 {
00151     printf( "===== Cluster buffer state: =====\n");
00152     printf( "Times of p-side clusters, size=%lu \n", fClusters[TSTSTopology::kPSide].size() );
00153     for( std::deque<TSTSCluster>::const_iterator it = fClusters[TSTSTopology::kPSide].begin(); it != fClusters[TSTSTopology::kPSide].end(); it++ ) {
00154         printf("%lld\n", it->GetTime() );
00155     }
00156     printf( "Times of n-side clusters, size=%lu \n", fClusters[TSTSTopology::kNSide].size());
00157     for( std::deque<TSTSCluster>::const_iterator it = fClusters[TSTSTopology::kNSide].begin(); it != fClusters[TSTSTopology::kNSide].end(); it++ ) {
00158         printf("%lld\n", it->GetTime() );
00159     }
00160 }
00161 
00162 
00163 
00164 /*
00165  * Assumes that the cluster buffers fClusters are not empty
00166  */
00167 TSTSTopology::ESTSSide TSTSHiterizer::GetOldesetClusterSide() const
00168 {
00169     return fClusters[TSTSTopology::kPSide].front().GetTime() < fClusters[TSTSTopology::kNSide].front().GetTime() ? TSTSTopology::kPSide : TSTSTopology::kNSide;
00170 }
00171 
00172 /*
00173  * In triggered mode the method must be called only when all clusters are already fed in.
00174  * Returns
00175  */
00176 
00177 Bool_t TSTSHiterizer::FetchHit( Bool_t noTrigger, TSTSHit & hit )
00178 {
00179     ReconstructHits( noTrigger );
00180     if( fHits.size() > 0 ) {
00181         hit = fHits.front();
00182         fHits.pop_front();
00183         return kTRUE;
00184     }
00185     return kFALSE;
00186 }
00187 
00188 
00189 /*
00190  * Clear all buffers. Normally not needed.
00191  */
00192 void TSTSHiterizer::Clear()
00193 {
00194     ClearClustBuffers();
00195     fHits.clear();
00196 }
00197 

Generated on Tue Dec 10 2013 04:52:18 for ROCsoft by  doxygen 1.7.1