]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSgeom.cxx
Additional protection to avoid rare problem related to the simulation of
[u/mrichter/AliRoot.git] / ITS / AliITSgeom.cxx
index e15eccdabf48d7f8bb031bd273df868c09955261..aae9928ab311e1133821c8f4ebd0411f79164ffc 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.20  2002/10/14 14:57:00  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.18.8.1  2002/07/24 09:27:50  alibrary
-Updating on VirtualMC
-
-Revision 1.19  2002/05/31 21:07:42  mariana
-Fix memory leak
-
-Revision 1.18  2001/08/24 21:06:37  nilsen
-Added more documentation, fixed up some coding violations, and some
-forward declorations.
-
-Revision 1.17  2001/07/27 08:06:48  hristov
-Use global gRandom generator (M.Ivanov)
-
-Revision 1.16  2001/02/08 23:57:00  nilsen
-Fixed up some informational printouts.
-
-Revision 1.15  2001/02/07 20:23:21  nilsen
-Fixed bug with HP and no unget in iostream.h. Now using putback instead.
-Other changes and fixes also included.
-
-Revision 1.14  2001/02/03 00:00:29  nilsen
-New version of AliITSgeom and related files. Now uses automatic streamers,
-set up for new formatted .det file which includes detector information.
-Additional smaller modifications are still to come.
-
-Revision 1.11  2000/10/02 16:32:35  barbera
-Forward declaration added
-
-Revision 1.4.4.15  2000/10/02 15:52:05  barbera
-Forward declaration added
-
-Revision 1.10  2000/09/05 14:25:50  nilsen
-Made fixes for HP compiler. All function parameter default values placed
-in .h file. Fixed the usual problem with HP compilers and the "for(Int_t i..."
-business. Replaced casting (Double_t [3][3]) to (Double_t (*)[3]) for HP.
-Lastly removed all "const" before function parameters which were 2 dim. arrays,
-because on HP root generates some strange code (?). Thanks Peter for the
-changes.
-
-Revision 1.9  2000/08/29 20:19:03  nilsen
-Removed dependency on structure AliITSeomS and replaced it with class
-AliITSgeomMatrix. Added many new functions with many new arguments. Most
-in the form of in line functions for speed.
-
-Revision 1.4.4.6  2000/06/04 16:33:32  Nilsen
-A restructured AliITSgeom class. Now used AliITSgeomMatrix.
-
-Revision 1.4.4.5  2000/03/04 23:42:39  Nilsen
-Updated the comments/documentations and improved the maintainability of the
-code.
-
-Revision 1.4.4.4  2000/03/02 21:27:07  Nilsen
-Added two functions, SetByAngles and SetTrans.
-
-Revision 1.4.4.3  2000/01/23 03:09:10  Nilsen
-// fixed compiler warnings for new function LtLErrorMatrix(...)
-
-Revision 1.4.4.2  2000/01/19 23:18:20  Nilsen
-Added transformations of Error matrix to AliITSgeom and fixed some typos
-in AliITS.h and AliITShitIndex.h
-
-Revision 1.4.4.1  2000/01/12 19:03:32  Nilsen
-This is the version of the files after the merging done in December 1999.
-See the ReadMe110100.txt file for details
-
-Revision 1.4  1999/10/15 07:03:20  fca
-Fixed bug in GetModuleId(Int_t index,Int_t &lay,Int_t &lad, Int_t &det) and
-a typo in the creator. aliroot need to be rerun to get a fixed geometry.
-
-Revision 1.3  1999/10/04 15:20:12  fca
-Correct syntax accepted by g++ but not standard for static members, remove minor warnings
-
-Revision 1.2  1999/09/29 09:24:20  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////
 // ITS geometry manipulation routines.                               //
@@ -197,18 +117,15 @@ pixel coordinate system.
 // and AliITSgeomSSD for a more detailed example.
 ////////////////////////////////////////////////////////////////////////
 #include <Riostream.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
 
-#include <TSystem.h>
 #include <TRandom.h>
+#include <TSystem.h>
 
 #include "AliITSgeom.h"
-#include "AliITSgeomSPD.h"
 #include "AliITSgeomSDD.h"
+#include "AliITSgeomSPD.h"
 #include "AliITSgeomSSD.h"
+#include "AliLog.h"
 
 ClassImp(AliITSgeom)
 
@@ -337,26 +254,26 @@ void AliITSgeom::ReadNewFile(const char *filename){
                        "fNDetectorTypes","fShape"  ,"Matrix"};
     Int_t i,j,lNdetTypes,ldet;
     char cmd[20],c;
-    AliITSgeomSPD *spd;
-    AliITSgeomSDD *sdd;
-    AliITSgeomSSD *ssd;
-    AliITSgeomMatrix *m;
-    ifstream *fp;
-    char *filtmp;
+    AliITSgeomSPD *spd=0;
+    AliITSgeomSDD *sdd=0;
+    AliITSgeomSSD *ssd=0;
+    AliITSgeomMatrix *m=0;
+    ifstream *fp=0;
+    char *filtmp=0;
 
     filtmp = gSystem->ExpandPathName(filename);
