Disabled writing to rechits.
[u/mrichter/AliRoot.git] / RICH / AliRICHDetect.cxx
index 273f9b8b3aaba17ccb303295c75ad4d9edba55bf..3cba63e932988e475311b49f2c1a82bb266eace5 100644 (file)
 
 /*
   $Log$
+  Revision 1.4  2000/06/15 15:46:59  jbarbosa
+  Corrected compilation errors on HP-UX (replaced pow with TMath::Power)
+
+  Revision 1.3  2000/06/13 13:15:41  jbarbosa
+  Still some code cleanup done (variable names)
+
+  Revision 1.2  2000/06/12 15:19:30  jbarbosa
+  Cleaned up version.
+
+  Revision 1.1  2000/04/19 13:05:14  morsch
+  J. Barbosa's spot reconstruction algorithm.
+
 */
 
 
 #include "AliRICH.h"
 #include "AliRICHPoints.h"
 #include "AliRICHDetect.h"
-#include "DataStructures.h"
+#include "AliRICHHit.h"
+#include "AliRICHDigit.h"
 #include "AliRun.h"
 #include "TParticle.h"
 #include "TMath.h"
@@ -33,6 +46,9 @@ ClassImp(AliRICHDetect)
 //___________________________________________
 AliRICHDetect::AliRICHDetect() : TObject()
 {
+
+// Default constructor 
+
     //fChambers = 0;
 }
 
