Skip to content
Snippets Groups Projects
TMust2Physics.h 12 KiB
Newer Older
Unknown's avatar
Unknown committed
#ifndef TMUST2PHYSICS_H
#define TMUST2PHYSICS_H
Unknown's avatar
Unknown committed
/*****************************************************************************
 * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
Unknown's avatar
Unknown committed
 * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
 * For the list of contributors see $NPTOOL/Licence/Contributors             *
 *****************************************************************************/
Unknown's avatar
Unknown committed

Unknown's avatar
Unknown committed
/*****************************************************************************
adrien-matta's avatar
adrien-matta committed
 * Original Author: Adrien MATTA  contact address: a.matta@surrey.ac.uk      *
 *                                                                           *
 * Creation Date  : febuary 2009                                             *
 * Last update    : July 2021
Unknown's avatar
Unknown committed
 *---------------------------------------------------------------------------*
 * Decription:                                                               *
 *  This class hold must2 treated data                                       *
 *                                                                           *
Unknown's avatar
Unknown committed
 *---------------------------------------------------------------------------*
 * Comment:                                                                  *
 *                                                                           *
 *                                                                           *
 *                                                                           *
Unknown's avatar
Unknown committed
 *****************************************************************************/
#include <map>
#include "NPCalibrationManager.h"
#include "NPInputParser.h"
#include "TMust2Data.h"
#include "TMust2Spectra.h"
#include "TMust2PhysicsReader.h"
#include "NPDetectorFactory.h"
// ROOT
#include "TVector2.h"
#include "TVector3.h"
Unknown's avatar
Unknown committed

// Forward Declaration
class TMust2Spectra;

class TMust2Physics : public TObject, public NPL::VDetector, public TMust2PhysicsReader{
Valérian Alcindor's avatar
Valérian Alcindor committed
public:
Valérian Alcindor's avatar
Valérian Alcindor committed
public:
  void Clear();
  void Clear(const Option_t*){};
Valérian Alcindor's avatar
Valérian Alcindor committed
public:
  int              CheckEvent(int N);
  bool             Match_Si_CsI(int X, int Y, int CristalNbr, int DetectorNbr);
  bool             Match_Si_SiLi(int X, int Y, int PadNbr);
  bool             ResolvePseudoEvent();
Valérian Alcindor's avatar
Valérian Alcindor committed
public:
Valérian Alcindor's avatar
Valérian Alcindor committed
  // Int_t EventMultiplicity;
  int EventMultiplicity;

  //   Provide a Classification of Event
  vector<int> EventType;

  // Telescope
  vector<int> TelescopeNumber;

  //   Si
  vector<double> Si_E;
  vector<double> Si_T;
  vector<int>    Si_X;
  vector<int>    Si_Y;

  // Use for checking purpose
  vector<double> Si_EX;
  vector<double> Si_TX;
  vector<double> Si_EY;
  vector<double> Si_TY;
  vector<int>    TelescopeNumber_X;
  vector<int>    TelescopeNumber_Y;
  //   Si(Li)
  vector<double> SiLi_E;
  vector<double> SiLi_T;
  vector<int>    SiLi_N;
  //   CsI
  vector<double> CsI_E;
  vector<double> CsI_T;
  vector<int>    CsI_N;

  // Physical Value
  vector<double> TotalEnergy;

Valérian Alcindor's avatar
Valérian Alcindor committed
public: //   Innherited from VDetector Class
  //   Read stream at ConfigFile to pick-up parameters of detector
  //   (Position,...) using Token
  void ReadConfiguration(NPL::InputParser parser); 

  //   Add Parameter to the CalibrationManger
  void AddParameterToCalibrationManager();

  //   Activated associated Branches and link it to the private member
  //   DetectorData address
  //   In this method mother Branches (Detector) AND daughter leaf
  //   (fDetector_parameter) have to be activated
  void InitializeRootInputRaw();

  //   Activated associated Branches and link it to the private member
  //   DetectorPhysics address
  //   In this method mother Branches (Detector) AND daughter leaf (parameter)
  //   have to be activated
  void InitializeRootInputPhysics();

  //   Create associated branches and associated private member DetectorPhysics
  //   address
  void InitializeRootOutput();

  //   This method is called at each event read from the Input Tree. Aime is to
  //   build treat Raw dat in order to extract physical parameter.
  void BuildPhysicalEvent();

  //   Same as above, but only the simplest event and/or simple method are used
  //   (low multiplicity, faster algorythm but less efficient ...).
  //   This method aimed to be used for analysis performed during experiment,
  //   when speed is requiered.
  //   NB: This method can eventually be the same as BuildPhysicalEvent.
  void BuildSimplePhysicalEvent();

