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

beamtime/sts-lasertest/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 
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 "roc/Message.h"
00018 #include "roc/Board.h"
00019 #include <vector>
00020 
00021 
00022 TSTSProc::TSTSProc(const char* name) : TCBMBeamtimeProc(name), 
00023         fRocInputEvent(0),
00024         fEpicsInputEvent(0),
00025         fOutputEvent(0)
00026 
00027 {
00028         cout << "**** TSTSProc: Create instance " << name << endl;
00029 //      TString obname;
00030 //      TString obtitle;
00031 
00032         fPar = (TSTSParam*) MakeParameter("STSPar", "TSTSParam");
00033 
00034         fRocParam = dynamic_cast< TRocParam * >( GetParameter( "RocPar" ) );
00035            if( ! fRocParam ) {
00036               GO4_STOP_ANALYSIS_MESSAGE("**** TSTSProc: Error: RocPar parameter not found! check your setup! STOP GO4\n");
00037 
00038            }
00039 
00040 
00041 
00042         fRocMessageBuffer= new TRocEvent("STSbuffer",42);
00043         for(int n=0;n<MAX_ROC;++n)
00044            {
00045               fOffScanpoint[n]=kFALSE;
00046               fInScanpoint[n] =kFALSE;
00047               fNextScanId[n]=0;
00048               fEventClosed[n]=kFALSE;
00049            }
00050         fReplayBuffers=kFALSE;
00051 
00052 
00053 //      fSTStm.resize( fSTSTopology.GetNDetectors() );
00054 //      fSTStmGate.resize( fSTSTopology.GetNDetectors() );
00055 //      fSTSNeg.resize( fSTSTopology.GetNDetectors() );
00056 //      fSTSPos.resize( fSTSTopology.GetNDetectors() );
00057 //      fSTSNegTimegated.resize( fSTSTopology.GetNDetectors() );
00058 //      fSTSPosTimegated.resize( fSTSTopology.GetNDetectors() );
00059 //      fSTSHit.resize( fSTSTopology.GetNDetectors() );
00060 //
00061 //      for (int iDet=0; iDet<fSTSTopology.GetNDetectors(); iDet++) {
00062 //              fSTStm.at(iDet) = MakeTH1('I', Form("STS/STS%dtm", iDet), Form("Time correlation on STS%d to Trigger signal", iDet), 500, -1000., 4000.);
00063 //              fSTStmGate.at(iDet) = MakeWinCond(Form("STS/STS%dtm_Gate", iDet), -20, 2000, fSTStm.at(iDet)->GetName());
00064 //              fSTSNeg.at(iDet) = MakeTH1('D', Form("STS/STS%d_Neg", iDet), Form("STS Station %d Negative side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00065 //              fSTSPos.at(iDet) = MakeTH1('D', Form("STS/STS%d_Pos", iDet), Form("STS Station %d Positive side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00066 //              fSTSNegTimegated.at(iDet) = MakeTH1('D', Form("STS/STS%d_Neg_Gated", iDet), Form("STS Station %d Negative side under time gate", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00067 //              fSTSPosTimegated.at(iDet) = MakeTH1('D', Form("STS/STS%d_Pos_Gated", iDet), Form("STS Station %d Positive side under time gate", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00068 //
00069 //              fSTSHit.at( iDet ).resize( fSTSTopology.GetNSides() );
00070 //              fSTSHit.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH1( 'D', Form("STS/HitPos%dp", iDet), Form("STS Station %d p-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00071 //              fSTSHit.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH1( 'D', Form("STS/HitPos%dn", iDet), Form("STS Station %d n-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00072 //      }
00073 
00074 
00075         fLaserPosition=MakeTH2( 'I', "STS/LaserPosition", "Current laser table coordinates", 100, -50,50 , 100, -50, 50 );
00076         for(int n=0;n<MAX_ROC;++n)
00077         {
00078            char folder[30];
00079       sprintf(folder,"STS/ROC%u/",n);
00080            for(unsigned nx=0;nx<MAX_NX;nx++) {
00081                    //if (!AssertNX(nx)) continue;
00082                    char nxfolder[30], nxinfo[30];
00083                    sprintf(nxfolder,"%sNX%u/Roc%u_nx%u_", folder, nx, n, nx);
00084                    sprintf(nxinfo,"ROC = %u NXYTER = %u", n, nx);
00085 
00086               fNxChannelVsLaserX[n][nx]=MakeTH2('I', Form("%schannels_LaserX", nxfolder), Form("Channels from %s vs laser X", nxinfo), 128, 0., 128.,100,-50,50, "ch","Xpos");
00087               fNxChannelVsLaserY[n][nx]=MakeTH2('I', Form("%schannels_LaserY", nxfolder), Form("Channels from %s vs laser Y", nxinfo), 128, 0., 128.,100,-50,50, "ch","Ypos");
00088            }
00089         }
00090 
00091 
00092         fSTSDigiPos.resize( fSTSTopology.GetNDetectors() );
00093    fSTSDigiPosLaserX.resize( fSTSTopology.GetNDetectors() );
00094    fSTSDigiPosLaserY.resize( fSTSTopology.GetNDetectors() );
00095         fSTSDigiAmp.resize( fSTSTopology.GetNDetectors() );
00096         fSTSDigiTime.resize( fSTSTopology.GetNDetectors() );
00097         fSTSDigiAmpVsPos.resize( fSTSTopology.GetNDetectors() );
00098         fSTSClustPos.resize( fSTSTopology.GetNDetectors() );
00099         fSTSClustAmp.resize( fSTSTopology.GetNDetectors() );
00100         fSTSClustAmpVsPos.resize( fSTSTopology.GetNDetectors() );
00101         fSTSClustAmpVsTime.resize( fSTSTopology.GetNDetectors() );
00102         fSTSHitXY.resize( fSTSTopology.GetNDetectors() );
00103         fSTSHitXYBinned.resize( fSTSTopology.GetNDetectors() );
00104         for( Int_t iDet=0; iDet < fSTSTopology.GetNDetectors(); iDet++) {
00105                 fSTSDigiPos.at( iDet ).resize( fSTSTopology.GetNSides() );
00106                 fSTSDigiAmp.at( iDet ).resize( fSTSTopology.GetNSides() );
00107                 fSTSDigiTime.at( iDet ).resize( fSTSTopology.GetNSides() );
00108                 fSTSDigiAmpVsPos.at( iDet ).resize( fSTSTopology.GetNSides() );
00109            fSTSDigiPosLaserX.at( iDet ).resize( fSTSTopology.GetNSides() );
00110            fSTSDigiPosLaserY.at( iDet ).resize( fSTSTopology.GetNSides() );
00111 
00112 
00113                 fSTSDigiPos.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH1( 'D', Form( "STS/DigiPos%dp", iDet ), Form("Digi position on STS station %d, p-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00114                 fSTSDigiPos.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH1( 'D', Form( "STS/DigiPos%dn", iDet ), Form("Digi position on STS station %d, n-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00115                 fSTSDigiAmp.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH1( 'D', Form( "STS/DigiAmp%dp", iDet ), Form("Digi amplitude on STS station %d, p-side", iDet), 500, 0, 500 );
00116                 fSTSDigiAmp.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH1( 'D', Form( "STS/DigiAmp%dn", iDet ), Form("Digi amplitude on STS station %d, n-side", iDet), 500, 0, 500 );
00117                 fSTSDigiTime.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH1( 'D', Form( "STS/DigiTime%dp", iDet ), Form("Digi time w.r.t. trigger on STS station %d, p-side", iDet), 1000, -2000, 2000 );
00118                 fSTSDigiTime.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH1( 'D', Form( "STS/DigiTime%dn", iDet ), Form("Digi time w.r.t. trigger on STS station %d, n-side", iDet), 1000, -2000, 2000 );
00119                 fSTSDigiAmpVsPos.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH2( 'D', Form( "STS/DigiAmpVsPos%dp", iDet ), Form("Digi amplitude on STS station %d, p-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 125, 0, 500 );
00120                 fSTSDigiAmpVsPos.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH2( 'D', Form( "STS/DigiAmpVsPos%dn", iDet ), Form("Digi amplitude on STS station %d, n-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 125, 0, 500 );
00121 
00122                 fSTSDigiPosLaserX.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH2( 'I', Form( "STS/DigiPosLaserX%dp", iDet ), Form("Digi position on STS station %d, p-side, vs Laser table X", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 100, -50, 50 );
00123                 fSTSDigiPosLaserX.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH2( 'I', Form( "STS/DigiPosLaserX%dn", iDet ), Form("Digi position on STS station %d, n-side, vs Laser table X", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 100, -50, 50 );
00124            fSTSDigiPosLaserY.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH2( 'I', Form( "STS/DigiPosLaserY%dp", iDet ), Form("Digi position on STS station %d, p-side, vs Laser table Y", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 100, -50, 50 );
00125            fSTSDigiPosLaserY.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH2( 'I', Form( "STS/DigiPosLaserY%dn", iDet ), Form("Digi position on STS station %d, n-side, vs Laser table Y", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 100, -50, 50 );
00126 
00127 
00128 
00129                 fSTSClustPos.at( iDet ).resize( fSTSTopology.GetNSides() );
00130                 fSTSClustAmp.at( iDet ).resize( fSTSTopology.GetNSides() );
00131                 fSTSClustAmpVsPos.at( iDet ).resize( fSTSTopology.GetNSides() );
00132                 fSTSClustAmpVsTime.at( iDet ).resize( fSTSTopology.GetNSides() );
00133 
00134                 fSTSClustPos.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH1( 'D', Form( "STS/ClustPos%dp", iDet ), Form("Cluster position on STS station %d, p-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00135                 fSTSClustPos.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH1( 'D', Form( "STS/ClustPos%dn", iDet ), Form("Cluster position on STS station %d, n-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00136                 fSTSClustAmp.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH1( 'D', Form( "STS/ClustAmp%dp", iDet ), Form("Cluster amplitude on STS station %d, p-side", iDet), 500, 0, 500 );
00137                 fSTSClustAmp.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH1( 'D', Form( "STS/ClustAmp%dn", iDet ), Form("Cluster amplitude on STS station %d, n-side", iDet), 500, 0, 500 );
00138                 fSTSClustAmpVsPos.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH2( 'D', Form( "STS/ClustAmpVsPos%dp", iDet ), Form("Cluster amplitude on STS station %d, p-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 125, 0, 500 );
00139                 fSTSClustAmpVsPos.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH2( 'D', Form( "STS/ClustAmpVsPos%dn", iDet ), Form("Cluster amplitude on STS station %d, n-side", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), 125, 0, 500 );
00140                 fSTSClustAmpVsTime.at( iDet ).at( TSTSTopology::kPSide ) = MakeTH2( 'D', Form( "STS/ClustAmpVsTime%dp", iDet ), Form("Cluster amplitude vs. time w.r.t. trigger on STS station %d, p-side", iDet), 100, -1000, 1000, 100, 0, 500 );
00141                 fSTSClustAmpVsTime.at( iDet ).at( TSTSTopology::kNSide ) = MakeTH2( 'D', Form( "STS/ClustAmpVsTime%dn", iDet ), Form("Cluster amplitude vs. time w.r.t. trigger on STS station %d, n-side", iDet), 100, -1000, 1000, 100, 0, 500 );
00142 
00143 //              fSTSHitXY.at( iDet ) = MakeTH2( 'D', Form("STS/HitXY%d", iDet), Form("Hit position in STS station %d", iDet), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ), fSTSTopology.GetNStrips( iDet ), 0, fSTSTopology.GetNStrips( iDet ) );
00144 //              fSTSHitXY.at( iDet )->GetXaxis()->SetTitle( "p-side strip" );
00145 //              fSTSHitXY.at( iDet )->GetYaxis()->SetTitle( "n-side strip" );
00146                 fSTSHitXY.at( iDet ) = MakeTH2( 'D', Form("STS/HitXY%d", iDet), Form("Hit position in STS station %d", iDet), fSTSTopology.GetNStrips( iDet ), -6.4, 6.4, fSTSTopology.GetNStrips( iDet ), -6.4, 6.4 );
00147                 fSTSHitXY.at( iDet )->GetXaxis()->SetTitle( "X pos" );
00148                 fSTSHitXY.at( iDet )->GetYaxis()->SetTitle( "Y pos" );
00149                 fSTSHitXYBinned.at( iDet ) = MakeTH2( 'D', Form("STS/HitXYBinned%d", iDet), Form("Hit position in STS station (binned) %d", iDet), fSTSTopology.GetNStrips( iDet ) / 8, -6.4, 6.4, fSTSTopology.GetNStrips( iDet )/8, -6.4, 6.4 );
00150                 fSTSHitXYBinned.at( iDet )->GetXaxis()->SetTitle( "X pos" );
00151                 fSTSHitXYBinned.at( iDet )->GetYaxis()->SetTitle( "Y pos" );
00152         }
00153 
00154         fClusterizers.resize( fSTSTopology.GetNDetectors() );
00155         fHiterizers.resize( fSTSTopology.GetNDetectors() );
00156         for( Int_t iDet=0; iDet<fSTSTopology.GetNDetectors(); iDet++) {
00157                 fClusterizers.at( iDet ).resize( fSTSTopology.GetNSides() );
00158                 fHiterizers.at( iDet ) = new TSTSHiterizer( iDet );
00159                 for( Int_t iSide = 0; iSide < fSTSTopology.GetNSides(); iSide++ ) {
00160                         fClusterizers.at( iDet ).at( iSide ) = new TSTSClusterizer( iDet, iSide );
00161                 }
00162         }
00163 
00164         if( fSTSTopology.GetNDetectors() == 3 ) {
00165                 printf("In TSTSProc: clusterization space tolerance on STS01,p-side is set to 2!\n");
00166                 fClusterizers.at( 1 ).at( TSTSTopology::kPSide )->SetSpaceTolerance( 2 );
00167         }
00168 
00169         printf("STS Histograms created \n");
00170         fflush ( stdout);
00171 
00172 }
00173 
00174 
00175 
00176 TSTSProc::~TSTSProc()
00177 {
00178         for( Int_t iDet=0; iDet<fSTSTopology.GetNDetectors(); iDet++) {
00179                 for( Int_t iSide = 0; iSide < fSTSTopology.GetNSides(); iSide++ ) {
00180                         delete fClusterizers.at( iDet ).at( iSide );
00181                         fClusterizers.at( iDet ).at( iSide ) = 0;
00182                 }
00183         }
00184 
00185         delete fRocMessageBuffer;
00186 }
00187 
00188 
00189 
00190 
00191 void TSTSProc::FinalizeEvent()
00192 {
00193 
00194         // TODO: look here for new arrived epics events, and store their values to match with roc id message later
00195         //
00196         if(fEpicsInputEvent && fEpicsInputEvent->IsValid())
00197         {
00198            // new epics event is marked as valid. only look for those here
00199            printf(" ------ TSTSProc found new epics input event!\n");
00200       fEpicsInputEvent->PrintEvent();
00201       cout << ""<< endl; // flush buffer
00202            Long64_t id=fEpicsInputEvent->GetLong("CBM:TABLE:run");
00203            Double_t x=fEpicsInputEvent->GetDouble("CBM:TABLE:xpos");
00204            Double_t y=fEpicsInputEvent->GetDouble("CBM:TABLE:ypos");
00205            Double_t u=fEpicsInputEvent->GetDouble("CBM:KEITHLEY0:GETVOLTS");
00206            UInt_t t=fEpicsInputEvent->GetUpdateTimeSeconds();
00207            if(id==0)
00208               {
00209                  //printf(" ------ ZERO marker ignored!!\n");
00210               }
00211            else
00212               {
00213                  fLaserSetupBuffer.push_back(TSTSEvent::lasersetup_t(id,x,y,u,t));
00214               }
00215          }
00216 
00217 
00218 
00219         // printf(" ------ TSTSProc::FinalizeEvent()\n");
00220         if(!fRocInputEvent->IsValid())
00221            {
00222               cout <<"Skip incomplete input event---" << endl;
00223               return; // skip incomplete roc events from first step
00224            }
00225 
00226         if(AllRocsHaveEventClosed())
00227            {
00228                     // we continue after the last scanpoint was done.
00229                     if(fOutputEvent->GetLaserSetup().ScanId!=0)
00230                        printf(" ------ TSTSProc provides cleared output event after scan :%d. \n",
00231                                                         fOutputEvent->GetLaserSetup().ScanId);
00232                     fOutputEvent->SetValid(kFALSE); // unless data and setup is matching for all rocs
00233                     if(fFullOutputEvent) fFullOutputEvent->SetValid(kFALSE); // suppress storing anything in tree off scanpoint
00234                     fOutputEvent->ClearLaserSetup();
00235                     for(int rid=0; rid<MAX_ROC;++rid) {
00236                        fNextScanId[rid]=0; // only reset current scanid after last roc finished
00237                        fEventClosed[rid]=kFALSE;
00238                     }
00239                     fReplayBuffers=kTRUE;
00240 
00241 
00242          }
00243 
00244 
00245 
00246 
00247         //loop over sts rocs and nxs here:
00248 
00249         //static Bool_t firstPoint=kTRUE;
00250         for( Int_t rocId = 0; rocId < fSTSTopology.GetRocArrSize(); rocId++) {
00251                 if( fSTSTopology.IsValidRoc( rocId ) ) {
00252                    TRocData* theRoc=dynamic_cast<TRocData*>(fRocInputEvent->getEventElement(rocId));
00253                         if(theRoc==0) continue;
00254                         TRocData* bufferRoc=dynamic_cast<TRocData*>(fRocMessageBuffer->getEventElement(rocId));
00255                         if(bufferRoc==0)
00256                            {
00257                               GO4_STOP_ANALYSIS_MESSAGE("**** TSTSProc: NEVER COME HERE: ROC buffer has no component for rocid %d, but input event has!!! STOP GO4",rocId);
00258                            }
00259 
00260                         // first check if epics data of next sysmes scanpoint has arrived:
00261                         if(fNextScanId[rocId])
00262                          CheckScanSetup(fNextScanId[rocId],rocId);
00263 
00264 
00265                         // replay message buffers after closing previous event:
00266                         if(fReplayBuffers)
00267                         {
00268                               // we found corresponding setup. Now prepare reprocess buffered messages:
00269                // add buffered messages at front of input event vectors
00270 
00271                if(bufferRoc->fExtMessages.size())
00272                   {
00273                      printf(" ------ TSTSProc inserting %d old messages for rocid %d!\n",bufferRoc->fExtMessages.size(), rocId);
00274                      theRoc->fExtMessages.insert (theRoc->fExtMessages.begin(),bufferRoc->fExtMessages.begin(),bufferRoc->fExtMessages.end());
00275                      bufferRoc->fExtMessages.clear();
00276                      cout << ""<< endl; // flush buffer
00277                   }
00278                            }
00279 
00280                         for (unsigned iMsg = 0; iMsg < theRoc->fExtMessages.size(); iMsg++) {
00281             TRocMessageExtended msg = theRoc->fExtMessages.at(iMsg);
00282 
00283 
00284 
00285             // check here for system message markers:
00286             if (msg.GetMessageType() == roc::MSG_SYS) {
00287                //printf(" ------ TSTSProc found system message!\n");
00288                roc::Message rmsg = msg.GetRocMessage();
00289                //printf(" ------                system message type:%d\n",rmsg.getSysMesType());
00290                if (rmsg.getSysMesType() == roc::SYSMSG_USER) {
00291                   uint32_t value = rmsg.getSysMesData() - LASERSCANIDOFF;
00292 //                  printf(
00293 //                        " ------ TSTSProc found user system message for rocid %d with value:%d\n",
00294 //                        rocId, value);
00295 //                  cout << endl;
00296                   if(value==0 && !fInScanpoint[rocId])
00297                      bufferRoc->fExtMessages.push_back(msg); // need to buffer 0 termination messages only for future scans
00298 
00299                   CheckScanSetup(value,rocId);
00300 
00301                } // SYSMSG_USER
00302             } //MSG_SYS
00303 
00304                                 if(fOffScanpoint[rocId]) continue; // ignore data during change of scanpoint
00305                                 if(!fInScanpoint[rocId]){
00306                                 // data belongs to a scanpoint, but we have not yet found epics info or must wait for other roc, buffer it!
00307                                    bufferRoc->fExtMessages.push_back(msg);
00308                                    continue;
00309                          //bufferRoc->fExtMessages.insert(bufferRoc->fExtMessages.begin(),theRoc->fExtMessages.begin() + iMsg,theRoc->fExtMessages.end());
00310                //printf(" ------ TSTSProc has buffered  %d roc messages for future scanpoint\n",bufferRoc->fExtMessages.size());
00311                          //break;
00312                                 }
00313 
00314                                 // JAM: the rest is standard STS code from beamtime, expect for some position correlation histograms added
00315                                 // note that we only use hit messages which belong to the current scanpoint.
00316                                 if(msg.GetMessageType() != roc::MSG_HIT) continue; // input vector contains _all_ message types now!
00317                                 ProcessValidMessage(msg);
00318 
00319                         } // for (unsigned iMsg = 0;
00320                 } // if( fSTSTopology.IsValidRoc( rocId ) )
00321         } //  for( Int_t rocId
00322 
00323 
00324 fReplayBuffers=kFALSE; //
00325 
00326 // JAM: still commented out hit evaluation, since this will slow down with roc simulator random noise.?
00327 //if(fOutputEvent->IsValid())
00328 //   EvaluateHits(); // only process hits when event is completed (just before writing it)
00329 
00330 
00331 
00332 
00333 }
00334 
00335 
00336 
00337 Bool_t TSTSProc::CheckScanSetup( uint32_t value , Int_t rocId)
00338 {
00339 
00340 if (value == 0) {
00341 
00342       if(fInScanpoint[rocId]) fEventClosed[rocId] = kTRUE; // zero after been in scanpoint: mark as closed
00343       fOffScanpoint[rocId] = kTRUE;
00344       fInScanpoint[rocId] = kFALSE;
00345 
00346    } else {
00347 
00348       // first check if other roc had already evaluated epics infos:
00349       uint32_t currentscan=fOutputEvent->GetLaserSetup().ScanId;
00350       if (currentscan) {
00351 
00352          if (currentscan == value) {
00353             // this setup was already found by other roc stream. use it!
00354              if(!fInScanpoint[rocId]) {
00355                    printf(" ------ TSTSProc set current scan %d for rocid %d\n",
00356                                                currentscan,rocId);cout << ""<< endl; // flush buffer
00357                    }
00358             fInScanpoint[rocId] = kTRUE;
00359             fOffScanpoint[rocId] = kFALSE;
00360          } else if(currentscan> value){
00361            // somehow we have old data that was not accounted. must drop it
00362                fInScanpoint[rocId] = kFALSE;
00363                fOffScanpoint[rocId] = kTRUE;
00364                printf(" ------ TSTSProc  never come here: data in rocid:%d belongs to old scanid %d, but current scanid:%d, ignored! \n",
00365                                                   rocId, value,currentscan); cout << ""<< endl; // flush buffer
00366          } else {
00367             // data of future scanpoint. provide bufferring.
00368             fInScanpoint[rocId] = kFALSE;
00369             fOffScanpoint[rocId] = kFALSE;
00370 //            printf(" ------ TSTSProc with current scan %d for rocid %d, future idvalue is %d\n",
00371 //                  currentscan,rocId,value); cout << ""<< endl; // flush buffer
00372          }
00373 
00374       } else {
00375             fOffScanpoint[rocId] = kFALSE;
00376             fInScanpoint[rocId] = kFALSE;
00377 
00378          for (unsigned epi = 0; epi < fLaserSetupBuffer.size();
00379                epi++) {
00380             TSTSEvent::lasersetup_t lset = fLaserSetupBuffer.at(
00381                   epi);
00382             if (lset.ScanId == value) {
00383                printf(
00384                      " ------ TSTSProc found current laser setup with id:%d for rocid %d\n",
00385                      lset.ScanId, rocId); cout << ""<< endl; // flush buffer
00386                fOutputEvent->SetLaserSetup(lset);
00387                fLaserSetupBuffer.erase(
00388                      fLaserSetupBuffer.begin() + epi);
00389                fInScanpoint[rocId] = kTRUE;
00390                fOffScanpoint[rocId] = kFALSE;
00391                //fLaserPosition->Reset("");// to test number of scanpoints
00392                fLaserPosition->Fill(lset.Xpos, lset.Ypos);
00393                epi = -1; // after element erase, scan list again with first index
00394 
00395             } else if (lset.ScanId < value) {
00396                printf(
00397                      " ------ TSTSProc NEVER COME HERE: removing old laser setup with id:%d\n",
00398                      lset.ScanId); cout << ""<< endl; // flush buffer
00399                fLaserSetupBuffer.erase(
00400                      fLaserSetupBuffer.begin() + epi);
00401                epi = -1; // after element erase, scan list again with first index
00402             } else {
00403                // do not touch future setups
00404 //               printf(
00405 //                     " ------ TSTSProc found future laser setup with id:%d\n",
00406 //                     lset.ScanId); cout << ""<< endl; // flush buffer
00407             }
00408          } // for
00409 
00410       } // if currentscan
00411    } // if value 0
00412 
00413 // finally mark next expected epics setup
00414 if(!fInScanpoint[rocId] &&  !fOffScanpoint[rocId] && fNextScanId[rocId]!=0)
00415 {
00416          fNextScanId[rocId]=value;
00417 }
00418 
00419 if(AllRocsHaveEventClosed())
00420         {
00421               printf(" ------ TSTSProc sees that all rocs have finished current scanpoint , enable output event for scan :%d. \n",
00422                                                                       fOutputEvent->GetLaserSetup().ScanId);
00423               cout << endl;
00424               fOutputEvent->SetValid(kTRUE);
00425               if(fFullOutputEvent) fFullOutputEvent->SetValid(kTRUE);
00426          }
00427 
00428 
00429 return kTRUE;
00430 }
00431 
00432 
00433 
00434 void TSTSProc::ProcessValidMessage( TRocMessageExtended& msg)
00435 {
00436 
00437 #ifdef CLEARCLUSTERS
00438    // JAM: clear hit/clusterizers before processing new data:
00439    for( Int_t iDet=0; iDet<fSTSTopology.GetNDetectors(); iDet++) {
00440          fHiterizers.at( iDet )->Clear();
00441          for( Int_t iSide = 0; iSide < fSTSTopology.GetNSides(); iSide++ ) {
00442             fClusterizers.at( iDet ).at( iSide )->Clear();
00443          }
00444       }
00445 #endif
00446 
00447 
00448 
00449 
00450    Int_t rocId=msg.GetRocNumber();
00451    Int_t nxId=msg.GetNxNumber();
00452    Int_t nxChannel=msg.GetNxChNum();
00453    Float_t timedist=msg.GetTriggerDeltaT(); // corrected trigger diff is already in input message!
00454    // Bool_t iscorrectedpedestal=kTRUE;
00455    Double_t nxadc_corr=msg.GetCorrectedNxADC();
00456    // if( nxadc_corr < 900 ) {
00457    //    iscorrectedpedestal=kFALSE;
00458    // }
00459 
00460    fNxChannelVsLaserX[rocId][nxId]->Fill(nxChannel,fOutputEvent->GetLaserSetup().Xpos);
00461    fNxChannelVsLaserY[rocId][nxId]->Fill(nxChannel,fOutputEvent->GetLaserSetup().Ypos);
00462 
00463 
00464    Int_t det = fSTSTopology.GetDetector( rocId );
00465    TSTSTopology::ESTSSide side = fSTSTopology.GetSide( rocId );
00466    Int_t strip = fSTSTopology.GetStrip( rocId, nxId, nxChannel );
00467 
00468    fSTSDigiPos.at( det ).at( side )->Fill( strip );
00469    fSTSDigiAmp.at( det ).at( side )->Fill( nxadc_corr );
00470    fSTSDigiTime.at( det ).at( side )->Fill( timedist );
00471    fSTSDigiAmpVsPos.at( det ).at( side )->Fill( strip, nxadc_corr );
00472 
00473    // here additional histograms strip vs laser table, etc
00474    fSTSDigiPosLaserX.at( det ).at( side )->Fill( strip, fOutputEvent->GetLaserSetup().Xpos);
00475    fSTSDigiPosLaserY.at( det ).at( side )->Fill( strip, fOutputEvent->GetLaserSetup().Ypos);
00476 
00477 
00478    TSTSDigi digi( strip, msg.GetFullTime(), nxadc_corr );
00479 
00480    if( ! fRocParam->ttriMode[rocId][nxId] || nxadc_corr >= fPar->fTtriGlobalThr ) {
00481       fClusterizers.at( det ).at( side )->FeedDigi( digi );
00482    }
00483 
00484    fOutputEvent->AddDigi( det, side, digi );
00485 }
00486 
00487 void TSTSProc::EvaluateHits()
00488 {
00489    printf(" ------ TSTSProc does EvaluateHits() before writing event... \n");
00490    cout << endl;
00491    for( Int_t iDet = 0; iDet < fSTSTopology.GetNDetectors(); iDet++ ) {
00492          for( Int_t iSide = 0; iSide < fSTSTopology.GetNSides(); iSide++ ) {
00493             TSTSCluster * clust = 0;
00494             while( ( clust = fClusterizers.at( iDet ).at( iSide )->FetchCluster( fRocParam->noTrigger ) ) != 0 ) {
00495                fSTSClustPos.at( iDet ).at( iSide )->Fill( clust->GetMainStrip() );
00496                fSTSClustAmp.at( iDet ).at( iSide )->Fill( clust->GetAmplitude() );
00497                fSTSClustAmpVsPos.at( iDet ).at( iSide )->Fill( clust->GetMainStrip(), clust->GetAmplitude() );
00498 
00499                fHiterizers.at( iDet )->FeedCluster( clust, (TSTSTopology::ESTSSide) iSide );
00500    //          delete clust;
00501    //          clust = 0;
00502             }
00503          }
00504       }
00505 
00506       for( Int_t iDet = 0;  iDet < fSTSTopology.GetNDetectors(); iDet++ ) {
00507          TSTSHit * hit = 0;
00508          while( ( hit = fHiterizers.at( iDet )->FetchHit( fRocParam->noTrigger ) ) ) {
00509 
00510             TSpacepoint point;
00511             fSTSGeometry.MakeSpacepoint( hit, iDet, point );
00512             delete hit;
00513             hit = 0;
00514 
00515             fSTSHitXY.at( iDet )->Fill( point.GetX(), point.GetY() );
00516             fSTSHitXYBinned.at( iDet )->Fill( point.GetX(), point.GetY() );
00517             fOutputEvent->AddPoint( iDet, point );
00518          }
00519       }
00520 }
00521 
00522 
00523 
00524 void TSTSProc::InitEvent(TGo4EventElement* outevnt)
00525 {
00526         // first assign input event:
00527         // since input event object is never discarded within processor lifetime,
00528         // we just search for subevent by name once to speed up processing
00529         if(fRocInputEvent==0)
00530         {
00531                 TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00532                 if(btevent)
00533                 {
00534                         fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00535               fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00536 
00537                 }
00538                 else
00539                 {
00540                         fRocInputEvent=dynamic_cast<TRocEvent*>(GetInputEvent());
00541 
00542                 }
00543                 if(fRocInputEvent==0) {
00544                         GO4_STOP_ANALYSIS_MESSAGE("**** TSTSProc: Fatal error: input event is not a TRocEvent!!! STOP GO4");
00545                 }
00546 
00547                  if(fEpicsInputEvent==0) {
00548                          Message(2,"**** TSTSProc: could not find TEpicsEvent!"); // but do not stop...
00549                       }
00550 
00551         }
00552 
00553         // then assign output event
00554         // since output event object is never discarded within processor lifetime,
00555         // we just search for subevent by name once to speed up processing
00556         if(fOutputEvent==0)
00557         {
00558                 TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00559                 if(btevent)
00560                 {
00561                         fOutputEvent=dynamic_cast<TSTSEvent*>(btevent->GetSubEvent("STS"));
00562                         fFullOutputEvent=btevent;
00563                 }
00564                 else
00565                 {
00566 
00567                         fOutputEvent= dynamic_cast<TSTSEvent*>(outevnt);
00568                 }
00569                 if(fOutputEvent==0) {
00570                         GO4_STOP_ANALYSIS_MESSAGE("**** TSTSProc: Fatal error: output event is not a TSTSEvent!!! STOP GO4");
00571                 }
00572 
00573                 // init flags for buffering/storing
00574                 fOutputEvent->SetValid(kFALSE);
00575                 if(fFullOutputEvent) fFullOutputEvent->SetValid(kFALSE);
00576 
00577         }
00578 
00579 }
00580 

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