Macros

Line Code
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 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
/** \class InvMatrixUtils

    \brief various utilities

*/

#ifndef InvMatrixUtils_h
#define InvMatrixUtils_h

#include <string>
#include <map>
#include "TObject.h"
#include "TF1.h"
#include "TH2.h"
#include "TProfile.h"
#include "TCanvas.h"
#include "CLHEP/Geometry/Point3D.h"
#include "CLHEP/Matrix/GenMatrix.h"
#include "CLHEP/Matrix/Matrix.h"
#include "CLHEP/Matrix/Vector.h"
#include "TFile.h"

//#include "ConfigParser.h"
#include "Calibration/Tools/interface/InvMatrixCommonDefs.h"

/** set the style for the printout*/
void setStyle();

/** search for an existing canvas with the name 
and returns the poiter to it */
TCanvas* getGlobalCanvas(std::string name = "Inv MatrixCanvas");

/** search for an existing TFile with the name 
and returns the poiter to it */
TFile* getGlobalTFile(std::string name = "Inv MatrixTFile.root");
//TFile * getGlobalTFile (const char* name) ;

/** search for an existing TFile with the name 
and saves it to disk with his name */
int saveGlobalTFile(std::string name = "Inv MatrixFile.root");

/** search for an existing calib matrix saved with the name 
and returns the poiter to it,
the deletion is responsiblity of the user */
CLHEP::HepMatrix* getSavedMatrix(const std::string& name);

/** return the impact position of the electron over ECAL */
HepGeom::Point3D<Float_t> TBposition(const Float_t amplit[7][7],
                                     const Float_t beamEne,
                                     const Float_t w0 = 4.0,
                                     const Float_t x0 = 8.9,  //mm
                                     const Float_t a0 = 6.2,
                                     const Float_t sideX = 24.06,   //mm
                                     const Float_t sideY = 22.02);  //mm

/** get the energy in the 5x5 
from the 7x7 array around the most energetic crystal*/
double get5x5(const Float_t energy[7][7]);

/** get the energy in the 3x3 
from the 7x7 array around the most energetic crystal*/
double get3x3(const Float_t energy[7][7]);

/**to get the parameters from a congiguration file*/
int parseConfigFile(const TString& config);

/**to get the crystal number from eta and phi*/
int xtalFromEtaPhi(const int& myEta, const int& myPhi);

/**to get the crystal number from iEta and iPhi
iEta runs from 1 to 85
iPhi runs from 1 to 20
*/
int xtalFromiEtaiPhi(const int& iEta, const int& iPhi);

/** get the eta coord [0,84] */
int etaFromXtal(const int& xtal);

/** get the phi coord [0,19] */
int phiFromXtal(const int& xtal);

/** get the eta coord [1,85] */
int ietaFromXtal(const int& xtal);

/** get the phi coord [1,20] */
int iphiFromXtal(const int& xtal);

/** to read a file containing unserted integers
while avoiding comment lines */
int extract(std::vector<int>* output, const std::string& dati);

/** to write the calibration constants file */
int writeCalibTxt(const CLHEP::HepMatrix& AmplitudeMatrix,
                  const CLHEP::HepMatrix& SigmaMatrix,
                  const CLHEP::HepMatrix& StatisticMatrix,
                  std::string fileName = "calibOutput.txt");

/** to write the file fpr the CMSSW in the DB compliant format (using Energy as reference)*/
int writeCMSSWCoeff(const CLHEP::HepMatrix& amplMatrix,
                    double calibThres,
                    float ERef,
                    const CLHEP::HepMatrix& sigmaMatrix,
                    const CLHEP::HepMatrix& statisticMatrix,
                    std::string fileName = "calibOutput.txt",
                    std::string genTag = "CAL_GENTAG",
                    std::string method = "CAL_METHOD",
                    std::string version = "CAL_VERSION",
                    std::string type = "CAL_TYPE");

/** to write the file fpr the CMSSW in the DB compliant format 
    (using Crystal as reference) */
int writeCMSSWCoeff(const CLHEP::HepMatrix& amplMatrix,
                    double calibThres,
                    int etaRef,
                    int phiRef,
                    const CLHEP::HepMatrix& sigmaMatrix,
                    const CLHEP::HepMatrix& statisticMatrix,
                    std::string fileName = "calibOutput.txt",
                    std::string genTag = "CAL_GENTAG",
                    std::string method = "CAL_METHOD",
                    std::string version = "CAL_VERSION",
                    std::string type = "CAL_TYPE");

/** translates the calib coefficients format,
    from the TB06Studies one to the CMSSSW one */
int translateCoeff(const CLHEP::HepMatrix& calibcoeff,
                   const CLHEP::HepMatrix& sigmaMatrix,
                   const CLHEP::HepMatrix& statisticMatrix,
                   std::string SMnumber = "1",
                   double calibThres = 0.01,
                   std::string fileName = "calibOutput.txt",
                   std::string genTag = "CAL_GENTAG",
                   std::string method = "CAL_METHOD",
                   std::string version = "CAL_VERSION",
                   std::string type = "CAL_TYPE");

/** translates the calib coefficients format,
    from the CMSSW one to the TB06Studies one */
int readCMSSWcoeff(CLHEP::HepMatrix& calibcoeff, const std::string& inputFileName, double defaultVal = 1.);

/** translates the calib coefficients format,
    from the CMSSW one to the TB06Studies one */
int readCMSSWcoeffForComparison(CLHEP::HepMatrix& calibcoeff, const std::string& inputFileName);

/** smart profiling by double averaging */
TH1D* smartProfile(TH2F* strip, double width);

/** smart profiling by fixing gaussian parameters and
    range from a first averaging */
TH1D* smartGausProfile(TH2F* strip, double width);

/**
   */
TH1D* smartError(TH1D* strip);

/**
find the effective sigma as the half width of the sub-distribution
containing 68.3% of the total distribution
*/
double effectiveSigma(TH1F& histogram, int vSteps = 100);

/**
find the support of the histogram above a threshold
return the min and max bins
*/
std::pair<int, int> findSupport(TH1F& histogram, double thres = 0.);

/** 
transfers a CLHEP matrix into a double array
with the size of a supermodule
*/
void mtrTransfer(double output[SCMaxEta][SCMaxPhi], CLHEP::HepMatrix* input, double Default);

/**
reset the matrices f the size of a supermodule
*/
template <class Type>
void mtrReset(Type superModules[SCMaxEta][SCMaxPhi], const Type val) {
  for (int e = 0; e < SCMaxEta; ++e)
    for (int p = 0; p < SCMaxPhi; ++p) {
      superModules[e][p] = val;
    }
}

/**
correction for eta containment for 3*3 cluster */
double etaCorrE1E9(int eta);
/**
correction for eta containment for 7*7 cluster */
double etaCorrE1E49(int eta);
/**
correction for eta containment for 5*5 cluster */
double etaCorrE1E25(int eta);

#endif