@@ -41,6 +57,8 @@ AliRICHDetect::AliRICHDetect(const char *name, const char *title)
     : TObject()
 {
     
+// Constructor
+
     /*fChambers = new TObjArray(7);
     for (Int_t i=0; i<7; i++) {
     
@@ -53,36 +71,40 @@ AliRICHDetect::AliRICHDetect(const char *name, const char *title)
 void AliRICHDetect::Detect()
 {      
     
+//
+// Detection algorithm
+
+
   //printf("Detection started!\n");
-  Float_t OMEGA,steptheta,stepphi,x,y,cx,cy,l,aux1,aux2,aux3,maxi,maxj,maxk,max;
+  Float_t omega,steptheta,stepphi,x,y,cx,cy,l,aux1,aux2,aux3,maxi,maxj,maxk,max;
   //Float_t theta,phi,realomega,realtheta;
   Int_t i,j,k;
   
   //const Float_t Noise_Level=0;          //Noise Level in percentage of mesh points
   //const Float_t t=0.6;                       //Softening of Noise Correction (factor)
   
-  const Float_t Pii=3.1415927;         
+  const Float_t kPi=3.1415927;         
   
-  const Float_t h=10;                       //Distance from Radiator to Pads in pads
+  const Float_t kHeight=10;                       //Distance from Radiator to Pads in pads
   
   
-  const Int_t dimensiontheta=100;              //Matrix dimension for angle Detection
-  const Int_t dimensionphi=100;
-  const Int_t dimensionOMEGA=100;
+  const Int_t kDimensionTheta=100;             //Matrix dimension for angle Detection
+  const Int_t kDimensionPhi=100;
+  const Int_t kDimensionOmega=100;
   
   //const Float_t SPOTp=.2;            //Percentage of spot action
   //const Int_t np=500;                //Number of points to reconstruct elipse 
-  const Float_t maxOMEGA=65*Pii/180;           //Maximum Cherenkov angle to identify
+  const Float_t kMaxOmega=65*kPi/180;          //Maximum Cherenkov angle to identify
   
-  Int_t Point[dimensiontheta][dimensionphi][dimensionOMEGA];
-  //Int_t Point1[dimensiontheta][dimensionphi][dimensionOMEGA];
+  Int_t point[kDimensionTheta][kDimensionPhi][kDimensionOmega];
+  //Int_t point1[kDimensionTheta][kDimensionPhi][kDimensionOmega];
   
-  steptheta=Pii/dimensiontheta;
-  stepphi=Pii/dimensionphi;
+  steptheta=kPi/kDimensionTheta;
+  stepphi=kPi/kDimensionPhi;
 
   AliRICHChamber*       iChamber;
   
-  AliRICH *RICH  = (AliRICH*)gAlice->GetDetector("RICH");
+  AliRICH *pRICH  = (AliRICH*)gAlice->GetDetector("RICH");
   Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
   //Int_t ntrks = gAlice->GetNtrack();
   
@@ -102,9 +124,9 @@ void AliRICHDetect::Detect()
   for (Int_t track=0; track<ntracks;track++) {
     gAlice->ResetHits();
     gAlice->TreeH()->GetEvent(track);
-    TClonesArray *Hits  = RICH->Hits();
-    if (Hits == 0) return;
-    Int_t nhits = Hits->GetEntriesFast();
+    TClonesArray *pHits  = pRICH->Hits();
+    if (pHits == 0) return;
+    Int_t nhits = pHits->GetEntriesFast();
     if (nhits == 0) continue;
     Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
     gAlice->TreeD()->GetEvent(nent-1);
@@ -114,22 +136,22 @@ void AliRICHDetect::Detect()
     
     Int_t counter=0;
     //Initialization
-    for(i=0;i<dimensiontheta;i++)
+    for(i=0;i<kDimensionTheta;i++)
       {
-       for(j=0;j<dimensionphi;j++)
+       for(j=0;j<kDimensionPhi;j++)
          {
-           for(k=0;k<dimensionOMEGA;k++)
+           for(k=0;k<kDimensionOmega;k++)
              {
                counter++;
-               Point[i][j][k]=0;
-               //printf("Dimensions theta:%d, phi:%d, omega:%d",dimensiontheta,dimensionphi,dimensionOMEGA);
+               point[i][j][k]=0;
+               //printf("Dimensions theta:%d, phi:%d, omega:%d",kDimensionTheta,kDimensionPhi,kDimensionOmega);
                //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
-               //-Noise_Level*(Area(i*Pii/(18*dimension),k*maxOMEGA/dimension)-Area((i-1)*Pii/(18*dimension),(k-1)*maxOMEGA/dimension));
-               //printf("n-%f",-Noise_Level*(Area(i*Pii/(18*dimension),k*maxOMEGA/dimension)-Area((i-1)*Pii/(18*dimension),(k-1)*maxOMEGA/dimension)));
+               //-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension));
+               //printf("n-%f",-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension)));
              }
          }
       }
-    mHit = (AliRICHHit*) Hits->UncheckedAt(0);
+    mHit = (AliRICHHit*) pHits->UncheckedAt(0);
     //printf("Aqui vou eu\n");
     Int_t nch  = mHit->fChamber;
     //printf("Aqui fui eu\n");
@@ -144,59 +166,59 @@ void AliRICHDetect::Detect()
     //printf("Chamber processed:%d\n",nch);
     printf("Center processed: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
 
-    iChamber = &(RICH->Chamber(nch-1));
+    iChamber = &(pRICH->Chamber(nch-1));
     
     //printf("Nch:%d\n",nch);
 
     iChamber->GlobaltoLocal(trackglob,trackloc);
     
-    printf("Transformation 1: %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
+    //printf("Transformation 1: %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
 
 
     iChamber->LocaltoGlobal(trackloc,trackglob);
        
-    printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
+    //printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
     
     
      
 
-    TClonesArray *Digits = RICH->DigitsAddress(nch-1);   
-    Int_t ndigits = Digits->GetEntriesFast();
+    TClonesArray *pDigits = pRICH->DigitsAddress(nch-1);   
+    Int_t ndigits = pDigits->GetEntriesFast();
     
     //printf("Got %d digits\n",ndigits);
 
     //printf("Starting calculations\n");
     
-    for(Float_t theta=0;theta<Pii/18;theta+=steptheta)
+    for(Float_t theta=0;theta<kPi/18;theta+=steptheta)
       {                        
-       for(Float_t phi=0;phi<=Pii/3;phi+=stepphi)
+       for(Float_t phi=0;phi<=kPi/3;phi+=stepphi)
          {                    
            for (Int_t dig=0;dig<ndigits;dig++)
              { 
-               points=(AliRICHDigit*) Digits->UncheckedAt(dig);
+               points=(AliRICHDigit*) pDigits->UncheckedAt(dig);
                
                x=points->fPadX-cx;
                y=points->fPadY-cy;
                //printf("Loaded digit %d with coordinates x:%f, y%f\n",dig,x,y);
                //cout<<"x="<<x<<" y="<<y<<endl;
                
-               if (sqrt(pow(x,2)+pow(y,2))<h*tan(theta+maxOMEGA)*3/4)
+               if (sqrt(TMath::Power(x,2)+TMath::Power(y,2))<kHeight*tan(theta+kMaxOmega)*3/4)
                  {
                    
-                   l=h/cos(theta);
+                   l=kHeight/cos(theta);
                    
                    aux1=-y*sin(phi)+x*cos(phi);
                    aux2=y*cos(phi)+x*sin(phi);
-                   aux3=( pow(aux1,2)+pow(cos(theta)*aux2 ,2))/pow(sin(theta)*aux2+l,2);
+                   aux3=( TMath::Power(aux1,2)+TMath::Power(cos(theta)*aux2 ,2))/TMath::Power(sin(theta)*aux2+l,2);
                    //cout<<"aux1="<<aux1<<" aux2="<<aux2<<" aux3="<<aux3;
                    
-                   OMEGA=atan(sqrt(aux3));
-                   //printf("Omega: %f\n",OMEGA);
+                   omega=atan(sqrt(aux3));
+                   //printf("Omega: %f\n",omega);
                    
-                   //cout<<"\ni="<<i<<" theta="<<Int_t(2*theta*dimension/Pii)<<" phi="<<Int_t(2*phi*dimension/Pii)<<" OMEGA="<<Int_t(2*OMEGA*dimension/Pii)<<endl<<endl;
+                   //cout<<"\ni="<<i<<" theta="<<Int_t(2*theta*dimension/kPi)<<" phi="<<Int_t(2*phi*dimension/kPi)<<" omega="<<Int_t(2*omega*dimension/kPi)<<endl<<endl;
                    //{Int_t lixo;cin>>lixo;}
-                   if(OMEGA<maxOMEGA)Point[Int_t(2*theta*dimensiontheta/Pii)][Int_t(2*phi*dimensionphi/Pii)][Int_t(OMEGA*dimensionOMEGA/maxOMEGA)]+=1; 
-                   //if(OMEGA<maxOMEGA)Point[Int_t(theta)][Int_t(phi)][Int_t(OMEGA)]+=1;
+                   if(omega<kMaxOmega)point[Int_t(2*theta*kDimensionTheta/kPi)][Int_t(2*phi*kDimensionPhi/kPi)][Int_t(omega*kDimensionOmega/kMaxOmega)]+=1;    
+                   //if(omega<kMaxOmega)point[Int_t(theta)][Int_t(phi)][Int_t(omega)]+=1;
                  }
                }
          }
@@ -208,37 +230,37 @@ void AliRICHDetect::Detect()
     /*for(s=1;i<=2;s++)
       {
        //buffer copy
-       for(i=0;i<=dimensiontheta;i++)
-         for(j=0;j<=dimensionphi;j++)
-           for(k=0;k<=dimensionOMEGA;k++)
-             Point1[i][j][k]=Point[i][j][k];   
+       for(i=0;i<=kDimensionTheta;i++)
+         for(j=0;j<=kDimensionPhi;j++)
+           for(k=0;k<=kDimensionOmega;k++)
+             point1[i][j][k]=point[i][j][k];   
        
        cout<<"COM SPOT!"<<endl;{Int_t lixo;cin>>lixo;}                                 
        //SPOT algorithm                        
-       for(i=1;i<dimensiontheta;i++)
-         for(j=1;j<dimensionphi;j++)
-           for(k=1;k<dimensionOMEGA;k++)
+       for(i=1;i<kDimensionTheta;i++)
+         for(j=1;j<kDimensionPhi;j++)
+           for(k=1;k<kDimensionOmega;k++)
              {
-               if((Point[i][k][j]>Point[i-1][k][j])&&(Point[i][k][j]>Point[i+1][k][j])&&
-                  (Point[i][k][j]>Point[i][k-1][j])&&(Point[i][k][j]>Point[i][k+1][j])&&
-                  (Point[i][k][j]>Point[i][k][j-1])&&(Point[i][k][j]>Point[i][k][j+1]))
+               if((point[i][k][j]>point[i-1][k][j])&&(point[i][k][j]>point[i+1][k][j])&&
+                  (point[i][k][j]>point[i][k-1][j])&&(point[i][k][j]>point[i][k+1][j])&&
+                  (point[i][k][j]>point[i][k][j-1])&&(point[i][k][j]>point[i][k][j+1]))
                  {
                    //cout<<"SPOT"<<endl;
                    //Execute SPOT on point                                                                                             
-                   Point1[i][j][k]+=int(SPOTp*(Point[i-1][k][j]+Point[i+1][k][j]+Point[i][k-1][j]+Point[i][k+1][j]+Point[i][k][j-1]+Point[i][k][j+1]));    
-                   Point1[i-1][k][j]=int(SPOTp*Point[i-1][k][j]);
-                   Point1[i+1][k][j]=Int_t(SPOTp*Point[i+1][k][j]);
-                   Point1[i][k-1][j]=Int_t(SPOTp*Point[i][k-1][j]);
-                   Point1[i][k+1][j]=Int_t(SPOTp*Point[i][k+1][j]);
-                   Point1[i][k][j-1]=Int_t(SPOTp*Point[i][k][j-1]);
-                   Point1[i][k][j+1]=Int_t(SPOTp*Point[i][k][j+1]);
+                   point1[i][j][k]+=int(SPOTp*(point[i-1][k][j]+point[i+1][k][j]+point[i][k-1][j]+point[i][k+1][j]+point[i][k][j-1]+point[i][k][j+1]));    
+                   point1[i-1][k][j]=int(SPOTp*point[i-1][k][j]);
+                   point1[i+1][k][j]=Int_t(SPOTp*point[i+1][k][j]);
+                   point1[i][k-1][j]=Int_t(SPOTp*point[i][k-1][j]);
+                   point1[i][k+1][j]=Int_t(SPOTp*point[i][k+1][j]);
+                   point1[i][k][j-1]=Int_t(SPOTp*point[i][k][j-1]);
+                   point1[i][k][j+1]=Int_t(SPOTp*point[i][k][j+1]);
                  }
              }
        //copy from buffer copy
-       for(i=1;i<dimensiontheta;i++)
-         for(j=1;j<dimensionphi;j++)
-           for(k=1;k<dimensionOMEGA;k++)
-             Point[i][j][k]=Point1[i][j][k];                                                                           
+       for(i=1;i<kDimensionTheta;i++)
+         for(j=1;j<kDimensionPhi;j++)
+           for(k=1;k<kDimensionOmega;k++)
+             point[i][j][k]=point1[i][j][k];                                                                           
          
          }*/
     
@@ -248,75 +270,80 @@ void AliRICHDetect::Detect()
     
     //cout<<"Proceeding to Identification"<<endl;
     
-    for(i=1;i<dimensiontheta-3;i++)
-      for(j=1;j<=dimensionphi-3;j++)
-       for(k=0;k<=dimensionOMEGA;k++)
-         if(Point[i][j][k]>max)
+    for(i=1;i<kDimensionTheta-3;i++)
+      for(j=1;j<=kDimensionPhi-3;j++)
+       for(k=0;k<=kDimensionOmega;k++)
+         if(point[i][j][k]>max)
            {
-             //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*maxOMEGA/dimension*180/Pii<<" max="<<max<<endl;
+             //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*kMaxOmega/dimension*180/kPi<<" max="<<max<<endl;
              maxi=i;maxj=j;maxk=k;
-             max=Point[i][j][k];
+             max=point[i][j][k];
              //printf("Max Omega %f, Max Theta %f, Max Phi %f\n",maxk,maxi,maxj);
            }
     
-    //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*Pii/(dimensiontheta*4));
-    //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk);
+    //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*kPi/(kDimensionTheta*4));
+    //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",kHeight,cx,cy,maxk);
 
 
     //fscanf(omegas,"%f",&realomega);
     //fscanf(thetas,"%f",&realtheta);
     //printf("Real Omega: %f",realomega);                      
-    //cout<<"Detected:theta="<<maxi*90/dimensiontheta<<"phi="<<maxj*90/dimensionphi<<"OMEGA="<<maxk*maxOMEGA/dimensionOMEGA*180/Pii<<" OmegaError="<<fabs(maxk*maxOMEGA/dimensionOMEGA*180/Pii-realomega)<<" ThetaError="<<fabs(maxi*90/dimensiontheta-realtheta)<<endl<<endl;         
+    //cout<<"Detected:theta="<<maxi*90/kDimensionTheta<<"phi="<<maxj*90/kDimensionPhi<<"omega="<<maxk*kMaxOmega/kDimensionOmega*180/kPi<<" OmegaError="<<fabs(maxk*kMaxOmega/kDimensionOmega*180/kPi-realomega)<<" ThetaError="<<fabs(maxi*90/kDimensionTheta-realtheta)<<endl<<endl;          
     
-    //fprintf(results,"Center Coordinates, cx=%6.2f cy=%6.2f, Real Omega=%6.2f, Detected Omega=%6.2f, Omega Error=%6.2f Theta Error=%6.2f\n",cx,cy,realomega,maxk*maxOMEGA/dimensionOMEGA*180/Pii,fabs(maxk*maxOMEGA/dimensionOMEGA*180/Pii-realomega),fabs(maxi*90/dimensiontheta-realtheta));
+    //fprintf(results,"Center Coordinates, cx=%6.2f cy=%6.2f, Real Omega=%6.2f, Detected Omega=%6.2f, Omega Error=%6.2f Theta Error=%6.2f\n",cx,cy,realomega,maxk*kMaxOmega/kDimensionOmega*180/kPi,fabs(maxk*kMaxOmega/kDimensionOmega*180/kPi-realomega),fabs(maxi*90/kDimensionTheta-realtheta));
     
     /*for(j=0;j<np;j++)
-      Pointpp(maxj*90/dimensiontheta,maxi*90/dimensionphi,maxk*maxOMEGA/dimensionOMEGA*180/Pii,cx,cy);//Generates a point on the elipse*/                  
+      pointpp(maxj*90/kDimensionTheta,maxi*90/kDimensionPhi,maxk*kMaxOmega/kDimensionOmega*180/kPi,cx,cy);//Generates a point on the elipse*/              
 
 
     //Start filling rec. hits
     
-    Float_t rechit[5];
+    Float_t rechit[6];
     
-    rechit[0] = (Float_t)( maxi*Pii/(dimensiontheta*4));
-    rechit[1]   = (Float_t)( maxj*Pii/(dimensionphi*4));
-    rechit[2] = (Float_t)( maxk*Pii/(dimensionOMEGA*4));
+    rechit[0] = (Float_t)( maxi*kPi/(kDimensionTheta*4));
+    rechit[1]   = (Float_t)( maxj*kPi/(kDimensionPhi*4));
+    rechit[2] = (Float_t)( maxk*kPi/(kDimensionOmega*4));
     //rechit[0] = (Float_t)( maxi);
     //rechit[1]   = (Float_t)( maxj);
     //rechit[2] = (Float_t)( maxk);
     rechit[3] = cx;
     rechit[4] = cy;
+    rechit[5] = 0.5;
     
     //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
     
     // fill rechits
-    RICH->AddRecHit(nch-1,rechit);
+    //pRICH->AddRecHit(nch-1,rechit);
   }                    
   //printf("\n\n\n\n");
   gAlice->TreeR()->Fill();
   //TTree *TR=gAlice->TreeR();
   //Stat_t ndig=TR->GetEntries();
   TClonesArray *fRec;
