1 #if !defined(__CINT__) || defined(__MAKECINT__)
4 #include <TClonesArray.h>
7 #include <TStopwatch.h>
8 #include "AliAlignObjParams.h"
9 #include "AliTrackPointArray.h"
10 #include "AliITSAlignMille.h"
13 //********************************************************************
14 // Example to run ITS alignment using Millepede
16 // Read tracks from AliTrackPoints.N.root and fill Millepede.
17 // Millepede configuration is taken from AliITSAlignMille.conf
18 // Results are written as AliAlignObjParams in outfile.
20 // Origin: M. Lunardon
21 //********************************************************************
24 int ITSAlignMille(int fromev=1, int toev=1, int fromentry=0, int nentries=-1, char *outfile="ITSAlignMille.root", char *confile="AliITSAlignMille.conf",int nreqpts=3) {
26 //AliLog::SetGlobalLogLevel(6);
28 TFile *fout=new TFile(outfile,"recreate");
29 if (!fout->IsOpen()) {
30 printf("\nCannot open output file!\n");
34 TChain *chain=new TChain("spTree");
35 char dir[100]="AliTrackPoints";
38 for (int iev=fromev; iev<=toev; iev++) {
39 sprintf(st,"%s/AliTrackPoints.%d.root",dir,iev);
43 int toentry=chain->GetEntries();
44 printf("There are %d entries in chain\n",toentry);
46 if (nentries>0 && nentries<(toentry-fromentry)) toentry=fromentry+nentries;
48 AliTrackPointArray *tpa = 0;
49 chain->SetBranchAddress("SP", &tpa);
51 ////////////////////////////////////////////
53 AliITSAlignMille *alig = new AliITSAlignMille(confile);
54 if (!alig->IsConfigured()) return -3;
56 Int_t nmod=alig->GetNModules();
57 alig->SetMinNPtsPerTrack(nreqpts);
59 // require 4 points in SPD (one per layer, up and down)
61 alig->SetRequiredPoint("LAYER",1,1,1);
62 alig->SetRequiredPoint("LAYER",1,-1,1);
63 alig->SetRequiredPoint("LAYER",2,1,1);
64 alig->SetRequiredPoint("LAYER",2,-1,1);
67 // correction for SSD bug (1) : inverisione sensor 18 e 19
70 Double_t *parameters = new Double_t[nmod*6];
71 Double_t *errors = new Double_t[nmod*6];
72 Double_t *pulls = new Double_t[nmod*6];
74 for(Int_t k=0;k<nmod*6;k++) {
80 // need array with size fNLocal*2
81 Double_t trackParams[10] = {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
82 alig->InitGlobalParameters(parameters);
85 Double_t sigmatra=alig->GetParSigTranslations();
86 Double_t sigmarot=alig->GetParSigRotations();
87 ////////////////////////////////////////////////////////////////////
94 int iTrackOk=0; // number of good passed track
95 // loop on spTree entries
96 // one entry = one track
97 for (int i=fromentry; i<toentry; i++) {
100 if (!alig->ProcessTrack(tpa)) {
102 printf("Calling LocalFit n. %d\n",iTrackOk);
103 alig->LocalFit(iTrackOk++,trackParams,0);
106 printf("\nMillepede fed with %d tracks\n",iTrackOk);
107 printf("Total number of rejected points because of bad EqLoc : %d\n\n",alig->GetTotBadLocEqPoints());
113 alig->GlobalFit(parameters,errors,pulls);
115 cout << "Done with GlobalFit " << endl;
117 ////////////////////////////////////////////////////////////
120 printf("\nProcessed points statistics:\n");
123 printf("\nOutput values and point statistics:\n\n");
124 for (int i=0; i<nmod; i++) {
125 Int_t statm=alig->GetProcessedPoints()[i];
126 if (statm>maxstat) maxstat=statm;
127 printf("index: %-4d stat: %-7d pars: %f %f %f %f %f %f\n",alig->GetModuleIndexArray()[i], statm,
136 FILE *pf=fopen("ITSAlignMille.out","w");
138 fprintf(pf,"# param dx dy dz dpsi dtheta dphi\n");
139 for (int i=0; i<nmod; i++) {
140 fprintf(pf," %-5d %-10f %-10f %-10f %-10f %-10f %-10f\n",i,
152 printf("Max statistics = %d\n",maxstat);
154 printf("No points for alignment! quitting now...\n");
158 TClonesArray *array = new TClonesArray("AliAlignObjParams",4000);
159 TClonesArray &alobj = *array;
162 new(alobj[0]) AliAlignObjParams("ITS", 0, 0., 0., 0., 0., 0., 0., kTRUE);
166 Double_t dx,dy,dz,dpsi,dtheta,dphi;
168 Double_t deltalocal[6];
171 AliAlignObjParams *tmpa=NULL;
173 // quality factor: 0 = NOT ALIGNED or OFF
174 // N = ALIGNED with statistics = N
177 // all ITS sensitive modules
178 for (int idx=0; idx<2198; idx++) {
179 volid=AliITSAlignMilleModule::GetVolumeIDFromIndex(idx);
180 symname = AliGeomManager::SymName(volid);
181 // default null misalignment
182 for (int jj=0;jj<21;jj++) corr[jj]=0.0;
183 for (int jj=0;jj<3;jj++) {t[jj]=0.0;r[jj]=0.0;}
186 if (alig->IsContained(volid)>=0) { // defined modules or inside a supermodule
187 alig->SetCurrentModule(idx); // set the supermodule that contains idx
188 int iidx=alig->GetCurrentModuleInternalIndex();
190 // check if all 6 parameters have been evaluated by millepede
193 for (int kk=0; kk<6; kk++) {
195 if (kk>2) parsig=sigmarot;
196 if (pulls[iidx*6+kk]==0.0 && errors[iidx*6+kk]==parsig) isoff=1;
199 // check if module was fixed
201 for (int kk=0; kk<6; kk++) {
202 if (parameters[iidx*6+kk]!=0.0 || pulls[iidx*6+kk]!=0.0 || errors[iidx*6+kk]!=0.0) isfixed=0;
205 if (!isoff && !isfixed) { // OK, has been evaluated
206 deltalocal[0] = parameters[iidx*6+0];
207 deltalocal[1] = parameters[iidx*6+1];
208 deltalocal[2] = parameters[iidx*6+2];
209 deltalocal[3] = parameters[iidx*6+3];
210 deltalocal[4] = parameters[iidx*6+4];
211 deltalocal[5] = parameters[iidx*6+5];
212 tmpa = alig->GetCurrentModule()->GetSensitiveVolumeMisalignment(volid,deltalocal);
214 printf("error transforming millepede parameters for module %d\n",idx);
218 // at the moment sigma of supermodule is given to sensitive modules. to be fixed...
219 corr[0] = errors[iidx*6+0]*errors[iidx*6+0];
220 corr[2] = errors[iidx*6+1]*errors[iidx*6+1];
221 corr[5] = errors[iidx*6+2]*errors[iidx*6+2];
222 corr[9] = errors[iidx*6+3]*errors[iidx*6+3];
223 corr[14]= errors[iidx*6+4]*errors[iidx*6+4];
224 corr[20]= errors[iidx*6+5]*errors[iidx*6+5];
225 Int_t statm=alig->GetProcessedPoints()[iidx];
230 printf("Module %d is OFF!\n",idx);
234 printf("Module %d was FIXED!\n",idx);
235 if (alig->GetPreAlignmentQualityFactor(idx)>0)
236 QF=alig->GetPreAlignmentQualityFactor(idx);
244 new(alobj[idx+1]) AliAlignObjParams(symname,volid,t[0],t[1],t[2],r[0],r[1],r[2],kFALSE);
245 AliAlignObjParams* alo = (AliAlignObjParams*) array->UncheckedAt(idx+1);
246 alo->SetCorrMatrix(corr);
247 alo->SetUniqueID(QF);
250 fout->WriteObject(array,"ITSAlignObjs","kSingleKey");