  // Same as above but for online analysis
  void BuildOnlinePhysicalEvent() { BuildPhysicalEvent(); };

  //   Those two method all to clear the Event Physics or Data
  void ClearEventPhysics() { Clear(); }
  void ClearEventData() { m_EventData->Clear(); }
  // Method related to the TSpectra classes, aimed at providing a framework for
  // online applications
  // Instantiate the Spectra class and the histogramm throught it
  
  bool UnallocateBeforeBuild();
  bool UnallocateBeforeTreat();
  
  void InitSpectra();
  // Fill the spectra hold by the spectra class
  void FillSpectra();
  // Used for Online mainly, perform check on the histo and for example change
  // their color if issues are found
  void CheckSpectra();
  // Used for Online only, clear all the spectra hold by the Spectra class
  void ClearSpectra();

  void SetTreeReader(TTreeReader* TreeReader);

Valérian Alcindor's avatar
Valérian Alcindor committed
public: //   Specific to MUST2 Array
  //   Clear The PreTeated object
  void ClearPreTreatedData() { m_PreTreatedData->Clear(); }

  //   Remove bad channel, calibrate the data and apply threshold
  void PreTreat();

  //   Return false if the channel is disabled by user
  //   Frist argument is either 0 for X,1 Y,2 SiLi, 3 CsI
  bool IsValidChannel(const int& DetectorType, const int& telescope,
                      const int& channel);

  //   Initialize the standard parameter for analysis
  //   ie: all channel enable, maximum multiplicity for strip = number of
  //   telescope
  void InitializeStandardParameter();

  //   Read the user configuration file; if no file found, load standard one
  void ReadAnalysisConfig();

  //   Add a Telescope using Corner Coordinate information
  void AddTelescope(TVector3 C_X1_Y1, TVector3 C_X128_Y1, TVector3 C_X1_Y128,
                    TVector3 C_X128_Y128);

  //   Add a Telescope using R Theta Phi of Si center information
  void AddTelescope(double theta, double phi, double distance, double beta_u,
                    double beta_v, double beta_w);

  // Use for reading Calibration Run, very simple methods; only apply
  // calibration, no condition
  void ReadCalibrationRun();

  // Give and external TMustData object to TMust2Physics. Needed for online
  // analysis for example.
  void SetRawDataPointer(void* rawDataPointer) {
    m_EventData = (TMust2Data*)rawDataPointer;
  }
  // Retrieve raw and pre-treated data
  TMust2Data* GetRawData() const {//std::cout << "test" << std::endl; 
  return m_EventData; }
  //TMust2Data* GetRawDataRead() const {std::cout << "test getrawdata" << std::endl; return r_EventData; }
  TMust2Data* GetPreTreatedData() const { return m_PreTreatedData; }
  //TMust2Physics* GetPhysicsData() const {return m_EventPhysics;}

  // Use to access the strip position
  double GetStripPositionX(const int N, const int X, const int Y) const {
    return m_StripPositionX[N - 1][X - 1][Y - 1];
  };
  double GetStripPositionY(const int N, const int X, const int Y) const {
    return m_StripPositionY[N - 1][X - 1][Y - 1];
  };
  double GetStripPositionZ(const int N, const int X, const int Y) const {
    return m_StripPositionZ[N - 1][X - 1][Y - 1];
  };

  double GetNumberOfTelescope() const { return m_NumberOfTelescope; };

  // To be called after a build Physical Event
  int GetEventMultiplicity() const { return EventMultiplicity; };

  double GetEnergyDeposit(const int i) const { return TotalEnergy[i]; };

  TVector3 GetPositionOfInteraction(const int i) const;
  TVector3 GetTelescopeNormal(const int i) const;

Valérian Alcindor's avatar
Valérian Alcindor committed
private: //   Parameter used in the analysis
  // By default take EX and TY.
  bool m_Take_E_Y; //!
  bool m_Take_T_Y; //!

  // Size Container to be used in the different loop of the analysis (value must
  // be given locally)
  unsigned int m_StripXEMult; //!
  unsigned int m_StripYEMult; //!
  unsigned int m_StripXTMult; //!
  unsigned int m_StripYTMult; //!
  unsigned int m_SiLiEMult; //!
  unsigned int m_SiLiTMult; //!
  unsigned int m_CsIEMult; //!
  unsigned int m_CsITMult; //!

  //   Event over this value after pre-treatment are not treated / avoid long
  //   treatment time on spurious event
  unsigned int m_MaximumStripMultiplicityAllowed; //!
  //   Give the allowance in percent of the difference in energy between X and Y
  double m_StripEnergyMatchingSigma; //!
  double m_StripEnergyMatchingNumberOfSigma; //!

