/** * \file CaloAxis.cpp * \author Elena Vannuccini */ #if !defined(__CINT__) || defined(__MAKECINT__) #include #endif //=============================================================================== // // // // //=============================================================================== /** * Add a calorimeter hit * @param iis strip 0-95 * @param iip plane 0-21 * @param fq signal * @param fz z-coordinate * @param fxy x or y-coordinate */ void CaloEvent::Add(int iis, int iip, float fq, float fz, float fxy){ // cout << " CaloEvent::Add()"<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); } } }; //=============================================================================== // // // // //=============================================================================== /** * Initialization */ void CaloAxis::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; } } /** * Reset */ void CaloAxis::Reset(){ x.clear(); y.clear(); w.clear(); q.clear(); if(sel)sel->Delete(); if(axis)axis->Delete(); Init(); } /** * */ void CaloAxis::Add(float xin, float yin){ x.push_back(xin); y.push_back(yin); w.push_back(1.); q.push_back(0.); }; void CaloAxis::Add(float xin, float yin, float qin){ x.push_back(xin); y.push_back(yin); q.push_back(qin); w.push_back(1.); }; void CaloAxis::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); }; /** * Fit a straight line thtrough the stored hits */ int CaloAxis::Fit(){ Float_t SSS = 0; Float_t SSX = 0; Float_t SXX = 0; Float_t SSY = 0; Float_t SXY = 0; Int_t np=0; for(Int_t i=0; i<(int)(x.size()); i++){ SSS += w[i]*w[i]; SSX += x[i]*w[i]*w[i]; SXX += x[i]*x[i]*w[i]*w[i]; SSY += y[i]*w[i]*w[i]; SXY += x[i]*y[i]*w[i]*w[i]; if(w[i])np++; } Float_t det = SSS*SXX-SSX*SSX; if(det==0)return 0; if(np<3)return 0; par[0] = (SSY*SXX-SXY*SSX)/det; par[1] = (SXY*SSS-SSY*SSX)/det; return 1; }; /** * Print select hits */ void CaloAxis::Print(){ for(Int_t i=0; i<(int)(x.size()); i++) if(w[i])cout << x[i] << " - "<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; } /** * Average signal per strip */ float CaloAxis::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(); } /** * Coordinate of the last hit included in the axis */ float CaloAxis::GetXmin(){ float zmin=9999; for(Int_t i=0; i<(int)(x.size()); i++) if(x[i]zmax) zmax = x[i]; return zmax; } /** * Draw the axis (in PAMELA reference plane) */ void CaloAxis::Draw(int col){ // cout << " CaloAxis::Draw()"<SetMarkerSize(0.4); sel->SetMarkerColor(col); axis = new TLine( par[0]+GetXmin()*par[1], GetXmin(), par[0]+GetXmax()*par[1], GetXmax() ); axis->SetLineWidth(1); axis->SetLineColor(col); // cout << sel << endl; // cout << axis << endl; sel->Draw(); axis->Draw(); }; /** * Fit an axis through the calorimeter pattern. * NB!! This method is optimized for non-interacting particles. */ int CaloAxis::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(); // 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)) ){ // 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) && (ip3 && 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; } } } // break the track if more than 3 planes are missing int nmissing = 0; for(int ip=0; ip<22; ip++){ if(pok[ip]==0){ nmissing++; }else{ nmissing = 0; } if(nmissing==6){ for(int ipp=ip+1; ipp<22; ipp++)pok[ipp]=0; break; } } for(int ip=0; ip<22; ip++)if(qpl[ip]!=0)cog[ip]=cog[ip]/qpl[ip]; if(niter==100)break; if(GetN()<3)break; Fit(); }while(niter==1 || GetN() != dof); // cout << " >>> "<