-  for (i=0;i<7;i++) {
-    fRec=RICH->RecHitsAddress(i);
+  for (i=0;i<kNCH;i++) {
+    fRec=pRICH->RecHitsAddress(i);
     int ndig=fRec->GetEntriesFast();
     printf ("Chamber %d, rings %d\n",i,ndig);
   }
   //printf("Number of rec. hits: %d",ndig);
-  RICH->ResetRecHits();
+  pRICH->ResetRecHits();
   //char hname[30];
   //sprintf(hname,"TreeR%d",track);
   //gAlice->TreeR()->Write(hname);
        
 }
 
-Float_t AliRICHDetect:: Area(Float_t theta,Float_t OMEGA)
+Float_t AliRICHDetect:: Area(Float_t theta,Float_t omega)
 {
-    
+
+//
+// Calculates area of an ellipse for given incidence angles    
+
+
     Float_t area;
-    const Float_t h=9.25;                       //Distance from Radiator to Pads in pads
+    const Float_t kHeight=9.25;                       //Distance from Radiator to Pads in pads
     
-    area=TMath::Pi()*pow(h*tan(OMEGA),2)/pow(pow(cos(theta),2)-pow(tan(OMEGA)*sin(theta),2),3/2);
+    area=TMath::Pi()*TMath::Power(kHeight*tan(omega),2)/TMath::Power(TMath::Power(cos(theta),2)-TMath::Power(tan(omega)*sin(theta),2),3/2);
     
     return (area);
 }