  // Raw Threshold
  int m_Si_X_E_RAW_Threshold; //!
  int m_Si_Y_E_RAW_Threshold; //!
  int m_SiLi_E_RAW_Threshold; //!
  int m_CsI_E_RAW_Threshold; //!

  // Calibrated Threshold
  double m_Si_X_E_Threshold; //!
  double m_Si_Y_E_Threshold; //!
  double m_SiLi_E_Threshold; //!
  double m_CsI_E_Threshold; //!

  // Geometric Matching
  // size in strip of a pad
  int m_SiLi_Size; //!
  // center position of the pad on X
  vector<int> m_SiLi_MatchingX; //!
  // center position of the pad on Y
  vector<int> m_SiLi_MatchingY; //!
  // size in strip of a cristal
  int m_CsI_Size; //!
  // center position of the cristal on X
  vector<int>                        m_CsI_MatchingX; //!
  std::map<int, std::pair<int, int>> m_ZeroDegree_CsI_MatchingX; //!
  // center position of the cristal on X
  vector<int>                        m_CsI_MatchingY; //!
  std::map<int, std::pair<int, int>> m_ZeroDegree_CsI_MatchingY; //!

  // If set to true, all event that do not come in front of a cristal will be
  // ignore all time (crossing or not),
  // Warning, this option reduce statistic, however it help eliminating
  // unrealevent event that cross the DSSD
  // And go between pad or cristal.
  bool m_Ignore_not_matching_SiLi; //!
  bool m_Ignore_not_matching_CsI; //!

Valérian Alcindor's avatar
Valérian Alcindor committed
private: //   Root Input and Output tree classes
  TMust2Data*    m_EventData; //!
  TMust2Data*    m_PreTreatedData; //!
  TMust2Physics* m_EventPhysics; //!
Valérian Alcindor's avatar
Valérian Alcindor committed
private: //   Map of activated channel
  map<int, vector<bool>> m_XChannelStatus; //!
  map<int, vector<bool>> m_YChannelStatus; //!
  map<int, vector<bool>> m_SiLiChannelStatus; //!
  map<int, vector<bool>> m_CsIChannelStatus; //!

Valérian Alcindor's avatar
Valérian Alcindor committed
private:
  int m_NumberOfTelescope; //!

  vector<vector<vector<double>>> m_StripPositionX; //!
  vector<vector<vector<double>>> m_StripPositionY; //!
  vector<vector<vector<double>>> m_StripPositionZ; //!

Valérian Alcindor's avatar
Valérian Alcindor committed
public:
  // Prevent to treat event with ambiguous matching beetween X and Y
  bool          m_multimatch; //!
  vector<int>   m_match_type; //!
Valérian Alcindor's avatar
Valérian Alcindor committed
  map<int, int> m_NMatchDet; //!
  map<int, int> m_StripXMultDet; //!
  map<int, int> m_StripYMultDet; //!
  map<int, int> m_NMatchX; //!
  map<int, int> m_NMatchY; //!
Valérian Alcindor's avatar
Valérian Alcindor committed

private:
  map<int, bool> m_CsIPresent; //!
  map<int, bool> m_SiLiPresent; //!
Valérian Alcindor's avatar
Valérian Alcindor committed
private: // Spectra Class
Valérian Alcindor's avatar
Valérian Alcindor committed
public:
Valérian Alcindor's avatar
Valérian Alcindor committed
public: // Spectra Getter
Valérian Alcindor's avatar
Valérian Alcindor committed
public: // Static constructor to be passed to the Detector Factory
  static NPL::VTreeReader* ConstructReader();
  ClassDef(TMust2Physics, 1) // Must2Physics structure
Unknown's avatar
Unknown committed
};

namespace MUST2_LOCAL {
//   DSSD
//   X
double fSi_X_E(const TMust2Data* Data, const int& i);
double fSi_X_T(const TMust2Data* Data, const int& i);
//   Y
double fSi_Y_E(const TMust2Data* Data, const int& i);
double fSi_Y_T(const TMust2Data* Data, const int& i);
//   SiLi
double fSiLi_E(const TMust2Data* Data, const int& i);
double fSiLi_T(const TMust2Data* Data, const int& i);
//   CsI
double fCsI_E(const TMust2Data* Data, const int& i);
double fCsI_T(const TMust2Data* Data, const int& i);
Valérian Alcindor's avatar
Valérian Alcindor committed
} // namespace MUST2_LOCAL
Unknown's avatar
Unknown committed
#endif