Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:38

0001 #include "TTree.h"
0002 
0003 #include "Alignment/CommonAlignment/interface/Alignable.h"
0004 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 // this class's header
0008 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentCorrelationsIORoot.h"
0009 
0010 // ----------------------------------------------------------------------------
0011 // constructor
0012 
0013 AlignmentCorrelationsIORoot::AlignmentCorrelationsIORoot() {
0014   treename = "AlignmentCorrelations";
0015   treetxt = "Correlations";
0016 }
0017 
0018 // ----------------------------------------------------------------------------
0019 
0020 void AlignmentCorrelationsIORoot::createBranches(void) {
0021   tree->Branch("Ali1Id", &Ali1Id, "Ali1Id/i");
0022   tree->Branch("Ali2Id", &Ali2Id, "Ali2Id/i");
0023   tree->Branch("Ali1ObjId", &Ali1ObjId, "Ali1ObjId/I");
0024   tree->Branch("Ali2ObjId", &Ali2ObjId, "Ali2ObjId/I");
0025   tree->Branch("corSize", &corSize, "corSize/I");
0026   tree->Branch("CorMatrix", &CorMatrix, "CorMatrix[corSize]/D");
0027 }
0028 
0029 // ----------------------------------------------------------------------------
0030 
0031 void AlignmentCorrelationsIORoot::setBranchAddresses(void) {
0032   tree->SetBranchAddress("corSize", &corSize);
0033   tree->SetBranchAddress("Ali1Id", &Ali1Id);
0034   tree->SetBranchAddress("Ali2Id", &Ali2Id);
0035   tree->SetBranchAddress("Ali1ObjId", &Ali1ObjId);
0036   tree->SetBranchAddress("Ali2ObjId", &Ali2ObjId);
0037   tree->SetBranchAddress("CorMatrix", &CorMatrix);
0038 }
0039 
0040 // ----------------------------------------------------------------------------
0041 
0042 int AlignmentCorrelationsIORoot::write(const align::Correlations& cor, bool validCheck) {
0043   int icount = 0;
0044 
0045   for (align::Correlations::const_iterator it = cor.begin(); it != cor.end(); ++it) {
0046     AlgebraicMatrix mat = (*it).second;
0047     std::pair<Alignable*, Alignable*> Pair = (*it).first;
0048     Alignable* ali1 = Pair.first;
0049     Alignable* ali2 = Pair.second;
0050     if ((ali1->alignmentParameters()->isValid() && ali2->alignmentParameters()->isValid()) || !(validCheck)) {
0051       Ali1ObjId = ali1->alignableObjectId();
0052       Ali2ObjId = ali2->alignableObjectId();
0053       Ali1Id = ali1->id();
0054       Ali2Id = ali2->id();
0055       int maxColumn = mat.num_row();
0056       corSize = maxColumn * maxColumn;
0057       for (int row = 0; row < maxColumn; row++)
0058         for (int col = 0; col < maxColumn; col++)
0059           CorMatrix[row + col * maxColumn] = mat[row][col];
0060       tree->Fill();
0061       icount++;
0062     }
0063   }
0064   edm::LogInfo("AlignmentCorrelationsIORoot") << "Writing correlations: all,written: " << cor.size() << "," << icount;
0065   return 0;
0066 }
0067 
0068 // ----------------------------------------------------------------------------
0069 // read correlations for those alignables in vector given as argument
0070 
0071 align::Correlations AlignmentCorrelationsIORoot::read(const align::Alignables& alivec, int& ierr) {
0072   align::Correlations theMap;
0073 
0074   // create ID map for all Alignables in alivec
0075   align::Alignables::const_iterator it1;
0076   std::map<std::pair<unsigned int, int>, Alignable*> idAlis;
0077   for (it1 = alivec.begin(); it1 != alivec.end(); ++it1)
0078     idAlis[std::make_pair((*it1)->id(), (*it1)->alignableObjectId())] = (*it1);
0079 
0080   std::map<std::pair<unsigned int, int>, Alignable*>::const_iterator aliSearch1;
0081   std::map<std::pair<unsigned int, int>, Alignable*>::const_iterator aliSearch2;
0082   int nfound = 0;
0083   double maxEntry = tree->GetEntries();
0084   for (int entry = 0; entry < maxEntry; entry++) {
0085     tree->GetEntry(entry);
0086     aliSearch1 = idAlis.find(std::make_pair(Ali1Id, Ali1ObjId));
0087     aliSearch2 = idAlis.find(std::make_pair(Ali2Id, Ali2ObjId));
0088     if (aliSearch1 != idAlis.end() && aliSearch2 != idAlis.end()) {
0089       // Alignables for this pair found
0090       nfound++;
0091       Alignable* myAli1 = (*aliSearch1).second;
0092       Alignable* myAli2 = (*aliSearch2).second;
0093       // FIXME: instead of nParMax in the next few lines one should probably
0094       //        use something like sqrt(corSize) - but take care of rounding!
0095       //        I have no time to test... :-( GF
0096       AlgebraicMatrix mat(nParMax, nParMax);
0097       for (int row = 0; row < nParMax; row++)
0098         for (int col = 0; col < nParMax; col++)
0099           mat[row][col] = CorMatrix[row + col * nParMax];
0100       theMap[std::make_pair(myAli1, myAli2)] = mat;
0101     }
0102   }
0103 
0104   edm::LogInfo("AlignmentCorrelationsIORoot") << "Read correlations: all,read: " << alivec.size() << "," << nfound;
0105 
0106   ierr = 0;
0107   return theMap;
0108 }