]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AlignITSmacro2.C
Automatic treatment of the magnetic field value
[u/mrichter/AliRoot.git] / ITS / AlignITSmacro2.C
1 //////////////////////////////////////////////////////////////////////////
2 //  Alice ITS first detector alignment program.                         //
3 //                                                                      //
4 // version: 0.0.0 Draft.                                                //
5 // Date: April 18 1999                                                  //
6 // By: Bjorn S. Nilsen                                                  //
7 //                                                                      //
8 //////////////////////////////////////////////////////////////////////////
9
10 #include <fstream.h>
11
12 // Data structure to hold averaged clusts.
13 struct ClustAl_sl{
14     Int_t lay,lad,det;
15     Float_t xg,yg,zg,xl,yl,zl;
16 };
17 struct ClustAl_tl{
18     Int_t    track,nclust;  // track number and number of data points.
19     ClustAl_sl *clust;      // data points to fit.
20     Float_t  a,b,c,d,a0,b0,c0,d0,qual;  // fit parameters and fit quality.
21     Float_t  px,py,pz,p,pt;
22     // x=a+bz and y=c+dz;
23     // x=a0+b0*y and z=c0+d0*y in coordinate system of clust[0].lay,lad,det
24 };
25
26 //
27 void AlignITSmacro3(const char *Rfilename="galice_ITS_B0.root",
28                     const char *sfile="Align_ITS_B0",
29                     Float_t sigma1=0.0,Float_t sigma2=0.0,Float_t sigma3=0.0,
30                     Int_t evNumber=0) {
31 /////////////////////////////////////////////////////////////////////////
32 //   This macro is a small example of a ROOT macro illustrating how to 
33 //   read the output of GALICE and fill some histograms.
34 //
35 //     Root > .L AlignITSmacro2.C    // this loads the macro in memory
36 //     Root > AlignITSmacro2();      // by default process first event   
37 //     Root > AlignITSmacro2("galice.root");   // process file galice.root
38 //     Root > AlignITSmacro2("galice.root",3); // process file galice.root
39 //                                                the first 4 events
40 //       or
41 //     Root > .x AlignITSmacro2.C;  //by default process first event
42 //     Root > .x AlignITSmacro2.C("galice.root");   // process file galice.root
43 //     Root > .x AlignITSmacro2.C("galice.root",3); // process file galice.root
44 //                                                     the first 4 events
45 /////////////////////////////////////////////////////////////////////////
46 //
47     gROOT->Reset();  // Reset root to it's default state
48 // Dynamically link some shared libs
49    if (gClassTable->GetID("AliRun") < 0) {
50       gROOT->LoadMacro("loadlibs.C");
51       loadlibs();
52    } // end if gClassTable...
53
54    // Connect the Root Galice file containing Geometry, Kine and Clusts
55    TFile *Rfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Rfilename);
56    if(!Rfile) Rfile = new TFile(Rfilename);
57    printf("reading from file %s\n",Rfilename);
58
59    // Get AliRun object from file or create it if not on file
60    if(!gAlice) {
61       gAlice = (AliRun*)Rfile->Get("gAlice");
62       if( gAlice) printf("AliRun object found on file\n");
63       if(!gAlice) gAlice = new AliRun("gAlice","Alice test program");
64    } /* end if gAlice */
65
66    Float_t    v0[3] = {0.0,0.0,0.0};
67    Float_t    tran[3] = {0.0,0.0,0.0},rot[3] = {0.0,0.0,0.0};
68    Float_t    trans[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
69                           2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
70                           2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // cm
71    Float_t    rots[15] ={0.0E-0,1.0E-4,4.0E-4,7.0E-4,1.0E-3,
72                          2.0E-3,4.0E-3,6.0E-3,8.0E-3,1.0E-2,
73                          2.0E-2,3.0E-2,5.0E-2,7.5E-2,1.0E-1}; // rad
74    Int_t      nparticles,Ntrkp,ntrk,Itimes,Isigmas;
75    AliITS     *ITS = 0;
76    TTree      *TH = 0;
77    AliITSgeom *gm,gm2;
78    char       Hfilename[80];
79 //   char       Gfilename[80];
80    TFile      *Hfile = 0;
81    ClustAl_tl *trk = 0;
82    FILE       *fp;
83
84    for(Int_t evnt=0;evnt<=evNumber;evnt++){
85       // define some variables for later use.
86       nparticles = gAlice->GetEvent(evnt);
87       printf("nparticles %d\n",nparticles);
88       if (nparticles <= 0) continue; /* get next event */
89
90       // Get pointers to Alice detectors and Clusts containers
91       ITS   = (AliITS*)gAlice->GetDetector("ITS");
92       if(!ITS) return;          /* error no ITS data exit */
93       TH    = gAlice->TreeH();
94       Ntrkp = TH->GetEntries();
95       gm    = ITS->GetITSgeom();
96
97       // Array (stucture) of clusts for the first and second layer
98       // this should be replaced with either clusters or digits
99       // when they are proporly defined.
100       trk = new ClustAl_tl[Ntrkp];
101
102       printf("Ntrkp=%d\n",Ntrkp);
103
104       HitsToClustAl(trk,ntrk,Ntrkp,TH,ITS,1.0);
105       printf("Filled data structures ntrk=%d fitting lines next\n",ntrk);
106 //
107       for(Itimes=0;Itimes<1;Itimes++){
108           if(Itimes==0){
109               fp = fopen();
110             fprintf(fp,"Rr,Rs,Rrx1,Rerx1,Rsrx1,Rserx1,Rrz1,Rerz1,Rsrz1,Rserz1,"
111                              "Rrx2,Rerx2,Rsrx2,Rserx2,Rrz2,Rerz2,Rsrz2,Rserz2,"
112                              "Rrx3,Rerx3,Rsrx3,Rserx3,Rrz3,Rerz3,Rsrz3,Rserz3,"
113                              "Rrx4,Rerx4,Rsrx4,Rserx4,Rrz4,Rerz4,Rsrz4,Rserz4,"
114                              "Rrx5,Rerx5,Rsrx5,Rserx5,Rrz5,Rerz5,Rsrz5,Rserz5,"
115                             "Rrx6,Rerx6,Rsrx6,Rserx6,Rrz6,Rerz6,Rsrz6,Rserz6");
116           }else if(Itimes==1){
117               fp = fopen();
118             fprintf(fp,"Fr,Fs,Frx1,Ferx1,Fsrx1,Fserx1,Frz1,Ferz1,Fsrz1,Fserz1,"
119                              "Frx2,Ferx2,Fsrx2,Fserx2,Frz2,Ferz2,Fsrz2,Fserz2,"
120                              "Frx3,Ferx3,Fsrx3,Fserx3,Frz3,Ferz3,Fsrz3,Fserz3,"
121                              "Frx4,Ferx4,Fsrx4,Fserx4,Frz4,Ferz4,Fsrz4,Fserz4,"
122                              "Frx5,Ferx5,Fsrx5,Fserx5,Frz5,Ferz5,Fsrz5,Fserz5,"
123                             "Frx6,Ferx6,Fsrx6,Fserx6,Frz6,Ferz6,Fsrz6,Fserz6");
124           }else if(Itimes==2){
125               fp = fopen();
126             fprintf(fp,"Zr,Zs,Zrx1,Zerx1,Zsrx1,Zserx1,Zrz1,Zerz1,Zsrz1,Zserz1,"
127                              "Zrx2,Zerx2,Zsrx2,Zserx2,Zrz2,Zerz2,Zsrz2,Zserz2,"
128                              "Zrx3,Zerx3,Zsrx3,Zserx3,Zrz3,Zerz3,Zsrz3,Zserz3,"
129                              "Zrx4,Zerx4,Zsrx4,Zserx4,Zrz4,Zerz4,Zsrz4,Zserz4,"
130                              "Zrx5,Zerx5,Zsrx5,Zserx5,Zrz5,Zerz5,Zsrz5,Zserz5,"
131                             "Zrx6,Zerx6,Zsrx6,Zserx6,Zrz6,Zerz6,Zsrz6,Zserz6");
132           }else if(Itimes==3){
133               fp = fopen();
134             fprintf(fp,"Ar,As,Arx1,Aerx1,Asrx1,Aserx1,Arz1,Aerz1,Asrz1,Aserz1,"
135                              "Arx2,Aerx2,Asrx2,Aserx2,Arz2,Aerz2,Asrz2,Aserz2,"
136                              "Arx3,Aerx3,Asrx3,Aserx3,Arz3,Aerz3,Asrz3,Aserz3,"
137                              "Arx4,Aerx4,Asrx4,Aserx4,Arz4,Aerz4,Asrz4,Aserz4,"
138                              "Arx5,Aerx5,Asrx5,Aserx5,Arz5,Aerz5,Asrz5,Aserz5,"
139                             "Arx6,Aerx6,Asrx6,Aserx6,Arz6,Aerz6,Asrz6,Aserz6");
140           }else if(Itimes==4){
141               fp = fopen();
142             fprintf(fp,"Br,Bs,Brx1,Berx1,Bsrx1,Bserx1,Brz1,Berz1,Bsrz1,Bserz1,"
143                              "Brx2,Berx2,Bsrx2,Bserx2,Brz2,Berz2,Bsrz2,Bserz2,"
144                              "Brx3,Berx3,Bsrx3,Bserx3,Brz3,Berz3,Bsrz3,Bserz3,"
145                              "Brx4,Berx4,Bsrx4,Bserx4,Brz4,Berz4,Bsrz4,Bserz4,"
146                              "Brx5,Berx5,Bsrx5,Bserx5,Brz5,Berz5,Bsrz5,Bserz5,"
147                             "Brx6,Berx6,Bsrx6,Bserx6,Brz6,Berz6,Bsrz6,Bserz6");
148           }else if(Itimes==5){
149               fp = fopen();
150             fprintf(fp,"Cr,Cs,Crx1,Cerx1,Csrx1,Cserx1,Crz1,Cerz1,Csrz1,Cserz1,"
151                              "Crx2,Cerx2,Csrx2,Cserx2,Crz2,Cerz2,Csrz2,Cserz2,"
152                              "Crx3,Cerx3,Csrx3,Cserx3,Crz3,Cerz3,Csrz3,Cserz3,"
153                              "Crx4,Cerx4,Csrx4,Cserx4,Crz4,Cerz4,Csrz4,Cserz4,"
154                              "Crx5,Cerx5,Csrx5,Cserx5,Crz5,Cerz5,Csrz5,Cserz5,"
155                             "Crx6,Cerx6,Csrx6,Cserx6,Crz6,Cerz6,Csrz6,Cserz6")
156           } // end if
157           for(Isigmas=0;Isigmas<11;Isigmas++){
158 //
159 //        tran[0] = sigma1;
160 //        tran[1] = sigma2;
161 //        tran[2] = sigma3;
162           if(Itimes==0){ tran[0] = trans[Isigmas];
163           }else tran[0] = 0.0;
164           if(Itimes==1){ tran[1] = trans[Isigmas];
165           }else tran[1] = 0.0;
166           if(Itimes==2){ tran[2] = trans[Isigmas];
167           }else tran[2] = 0.0;
168           if(Itimes==3){ rot[0] = rots[Isigmas];
169           }else rot[0] = 0.0;
170           if(Itimes==4){ rot[1] = rots[Isigmas];
171           }else rot[1] = 0.0;
172           if(Itimes==5){ rot[2] = rots[Isigmas];
173           }else rot[2] = 0.0;
174           printf("tran= %e %e %e (cm), rot=%e %e %e (rad)\n",
175                  tran[0],tran[1],tran[2],rot[0],rot[1],rot[2]);
176 //
177           gm2 = *gm;
178           gm2.RandomCylindericalChange(tran,rot);
179
180           FillGlobalPositions(trk,ntrk,&gm2);
181           // setup to save all created histograms.
182           sprintf(Hfilename,"%s_%04.0fr%04.0fp%04.0fz%04.0fx%04.0fy%04.0fz.root",
183                   sfile,
184                   10000.*tran[0],10000.*tran[1],10000.*tran[2],
185                   10000.* rot[0],10000.* rot[1],10000.* rot[2]);
186           Hfile = (TFile*)gROOT->GetListOfFiles()->FindObject(Hfilename);
187           if(Hfile) Hfile->Close();
188           Hfile = new TFile(Hfilename,"RECREATE","Histograms from AlignITS.C");
189           printf("Histograms saved to file %s\n",Hfilename);
190           //
191           PlotGeomChanges(gm,&gm2,Hfile);
192           //
193           // fit all tracks and do a track quality hist.
194           FitAllTracks(trk,ntrk,v0,&gm2,sfile,Hfile);
195 //        FitVertexAll(trk,ntrk,sfile,Hfile); 
196           // Find all 2 track vertecies and hist. them.
197           Hfile->Close();
198           //
199       } // end for Isigmas
200           fp = fclose();
201       } // end for Itimes
202 //
203       printf("Event %d done\n",evnt);
204 //
205       deleteClustAl(trk,ntrk); // subrotine to delet memory allocated
206                                // inside HitsToclustAl.
207       delete[] trk;            // now delet memory allocated above.
208    } // end for evnt
209    Rfile->Close();
210    return;
211 }