1 #include "AliMillePedeRecord.h"
5 /**********************************************************************************************/
6 /* AliMillePedeRecords: class to store the data of single track processing */
7 /* Format: for each measured point the data is stored consequtively */
10 /* Local_param_id dResidual/dLocal_param */
12 /* -2 weight of the measurement */
13 /* Global_param_od dResidual/dGlobal_param */
16 /* The records for all processed tracks are stored in the temporary tree in orgder to be */
17 /* reused for multiple iterations of MillePede */
19 /* Author: ruben.shahoyan@cern.ch */
21 /**********************************************************************************************/
23 ClassImp(AliMillePedeRecord)
25 //_____________________________________________________________________________________________
26 AliMillePedeRecord::AliMillePedeRecord() :
27 fSize(0),fNGroups(0),fRunID(0),fGroupID(0),fIndex(0),fValue(0),fWeight(1) {SetUniqueID(0);}
29 //_____________________________________________________________________________________________
30 AliMillePedeRecord::AliMillePedeRecord(const AliMillePedeRecord& src) :
31 TObject(src),fSize(src.fSize),fNGroups(src.fNGroups),fRunID(src.fRunID),fGroupID(0),fIndex(0),fValue(0),fWeight(src.fWeight)
34 fIndex = new Int_t[GetDtBufferSize()];
35 memcpy(fIndex,src.fIndex,fSize*sizeof(Int_t));
36 fValue = new Double_t[GetDtBufferSize()];
37 memcpy(fValue,src.fValue,fSize*sizeof(Double_t));
38 fGroupID = new UShort_t[GetGrBufferSize()];
39 memcpy(fGroupID,src.fGroupID,GetGrBufferSize()*sizeof(UShort_t));
42 //_____________________________________________________________________________________________
43 AliMillePedeRecord& AliMillePedeRecord::operator=(const AliMillePedeRecord& rhs)
48 for (int i=0;i<rhs.GetSize();i++) {
51 rhs.GetIndexValue(i,ind,val);
52 AddIndexValue(ind,val);
54 fWeight = rhs.fWeight;
56 for (int i=0;i<rhs.GetNGroups();i++) MarkGroup(rhs.GetGroupID(i));
61 //_____________________________________________________________________________________________
62 AliMillePedeRecord::~AliMillePedeRecord() {delete[] fIndex; delete[] fValue; delete[] fGroupID;}
64 //_____________________________________________________________________________________________
65 void AliMillePedeRecord::Reset()
69 for (int i=fNGroups;i--;) fGroupID[i] = 0;
75 //_____________________________________________________________________________________________
76 void AliMillePedeRecord::Print(const Option_t *) const
79 if (!fSize) {AliInfo("No data"); return;}
82 if (fNGroups) printf("Groups: ");
83 for (int i=0;i<fNGroups;i++) printf("%4d |",GetGroupID(i));
84 printf("Run: %9d Weight: %+.2e\n",fRunID,fWeight);
87 Double_t resid = fValue[cnt++];
88 Double_t *derLoc = GetValue()+cnt;
89 int *indLoc = GetIndex()+cnt;
91 while(!IsWeight(cnt)) {nLoc++;cnt++;}
92 Double_t weight = GetValue(cnt++);
93 Double_t *derGlo = GetValue()+cnt;
94 int *indGlo = GetIndex()+cnt;
96 while(!IsResidual(cnt) && cnt<fSize) {nGlo++; cnt++;}
98 printf("\n*** Point#%2d | Residual = %+.4e | Weight = %+.4e\n",point++,resid,weight);
100 for (int i=0;i<nLoc;i++) printf("[%5d] %+.4e|",indLoc[i],derLoc[i]); printf("\n");
102 for (int i=0;i<nGlo;i++) printf("[%5d] %+.4e|",indGlo[i],derGlo[i]); printf("\n");
108 //_____________________________________________________________________________________________
109 Double_t AliMillePedeRecord::GetGloResWProd(Int_t indx) const
111 // get sum of derivative over global variable indx * res. at point * weight
112 if (!fSize) {AliInfo("No data"); return 0;}
114 double prodsum = 0.0;
118 Double_t resid = fValue[cnt++];
119 while(!IsWeight(cnt)) cnt++;
120 Double_t weight = GetValue(cnt++);
121 Double_t *derGlo = GetValue()+cnt;
122 int *indGlo = GetIndex()+cnt;
124 while(!IsResidual(cnt) && cnt<fSize) {nGlo++; cnt++;}
125 for (int i=nGlo;i--;) if (indGlo[i]==indx) prodsum += resid*weight*derGlo[i];
131 //_____________________________________________________________________________________________
132 Double_t AliMillePedeRecord::GetGlobalDeriv(Int_t pnt, Int_t indx) const
134 // get derivative over global variable indx at point pnt
135 if (!fSize) {AliError("No data"); return 0;}
141 while(!IsWeight(cnt)) cnt++;
143 Double_t *derGlo = GetValue()+cnt;
144 int *indGlo = GetIndex()+cnt;
146 while(!IsResidual(cnt) && cnt<fSize) {nGlo++; cnt++;}
148 if (pnt != point++) continue;
149 for (int i=nGlo;i--;) if (indGlo[i]==indx) return derGlo[i];
156 //_____________________________________________________________________________________________
157 Double_t AliMillePedeRecord::GetLocalDeriv(Int_t pnt, Int_t indx) const
159 // get derivative over local variable indx at point pnt
160 if (!fSize) {AliError("No data"); return 0;}
166 Double_t *derLoc = GetValue()+cnt;
167 int *indLoc = GetIndex()+cnt;
169 while(!IsWeight(cnt)) {nLoc++;cnt++;}
171 while(!IsResidual(cnt) && cnt<fSize) cnt++;
172 if (pnt != point++) continue;
173 for (int i=nLoc;i--;) if (indLoc[i]==indx) return derLoc[i];
180 //_____________________________________________________________________________________________
181 Double_t AliMillePedeRecord::GetResidual(Int_t pnt) const
183 // get residual at point pnt
184 if (!fSize) {AliError("No data"); return 0;}
189 Double_t resid = fValue[cnt++];
190 while(!IsWeight(cnt)) cnt++;
192 while(!IsResidual(cnt) && cnt<fSize) cnt++;
193 if (pnt != point++) continue;
200 //_____________________________________________________________________________________________
201 Double_t AliMillePedeRecord::GetWeight(Int_t pnt) const
203 // get weight of point pnt
204 if (!fSize) {AliError("No data"); return 0;}
210 while(!IsWeight(cnt)) cnt++;
211 if (point==pnt) return GetValue(cnt);;
213 while(!IsResidual(cnt) && cnt<fSize) cnt++;
220 //_____________________________________________________________________________________________
221 void AliMillePedeRecord::ExpandDtBuffer(Int_t bfsize)
223 // add extra space for derivatives data
224 bfsize = TMath::Max(bfsize,GetDtBufferSize());
225 Int_t *tmpI = new Int_t[bfsize];
226 memcpy(tmpI,fIndex, fSize*sizeof(Int_t));
230 Double_t *tmpD = new Double_t[bfsize];
231 memcpy(tmpD,fValue, fSize*sizeof(Double_t));
235 SetDtBufferSize(bfsize);
238 //_____________________________________________________________________________________________
239 void AliMillePedeRecord::ExpandGrBuffer(Int_t bfsize)
241 // add extra space for groupID data
242 bfsize = TMath::Max(bfsize,GetGrBufferSize());
243 UShort_t *tmpI = new UShort_t[bfsize];
244 memcpy(tmpI,fGroupID, fNGroups*sizeof(UShort_t));
247 for (int i=fNGroups;i<bfsize;i++) fGroupID[i] = 0;
249 SetGrBufferSize(bfsize);
252 //_____________________________________________________________________________________________
253 void AliMillePedeRecord::MarkGroup(Int_t id)
255 // mark the presence of the detector group
256 id++; // groupID is stored as realID+1
257 if (fNGroups>0 && fGroupID[fNGroups-1]==id) return; // already there
258 if (fNGroups>=GetGrBufferSize()) ExpandGrBuffer(2*(fNGroups+1));
259 fGroupID[fNGroups++] = id;