00001 #include "TTree.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "Alignment/CommonAlignment/interface/Alignable.h"
00006 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00007 #include "Alignment/HIPAlignmentAlgorithm/interface/HIPUserVariables.h"
00008
00009
00010
00011 #include "Alignment/HIPAlignmentAlgorithm/interface/HIPUserVariablesIORoot.h"
00012
00013
00014
00015
00016 HIPUserVariablesIORoot::HIPUserVariablesIORoot()
00017 {
00018 treename = "T9";
00019 treetxt = "HIP User Variables";
00020 }
00021
00022
00023
00024 void HIPUserVariablesIORoot::createBranches(void)
00025 {
00026 tree->Branch("Id", &Id, "Id/i");
00027 tree->Branch("ObjId", &ObjId, "ObjId/I");
00028
00029 tree->Branch("Nhit", &Nhit, "Nhit/I");
00030 tree->Branch("Nparj", &Nparj, "Nparj/I");
00031 tree->Branch("Jtvj", &Jtvj, "Jtvj[Nparj]/D");
00032 tree->Branch("Npare", &Npare, "Npare/I");
00033 tree->Branch("Jtve", &Jtve, "Jtve[Npare]/D");
00034 tree->Branch("AlignableChi2", &AlignableChi2, "AlignableChi2/D");
00035 tree->Branch("AlignableNdof", &AlignableNdof, "AlignableNdof/i");
00036 }
00037
00038
00039
00040 void HIPUserVariablesIORoot::setBranchAddresses(void)
00041 {
00042 tree->SetBranchAddress("Id", &Id);
00043 tree->SetBranchAddress("ObjId", &ObjId);
00044
00045 tree->SetBranchAddress("Nhit", &Nhit);
00046 tree->SetBranchAddress("Nparj", &Nparj);
00047 tree->SetBranchAddress("Jtvj", &Jtvj);
00048 tree->SetBranchAddress("Npare", &Npare);
00049 tree->SetBranchAddress("Jtve", &Jtve);
00050 tree->SetBranchAddress("AlignableChi2", &AlignableChi2);
00051 tree->SetBranchAddress("AlignableNdof", &AlignableNdof);
00052
00053 }
00054
00055
00056
00057
00058 int HIPUserVariablesIORoot::findEntry(unsigned int detId,int comp)
00059 {
00060 if (newopen) {
00061 edm::LogInfo("Alignment") <<"[HIPUserVariablesIORoot::findEntry] fill map ...";
00062 treemap.erase(treemap.begin(),treemap.end());
00063 for (int ev = 0;ev<tree->GetEntries();ev++) {
00064 tree->GetEntry(ev);
00065 treemap[std::make_pair(Id,ObjId)]=ev;
00066 }
00067 newopen=false;
00068 }
00069
00070
00071 treemaptype::iterator imap = treemap.find(std::make_pair(detId,comp));
00072 int result=-1;
00073 if (imap != treemap.end()) result=(*imap).second;
00074 return result;
00075
00076
00077
00078
00079
00080
00081
00082
00083 }
00084
00085
00086
00087 int HIPUserVariablesIORoot::writeOne(Alignable* ali)
00088 {
00089 AlignmentParameters* ap=ali->alignmentParameters();
00090
00091 if ((ap->userVariables())==0) {
00092 edm::LogError("Alignment") <<"UserVariables not found!";
00093 return -1;
00094 }
00095
00096 HIPUserVariables* uvar =
00097 dynamic_cast<HIPUserVariables*>(ap->userVariables());
00098
00099 AlgebraicSymMatrix jtvj = uvar->jtvj;
00100 AlgebraicVector jtve = uvar->jtve;
00101 int nhit=uvar->nhit;
00102 int np=jtve.num_row();
00103
00104 Nhit=nhit;
00105 Npare=np;
00106 Nparj=np*(np+1)/2;
00107 int count=0;
00108 for(int row=0;row<np;row++){
00109 Jtve[row]=jtve[row];
00110 for(int col=0;col<np;col++){
00111 if(row-1<col){Jtvj[count]=jtvj[row][col];count++;}
00112 }
00113 }
00114 Id = ali->id();
00115 ObjId = ali->alignableObjectId();
00116
00117
00118 AlignableChi2= uvar->alichi2 ;
00119 AlignableNdof= uvar->alindof ;
00120
00121 tree->Fill();
00122 return 0;
00123 }
00124
00125
00126
00127 AlignmentUserVariables* HIPUserVariablesIORoot::readOne(Alignable* ali,
00128 int& ierr)
00129 {
00130 ierr=0;
00131 HIPUserVariables* uvar;
00132
00133 int entry = findEntry(ali->id(), ali->alignableObjectId());
00134 if(entry!=-1) {
00135 tree->GetEntry(entry);
00136
00137 int np=Npare;
00138 AlgebraicVector jtve(np,0);
00139 AlgebraicSymMatrix jtvj(np,0);
00140 int count=0;
00141 for(int row=0;row<np;row++) {
00142 jtve[row]=Jtve[row];
00143 for(int col=0; col < np;col++) {
00144 if(row-1<col) {jtvj[row][col]=Jtvj[count];count++;}
00145 }
00146 }
00147
00148 uvar = new HIPUserVariables(np);
00149 uvar->jtvj=jtvj;
00150 uvar->jtve=jtve;
00151 uvar->nhit=Nhit;
00152
00153
00154 uvar->alichi2=AlignableChi2;
00155 uvar->alindof=AlignableNdof;
00156
00157 return uvar;
00158 }
00159
00160
00161 return 0 ;
00162 }
00163
00164
00165
00166 void
00167 HIPUserVariablesIORoot::writeHIPUserVariables (const Alignables& alivec,
00168 const char* filename, int iter, bool validCheck, int& ierr)
00169 {
00170 ierr=0;
00171 int iret;
00172 iret = open(filename,iter,true);
00173 if (iret!=0) { ierr=-1; return;}
00174 iret = write(alivec,validCheck);
00175 if (iret!=0) { ierr=-2; return;}
00176 iret = close();
00177 if (iret!=0) { ierr=-3; return;}
00178 }
00179
00180
00181
00182 std::vector<AlignmentUserVariables*>
00183 HIPUserVariablesIORoot::readHIPUserVariables (const Alignables& alivec,
00184 const char* filename, int iter, int& ierr)
00185 {
00186 std::vector<AlignmentUserVariables*> result;
00187 ierr=0;
00188 int iret;
00189 iret = open(filename,iter,false);
00190 if (iret!=0) { ierr=-1; return result;}
00191 result = read(alivec,iret);
00192 if (iret!=0) { ierr=-2; return result;}
00193 iret = close();
00194 if (iret!=0) { ierr=-3; return result;}
00195
00196 return result;
00197 }