SND@LHC Software
Loading...
Searching...
No Matches
ecalReco.cxx
Go to the documentation of this file.
1#include "ecalReco.h"
2
3#include "ecalCell.h"
4#include "ecalCluster.h"
5#include "ecalStructure.h"
7#include "ecalReconstructed.h"
8
9#include "TClonesArray.h"
10
11#include <iostream>
12#include <list>
13
14using namespace std;
15
16void ecalReco::Exec(Option_t* option)
17{
18 fEv++; fN=0; fRejected=0; fRejectedP=0;
19// if (fVerbose>0) Info("Exec", "Event %d.", fEv);
20
21 fReconstucted->Delete();
22
23 Int_t i;
24 Int_t nc=fClusters->GetEntriesFast();
25 ecalCluster* cls;
27 Float_t x;
28 Float_t y;
29 ecalCell* maxs[40]; //maximums of the cluster
30 Float_t e3[40]; //energy in 3x3 area near the maximum
31 list<ecalCell*> lists[40]; //lists of 5x5-3x3 clusters near the maximum
32 Int_t n;
33 Int_t j;
34 Int_t k;
35 list<ecalCell*> cells;
36 list<ecalCell*> cells2;
37 list<ecalCell*>::const_iterator p;
38 list<ecalCell*>::const_iterator p2;
39 Float_t rawE;
40 Float_t ourE;
41 Float_t allE;
42 ecalCell* tcell;
43
44 for(i=0;i<nc;i++)
45 {
46 cls=(ecalCluster*)fClusters->At(i);
47 // Clusters with single maximum. Separate code for speedup
48 if (cls->Maxs()==1)
49 {
50 ReconstructXY(fStr->GetHitCell(cls->PeakNum(0)), x, y);
51 reco=new ((*fReconstucted)[fN++]) ecalReconstructed(cls->Energy(), cls->PreCalibrated(), x, y, cls->PeakNum(0), i);
52 cls->SetStatus(1);
53 continue;
54 }
55 TryReconstruct(cls, i);
56/*
57 //Multimaximum case
58 n=cls->Maxs();
59 for(j=0;j<n;j++)
60 {
61 maxs[j]=fStr->GetHitCell(cls->PeakNum(j));
62 e3[j]=maxs[j]->GetEnergy();
63 lists[j].clear();
64 maxs[j]->GetNeighborsList(cells);
65 for(p=cells.begin();p!=cells.end();++p)
66 {
67 e3[j]+=(*p)->GetEnergy();
68 for(k=0;k<j-1;k++)
69 {
70 tcell=fStr->GetHitCell(cls->PeakNum(k));
71 tcell->GetNeighborsList(cells2);
72 // Have an intersection between 3x3 areas near maximum
73 if (find(cells2.begin(), cells2.end(), *p)!=cells2.end()) break;
74 }
75 if (j!=0&&k!=j-1) break;
76
77 //form 5x5-3x3
78 (*p)->GetNeighborsList(cells2);
79 for(p2=cells2.begin();p2!=cells2.end();++p2)
80 {
81 if (*p2==maxs[j])
82 continue; //exclude maximum
83 if (find(cells.begin(), cells.end(), *p2)!=cells.end())
84 continue; //exclude 3x3 area
85 if (find(lists[j].begin(), lists[j].end(), *p2)==lists[j].end())
86 lists[j].push_back(*p2);
87 }
88 }
89 if (p!=cells.end()) break;
90 }
91 if (j!=n)
92 {
93 cls->SetStatus(-1);
94 fRejected++; fRejectedP+=cls->Maxs();
95 if (fVerbose>9)
96 Info("Exec", "Cluster %d with %d maximums rejected", i, n);
97 continue;
98 }
99 //Second pass. Reconstruction
100 for(j=0;j<n;j++)
101 {
102 ReconstructXY(maxs[j], x, y);
103 rawE=ourE=e3[j];
104 for(p=lists[j].begin();p!=lists[j].end();++p)
105 {
106 allE=ourE;
107 for(k=0;k<n;k++)
108 {
109 if (k==j) continue;
110 maxs[k]->Get5x5Cluster(cells2);
111 if (find(cells2.begin(), cells2.end(), *p)!=cells2.end()) allE+=e3[k];
112 }
113 rawE+=(*p)->GetEnergy()*ourE/allE;
114 }
115 reco=new ((*fReconstucted)[fN++]) ecalReconstructed(rawE, fCalib->Calibrate(maxs[j]->GetType(), rawE), x, y, cls->PeakNum(j), i);
116 }
117 cls->SetStatus(1);
118*/
119 }
120 if (fVerbose>0) Info("Exec", "Event %d. Good %d. Bad %d cls, %d maxs.", fEv, fN, fRejected, fRejectedP);
121}
122
123void ecalReco::TryReconstruct(ecalCluster* cls, Int_t clsnum)
124{
125 Int_t n=cls->Maxs();
126 Int_t i;
127 Int_t k;
128 ecalCell* maxs[40]; //maximums of the cluster
129 Float_t e3[40]; //energy in 3x3 area near the maximum
130 list<ecalCell*> lists[40]; //lists of 5x5-3x3 areas near maximum
131 Int_t isgood[40]; //good maximum (no intersection of 3x3 areas)
132 Int_t rejected=0;
133 list<ecalCell*> cells;
134 list<ecalCell*> cells2;
135 list<ecalCell*>::const_iterator p;
136 list<ecalCell*>::const_iterator p2;
137 ecalReconstructed* reco;
138 Float_t rawE;
139 Float_t ourE;
140 Float_t allE;
141 ecalCell* tcell;
142 Float_t x;
143 Float_t y;
144
145 for(i=0;i<n;i++)
146 {
147 maxs[i]=fStr->GetHitCell(cls->PeakNum(i));
148 e3[i]=maxs[i]->GetEnergy();
149 lists[i].clear();
150 isgood[i]=1;
151 maxs[i]->GetNeighborsList(cells);
152 for(p=cells.begin();p!=cells.end();++p)
153 {
154 e3[i]+=(*p)->GetEnergy();
155 for(k=0;k<i-1;k++)
156 {
157 tcell=fStr->GetHitCell(cls->PeakNum(k));
158 tcell->GetNeighborsList(cells2);
159 // Have an intersection between 3x3 areas near maximum
160 if (find(cells2.begin(), cells2.end(), *p)!=cells2.end()) isgood[i]--;
161 }
162 //form 5x5-3x3
163 (*p)->GetNeighborsList(cells2);
164 for(p2=cells2.begin();p2!=cells2.end();++p2)
165 {
166 if (*p2==maxs[i])
167 continue; //exclude maximum
168 if (find(cells.begin(), cells.end(), *p2)!=cells.end())
169 continue; //exclude 3x3 area
170 if (find(lists[i].begin(), lists[i].end(), *p2)==lists[i].end())
171 lists[i].push_back(*p2);
172 }
173 }
174 if (p!=cells.end()) break;
175 }
176
177 //Second pass. Reconstruction
178 for(i=0;i<n;i++)
179 {
180 if (isgood[i]!=1)
181 {
182 rejected++; fRejectedP++;
183 continue;
184 }
185 ReconstructXY(maxs[i], x, y);
186 rawE=ourE=e3[i];
187 for(p=lists[i].begin();p!=lists[i].end();++p)
188 {
189 allE=ourE;
190 for(k=0;k<n;k++)
191 {
192 if (k==i) continue;
193 maxs[k]->Get5x5Cluster(cells2);
194 if (find(cells2.begin(), cells2.end(), *p)!=cells2.end()) allE+=e3[k];
195 }
196 rawE+=(*p)->GetEnergy()*ourE/allE;
197 }
198 reco=new ((*fReconstucted)[fN++]) ecalReconstructed(rawE, fCalib->Calibrate(maxs[i]->GetType(), rawE), x, y, cls->PeakNum(i), clsnum);
199 }
200 cls->SetStatus(1);
201 if (rejected>0)
202 {
203 cls->SetStatus(-rejected);
204 fRejected++;
205 }
206}
207
208void ecalReco::ReconstructXY(ecalCell* max, Float_t& x, Float_t& y)
209{
210 // Now use just center of gravity
211 Float_t e=max->GetEnergy();
212 list<ecalCell*> cls;
213 list<ecalCell*>::const_iterator p;
214
215 x=max->GetCenterX()*max->GetEnergy();
216 y=max->GetCenterY()*max->GetEnergy();
217 max->GetNeighborsList(cls);
218 for(p=cls.begin();p!=cls.end();++p)
219 {
220 x+=(*p)->GetCenterX()*(*p)->GetEnergy();
221 y+=(*p)->GetCenterY()*(*p)->GetEnergy();
222 e+=(*p)->GetEnergy();
223 }
224 x/=e; y/=e;
225// cout << x << ", " << y << " : " << max->GetCenterX() << ", " << max->GetCenterY() << endl;
226}
227
229ecalReco::ecalReco(const char* name, const Int_t verbose)
230 : FairTask(name, verbose), fEv(0), fN(0), fRejected(0), fRejectedP(0),
231 fClusters(NULL), fReconstucted(NULL), fStr(NULL), fCalib(NULL)
232{
233 ;
234}
235
238 : FairTask(), fEv(-1111), fN(0), fRejected(0), fRejectedP(0),
239 fClusters(NULL), fReconstucted(NULL), fStr(NULL), fCalib(NULL)
240{
241 ;
242}
243
246{
247 ;
248}
249
252{
253 if (fReconstucted)
254 {
255 fReconstucted->Delete();
256 delete fReconstucted;
257 }
258}
259
260InitStatus ecalReco::Init()
261{
262 FairRootManager* io=FairRootManager::Instance();
263 if (!io)
264 {
265 Fatal("Init", "Can't find IOManager.");
266 return kFATAL;
267 }
268 fStr=(ecalStructure*)io->GetObject("EcalStructure");
269 if (!fStr)
270 {
271 Fatal("Init()", "Can't find calorimeter structure in the system.");
272 return kFATAL;
273 }
274 fCalib=(ecalClusterCalibration*)io->GetObject("ecalClusterCalibration");
275 if (!fCalib)
276 {
277 Fatal("Init", "Can't find ecalClusterCalibration in the system.");
278 return kFATAL;
279 }
280 fClusters=(TClonesArray*)io->GetObject("EcalClusters");
281 if (!fClusters)
282 {
283 Fatal("Init()", "Can't find calorimeter clusters in the system.");
284 return kFATAL;
285 }
286
287 fReconstucted=new TClonesArray("ecalReconstructed", 2000);
288 io->Register("EcalReco", "ECAL", fReconstucted, kTRUE);
289
290 fEv=0;
291 return kSUCCESS;
292}
293
294TClonesArray* ecalReco::InitPython(TClonesArray* clusters, ecalStructure* str, ecalClusterCalibration* calib)
295{
296 fStr=str;
297 fCalib=calib;
298 fClusters=clusters;
299 fReconstucted=new TClonesArray("ecalReconstructed", 2000);
300
301 fEv=0;
302 return fReconstucted;
303}
304
Char_t GetType() const
Definition ecalCell.h:26
void GetNeighborsList(std::list< ecalCell * > &neib) const
Definition ecalCell.h:48
void Get5x5Cluster(std::list< ecalCell * > &cls)
Definition ecalCell.h:58
Float_t GetEnergy() const
Definition ecalCell.h:42
Double_t Calibrate(Int_t celltype, Double_t energy)
Double_t PreCalibrated() const
Definition ecalCluster.h:41
Int_t Maxs() const
Definition ecalCluster.h:37
void SetStatus(Short_t st)
Definition ecalCluster.h:55
Double_t Energy() const
Definition ecalCluster.h:39
Int_t PeakNum(Int_t i) const
Definition ecalCluster.h:59
virtual void Finish()
Definition ecalReco.cxx:245
Int_t fRejected
Definition ecalReco.h:41
ecalStructure * fStr
Definition ecalReco.h:50
void TryReconstruct(ecalCluster *cls, Int_t clsnum)
Definition ecalReco.cxx:123
void ReconstructXY(ecalCell *max, Float_t &x, Float_t &y)
Definition ecalReco.cxx:208
TClonesArray * InitPython(TClonesArray *clusters, ecalStructure *str, ecalClusterCalibration *calib)
Definition ecalReco.cxx:294
Int_t fRejectedP
Definition ecalReco.h:43
TClonesArray * fClusters
Definition ecalReco.h:46
virtual void Exec(Option_t *option)
Definition ecalReco.cxx:16
ecalClusterCalibration * fCalib
Definition ecalReco.h:52
TClonesArray * fReconstucted
Definition ecalReco.h:48
virtual InitStatus Init()
Definition ecalReco.cxx:260
Int_t fEv
Definition ecalReco.h:37
Int_t fN
Definition ecalReco.h:39
ecalCell * GetHitCell(const Int_t hitId) const
ClassImp(ecalContFact) ecalContFact