StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsClusterFitter.h
Go to the documentation of this file.
1 // $Id: StFmsClusterFitter.h,v 1.11 2020/08/05 16:17:23 akio Exp $
2 //
3 // $Log: StFmsClusterFitter.h,v $
4 // Revision 1.11 2020/08/05 16:17:23 akio
5 // Avoid floating point exception (from Yuri)
6 //
7 // Revision 1.10 2019/06/26 16:49:53 akio
8 // shower shape scaling for all shapes
9 //
10 // Revision 1.9 2018/03/02 20:27:29 akio
11 // Big update from Zhanwen Zhu with new shower shape and six z slices
12 //
13 // Revision 1.8 2016/06/07 15:51:44 akio
14 // Making code better based on Coverity reports
15 //
16 // Revision 1.7 2015/11/05 17:54:57 akio
17 // Adding option to scale up shower shape function for large cells
18 //
19 // Revision 1.6 2015/10/30 21:33:56 akio
20 // fix parameter initialization
21 // adding new cluster categorization method
22 //
23 // Revision 1.5 2015/10/29 21:14:55 akio
24 // increase max number of clusters
25 // a bug fixes in valley tower association
26 // removing some debug comments
27 //
28 // Revision 1.4 2015/10/23 15:05:07 akio
29 // fixed constexpr
30 //
31 // Revision 1.3 2015/10/21 15:58:04 akio
32 // Code speed up (~x2) by optimizing minimization fuctions and showershape function
33 // Add option to merge small cells to large, so that it finds cluster at border
34 // Add option to perform 1photon fit when 2photon fit faield
35 // Add option to turn on/off global refit
36 // Moment analysis done without ECUTOFF when no tower in cluster exceed ECUTOFF=0.5GeV
37 //
38 // Revision 1.2 2015/09/02 15:01:32 akio
39 // Removing StFmsGeometry class, and now it uses StFmsDbMaker to get appropriate parameters.
40 //
41 // Revision 1.1 2015/03/10 14:38:53 jeromel
42 // First version of FmsUtil from Yuxi Pan - reviewd 2015/02
43 //
53 #ifndef STROOT_STFMSPOINTMAKER_STFMSCLUSTERFITTER_H_
54 #define STROOT_STFMSPOINTMAKER_STFMSCLUSTERFITTER_H_
55 
56 #ifndef __CINT__ // Hide std::array from CINT, as CINT cannot parse C++11
57 #include <array>
58 #endif // __CINT__
59 #include <list>
60 #include <vector>
61 
62 #include "TMinuit.h"
63 #include "TObject.h"
64 
65 #include "StFmsFittedPhoton.h"
66 #include "StFmsTowerCluster.h"
67 
68 class TF2;
69 class TString;
70 
71 namespace FMSCluster { // $NMSPC
72 typedef std::list<StFmsFittedPhoton> PhotonList;
73  //class StFmsGeometry;
74 class StFmsTower;
95 class StFmsClusterFitter : public TObject {
96  public:
98  StFmsClusterFitter(/*const StFmsGeometry* geometry,*/ Int_t detectorId, Float_t xw, Float_t yw,
99  Float_t scaleShowerShapeLarge , Float_t scaleShowerShapeSmall,
100  Int_t ShowerShapeWithAngle , Int_t MergeSmallToLarge, double vertexZ);
108  virtual ~StFmsClusterFitter();
115  TF2* showerShapeFunction();
117  void setTowers(StFmsTowerCluster::Towers* towers);
135  Double_t fitNPhoton(const std::vector<double>& parameteres,
136  const std::vector<double>& steps,
137  const std::vector<double>& lower,
138  const std::vector<double>& up,
139  PhotonList* photons);
141  Double_t fitNPhoton(const std::vector<double>& parameters,
142  const std::vector<double>& lower,
143  const std::vector<double>& up,
144  PhotonList* photons);
162 #ifndef __CINT__ // Hide std::array from CINT, as CINT cannot parse C++11
163  Int_t fit2Photon(const std::array<double, 7>& parameters,
164  const std::array<double, 7>& steps,
165  const std::array<double, 7>& lower,
166  const std::array<double, 7>& upper,
167  PhotonList* photons);
168 #endif // __CINT__
169 
183  static inline Double_t energyDepositionInTowerOLD(Double_t x, Double_t y, Double_t* par);
184 
188  static Double_t energyDepositionInTower(Double_t* x, Double_t* par);
189  static inline Double_t energyDepositionInTower(Double_t x, Double_t y,Double_t xun, Double_t yun, Double_t* parmeters,Int_t MergeSmallToLarge,double vertexz);
190  static inline Double_t energyDepositionInTowerSingleLayer(Double_t x, Double_t y, Double_t* parameters);
191 
193  static int maxNFittedPhotons();
194 
195  private:
199  StFmsClusterFitter& operator=(const StFmsClusterFitter&);
208  int runMinuitMinimization();
219  static inline Double_t energyDepositionDistribution(Double_t x, Double_t y, Double_t* par);
220  static Double_t energyDepositionDistribution(Double_t* x, Double_t* par);
230  static void minimizationFunctionNPhoton(Int_t& npar, Double_t* grad,
231  Double_t& fval, Double_t* par,
232  Int_t iflag);
238  static void minimizationFunction2Photon(Int_t& nparam, Double_t* grad,
239  Double_t& fval, Double_t* param,
240  Int_t iflag);
249  template<class Container>
250  int setMinuitParameter(int index, const TString& name,
251  const Container& parameters,
252  const Container& steps,
253  const Container& lower,
254  const Container& upper);
263  int readMinuitParameters(std::vector<double>& parameters,
264  std::vector<double>& errors);
265  TMinuit mMinuit;
266  static StFmsTowerCluster::Towers* mTowers;
267  static Double_t mEnergySum;
268  Float_t mScaleShowerShapeLarge=1.0;
269  Float_t mScaleShowerShapeSmall=1.0;
270  Int_t mShowerShapeWithAngle;
271  Int_t mMergeSmallToLarge;
272 
273 
274  ClassDef(StFmsClusterFitter, 0)
275 }; // class StFmsClusterFitter
276 
277 inline double asmsqrt(double x) { //slower than std::sqrt()
278  __asm__ ("fsqrt" : "+t" (x));
279  return x;
280 }
281 
282 // Returns a * f(x,y,b) as defined here:
283 // https://drupal.star.bnl.gov/STAR/blog/leun/2010/aug/02/fms-meeting-20100802
284 inline double showerShapeComponent(double x, double y, double a, double b) {
285  if (a == 0.0 || b == 0.0) return 0.0;
286  return a * atan(x * y / (b * sqrt(b * b + x * x + y * y)));
287 }
288 
289 inline Double_t StFmsClusterFitter::energyDepositionDistribution(double x, double y, double* parameters){
290  constexpr double ootwopi = 1.0/2.0/3.14159265358979323846;
291  return ( showerShapeComponent(x, y, parameters[1], parameters[4])
292  + showerShapeComponent(x, y, parameters[2], parameters[5])
293  + showerShapeComponent(x, y, parameters[3], parameters[6]) ) * ootwopi;
294 }
295 
296 inline Double_t StFmsClusterFitter::energyDepositionInTowerOLD(Double_t x, Double_t y, Double_t* parameters){
297  //old version without incident angle effect
298  const double w = parameters[0]/2.0;
299  return energyDepositionDistribution(x-w,y-w,parameters)
300  - energyDepositionDistribution(x-w,y+w,parameters)
301  - energyDepositionDistribution(x+w,y-w,parameters)
302  + energyDepositionDistribution(x+w,y+w,parameters);
303 }
304 
305 //x,y are cell position, and xun,yun are photon position, in cell coordinate at Z=ZMAX
306 inline Double_t StFmsClusterFitter::energyDepositionInTower(Double_t x, Double_t y,Double_t xun, Double_t yun,
307  Double_t* parameters,Int_t mMerge ,double vertexz){
308  //Double_t para[60];
309  Double_t *Zc;
310  Double_t ZcS[6] = {720.45,727.95,735.45,742.95,750.45,757.95};
311  Double_t ZcL[6] = {722.98,733.01,743.04,753.07,763.10,773.13};
312 
313  //for(Int_t i = 0; i < 60; i++){ para[i]=parameters[i]; }
314  Double_t Zmax,yoff,xoff;
315  if (parameters[0] > 4) {
316  yoff=98.8; Zmax=735.45; xoff=0.3; Zc=ZcL;
317  }else{
318  yoff=46.5; Zmax=735.45; xoff=0.93; Zc=ZcS;
319  }
320  if (mMerge>0) yoff=98.8;
321 
322  Double_t tanx = ( xun + xoff) / (Zmax-vertexz); //recalculate tanx and tany for each iteration
323  Double_t tany = ( yoff - yun) / (Zmax-vertexz); //use Zmax instead of lzz, 06/25/2012 Yuxi
324 
325  Double_t sum = 0.0;
326  for(Int_t i = 0; i < 6; i++){
327  Double_t xc = xun + tanx*(Zc[i] - Zmax);
328  Double_t yc = yun - tany*(Zc[i] - Zmax); //large (positive) tany corresponds to smaller row # (yc)
329  Int_t istart = i*10;
330  sum += ( energyDepositionInTowerSingleLayer(x-xc,y-yc,&parameters[istart]) * parameters[istart+7]) ;
331  }
332  return sum;
333 }
334 
335 inline Double_t StFmsClusterFitter::energyDepositionInTowerSingleLayer(Double_t x, Double_t y, Double_t* parameters){
336  const double w = parameters[0];
337  double ww1=0;
338  double ww2=0;
339  if (w < 4) {ww1=3.822/2; ww2=3.875/2; }
340  else {ww1=5.812/2; ww2=5.812/2; }
341 
342  return energyDepositionDistribution(x-ww1,y-ww2,parameters)
343  - energyDepositionDistribution(x-ww1,y+ww2,parameters)
344  - energyDepositionDistribution(x+ww1,y-ww2,parameters)
345  + energyDepositionDistribution(x+ww1,y+ww2,parameters);
346 }
347 
348 
349 } // namespace FMSCluster
350 #endif // STROOT_STFMSPOINTMAKER_STFMSCLUSTERFITTER_H_
Int_t fit2Photon(const std::array< double, 7 > &parameters, const std::array< double, 7 > &steps, const std::array< double, 7 > &lower, const std::array< double, 7 > &upper, PhotonList *photons)
static Double_t energyDepositionInTowerOLD(Double_t x, Double_t y, Double_t *par)
std::list< StFmsTower * > Towers
Shorthand for tower collection.
static Double_t energyDepositionInTower(Double_t *x, Double_t *par)
Declaration of StFmsTowerCluster, a cluster of FMS towers.
Double_t fitNPhoton(const std::vector< double > &parameteres, const std::vector< double > &steps, const std::vector< double > &lower, const std::vector< double > &up, PhotonList *photons)
void setTowers(StFmsTowerCluster::Towers *towers)
Declaration of StFmsFittedPhoton, a photon fitted to an FMS cluster.