#ifndef CALOAXIS2_H_ #define CALOAXIS2_H_ #if !defined(__CINT__) || defined(__MAKECINT__) #include #include #include #include #include #include #include #include #include #include using namespace std; #include //#include #endif // !defined(__CINT__) || defined(__MAKECINT__) //=============================================================================== // // // // //=============================================================================== class CaloEvent{ public: // calo event // ------------------------------ // hit strips // ------------------------------ vector ids; //strip 0-95 vector idp; //plane 0-21 vector q; // signal vector zcoord; vector xycoord; // ------------------------------ // methods // ------------------------------ void Add(int iis, int iip, float fq, float fz, float fxy){ ids.push_back(iis); idp.push_back(iip); q.push_back(fq); zcoord.push_back(fz); xycoord.push_back(fxy); }; int GetN(){return (int)(q.size());}; void Reset(){ ids.clear(); idp.clear(); q.clear(); zcoord.clear(); xycoord.clear(); }; void Delete(){ Reset(); }; ~CaloEvent(){ Delete(); }; CaloEvent(){ }; CaloEvent( CaloLevel1* calo, int view, Bool_t usemechanicalalignement){ Set(calo,view,usemechanicalalignement); }; CaloEvent( CaloLevel1* calo, int view){ Set(calo,view); }; void Set(CaloLevel1* calo, int view, Bool_t usemechanicalalignement){ Reset(); // cout << " CaloEvent::Set()"<istrip;ih++){ int iv=-1; int ip=-1; int is=-1; calo->DecodeEstrip(ih,iv,ip,is); if(iv==view){ cstrip.Set(view,ip,is); float fxy = 0.; if( !view ) fxy = cstrip.GetX(); else fxy = cstrip.GetY(); float fz = cstrip.GetZ(); float fq = cstrip.GetE(); if(fq>0)Add(is,ip,fq,fz,fxy); } } }; void Set(CaloLevel1* calo, int view){ Set(calo,view,0); }; }; //=============================================================================== // // // // //=============================================================================== class CaloAxis { public: CaloEvent *cevent; // ------------------------------ // selected points along the axis // ------------------------------ // fitted points vector x;// independent coordinates (z) vector y;// dependente coordinate (x/y) vector w;// fit weight vector q;// signal // ------------------------------ // axis parameters // ------------------------------ Float_t par[2]; Float_t covpar[2][2]; // ------------------------------ // general variables // ------------------------------ float cog[22];// baricenter float qpl[22]; // charge in each plane // ------------------------------ // objects to draw the axis // ------------------------------ TPolyMarker *sel; TLine *axis; // ------------------------------ // methods // ------------------------------ void Init(){ for(Int_t i=0; i<2;i++){ par[i]=0; for(Int_t j=0; j<2;j++)covpar[i][j]=0; }; sel = 0; axis = 0; for(Int_t i=0; i<22; i++){ cog[i]=0; qpl[i]=0; } // if(cevent)cevent->Reset(); } void Set(CaloLevel1* calo, Int_t view){ cevent->Set(calo,view,0); }; void Set(CaloLevel1* calo, Int_t view, Bool_t usemechanicalalignement){ cevent->Set(calo,view,usemechanicalalignement); }; CaloAxis(){ cevent = new CaloEvent(); Init(); }; CaloAxis(CaloLevel1* calo, Int_t view){ cevent = new CaloEvent(); Init(); Set(calo,view); }; CaloAxis(CaloLevel1* calo, Int_t view, Bool_t usemechanicalalignement){ cevent = new CaloEvent(); Init(); Set(calo,view,usemechanicalalignement); }; void Reset(){ // cout << " CaloAxis::Reset()"<Delete(); // cout << axis << endl; if(axis)axis->Delete(); // if(cevent)cevent->Reset(); Init(); } void Delete(){ Reset(); delete cevent; }; ~CaloAxis(){ Delete(); }; void Add(float xin, float yin){ x.push_back(xin); y.push_back(yin); w.push_back(1.); q.push_back(0.); /* Int_t nin = x.size(); */ /* if(nin>2)Fit(); */ }; void Add(float xin, float yin, float qin){ x.push_back(xin); y.push_back(yin); q.push_back(qin); w.push_back(1.); /* Int_t nin = x.size(); */ /* if(nin>2)Fit(); */ }; void Add(float xin, float yin, float qin, float win){ x.push_back(xin); y.push_back(yin); w.push_back(win); q.push_back(qin); /* Int_t nin = x.size(); */ /* if(nin>2)Fit(); */ }; int Fit(){ // cout << " CaloAxis::Fit()"<GetN(); ih++){ float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; float q = cevent->q[ih]; //int ip = cevent->idp[ih]; float d = fabs(x-par[0]-par[1]*z)/sqrt(par[1]*par[1]+1); if( d < toll )qaxis+=q; } return qaxis; } float GetCOG(Int_t ip){ if(ip>=0 && ip<22)return cog[ip]; else return 0; } float GetQ(Int_t ip){ if(ip>=0 && ip<22)return qpl[ip]; else return 0; } float GetQstrip(){ float qaxis=0; for(Int_t i=0; i<(int)(q.size()); i++) qaxis +=q[i]; if(q.size()==0) return 0.; return qaxis/q.size(); } float GetYfit(float x){ return par[0]+x*par[1]; } float GetXmin(){ float zmin=9999; for(Int_t i=0; i<(int)(x.size()); i++) if(x[i]zmax) zmax = x[i]; return zmax; } void Draw(){ // cout << " CaloAxis::Draw()"<SetMarkerSize(0.3); sel->SetMarkerColor(5); axis = new TLine( par[0]+GetXmin()*par[1], GetXmin(), par[0]+GetXmax()*par[1], GetXmax() ); axis->SetLineWidth(1); axis->SetLineColor(5); // cout << sel << endl; // cout << axis << endl; sel->Draw(); axis->Draw(); }; //----------------------------------------------------------------- // fit the axis (optimized for non-interacting patterns) //----------------------------------------------------------------- int FitAxis( CaloLevel1* calo , Int_t view , Float_t toll , Bool_t usemechanicalalignement ){ // cout << "CaloAxis::FitAxis(...)"<GetN(); ih++){ float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; float q = cevent->q[ih]; Add(z,x,q); } if(GetN()<3)return 0; Fit(); // useful for debug cout << "(1)"<GetN(); ih++){//loop over selected hits float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; float q = cevent->q[ih]; int ip = cevent->idp[ih]; float d = fabs(x-P0-P1*z)/sqrt(P1*P1+1);//distance to axis // cout<1 && pok[ip]==1)) ){ // if( d < ttoll ){ float W=a+b*(ip+1); // cout << ip << " "<>> "<GetN(); ih++){ float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; //float q = cevent->q[ih]; int ip = cevent->idp[ih]; //int is = cevent->ids[ih]; float d = fabs(x-P0-P1*z)/sqrt(P1*P1+1); if( d < toll && dxycoord[closest[ip]]; float z = cevent->zcoord[closest[ip]]; float q = cevent->q[closest[ip]]; //int is = cevent->ids[closest[ip]]; Add(z,x,q,q); cog[ip] += x*q; qpl[ip] += q; // cout << ip << " -o- "<GetN(); ih++){ float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; float q = cevent->q[ih]; int ip = cevent->idp[ih]; int is = cevent->ids[ih]; if( closest[ip]!=-1 ){ int isc = cevent->ids[closest[ip]]; if( is == isc+1 || is == isc-1 ){ Add(z,x,q,q); cog[ip] += x*q; qpl[ip] += q; // cout << ip << " -+- "<GetN(); ih++){ float x = cevent->xycoord[ih]; //float z = cevent->zcoord[ih]; float q = cevent->q[ih]; int ip = cevent->idp[ih]; cog[ip] += x*q; qpl[ip] += q; // Add(z,x,q); } for(int ip=0; ip<22; ip++){ if(qpl[ip]!=0)cog[ip]=cog[ip]/qpl[ip]; // cout << ip << " > "<qplmax){ ipmax=ip; qplmax=qpl[ip]; dmin[ip]=1000.;//init closest[ip]=-1;//init } for(int ih=0;ihGetN(); ih++){ float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; float q = cevent->q[ih]; int ip = cevent->idp[ih]; // if( (ipmax>3 && ip<=ipmax) || ipmax<=3 )Add(z,x,q); if( ip<=ipmax || ip<=3 ){ Add(z,x,q); } } if(GetN()<3)return 0; Fit(); // cout << " n. hits :"<GetN(); ih++){ float x = cevent->xycoord[ih]; float z = cevent->zcoord[ih]; float q = cevent->q[ih]; int ip = cevent->idp[ih]; float d = fabs(x-P0-P1*z)/sqrt(P1*P1+1); // cout<1 && pok[ip]==1)) && (ip<=ipmax || ip<=3) && // ((ipmax>3 && ip<=ipmax) || ipmax<=3) && true){ if(niter==1 && d1)Add(z,x,q,W*q); */ /* else Add(z,x,q,W); */ cog[ip] += x*q; qpl[ip] += q; Add(z,x,q,W); pok[ip]=1; cout << ip << " "<>> "<GetN(); ih++){ */ /* float x = cevent->xycoord[ih]; */ /* float z = cevent->zcoord[ih]; */ /* float q = cevent->q[ih]; */ /* int ip = cevent->idp[ih]; */ /* int is = cevent->ids[ih]; */ /* float d = fabs(x-P0-P1*z)/sqrt(P1*P1+1); */ /* if( d < toll && dxycoord[closest[ip]]; */ /* float z = cevent->zcoord[closest[ip]]; */ /* float q = cevent->q[closest[ip]]; */ /* int is = cevent->ids[closest[ip]]; */ /* Add(z,x,q,q); */ /* cog[ip] += x*q; */ /* qpl[ip] += q; */ /* // cout << ip << " -o- "<GetN(); ih++){ */ /* float x = cevent->xycoord[ih]; */ /* float z = cevent->zcoord[ih]; */ /* float q = cevent->q[ih]; */ /* int ip = cevent->idp[ih]; */ /* int is = cevent->ids[ih]; */ /* if( closest[ip]!=-1 ){ */ /* int isc = cevent->ids[closest[ip]]; */ /* if( is == isc+1 || is == isc-1 ){ */ /* Add(z,x,q,q); */ /* cog[ip] += x*q; */ /* qpl[ip] += q; */ /* // cout << ip << " -+- "<