CMS 3D CMS Logo

RPCRawSynchro.cc

Go to the documentation of this file.
00001 #include "EventFilter/RPCRawToDigi/interface/RPCRawSynchro.h"
00002 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <iomanip>
00007 #include <cmath>
00008 #include "TH2D.h"
00009 #include "TH1D.h"
00010 
00011 
00012 
00013 using namespace rpcrawtodigi;
00014 using namespace std;
00015 
00016 struct lessVectSum {
00017   bool operator () (const pair<unsigned int, unsigned int> & o1,
00018                     const pair<unsigned int, unsigned int> & o2) {
00019     return o1.second < o2.second;
00020   };
00021 };
00022 
00023 
00024 
00025 bool RPCRawSynchro::lessLB::operator () (const LinkBoardElectronicIndex& lb1, 
00026       const LinkBoardElectronicIndex& lb2) const
00027 {
00028   if (lb1.dccId < lb2.dccId) return true;
00029   if (    (lb1.dccId==lb2.dccId)
00030        && (lb1.dccInputChannelNum< lb2.dccInputChannelNum) ) return true;
00031   if (    (lb1.dccId==lb2.dccId)
00032        && (lb1.dccInputChannelNum == lb2.dccInputChannelNum)
00033        && (lb1.tbLinkInputNum < lb2.tbLinkInputNum ) ) return true;
00034   if (    (lb1.dccId==lb2.dccId)
00035        && (lb1.dccInputChannelNum == lb2.dccInputChannelNum)
00036        && (lb1.tbLinkInputNum == lb2.tbLinkInputNum )
00037        && (lb1.lbNumInLink < lb2.lbNumInLink) ) return true;
00038   return false;
00039 }
00040 
00041 int RPCRawSynchro::bxDifference(const EventRecords & event)
00042 {
00043   static const int nOrbits = 3564;
00044   int diff = event.recordBX().bx() - event.triggerBx() + 3;
00045   if (diff >  nOrbits/2) diff -=nOrbits;
00046   if (diff < -nOrbits/2) diff +=nOrbits;
00047   return diff;
00048 }
00049 
00050 void RPCRawSynchro::add(const ProdItem & vItem)
00051 {
00052   for (ProdItem::const_iterator it = vItem.begin(); it != vItem.end(); ++it) { 
00053     const LinkBoardElectronicIndex & key = it->first;
00054     int bxDiff = it->second;
00055     if (theSynchroCounts.find(key)==theSynchroCounts.end()) theSynchroCounts[key]=vector<int>(8,0);
00056     vector<int> & v = theSynchroCounts[key];
00057     if (bxDiff < 0) continue;
00058     if (bxDiff > 7) continue;
00059     v[bxDiff]++;
00060   }
00061 }
00062 
00063 std::string RPCRawSynchro::dumpDccBx(int dcc, TH1D * histo) const
00064 {
00065   typedef std::map<int,std::vector<int> > CountMap;
00066   CountMap bxCounts;
00067   std::ostringstream str;
00068 
00069   for (int rmb=0; rmb <=35; rmb++)  bxCounts[rmb]=vector<int>(8,0);
00070   
00071   for (LBCountMap::const_iterator im = theSynchroCounts.begin(); im != theSynchroCounts.end(); ++im) {
00072     const LinkBoardElectronicIndex & ele = im->first;
00073     if (ele.dccId!= dcc) continue;
00074     vector<int> & v = bxCounts[ele.dccInputChannelNum];
00075     const vector<int> & vSyncro = im->second;
00076     for (int i=0; i<8;++i) v[i] += vSyncro[i]; 
00077   }
00078 
00079   for (CountMap::const_iterator im=bxCounts.begin(); im!= bxCounts.end(); ++im) {
00080     int totCount=0;
00081     for (unsigned int i=0; i<im->second.size(); i++) totCount +=  im->second[i];
00082     if (totCount>0) {
00083       str<<"dcc="<<setw(3)<<dcc<<" rmb="<<setw(3)<<im->first<<" counts: ";
00084       for (unsigned int i=0; i<im->second.size(); i++) str<<" "<<setw(6)<<im->second[i];
00085       for (unsigned int i=0; i<im->second.size(); i++) histo->Fill(double(i)-3., double(im->second[i]));
00086       str<<endl;
00087     }
00088   }
00089   return str.str();
00090 }
00091 
00092 std::string RPCRawSynchro::dumpDelays(const RPCReadOutMapping *rm, TH2D * histo) const
00093 {
00094   std::ostringstream sss;
00095 
00096   vector< std::vector<int> > vectRes;
00097   vector< string > vectNamesCh;
00098   vector< string > vectNamesPart;
00099   vector< string > vectNamesLink;
00100   vector< float > vectMean;
00101   vector< pair<unsigned int, unsigned int> > vectSums;
00102   vector< float > vectRMS;
00103   for (LBCountMap::const_iterator im = theSynchroCounts.begin(); im != theSynchroCounts.end(); ++im) {
00104     const LinkBoardSpec* linkBoard = rm->location(im->first);
00105     if (linkBoard==0) continue;
00106     float sumW =0.;
00107     unsigned  int stat = 0;
00108     for (unsigned int i=0; i<im->second.size(); i++) {
00109       stat += im->second[i];
00110       sumW += i*im->second[i];
00111     }
00112     float mean = sumW/stat;
00113     float rms2 = 0.;
00114     for (unsigned int i=0; i<im->second.size(); i++) rms2 += im->second[i]*(mean-i)*(mean-i);
00115 //    vector<string> chnames;
00116 //    for (vector<FebConnectorSpec>::const_iterator ifs = linkBoard->febs().begin(); ifs !=  linkBoard->febs().end(); ++ifs) {
00117 //      vector<string>::iterator immm = find(chnames.begin(),chnames.end(),ifs->chamber().chamberLocationName);
00118 //      if (immm == chnames.end()) chnames.push_back(ifs->chamber().chamberLocationName);
00119 //    }
00120     const ChamberLocationSpec & chamber = linkBoard->febs().front().chamber();
00121     const FebLocationSpec & feb =  linkBoard->febs().front().feb();
00122     sss <<chamber.chamberLocationName
00123         <<" "<< feb.localEtaPartition
00124         <<" mean: "<<mean <<" rms: " << sqrt(rms2/stat)
00125         << im->first.print();
00126         for (unsigned int i=0; i<im->second.size(); i++) sss<<" "<<setw(6)<<im->second[i];
00127 //      if (chnames.size() >1) { sss<<" *****"; for (unsigned int i=0; i<chnames.size();++i) sss<<" "<<chnames[i]; }
00128         sss<<std::endl;
00129 
00130     unsigned int idx = 0;
00131     while (idx < vectNamesCh.size()) {
00132       if (vectNamesCh[idx] == chamber.chamberLocationName && vectNamesPart[idx] == feb.localEtaPartition) break;
00133       idx++;
00134     }
00135     if (idx == vectNamesCh.size()) {
00136 
00137       vectRes.push_back(im->second);
00138       vectNamesCh.push_back(chamber.chamberLocationName);
00139       vectNamesPart.push_back(feb.localEtaPartition);
00140       vectNamesLink.push_back(im->first.print());
00141       vectSums.push_back(make_pair(idx,stat));
00142       vectMean.push_back(mean);
00143       vectRMS.push_back(sqrt(rms2/stat));
00144     }
00145   }
00146 
00147   sss <<endl<<endl<<"GOING TO WRITE: " << endl;
00148   sort(vectSums.begin(), vectSums.end(), lessVectSum() );
00149   for (vector<std::pair<unsigned int, unsigned int> >::const_iterator it = vectSums.begin();
00150        it != vectSums.end(); ++it) {
00151 
00152     unsigned int iindex = it->first;
00153 
00154     histo->Fill(vectMean[iindex]-3., vectRMS[iindex]);
00155     sss <<  vectNamesCh[iindex] <<" "
00156         << vectNamesPart[iindex]  <<" mean: "<<vectMean[iindex]<<" rms: "
00157         << vectRMS[iindex] << vectNamesLink[iindex];
00158     for (unsigned int i=0;  i< vectRes[iindex].size(); ++i) sss <<" "<<setw(6)<<vectRes[iindex][i];
00159 
00160     sss <<endl;
00161 
00162   }
00163   return sss.str();
00164 }
00165 

Generated on Tue Jun 9 17:34:47 2009 for CMSSW by  doxygen 1.5.4