fRecord(0),
fDataRecFile(0),
fTreeData(0),
+ fRecFileStatus(0),
//
fConstrRecFName("/tmp/mp2_constraints_records.root"),
fTreeConstr(0),
fInitPar(0),fDeltaPar(0),fSigmaPar(0),fIsLinear(0),fConstrUsed(0),fGlo2CGlo(0),fCGlo2Glo(0),
fMatCLoc(0),fMatCGlo(0),fMatCGloLoc(0),fFillIndex(0),fFillValue(0),
fDataRecFName(0),fRecord(0),fDataRecFile(0),
- fTreeData(0),fConstrRecFName(0),fTreeConstr(0),fConsRecFile(0),fCurrRecDataID(0),
+ fTreeData(0),fRecFileStatus(0),fConstrRecFName(0),fTreeConstr(0),fConsRecFile(0),fCurrRecDataID(0),
fCurrRecConstrID(0),fLocFitAdd(kTRUE)
{printf("Dummy\n");}
if (!fRecord) fRecord = new AliMillePedeRecord();
//
fDataRecFile = TFile::Open(GetDataRecFName(),read ? "":"recreate");
- if (!fDataRecFile) {AliInfo(Form("Failed to initialize data records file %s",GetDataRecFName())); return kFALSE;}
+ if (!fDataRecFile) {AliFatal(Form("Failed to initialize data records file %s",GetDataRecFName())); return kFALSE;}
//
AliInfo(Form("File %s used for derivatives records",GetDataRecFName()));
if (read) {
fTreeData = (TTree*)fDataRecFile->Get("AliMillePedeRecords_Data");
- if (!fTreeData) {AliInfo(Form("Did not find data records tree in %s",GetDataRecFName())); return kFALSE;}
+ if (!fTreeData) {AliFatal(Form("Did not find data records tree in %s",GetDataRecFName())); return kFALSE;}
fTreeData->SetBranchAddress("Record_Data",&fRecord);
AliInfo(Form("Found %d derivatives records",fTreeData->GetEntries()));
}
fTreeData->Branch("Record_Data","AliMillePedeRecord",&fRecord,32000,99);
}
fCurrRecDataID = -1;
+ fRecFileStatus = read ? 1:2;
//
return kTRUE;
}
delete fDataRecFile;
fDataRecFile = 0;
}
+ fRecFileStatus = 0;
//
}
return kTRUE;
}
+//_____________________________________________________________________________________________
+void AliMillePede2::SetRecordWeight(double wgh)
+{
+ if (fRecFileStatus<2) InitDataRecStorage(); // create a buffer to store the data
+ fRecord->SetWeight(wgh);
+}
+
//_____________________________________________________________________________________________
void AliMillePede2::SetLocalEquation(double *dergb, double *derlc, double lMeas, double lSigma)
{
- if (!fDataRecFile || !fDataRecFile->IsWritable()) InitDataRecStorage(); // create a buffer to store the data
+ if (fRecFileStatus<2) InitDataRecStorage(); // create a buffer to store the data
//
// write data of single measurement
if (lSigma<=0.0) { // If parameter is fixed, then no equation
return;
}
//
- if (!fDataRecFile || !fDataRecFile->IsWritable()) InitDataRecStorage(); // create a buffer to store the data
+ if (fRecFileStatus<2) InitDataRecStorage(); // create a buffer to store the data
//
fRecord->AddResidual(lMeas);
//
}
double vl;
//
+ double gloWgh = fRecord->GetWeight(); // global weight for this set
Int_t maxLocUsed = 0;
//
for (int ip=nPoints;ip--;) { // Transfer the measurement records to matrices
double resid = fRecord->GetValue( refLoc[ip]-1 );
- double weight = fRecord->GetValue( refGlo[ip]-1 );
+ double weight = fRecord->GetValue( refGlo[ip]-1 )*gloWgh;
double *derLoc = fRecord->GetValue()+refLoc[ip];
double *derGlo = fRecord->GetValue()+refGlo[ip];
int *indLoc = fRecord->GetIndex()+refLoc[ip];
int *indGlo = fRecord->GetIndex()+refGlo[ip];
//
- for (int i=nrefGlo[ip];i--;) { // suppress the global part (only relevant with iterations)
+ for (int i=nrefGlo[ip];i--;) { // suppress the global part (only relevant with iterations)
int iID = indGlo[i]; // Global param indice
if (fSigmaPar[iID]<=0.) continue; // fixed parameter RRRCheck
if (fIsLinear[iID]) resid -= derGlo[i]*(fInitPar[iID]+fDeltaPar[iID]); // linear parameter
//
// first try to solve by faster Cholesky decomposition, then by Gaussian elimination
if (!matCLoc.SolveChol(fVecBLoc,kTRUE)) {
- AliInfo("Failed to solve locals by Cholesky, traying Gaussian Elimination");
+ AliInfo("Failed to solve locals by Cholesky, trying Gaussian Elimination");
if (!matCLoc.SolveSpmInv(fVecBLoc,kTRUE)) {
AliInfo("Failed to solve locals by Gaussian Elimination, skip...");
matCLoc.Print("d");
//
for (int ip=nPoints;ip--;) { // Calculate residuals
double resid = fRecord->GetValue( refLoc[ip]-1 );
- double weight = fRecord->GetValue( refGlo[ip]-1 );
+ double weight = fRecord->GetValue( refGlo[ip]-1 )*gloWgh;
double *derLoc = fRecord->GetValue()+refLoc[ip];
double *derGlo = fRecord->GetValue()+refGlo[ip];
int *indLoc = fRecord->GetIndex()+refLoc[ip];
nEq++; // number of equations
} // end of Calculate residuals
//
+ lChi2 /= gloWgh;
int nDoF = nEq-maxLocUsed;
lChi2 = (nDoF>0) ? lChi2/nDoF : 0; // Chi^2/dof
//
//
for (int ip=nPoints;ip--;) { // Update matrices
double resid = fRecord->GetValue( refLoc[ip]-1 );
- double weight = fRecord->GetValue( refGlo[ip]-1 );
+ double weight = fRecord->GetValue( refGlo[ip]-1 )*gloWgh;
double *derLoc = fRecord->GetValue()+refLoc[ip];
double *derGlo = fRecord->GetValue()+refGlo[ip];
int *indLoc = fRecord->GetIndex()+refLoc[ip];
if (fProcPnt[i]<1) {
fNGloFix++;
fVecBGlo[i] = 0.;
- matCGlo.DiagElem(i) = float(fNLocEquations*fNLocEquations);
+ matCGlo.DiagElem(i) = 1.;//float(fNLocEquations*fNLocEquations);
}
else matCGlo.DiagElem(i) += (fgWeightSigma ? fProcPnt[i] : 1.)/(fSigmaPar[i]*fSigmaPar[i]);
}
void SetGlobalConstraint(const int *indgb,double *dergb, int ngb, double val, double sigma=0);
//
// processing of the local measurement
+ void SetRecordWeight(double wgh);
void SetLocalEquation(double *dergb, double *derlc, double lMeas, double lSigma);
void SetLocalEquation(int *indgb, double *dergb, int ngb, int *indlc,
double *derlc,int nlc,double lMeas,double lSigma);
AliMillePedeRecord *fRecord; // Buffer of measurements records
TFile *fDataRecFile; // File of processed measurements records
TTree *fTreeData; // Tree of processed measurements records
+ Int_t fRecFileStatus; // state of the record file (0-no, 1-read, 2-rw)
//
TString fConstrRecFName; // Name of File for constraints records
TTree *fTreeConstr; // Tree of constraint records
//_____________________________________________________________________________________________
AliMillePedeRecord::AliMillePedeRecord(const AliMillePedeRecord& src) :
- TObject(src),fSize(src.fSize),fNGroups(src.fNGroups),fGroupID(0),fIndex(0),fValue(0)
+ TObject(src),fSize(src.fSize),fNGroups(src.fNGroups),fGroupID(0),fIndex(0),fValue(0),fWeight(src.fWeight)
{
fIndex = new Int_t[GetDtBufferSize()];
memcpy(fIndex,src.fIndex,fSize*sizeof(Int_t));
fValue = new Double_t[GetDtBufferSize()];
memcpy(fValue,src.fValue,fSize*sizeof(Double_t));
- fGroupID = new Int_t[GetGrBufferSize()];
- memcpy(fGroupID,src.fGroupID,GetGrBufferSize()*sizeof(Int_t));
+ fGroupID = new UShort_t[GetGrBufferSize()];
+ memcpy(fGroupID,src.fGroupID,GetGrBufferSize()*sizeof(UShort_t));
}
//_____________________________________________________________________________________________
rhs.GetIndexValue(i,ind,val);
AddIndexValue(ind,val);
}
+ fWeight = rhs.fWeight;
for (int i=0;i<rhs.GetNGroups();i++) MarkGroup(rhs.GetGroupID(i));
}
return *this;
void AliMillePedeRecord::Reset()
{
fSize = 0;
- for (int i=fNGroups;i--;) fGroupID[i] = -1;
+ for (int i=fNGroups;i--;) fGroupID[i] = 0;
fNGroups = 0;
+ fWeight = 1.;
}
//_____________________________________________________________________________________________
int cnt=0,point=0;
//
if (fNGroups) printf("Groups: ");
- for (int i=0;i<fNGroups;i++) printf("%4d |",GetGroupID(i)); printf("\n");
+ for (int i=0;i<fNGroups;i++) printf("%4d |",GetGroupID(i));
+ printf(" Weight: %+.2e\n",fWeight);
while(cnt<fSize) {
//
Double_t resid = fValue[cnt++];
{
// add extra space for groupID data
bfsize = TMath::Max(bfsize,GetGrBufferSize());
- Int_t *tmpI = new Int_t[bfsize];
- memcpy(tmpI,fGroupID, fNGroups*sizeof(Int_t));
- delete fGroupID;
+ UShort_t *tmpI = new UShort_t[bfsize];
+ memcpy(tmpI,fGroupID, fNGroups*sizeof(UShort_t));
+ delete[] fGroupID;
fGroupID = tmpI;
- for (int i=fNGroups;i<bfsize;i++) fGroupID[i] = -1;
+ for (int i=fNGroups;i<bfsize;i++) fGroupID[i] = 0;
//
SetGrBufferSize(bfsize);
}
void AliMillePedeRecord::MarkGroup(Int_t id)
{
// mark the presence of the detector group
+ id++; // groupID is stored as realID+1
if (fNGroups>0 && fGroupID[fNGroups-1]==id) return; // already there
if (fNGroups>=GetGrBufferSize()) ExpandGrBuffer(2*(fNGroups+1));
fGroupID[fNGroups++] = id;
}
-//_____________________________________________________________________________________________
-Bool_t AliMillePedeRecord::IsGroupPresent(Int_t id) const
-{
- for (int i=fNGroups;i--;) if (GetGroupID(i)==id) return kTRUE;
- return kFALSE;
-}
void AddIndexValue(Int_t ind, Double_t val);
void AddResidual(Double_t val) {AddIndexValue(-1,val);}
void AddWeight(Double_t val) {AddIndexValue(-2,val);}
+ void SetWeight(Double_t w=1) {fWeight = w;}
Bool_t IsResidual(Int_t i) const {return fIndex[i]==-1;}
Bool_t IsWeight(Int_t i) const {return fIndex[i]==-2;}
//
Double_t *GetValue() const {return fValue;}
Double_t GetValue(Int_t i) const {return fValue[i];}
+ Double_t GetWeight() const {return fWeight;}
//
void MarkGroup(Int_t id);
Int_t GetNGroups() const {return fNGroups;}
- Int_t GetGroupID(Int_t i) const {return fGroupID[i];}
+ Int_t GetGroupID(Int_t i) const {return fGroupID[i]-1;}
Bool_t IsGroupPresent(Int_t id) const;
//
protected:
protected:
Int_t fSize; // size of the record
Int_t fNGroups; // number of groups (e.g. detectors) contributing
- Int_t * fGroupID; //[fNGroups] groups id's (in increasing order)
+ UShort_t* fGroupID; //[fNGroups] groups id's+1 (in increasing order)
Int_t * fIndex; //[fSize] index of variables
- Double_t* fValue; //[fSize] array of values: derivs,residuals
+ Double32_t* fValue; //[fSize] array of values: derivs,residuals
+ Double32_t fWeight; //global weight for the record
//
- ClassDef(AliMillePedeRecord,1) // Record of track residuals and local/global deriavtives
+ ClassDef(AliMillePedeRecord,2) // Record of track residuals and local/global deriavtives
};
+//_____________________________________________________________________________________________
inline void AliMillePedeRecord::AddIndexValue(Int_t ind, Double_t val)
{
+ // add new pair of index/value
if (fSize>=GetDtBufferSize()) ExpandDtBuffer(2*(fSize+1));
fIndex[fSize]=ind;
fValue[fSize++]=val;
}
+//_____________________________________________________________________________________________
+inline Bool_t AliMillePedeRecord::IsGroupPresent(Int_t id) const
+{
+ // check if group is defined
+ id++;
+ for (int i=fNGroups;i--;) if (fGroupID[i]==id) return kTRUE;
+ return kFALSE;
+}
+
#endif