![]() |
Mixed Data Coincidence Analysis Software 1.0
A program to analyze files produced by the EventMixer software.
|
00001 #include "GammaIdentifier.hh" 00002 00003 GammaIdentifier::GammaIdentifier(GammaEnergyChart * toUse, double tol, float minGamma, float maxGamma, float bgTol, bool forceCorr) 00004 :myChart(toUse), tolerance(tol), bgTolerance(bgTol), minGammaEnergy(minGamma), maxGammaEnergy(maxGamma), forceCorrect(forceCorr) 00005 { 00006 myTable = new ElementLookupTable(); 00007 } 00008 00009 GammaIdentifier::~GammaIdentifier() 00010 { 00011 delete myTable; 00012 } 00013 00014 void GammaIdentifier::addCoincidence(pair<EventHit*, EventHit*> toAdd) 00015 { 00016 myChart->addCoincidence(toAdd, tolerance); 00017 coincidences.push_back(toAdd); 00018 } 00019 00020 list<ScorePair> GammaIdentifier::doSimpleScoring() 00021 { 00022 list<ScorePair> scoring; 00023 map<pair<int, int>, vector<GammaLine*> > * lines = myChart->getGammaLines(); 00024 for(map<pair<int, int>, vector<GammaLine*> >::iterator it = lines->begin(); it!=lines->end(); it++) 00025 { 00026 scoring.push_back(ScorePair()); 00027 scoring.back().A=it->first.first; 00028 scoring.back().Z=it->first.second; 00029 for(vector<GammaLine*>::iterator ig = it->second.begin(); ig!=it->second.end(); ig++) 00030 { 00031 scoring.back().score+=(*ig)->coincidences.size(); 00032 } 00033 } 00034 scoring.sort(); 00035 return scoring; 00036 } 00037 00038 string GammaIdentifier::getMATLABstring(int figure) 00039 { 00040 list<ScorePair> score = doProbabilisticScoring(); 00041 stringstream ss; 00042 ss << "A" << coincidences.front().first->A << "Z" << coincidences.front().first->Z << "=[" << endl; 00043 for(list<pair<EventHit*, EventHit*> >::iterator it = coincidences.begin(); it!=coincidences.end(); it++) 00044 { 00045 ss << scientific << it->second->Ge << endl; 00046 } 00047 ss << "];" << endl; 00048 ss << "figure(" << figure << ");" << endl; 00049 ss << "hold on;" << endl; 00050 ss << "hist(" << "A" << coincidences.front().first->A << "Z" << coincidences.front().first->Z << ",[" << minGammaEnergy << ":" << 2*tolerance << ":" << maxGammaEnergy << "]);" << endl; 00051 ss << "[AZh, AZe]=hist(" << "A" << coincidences.front().first->A << "Z" << coincidences.front().first->Z << ",[" << minGammaEnergy << ":" << 2*tolerance << ":" << maxGammaEnergy << "]);" << endl; 00052 ss << "h = findobj(gca,'Type','patch');\nset(h,'FaceColor','b','EdgeColor','b')" << endl; 00053 ss << "AZs=smooth(AZh,33);" << endl; 00054 ss << "plot(AZe,AZs,'r-');" << endl; 00055 ss << "AZd=(AZh-AZs');" << endl; 00056 ss << "AZv=AZd.^2;" << endl; 00057 ss << "AZvs=smooth(AZv,33);" << endl; 00058 ss << "AZstd=sqrt(AZvs);" << endl; 00059 ss << "plot(AZe,AZs+2*AZstd,'k-');" << endl; 00060 00061 map<pair<int, int>, vector<GammaLine*> > * lines = myChart->getGammaLines(); 00062 unsigned int max = 0; 00063 for(map<pair<int, int>, vector<GammaLine*> >::iterator it = lines->begin(); it!=lines->end(); it++) 00064 { 00065 if((it->first.first==score.front().A && it->first.second==score.front().Z)) 00066 { 00067 for(vector<GammaLine*>::iterator ig = it->second.begin(); ig!=it->second.end(); ig++) 00068 { 00069 if((*ig)->coincidences.size()>max) 00070 max = (*ig)->coincidences.size(); 00071 ss << "plot([" << (*ig)->gamma << " " << (*ig)->gamma <<"],[" 00072 << 0 << " " << (*ig)->coincidences.size() << "],'r','LineWidth',2);" << endl; 00073 ss.precision(5); 00074 ss << "text(" << (*ig)->gamma << "," << (float)(*ig)->coincidences.size()+0.25 << ",'"; 00075 ss.precision(3); 00076 ss.unsetf(ios::fixed); 00077 ss.unsetf(ios::scientific); 00078 ss << fixed << (*ig)->gamma << " MeV, #=" << fixed << (*ig)->coincidences.size() << "');" << endl; 00079 } 00080 00081 } 00082 } 00083 ss << "xlim([" << minGammaEnergy << " " << maxGammaEnergy << "]);" << endl; 00084 ss << "ylim([0 " << max+1 << "]);" << endl; 00085 ss << "title('^{" << coincidences.front().first->A << "}" << myTable->lookupElement((unsigned short int)coincidences.front().first->Z) << ": identified as ^{" << score.front().A << "}" << myTable->lookupElement((unsigned short int)score.front().Z) << "');" << endl; 00086 ss << "xlabel('Energy [/MeV]');" << "ylabel('Counts');" << endl; 00087 00088 00089 00090 return ss.str(); 00091 } 00092 00093 00094 list<ScorePair> GammaIdentifier::doProbabilisticScoring() 00095 { 00096 list<ScorePair> scoring; 00097 if(forceCorrect) 00098 { 00099 scoring.push_back(ScorePair()); 00100 scoring.back().A=coincidences.front().first->A; 00101 scoring.back().Z=coincidences.front().first->Z; 00102 return scoring; 00103 } 00104 map<pair<int, int>, vector<GammaLine*> > * lines = myChart->getGammaLines(); 00105 //cout << endl << endl; 00106 for(map<pair<int, int>, vector<GammaLine*> >::iterator it = lines->begin(); it!=lines->end(); it++) 00107 { 00108 scoring.push_back(ScorePair()); 00109 scoring.back().A=it->first.first; 00110 scoring.back().Z=it->first.second; 00111 //cout << scoring.back().A << " " << scoring.back().Z << ": "; 00112 float score = 0; 00113 for(vector<GammaLine*>::iterator ig = it->second.begin(); ig!=it->second.end(); ig++) 00114 { 00115 float lineSize = 0; 00116 if(((*ig)->coincidences.size()-(*ig)->getBackgroundMean())>2*sqrt((*ig)->coincidences.size()+(*ig)->getBackgroundSTD())) 00117 //if((*ig)->coincidences.size()-2*(*ig)->getBackgroundSTD()-(*ig)->getBackgroundMean()) 00118 { 00119 lineSize = (*ig)->coincidences.size(); 00120 } 00121 00122 lineSize/=(*ig)->probability; 00123 //cout << (*ig)->gamma << "(" << (*ig)->probability << "): " << (*ig)->coincidences.size() << " LS:" << lineSize << " "; 00124 score+=lineSize/it->second.size(); 00125 } 00126 //cout << endl; 00127 scoring.back().score=score; 00128 //if(lines.size()<2) 00129 //scoring.back().score/=2; //We need some kind of penalty if there is only one line... 00130 00131 /*if(lines.size()>0) 00132 tempScore/=scoreCount; 00133 00134 scoring.back().score/=scoreCount;*/ 00135 00136 } 00137 scoring.sort(); 00138 return scoring; 00139 } 00140 00141 string GammaIdentifier::getPeakString() 00142 { 00143 list<ScorePair> score = doProbabilisticScoring(); 00144 stringstream ss; 00145 ss << "tA" << coincidences.front().first->A << "Z" << coincidences.front().first->Z << "=[" << endl; 00146 00147 map<pair<int, int>, vector<GammaLine*> > * lines = myChart->getGammaLines(); 00148 for(map<pair<int, int>, vector<GammaLine*> >::iterator it = lines->begin(); it!=lines->end(); it++) 00149 { 00150 if((it->first.first==score.front().A && it->first.second==score.front().Z)) 00151 { 00152 for(vector<GammaLine*>::iterator ig = it->second.begin(); ig!=it->second.end(); ig++) 00153 { 00154 for(vector<pair<EventHit*, EventHit*> >::iterator ip = (*ig)->coincidences.begin(); ip!=(*ig)->coincidences.end(); ip++) 00155 { 00156 ss << scientific << (ip->second->time-ip->first->time) << endl; 00157 } 00158 } 00159 } 00160 } 00161 ss << "];"; 00162 return ss.str(); 00163 }