-    cout << "AliITSgeom, Reading New .det file " << filtmp << endl;
+    AliInfo(Form("Reading New .det file %s",filtmp));
     fp = new ifstream(filtmp,ios::in);  // open file to write
     while(fp->get(c)!=NULL){ // for ever loop
        if(c==' ') continue; // remove blanks
        if(c=='\n') continue;
-       if(c=='#' || c=='!'){for(;fp->get(c)!=NULL,c!='\n';); continue;}
+       if(c=='#' || c=='!') {while(fp->get(c)) if(c=='\n') break; continue;}
        if(c=='/'){
            fp->get(c);{
-               if(c=='/'){for(;fp->get(c)!=NULL,c!='\n';);continue;}
+             if(c=='/') {while(fp->get(c)) if(c=='\n') break; continue;}
                if(c=='*'){
                NotYet:
-                   for(;fp->get(c)!=NULL,c!='*';);
+                   while(fp->get(c)) if(c=='*') break;
                    fp->get(c);{
                        if(c=='/') continue;
                        goto NotYet;
@@ -408,26 +325,26 @@ void AliITSgeom::ReadNewFile(const char *filename){
            if(fShape==0) fShape = new TObjArray(5,0);
            switch (ldet){
            case kSPD :
-               ReSetShape(ldet,(TObject*) new AliITSgeomSPD());
-               spd = (AliITSgeomSPD*) (fShape->At(ldet));
+               spd = new AliITSgeomSPD();
                *fp >> *spd;
+               ReSetShape(ldet,spd);
                spd = 0;
                break;
-           case kSDD :
-               ReSetShape(ldet,(TObject*) new AliITSgeomSDD());
-               sdd = (AliITSgeomSDD*) (fShape->At(ldet));
+           case kSDD : case kSDDp:
+               sdd = new AliITSgeomSDD();
                *fp >> *sdd;
+               ReSetShape(ldet,sdd);
                sdd = 0;
                break;
            case kSSD : case kSSDp :
-               ReSetShape(ldet,(TObject*) new AliITSgeomSSD());
-               ssd = (AliITSgeomSSD*) (fShape->At(ldet));
+               ssd = new AliITSgeomSSD();
                *fp >> *ssd;
+               ReSetShape(ldet,ssd);
                ssd = 0;
                break;
            default:
-               Error("ReadNewFile","Unknown fShape type number=%d c=%c",ldet,c);
-               for(;fp->get(c)==NULL,c!='\n';); // skip to end of line.
+               AliError(Form("Unknown fShape type number=%d c=%c",ldet,c));
+               while(fp->get(c)) if(c=='\n') break; // skip to end of line.
                break;
            } // end switch
            break;
@@ -441,8 +358,8 @@ void AliITSgeom::ReadNewFile(const char *filename){
            m = 0;
            break;
        default:
-           Error("ReadNewFile","Data line i=%d c=%c",i,c);
-           for(;fp->get(c)==NULL,c!='\n';); // skip this line
+           AliError(Form("ReadNewFile","Data line i=%d c=%c",i,c));
+           while(fp->get(c)) if(c=='\n') break; // skip this line
            break;
        } // end switch i
     } // end while
@@ -619,7 +536,7 @@ AliITSgeom::AliITSgeom(const char *filename){
     fclose(pf);
 }
 //______________________________________________________________________
-AliITSgeom::AliITSgeom(AliITSgeom &source){
+AliITSgeom::AliITSgeom(const AliITSgeom &source) : TObject(source){
     //     The copy constructor for the AliITSgeom class. It calls the
     // = operator function. See the = operator function for more details.
     // Inputs are:
@@ -632,7 +549,7 @@ AliITSgeom::AliITSgeom(AliITSgeom &source){
     return;
 }
 //______________________________________________________________________
-AliITSgeom& AliITSgeom::operator=(AliITSgeom &source){
+AliITSgeom& AliITSgeom::operator=(const AliITSgeom &source){
     //     The = operator function for the AliITSgeom class. It makes an
     // independent copy of the class in such a way that any changes made
     // to the copied class will not affect the source class in any way.
@@ -688,6 +605,7 @@ Int_t AliITSgeom::GetModuleIndex(Int_t lay,Int_t lad,Int_t det){
     j = 0;
     for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k];
     i = i+j;
+    if(i>=fNmodules) return -1;
     GetGeomMatrix(i)->GetIndex(id);
     if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
     // Array of modules fGm is not in expected order. Search for this index
@@ -711,9 +629,17 @@ void AliITSgeom::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det){
     // Int_t lad    The ladder number. Starting from 1.
     // Int_t det    The detector number. Starting from 1.
     Int_t id[3];
-
-    GetGeomMatrix(index)->GetIndex(id);
-    lay = id[0]; lad = id[1]; det = id[2];
+    AliITSgeomMatrix *g = GetGeomMatrix(index);
+    if (g == 0x0)
+     {
+      Error("GetModuleId","Can not get GeoMatrix for index = %d",index);
+      lay = -1; lad = -1; det = -1;
+     }
+    else
+     {
+      g->GetIndex(id);
+      lay = id[0]; lad = id[1]; det = id[2];
+     }
     return;
 
     // The old way kept for posterity.
@@ -915,6 +841,24 @@ ofstream & AliITSgeom::PrintGeom(ofstream &rb){
     for(i=0;i<fNmodules;i++) {
        rb <<setprecision(16) << *(GetGeomMatrix(i)) << "\n";
     } // end for i
+    rb << fShape->GetEntries()<<endl;
+    for(i=0;i<fShape->GetEntries();i++) if(fShape->At(i)!=0) switch (i){
+    case kSPD:
+       rb << kSPD <<","<< (AliITSgeomSPD*)(fShape->At(kSPD));
+       break;
+    case kSDD:
+       rb << kSDD <<","<< (AliITSgeomSDD*)(fShape->At(kSDD));
+       break;
+    case kSSD:
+       rb << kSSD <<","<< (AliITSgeomSSD*)(fShape->At(kSSD));
+       break;
+    case kSSDp:
+       rb << kSSDp <<","<< (AliITSgeomSSD*)(fShape->At(kSSDp));
+       break;
+    case kSDDp:
+       rb << kSDDp <<","<< (AliITSgeomSDD*)(fShape->At(kSDDp));
+       break;
+    } // end for i / switch
     return rb;
 }
 //______________________________________________________________________
@@ -924,7 +868,7 @@ ifstream & AliITSgeom::ReadGeom(ifstream &rb){
     // ifstream &rb    The input streaming buffer.
     // Outputs are:
     // ifstream &rb    The input streaming buffer.
-    Int_t i;
+    Int_t i,j;
 
     fNlad = new Int_t[fNlayers];
     fNdet = new Int_t[fNlayers];
@@ -943,6 +887,38 @@ ifstream & AliITSgeom::ReadGeom(ifstream &rb){
        fGm->AddAt(new AliITSgeomMatrix,i);
        rb >> *(GetGeomMatrix(i));
     } // end for i
+    rb >> i;
+    fShape = new TObjArray(i);
+    for(i=0;i<fShape->GetEntries();i++) {
+       rb >> j;
+       switch (j){
+       case kSPD:{
+           AliITSgeomSPD *s = new AliITSgeomSPD();
+           rb >> *s;
+           fShape->AddAt(s,kSPD);}
+           break;
+       case kSDD:{
+           AliITSgeomSDD *s = new AliITSgeomSDD();
+           rb >> *s;
+           fShape->AddAt(s,kSDD);}
+           break;
+       case kSSD:{
+           AliITSgeomSSD *s = new AliITSgeomSSD();
+           rb >> *s;
+           fShape->AddAt(s,kSSD);}
+           break;
+       case kSSDp:{
+           AliITSgeomSSD *s = new AliITSgeomSSD();
+           rb >> *s;
+           fShape->AddAt(s,kSSDp);}
+           break;
+       case kSDDp:{
+           AliITSgeomSDD *s = new AliITSgeomSDD();
+           rb >> *s;
+           fShape->AddAt(s,kSDDp);}
+           break;
+       } // end  switch
+    } //  end for i
     return rb;
 }
 //______________________________________________________________________
@@ -1230,4 +1206,25 @@ void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay){
     } // end for i
     for(i=0;i<27;i++) n[i] = in[i];
 }
-//----------------------------------------------------------------------
+//_______________________________________________________________________
+void AliITSgeom::DetLToTrackingV2(Int_t md, Float_t xin, Float_t zin, Float_t &yout, Float_t &zout) {
+
+  //Conversion from local coordinates on detectors to local
+  //coordinates used for tracking ("v2")
+  Float_t x,y,z; Double_t rt[9];GetTrans(md,x,y,z);GetRotMatrix(md,rt);
+  Double_t al=TMath::ATan2(rt[1],rt[0])+TMath::Pi();
+  yout=-(-xin+(x*TMath::Cos(al)+y*TMath::Sin(al)));
+  if(md<(GetModuleIndex(2,1,1)-1))yout*=-1; zout=-zin+(Double_t)z; 
+}
+
+//_______________________________________________________________________
+void AliITSgeom::TrackingV2ToDetL(Int_t md,Float_t yin,Float_t zin,Float_t &xout,Float_t &zout) {
+  //Conversion from local coordinates used for tracking ("v2") to
+  //local detector coordinates
+  
+  Float_t x,y,z; Double_t rt[9];GetTrans(md,x,y,z);GetRotMatrix(md,rt);
+  Double_t al=TMath::ATan2(rt[1],rt[0])+TMath::Pi();
+  xout=yin;if(md<(GetModuleIndex(2,1,1)-1))xout=-xout;
+  xout+=(x*TMath::Cos(al)+y*TMath::Sin(al));
+  zout=-zin+(Double_t)z; 
+}