File indexing completed on 2024-04-06 11:59:38
0001 #include <iostream>
0002 #include <vector>
0003 #include "TKey.h"
0004
0005 Double_t mycurvefunc(Double_t *x, Double_t *par){
0006 return par[0]+ x[0]*par[1];
0007 }
0008 void make_gaincurves(){
0009
0010 TFile *file = new TFile("Pixel_DQM_Calibration_smallGain.root");
0011 file->cd();
0012
0013 TList *list = file->GetListOfKeys();
0014 gStyle->SetOptStat(0);
0015 Int_t nkeys = file->GetNkeys();
0016 TDirectory *dir = file->GetDirectory("DQMData");
0017 if(dir==0)
0018 return;
0019
0020
0021 TLatex CMSprelim(0.3,0.3,"CMS Preliminary");
0022 CMSprelim.SetTextColor(2);
0023 CMSprelim.SetTextSize(CMSprelim.GetTextSize()*1.2);
0024
0025 TString comparestring = "Module";
0026 TString curvestring = "GainCurve";
0027 std::vector<TString> keylist;
0028 std::vector<TString> hist1list;
0029 std::vector<TString> hist2list;
0030 std::vector<TString> dirlist;
0031 std::vector<TString> notdonelist;
0032 std::vector<int> nsubdirs;
0033 TDirectory *dirsav = dir;
0034 list = dir->GetListOfKeys();
0035 int ikey=0;
0036 int localkey=0;
0037 int ntimes=0;
0038
0039 TCanvas *curvecanvas = new TCanvas();
0040 for(ikey=0;ikey<list->GetEntries(); ikey++){
0041 TKey *thekey = (TKey*)list->At(ikey);
0042 if(thekey==0)
0043 continue;
0044 TString keyname=thekey->GetName();
0045 keyname.ReplaceAll(" ","");
0046 TString keytype=thekey->GetClassName();
0047 keytype.ReplaceAll(" ","");
0048 if(keyname=="EventInfo")
0049 continue;
0050
0051 if(keytype=="TDirectoryFile"){
0052 TString dirname=dir->GetPath();
0053 dirname+="/";
0054 dirname+=keyname;
0055
0056 dir=file->GetDirectory(dirname);
0057
0058 list=dir->GetListOfKeys();
0059 if(dirname.Contains(comparestring))
0060 dirlist.push_back(dirname);
0061 else{
0062 notdonelist.push_back(dirname);
0063 nsubdirs.push_back(-1);
0064 }
0065 }
0066 }
0067 int nempty=0;
0068 while(nempty!=notdonelist.size()){
0069 for(int idir=0; idir<notdonelist.size(); ++idir){
0070 if(nsubdirs[idir]==0)
0071 continue;
0072
0073 dir = file->GetDirectory(notdonelist[idir]);
0074
0075 list= dir->GetListOfKeys();
0076
0077 int ndirectories=0;
0078 for(ikey=0;ikey<list->GetEntries(); ikey++){
0079 TKey *thekey = (TKey*)list->At(ikey);
0080 if(thekey==0)
0081 continue;
0082 TString keyname=thekey->GetName();
0083 keyname.ReplaceAll(" ","");
0084 TString keytype=thekey->GetClassName();
0085 keytype.ReplaceAll(" ","");
0086 if(keytype=="TDirectoryFile"){
0087 TString dirname=dir->GetPath();
0088 dirname+="/";
0089 dirname+=keyname;
0090
0091 ndirectories++;
0092 if(dirname.Contains(comparestring))
0093 dirlist.push_back(dirname);
0094 else{
0095 notdonelist.push_back(dirname);
0096 nsubdirs.push_back(-1);
0097 }
0098 }
0099 }
0100 nsubdirs[idir]=ndirectories;
0101
0102 }
0103
0104 nempty=0;
0105 for(int i=0; i<nsubdirs.size(); i++){
0106 if(nsubdirs[i]!=-1)
0107 nempty++;
0108 }
0109 }
0110 gStyle->SetOptStat(0);
0111 int ncurves=0;
0112 for(int i=0; i<dirlist.size() ; ++i){
0113
0114
0115 dir = file->GetDirectory(dirlist[i]);
0116 list= dir->GetListOfKeys();
0117
0118 for(ikey=0;ikey<list->GetEntries(); ikey++){
0119
0120 TKey *thekey = (TKey*)list->At(ikey);
0121 if(thekey==0)
0122 continue;
0123 TString keyname=thekey->GetName();
0124 keyname.ReplaceAll(" ","");
0125 TString keytype=thekey->GetClassName();
0126 keytype.ReplaceAll(" ","");
0127 std::cout << ikey << " " << keyname << std::endl;
0128
0129 if(keytype=="TH1F"){
0130 std::cout << keyname << std::endl;
0131 dir=file->GetDirectory(dirlist[i]);
0132 TH1F* temp = (TH1F*) dir->Get(keyname);
0133 if(keyname.Contains(curvestring)){
0134 ncurves++;
0135 std::cout << keyname << std::endl;
0136 curvecanvas->cd();
0137 curvecanvas->Clear();
0138 dir=file->GetDirectory(dirlist[i]);
0139 dir->cd();
0140 gStyle->SetOptStat(0);
0141 gStyle->SetOptFit(0);
0142 temp->SetMarkerSize(2.0);
0143 temp->GetXaxis()->SetTitle("VCAL");
0144 temp->GetYaxis()->SetTitle("Average ADC response");
0145 temp->DrawClone();
0146 float gainandped[2];
0147 getgainresult(keyname,file, dirlist[i],gainandped);
0148 std::cout << gainandped[0] << " " << gainandped[1] << std::endl;
0149 if(gainandped[0]>0.){
0150 TString funcname = keyname;
0151 funcname+="func";
0152 TF1 *func = new TF1(funcname,mycurvefunc,0,256,2);
0153 func->SetLineWidth(3);
0154 func->SetParameter(0,gainandped[1]);
0155 func->SetParameter(1,1./gainandped[0]);
0156 func->DrawClone("lsame");
0157 CMSprelim.DrawText(10,10,"CMS Pixel");
0158 TLegend *legend = new TLegend(0.11,0.2,0.7,0.3);
0159 legend->SetFillStyle(0);
0160 legend->SetBorderSize(0);
0161 TString fitstring = " y = #frac{x}{";
0162 fitstring+= gainandped[0];
0163 fitstring+="} + " ;
0164 fitstring+= gainandped[1];
0165
0166 legend->AddEntry(func,fitstring,"l");
0167 legend->DrawClone("same");
0168 }
0169 curvecanvas->Update();
0170 curvecanvas->Print(keyname+".jpg");
0171 curvecanvas->Print(keyname+".eps");
0172 }
0173
0174 }
0175 }
0176 }
0177
0178
0179
0180
0181
0182 }
0183
0184
0185 float getgainresult(TString keyname, TFile *file, TString dirname, float *gainandped){
0186
0187
0188 std::string strversion = keyname;
0189 std::string cutstring[20];
0190 int foundunderscore=0;
0191 for(int i=0; i<20 && foundunderscore<strversion.size(); i++){
0192 int found=strversion.find("_",foundunderscore);
0193 std::string thesubstr = strversion.substr(foundunderscore,found-foundunderscore);
0194
0195 cutstring[i]=thesubstr;
0196 foundunderscore=found+1;
0197 }
0198
0199 int row = atoi(cutstring[2].c_str());
0200 int col = atoi(cutstring[4].c_str());
0201 int detid = atoi(cutstring[6].c_str());
0202
0203 TString gainhisto = dirname;
0204 gainhisto+="/Gain2d_siPixelCalibDigis_";
0205 gainhisto+=detid;
0206 TString pedhisto = dirname;
0207 pedhisto+="/Pedestal2d_siPixelCalibDigis_";
0208 pedhisto+=detid;
0209
0210 file->cd();
0211 TH2F *gain2d = file->Get(gainhisto);
0212 float gainval=0;
0213 float pedval=0;
0214 if(gain2d!=0)
0215 gainval = gain2d->GetBinContent(row,col);
0216 else return 0;
0217 TH2F *ped2d = file->Get(pedhisto);
0218 if(ped2d)
0219 pedval=ped2d->GetBinContent(row,col);
0220 else return 0;
0221
0222
0223
0224 gainval = gain2d->GetBinContent(col+1,row+1);
0225 pedval = ped2d->GetBinContent(col+1,row+1);
0226
0227 gainandped[0]=gainval;
0228 gainandped[1]=pedval;
0229 return 1;
0230 }
0231 double getpedresult(TString keyname){
0232 std::cout << "examining histo " << keyname << std::endl;
0233 float result=0;
0234
0235
0236 return result;
0237
0238 }
0239
0240 int getrow(std::string keyname){
0241
0242 return 0;
0243 }
0244
0245 int getcol(std::string keyname){
0246 return 0;
0247 }