SND@LHC Software
Loading...
Searching...
No Matches
ecalLightMap.cxx
Go to the documentation of this file.
1#include "ecalLightMap.h"
2
3#include "TSystem.h"
4
5#include <iostream>
6#include <fstream>
7#include <string>
8#include <list>
9#include <stdlib.h>
10
11using namespace std;
12
13ecalLightMap::ecalLightMap(const char* fname, const char* title)
14 : TNamed(fname, title),
15 fSSide(-1111.), fS(-1111), fSize(0), fData(NULL)
16{
17 Init(fname);
18}
19
21void ecalLightMap::Init(const char* filename)
22{
23 TString fn=filename;
24 gSystem->ExpandPathName(fn);
25 ifstream f(fn);
26 list<Double_t> lst;
27 string buf;
28 string token;
29 string message;
30 if (!f)
31 {
32 Fatal("Init","Can't open file %s.", filename);
33 return;
34 }
35
36 while(getline(f, buf))
37 {
38 if (buf.empty()) continue;
39 if (buf.find_first_not_of(" ")==string::npos) continue;
40 //Skipping initial spaces
41 message=buf.substr(buf.find_first_not_of(" "));
42 if (message.empty()) continue;
43 //Removing comments
44 message=message.substr(0,message.find("#"));
45 if (message.empty()) continue;
46 while(!message.empty())
47 {
48 token=message.substr(0,message.find_first_of(" "));
49 if (token.empty()) break;
50 lst.push_back(atof(token.c_str()));
51 if (token==message) break;
52 token=message.substr(message.find_first_of(" "));
53 if (token.empty()) break;
54 if (token.find_first_not_of(" ")==string::npos) break;
55 message=token.substr(token.find_first_not_of(" "));
56 }
57 }
58 f.close();
59
60 list<Double_t>::const_iterator p=lst.begin();
61 Double_t xsize;
62 Double_t ysize;
63 Double_t sqside;
64 Double_t l;
65 Double_t x;
66 Double_t y;
67 Double_t z;
68 Double_t v;
69 Int_t n;
70 Int_t i;
71
72 xsize=(*p); ++p; ysize=(*p); ++p; sqside=(*p); ++p;
73 fS=(Int_t)((xsize+0.00001)/sqside);
74 fSize=fS*fS; fSSide=sqside/xsize;
75 fData=new Double_t[fSize];
76 for(i=0;i<fSize;i++)
77 fData[i]=-1111;
78 for(;;)
79 {
80 if (p==lst.end()) break; l=(*p); ++p;
81 if (p==lst.end()) break; x=(*p); ++p;
82 if (p==lst.end()) break; y=(*p); ++p;
83 if (p==lst.end()) break; z=(*p); ++p;
84 if (p==lst.end()) break; v=(*p); ++p;
85 x/=xsize; y/=ysize;
86 n=GetNum(x ,y);
87 if (n>=fSize)
88 {
89 Info("Init","Data is not selfconsistent (%f, %f), %d", x, y, fSize);
90 }
91 fData[n]=v;
92 }
93 lst.clear();
94 FillGaps();
95 Normalize();
96}
97
100{
101 Int_t i;
102 Int_t j;
103 Double_t x;
104 Double_t y;
105 Int_t n[3];
106 Double_t v;
107 Int_t d;
108
109 for(i=0;i<fSize;i++)
110 if (fData[i]<0)
111 {
112 x=(i%fS)*fSSide-0.5+fSSide/2.0;
113 y=(i/fS)*fSSide-0.5+fSSide/2.0;
114 n[0]=GetNum( x,-y);
115 n[1]=GetNum(-x, y);
116 n[2]=GetNum(-x,-y);
117 v=0; d=0;
118 for(j=0;j<3;j++)
119 if (n[j]>=0&&fData[n[j]]>=0)
120 { d++; v+=fData[n[j]]; }
121 if (d>0)
122 {
123 v/=d; fData[i]=v;
124 if (fData[n[0]]<=0) fData[n[0]]=v;
125 if (fData[n[1]]<=0) fData[n[1]]=v;
126 if (fData[n[2]]<=0) fData[n[2]]=v;
127 }
128 else
129 Info("FillGaps","No data for (%f,%f)", x, y);
130 }
131}
132
135{
136 Int_t i;
137 Int_t n=0;
138 Double_t v=0;
139 for(i=0;i<fSize;i++)
140 if (fData[i]>0)
141 { v+=fData[i]; n++; }
142 v/=n;
143 for(i=0;i<fSize;i++)
144 if (fData[i]>0)
145 fData[i]/=v;
146}
147
Int_t GetNum(Double_t x, Double_t y)
void Init(const char *filename)
Double_t fSSide
Double_t * fData
ClassImp(ecalContFact) ecalContFact