Changeset 222 in Idarraga


Ignore:
Timestamp:
Jul 26, 2011, 3:34:46 PM (13 years ago)
Author:
idarraga
Message:
 
Location:
mafalda
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • mafalda/AnalysisCore/MediPixAnalysisCore.cpp

    r179 r222  
    4545        m_outputFilename = "MPXResults.root"; // output filename by default
    4646
     47        // fast matrix
     48        m_frameXC_Fast = 0x0;
     49
     50        // TOT cut
     51        m_totMaxCut = 11800; // timepix cut, settable through toplayer
    4752}
    4853
     
    134139                nb = fChain->GetEntry(jentry);   nbytes += nb;
    135140
    136                 //jFrameId = jentry;
    137 
    138                 // Calling algos to execution
     141                // At this point the Baskets have been opened.
     142                // Reading the pixel matrix (std::map) might be slow at this point.
     143                // Converting to a C-type array in order to fasten the reading
     144                RemakePixelMap();
     145
     146                // Calling algos for execution
    139147                for (algScheduleItr = m_algosSchedule.begin() ; algScheduleItr != m_algosSchedule.end() ; algScheduleItr++ ) {
    140148
     
    339347}
    340348
     349void MediPixAnalysisCore::RemakePixelMap(){
     350
     351        if ( m_frameXC_Fast == 0x0 ) { // first time
     352
     353                Log << MSG::ALWAYS << "Creating fast matrix map" << endreq;
     354                m_frameXC_Fast = new int[fWidth*fHeight];
     355
     356        } else if ( fWidth != fWidth_previous || fHeight != fHeight_previous ) { // in case matrix size changes during run
     357
     358                delete m_frameXC_Fast;
     359                m_frameXC_Fast = new int[fWidth*fHeight];
     360
     361        }
     362
     363        // clean up always
     364        for( int i = 0 ; i < fWidth*fHeight ; i++ ) m_frameXC_Fast[i] = 0;
     365
     366        // copy information from the map
     367        std::map<int,int>::iterator itr = m_frameXC.begin();
     368        int arraylength = fWidth*fHeight;
     369        for ( ; itr != m_frameXC.end() ; itr++) {
     370
     371                if((*itr).first > arraylength) {
     372                        std::cout << "[{AnalysisCore} WARNING] Attempt to fill up entries outside of the pad --> inconsistent data !" << std::endl;
     373                        std::cout << "                         Trying to recover by avoiding this entry.  Position : " << (*itr).first << std::endl;
     374                        std::cout << "                         in a " << fWidth << "x" << fHeight << " matrix." << std::endl;
     375                        continue;
     376                }
     377
     378                if((*itr).second < m_totMaxCut) {
     379                        m_frameXC_Fast[(*itr).first] = (*itr).second;
     380                }
     381
     382        }
     383
     384        fWidth_previous = fWidth;
     385        fHeight_previous = fHeight;
     386}
    341387
    342388#endif
  • mafalda/AnalysisCore/MediPixAnalysisCore.h

    r179 r222  
    7272        std::map<int,double> m_frameXC_E;
    7373
     74        // Fast versions
     75        int * m_frameXC_Fast;
     76
    7477        std::map<int, int>   m_lvl1;
    7578        //Int_t           m_frameMatrix[256][256];
     
    8184
    8285        Int_t           fFormat;
     86        // size of the matrix
    8387        Int_t           fWidth;
    8488        Int_t           fHeight;
     89        // check previous size
     90        Int_t           fWidth_previous;
     91        Int_t           fHeight_previous;
     92
    8593        Int_t           fAcq_mode;
    8694        Double_t        fAcq_time;
     
    194202        inline void ListenToTheManager(AnalysisManager * mngr){theManager = mngr;};
    195203
     204        inline void SetTOTMaxCut(int c){m_totMaxCut = c;};
     205
    196206private:
     207
     208        // Copy the frameXC map to a C-array.
     209        // This fasten things up
     210        void RemakePixelMap();
     211
    197212
    198213        MediPixAlgoTimer * algoTimers;
     
    211226        // default branches
    212227        std::map<string, Double_t> m_timePerFrameMap;
     228
     229        // TOT cuts
     230        int m_totMaxCut;
    213231
    214232};
  • mafalda/AnalysisCore/MediPixAnalysisManager.h

    r175 r222  
    5959        MediPixStoreGate * GetStoreGate(){return storeGate;};
    6060
    61         /* Retreive data safely */
     61        /*
     62         //Retreive data safely
    6263        inline Int_t GetMatrixElement(Int_t col, Int_t row)
    6364        {
     
    6970                        return analysisCore->m_frameXC[xplace];
    7071                }
    71                 //return analysisCore->m_frameMatrix[col][row];
     72
     73                return 0;
     74        };
     75         */
     76        inline Int_t GetMatrixElement(Int_t col, Int_t row)
     77        {
     78                int xplace = row*analysisCore->fWidth + col;
     79                return analysisCore->m_frameXC_Fast[xplace];
    7280        };
    7381
     
    142150
    143151        inline std::vector<Int_t> GetfCounters()
    144                                                                                                                                   {return analysisCore->fCounters;};
     152                                                                                                                                                  {return analysisCore->fCounters;};
    145153
    146154        inline std::vector<Int_t> GetfDACs()
    147                                                                                                                                   {return analysisCore->fDACs;};
     155                                                                                                                                                  {return analysisCore->fDACs;};
    148156
    149157        inline Int_t GetTHL(){
     
    206214
    207215        inline TApplication * GetApplication()
    208                                                 {return analysisCore->g_theApp;};
     216                                                                {return analysisCore->g_theApp;};
    209217
    210218private:
  • mafalda/BlobsFinder/BlobsFinder.cpp

    r163 r222  
    1212#include "MAFTools/MAFTools.h"
    1313
     14
    1415using namespace MSG;
    1516
     
    2829void AllBlobsContainer::SetBlobType(Int_t id, blobtype type){
    2930        allBlobs[id].SetBlobType(type);
     31
    3032}
    3133
     
    3840}
    3941
    40 void blob::SetBlobType(blobtype type)
    41 {
     42void blob::SetBlobType(blobtype type) {
    4243        btype = type;
    4344}
     45
     46/*
     47template<class T>
     48void blob<T>::SetBlobType(T type) {
     49//void blob<T>::SetBlobType(blobtype type) {
     50        btype = type;
     51}
     52*/
    4453
    4554/**
  • mafalda/BlobsFinder/BlobsFinder.h

    r95 r222  
    3434#define __BLOB_GOOD_TO_STORE   201
    3535
    36 #define MAX_BLOBS_PER_FRAME   2000
     36#define MAX_BLOBS_PER_FRAME   20000
    3737// numbering of quadrants
    3838#define Q_FIRST  1
     
    129129 * One blob contents
    130130 */
    131 //typedef struct {
     131
    132132class blob {
    133133
     
    135135 
    136136  TString GetTypeAsString();
     137  //void SetBlobType(blobtype);
    137138  void SetBlobType(blobtype);
    138139  blobProperties GetBlobProperties(){return bP;};
    139140  blobtype GetBlobType(){return btype;};
    140141  set< pair<Int_t, Int_t> > GetContentSet(){return blobContentSet;};
     142  list< pair < pair<Int_t, Int_t>, Int_t > > GetBlobContent(){return blobContent;};
    141143
    142144  // this will go private ... TODO !!!
     
    153155
    154156  blobProperties bP;
     157  //blobtype btype;
    155158  blobtype btype;
    156159 
    157160};
    158161
     162//template class blob<blobtype>;
    159163
    160164/**
     
    163167 *
    164168 */
     169
    165170/* *************************************** */
    166171class AllBlobsContainer : public CandidateContainer {
    167172 
    168173 public:
     174
    169175  AllBlobsContainer(MediPixAlgo *);
    170176  virtual ~AllBlobsContainer(){};
     
    173179  blobtype GetBlobType(Int_t);
    174180  TString GetTypeAsString(Int_t);
     181  void PushBack(blob b){ allBlobs.push_back(b); };
    175182
    176183 public:
  • mafalda/FEI3/FEI3Mips/FEI3Mips.cpp

    r179 r222  
    1212#include "MPXAlgo/Highlighter.h"
    1313
    14 #include "TH1F.h"
    15 
    1614using namespace MSG;
    1715
     
    2018FEI3Mips::FEI3Mips()
    2119: m_minNPixels ( 5 ),
     20  m_minMipLength ( 3.0 ), // [mm]
    2221  m_nDivisions ( 4 ),
    2322  m_pixSizeX ( 0.40 ), // FEI3 [mm]
     
    2524  m_FEI3_PIXELSIZE_YX_FRACTION ( m_pixSizeY/m_pixSizeX ),
    2625  m_totalMIPsLength ( 0.0 ),
    27   m_dRayBalSearch ( 1.4 )
     26  m_dRayBalSearch ( 1.4 ),
     27  m_distanceCutHot ( 3 ),
     28  m_distancePerpHot ( 3 ),
     29  m_guardDistanceX ( 1 ),
     30  m_guardDistanceY ( 5 )
    2831{
    2932
     
    4144        getMyTree()->Branch("lvl1Weights", &m_lvl1Weights);
    4245        getMyTree()->Branch("chargePerSection", &m_chargePerSection);
     46        getMyTree()->Branch("deltaRayTOT", &m_deltaRayTOT);
     47        getMyTree()->Branch("mipLength", &m_mipLength);
     48        getMyTree()->Branch("meanChargePerSection", &m_meanChargePerSection);
     49        getMyTree()->Branch("sectionCenter_x", &m_sectionCenter_x);
     50        getMyTree()->Branch("sectionCenter_y", &m_sectionCenter_y);
     51        getMyTree()->Branch("nDeltaRayExplicit", &m_nDeltaRayPerFrame);
     52        getMyTree()->Branch("nDeltaRaySoft", &m_nDeltaRaySoftPerFrame);
    4353
    4454        getMyTree()->Branch("clusterSize", &m_clusterSize, "clusterSize/I");
     
    4858        // A configuration value that can be tuned from the Viewer
    4959        RegisterConfigurationValue(&m_minNPixels, "minNPixels");
     60        RegisterConfigurationValue(&m_minMipLength, "minMipLength");
    5061        RegisterConfigurationValue(&m_nDivisions, "nDivisions");
    5162        RegisterConfigurationValue(&m_pixSizeX, "pixelSizeX");
    5263        RegisterConfigurationValue(&m_pixSizeY, "pixelSizeY");
    5364        RegisterConfigurationValue(&m_dRayBalSearch, "dRayBalSearch");
    54 
     65        RegisterConfigurationValue(&m_distanceCutHot, "distanceCutHot");
     66        RegisterConfigurationValue(&m_distancePerpHot, "distancePerpHot");
     67        RegisterConfigurationValue(&m_guardDistanceX, "guardDistanceX");
     68        RegisterConfigurationValue(&m_guardDistanceY, "guardDistanceY");
    5569
    5670}
    5771
    5872void FEI3Mips::Execute(){
     73
     74        // A check on parameters
     75        // The number of divisions can not be smaller than the minimum amount of
     76        // pixels required in a mip
     77        if(m_nDivisions > m_minNPixels) {
     78                Log << MSG::ERROR << "The number of divisions can not be bigger than the minimum amount of" << endreq;
     79                Log << MSG::ERROR << "pixels required in a mip to process.  Fix the parameters.  Giving up." << endreq;
     80                exit(1);
     81        }
    5982
    6083        // Ask the store gate if the previous algorithm (BlobsFinder --> reponsible for clustering)
     
    6891        // AllBlobsContainer is a box full of Blobs(Clusters). Now we can iterate over all clusters inside.
    6992        vector<blob> blobsVector = m_aB->GetBlobsVector();
     93
     94        // If nothing to do, return
     95        if(blobsVector.empty()) return;
     96
    7097        Log << MSG::INFO << "Number of blobs from clustering = " << (Int_t) blobsVector.size() << endreq;
    7198        vector<blob>::iterator blobsItr = blobsVector.begin(); //allBlobs.begin();
     
    88115                        m_clusterSize = (*blobsItr).GetBlobProperties().nPixels;
    89116
     117                        // Here we obtain two pairs with the pixels at the extreme ends of the Mip
     118                        //vector< pair<Int_t, Int_t> > limitPixels = FindLimitPixels(*blobsItr);
     119                        //i-
     120                        vector< pair<Float_t, Float_t> > limitPixels = FindLimitPixels(*blobsItr);
     121
     122                        // Make sure the mip starts and ends inside the pad at a certain minimum
     123                        //  distance from the borders
     124                        if ( MAFTools::BlobAtADistanceFromEdges(*blobsItr, limitPixels, GetWidth(), GetHeight(),
     125                                        m_guardDistanceX, m_guardDistanceY) ) {
     126                                continue;
     127                        }
     128
    90129                        // create all slots to put the weighted charge and others observables
    91130                        for(int ni = 0 ; ni < m_nDivisions ; ni++){
     
    93132                                m_lvl1Weights.push_back(0.0);
    94133                                m_chargePerSection.push_back(vector<Int_t>()); // push back empty vectors
    95                         }
    96 
    97                         // Here we obtain two pairs with the pixels at the extreme ends of the Mip
    98                         vector< pair<Int_t, Int_t> > limitPixels = FindLimitPixels(*blobsItr);
     134                                m_XYPerSection.push_back(vector<pair <Int_t, Int_t> >());
     135                                m_meanChargePerSection.push_back(0.0);
     136                                m_sectionCenter_x.push_back(0.0);
     137                                m_sectionCenter_y.push_back(0.0);
     138                        }
    99139
    100140                        // If the whole mip is in the same column, don't process it.
     
    102142                        //  same column in FE-I3.  FE-I4 too ?
    103143                        if (limitPixels[__TAIL_INDX].first - limitPixels[__HEAD_INDX].first == 0) {
    104                                 return;
     144                                ClearThisAlgo();
     145                                continue;
    105146                        }
    106147
     
    112153                                        limitPixels[__TAIL_INDX].first * m_pixSizeX,
    113154                                        limitPixels[__TAIL_INDX].second * m_pixSizeY);
     155                        m_mipLength.push_back( totalLength ); // mm
    114156                        m_totalMIPsLength += totalLength;
    115                         Log << MSG::DEBUG << "Integrated mips length = " << m_totalMIPsLength << " [mm]" << endreq;
     157                        Log << MSG::INFO << "Integrated mips length = " << m_totalMIPsLength << " [mm]" << endreq;
     158
     159                        // cut by mip length
     160                        if ( totalLength < m_minMipLength ) {
     161                                ClearThisAlgo();
     162                                continue;
     163                        }
    116164
    117165                        // Fech the linear regression information for this mip
     
    153201                        if(x2i < x1i) startX = x2i;
    154202
    155                         // build the rest of the point within the boundaries
     203                        // Build the rest of the point within the boundaries
    156204                        for (int i = 1 ; i < m_nDivisions ; i++) {
    157205
     
    159207                                Float_t newPY = newPX*slope + cut;
    160208
    161                                 limitPixels.push_back( make_pair( TMath::FloorNint(newPX), TMath::FloorNint(newPY) ) );
     209                                Log << MSG::INFO << "division point : " << newPX << " , " << newPY << endreq;
     210
     211                                //limitPixels.push_back( make_pair( TMath::FloorNint(newPX), TMath::FloorNint(newPY) ) );
     212                                //i-
     213                                limitPixels.push_back( make_pair( newPX, newPY ) );
    162214                        }
    163215
     
    166218                        vector< pair<Float_t, Float_t > > linePars;
    167219
     220                        // Flag which indicates if we are dealing with a track with slope = 0.  Special case.
     221                        bool parallelLine = false;
    168222                        for (int i = 0 ; i < m_nDivisions+1 ; i++) { // there are m_nDivisions+1 lines !
    169                                 linePars.push_back(  GetParallelLineAt(slope, cut, limitPixels[i])  );
     223
     224                                // WARNING ! If slope == 0. a flag indicating it is raised
     225                                linePars.push_back(  GetParallelLineAt(slope, cut, limitPixels[i], &parallelLine)  );
     226
    170227                        }
    171228
     
    195252                                for( separatorItr = linePars.end()-1 ; separatorItr != linePars.begin()-1 ; separatorItr-- ) {
    196253
    197                                         // calculate the perpendicular distance to each line
    198                                         Double_t perpDistance = MAFTools::CalcPerpDistanceToLine( (*separatorItr).first,
    199                                                         (*separatorItr).second, *contItr );
     254                                        // deal with the slope=0 case
     255                                        Double_t perpDistance = 0.;
     256                                        if(parallelLine) {
     257                                                //Log << MSG::DEBUG << x << " --> " << (*separatorItr).first << endreq;
     258                                                perpDistance = TMath::Abs( x - (*separatorItr).first);
     259                                        } else {
     260                                                // calculate the perpendicular distance to each line
     261                                                perpDistance = MAFTools::CalcPerpDistanceToLine( (*separatorItr).first,
     262                                                                (*separatorItr).second, *contItr );
     263                                        }
    200264
    201265                                        Log << MSG::DEBUG << "pixel : " << x << " , " << y << " | perpDistance = " << perpDistance << " ";
     
    205269                                                locationBitWord ^= 0x1;
    206270                                                Log << MSG::DEBUG << " 1 ";
    207                                         }else{
     271                                        } else {
    208272                                                //locationBitWord ^= 0x0;
    209273                                                Log << MSG::DEBUG << " 0 ";
     
    212276                                        if(separatorItr != linePars.begin()) locationBitWord = locationBitWord << 1;
    213277                                        Log << MSG::DEBUG << endreq;
     278
    214279                                }
    215280
     
    232297                                        // store charge for landau distribution per section
    233298                                        m_chargePerSection[__HEAD_INDX].push_back( GetMatrixElement(*contItr) );
     299                                        m_XYPerSection[__HEAD_INDX].push_back( make_pair(x, y) );
     300
     301                                        // mean charge per section
     302                                        m_meanChargePerSection[__HEAD_INDX] += GetMatrixElement(*contItr);
     303
     304                                        // mean position
     305                                        m_sectionCenter_x[__HEAD_INDX] += x;
     306                                        m_sectionCenter_y[__HEAD_INDX] += y;
     307
    234308
    235309                                }else if( firstThreeBits == __RIGHT_CORNER_MASK_1
     
    242316                                        // store charge for landau distribution per section
    243317                                        m_chargePerSection[__TAIL_INDX].push_back( GetMatrixElement(*contItr) );
     318                                        m_XYPerSection[__TAIL_INDX].push_back( make_pair(x, y) );
     319
     320                                        // mean charge per section
     321                                        m_meanChargePerSection[__TAIL_INDX] += GetMatrixElement(*contItr);
     322
     323                                        // mean position
     324                                        m_sectionCenter_x[__TAIL_INDX] += x;
     325                                        m_sectionCenter_y[__TAIL_INDX] += y;
    244326
    245327                                }else{
     
    259341                                                nB--;
    260342                                        }
     343
    261344                                        Log << MSG::DEBUG << "... column " << nB << " ... " << GetFrameId() << endreq;
    262345                                        m_chargeWeights[nB] += GetMatrixElement(*contItr);
    263346                                        m_lvl1Weights[nB] += GetLVL1(*contItr);
     347
    264348                                        // Store charge for landau distribution per section
    265349                                        m_chargePerSection[nB].push_back( GetMatrixElement(*contItr) );
     350                                        m_XYPerSection[nB].push_back( make_pair(x, y) );
     351
     352                                        // charge per section
     353                                        m_meanChargePerSection[nB] += GetMatrixElement(*contItr);
     354
     355                                        // mean position
     356                                        m_sectionCenter_x[nB] += x;
     357                                        m_sectionCenter_y[nB] += y;
    266358
    267359                                }
     
    269361                        }
    270362
     363                        // FIXME !!!
     364                        // finish up the mean charge per section and position
     365                        for (int ix = 0 ; ix < (int)m_chargePerSection.size() ; ix++) {
     366                                int nEntriesSection = m_chargePerSection[ix].size();
     367                                m_meanChargePerSection[ix] /= nEntriesSection;
     368                                m_sectionCenter_x[ix] /= nEntriesSection;
     369                                m_sectionCenter_y[ix] /= nEntriesSection;
     370                        }
    271371
    272372                        // normalize by the total charge
    273373                        vector<Float_t>::iterator itr = m_chargeWeights.begin();
    274374                        int cntr = 0 ;
    275                         for( ; itr != m_chargeWeights.end() ; itr++){
     375                        for( ; itr != m_chargeWeights.end() ; itr++) {
    276376                                (*itr) /= (*blobsItr).GetBlobProperties().totalCharge;
    277377                                (*itr) *= 100.; // percentage
     
    288388                        m_nDeltaRaySoft += nDeltaSoft;
    289389
     390                        m_nDeltaRayPerFrame += nDeltaR; // this one is cleared on a frame-per-frame basis
     391                        m_nDeltaRaySoftPerFrame += nDeltaSoft; // this one is cleared on a frame-per-frame basis
     392
     393                        // Look at the hard delta rays trying to extract an energy profile
     394                        if (nDeltaR > 0) {
     395                                m_deltaRayTOT = ExtractDeltaRayEnergy(*blobsItr);
     396                        }
     397
    290398                        // WARNING, filling once per mip !!!
    291399                        m_frameId = GetFrameId();
     
    295403                        m_lvl1Weights.clear();
    296404                        m_chargePerSection.clear();
     405                        m_XYPerSection.clear();
     406                        m_mipLength.clear();
     407                        m_meanChargePerSection.clear();
     408                        m_sectionCenter_x.clear();
     409                        m_sectionCenter_y.clear();
     410
    297411                        m_alphaAngle = 0.;
    298412                        m_clusterSize = 0;
     413                        m_nDeltaRayPerFrame = 0;
     414                        m_nDeltaRaySoftPerFrame = 0;
    299415
    300416                } else {
     
    311427        m_lvl1Weights.clear();
    312428        m_chargePerSection.clear();
    313 
    314 }
    315 
     429        m_XYPerSection.clear();
     430        m_deltaRayTOT.clear();
     431        m_mipLength.clear();
     432
     433}
     434
     435void FEI3Mips::ClearThisAlgo(){
     436
     437        m_chargeWeights.clear();
     438        m_lvl1Weights.clear();
     439        m_chargePerSection.clear();
     440        m_XYPerSection.clear();
     441        m_mipLength.clear();
     442        m_meanChargePerSection.clear();
     443        m_sectionCenter_x.clear();
     444        m_sectionCenter_y.clear();
     445
     446}
    316447
    317448void FEI3Mips::Finalize() {
     
    325456        Log << MSG::INFO << "Total Number delta rays per centimeter = " << (m_nDeltaRay+m_nDeltaRaySoft)/(m_totalMIPsLength*0.1) << endreq;
    326457
     458}
     459
     460vector<Float_t> FEI3Mips::ExtractDeltaRayEnergy (blob bl) {
     461
     462        // At this point the information in m_chargeWeights is already
     463        // expressed in percentage per segment
     464        vector<Float_t>::iterator itr = m_chargeWeights.begin();
     465        Int_t indxMaxSeg = 0;
     466        Float_t maxSeg = 0.;
     467
     468        Int_t cntr = 0;
     469        // Find the hotest segment
     470        for ( ; itr != m_chargeWeights.end() ; itr++ ) {
     471
     472                if ( (*itr) > maxSeg ) {
     473                        maxSeg = (*itr);
     474                        indxMaxSeg = cntr;
     475                }
     476                cntr++;
     477        }
     478
     479        //  indxMaxSeg is the index of the hotest segment
     480        Log << MSG::INFO << "[" << indxMaxSeg << "] max = " << maxSeg << endreq;
     481
     482        // Now in this segment find the hotest point ( look at indxMaxSeg ! )
     483        vector<Int_t>::iterator cItr = m_chargePerSection[indxMaxSeg].begin();
     484        vector< pair<Int_t, Int_t> >::iterator xyItr = m_XYPerSection[indxMaxSeg].begin();
     485        Int_t highC = 0;
     486        Int_t highIndx = 0;
     487        cntr = 0;
     488        for ( ; cItr !=  m_chargePerSection[indxMaxSeg].end() ; ) {
     489
     490                if( *cItr > highC ) {
     491                        highC = *cItr;
     492                        highIndx = cntr;
     493                }
     494
     495                cntr++;
     496                cItr++;
     497                xyItr++;
     498        }
     499
     500        Log << MSG::INFO << "spot <" << m_XYPerSection[indxMaxSeg][highIndx].first << ", "
     501                        << m_XYPerSection[indxMaxSeg][highIndx].second << "> : "
     502                        << m_chargePerSection[indxMaxSeg][highIndx] << endreq;
     503
     504        // Once having the hotest pixel I can search for all the charge belonging to the
     505        // delta ray which has been emitted at m_XYPerSection[indxMaxSeg][highIndx].
     506        //
     507        // The approach is the following:
     508        // 1) Pixels very close to the hotest pixel probably have a bit of a higher TOT that
     509        //    the mean energy in the rest of the mip track.  That extra energy should be added
     510        //    to the delta ray spectrum.
     511        // 2) If the delta ray stayed in the plane of the sensor, there will probably be a few
     512        //    pixels ON close to the mip track with the shape of a low energy electron (curly).
     513        //    This energy ought to be added too.
     514
     515        vector<Float_t> deltaRaysTOT;
     516
     517        // The mean TOT in all the track is
     518        Float_t meanTOT = Float_t( bl.GetBlobProperties().totalCharge ) /
     519                        Float_t( bl.GetBlobProperties().nPixels );
     520
     521        Log << MSG::INFO << "mean TOT in mip = " << meanTOT << endreq;
     522
     523        // calculate perp distance in each point and also the distance to the hot point
     524        Float_t slope = bl.GetBlobProperties().fitSlope;
     525        Float_t cut = bl.GetBlobProperties().fitCut;
     526        // Prepare perpendicular line passing by hot pixel
     527        Float_t slopePrim = -1/slope;
     528        Float_t cutPrim = m_XYPerSection[indxMaxSeg][highIndx].second;
     529        cutPrim -= slopePrim * m_XYPerSection[indxMaxSeg][highIndx].first;
     530
     531        list< pair < pair<Int_t, Int_t>, Int_t > > contents = bl.GetBlobContent();
     532        list< pair < pair<Int_t, Int_t>, Int_t > >::iterator bcItr = contents.begin();
     533
     534        Double_t distP = 0., distHot = 0., distHotPerp = 0.;
     535        Float_t deltaRayTotalTOT = 0.;
     536
     537        // draw the perp line passing by hot pixel
     538        Float_t x1p = m_XYPerSection[indxMaxSeg][highIndx].first;
     539        Float_t y1p = m_XYPerSection[indxMaxSeg][highIndx].second;
     540        Float_t x2p = x1p*1.5;
     541        Float_t y2p = slopePrim * x2p + cutPrim;
     542        MAFTools::DrawLine(this, x1p, y1p, x2p, y2p, 2, 1, kBlack);
     543
     544        for ( ; bcItr != contents.end() ; bcItr++ ) {
     545
     546                // perpendicular distance to Linear Regression
     547                distP = MAFTools::CalcPerpDistanceToLine(slope, cut, (*bcItr).first);
     548                // distance to hot pixel (vertex)
     549                distHot = MAFTools::CalcDistance(m_XYPerSection[indxMaxSeg][highIndx], (*bcItr).first);
     550                // perpendicular distance to perp to Linear Regression passing by hot pixel
     551                distHotPerp = MAFTools::CalcPerpDistanceToLine(slopePrim, cutPrim, (*bcItr).first);
     552
     553                if( (distP < 1.0 && distHot < m_distanceCutHot) // close to vertex
     554                                || distHotPerp < m_distancePerpHot) // parallel path
     555                {
     556
     557                        Highlighter * fp = new Highlighter((*bcItr).first.first,
     558                                        (*bcItr).first.second,
     559                                        "arrow", this);
     560                        fp->SetLineColor(kRed);
     561                        fp->SetLineWidth(1);
     562                        PullToStoreGateAccess(fp, MPXDefs::DO_NOT_SERIALIZE_ME);
     563
     564                        Log << MSG::DEBUG << "perp dist = " << distP << ", distance to Hot = " << distHot << endreq;
     565                        // Finally store the excess energy if it is over the mean
     566                        Float_t TOTDiff = GetMatrixElement( (*bcItr).first ) - meanTOT;
     567                        if( TOTDiff > 0 ) {
     568                                // FIXME !, store the whole energy !
     569                                deltaRayTotalTOT += TOTDiff;
     570                        }
     571                }
     572        }
     573
     574        deltaRaysTOT.push_back(deltaRayTotalTOT);
     575
     576        return deltaRaysTOT;
    327577}
    328578
     
    379629}
    380630
    381 vector<pair<Int_t, Int_t> > FEI3Mips::FindLimitPixels(blob theBlob) {
     631vector<pair<Float_t, Float_t> > FEI3Mips::FindLimitPixels(blob theBlob) {
    382632
    383633        // result vector
    384         vector<pair<Int_t, Int_t> > limits;
     634        vector<pair<Float_t, Float_t> > limits;
    385635        limits.push_back( make_pair(0, 0) );
    386636        limits.push_back( make_pair(0, 0) );
     
    400650
    401651                        if( dist > max ) {
     652
    402653                                max = dist;
     654
    403655                                limits[0] = *contItrA;
    404656                                limits[1] = *contItrB;
     657
     658                                // The limit in the extreme right needs an adjustement of 1 pixel
     659                                limits[1].first += 1; // 1 pixel
     660
    405661                        }
    406662
     
    428684}
    429685
    430 pair<Float_t, Float_t> FEI3Mips::GetParallelLineAt(Float_t slope, Float_t, pair<Int_t, Int_t> point) {
     686// FIXME ... shouldn't this be called "Perpendicular" ? just check the logics.
     687//pair<Float_t, Float_t> FEI3Mips::GetParallelLineAt(Float_t slope, Float_t cut, pair<Int_t, Int_t> point, bool * pL) {
     688//i-
     689pair<Float_t, Float_t> FEI3Mips::GetParallelLineAt(Float_t slope, Float_t cut, pair<Float_t, Float_t> point, bool * pL) {
     690
     691        if ( slope == 0. ) {
     692                // In this trivial case, I basically return the pair 'point'.
     693                // I will only need the x coordinate to calculate the distance later on
     694                *pL = true;
     695                return point;
     696
     697        }
    431698
    432699        Float_t cutPrim = 0.;
  • mafalda/FEI3/FEI3Mips/FEI3Mips.h

    r175 r222  
    3535  void Finalize();
    3636
    37   vector<pair<Int_t, Int_t> > FindLimitPixels(blob);
    38   pair<Float_t, Float_t> GetParallelLineAt(Float_t, Float_t, pair<Int_t, Int_t>);
     37  vector<pair<Float_t, Float_t> > FindLimitPixels(blob);
     38  //-i
     39  //pair<Float_t, Float_t> GetParallelLineAt(Float_t, Float_t, pair<Int_t, Int_t>, bool *);
     40  pair<Float_t, Float_t> GetParallelLineAt(Float_t, Float_t, pair<Float_t, Float_t>, bool *);
    3941  Int_t NumberOfBitsOnBeforeDoubleZero(UInt_t);
    4042  Int_t GuessNumberOfDeltaRaysFromUnbalance(Int_t &, Int_t &);
     43  vector<Float_t> ExtractDeltaRayEnergy(blob);
     44  void ClearThisAlgo();
    4145
    4246private:
     
    4448  AllBlobsContainer * m_aB;
    4549  Int_t m_minNPixels;
     50  Float_t m_minMipLength;
    4651  Int_t m_nDivisions;
    4752  Float_t m_pixSizeX;
    4853  Float_t m_pixSizeY;
    4954  Float_t m_dRayBalSearch;
     55  Int_t m_guardDistanceX;
     56  Int_t m_guardDistanceY;
    5057  const Float_t m_FEI3_PIXELSIZE_YX_FRACTION;
    5158
     
    5461  vector<Float_t> m_lvl1Weights;
    5562
     63  // charge per section
    5664  vector< vector<Int_t> > m_chargePerSection;
     65  vector< Float_t > m_meanChargePerSection;
     66  vector< Float_t > m_sectionCenter_x;
     67  vector< Float_t > m_sectionCenter_y;
    5768
     69  // store the coordinates too
     70  vector< vector< pair<Int_t, Int_t> > > m_XYPerSection;
     71
     72  vector<Float_t> m_deltaRayTOT;
     73  vector<Float_t> m_mipLength;
    5874  Double_t m_totalMIPsLength;
    59   Int_t m_nDeltaRay;
    60   Int_t m_nDeltaRaySoft;
     75
     76  Int_t m_nDeltaRay; // counter over the whole run
     77  Int_t m_nDeltaRaySoft; // counter over the whole run
     78  Int_t m_nDeltaRayPerFrame; // to store frame per frame
     79  Int_t m_nDeltaRaySoftPerFrame; // to store frame per frame
     80
     81  Int_t m_distanceCutHot;
     82  Int_t m_distancePerpHot;
    6183
    6284  Int_t m_clusterSize;
  • mafalda/MAFTools/MAFTools.cpp

    r124 r222  
    1212#include "MPXAlgo/Highlighter.h"
    1313#include "MPXAlgo/MediPixAlgo.h"
     14
     15#include "BlobsFinder/BlobsFinder.h"
    1416
    1517#include <set>
     
    157159}
    158160
     161vector<pair<Float_t, Float_t> > FindLimitPixels(blob theBlob) {
     162
     163        // result vector
     164        vector<pair<Float_t, Float_t> > limits;
     165        limits.push_back( make_pair(0, 0) );
     166        limits.push_back( make_pair(0, 0) );
     167
     168        set< pair<Int_t, Int_t> > contents = theBlob.GetContentSet();
     169
     170        set< pair<Int_t, Int_t> >::iterator contItrA = contents.begin();
     171        set< pair<Int_t, Int_t> >::iterator contItrB = contents.begin();
     172
     173        double max = 0., dist = 0.;
     174
     175        for( ; contItrA != contents.end() ; contItrA++) {
     176
     177                for(contItrB = contItrA ; contItrB != contents.end() ; contItrB++) {
     178
     179                        dist = MAFTools::CalcDistance( *contItrA, *contItrB );
     180
     181                        if( dist > max ) {
     182                                max = dist;
     183                                limits[0] = *contItrA;
     184                                limits[1] = *contItrB;
     185                        }
     186
     187                }
     188
     189        }
     190
     191        return limits;
     192}
     193
     194
     195Bool_t BlobAtADistanceFromEdges(blob, vector<pair<Float_t, Float_t> > l, Int_t width, Int_t height,
     196                Int_t cutx, Int_t cuty) {
     197
     198        Int_t dist = 0.; // in units of pixels
     199
     200        // lower border
     201        for (int i = 0 ; i < (int)l.size() ; i++) {
     202                dist = l[i].second;
     203                if ( dist <= cuty ) return true;
     204        }
     205        // left border
     206        for (int i = 0 ; i < (int)l.size() ; i++) {
     207                dist = l[i].first;
     208                if ( dist <= cutx ) return true;
     209        }
     210        // top border
     211        for (int i = 0 ; i < (int)l.size() ; i++) {
     212                dist = height - l[i].second;
     213                if ( dist <= cuty ) return true;
     214        }
     215        // right border
     216        for (int i = 0 ; i < (int)l.size() ; i++) {
     217                dist = width - l[i].first;
     218                if ( dist <= cutx ) return true;
     219        }
     220
     221        return false;
     222}
     223
    159224}
    160225
  • mafalda/MAFTools/MAFTools.h

    r124 r222  
    11/**
    2  *
    3  * Author:  John Idarraga <idarraga@cern.ch> , 2009
    4  * Medipix Group, Universite de Montreal
    5  *
     2 * Author:  John Idarraga <idarraga@cern.ch>
    63 */
    74
     
    1512#include <TROOT.h>
    1613
     14class blob;
    1715class MediPixAlgo;
    1816
     
    4543  std::string DumpWordInBinary(UInt_t word);
    4644
     45  // Blobs handling
     46  vector<pair<Float_t, Float_t> > FindLimitPixels(blob);
     47
     48  /*
     49   * Check if a blob appears within a certain distance from the edges
     50   * Parameters:
     51   *  - blob
     52   *  - vector containing farthest pixels in the blob (see FindLimitPixels(blob))
     53   *  - Width of sensor in units of pixels
     54   *  - Height of sensor in units of pixels
     55   */
     56  Bool_t BlobAtADistanceFromEdges(blob, vector<pair<Float_t, Float_t> >, Int_t, Int_t, Int_t, Int_t);
     57
    4758}
    4859
  • mafalda/MPXAlgo/MediPixAlgo.h

    r179 r222  
    6565  Int_t GetMatrixXdim();
    6666  Int_t GetMatrixWidth(){return GetMatrixXdim();}; // same
     67  Int_t GetWidth(){return GetMatrixXdim();}; // same
     68
    6769  Int_t GetMatrixYdim();
    6870  Int_t GetMatrixHeight(){return GetMatrixYdim();}; // same
     71  Int_t GetHeight(){return GetMatrixYdim();}; // same
    6972
    7073  Int_t GetMatrixElement(Int_t col, Int_t row);
  • mafalda/ShallowAngleFEIX/ShallowAngleFEIX.cpp

    r219 r222  
    130130
    131131
    132                         Log << MSG::INFO << "angle = " <<  (*blobsItr).GetBlobProperties().rotAngle << endreq;
     132                        Log << MSG::INFO << "Mip angle = " <<  (*blobsItr).GetBlobProperties().rotAngle << endreq;
    133133                        if( TMath::Abs( (*blobsItr).GetBlobProperties().rotAngle ) > TMath::Pi()/3.)
    134134                                continue;
    135135
    136                         // Start counting
    137                         Log << MSG::DEBUG << "tail first  = " << limitPixels[__TAIL_INDX].first << endreq;
    138                         Log << MSG::DEBUG << "head first  = " << limitPixels[__HEAD_INDX].first << endreq;
    139                         Log << MSG::DEBUG << "tail second = " << limitPixels[__TAIL_INDX].second << endreq;
    140                         Log << MSG::DEBUG << "head second = " << limitPixels[__HEAD_INDX].second << endreq;
    141 
    142                         int initx = limitPixels[__HEAD_INDX].first;
    143                         int endx = limitPixels[__TAIL_INDX].first;
    144                         if ( initx > endx ) {
    145                                 initx = limitPixels[__TAIL_INDX].first;
    146                                 endx = limitPixels[__HEAD_INDX].first;
    147                         }
    148                         int inity = limitPixels[__HEAD_INDX].second;
    149                         int endy = limitPixels[__TAIL_INDX].second;
    150                         if ( inity > endy ) {
    151                                 inity = limitPixels[__TAIL_INDX].second;
    152                                 endy = limitPixels[__HEAD_INDX].second;
    153                         }
     136                        // Find the limit pixels to add-up the charge per column.
     137                        //  It turns out that the limit pixels found above are not exactly
     138                        //  what I need here.  Often a delta ray comes out of the box marked
     139                        //  by these limits and it could remain not included.
     140                        // I will use the limits given by the box.
     141
     142                        Float_t midx = ((Float_t)(*blobsItr).GetBlobProperties().width_x) /2.;
     143                        Float_t midy = ((Float_t)(*blobsItr).GetBlobProperties().width_y) /2.;
     144                        int initx = TMath::FloorNint((*blobsItr).GetBlobProperties().geoCenter_x - midx);
     145                        int endx = TMath::FloorNint((*blobsItr).GetBlobProperties().geoCenter_x + midx - 1);
     146                        int inity = TMath::FloorNint((*blobsItr).GetBlobProperties().geoCenter_y - midy);
     147                        int endy = TMath::FloorNint((*blobsItr).GetBlobProperties().geoCenter_y + midy - 1);
     148
     149                        Log << MSG::INFO << "Searching in box limited by x:" << initx << " , " << endx << endreq;
     150                        Log << MSG::INFO << "                            y:" << inity << " , " << endy << endreq;
    154151
    155152                        m_clusterHeight = (*blobsItr).GetBlobProperties().width_y;
     
    163160                                for (int y = inity ; y <= endy ; y++) {
    164161
    165                                         Log << MSG::DEBUG << "search : " << x << " , " << y << endreq;
     162                                        Log << MSG::DEBUG << "  --> " << x << " , " << y << " : " << GetMatrixElement(x,y) << endreq;
    166163                                        m_totPerSegment[cntr] += GetMatrixElement(x,y);
    167164                                        m_chargeWeights[cntr] += GetMatrixElement(x,y); // normalized later
     
    189186                                        Log << MSG::DEBUG << "[" << segCntr << "] "
    190187                                                        << "(TOT , fraction) : " <<
    191                                                         *itrT << " , " << cout.precision(2) << (*itrW)*100
     188                                                        *itrT << " , " << (*itrW)*100 << "\%"
    192189                                                        << endreq;
    193190
     
    232229        Int_t nExplicit = 0, nSoft = 0;
    233230
     231        Log << MSG::INFO << "Starting delta ray search " << endreq;
     232
    234233        for ( ; itr != m_chargeWeights.end() ; itr++ ) {
    235234
     
    241240                        unbalance = (*itr)/(*itrC);
    242241                        if ( unbalance > m_dRayBalSearch ) {
    243                                 Log << MSG::INFO << "section " << cntr << " much hotter than " << cntrE << endreq;
     242                                Log << MSG::DEBUG << "section " << cntr << " much hotter than " << cntrE << endreq;
    244243                                nNoticeableUnbalances[cntr]++;
    245244                        }
     
    258257        for( ; itrU != nNoticeableUnbalances.end() ; itrU++){
    259258
    260                 if ( (*itrU) == nDiv - 1 ) { // an explicit delta ray.  Unbalance to all other segments
     259                if ( (*itrU) == nDiv - 1 ) { // an explicit delta ray.  Un-balance to all other segments
    261260                        nExplicit++;
    262                 } else if ( (*itrU) == nDiv - 2 ) {
     261                } else if ( (*itrU) == nDiv - 2 ) { // a soft.  Unbalance to all-1 other segments
    263262                        nSoft++;
    264263                }
Note: See TracChangeset for help on using the changeset viewer.