18 #include "TObjArray.h"
20 #include "Sti/StiKalmanTrackNode.h"
22 typedef std::map<std::string, int> myTallyMap_t;
23 typedef myTallyMap_t::const_iterator myTallyIter_t;
24 static myTallyMap_t mgTally;
27 int StiDebug::mgDebug=1;
28 int StiDebug::mgRecov=1;
29 int StiDebug::mgCheck=1;
31 typedef std::map<std::string, TH1*> myDebMap_t;
32 typedef myDebMap_t::const_iterator myDebIter_t;
33 static myDebMap_t myDebMap;
35 typedef std::map<std::string, TCanvas*> myCanMap_t;
36 typedef myCanMap_t::const_iterator myCanIter_t;
46 if (gROOT->IsBatch())
return;
49 int StiDebug::iFlag(
const char *flagName,
int dflt)
51 const char *val = gSystem->Getenv(flagName);
52 if (!val)
return dflt;
53 printf(
"\nStiDebug::iFlag: %s = %s\n\n",flagName,val);
59 double StiDebug::dFlag(
const char *flagName,
double dflt)
61 const char *val = gSystem->Getenv(flagName);
62 if (!val)
return dflt;
63 printf(
"\nStiDebug::dFlag: %s = %s\n\n",flagName,val);
68 void StiDebug::tally(
const char *name,
int val)
70 if (mgDebug<2)
return;
74 void StiDebug::Finish()
79 void StiDebug::Break(
int kase)
81 static int myBreak=-2005;
82 if (kase!=myBreak)
return;
84 printf(
"*** Break(%d) ***\n",kase);
87 void StiDebug::FpeOn()
89 gSystem->SetFPEMask(kInvalid | kDivByZero | kOverflow );
90 printf(
"*** Float Point Exception is ON ***\n");
102 static TCanvas *myCanvas=0;
103 static TGraph *graph[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
105 float X[3][3][100],Y[3][3][100];
108 if (!myCanvas) {myCanvas =
new TCanvas(
"C1",
"",600,800);
109 myCanvas->Divide(1,3);}
111 double curv = 0,xPrev=0,yPrev=0;
int nCurv = 0;
113 for (
int i=0;i<9;i++) {
delete graph[0][i];graph[0][i]=0;}
116 for (
int ig=0;ig<3;ig++) {
120 for (it=kt->
begin();it!=kt->
end();++it) {
122 if (!node->isValid())
continue;
124 double xNode = node->x_g();
125 double yNode = node->y_g();
127 double ds = sqrt(pow(xNode-xPrev,2)+pow(yNode-yPrev,2));
128 double si = 0.5*ds*curv;
if (si>0.99) si=0.99;
129 if (si>0.01) ds = 2*asin(si)/curv;
136 if (hit && node->getChi2()>1000) hit=0;
137 if (ig==2 && !hit)
continue;
138 if (ig==0) { curv += node->
getCurvature(); nCurv++;
continue;}
140 X[0][ig][n] = node->x_g();
141 Y[0][ig][n] = node->y_g();
142 Y[2][ig][n] = node->z_g();
144 X[0][ig][n] = hit->
x_g();
145 Y[0][ig][n] = hit->y_g();
146 Y[2][ig][n] = hit->z_g();
150 float xh = X[0][ig][n]-X[0][ig][0];
151 float yh = Y[0][ig][n]-Y[0][ig][0];
152 float rh = xh*xh+yh*yh+1E-10;
153 X[1][ig][n-1] = xh/rh;
154 Y[1][ig][n-1] = yh/rh;
159 if (ig==0) { curv=fabs(curv)/nCurv;
continue;}
165 for (
int ip=0;ip<3;ip++) {
166 double xMin=999,xMax=-999,yMin=999,yMax=-999;
167 for (
int ig=1;ig<3;ig++) {
168 for (
int j=0;j<N[ip][ig];j++) {
169 double x = X[ip][ig][j];
170 if (xMin> x) xMin = x;
171 if (xMax< x) xMax = x;
172 double y = Y[ip][ig][j];
173 if (yMin> y) yMin = y;
174 if (yMax< y) yMax = y;
177 X[ip][0][0] = xMin; Y[ip][0][0] = yMin;
178 X[ip][0][1] = xMin; Y[ip][0][1] = yMax;
179 X[ip][0][2] = xMax; Y[ip][0][2] = yMin;
180 X[ip][0][3] = xMax; Y[ip][0][3] = yMax;
183 static const char *opt[]={
"AP",
"Same CP",
"Same *"};
184 for (
int ip=0;ip<3;ip++) {
185 for (
int ig =0;ig<3;ig++) {
186 graph[ip][ig] =
new TGraph(N[ip][ig] , X[ip][ig], Y[ip][ig]);
187 if(ig==2) graph[ip][ig]->SetMarkerColor(kRed);
188 myCanvas->cd(ip+1); graph[ip][ig]->Draw(opt[ig]);
195 if (!myCanvas)
return;
196 myCanvas->Modified();
199 while(!gSystem->ProcessEvents()){};
211 return ((
StiAux_t*)(fArr.GetArray())) +
id-1;
216 int n = fArr.GetSize();
218 if (
int(fN*
sizeof(
StiAux_t))>n) fArr.Set((n+100)*2);
219 memcpy(Get(fN),add,
sizeof(
StiAux_t));
223 void StiAux::PrintIt(
int id)
225 static const char* tit[] = {
226 "xnl[3]=",
"",
"",
"xhl[3]=",
"",
"",
230 "xng[3]=",
"",
"",
"xhg[3]=",
"",
"",
231 "psi=",
"dip=",
"chi2=",0};
233 float *aux = (
float*)Get(
id);
235 for (
int i=0;tit[i];i++) { printf(
"%s%g ",tit[i],aux[i]);}
240 void StiDebug::Count(
const char *key,
double val)
242 if (mgDebug<2)
return;
243 TH1 *&h = (TH1*&)myDebMap[key];
244 if (!h) { h =
new TH1F(key,key,100,0.,0.);}
248 void StiDebug::Count(
const char *key,
const char *val)
250 if (mgDebug<2)
return;
251 TH1 *&h = (TH1*&)myDebMap[key];
252 if (!h) { h =
new TH1F(key,key,0,0.,0.);}
256 void StiDebug::Count(
const char *key,
double val,
double left,
double rite)
258 if (mgDebug<2)
return;
259 TH1 *&h = (TH1*&)myDebMap[key];
260 if (!h) { h =
new TH1F(key,key,100,left,rite);}
264 void StiDebug::Count(
const char *key,
double valx,
double valy
265 ,
double leftx,
double ritex
266 ,
double lefty,
double ritey)
268 if (mgDebug<2)
return;
269 TH1 *&h = (TH1*&)myDebMap[key];
270 if (!h) { h =
new TH2F(key,key,100,leftx,ritex,100,lefty,ritey);}
274 void StiDebug::Count(
const char *key,
double valx,
double valy)
276 if (mgDebug<2)
return;
277 TH1 *&h = (TH1*&)myDebMap[key];
278 if (!h) { h =
new TH2F(key,key,100,0.,0.,100,0,0);}
282 void StiDebug::Count(
const char *key,
const char *valx,
double valy)
284 if (mgDebug<2)
return;
285 TH2 *&h = (TH2*&)myDebMap[key];
286 if (!h) { h =
new TH2F(key,key,100,0.,0.,100,0,0);}
287 h->Fill(valx,valy,1.);
290 void StiDebug::Sumary(
int nHist)
293 printf(
"StiDebug::Sumary()\n");
296 for (myTallyIter_t iter = mgTally.begin();iter != mgTally.end();++iter) {
297 int nn = (*iter).second; n++;
298 const char *kto = (*iter).first.c_str();
299 printf(
"%3d - Tally.%s = %d\n",n,kto,nn);
306 for (
int numCha = 0; numCha<2; numCha++) {
308 for (myDebIter_t iter = myDebMap.begin();iter != myDebMap.end();++iter) {
309 TH1 *h = (*iter).second; n++;
310 if (!h->IsA()->InheritsFrom(
"TH1"))
continue;
311 if ( h->IsA()->InheritsFrom(
"TH2"))
continue;
313 int nEnt = h->GetEntries();
315 if ((h->GetXaxis()->GetLabels()==0) != (numCha == 0))
continue;
316 double mean = h->GetMean();
317 double rms = h->GetRMS();
318 printf(
"TH1 %2d - %12s:\t %5d %g(+-%g)\n",n,h->GetName(),nEnt,mean,rms);
319 if (nH==nHist) {Draw(nH,H);nH=0;}
320 if (numCha) h->LabelsOption(
">V",
"X");
325 for (myDebIter_t iter = myDebMap.begin();iter != myDebMap.end();++iter) {
326 TH1 *h = (*iter).second; n++;
327 if (!h->IsA()->InheritsFrom(
"TH2"))
continue;
328 int nEnt = h->GetEntries();
330 double mean = h->GetMean();
331 double rms = h->GetRMS();
332 printf(
"TH2 %2d - %12s:\t %5d %g(+-%g)\n",n,h->GetName(),nEnt,mean,rms);
337 while(!gSystem->ProcessEvents()){};
342 void StiDebug::Draw(
int nH,TH1** H)
344 static int nCall=0; nCall++;
346 TString ts(
"C_"); ts += H[0]->GetName();
347 TCanvas *&C = myCanMap[ts.Data()];
348 if (!C) C =
new TCanvas(ts.Data(),ts.Data(),600,800);
349 C->Clear();C->Divide(1,nH);
350 for (
int i=0;i<nH;i++) { C->cd(i+1); H[i]->Draw(); }
352 C->Modified();C->Update();
Definition of Kalman Track.
Float_t x_g() const
Return the global x, y, z values.
Definition of Kalman Track.
const StiKTNBidirectionalIterator & end() const
double getCurvature() const
Calculates and returns the tangent of the track pitch angle at this node.
StiKTNBidirectionalIterator begin() const