Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:00

0001 #include <fstream>
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005 #include <cassert>
0006 #include <map>
0007 #include <vector>
0008 #include <cmath>
0009 
0010 #include "TH1F.h"
0011 #include "TH2F.h"
0012 #include "TProfile.h"
0013 #include "TLegend.h"
0014 #include "TFile.h"
0015 #include "TCanvas.h"
0016 #include "TROOT.h"
0017 #include "TStyle.h"
0018 #include "TString.h"
0019 #include "TDirectory.h"
0020 
0021 //struct Clusters {
0022 //  unsigned int nEvents;
0023 //  double mean;
0024 //  double meanErr;
0025 //};
0026 
0027 int main(int argc, char** argv) {//main
0028 
0029   if (argc < 6){
0030     std::cout << "Usage: " << argv[0] 
0031           << " <path to file (paths available given in getCommand script)> <first run (0=all)> <last run (0=all)> <total number of runs> <run number list>"  
0032           << std::endl;
0033     return 0;
0034   }
0035   std::string lPath = argv[1];
0036   
0037   bool lAfsFiles = true;
0038 
0039   if (lPath.find("/afs") == lPath.npos) lAfsFiles = false;
0040 
0041   std::string lFolder = lPath.substr(lPath.find("xxxx")-5,9);
0042   if (lAfsFiles) lFolder += "_afs";
0043   std::cout << " -- Folder = " << lFolder << std::endl;
0044   
0045   unsigned int nRuns;
0046   std::istringstream(argv[4])>>nRuns;
0047 
0048   unsigned int lRunMin=0;
0049   unsigned int lRunMax=10000000;
0050   std::istringstream(argv[2])>>lRunMin;
0051   std::istringstream(argv[3])>>lRunMax;
0052 
0053   if (lRunMax==0) lRunMax=10000000;
0054 
0055   std::vector<unsigned int> runs;
0056   const unsigned int nHistsDetailed = 5;
0057 
0058   std::map<unsigned int,std::vector<std::pair<unsigned int,float> > > lMap[nHistsDetailed];
0059   std::pair<std::map<unsigned int,std::vector<std::pair<unsigned int,float> > >::iterator,bool> lMapIter;
0060   std::map<unsigned int,std::vector<std::pair<unsigned int,float> > > lMapRun[nHistsDetailed];
0061   std::pair<std::map<unsigned int,std::vector<std::pair<unsigned int,float> > >::iterator,bool> lMapRunIter;
0062 
0063   std::map<unsigned int,double> lMapFED; 
0064   std::map<unsigned int,std::pair<double,double> > lMapFEDChannels; 
0065   std::map<unsigned int,std::pair<double,double> > lMapChannels; 
0066   std::map<unsigned int,std::pair<double,double> > lMapAll; 
0067 
0068   //4 histos, 4 partitions
0069   //pair nb events, mean+err value of histo
0070   //std::map<unsigned int,Clusters> lMapClust[4][4];
0071   //std::map<unsigned int,Clusters>::iterator lIterClust;
0072   //TString clustDir[4] = {"TIB","TID","TOB","TEC"};
0073 
0074   unsigned int nDirNotFound = 0;
0075   //unsigned int nClustDirNotFound = 0;
0076   unsigned int nFileNotFound = 0;
0077 
0078   std::ofstream txtoutfile;
0079   std::ostringstream txtname;
0080   txtname << "FEDErrors_" << lFolder << "_" << lRunMin << "_" << lRunMax << ".dat";
0081 
0082   txtoutfile.open(txtname.str().c_str(),std::ios::out);
0083 
0084   txtoutfile << "| Error type | run # | fedID | rate of error |" << std::endl;
0085     //TString histName  = "APVAddressErrorBits";
0086 
0087   TString histName[nHistsDetailed]  = {"FEMissing","APVAddressErrorBits","APVErrorBits","UnlockedBits","OOSBits"};
0088 
0089   std::vector<double> lNormVal[nHistsDetailed];
0090   for (unsigned int r(0); r<nRuns; ++r){//loop on runs
0091     
0092     unsigned int lRun;
0093     std::istringstream(argv[5+r])>>lRun;
0094 
0095     std::cout << "Processing run " << lRun << std::endl;
0096 
0097     if (lRun < lRunMin || lRun > lRunMax) continue;
0098 
0099     runs.push_back(lRun);
0100 
0101 
0102     TString fileName = lPath;
0103 
0104     //     fileName += "/";
0105     //     fileName += static_cast<unsigned int>(lRun/1000.);
0106     //     fileName += "/";
0107     //     if (lRun - static_cast<unsigned int>(lRun/1000.)*1000 < 10) fileName += "00" ;
0108     //     else if (lRun - static_cast<unsigned int>(lRun/1000.)*1000 < 100) fileName += "0" ;
0109     //     fileName += lRun - static_cast<unsigned int>(lRun/1000.)*1000;
0110 
0111     unsigned int lSubFolder = static_cast<unsigned int>(lRun/100.);
0112 
0113     TString baseName = fileName;
0114     if (lAfsFiles) {
0115       std::cout << " Reading files from afs..." << std::endl;
0116       fileName += "/000";
0117       fileName += lSubFolder;
0118       fileName += "xx";
0119     }
0120     fileName += "/DQM_V0001_SiStrip_R000";
0121     fileName += lRun;
0122     fileName += ".root";
0123 
0124     
0125     //    fileName += "/DQM_V0005_R000";
0126     //     fileName += lRun;
0127     //     fileName += ".root";
0128 
0129 
0130     TFile *f = TFile::Open(fileName);
0131     
0132  //    if (!f) {
0133 //       std::cout << "Cannot open file " << fileName << " for reading !" << std::endl;
0134 //       fileName = baseName;
0135 //       fileName += "/DQM_V0004_R000";
0136 //       fileName += lRun;
0137 //       fileName += ".root";
0138       
0139 //       f = TFile::Open(fileName);
0140 //       if (!f) {
0141 //  std::cout << "Cannot open file " << fileName << " for reading !" << std::endl;
0142 //  fileName = baseName;
0143 //  fileName += "/DQM_V0003_R000";
0144 //  fileName += lRun;
0145 //  fileName += ".root";
0146     
0147 //  f = TFile::Open(fileName);
0148 //  if (!f) {
0149 //    std::cout << "Cannot open file " << fileName << " for reading !" << std::endl;
0150 //    fileName = baseName;
0151 //    fileName += "/DQM_V0002_R000";
0152 //    fileName += lRun;
0153 //    fileName += ".root";
0154       
0155 //    f = TFile::Open(fileName);
0156 //    if (!f) {
0157 //      std::cout << "Cannot open file " << fileName << " for reading !" << std::endl;
0158 //      fileName = baseName;
0159 //      fileName += "/DQM_V0001_R000";
0160 //      fileName += lRun;
0161 //      fileName += ".root";
0162         
0163 //      f = TFile::Open(fileName);
0164     if (!f) {
0165       std::cout << "Cannot open file " << fileName << " for reading ! Continue ..." << std::endl;
0166       nFileNotFound++;
0167       //return 0;
0168       continue;
0169     }
0170 //    }
0171 //  }
0172 //       }
0173 //     }
0174 
0175     TString dirName = "DQMData/Run ";
0176     dirName += lRun;
0177     dirName += "/SiStrip/Run summary/ReadoutView/";
0178     std::cout << "Directory " << dirName << std::endl;
0179 
0180     if (!f->cd(dirName)) {
0181       std::cerr << "Folder not found. Check if file valid or source code valid in " << __FILE__ << ", variable dirName! Going to next run." << std::endl;
0182       nDirNotFound++;
0183       //return 0;
0184       continue;
0185     }
0186 
0187     //looking for object with name chNames etc...
0188     TString normDir = dirName;
0189     normDir += "FedMonitoringSummary/";
0190     if (!f->cd(normDir)) {
0191       std::cerr << "Folder " << normDir << " not found, continuing... " << __FILE__ << ", line " << __LINE__ << std::endl;
0192       nDirNotFound++;
0193       //return 0;
0194       continue;
0195     };
0196 
0197   
0198 
0199     TH1F *hNorm = (TH1F*)gDirectory->Get("FED/nFEDErrors");
0200     if (!hNorm) hNorm = (TH1F*)gDirectory->Get("FEDLevel/nFEDErrors");
0201     if (!hNorm) hNorm = (TH1F*)gDirectory->Get("nFEDErrors");
0202     if (!hNorm) {
0203       std::cout << "Error, histogram nFEDErrors not found. Continue..." << std::endl;
0204       continue;//return 0;
0205     }
0206     double norm = hNorm->GetEntries();
0207 
0208     lMapFED.insert(std::pair<unsigned int,double>(lRun,hNorm->GetMean()));                                          
0209           
0210     TH1F *hChannels = (TH1F*)gDirectory->Get("Fiber/nBadChannelStatusBits");
0211     if (!hChannels) hChannels = (TH1F*)gDirectory->Get("FiberLevel/nBadChannelStatusBits");
0212     if (!hChannels) hChannels = (TH1F*)gDirectory->Get("nBadChannelStatusBits");
0213     if (!hChannels){
0214       std::cout << "Error, histogram nBadChannelStatusBits not found. Continue..." << std::endl;
0215       continue;
0216     }
0217 
0218     lMapChannels.insert(std::pair<unsigned int,std::pair<double,double> >(lRun,std::pair<double,double>(hChannels->GetMean(),hChannels->GetMeanError())));               
0219 
0220     
0221 
0222     TProfile *hAll = (TProfile*)gDirectory->Get("Trends/nTotalBadChannelsvsTime");
0223     if (!hAll) hAll = (TProfile*)gDirectory->Get("ErrorsVsTime/nTotalBadChannelsvsTime");
0224     if (!hAll) hAll = (TProfile*)gDirectory->Get("nTotalBadChannelsvsTime");
0225     if (!hAll) {
0226       std::cout << "Error, histogram nTotalBadChannelsvsTime not found. Continue..." << std::endl;
0227       continue;
0228     }
0229     lMapAll.insert(std::pair<unsigned int,std::pair<double,double> >(lRun,std::pair<double,double>(hAll->GetMean(2),hAll->GetMeanError(2))));
0230 
0231     if (hAll->GetMean(2) < 0.000001) std::cout << " -- Run " << lRun << " has no errors." << std::endl; 
0232 
0233     lMapFEDChannels.insert(std::pair<unsigned int,std::pair<double,double> >(lRun,std::pair<double,double>(hAll->GetMean(2)-hChannels->GetMean(),sqrt(hAll->GetMeanError(2)*hAll->GetMeanError(2)+hChannels->GetMeanError()*hChannels->GetMeanError()))));
0234 
0235     //find out which FEDs are in error, and which error
0236     //TString lFedName[6] = {"AnyFEDErrors","CorruptBuffers","AnyFEProblems","AnyDAQProblems","DataMissing","BadDAQCRCs"};
0237 
0238     const unsigned int nHistos = 5;
0239 
0240     std::string lFedName[nHistos] = {"FED/VsId/AnyFEDErrors","FED/VsId/CorruptBuffers","FE/VsId/AnyFEProblems","FED/VsId/BadDAQCRCs","FED/VsId/DataMissing"};
0241     std::string lFedNameBis[nHistos] = {"FEDLevel/VsFedId/AnyFEDErrors","FEDLevel/VsFedId/CorruptBuffers","FrontEndLevel/VsFedId/AnyFEProblems","FEDLevel/VsFedId/BadDAQCRCs","FEDLevel/VsFedId/DataMissing"};
0242     std::string lFedNameTer[nHistos] = {"AnyFEDErrors","CorruptBuffers","AnyFEProblems","BadDAQCRCs","DataMissing"};
0243     
0244     for (unsigned int iH(0); iH<nHistos; ++iH){                                                                           
0245       TH1F *FEDobj = (TH1F*)gDirectory->Get(lFedName[iH].c_str());
0246       if (!FEDobj) FEDobj = (TH1F*)gDirectory->Get(lFedNameBis[iH].c_str());
0247       if (!FEDobj) FEDobj = (TH1F*)gDirectory->Get(lFedNameTer[iH].c_str());
0248 
0249       if (!FEDobj) { 
0250     std::cout << "Error, histogram " << lFedName[iH] << " not found. Continue..." << std::endl;
0251     continue;//return 0;
0252       }
0253       else { 
0254     if (FEDobj->GetEntries() != 0) {
0255       unsigned int nFeds = 0;
0256       for (int bin(1); bin<FEDobj->GetNbinsX()+1; ++bin){
0257         if (FEDobj->GetBinContent(bin)>0){
0258           ++nFeds;
0259         }
0260       }
0261       for (int bin(1); bin<FEDobj->GetNbinsX()+1; ++bin){
0262         if (FEDobj->GetBinContent(bin)>0){
0263           unsigned int iFed = bin+49;
0264           float lStat = FEDobj->GetBinContent(bin)/norm*1.;
0265           if (nFeds < 90) {// lesss than any entire partition....
0266         txtoutfile << lFedName[iH] << " " << lRun << " " << iFed << " " << lStat << std::endl;
0267           }
0268           else {
0269         txtoutfile << lFedName[iH] << " " << lRun << " " << nFeds << " FEDs with rate: " << lStat << std::endl;
0270         break;
0271           }
0272         }
0273       }
0274     }
0275       }
0276     }
0277 
0278     for (unsigned int ifed(50); ifed<500;++ifed){//loop on FEDs
0279 
0280       TString fedDir = dirName;
0281       fedDir += "FrontEndDriver";
0282       fedDir += ifed;
0283 
0284       if (!f->cd(fedDir)) continue;
0285       else {
0286     //std::cout << " - Errors detected for FED " << ifed << std::endl;
0287       }
0288       
0289       TDirectory *current = gDirectory;
0290 
0291       //channel histos
0292       for (unsigned int iH(0); iH<nHistsDetailed; ++iH){                                                                           
0293  
0294     TString objName = histName[iH];
0295     objName += "ForFED";
0296     objName += ifed;
0297     TH1F *obj = (TH1F*)current->Get(objName);
0298     
0299     if (!obj) {
0300       //std::cout << "Error, histogram " << objName << " not found. Next ..." << std::endl;
0301       continue;//return 0;
0302     }
0303     else {
0304       std::cout << "Processing histogram " << objName << ", nentries = " << obj->GetEntries() << std::endl;
0305       if (obj->GetEntries() != 0) {
0306         for (int bin(1); bin<obj->GetNbinsX()+1; ++bin){
0307           if (obj->GetBinContent(bin)>0){ 
0308         //unsigned int iCh = static_cast<int>((bin-1)/2.);
0309         //unsigned int iAPV = (bin-1);//%2;
0310         unsigned int iCh = bin-1;
0311         if (iH==0) iCh = iCh*12;//fe level
0312         unsigned int iAPV = 0;
0313         if (iH==1 || iH==2) {
0314           iAPV = iCh%2;
0315           iCh = static_cast<unsigned int>(iCh/2.);
0316         }
0317         float lStat = obj->GetBinContent(bin)/norm*1.;
0318         std::vector<std::pair<unsigned int, float> > lVec;
0319         lVec.push_back(std::pair<unsigned int, float>(lRun,lStat));
0320         std::vector<std::pair<unsigned int, float> > lVecRun;
0321         unsigned int lChIdx = 2*96*ifed+2*iCh+iAPV;
0322         lVecRun.push_back(std::pair<unsigned int, float>(lChIdx,lStat));
0323         //lMapIter = lMap.insert(std::pair<unsigned int,std::vector<std::pair<unsigned int,float> > >(192*ifed+iAPV,lVec));
0324         lMapIter = lMap[iH].insert(std::pair<unsigned int,std::vector<std::pair<unsigned int,float> > >(lChIdx,lVec));
0325         if (!lMapIter.second) ((lMapIter.first)->second).push_back(std::pair<unsigned int, float>(lRun,lStat));
0326         lMapRunIter = lMapRun[iH].insert(std::pair<unsigned int,std::vector<std::pair<unsigned int,float> > >(lRun,lVecRun));
0327         if (!lMapRunIter.second) ((lMapRunIter.first)->second).push_back(std::pair<unsigned int, float>(lChIdx,lStat));
0328         else {
0329           lNormVal[iH].push_back(norm);
0330         }
0331           }
0332         }
0333       }
0334     }
0335       }
0336       
0337     }//loop on feds
0338 
0339 //     TString clustDirBase = "DQMData/Run ";
0340 //     clustDirBase += lRun;
0341 //     clustDirBase += "/SiStrip/Run summary/MechanicalView/";
0342 //     TString histClust[4] = {"Summary_MeanNumberOfClusters__",
0343 //              "Summary_MeanNumberOfDigis__",
0344 //              "Summary_TotalNumberOfClusters_OffTrack_in_",
0345 //              "Summary_TotalNumberOfClusters_OnTrack_in_"};
0346 
0347 //     for (unsigned iP(0); iP<4; iP++){//loop on partitions
0348 //       TString lClustDir = clustDirBase+clustDir[iP];
0349 //       if (!f->cd(lClustDir)) {
0350 //       std::cerr << "Folder not found. Check if file valid or source code valid in " << __FILE__ << ", variable dirName! Going to next run." << std::endl;
0351 //       nClustDirNotFound++;
0352 //       //return 0;
0353 //       continue;
0354 //       }
0355 
0356 //       for (unsigned int iH(0); iH<4; iH++){
0357 //  TString lHistName = histClust[iH];
0358 //  lHistName += clustDir[iP];
0359 
0360 //  TH1F *hClust = (TH1F*)gDirectory->Get(lHistName);
0361 //  if (!hClust) {
0362 //    std::cout << "Can't find object " << lHistName << " in directory " 
0363 //          << lClustDir
0364 //          << ", continuing..."
0365 //          << std::endl;
0366 //    continue;
0367 //  }
0368 //  Clusters lClust;
0369 //  lClust.nEvents = hClust->GetEntries();
0370 //  lClust.mean = hClust->GetMean();
0371 //  lClust.meanErr = hClust->GetMeanError();
0372 //  lMapClust[iP][iH].insert(std::pair<unsigned int,Clusters >(lRun,lClust));
0373 //       }
0374 
0375 
0376 //     }//loop on partitions
0377 
0378 
0379 
0380     f->Close();
0381   }//loop on runs
0382 
0383   const unsigned int nErr[nHistsDetailed] = {lMap[0].size(),lMap[1].size(),lMap[2].size(),lMap[3].size(),lMap[4].size()};
0384 
0385   //assert (runs.size() == nRuns);
0386   nRuns = runs.size();
0387 
0388   //std::cout << "Found " << nErr << " APVs with errors in " << nRuns << " runs processed." << std::endl;
0389   for (unsigned int iH(0); iH<nHistsDetailed; ++iH){
0390     txtoutfile << "Found " << nErr[iH] << " channels with errors " << histName[iH] << " in " << lMapRun[iH].size() << " runs with this type of errors." << std::endl;
0391   }
0392   std::cout << "Number of runs where file was not found : " << nFileNotFound << std::endl;
0393   std::cout << "Number of runs where folder was not found : " << nDirNotFound << std::endl;
0394   //std::cout << "Number of runs where cluster folder was not found : " << nClustDirNotFound << std::endl;
0395 
0396   //TFile *outfile = TFile::Open("APVAddressErrors.root","RECREATE");
0397 
0398   std::ostringstream lrootname;
0399   lrootname << "MyHDQM_" << lFolder << "_" << runs[0] << "_" << runs[nRuns-1] << ".root";
0400 
0401   TFile *outfile = TFile::Open(lrootname.str().c_str(),"RECREATE");
0402   outfile->cd();
0403 
0404 
0405   txtoutfile << " ****************************************** " 
0406          << std::endl
0407          << " ** Summary of errors per FED/CH per run ** " 
0408          << std::endl
0409          << " ***** for rate < 1% and nRuns < 5 ******** "
0410          << std::endl
0411          << " ****************************************** " 
0412          <<std::endl;
0413   
0414   for (unsigned int iH=0; iH<nHistsDetailed; ++iH){//loop on histos
0415 
0416     TH1F *h[nErr[iH]];
0417     std::map<unsigned int,std::vector<std::pair<unsigned int,float> > >::iterator lIter = lMap[iH].begin();
0418     std::ostringstream lNameRun;
0419     lNameRun << "Number_" << histName[iH] << "_vsRun";
0420     TH1F *hRun = new TH1F(lNameRun.str().c_str(),"Number of channel with Error vs run; run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0421     lNameRun.str("");
0422     lNameRun << "FEDS_" << histName[iH] << "_vsRun";
0423     TH2F *hFEDRun_apv0 = new TH2F((lNameRun.str()+"_apv0").c_str(),"Number of runs with FED channels APV0 with Errors; FED id ; ch id",440,50,490,96,0,96);
0424     TH2F *hFEDRun_apv1 = new TH2F((lNameRun.str()+"_apv1").c_str(),"Number of runs with FED channels APV1 with Errors; FED id ; ch id",440,50,490,96,0,96);
0425     lNameRun.str("");
0426     lNameRun << "FEDS_" << histName[iH] << "_vsRate";
0427     TH2F *hFEDRate_apv0 = new TH2F((lNameRun.str()+"_apv0").c_str(),"Mean rate of errors of FED channels APV0 with Errors; FED id ; ch id",440,50,490,96,0,96);
0428     TH2F *hFEDRate_apv1 = new TH2F((lNameRun.str()+"_apv1").c_str(),"Mean rate of errors of FED channels APV1 with Errors; FED id ; ch id",440,50,490,96,0,96);
0429     std::map<unsigned int,std::vector<std::pair<unsigned int,float> > >::iterator lIterRun = lMapRun[iH].begin();
0430 
0431     assert(lNormVal[iH].size() == lMapRun[iH].size());
0432     unsigned int lIdx = 0;
0433     for (;lIterRun!=lMapRun[iH].end(); ++lIterRun,++lIdx){//loop on elements
0434 
0435       std::vector<std::pair<unsigned int,float> > lVec = lIterRun->second;
0436       hRun->Fill(lIterRun->first,lVec.size());
0437       for (unsigned int ele(0);ele<lVec.size();++ele){
0438     unsigned int lCh = lVec[ele].first;
0439     unsigned int lElements = lMap[iH][lCh].size();
0440     unsigned int lApv = static_cast<unsigned int>(lCh%2);
0441     if (lElements<5 && lVec[ele].second < 0.01) {
0442       txtoutfile << histName[iH] 
0443              << " Run " << lIterRun->first << " fed " 
0444              << static_cast<unsigned int>(lCh/192.) << " ch " 
0445              << static_cast<unsigned int>((lCh%192)/2.) << " apv "
0446              << lApv
0447              << " rate " << lVec[ele].second 
0448              << " (" << 1/lNormVal[iH][lIdx] << ")"
0449              << " nRuns " << lElements
0450              << std::endl;
0451     }
0452     if (lApv==0) {
0453       hFEDRun_apv0->Fill(static_cast<unsigned int>(lCh/192.),static_cast<unsigned int>((lCh%192)/2.));
0454       hFEDRate_apv0->Fill(static_cast<unsigned int>(lCh/192.),static_cast<unsigned int>((lCh%192)/2.),lVec[ele].second/lElements);
0455     }
0456     else {
0457       hFEDRun_apv1->Fill(static_cast<unsigned int>(lCh/192.),static_cast<unsigned int>((lCh%192)/2.));
0458       hFEDRate_apv1->Fill(static_cast<unsigned int>(lCh/192.),static_cast<unsigned int>((lCh%192)/2.),lVec[ele].second/lElements);
0459     }
0460       }
0461     }//loop on elements
0462 
0463 
0464 
0465 
0466 //     unsigned int e = 0;
0467 //     for (;lIter!=lMap[iH].end(); lIter++,e++){//loop on elements
0468 
0469 //       unsigned int lCh = lIter->first;
0470 //       std::ostringstream lName;
0471 //       //lName << "ErrorFed" << static_cast<unsigned int>(lCh/192.) << "Ch" << static_cast<unsigned int>(lCh%192/2.) << "APV" << lCh%2;
0472 //       lName << "Hist" << iH << "ErrorFed" << static_cast<unsigned int>(lCh/96.) << "Ch" << static_cast<unsigned int>(lCh%96) ;//<< "APV" << lCh%2;
0473 
0474 //       //h[e] = new TH1F(lName.str().c_str(),"rate of APVAddressError vs run",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0475 //       h[e] = new TH1F(lName.str().c_str(),"rate of Error vs run; run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0476 
0477 //       std::vector<std::pair<unsigned int,float> > lVec = lIter->second;
0478 //       unsigned int nBins = lVec.size();
0479       
0480 //       for (unsigned int b(0); b<nBins; b++){
0481 //  //std::cout <<"Run " << lVec.at(b).first << ", runs[0] = " << runs[0] << ", runs[" << nRuns-1 << "] = " << runs[nRuns-1] << std::endl; 
0482 
0483 //  h[e]->SetBinContent(lVec.at(b).first-runs[0]+1,lVec.at(b).second);
0484 //  //std::cout << "Setting bin " << lVec.at(b).first-runs[0]+1 << " content to " << lVec.at(b).second << std::endl;
0485 //       }
0486 
0487 //       //h[e]->Write();
0488 
0489 //     }//loop on elements
0490   }//loop on histos
0491 
0492   TH1F *hRate = new TH1F("hRate",";run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0493   std::map<unsigned int,double>::iterator lIterFED = lMapFED.begin();
0494   for (;lIterFED!=lMapFED.end(); ++lIterFED){
0495     hRate->SetBinContent(lIterFED->first-runs[0]+1,lIterFED->second);
0496   }
0497 
0498 
0499   TH1F *hRateFEDChannels = new TH1F("hRateFEDChannels",";run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0500   std::map<unsigned int,std::pair<double,double> >::iterator lIterFEDCh = lMapFEDChannels.begin();
0501   for (;lIterFEDCh!=lMapFEDChannels.end(); ++lIterFEDCh){
0502     hRateFEDChannels->SetBinContent(lIterFEDCh->first-runs[0]+1,lIterFEDCh->second.first/36392.*100);
0503     hRateFEDChannels->SetBinError(lIterFEDCh->first-runs[0]+1,lIterFEDCh->second.second/36392.*100);
0504   }
0505 
0506   TH1F *hRateChannels = new TH1F("hRateChannels",";run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0507   std::map<unsigned int,std::pair<double,double> >::iterator lIterCh = lMapChannels.begin();
0508   for (;lIterCh!=lMapChannels.end(); ++lIterCh){
0509     hRateChannels->SetBinContent(lIterCh->first-runs[0]+1,lIterCh->second.first/36392.*100);
0510     hRateChannels->SetBinError(lIterCh->first-runs[0]+1,lIterCh->second.second/36392.*100);
0511   }
0512 
0513   TH1F *hRateAll = new TH1F("hRateAll",";run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0514   std::map<unsigned int,std::pair<double,double> >::iterator lIterAll = lMapAll.begin();
0515   for (;lIterAll!=lMapAll.end(); ++lIterAll){
0516     hRateAll->SetBinContent(lIterAll->first-runs[0]+1,lIterAll->second.first/36392.*100);
0517     hRateAll->SetBinError(lIterAll->first-runs[0]+1,lIterAll->second.second/36392.*100);
0518   }
0519 
0520 
0521 
0522 //   TH1F *hRateClust[4][4];
0523 //   for (unsigned int iP(0); iP<4; iP++){
0524 //     for (unsigned int iH(0); iH<4; iH++){
0525 //       std::ostringstream lNameClust;
0526 //       lNameClust << "hRateClust_" << clustDir[iP] << "_" << iH ;
0527 //       hRateClust[iP][iH] = new TH1F(lNameClust.str().c_str(),";run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
0528 //       lIterClust = lMapClust[iP][iH].begin();
0529 //       for (;lIterClust!=lMapClust[iP][iH].end(); lIterClust++){
0530 //  hRateClust[iP][iH]->SetBinContent(lIterClust->first-runs[0]+1,lIterClust->second.mean);
0531 //  hRateClust[iP][iH]->SetBinError(lIterClust->first-runs[0]+1,lIterClust->second.meanErr);
0532 //       }
0533 //     }
0534 //   }
0535 
0536 
0537   outfile->Write();
0538   outfile->Close();
0539   txtoutfile.close();
0540 
0541   return 1;
0542   
0543 }//main