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

beamtime/cosy-jan12/go4/STS/TSTSProc.cxx (r4864/r3159)

Go to the documentation of this file.
00001 /* Generated by Together */
00002 
00003 #include "TSTSProc.h"
00004 #include "TCBMBeamtimeEvent.h"
00005 #include "TRocParam.h"
00006 #include "TSTSTopology.h"
00007 #include "TROOT.h"
00008 #include "TGo4Version.h"
00009 #if __GO4BUILDVERSION__ > 40502
00010 #include "go4iostream.h"
00011 #else
00012 #include "Riostream.h"
00013 #endif
00014 #include "TSystem.h"
00015 #include "TGo4UserException.h"
00016 #include "TGo4MbsEvent.h"
00017 #include "TGo4Log.h"
00018 #include "roc/Message.h"
00019 #include "roc/Board.h"
00020 #include <vector>
00021 
00022 
00023 TSTSProc::TSTSProc(const char* name) :
00024     TCBMBeamtimeProc(name),
00025         fRocInputEvent(0),
00026         fOutputEvent(0),
00027         fBeamEvent(0)
00028 {
00029         cout << "**** TSTSProc: Create instance " << name << endl;
00030         fSTSPar = (TSTSParam*) MakeParameter("STSPar", "TSTSParam" /*, "set_STSPar.C" */);
00031         ExecSetStsParamMacro();
00032         CreateHistograms();
00033         CreateClusterizers();
00034         CreateHiterizers();
00035         fRocPar = GetRocPar();
00036 }
00037 
00038 
00039 
00040 TSTSProc::~TSTSProc()
00041 {
00042         for( UInt_t iDet = 0; iDet < fClusterizers.size(); ++iDet ) {
00043                 for( UInt_t iSide = 0; iSide < fClusterizers.at( iDet ).size(); iSide++ ) {
00044                         TSTSClusterizer * & currClusterizer = fClusterizers.at( iDet ).at( iSide );
00045                         if( currClusterizer) {
00046                             delete currClusterizer;
00047                             currClusterizer = 0;
00048                         }
00049                 }
00050         }
00051 
00052     for( UInt_t iDet = 0; iDet < fHiterizers.size(); ++iDet ) {
00053         TSTSHiterizer * & currHiterizer = fHiterizers.at( iDet );
00054         if( currHiterizer ) {
00055             delete currHiterizer;
00056             currHiterizer = 0;
00057         }
00058     }
00059 
00060 }
00061 
00062 
00063 
00064 void TSTSProc::ExecSetStsParamMacro()
00065 {
00066     TString setupmacro = "set_STSPar.C";
00067     if (!gSystem->AccessPathName(setupmacro.Data())) {
00068         TGo4Log::Info("Executing ROC parameter setup script %s", setupmacro.Data());
00069         gROOT->ProcessLine(Form(".x %s", setupmacro.Data()));
00070         // need to copy parameter setup to static event array,
00071         // when restored from Autosave file, executed in UpdateFrom method
00072     } else {
00073         TGo4Log::Info("NO STS parameter setup script %s. Results will be wrong at least because the topology is not specified!", setupmacro.Data());
00074     }
00075 }
00076 
00077 
00078 
00079 void TSTSProc::CreateHistograms()
00080 {
00081     TSTSTopology * topology = fSTSPar->fSTSTopology;
00082     fSTSDigiPos.resize( topology->GetDetArrSize() );
00083     fSTSDigiAmp.resize( topology->GetDetArrSize() );
00084     fSTSDigiTime.resize( topology->GetDetArrSize() );
00085     fSTSDigiAmpVsPos.resize( topology->GetDetArrSize() );
00086     fSTSClustPos.resize( topology->GetDetArrSize() );
00087     fSTSClustAmp.resize( topology->GetDetArrSize() );
00088     fSTSClustAmpVsPos.resize( topology->GetDetArrSize() );
00089     fSTSClustAmpVsTime.resize( topology->GetDetArrSize() );
00090     fSTSHitXY.resize( topology->GetDetArrSize() );
00091     fSTSHitXYBinned.resize( topology->GetDetArrSize() );
00092     for( UInt_t iDet=0; iDet < topology->GetDetArrSize(); iDet++) {
00093         fSTSDigiPos.at( iDet ).resize( TSTSTopology::kNSides );
00094         fSTSDigiAmp.at( iDet ).resize( TSTSTopology::kNSides );
00095         fSTSDigiTime.at( iDet ).resize( TSTSTopology::kNSides );
00096         fSTSDigiAmpVsPos.at( iDet ).resize( TSTSTopology::kNSides );
00097         fSTSClustPos.at( iDet ).resize( TSTSTopology::kNSides );
00098         fSTSClustAmp.at( iDet ).resize( TSTSTopology::kNSides );
00099         fSTSClustAmpVsPos.at( iDet ).resize( TSTSTopology::kNSides );
00100         fSTSClustAmpVsTime.at( iDet ).resize( TSTSTopology::kNSides );
00101 
00102         UInt_t nStrips = topology->GetStripArrSize( iDet, TSTSTopology::kPSide );
00103         for( UInt_t iSide = 0; iSide < TSTSTopology::kNSides; ++iSide ) {
00104             Char_t sideName = TSTSTopology::GetSideName( iSide );
00105             fSTSDigiPos.at( iDet ).at( iSide ) = MakeTH1( 'D', Form( "STS/DigiPos%d%c", iDet, sideName ), Form("Digi position on STS station %d, %c-side", iDet, sideName ), nStrips, 0, nStrips );
00106             fSTSDigiAmp.at( iDet ).at( iSide ) = MakeTH1( 'D', Form( "STS/DigiAmp%d%c", iDet, sideName ), Form("Digi amplitude on STS station %d, %c-side", iDet, sideName), 500, 0, 500 );
00107             fSTSDigiTime.at( iDet ).at( iSide ) = MakeTH1( 'D', Form( "STS/DigiTime%d%c", iDet, sideName ), Form("Digi time w.r.t. trigger on STS station %d, %c-side", iDet, sideName ), 1000, -2000, 2000 );
00108             fSTSDigiAmpVsPos.at( iDet ).at( iSide ) = MakeTH2( 'D', Form( "STS/DigiAmpVsPos%d%c", iDet, sideName ), Form("Digi amplitude on STS station %d, %c-side", iDet, sideName ), nStrips, 0, nStrips, 125, 0, 500 );
00109             fSTSClustPos.at( iDet ).at( iSide ) = MakeTH1( 'D', Form( "STS/ClustPos%d%c", iDet, sideName ), Form("Cluster position on STS station %d, %c-side", iDet, sideName ), nStrips, 0, nStrips );
00110             fSTSClustAmp.at( iDet ).at( iSide ) = MakeTH1( 'D', Form( "STS/ClustAmp%d%c", iDet, sideName ), Form("Cluster amplitude on STS station %d, %c-side", iDet, sideName ), 500, 0, 500 );
00111             fSTSClustAmpVsPos.at( iDet ).at( iSide ) = MakeTH2( 'D', Form( "STS/ClustAmpVsPos%d%c", iDet, sideName ), Form("Cluster amplitude on STS station %d, %c-side", iDet, sideName ), nStrips, 0, nStrips, 125, 0, 500 );
00112             fSTSClustAmpVsTime.at( iDet ).at( iSide ) = MakeTH2( 'D', Form( "STS/ClustAmpVsTime%d%c", iDet, sideName ), Form("Cluster amplitude vs. time w.r.t. trigger on STS station %d, %c-side", iDet, sideName), 100, -1000, 1000, 100, 0, 500 );
00113         }
00114         fSTSHitXY.at( iDet ) = MakeTH2( 'D', Form("STS/HitXY%d", iDet), Form("Hit position in STS station %d", iDet), nStrips, -6.4, 6.4, nStrips, -6.4, 6.4 );
00115         fSTSHitXY.at( iDet )->GetXaxis()->SetTitle( "X pos" );
00116         fSTSHitXY.at( iDet )->GetYaxis()->SetTitle( "Y pos" );
00117         fSTSHitXYBinned.at( iDet ) = MakeTH2( 'D', Form("STS/HitXYBinned%d", iDet), Form("Hit position in STS station (binned) %d", iDet), nStrips / 8, -6.4, 6.4, nStrips / 8, -6.4, 6.4 );
00118         fSTSHitXYBinned.at( iDet )->GetXaxis()->SetTitle( "X pos" );
00119         fSTSHitXYBinned.at( iDet )->GetYaxis()->SetTitle( "Y pos" );
00120     }
00121 }
00122 
00123 
00124 
00125 void TSTSProc::CreateClusterizers()
00126 {
00127     TSTSTopology * topology = fSTSPar->fSTSTopology;
00128     fClusterizers.resize( topology->GetDetArrSize() );
00129     for( UInt_t iDet=0; iDet<topology->GetDetArrSize(); iDet++) {
00130         fClusterizers.at( iDet ).resize( TSTSTopology::kNSides );
00131         for( Int_t iSide = 0; iSide < TSTSTopology::kNSides; iSide++ ) {
00132             fClusterizers.at( iDet ).at( iSide ) = new TSTSClusterizer( iDet, iSide );
00133             fClusterizers.at( iDet ).at( iSide )->SetTimeWindow( fSTSPar->fClusterizerTimeWindow );
00134             fClusterizers.at( iDet ).at( iSide )->SetTimeTolerance( fSTSPar->fClusterizerTimeTolerance );
00135             fClusterizers.at( iDet ).at( iSide )->SetSpaceTolerance( fSTSPar->fClusterizerSpaceTolerance );
00136         }
00137     }
00138 }
00139 
00140 
00141 
00142 void TSTSProc::CreateHiterizers()
00143 {
00144     TSTSTopology * topology = fSTSPar->fSTSTopology;
00145     fHiterizers.resize( topology->GetDetArrSize() );
00146     for( UInt_t iDet=0; iDet<topology->GetDetArrSize(); iDet++) {
00147         fHiterizers.at( iDet ) = new TSTSHiterizer( iDet );
00148         fHiterizers.at( iDet )->SetTimeWindow( fSTSPar->fHiterizerTimeWindow );
00149         fHiterizers.at( iDet )->SetTimeTolerance( fSTSPar->fHiterizerTimeTolerance );
00150     }
00151 }
00152 
00153 
00154 TRocParam * TSTSProc::GetRocPar()
00155 {
00156     TRocParam * rocParam = dynamic_cast< TRocParam * >( GetParameter( "RocPar" ) );
00157     if( ! rocParam ) {
00158         printf("Error in TSTSProc::GetRocPar: RocPar parameter not found\n");
00159     }
00160     return rocParam;
00161 }
00162 
00163 
00164 
00165 void TSTSProc::FinalizeEvent()
00166 {
00167     if( ! fRocInputEvent->IsValid() ) {
00168         return;
00169     }
00170 
00171     TSTSTopology * topology = fSTSPar->fSTSTopology;
00172     for( UInt_t iRoc = 0; iRoc < topology->GetRocArrSize(); iRoc++ ) {
00173         if( ! topology->IsValidRoc( iRoc ) ) {
00174             continue;
00175         }
00176 
00177         TRocData* rocData = dynamic_cast< TRocData * >( fRocInputEvent->getEventElement( iRoc ) );
00178         if( ! rocData ) {
00179             continue;
00180         }
00181 
00182         for( UInt_t iMsg = 0; iMsg < rocData->fExtMessages.size(); iMsg++) {
00183             TRocMessageExtended exMsg = rocData->fExtMessages.at( iMsg );
00184             if( exMsg.GetMessageType() != roc::MSG_HIT) {
00185                 continue; // note that input vector contains _all_ message types now!
00186             }
00187 
00188             Int_t nx = exMsg.GetNxNumber();
00189             Int_t ch = exMsg.GetNxChNum();
00190             Float_t timeDist = exMsg.GetTriggerDeltaT(); // corrected trigger diff is already in input message!
00191             Double_t amp = exMsg.GetCorrectedNxADC();
00192             Int_t det = topology->GetDetector( iRoc, nx );
00193             TSTSTopology::ESTSSide side = topology->GetSide( iRoc, nx );
00194             Int_t strip = topology->GetStrip( iRoc, nx, ch );
00195 
00196             fSTSDigiPos.at( det ).at( side )->Fill( strip );
00197             fSTSDigiAmp.at( det ).at( side )->Fill( amp );
00198             fSTSDigiTime.at( det ).at( side )->Fill( timeDist );
00199             fSTSDigiAmpVsPos.at( det ).at( side )->Fill( strip, amp );
00200 
00201             TSTSDigi digi( strip, exMsg.GetFullTime(), amp );
00202 
00203             Bool_t useDigi = kTRUE;
00204             if( fRocPar->ttriMode[ iRoc ][ nx ] ) {
00205                 Float_t const & thr = fSTSPar->fTtriThrUseGlobal ? fSTSPar->fTtriGlobalThr : fSTSPar->fTtriThr[ iRoc ][ nx ];
00206                 if( amp < thr ) {
00207                     useDigi = kFALSE;
00208                 }
00209             }
00210             if( useDigi ) {
00211                 fClusterizers.at( det ).at( side )->FeedDigi( digi );
00212             }
00213 
00214             fOutputEvent->AddDigi( det, side, digi );
00215         }
00216 
00217     }
00218 
00219 
00220         for( UInt_t iDet = 0; iDet < topology->GetDetArrSize(); iDet++ ) {
00221             for( UInt_t iSide = 0; iSide < TSTSTopology::kNSides; iSide++ ) {
00222                         TSTSCluster clust;
00223                         while( fClusterizers.at( iDet ).at( iSide )->FetchCluster( fRocPar->noTrigger, clust ) ) {
00224                                 fSTSClustPos.at( iDet ).at( iSide )->Fill( clust.GetMainStrip() );
00225                                 fSTSClustAmp.at( iDet ).at( iSide )->Fill( clust.GetAmplitude() );
00226                                 fSTSClustAmpVsPos.at( iDet ).at( iSide )->Fill( clust.GetMainStrip(), clust.GetAmplitude() );
00227                                 fOutputEvent->AddCluster( iDet, iSide, clust );
00228                                 fHiterizers.at( iDet )->FeedCluster( clust, (TSTSTopology::ESTSSide) iSide );
00229                         }
00230                 }
00231         }
00232 
00233         for( UInt_t iDet = 0;  iDet < topology->GetDetArrSize(); iDet++ ) {
00234                 TSTSHit hit;
00235                 while( fHiterizers.at( iDet )->FetchHit( fRocPar->noTrigger, hit ) ) {
00236 
00237                         TSpacepoint point;
00238                         fSTSGeometry.MakeSpacepoint( hit, iDet, point );
00239 
00240                         fSTSHitXY.at( iDet )->Fill( point.GetX(), point.GetY() );
00241                         fSTSHitXYBinned.at( iDet )->Fill( point.GetX(), point.GetY() );
00242                         fOutputEvent->AddPoint( iDet, point );
00243                 }
00244         }
00245 
00246 
00247 
00248 }
00249 
00250 
00251 void TSTSProc::InitEvent(TGo4EventElement* outevnt)
00252 {
00253         // first assign input event:
00254         // since input event object is never discarded within processor lifetime,
00255         // we just search for subevent by name once to speed up processing
00256         if(fRocInputEvent==0)
00257         {
00258                 TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00259                 if(btevent)
00260                 {
00261                         fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00262                 }       
00263                 else
00264                 {
00265                         fRocInputEvent=dynamic_cast<TRocEvent*>(GetInputEvent());
00266 
00267                 }
00268                 if(fRocInputEvent==0) {
00269                         GO4_STOP_ANALYSIS_MESSAGE("**** TSTSProc: Fatal error: input event is not a TRocEvent!!! STOP GO4");
00270                 }   
00271         }
00272 
00273         // then assign output event
00274         // since output event object is never discarded within processor lifetime,
00275         // we just search for subevent by name once to speed up processing
00276         if(fOutputEvent==0)
00277         {
00278                 TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00279                 if(btevent)
00280                 {
00281                         fOutputEvent=dynamic_cast<TSTSEvent*>(btevent->GetSubEvent("STS"));
00282                         fBeamEvent=dynamic_cast<TBeamMonitorEvent*>(btevent->GetSubEvent("BEAM"));
00283                         fFiberHodEvent1=dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo1"));
00284                         fFiberHodEvent2=dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo2"));
00285                 }
00286                 else
00287                 {
00288 
00289                         fOutputEvent= dynamic_cast<TSTSEvent*>(outevnt);
00290                 }
00291                 if(fOutputEvent==0) {
00292                         GO4_STOP_ANALYSIS_MESSAGE("**** TSTSProc: Fatal error: output event is not a TSTSEvent!!! STOP GO4");
00293                 }
00294 
00295         }
00296 
00297 }
00298 

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