// COMET software includes #include "IMidasBank.hxx" #include "IMidasFile.hxx" #include "IMidasBankProxy.hxx" #include "IMidasBankProxyRegistry.hxx" #include "ICOMETRawEvent.hxx" // oaRawEvent includes #include "ITripTDigitBank.hxx" #include "IMCMBank.hxx" #include "IMidasTripTDigitItr.hxx" #include "IMidasTripTDigit.hxx" #include #include #include #include class IRMMSkewChecker { public: IRMMSkewChecker( std::string outFileName ) : Proc_Tr(std::vector(10,0)), fN_Faulty_P0DZERO(0), fN_Faulty_ECALZERO(0), fN_Faulty_SMRDZERO(0), fN_Faulty_TIME(0), fN_SMRDZERO(0), ALL_OK(true), fOffStream( outFileName.c_str() ) { } ~IRMMSkewChecker() { if ( !ALL_OK ){ fOffStream << "RMM-MCM Mis-Sync Found." << std::endl; } fOffStream.close(); } void Event( COMET::ICOMETRawEvent* re); void ProcessFile( std::string fileName ); private: Short_t fRMM[12][4]; ULong64_t fTDCT0[12][4]; ULong64_t countSkew[12][4]; std::vector Proc_Tr; Int_t fN_Faulty_P0DZERO; Int_t fN_Faulty_ECALZERO; Int_t fN_Faulty_SMRDZERO; Int_t fN_Faulty_TIME; Int_t fN_SMRDZERO; bool ALL_OK; std::ofstream fOffStream; }; //____________________________________________________________________________ void IRMMSkewChecker::Event(COMET::ICOMETRawEvent* re) { ULong64_t gtrigTriggerW = 0; UInt_t fEN = 0; UInt_t fTr = 0; bool READ_RMM_0 = false; bool READ_RMM_1 = false; bool READ_RMM_2 = false; bool READ_RMM_3 = false; bool READ_ECAL = false; bool READ_P0D = false; //bool READ_NEXT = false; //bool FILLED = false; bool NO_HIT = false; ULong64_t timet0; Int_t rmm; const char *name; bool MCM_flag=false; COMET::IHandle mcmBank; while (MCM_flag==false&&(mcmBank = re->GetMidasBank("",mcmBank))) { const Char_t *Mname = mcmBank->GetName(); if (Mname[0]=='S'||Mname[0]=='O') { MCM_flag=true; gtrigTriggerW = (ULong64_t)mcmBank->GetTriggerWord(); fEN = (UInt_t )(gtrigTriggerW&0x0000FFFF); fTr = (UInt_t)( (gtrigTriggerW>>48) & 0x0000FFFF ); }//Trigger Info Extract } // Loop over all banks of type TTripTHitBank COMET::IHandle triptBank; for (Int_t i = 0; i < 12 ;i++) { for (Int_t j = 0; j < 4 ;j++) { fTDCT0[i][j] = 0; fRMM[i][j] = 0; } } while ((triptBank = re->GetMidasBank("",triptBank))) { name = triptBank->GetName(); //Int_t rmm = (name[2]>'9')?(name[2]-'A'+10):(name[2]-'0'); // RMM is third digit in the bank name, 0123456789ABCDEFG... Int_t detector = (name[0]=='P') ? 0 : // P0D (name[0]=='I') ? 1 : // INGRID (name[0]=='E') ? 2 : // ECAL (name[0]=='S') ? 3 : 4; // SMRD : 4=Unknown READ_RMM_0 = false; READ_RMM_1 = false; READ_RMM_2 = false; READ_RMM_3 = false; READ_ECAL = false; READ_P0D = false; //READ_NEXT = false; //FILLED = false; if(detector == 0 || detector == 2 || detector == 3) { // Create an iterator over digits COMET::IMidasTripTDigitItr itr(triptBank->GetMidasTripTDigitItr()); //if ( itr.EOD() ) triptBank->ls("dump"); if ( detector ==3 && itr.EOD() ) NO_HIT=true; while ( ( ! itr.EOD() ) && (! READ_RMM_0) && (! READ_RMM_1) && (! READ_RMM_2) && (! READ_RMM_3) && (! READ_P0D) && (! READ_ECAL)){ //&& (! FILLED) COMET::IMidasTripTDigit digit(itr.Get()); timet0 = digit.GetTimeOffsetT0(); rmm = digit.GetRMMNum(); fTDCT0[rmm][detector] = timet0; if (timet0 == 1099511562239){ fTDCT0[rmm][detector] = 0; }//No TDC info. Over write with 0. fRMM[rmm][detector] = rmm; if ( rmm == 0 && detector == 3 ) READ_RMM_0 = true; if ( rmm == 1 && detector == 3 ) READ_RMM_1 = true; if ( rmm == 2 && detector == 3 ) READ_RMM_2 = true; if ( rmm == 3 && detector == 3 ) READ_RMM_3 = true; if ( detector == 0 ) READ_P0D = true; if ( detector == 2 ) READ_ECAL = true; //FILLED = true; // /* fOffStream << fEN << " "; fOffStream << fTr << " "; fOffStream << name << " "; fOffStream << rmm << " "; fOffStream << fTDCT0[rmm][detector] << std::endl; */ /* if (timet0 == 1099511562239 || READ_NEXT){ READ_RMM_0 = false; READ_RMM_1 = false; READ_RMM_2 = false; READ_RMM_3 = false; READ_ECAL = false; READ_P0D = false; triptBank->ls("dump"); digit.Print(); if(digit.IsValid()) fOffStream<< "IsValid" << std::endl; triptBank->ls("dump"); if (! READ_NEXT )READ_NEXT = true; if ( READ_NEXT && timet0 != 1099511562239 )READ_NEXT = false; } */ } } // End of loop over digits in this bank } // End of loop over banks of digits in this event bool GOODTIME = true; //bool P0DZERO = false; //bool ECALZERO = false; bool SMRDZERO = false; if ((!(fTDCT0[0][3]>0 && fTDCT0[1][3]>0 && fTDCT0[2][3]>0 && fTDCT0[3][3]>0)) && ((fTDCT0[0][0]>0 && fTDCT0[0][2]>0))){ SMRDZERO = true; } //if ((!(fTDCT0[0][0]>0 && fTDCT0[1][0]>0 && fTDCT0[2][0]>0 && fTDCT0[3][0]>0 && fTDCT0[4][0]>0 && fTDCT0[5][0]>0)) && ((fTDCT0[0][3]>0 && fTDCT0[0][2]>0))){ // P0DZERO = true; //} //if ((!(fTDCT0[0][2]>0 && fTDCT0[1][2]>0 && fTDCT0[2][2]>0 && fTDCT0[3][2]>0 && fTDCT0[4][2]>0 && fTDCT0[5][2]>0 && fTDCT0[6][2]>0 && fTDCT0[7][2]>0 && fTDCT0[8][2]>0 && fTDCT0[9][2]>0 && fTDCT0[10][2]>0 && fTDCT0[11][2]>0)) && ((fTDCT0[0][3]>0 && fTDCT0[0][0]>0))){ // ECALZERO = true; //} Int_t Ref=0; if ( fTDCT0[0][0] > 0 && fTDCT0[0][2] > 0 ){ Ref = (fTDCT0[0][0]/10000 + fTDCT0[0][2]/10000)/2; } if ( fTDCT0[0][0] == 0 && fTDCT0[0][2] > 0 ){ Ref = fTDCT0[0][2]/10000; } if ( fTDCT0[0][0] > 0 && fTDCT0[0][2] == 0 ){ Ref = fTDCT0[0][0]/10000; } if ( fTDCT0[0][0] == 0 && fTDCT0[0][2] == 0 ){ Ref = 0; } for (Int_t i=0;i<4;i++){ for (Int_t j=0;j<12;j++){ if (fTDCT0[j][i]!=0 && abs(fTDCT0[j][i]/10000-Ref)>1) { GOODTIME = false; countSkew[j][i]++; } } } if((!GOODTIME)||SMRDZERO) { /* for (Int_t i=0;i<4;i++){ //fOffStream << fEN << " "; //fOffStream << fTr << " "; //fOffStream << "SMRD" << " "; //fOffStream << i << " "; //fOffStream << fTDCT0[i][3] << std::endl; } for (Int_t i=0;i<6;i++){ //fOffStream << fEN << " "; //fOffStream << fTr << " "; //fOffStream << "P0D " << " "; //fOffStream << fRMM[i][0] << " "; //fOffStream << fTDCT0[i][0] << std::endl; } for (Int_t i=0;i<12;i++){ //fOffStream << fEN << " "; //fOffStream << fTr << " "; //fOffStream << "ECAL" << " "; //fOffStream << fRMM[i][2] << " "; //fOffStream << fTDCT0[i][2] << std::endl; } */ if((!GOODTIME)&&fEN==0){ fOffStream << "Mis-Sync at 0th Event. Seems OK" << std::endl; fN_Faulty_TIME++; } else if((!GOODTIME)) { //fOffStream << "Timing Fault!!" << std::endl; ALL_OK = false; fN_Faulty_TIME++; } if(SMRDZERO && NO_HIT){ //fOffStream << "SMRD No-Event. (shouldn't be problem)" << std::endl; fN_SMRDZERO++; } if(SMRDZERO && !NO_HIT){ fOffStream << "SMRD No-Event. (shouldn't be problem. t0=ffffffeffff is overwrited with 0.)" << std::endl; fN_Faulty_SMRDZERO++; //fN_Faulty_TIME++; fN_SMRDZERO++; } } Int_t fLog2Tr = -1; /* while ( fTr > 1){ fTr = fTr/2; fLog2Tr++; } */ if (fTr == 0) fLog2Tr = 9; else if (fTr == 1) fLog2Tr = 0; else if (fTr == 2) fLog2Tr = 1; else if (fTr == 4) fLog2Tr = 2; else if (fTr == 8) fLog2Tr = 3; else if (fTr == 16) fLog2Tr = 4; else if (fTr == 32) fLog2Tr = 5; else if (fTr == 64) fLog2Tr = 6; else if (fTr == 128) fLog2Tr = 7; else if (fTr == 256) fLog2Tr = 8; else { fOffStream << fTr << " Whats' happened?" < //COMET::ICOMETRawEvent* re = mf.ReadRawEvent(); //<-YANO TEST re->PromoteMidasBanks(false); Event(re); delete re; // added by yano memset(fTDCT0,0,sizeof(fTDCT0)); memset(fRMM,0,sizeof(fRMM)); // added by yano } // End loop over events //fOffStream << "*Event Processed:" << std::endl; Int_t Total_Proc_Tr = 0; for (Int_t i = 0; i < 9 ; i++) { //fOffStream << "*Tr: " << pow(2,i) << " Event: " << Proc_Tr[i] << std::endl; Total_Proc_Tr = Total_Proc_Tr + Proc_Tr[i]; } //fOffStream << "*Tr: " << "no-bit" << " Event: " << Proc_Tr[9] << std::endl; Total_Proc_Tr = Total_Proc_Tr + Proc_Tr[9]; fOffStream << "*bad P0D t0=0 events: " << fN_Faulty_P0DZERO << " : " << fN_Faulty_P0DZERO*100./Total_Proc_Tr<< std::endl; fOffStream << "*bad ECAL t0=0 events: " << fN_Faulty_ECALZERO << " : " << fN_Faulty_ECALZERO*100./Total_Proc_Tr<< std::endl; fOffStream << "*bad SMRD t0=0 events: " << fN_Faulty_SMRDZERO << " : " << fN_Faulty_SMRDZERO*100./Total_Proc_Tr<< std::endl; fOffStream << "*Good? SMRD t0=0 events: " << fN_SMRDZERO << " : " << fN_SMRDZERO*100./Total_Proc_Tr << std::endl; fOffStream << "*Mis-Sync events: " << fN_Faulty_TIME << " : " << fN_Faulty_TIME*100./Total_Proc_Tr << std::endl; if (fN_Faulty_TIME!=0){ for (Int_t i = 0; i < 12 ;i++) { for (Int_t j = 0; j < 4 ;j++) { if (countSkew[i][j] != 0){ if(j==0){ fOffStream << "P0D RMM" << i << " reported " << countSkew[i][j] << " event skews" << std::endl; } else if (j==2) { fOffStream << "ECAL RMM" << i << " reported " << countSkew[i][j] << " event skews" << std::endl; } else if (j==3) { fOffStream << "SMRD RMM" << i << " reported " << countSkew[i][j] << " event skews" << std::endl; } } } } } } //____________________________________________________________________________ int main(int argc, char **argv) { if ( argc != 3 ) { std::cerr << "usage: " << argv[0] << " " << std::endl; exit(1); } std::string inFileName = argv[1]; std::string outFileName = argv[2]; IRMMSkewChecker sk( outFileName ); sk.ProcessFile( inFileName ); }