ImgPixSpectra/include/CSPadPixSpectra.h

Go to the documentation of this file.
00001 #ifndef IMGPIXSPECTRA_CSPADPIXSPECTRA_H
00002 #define IMGPIXSPECTRA_CSPADPIXSPECTRA_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id$
00007 //
00008 // Description:
00009 //      Class CSPadPixSpectra.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 
00017 //----------------------
00018 // Base Class Headers --
00019 //----------------------
00020 #include "psana/Module.h"
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "psddl_psana/cspad.ddl.h"
00026 //#include "ndarray/ndarray.h"
00027 
00028 //------------------------------------
00029 // Collaborating Class Declarations --
00030 //------------------------------------
00031 
00032 //              ---------------------
00033 //              -- Class Interface --
00034 //              ---------------------
00035 
00036 namespace ImgPixSpectra {
00037 
00038 /// @addtogroup ImgPixSpectra
00039 
00040 /**
00041  *  @ingroup ImgPixSpectra
00042  *
00043  *  @brief Creates the spectal array for all pixels in the CSPad detector.
00044  *
00045  *  CSPadPixSpectra class is a psana module which creates and fills 
00046  *  the spectral array for all pixels in the CSPad array. The spectral
00047  *  array has two dimensions, the total number of pixels and
00048  *  the number of amplitude bins requested in the list of configuration parameters.
00049  *
00050  *  An example of the configuration file (psana.cfg) for this module:
00051  *
00052  *    @code
00053  *    [psana]
00054  *    files         = /reg/d/psdm/CXI/cxi35711/xtc/e86-r0009-s00-c00.xtc
00055  *    modules       = ImgPixSpectra.CSPadPixSpectra
00056  *
00057  *    [ImgPixSpectra.CSPadPixSpectra]
00058  *    source        = CxiDs1.0:Cspad.0
00059  *    amin          =    10.
00060  *    amax          =  2010.
00061  *    nbins         =   100
00062  *    arr_fname     = cspad-pix-spectra.txt
00063  *    #events       =   500                                                  
00064  *    @endcode
00065  *
00066  *  The output file "cspad-pix-spectra.txt" contains the spectral array 
00067  *  for CSPad pixels accumulated in job. 
00068  *  Axillary file with additional name extension ".sha" contains the shape parameters
00069  *  of the spectral array. The file(s) can be used for further analysis 
00070  *  or presentation, for example, using the python script:
00071  *
00072  *    @code
00073  *    ImgPixSpectra/data/PlotSpectralArrayFromFile.py cspad-pix-spectra.txt
00074  *    @endcode
00075  *
00076  *  This software was developed for the LCLS project. If you use all or 
00077  *  part of it, please give an appropriate acknowledgment.
00078  *
00079  *  @see AdditionalClass
00080  *
00081  *  @version \$Id: CSPadPixSpectra.h$
00082  *
00083  *  @author Mikhail S. Dubrovin
00084  */
00085 
00086 class CSPadPixSpectra : public Module {
00087 public:
00088 
00089   typedef Psana::CsPad::DataV2    CSPadDataType;
00090   typedef Psana::CsPad::ElementV2 CSPadElementType;
00091   typedef Psana::CsPad::ConfigV3  CSPadConfigType;
00092 
00093   // Default constructor
00094   CSPadPixSpectra (const std::string& name) ;
00095 
00096   // Destructor
00097   virtual ~CSPadPixSpectra () ;
00098 
00099   /// Method which is called once at the beginning of the job
00100   virtual void beginJob(Event& evt, Env& env);
00101   
00102   /// Method which is called at the beginning of the run
00103   virtual void beginRun(Event& evt, Env& env);
00104   
00105   /// Method which is called at the beginning of the calibration cycle
00106   virtual void beginCalibCycle(Event& evt, Env& env);
00107   
00108   /// Method which is called with event data, this is the only required 
00109   /// method, all other methods are optional
00110   virtual void event(Event& evt, Env& env);
00111   
00112   /// Method which is called at the end of the calibration cycle
00113   virtual void endCalibCycle(Event& evt, Env& env);
00114 
00115   /// Method which is called at the end of the run
00116   virtual void endRun(Event& evt, Env& env);
00117 
00118   /// Method which is called once at the end of the job
00119   virtual void endJob(Event& evt, Env& env);
00120 
00121 protected:
00122 
00123   void getQuadConfigPars(Env& env);
00124   void printQuadConfigPars();
00125   void printInputPars();
00126   void arrayInit();
00127   void arrayDelete();
00128   void loopOverQuads(shared_ptr<CSPadDataType> data);
00129   void arrayFill(int quad, const int16_t* data, uint32_t roiMask);
00130   void saveArrayInFile();
00131   void saveShapeInFile();
00132   int  ampToIndex(double amp);
00133 
00134 private:
00135 
00136   // Data members, this is for example purposes only
00137   
00138   Source   m_src;         // Data source set from config file
00139   Pds::Src m_actualSrc;
00140   std::string m_key;
00141   unsigned m_maxEvents;
00142   double   m_amin;
00143   double   m_amax;
00144   int      m_nbins;
00145   std::string   m_arr_fname;
00146   std::string   m_arr_shape_fname;
00147   bool     m_filter;
00148   long     m_count;
00149   
00150   int      m_nbins1;
00151   double   m_factor;
00152 
00153   uint32_t m_roiMask        [4];
00154   uint32_t m_numAsicsStored [4];
00155 
00156   uint32_t m_nquads;         // 4
00157   uint32_t m_n2x1;           // 8
00158   uint32_t m_ncols2x1;       // 185
00159   uint32_t m_nrows2x1;       // 388
00160   uint32_t m_sizeOf2x1Arr;   // 185*388;
00161   uint32_t m_sizeOfQuadArr;  // 185*388*8;
00162   uint32_t m_sizeOfCSPadArr; // 185*388*8*4;
00163   uint32_t m_pixel_ind;
00164 
00165   //std::vector<int> m_image_shape;
00166 
00167   int*           m_arr;
00168   //ndarray<int,2> m_arr2d;
00169 
00170 
00171 //--------------------
00172   /**
00173    * @brief Gets m_numQuadsInConfig, m_roiMask[q] and m_numAsicsStored[q] from the Psana::CsPad::ConfigV# object.
00174    * 
00175    */
00176 
00177 template <typename T>
00178 bool getQuadConfigParsForType(Env& env)
00179 {
00180   shared_ptr<T> config = env.configStore().get(m_src);
00181   if (config.get()) {
00182       for (uint32_t q = 0; q < 4; ++ q) {
00183         m_roiMask[q]         = config->roiMask(q);
00184         m_numAsicsStored[q]  = config->numAsicsStored(q);
00185       }
00186 
00187       m_nquads         = config->numQuads();               // this may be less than 4
00188       m_n2x1           = Psana::CsPad::SectorsPerQuad;     // v_image_shape[0]; // 8
00189       m_ncols2x1       = Psana::CsPad::ColumnsPerASIC;     // v_image_shape[1]; // 185
00190       m_nrows2x1       = Psana::CsPad::MaxRowsPerASIC * 2; // v_image_shape[2]; // 388
00191       m_sizeOf2x1Arr   = m_nrows2x1      * m_ncols2x1;                          // 185*388;
00192       m_sizeOfQuadArr  = m_sizeOf2x1Arr  * m_n2x1;                              // 185*388*8;
00193       m_sizeOfCSPadArr = m_sizeOfQuadArr * 4;                                   // 185*388*8*4;
00194 
00195       return true; 
00196   }
00197   return false;
00198 }
00199 
00200 //--------------------
00201 
00202 };
00203 
00204 } // namespace ImgPixSpectra
00205 
00206 #endif // IMGPIXSPECTRA_CSPADPIXSPECTRA_H

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7