@@ -356,10 +383,10 @@ for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
 return t;
 }*/
 
-/*void Pointpp(Float_t alfa,Float_t theta,Float_t OMEGA,Float_t cx,Float_t cy)
+/*void pointpp(Float_t alfa,Float_t theta,Float_t omega,Float_t cx,Float_t cy)
   {
   Int_t s;
-  Float_t fiducial=h*tan((OMEGA+theta)*Pii/180),l=h/cos(theta*Pii/180),xtrial,y,c0,c1,c2;
+  Float_t fiducial=h*tan((omega+theta)*kPi/180),l=h/cos(theta*kPi/180),xtrial,y,c0,c1,c2;
   
   //cout<<"fiducial="<<fiducial<<endl;
   
@@ -370,13 +397,13 @@ return t;
   if(aleat(1)>.5) s=1; else s=-1;
   //Trial a y
   y=s*aleat(fiducial);         
-  Float_t alfa1=alfa*Pii/180;
-  Float_t theta1=theta*Pii/180;
-  Float_t OMEGA1=OMEGA*Pii/180;
+  Float_t alfa1=alfa*kPi/180;
+  Float_t theta1=theta*kPi/180;
+  Float_t omega1=omega*kPi/180;
   //Solve the eq for a trial x
-  c0=-pow(y*cos(alfa1)*cos(theta1),2)-pow(y*sin(alfa1),2)+pow(l*tan(OMEGA1),2)+2*l*y*cos(alfa1)*sin(theta1)*pow(tan(OMEGA1),2)+pow(y*cos(alfa1)*sin(theta1)*tan(OMEGA1),2);
-  c1=2*y*cos(alfa1)*sin(alfa1)-2*y*cos(alfa1)*pow(cos(theta1),2)*sin(alfa1)+2*l*sin(alfa1)*sin(theta1)*pow(tan(OMEGA1),2)+2*y*cos(alfa1)*sin(alfa1)*pow(sin(theta1),2)*pow(tan(OMEGA1),2);
-  c2=-pow(cos(alfa1),2)-pow(cos(theta1)*sin(alfa1),2)+pow(sin(alfa1)*sin(theta1)*tan(OMEGA1),2);
+  c0=-TMath::Power(y*cos(alfa1)*cos(theta1),2)-TMath::Power(y*sin(alfa1),2)+TMath::Power(l*tan(omega1),2)+2*l*y*cos(alfa1)*sin(theta1)*TMath::Power(tan(omega1),2)+TMath::Power(y*cos(alfa1)*sin(theta1)*tan(omega1),2);
+  c1=2*y*cos(alfa1)*sin(alfa1)-2*y*cos(alfa1)*TMath::Power(cos(theta1),2)*sin(alfa1)+2*l*sin(alfa1)*sin(theta1)*TMath::Power(tan(omega1),2)+2*y*cos(alfa1)*sin(alfa1)*TMath::Power(sin(theta1),2)*TMath::Power(tan(omega1),2);
+  c2=-TMath::Power(cos(alfa1),2)-TMath::Power(cos(theta1)*sin(alfa1),2)+TMath::Power(sin(alfa1)*sin(theta1)*tan(omega1),2);
   //cout<<"Trial: y="<<y<<"c0="<<c0<<" c1="<<c1<<" c2="<<c2<<endl;
   }
   //Choose which side to go...