// ------------------------------------------------------------------------- // ----- CbmMvdStringFinder source file ----- // ----- Created 28.06.2011 by Q. Li, M. Deveaux ----- // ------------------------------------------------------------------------- #include "CbmMvdStringFinder.h" #include "FairLogger.h" #include using std::cout; using std::endl; // ----- Default constructor ------------------------------------------- CbmMvdStringFinder::CbmMvdStringFinder(): FairTask() { fMimoData = new TClonesArray("CbmMvdMimoData"); fMimoDataStateMatch = new TClonesArray("CbmMvdMimoStateMatch"); fVerbose=0; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmMvdStringFinder::CbmMvdStringFinder(const char* name, Int_t iVerbose) : FairTask(name){ fVerbose=iVerbose; fInputPersistance=-1; fMimoData = new TClonesArray("CbmMvdMimoData"); fMimoDataStateMatch = new TClonesArray("CbmMvdMimoStateMatch"); } // ------------------------------------------------------------------------- InitStatus CbmMvdStringFinder::Init(){ FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { cout << "-E- " << GetName() << "::Init: No FairRootManager!" << endl; return kFATAL; } fHitArray = (TClonesArray*) ioman->GetObject("MvdHit"); fDigiArray= (TClonesArray*) ioman->GetObject("MvdDigi"); if (!fHitArray) {cout << "test" << endl; Fatal (GetName(), "Could not find hits, good bye!");} if (!fDigiArray){cout << "one more test" << endl; Fatal (GetName(), "Could not find digis, good bye!");} //Creat 50 CbmMvdDig* vectors for 50 sensors in one station for(Int_t i = 0;iRegister("MimoData","MVD",fMimoData,kTRUE); cout <<"register fMimoData is ok "<Register("MimoDataStateMatch","MVD",fMimoDataStateMatch,kTRUE); cout <<"register fMimoStateMatch is ok "<GetEntries();//get the num of entry in each event cout << "There are "<< num_entries<<" digis in event "<At(num_loop); fStationNum = fDigi->GetStationNr(); fPixel_X_InStation = fDigi->GetPixelX(); fPixel_Y_InStation = fDigi->GetPixelY(); fSensorNumInStation = (fPixel_X_InStation/1152+1)+(fPixel_Y_InStation/576)*5; if(fStationNum == fStationNr) { Array_AT[fSensorNumInStation].push_back(num_loop); } } } // for each row :get the coordinate of the hittd pixels,and store into the iLineArray[][] in order /** Attention :SensorNum shoud be in the range of 1-50 **/ void CbmMvdStringFinder::GetUsefulData(Int_t SensorNum) { Int_t fPixel_X_InStation = 0; Int_t fPixel_Y_InStation = 0; Int_t fPixel_X_InSensor = 0; Int_t fPixel_Y_InSensor = 0; Int_t fIndex = 0; Int_t fNumOfLine = 0; Int_t fNumOfColumn = 0; fSensorID = SensorNum; fLineArray.clear(); cout <<"There are " << Array_AT[ SensorNum ].size()<<" digis in sensor number " << SensorNum<<"."<At(fIndex); fPixel_X_InStation = fDigi->GetPixelX(); fPixel_Y_InStation = fDigi->GetPixelY(); //translate the Inder X/Y into the x/y in sensor fPixel_X_InSensor = fPixel_X_InStation%1152; fPixel_Y_InSensor = fPixel_Y_InStation%576; fNumOfLine = fLineArray.size(); if(i == 0) { fLineArray.push_back(fCoordinate); fLineArray[0].push_back(fPixel_Y_InSensor); fLineArray[0].push_back(fPixel_X_InSensor); } else { for(Int_t j=0;jAt(fIndex); fPixel_X_position = fDigi->GetPixelX(); fPixel_Y_position = fDigi->GetPixelY(); fNumOfLine = fDigiLineArray.size(); if(i == 0) { fDigiLineArray.push_back(fDigiLine); fDigiLineArray[0].push_back(fIndex); } else { for(Int_t j=0;jAt(fIndex2); fPixel_Y2 = fDigi->GetPixelY(); if(fPixel_Y_position == fPixel_Y2) { fDigiLineArray[j].push_back(fIndex); j = fNumOfLine; } else if( j== (fNumOfLine-1)) { fDigiLineArray.push_back(fDigiLine); fDigiLineArray[j+1].push_back(fIndex); } } } } } //order the Y and X fNumOfLine = fDigiLineArray.size(); //sort the fIndex Int_t exchange = fNumOfLine -1; Int_t bound = 0; Int_t Y1=0; Int_t Y2=0; vector< Int_t > fTemp; fTemp.clear(); while(exchange) { bound = exchange; exchange = 0; for(Int_t i=0;iAt(fIndex); Y1 = fDigi->GetPixelY(); fIndex = fDigiLineArray[i+1][0]; fDigi = (CbmMvdDigi*)fDigiArray->At(fIndex); Y2 = fDigi->GetPixelY(); if(Y1>Y2) { fTemp = fDigiLineArray[i]; fDigiLineArray[i] = fDigiLineArray[i+1]; fDigiLineArray[i+1] = fTemp; exchange = i; } } } //sort the X Index Int_t X1=0; Int_t X2=0; Int_t fTemp2 = 0; for(Int_t i =0;i< fNumOfLine;i++) { exchange = fDigiLineArray[i].size()-1; while(exchange) { bound = exchange; exchange = 0; for(Int_t j=0;jAt(fIndex); X1 = fDigi->GetPixelX(); fIndex = fDigiLineArray[i][j+1]; fDigi = (CbmMvdDigi*)fDigiArray->At(fIndex); X2 = fDigi->GetPixelX(); if(X1>X2) { fTemp2 = fDigiLineArray[i][j]; fDigiLineArray[i][j] = fDigiLineArray[i][j+1]; fDigiLineArray[i][j+1] = fTemp2; exchange = j; } } } } } // Creat the dataframe of mimosa26 Based on the funtion of GetUsefulData(); // store the data into a Int_t vector fFrameArray[],a char fMimoDataArray[570*2], // store the Digi number of each state into the fStateMatchInformation for the statematch class void CbmMvdStringFinder::CreatDataFrameMimosa26(){ Int_t fLineNum = 0; Int_t fDiff = 0; Int_t fStateNum =0; Int_t fStateCode = 0; Int_t fColAddr = 0; Int_t fRowAddr = 0; fDatalength0 = 0; fDatalength1 = 0; fStateNumInOneFrame = 0; fLineNum = fLineArray.size(); fFrameArray.clear(); fStateMatchInformation.clear(); fFrameArray.push_back(fHeader0); fFrameArray.push_back(fHeader1); fFrameArray.push_back(fFrameCounter0); fFrameArray.push_back(fFrameConnter1); if(fLineArray.size() == 0) cout <<"Info:There is no any Digis in the " < 1 ||fStateCode == 3 )// save one state into a temp vector { fStateN = fStateCode*16384+fColAddr*8; fTempArray.push_back(fStateN); fStateNum++; fStateNumInOneFrame++; fDatalength0++; fStateMatchInformation.push_back(fOneState); Int_t fIndex = fStateMatchInformation.size(); for(Int_t m=0;m<(fStateCode+1);m++) { fStateMatchInformation[fIndex-1].push_back(fDigiLineArray[i][j-fStateCode-1+m]); } //reset for a new state fColAddr = fLineArray[i][j+1]; fStateCode = 0; } else if(fDiff==1) { fStateCode++; } } } } if(fStateNum > 9) { cout<<"there are more than 9 state in one row,the num is " < fByteNumberOfData/2) { cout << "Error: the Length of Data is overflow...."; } else { for(Int_t i = 0;iClear(); fMimoDataStateMatch->Clear(); fEventNum++; Int_t fNum = 0; Int_t header = 0; ReadOfFDigi(1);//get all the Digi nymber for of each sensor of 1 station GetUsefulData(27);//get the real data(x,y) of one sensor by row GetStateDigi(27);//get the digi Num of one sensor by row CreatDataFrameMimosa26();//creat the standard Mimosa data frame,store into a fFrameArray[570]*16bits and array[570*2]*8bits fROCFrame = 1; fTimeStamp = 2; fSensorOffset = 3; fTemp = 4; fROCAddress = 5; cout << "Writing MimoData into String.root of the "<< fEventNum <<" Event" <GetEntriesFast(); new ((*fMimoData)[fNum]) CbmMvdMimoData(fROCFrame,fTimeStamp,fSensorOffset,fTemp,fROCAddress,fMimoDataArray,fStateNumInOneFrame); cout << "Writing MimoDataStateMatch into String.root of the "<< fEventNum <<" Event" <GetEntriesFast(); new ((*fMimoDataStateMatch)[fNum]) CbmMvdMimoStateMatch(fROCFrame,fTimeStamp,fSensorOffset,fTemp,fROCAddress,fStateMatchInformation); } void CbmMvdStringFinder::Finish() { cout<<"End..."<