CMS 3D CMS Logo

HIPUserVariablesIORoot.cc

Go to the documentation of this file.
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 // this class's header
00011 #include "Alignment/HIPAlignmentAlgorithm/interface/HIPUserVariablesIORoot.h"
00012 
00013 // ----------------------------------------------------------------------------
00014 // constructor
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 }
00035 
00036 // ----------------------------------------------------------------------------
00037 
00038 void HIPUserVariablesIORoot::setBranchAddresses(void) 
00039 {
00040   tree->SetBranchAddress("Id",        &Id);
00041   tree->SetBranchAddress("ObjId",     &ObjId);
00042 
00043   tree->SetBranchAddress("Nhit",      &Nhit);
00044   tree->SetBranchAddress("Nparj",     &Nparj);
00045   tree->SetBranchAddress("Jtvj",      &Jtvj);
00046   tree->SetBranchAddress("Npare",     &Npare);
00047   tree->SetBranchAddress("Jtve",      &Jtve);
00048 }
00049 
00050 // ----------------------------------------------------------------------------
00051 // find tree entry based on detID and typeID
00052 
00053 int HIPUserVariablesIORoot::findEntry(unsigned int detId,int comp)
00054 {
00055   if (newopen) { // we're here first time
00056     edm::LogInfo("Alignment") <<"[HIPUserVariablesIORoot::findEntry] fill map ...";
00057     treemap.erase(treemap.begin(),treemap.end());
00058     for (int ev = 0;ev<tree->GetEntries();ev++) {
00059       tree->GetEntry(ev); 
00060       treemap[std::make_pair(Id,ObjId)]=ev;
00061     }
00062     newopen=false;
00063   }
00064   
00065   // now we have filled the map
00066   treemaptype::iterator imap = treemap.find(std::make_pair(detId,comp));
00067   int result=-1;
00068   if (imap != treemap.end()) result=(*imap).second;
00069   return result;
00070 
00071 
00072   //double noAliPar = tree->GetEntries();
00073   //for (int ev = 0;ev<noAliPar;ev++) {
00074   //  tree->GetEntry(ev); 
00075   //  if(Id==detId&&comp==ObjId) return (ev);
00076   //}
00077   //return(-1);
00078 }
00079 
00080 // ----------------------------------------------------------------------------
00081 
00082 int HIPUserVariablesIORoot::writeOne(Alignable* ali)
00083 {
00084   AlignmentParameters* ap=ali->alignmentParameters();
00085 
00086   if ((ap->userVariables())==0) { 
00087     edm::LogError("Alignment") <<"UserVariables not found!"; 
00088     return -1; 
00089   }
00090 
00091   HIPUserVariables* uvar = 
00092     dynamic_cast<HIPUserVariables*>(ap->userVariables());
00093 
00094   AlgebraicSymMatrix jtvj = uvar->jtvj;
00095   AlgebraicVector jtve = uvar->jtve;
00096   int nhit=uvar->nhit;
00097   int np=jtve.num_row();
00098 
00099   Nhit=nhit;
00100   Npare=np;
00101   Nparj=np*(np+1)/2;
00102   int count=0;
00103   for(int row=0;row<np;row++){
00104     Jtve[row]=jtve[row];
00105     for(int col=0;col<np;col++){
00106       if(row-1<col){Jtvj[count]=jtvj[row][col];count++;}
00107     }
00108   }
00109   Id = ali->id();
00110   ObjId = ali->alignableObjectId();
00111 
00112   tree->Fill();
00113   return 0;
00114 }
00115 
00116 // ----------------------------------------------------------------------------
00117 
00118 AlignmentUserVariables* HIPUserVariablesIORoot::readOne(Alignable* ali, 
00119   int& ierr)
00120 {
00121   ierr=0;
00122   HIPUserVariables* uvar;
00123 
00124   int entry = findEntry(ali->id(), ali->alignableObjectId());
00125   if(entry!=-1) {
00126     tree->GetEntry(entry);
00127 
00128     int np=Npare;
00129     AlgebraicVector jtve(np,0);
00130     AlgebraicSymMatrix jtvj(np,0);
00131     int count=0;
00132     for(int row=0;row<np;row++) {
00133       jtve[row]=Jtve[row];
00134       for(int col=0; col < np;col++) {
00135         if(row-1<col) {jtvj[row][col]=Jtvj[count];count++;}
00136       }
00137     } 
00138 
00139     uvar = new HIPUserVariables(np);
00140     uvar->jtvj=jtvj;
00141     uvar->jtve=jtve;
00142     uvar->nhit=Nhit;
00143 
00144     return uvar;
00145   }
00146 
00147   //  ierr=-1;
00148   return 0 ;
00149 }
00150 
00151 //-----------------------------------------------------------------------------
00152 
00153 void 
00154 HIPUserVariablesIORoot::writeHIPUserVariables (const Alignables& alivec, 
00155   const char* filename, int iter, bool validCheck, int& ierr)
00156 {
00157   ierr=0;
00158   int iret;
00159   iret = open(filename,iter,true);
00160   if (iret!=0) { ierr=-1; return;}
00161   iret = write(alivec,validCheck);
00162   if (iret!=0) { ierr=-2; return;}
00163   iret = close();
00164   if (iret!=0) { ierr=-3; return;}
00165 }
00166 
00167 //-----------------------------------------------------------------------------
00168 
00169 std::vector<AlignmentUserVariables*> 
00170 HIPUserVariablesIORoot::readHIPUserVariables (const Alignables& alivec, 
00171   const char* filename, int iter, int& ierr)
00172 {
00173   std::vector<AlignmentUserVariables*> result;
00174   ierr=0;
00175   int iret;
00176   iret = open(filename,iter,false);
00177   if (iret!=0) { ierr=-1; return result;}
00178   result = read(alivec,iret);
00179   if (iret!=0) { ierr=-2; return result;}
00180   iret = close();
00181   if (iret!=0) { ierr=-3; return result;}
00182 
00183   return result;
00184 }

Generated on Tue Jun 9 17:24:02 2009 for CMSSW by  doxygen 1.5.4