TSamuraiFDC2Physics.h 7.69 KB
Newer Older
Adrien Matta's avatar
Adrien Matta committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#ifndef TSAMURAIFDC2PHYSICS_H
#define TSAMURAIFDC2PHYSICS_H
/*****************************************************************************
 * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
 *                                                                           *
 * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
 * For the list of contributors see $NPTOOL/Licence/Contributors             *
 *****************************************************************************/

/*****************************************************************************
 * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
 *                                                                           *
 * Creation Date  : October 2020                                             *
 * Last update    :                                                          *
 *---------------------------------------------------------------------------*
 * Decription:                                                               *
 *  This class hold SamuraiFDC2 treated data                                 *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * Comment:                                                                  *
 *                                                                           *  
 *                                                                           *
 *                                                                           *
 *****************************************************************************/
// STL
#include <vector>
Adrien Matta's avatar
Adrien Matta committed
27
#include <map>
Adrien Matta's avatar
Adrien Matta committed
28 29 30 31 32 33 34

// NPL
#include "TSamuraiFDC2Data.h"
//#include "TSamuraiFDC2Spectra.h"
#include "NPCalibrationManager.h"
#include "NPVDetector.h"
#include "NPInputParser.h"
Adrien Matta's avatar
Adrien Matta committed
35
#include "NPXmlParser.h"
Adrien Matta's avatar
Adrien Matta committed
36 37 38 39 40 41 42 43 44 45 46
// ROOT 
#include "TVector2.h" 
#include "TVector3.h" 
#include "TObject.h"
#include "TCanvas.h"
#include "TRandom3.h"
// Forward declaration
//class TSamuraiFDC2Spectra;


using namespace std ;
Adrien Matta's avatar
Adrien Matta committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
// little class to index each of the DC wire
class SamuraiDCIndex{
  public:
   SamuraiDCIndex(){};  
   ~SamuraiDCIndex(){};  
   SamuraiDCIndex(unsigned int det, unsigned int layer, unsigned int wire){
     m_det=det;
     m_layer=layer;
     m_wire=wire;
     m_norme=Norme();
   };  
  
  unsigned int m_det;
  unsigned int m_layer;
  unsigned int m_wire;
  unsigned int m_norme;
    
  int Norme() const {return (m_det*1000000000+m_layer*1000000+m_wire);} ;
  bool operator<(const SamuraiDCIndex i2){
    return this->Norme()<i2.Norme();
    }
  
  friend bool operator<(const SamuraiDCIndex i1,const SamuraiDCIndex i2){
    return i1.Norme()<i2.Norme();
    }
  
  friend bool operator==(const SamuraiDCIndex i1,const SamuraiDCIndex i2){
   return i1.Norme()==i2.Norme();
   }
  };

Adrien Matta's avatar
Adrien Matta committed
78 79 80 81 82 83 84 85 86 87 88 89

class TSamuraiFDC2Physics : public TObject, public NPL::VDetector{
  public:
    TSamuraiFDC2Physics();
    ~TSamuraiFDC2Physics() {};

  public: 
    void Clear();   
    void Clear(const Option_t*) {};

  public:
    //   Provide Physical Multiplicity
Adrien Matta's avatar
Adrien Matta committed
90
    vector<double> DriftLength;
Adrien Matta's avatar
Adrien Matta committed
91 92 93 94 95
    vector<int> Detector;
    vector<int> Layer;
    vector<int> Wire;
    vector<double> Time;
    vector<double> ToT;
Adrien Matta's avatar
Adrien Matta committed
96
    vector<bool>   Matched;
Adrien Matta's avatar
Adrien Matta committed
97 98 99 100
    // Computed variable
    vector<TVector3> ParticleDirection;
    vector<TVector3> MiddlePosition;

Adrien Matta's avatar
Adrien Matta committed
101
    double PosX;
Adrien Matta's avatar
Adrien Matta committed
102 103
    double PosY;
    int Mult;
Adrien Matta's avatar
Adrien Matta committed
104 105 106 107
  public:
    // Projected position at given Z plan
    TVector3 ProjectedPosition(double Z);

Adrien Matta's avatar
Adrien Matta committed
108 109 110 111 112 113 114 115 116 117
  private: // Charateristic of the DC 
    void AddDC(string name, NPL::XmlParser&);//! take the XML file and fill in Wire_X and Layer_Angle
    map<SamuraiDCIndex,double> Wire_X;//! X position of the wires
    map<SamuraiDCIndex,double> Wire_Z;//! Z position of the wires
    map<SamuraiDCIndex,double> Wire_T;//! Wire Angle (0 for X, 90 for Y, U and V are typically at +/-30)
  
  private: // Analysis
    double ToTThreshold;//! a ToT threshold to remove noise
    void RemoveNoise();
    // Construct the 2D track and ref position at Z=0 based on X,Z and Radius provided
118
    void Track2D(const vector<double>& X,const vector<double>& Z,const vector<double>& R,double& dirX, double& dirZ,double& refX );
Adrien Matta's avatar
Adrien Matta committed
119 120
    // Compute X and Y of interaction point based on drift vector of two different wire plane
    void ResolvePlane(const TVector3& PosU,const double& ThetaU ,const TVector3& PosV, const double& ThetaV, TVector3& PosXY);
Adrien Matta's avatar
Adrien Matta committed
121 122 123 124
    double SumD(const double* parameter );
    vector<double> fitX;
    vector<double> fitZ;
    vector<double> fitR;
Adrien Matta's avatar
Adrien Matta committed
125

Adrien Matta's avatar
Adrien Matta committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
  public: //   Innherited from VDetector Class

    // Read stream at ConfigFile to pick-up parameters of detector (Position,...) using Token
    void ReadConfiguration(NPL::InputParser) ;


    // 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
    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();
    // Write Spectra to file
    void WriteSpectra();

  public:      //   Specific to SamuraiFDC2 Array

    //   Clear The PreTeated object
    void ClearPreTreatedData()   {m_PreTreatedData->Clear();}

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

    // Retrieve raw and pre-treated data
    TSamuraiFDC2Data* GetRawData()        const {return m_EventData;}
    TSamuraiFDC2Data* GetPreTreatedData() const {return m_PreTreatedData;}

  private:   //   Root Input and Output tree classes
    TSamuraiFDC2Data*         m_EventData;//!
    TSamuraiFDC2Data*         m_PreTreatedData;//!
    TSamuraiFDC2Physics*      m_EventPhysics;//!


  private: // Spectra Class
   // TSamuraiFDC2Spectra* m_Spectra; // !

  public: // Spectra Getter
    map< string , TH1*> GetSpectra(); 

  public: // Static constructor to be passed to the Detector Factory
    static NPL::VDetector* Construct();
    ClassDef(TSamuraiFDC2Physics,1)  // SamuraiFDC2Physics structure
};

#endif