OpeTool.cpp

00001 #include "OpeTool.h"
00002 #include "SctData/RawScanResult.h"
00003 #include "Sct/LogicErrors.h"
00004 #include <boost/shared_ptr.hpp>
00005 
00006 #include "TH2.h"
00007 #include "TH1.h"
00008 #include "TMath.h"
00009 #include "TFile.h"
00010 
00011 using namespace SctData;
00012 using namespace Sct;
00013 using boost::shared_ptr;
00014 
00015 namespace SctAnalysis {
00016 
00017   OpeTool::OpeTool(){}
00018 
00019   OpeTool::~OpeTool(){}
00020 
00021   boost::shared_ptr<SctData::OpeResult> OpeTool::analyzeModule(const RawScanResult& raw){
00022 
00023     unsigned nOPE = raw.nOccupancyPerEvent();
00024 
00025     shared_ptr<OpeResult> result;
00026     if (nOPE==0) return result;
00027     
00028     result = shared_ptr<OpeResult>(new OpeResult(raw.getUniqueID()));
00029 
00030     //For each chip... 
00031     for (unsigned int ichip=0; ichip<nOPE; ++ichip) {
00032       const TH2D& chipHist = raw.getOccupancyPerEvent(ichip);
00033       const int biny = chipHist.GetNbinsY();
00034 
00035       std::ostringstream newhistname;
00036       newhistname << raw.getClassName() << "." << raw.getUniqueID() 
00037           << "_Chip" << ichip << "_Ope_Badness"; 
00038 
00039       std::ostringstream newtitle;
00040       newtitle << "Chip" << ichip << "_Ope_Badness"; 
00041 
00042       const char* c_name=newhistname.str().c_str();
00043       const char* c_title=newtitle.str().c_str();
00044       //  we need to make a non-const number of bins :(
00045       int NonConstBinY=biny;
00046       shared_ptr<TH1> badnessHist(new TH1D(c_name, c_title, NonConstBinY, chipHist.GetYaxis()->GetXbins()->GetArray()));
00047 
00048       // We want only bad OPEs over a threshold of -20. Below -20, OPE is dominated by s-curve wiggles...
00049       // The modules will run at around 1fC which corresponds to a threshold of 0 so ignore anything below -20. 
00050       // Lets find which bin -20 corresponds to. 
00051       double maxabove20 = 0;
00052       int badbin = 0;
00053       // loop over y bins making projections
00054       for(int iy=1; iy<biny+1; ++iy){
00055     std::ostringstream projectionName;
00056     projectionName << raw.getClassName() << "." << raw.getUniqueID() 
00057                << "_Chip" << ichip << "_bin" << iy; 
00058     shared_ptr<TH1D> proj(chipHist.ProjectionX(projectionName.str().c_str(),iy,iy,""));
00059     double mybadness = fractionVariance(*proj);
00060     badnessHist->SetBinContent(iy, mybadness);
00061 
00062     if ((badnessHist->GetBinCenter(iy))>-20.0) {
00063       if (mybadness > maxabove20) {
00064         maxabove20 = mybadness;
00065         badbin = iy;
00066       }
00067     }
00068       }
00069 
00070       SctData::ChipOpeResult& chipResult=result->getChipResult(ichip);
00071 
00072       // FILL IN THAT HISTOGRAM
00073       chipResult.hist=badnessHist;
00074 
00075       chipResult.badmax= maxabove20; 
00076       chipResult.threshold= badnessHist->GetBinCenter(badbin);
00077 
00078     }
00079 
00080     // Return result. The defect will be decided upon in the NoiseOccupancyAlgorithm. 
00081     return result;
00082   }
00083 
00084   double OpeTool::fractionVariance(const TH1& data) {
00085 
00086     double range = data.GetXaxis()->GetXmax() - data.GetXaxis()->GetXmin();
00087     double prob = (data.GetMean())/range;
00088     // theoretically calculate the RMS from the probability dist:
00089     double calcRMS = sqrt(range*prob*(1-prob));
00090     // measure the RMS from data
00091     double measRMS = data.GetRMS();
00092     // return the fraction of the measured and calculated RMS
00093     // std::cout << "OPE: measuredRMS :" << measRMS << " calcRMS :" << calcRMS << std::endl;    
00094     if (calcRMS ==0) return 1;
00095     else return measRMS/calcRMS;
00096   }
00097   
00098 }

Generated on Mon Feb 6 14:01:24 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6