/* * Scan.cpp * * Created on: Dec 25, 2014 * Author: Hovanes Egiyan */ #include "Scan.hh" #include "ScanCorrection.hh" ClassImp( Scan ) using namespace std; // Define the name of the detector to be used for normalization purposes string Scan::sNormDetName = " IBCAD00CRCUR6"; Scan::Scan() : TObject(), sScanFile(), sScanPlot(), sOverviewMainFrame() { return; } Scan::Scan( ScanFile* scanFile ) : TObject(), sScanFile( scanFile ), sScanStream( new ScanStream( sScanFile ) ), sScanPlot(), sOverviewMainFrame() { buildPlots(); return; } Scan::~Scan() { // First delete the plots and canvases that exist map >::iterator itP; // First loop over positioners for ( itP = sScanPlot.begin(); itP != sScanPlot.end(); itP++ ) { int posNumber = itP->first; map plotMap = itP->second; map::iterator itD; // Now loop over detectors for ( itD = plotMap.begin(); itD != plotMap.end(); itD++ ) { // int detNumber = itD->first; ScanPlot* plot2delete = itD->second; if ( plot2delete != 0 ) delete plot2delete; plot2delete = 0; } try { if ( sOverviewMainFrame[posNumber] != 0 && sOverviewMainFrame[posNumber]->IsActive() ) sOverviewMainFrame[posNumber]->CloseWindow(); } catch ( ... ) { cout << "Failed to delete OvervewMainFrame for positioner " << posNumber << endl; } } if ( sScanStream != 0 ) delete sScanStream; return; } void Scan::buildPlots() { // For each positioner crate an overview canvas for ( map::iterator itP = sScanStream->getPositioners().begin(); itP != sScanStream->getPositioners().end(); itP++ ) { int posNumber = itP->first; ScanPositioner* positioner = itP->second; map plotMap; cout << "Address for positioner " << positioner->getName() << " is " << hex << showbase << positioner << dec << endl; ScanDetector* normDetector = 0; // Loop through all detectors and create the corresponding ScanPlot objects for each detector for ( map::iterator itD = sScanStream->getDetectors().begin(); itD != sScanStream->getDetectors().end(); itD++ ) { // For each detector and each positioner create a ScanPlot object // and store it in a map with the detector number as the key int detNumber = itD->first; ScanDetector* detector = itD->second; cout << "Address for detector :" << detector->getName() << ": is " << hex << showbase << detector << dec << endl; ScanPlot* newPlot = new ScanPlot( detector, positioner, sScanStream->getScanName(), true ); if ( newPlot != 0 ) plotMap[detNumber] = newPlot; cout << "Comparing <" << string( detector->getName() ) << " to " << sNormDetName << endl; if ( string( detector->getName() ) == sNormDetName ) { normDetector = detector; cout << "Found normalization detector " << detector->getName() << endl; } } // Loop over all detectors again and make the plots smoother by correcting by the current or other // normalization detector and to apply corrections. Here normalization simply means correction by some intensity. for ( map::iterator itD = sScanStream->getDetectors().begin(); itD != sScanStream->getDetectors().end(); itD++ ) { int detNumber = itD->first; ScanDetector* detector = itD->second; if ( normDetector != 0 ) { plotMap[detNumber]->setNormDetector( normDetector ); plotMap[detNumber]->normalize(); } // Now look for corrections that could be applied to this detector if ( ScanCorrection::getCorrectionMap().count( detector->getName() ) > 0 ) { // Create the correction object if the correction map has for for this detector string corDetName = ScanCorrection::getCorrectionMap()[detector->getName()].first; TF1* corrFunc = ScanCorrection::getCorrectionMap()[detector->getName()].second; // try to find a detector who's value is the argument for the correction factor for ( map::iterator itCorrDet = sScanStream->getDetectors().begin(); itCorrDet != sScanStream->getDetectors().end(); itCorrDet++ ) { ScanDetector* corrDetector = itCorrDet->second; if ( corrDetector->getName() == corDetName ) { ScanCorrection correction( corrDetector, corrFunc ); cout << "Will apply correction to detector " << detector->GetName() << " based on detector readout for " << corrDetector->getName() << " with function " << corrFunc->GetTitle() << endl; plotMap[detNumber]->applyCorrections( correction ); break; } } } } // Assign the plot map just created to the plotMap for this positioner with the // positioner number as the key for the map. sScanPlot[posNumber] = plotMap; // Create a new frame for this positioner string frameName = sScanFile->getFileName() + " : " + positioner->getName(); OverviewMainFrame* newMainFrame = new OverviewMainFrame( gClient->GetRoot(), frameName.c_str(), 1600, 700, sScanPlot[posNumber], sScanStream->getNDetectors() ); sOverviewMainFrame[posNumber] = newMainFrame; } return; } void Scan::removeOverviewMainFrame( const int posNumb ) { sOverviewMainFrame.erase( posNumb ); return; }