// ------------------------------------------------------------------------- // ----- CbmMvdSensor source file ----- // ----- Created 31/01/11 by M. Deveaux ----- // ------------------------------------------------------------------------- #include "CbmMvdSensor.h" //#include "CbmMvdMimosa26AHR.h" #include "TGeoManager.h" #include "CbmMvdSensorPlugin.h" #include using std::cout; using std::endl; // ----- Default constructor ------------------------------------------- CbmMvdSensor::CbmMvdSensor() : fStationNr(0), fVolumeId(0) { cout << "-W- " << GetName() << ": MVD-Sensor initialized without technical data."; cout << " Assuming default sensor." << endl; fSensorData=new CbmMvdSensorDataSheet(); fPluginArray=new TObjArray(1); cout << "-W- " << GetName() << ": MVD-Sensor initialized without geometry data. "; cout << " Must be added manually before using this class." << endl; cout << "-W- " << GetName() << ": MVD-Sensor initialized without valid start time. "; cout << " Must be added manually before using this class." << endl; fSensorStartTime=0; fRecoMatrix=0; fMCMatrix=0; fAlignmentCorr=0; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmMvdSensor::CbmMvdSensor(const char* name, CbmMvdSensorDataSheet* dataSheet, TString volName, TString nodeName, Int_t stationNr, Int_t volumeId, Double_t sensorStartTime) : TNamed(name, ""), fStationNr(stationNr), fVolumeId(volumeId) { //names needed to find volume in TGeoManager fVolName=volName; fNodeName=nodeName; fRecoMatrix=0; fMCMatrix=0; fAlignmentCorr=0; ReadSensorGeometry(volName, nodeName); fSensorData= dataSheet; fSensorStartTime=sensorStartTime; fPluginArray=new TObjArray(1); } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmMvdSensor::~CbmMvdSensor() { delete fSensorData; } // -------Setters ----------------------------------------------------- void CbmMvdSensor::SetAlignment(TGeoHMatrix* alignmentMatrix) { if (fAlignmentCorr) {delete fAlignmentCorr;}; fAlignmentCorr=(TGeoHMatrix*)alignmentMatrix->Clone(fVolName+"_AlignmentData"); } // -------Initialization tools ----------------------------------------------------- Int_t CbmMvdSensor::ReadSensorGeometry(TString volName, TString nodeName) { cout << "-I- " << GetName() << " : Searching for station: " << volName << endl; Int_t volId = -1; TGeoVolume* volume; volId = gGeoManager->GetUID(volName); //search for node in geometry data base if ( !(volId > -1) ) { cout << "-W- " << GetName() << ": Station " << volName << " not found, ignored for now." << endl; } else { // volume found // Get shape parameters volume = gGeoManager ->GetVolume(volName.Data()); fShape = (TGeoBBox*) volume ->GetShape(); // cout<< "This is the volume:" <Dump(); // cout<< "This is the shape:" << endl; // fShape->Dump(); } Bool_t nodeFound = gGeoManager->cd(nodeName.Data()); if ( ! nodeFound ) { cout << "-W- " << GetName() << "::SetMvdGeometry: Node " << nodeName << " not found in geometry!" << endl; cout << " Ignored for now." << endl; cout << endl; } else { if(fMCMatrix) {delete fMCMatrix;}; //delete local copy of the position information // fMCMatrix=new TGeoHMatrix(); /*while(!(volume->IsTopVolume())){ cout << "ping"<< endl; TGeoHMatrix* tempMatrix=gGeoManager->GetCurrentMatrix(); if (!tempMatrix){cout << "- E -" << GetName() << ": Didn't receive TGeoMatrix of this sensor" << endl;} fMCMatrix->Multiply(tempMatrix); gGeoManager->CdUp(); volume=(TGeoVolume*)gGeoManager->GetCurrentVolume(); } */ fMCMatrix=(TGeoHMatrix*)(gGeoManager->GetCurrentMatrix())->Clone(volName+"_MC_Matrix"); fMCMatrix->SetName(volName+"_MC_Matrix"); if (!fRecoMatrix) { //The initial guess on the reconstructed position is that the MC-position is correct fRecoMatrix=(TGeoHMatrix*)fMCMatrix->Clone(volName+"_Reco_Matrix"); }; if (!fAlignmentCorr){ //If no knowledge on the reco matrix is available there is plausibly no correction data. fAlignmentCorr=new TGeoHMatrix(volName+"_AlignmentData"); } } cout << " Found." << endl; Double_t* tempCoordinate=fRecoMatrix->GetTranslation(); for(Int_t i=0;i<3;i++){cout << tempCoordinate[i] << " ";} cout<< endl; for(Int_t i=0;i<3;i++){fSensorPosition[i]=tempCoordinate[i];} } //------------------------------------------------------------------- void CbmMvdSensor::Init(){ Int_t nPlugin=fPluginArray->GetEntriesFast(); CbmMvdSensorPlugin* pluginFirst; CbmMvdSensorPlugin* pluginNext; TClonesArray* dataArray; for(Int_t i=0;iAt(i); pluginFirst->Init(); } //Link data chain if(nPlugin>1){ for(Int_t i=0;iAt(i); pluginNext =(CbmMvdSensorPlugin*)fPluginArray->At(i+1); //Rules: The output array of the previous plugin is input of the next dataArray=pluginFirst->GetOutputArray(); pluginNext->SetInputArray(dataArray); //The plugin knows its precessor and sucessor to communicate pluginFirst->SetNextPlugin(pluginNext); pluginNext->SetPreviousPlugin(pluginFirst); } } } void CbmMvdSensor::ExecChain(){ CbmMvdSensorPlugin* plugin; Int_t nPlugin=fPluginArray->GetEntriesFast(); plugin=(CbmMvdSensorPlugin*)fPluginArray->At(nPlugin); plugin->ExecChain(); } void CbmMvdSensor::Exec(UInt_t nPlugin){ Int_t nPluginMax=fPluginArray->GetEntriesFast(); if(nPlugin>nPluginMax) {Fatal(GetName()," Error - Called non-existing plugin");} CbmMvdSensorPlugin* plugin=(CbmMvdSensorPlugin*)fPluginArray->At(nPlugin); plugin->Exec(); } // ----- Coordinate Transformations -------------------------------- void CbmMvdSensor::LocalToTop (Double_t* local, Double_t* lab){ fRecoMatrix->LocalToMaster(local, lab); }; void CbmMvdSensor::TopToLocal (Double_t* lab, Double_t* local){ fRecoMatrix->MasterToLocal(lab, local); }; void CbmMvdSensor::LocalToPixel (Double_t* local, Int_t &pixelNumberX, Int_t &pixelNumberY){ //Compute position of the frame relativ to the border of the matrix //which contains the pixel (0/0) Double_t x=local[1] + fSensorData->GetPixelSignX() * GetDX(); Double_t y=local[2] + fSensorData->GetPixelSignY() * GetDY(); //Compute the number of the pixel hit. //Note: substract 0.5 to move from border to center of pixel pixelNumberX= Int_t((x/fSensorData->GetPixelPitchX())-0.5); pixelNumberY= Int_t((y/fSensorData->GetPixelPitchY())-0.5); }; void CbmMvdSensor::PixelToLocal (Int_t pixelNumberX, Int_t pixelNumberY, Double_t* local){ //Compute distance from border of the pixel matrix //Ignore the direction of pixel numbering so far Double_t x =pixelNumberX * fSensorData->GetPixelPitchX() + 0.5; Double_t y =pixelNumberY* fSensorData->GetPixelPitchY() + 0.5; //Perform coordinate transformation from border of matrix to center of volume local[0]= x- fSensorData->GetPixelSignX()*GetDX(); local[1]= y- fSensorData->GetPixelSignX()*GetDX(); local[2]=0; //per definition always at the sensor surface; }; void CbmMvdSensor::PixelToTop (Int_t pixelNumberX, Int_t pixelNumberY, Double_t* lab) { PixelToLocal (pixelNumberX, pixelNumberY,fTempCoordinate); LocalToTop(fTempCoordinate, lab); }; void CbmMvdSensor::TopToPixel (Double_t* lab, Int_t &pixelNumberX, Int_t &pixelNumberY){ TopToLocal(lab, fTempCoordinate); LocalToPixel(fTempCoordinate, pixelNumberX, pixelNumberY); }; Int_t CbmMvdSensor::GetFrameNumber (Int_t pixelNumberY, Double_t absoluteTime){ Double_t timeSinceStart= absoluteTime - fSensorStartTime; Double_t timeInUnitsOfFrames= timeSinceStart/fSensorData->GetIntegrationTime(); // Get time substracting the full frames (140.3 -> 0.3) Double_t timeSinceStartOfTheFrame= timeInUnitsOfFrames - (Int_t)timeInUnitsOfFrames; Int_t rowUnderReadout = Int_t(fSensorData->GetNPixelsY() * timeSinceStartOfTheFrame); return timeInUnitsOfFrames - (pixelNumberY>rowUnderReadout); /* This statement is equivalent to: if (pixelNumberY>rowUnderReadout) {return timeInUnitsOfFrames;} else {return timeInUnitsOfFrames-1;} */ } // ----- Public method Print ------------------------------------------- void CbmMvdSensor::Print(Option_t* opt) const { cout << " --- " << GetName() << ", sensor name" << fVolName << endl; cout << " MC - ID: " << fVolumeId << endl; cout << "---------------------------------------------------------" << endl; cout << " Position information: " << endl; fRecoMatrix->Print(); cout << " --------------------------------------------------------" << endl; cout << " Technical information: " << endl; fSensorData->Print(""); cout << " , MC Id " << fVolumeId <