BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcRecSplitWeighted.cxx
Go to the documentation of this file.
1//
2// Spliter
3// Simple weighted method
4//
5// Zhe Wang 2004, 8, 31
6//
7#include <iostream>
8
9#include "EmcRec/EmcRecSplitWeighted.h"
10#include "EmcRec/EmcRecShowerEnergy.h"
11#include "EmcRec/EmcRecShowerPosLin.h"
12#include "EmcRec/EmcRecShowerPosLog.h"
13#include "EmcRec/EmcRecShowerPosLoglin.h"
14#include "EmcRec/EmcRecShowerPosLinShMax.h"
15#include "EmcRec/EmcRecShowerPosLogShMax.h"
16#include "EmcRec/EmcRecShowerShape.h"
17#include "EmcRec/EmcRecParameter.h"
18#include "EmcRecGeoSvc/EmcRecGeoSvc.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/ISvcLocator.h"
21
22// Constructors and destructors
24{
27
29// if(Para.PositionMode1()=="lin") {
30// fShowerPos=new EmcRecShowerPosLin;
31// } else {
32// fShowerPos=new EmcRecShowerPosLog;
33// }
34
35 if(Para.PositionMode1()=="lin") {
37 } else if(Para.PositionMode1()=="log"){
39 } else if(Para.PositionMode1()=="loglin"){
41 } else if(Para.PositionMode1()=="linsh"){
43 } else if(Para.PositionMode1()=="logsh"){
45 }
46
47}
48
49
51{
52 delete fShowerE;
53 delete fShowerPos;
54 delete fShowerShape;
55}
56
58 const RecEmcIDVector& aMaxVec,
59 RecEmcShowerMap& aShowerMap)
60{
61 //A exponential function will be used to describe the shape of a shower.
62 //Energy fall off with distance from centre of shower is exp(-a*dist/r)
63 //dist: distance from center
64 //r: moliere radius
65 //a: a parameter, needed to be optimised
67
68 //Calculate the cut of second moment
69 double eCluster=aCluster.getEnergy();
70 double cut=0;
71 if(eCluster>Para.SmCut(3)) {
72 cut=Para.SmCut(0)*exp(-(eCluster)/Para.SmCut(1))+Para.SmCut(2);
73 } else {
74 cut=Para.SmCut(0)*exp(-(Para.SmCut(3))/Para.SmCut(1))+Para.SmCut(2); //constant
75 }
76 cut/=10;
77
78 RecEmcShower aShower;
79 RecEmcHit aHit;
80 RecEmcFraction aFraction;
81 RecEmcHitMap::const_iterator ciHitMap;
82 if(aMaxVec.size()==0) {
83 // the cluster is abandoned
84 }
85
86 // only one seed or second moment belows cut
87 else if(aMaxVec.size()==1||aMaxVec.size()>20||aCluster.getSecondMoment()<cut) {
88 aShower.Clear();
89 aShower.setStatus(1);
90 // ID
91 aShower.ShowerId(aMaxVec[0]);
92 aShower.ClusterId(aCluster.getClusterId());
93 aCluster.InsertShowerId(aMaxVec[0]);
94 // each fraction
95 double time=aCluster.Find(aMaxVec[0])->second.getTime();
96 if(time>=Para.TimeMin()&&time<=Para.TimeMax()) {
97 for(ciHitMap=aCluster.Begin();
98 ciHitMap!=aCluster.End();
99 ++ciHitMap) {
100 aHit=ciHitMap->second;
101 //if((aHit.time()>=Para.TimeMin()) &&
102 //(aHit.time()<=Para.TimeMax())){
103 aFraction=aHit;
104 aFraction.Fraction(1);
105 aShower.Insert(aFraction);
106 //}
107 }
108
109 aShower.setTime(time);
110 fShowerE->Energy(aShower);
111 fShowerPos->Position(aShower);
113 aShower.ThetaGap(9);
114 aShower.PhiGap(9);
115 // push it into map
116 aShowerMap[aMaxVec[0]]=aShower;
117 }
118 }
119
120
121 // two or more seeds and second moment beyonds cut
122 else if(aMaxVec.size()>1&&aMaxVec.size()<=20&&aCluster.getSecondMoment()>cut) {
123 //cout<<"In EmcRecSplitWeighted: ";
124 //cout<<aMaxVec.size();
125 //cout<<" seeds in a cluster"<<endl;
126
127 RecEmcCluster tmpCluster=aCluster;
128 RecEmcHitMap::const_iterator ci_HitMap;
129 ci_RecEmcIDVector ciMax, ciMax1;;
130 RecEmcShower aShower;
131 RecEmcShowerMap tmpShowerMap;
132 RecEmcShowerMap::iterator i_ShowerMap,i2_ShowerMap;
133
134 RecEmcFraction aFrac;
135 unsigned int iterations=0; //iteration time
136 double centroidShift; //center shift between 2 iterations
137 map<RecEmcID,HepPoint3D,less<RecEmcID> > showerCentroid; //shower center
138 map<RecEmcID,HepPoint3D,less<RecEmcID> >::const_iterator ci_showerCentroid;
139
140 IEmcRecGeoSvc* iGeoSvc;
141 ISvcLocator* svcLocator = Gaudi::svcLocator();
142 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
143 if(sc!=StatusCode::SUCCESS) {
144 //cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
145 }
146
147 //Preparation
148 for(ciMax=aMaxVec.begin();
149 ciMax!=aMaxVec.end();
150 ++ciMax) {
151 //initialize: seed's front center
152 showerCentroid[*ciMax]=iGeoSvc->GetCFrontCenter(*ciMax);
153 }
154 do {
155 centroidShift=0.;
156 tmpShowerMap.clear();
157 for(ciMax=aMaxVec.begin();
158 ciMax!=aMaxVec.end();
159 ++ciMax) {
160 double weightTotal=0.,weight=0.;
161
162 aShower.Clear();
163 aShower.ShowerId(*ciMax);
164
165 // figure out the weight for each cell for each seed
166 for(ci_HitMap=tmpCluster.Begin();
167 ci_HitMap!=tmpCluster.End();
168 ++ci_HitMap) {
169
170 aFrac=ci_HitMap->second;
171 double aDistance=0;
172 RecEmcEnergy aESeed=0;
173
174 bool isSeed=false;
175 for(ciMax1=aMaxVec.begin();
176 ciMax1!=aMaxVec.end();
177 ++ciMax1) {
178 HepPoint3D seedPoint(showerCentroid[*ciMax1]);
179 HepPoint3D hitPoint(iGeoSvc->GetCFrontCenter(aFrac.getCellId()));
180
181 RecEmcEnergy theESeed=tmpCluster.Find(*ciMax1)->second.getEnergy();
182 double theDistance;
183 if(*ciMax1==aFrac.getCellId()) {
184 isSeed=true;
185 theDistance=0.;
186 } else {
187 theDistance=(hitPoint-seedPoint).mag();
188 }
189
190 if(*ciMax1==*ciMax) {
191 aDistance=theDistance;
192 aESeed=theESeed;
193 }
194
195 weightTotal+=theESeed*exp(-Para.LateralProfile()*theDistance/Para.MoliereRadius());
196 }
197
198 weight=aESeed*exp(-Para.LateralProfile()*aDistance/Para.MoliereRadius())/weightTotal;
199 aFrac.Fraction(weight);
200 //if((aFrac.time()>=Para.TimeMin() &&
201 //aFrac.time()<=Para.TimeMax()) ||
202 //isSeed) {
203 if(aFrac.getEnergy()*aFrac.getFraction()>Para.ElectronicsNoiseLevel()) {
204 aShower.Insert(aFrac);
205 }
206 //}
207 weightTotal=0;
208 }
209
210 fShowerE->Energy(aShower);
211 fShowerPos->Position(aShower);
212 HepPoint3D newCentroid(aShower.position());
213 HepPoint3D oldCentroid(showerCentroid[*ciMax]);
214 centroidShift+=(newCentroid-oldCentroid).mag();
215 tmpShowerMap[aShower.getShowerId()]=aShower;
216 showerCentroid[*ciMax]=newCentroid;
217 }
218
219 centroidShift/=(double)aMaxVec.size();
220 for(ci_showerCentroid=showerCentroid.begin();
221 ci_showerCentroid!=showerCentroid.end();
222 ci_showerCentroid++){
223 showerCentroid[ci_showerCentroid->first]
224 =tmpShowerMap[ci_showerCentroid->first].position();
225 }
226 iterations++;
227 //cout<<"iterations: "<<iterations<<"\tcentroidShift: "<<centroidShift<<endl;
228 }
229 while((iterations<8)&&(centroidShift>0.01));
230
231 unsigned int tht,phi;
232 unsigned int tht2,phi2;
233 unsigned int dtht,dphi;
234 unsigned int thetagap=0,phigap=0;
235 double distmin,dist;
236 RecEmcID id,id2,nearest;
237 // shower attributes
238 for(i_ShowerMap=tmpShowerMap.begin();
239 i_ShowerMap!=tmpShowerMap.end();
240 ++i_ShowerMap) {
241 aCluster.InsertShowerId(i_ShowerMap->second.getShowerId());
242 i_ShowerMap->second.ClusterId(aCluster.getClusterId());
243 i_ShowerMap->second.setStatus(2);
244 fShowerE->Energy(i_ShowerMap->second);
245 fShowerPos->Position(i_ShowerMap->second);
246 fShowerShape->CalculateMoment(i_ShowerMap->second);
247 //
248 // min theta, phi gap
249 id=(i_ShowerMap->second).getShowerId();
250 tht=EmcID::theta_module(id);
251 phi=EmcID::phi_module(id);
252 distmin=999999;
253 for(i2_ShowerMap=tmpShowerMap.begin();
254 i2_ShowerMap!=tmpShowerMap.end();
255 ++i2_ShowerMap) {
256 id2=(i2_ShowerMap->second).getShowerId();
257 tht2=EmcID::theta_module(id2);
259 if(id!=id2) {
260 dtht=tht>tht2 ? tht-tht2 : tht2-tht;
261 dphi=phi>phi2 ? phi-phi2 : phi2-phi;
262 if(dphi>(EmcID::getPHI_BARREL_MAX()+1)/2) dphi=EmcID::getPHI_BARREL_MAX()+1-dphi;
263 dist=sqrt(double(dtht*dtht+dphi*dphi));
264 if(dist<distmin) {
265 distmin=dist;
266 nearest=id2;
267 if(dtht>6) dtht=6;
268 if(dphi>6) dphi=6;
269 thetagap=dtht;
270 phigap=dphi;
271 }
272 }
273 }
274 //cout<<"+++++"<<id<<" "<<thetagap<<" "<<phigap<<endl;
275 i_ShowerMap->second.NearestSeed(nearest);
276 i_ShowerMap->second.ThetaGap(thetagap);
277 i_ShowerMap->second.PhiGap(phigap);
278
279 // save it
280 double time=
281 i_ShowerMap->second.Find(i_ShowerMap->second.getShowerId())->second.getTime();
282 if(time>=Para.TimeMin() && time<=Para.TimeMax() &&
283 (i_ShowerMap->second.getEAll()>Para.EThresholdCluster())) {
284 i_ShowerMap->second.setTime(time);
285 aShowerMap[i_ShowerMap->first]=i_ShowerMap->second;
286 }
287 }
288 tmpShowerMap.clear();
289 }
290
291}
Double_t phi2
Double_t time
map< RecEmcID, RecEmcShower, less< RecEmcID > > RecEmcShowerMap
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
Definition: KarFin.h:34
static unsigned int getPHI_BARREL_MAX()
Definition: EmcID.cxx:107
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
static EmcRecParameter & GetInstance()
double EThresholdCluster() const
double ElectronicsNoiseLevel() const
double LateralProfile() const
double TimeMax() const
double MoliereRadius() const
double TimeMin() const
double SmCut(int n) const
void Energy(RecEmcShower &aShower)
virtual void Position(RecEmcShower &aShower)=0
void CalculateMoment(RecEmcShower &aShower) const
virtual void Split(RecEmcCluster &aCluster, const RecEmcIDVector &aMaxVec, RecEmcShowerMap &aShowerMap)
virtual HepPoint3D GetCFrontCenter(const Identifier &id) const =0
RecEmcEnergy getEnergy() const
RecEmcHitMap::const_iterator Find(const RecEmcID &CellId) const
double getSecondMoment() const
RecEmcHitMap::const_iterator Begin() const
RecEmcHitMap::const_iterator End() const
void InsertShowerId(const RecEmcID id)
RecEmcFrac Fraction(const RecEmcFrac &Fraction)
RecEmcFrac getFraction() const
void ClusterId(const RecEmcID id)
RecEmcID ShowerId(RecEmcID id)
int ThetaGap() const
void Insert(const RecEmcFraction &aFraction)
int PhiGap() const
Char_t cut[200]
Definition: eff.cxx:63