File indexing completed on 2024-04-06 12:22:51
0001 void noiseMatrixMacro(){
0002 gROOT->SetBatch();
0003 gROOT->ProcessLine(".L GenFuncMacro.C");
0004
0005
0006
0007 char *myFileName;
0008 char *myFilePath;
0009 void *dirp = gSystem->OpenDirectory("/tmp/csccalib");
0010 char *afile;
0011 while(afile = gSystem->GetDirEntry(dirp)) {
0012 char *bfile[0] = afile[0];
0013 if (bfile[0]=='c') {
0014 printf("file: %s\n",afile);
0015 myFileName = afile;
0016 }
0017 myFilePath = Form("/tmp/csccalib/%s", myFileName);
0018 }
0019
0020
0021 int nDDU = 1;
0022 int nCham = 1;
0023 int nLayer = 6;
0024
0025
0026 gStyle->SetCanvasColor(0);
0027 gStyle->SetPadColor(0);
0028 gStyle->SetPadBorderMode(0);
0029 gStyle->SetCanvasBorderMode(0);
0030 gStyle->SetFrameBorderMode(0);
0031 gStyle->SetStatH(0.2);
0032 gStyle->SetStatW(0.3);
0033
0034 std::cout << "opening: " << myFileName << std::endl;
0035 TFile *myFile = TFile::Open(myFilePath);
0036
0037 Calibration->Draw("cham");
0038 int nCham = htemp->GetXaxis()->GetXmax();
0039
0040
0041
0042 gSystem->cd("/afs/cern.ch/cms/CSC/html/csccalib/");
0043
0044
0045 makeDirectory("images");
0046 gSystem->cd("images");
0047
0048 makeDirectory("NoiseMatrix");
0049 gSystem->cd("NoiseMatrix");
0050
0051 makeDirectory(myFileName);
0052 gSystem->cd(myFileName);
0053 gSystem->cd("../../../");
0054
0055
0056 directoryCheck();
0057
0058 flagNoiseMatrixGraphs(myFileName);
0059 NoiseMatrixChamberGraphs(myFileName, nDDU, nCham);
0060 NoiseMatrixLayerGraphs(myFileName, nDDU, nCham, nLayer);
0061
0062 gSystem->cd("/afs/cern.ch/user/c/csccalib/scratch0/CMSSW_1_1_1/src/OnlineDB/CSCCondDB/test");
0063 gROOT->ProcessLine(".q");
0064 }
0065
0066 void GetChamberIDs(int IDArray[9]){
0067 TCanvas *IDcanv = new TCanvas ("idGraph", "idGraph");
0068 IDcanv->cd();
0069 TH1F *idDummy = new TH1F("idDummy", "idDummy", 10, 220000000, 221000000);
0070 idDummy->Draw();
0071 for (int chamber=0; chamber<9; ++chamber){
0072 TString idCut = Form ("cham==%d", chamber);
0073 Calibration->Project("idDummy", "id", idCut);
0074 Int_t idNum = idDummy->GetMean();
0075 IDArray[chamber]=idNum;
0076 }
0077 }
0078
0079
0080
0081 void GetNoiseBounds(Float_t boundsChamMin[9], Float_t boundsChamMax[9], int nCham){
0082 TCanvas *NoiseBoundCanv = new TCanvas ("NoiseBoundCanv", "NoiseBoundCanv");
0083 NoiseBoundCanv->Divide(2,1);
0084 for (int chamber=0; chamber<nCham; ++chamber){
0085 NoiseBoundCanv->cd(1);
0086 TString NoiseCut = Form ("cham==%d", chamber);
0087 Calibration->Draw("MaxNoise", NoiseCut);
0088 Float_t NoiseBoundMax = htemp->GetXaxis()->GetXmax();
0089 boundsChamMax[chamber]=NoiseBoundMax;
0090 std::cout << NoiseBoundMax << std::endl;
0091 NoiseBoundCanv->cd(2);
0092 Calibration->Draw("MinNoise", NoiseCut);
0093 Float_t NoiseBoundMin = htemp->GetXaxis()->GetXmin();
0094 boundsChamMin[chamber]=NoiseBoundMin;
0095 std::cout << NoiseBoundMin << std::endl;
0096 }
0097 }
0098
0099 void NoiseMatrixChamberGraphs(TString myFileName, int nDDU, int nCham){
0100 gSystem->cd("images/NoiseMatrix");
0101 gSystem->cd(myFileName);
0102 makeDirectory("ElementChamberGraphs");
0103 gSystem->cd("ElementChamberGraphs");
0104
0105 int nElements = 12;
0106 TH2F *noiseGraph;
0107 TCanvas *noiseCanv;
0108 for (int i=0; i< nDDU; ++i){
0109 int idArray[9];
0110 GetChamberIDs(idArray);
0111 Float_t BoundsChamMin[9];
0112 Float_t BoundsChamMax[9];
0113
0114 GetNoiseBounds(BoundsChamMin, BoundsChamMax, nCham);
0115 for (int j=0; j<nCham; ++j){
0116 TString NoiseCanvName = Form("Noise_Matrix_Elements_Chamber_%d",idArray[j]);
0117 noiseCanv = new TCanvas(NoiseCanvName, NoiseCanvName,200,10,1200,800);
0118 noiseCanv->Divide(4,3);
0119 noiseCanv->Draw();
0120 for (int k=0; k<nElements; ++k){
0121 TString ElementGraphName = Form("Element_%d",k);
0122 noiseGraph = new TH2F(ElementGraphName,ElementGraphName,80,0,80,20,BoundsChamMin[j],BoundsChamMax[j]);
0123 noiseCanv->cd(k+1);
0124 noiseGraph->Draw();
0125 TString GraphForm = Form("elem[%d]:strip", k);
0126 TString GraphCut = Form("cham==%d", j);
0127 Calibration->Project(ElementGraphName, GraphForm, GraphCut);
0128 }
0129 noiseCanv->Update();
0130 PrintAsGif(noiseCanv, NoiseCanvName);
0131 }
0132 }
0133
0134 gSystem->cd("../");
0135 directoryCheck();
0136 }
0137
0138 void NoiseMatrixLayerGraphs(TString myFileName, int nDDU, int nCham, int nLayer){
0139
0140
0141
0142 int nElements = 12;
0143 TH2F *noiseGraph;
0144 TCanvas *noiseCanv;
0145 for (int i=0; i< nDDU; ++i){
0146 int idArray[9];
0147 GetChamberIDs(idArray);
0148
0149
0150 Float_t BoundsChamMin[9];
0151 Float_t BoundsChamMax[9];
0152
0153 GetNoiseBounds(BoundsChamMin, BoundsChamMax, nCham);
0154 for (int j=0; j<nCham; ++j){
0155 TString ChamDirecName = Form("Chamber_%d_Layer_Graphs", idArray[j]);
0156 makeDirectory(ChamDirecName);
0157 gSystem->cd(ChamDirecName);
0158 for (int l=0; l<nLayer; ++l){
0159 TString NoiseCanvName = Form ("Noise_Matrix_Elements_Chamber_%d_Layer_%d",idArray[j],l);
0160 noiseCanv = new TCanvas(NoiseCanvName, NoiseCanvName,200,10,1200,800);
0161 noiseCanv->Divide(4,3);
0162 noiseCanv->Draw();
0163 for (int k=0; k<nElements; ++k){
0164 TString ElementGraphName = Form("Element_%d",k);
0165 noiseGraph = new TH2F(ElementGraphName,ElementGraphName,80,0,80,20,BoundsChamMin[j],BoundsChamMax[j]);
0166 noiseCanv->cd(k+1);
0167 noiseGraph->Draw();
0168 TString GraphForm = Form("elem[%d]:strip", k);
0169 TString GraphCut = Form("cham==%d&&layer==%d", j, l);
0170 Calibration->Project(ElementGraphName, GraphForm, GraphCut);
0171 }
0172 noiseCanv->Update();
0173 PrintAsGif(noiseCanv, NoiseCanvName);
0174 }
0175 gSystem->cd("../");
0176 }
0177 }
0178 gSystem->cd("../../../");
0179 directoryCheck();
0180 }
0181
0182 void flagNoiseMatrixGraphs(TString myFileName){
0183 gSystem->cd("images/NoiseMatrix");
0184 gSystem->cd(myFileName);
0185
0186 TCanvas *flagNoiseMatrixCanv = new TCanvas("flagNoiseMatrixCanv", "flagNoiseMatrixCanv", 200,10,800,800);
0187 flagNoiseMatrixCanv->SetCanvasSize(1200,800);
0188 flagNoiseMatrixCanv->cd();
0189 flagNoiseMatrixGraph_1D = new TH1F("flagNoiseMatrixGraph_1D", "flagNoiseMatrixGraph_1D", 5, 0, 5);
0190 flagNoiseMatrixGraph_1D->GetYaxis()->SetTitle("Number of flag of each type");
0191 flagNoiseMatrixGraph_1D->GetYaxis()->SetLabelSize(0.035);
0192
0193 TLegend *LegNoiseMatrix = new TLegend(0.7,0.5,0.89,0.7);
0194 LegNoiseMatrix->SetHeader("Noise Matrix Flags Definitions");
0195 LegNoiseMatrix->SetFillColor(0);
0196 LegNoiseMatrix->SetTextSize(0);
0197
0198 Calibration->UseCurrentStyle();
0199 Calibration->Draw("flagMatrix>>flagNoiseMatrixGraph_1D");
0200
0201 LegNoiseMatrix->AddEntry("", "1: Good");
0202 LegNoiseMatrix->AddEntry("", "2: High Noise");
0203 LegNoiseMatrix->AddEntry("", "3: Low Noise" );
0204 LegNoiseMatrix->Draw("same");
0205
0206 flagNoiseMatrixCanv->Update();
0207
0208 PrintAsGif(flagNoiseMatrixCanv, "flagNoiseMatrixGraph_1D");
0209
0210
0211 gStyle->SetOptStat(0);
0212 TCanvas *flagNoiseMatrixChamberCanv = new TCanvas("flagNoiseMatrixChamberCanv", "flagNoiseMatrixChamberCanv", 200,10,800,800);
0213 flagNoiseMatrixChamberCanv->SetCanvasSize(1200,800);
0214
0215
0216 TLegend *LegNoiseMatrixChamber = new TLegend(0.85,0.8,0.98,0.98);
0217 LegNoiseMatrixChamber->SetHeader("Noise Matrix Flags Definitions");
0218 LegNoiseMatrixChamber->SetFillColor(0);
0219 LegNoiseMatrixChamber->SetTextSize(0);
0220
0221
0222 flagNoiseMatrixGraph_2D_Chamber = new TH2F("flagNoiseMatrixGraph_2D_Chamber", "flagNoiseMatrixGraph_2D_Chamber", 9, 0, 9, 4, 0, 4);
0223
0224 flagNoiseMatrixGraph_2D_Chamber0 = new TH2F("flagNoiseMatrixGraph_2D_Chamber0", "flagNoiseMatrixGraph_2D_Chamber0", 9, 0, 9, 4, 0, 4);
0225
0226 flagNoiseMatrixGraph_2D_Chamber1 = new TH2F("flagNoiseMatrixGraph_2D_Chamber1", "flagNoiseMatrixGraph_2D_Chamber1", 9, 0, 9, 4, 0, 4);
0227 flagNoiseMatrixGraph_2D_Chamber2 = new TH2F("flagNoiseMatrixGraph_2D_Chamber2", "flagNoiseMatrixGraph_2D_Chamber2", 9, 0, 9, 4, 0, 4);
0228 flagNoiseMatrixGraph_2D_Chamber3 = new TH2F("flagNoiseMatrixGraph_2D_Chamber3", "flagNoiseMatrixGraph_2D_Chamber3", 9, 0, 9, 4, 0, 4);
0229 flagNoiseMatrixGraph_2D_Chamber4 = new TH2F("flagNoiseMatrixGraph_2D_Chamber4", "flagNoiseMatrixGraph_2D_Chamber4", 9, 0, 9, 4, 0, 4);
0230
0231
0232 Calibration->Project("flagNoiseMatrixGraph_2D_Chamber0", "flagMatrix:cham");
0233 Double_t binMaxValCham = flagNoiseMatrixGraph_2D_Chamber0->GetMaximum();
0234
0235 flagNoiseMatrixGraph_2D_Chamber->SetMaximum(binMaxValCham);
0236
0237
0238 Calibration->Project("flagNoiseMatrixGraph_2D_Chamber1","flagMatrix:cham", "flagMatrix==1", "box");
0239 Calibration->Project("flagNoiseMatrixGraph_2D_Chamber2","flagMatrix:cham", "flagMatrix==2", "box");
0240 Calibration->Project("flagNoiseMatrixGraph_2D_Chamber3","flagMatrix:cham", "flagMatrix==3", "box");
0241
0242
0243 flagNoiseMatrixGraph_2D_Chamber1->SetFillColor(1);
0244 flagNoiseMatrixGraph_2D_Chamber2->SetFillColor(2);
0245 flagNoiseMatrixGraph_2D_Chamber3->SetFillColor(3);
0246
0247 int idArray[9];
0248 GetChamberIDs(idArray);
0249 for (int chamNum = 0; chamNum<9; ++chamNum){
0250 int chamNumPlus = chamNum + 1;
0251
0252 Int_t chamber_id_int = idArray[chamNum];
0253 std::stringstream chamber_id_stream;
0254 chamber_id_stream << chamber_id_int;
0255 TString chamber_id_str = chamber_id_stream.str();
0256 if (chamber_id_str.BeginsWith("220")==0 ){
0257 chamber_id_str=0;
0258 }else{
0259 chamber_id_str.Remove(8,8);
0260 chamber_id_str.Remove(0,3);
0261 }
0262 flagNoiseMatrixGraph_2D_Chamber->GetXaxis()->SetBinLabel(chamNumPlus,chamber_id_str);
0263 }
0264
0265 flagNoiseMatrixGraph_2D_Chamber->GetYaxis()->SetTitle("Flag");
0266 flagNoiseMatrixGraph_2D_Chamber->GetXaxis()->SetTitle("Chamber");
0267
0268 flagNoiseMatrixChamberCanv->cd();
0269
0270 flagNoiseMatrixGraph_2D_Chamber->Draw("box");
0271
0272 flagNoiseMatrixGraph_2D_Chamber1->Draw("samebox");
0273 flagNoiseMatrixGraph_2D_Chamber2->Draw("samebox");
0274 flagNoiseMatrixGraph_2D_Chamber3->Draw("samebox");
0275 flagNoiseMatrixGraph_2D_Chamber4->Draw("samebox");
0276
0277
0278 LegNoiseMatrixChamber->AddEntry(flagNoiseMatrixGraph_2D_Chamber1, "Good", "f");
0279 LegNoiseMatrixChamber->AddEntry(flagNoiseMatrixGraph_2D_Chamber2, "High Noise", "f");
0280 LegNoiseMatrixChamber->AddEntry(flagNoiseMatrixGraph_2D_Chamber3, "Low noise", "f");
0281 LegNoiseMatrixChamber->Draw("same");
0282
0283
0284 PrintAsGif(flagNoiseMatrixChamberCanv, "flagNoiseMatrixChamber");
0285 gStyle->SetOptStat(0);gSystem->cd("../../../");
0286 directoryCheck();
0287 }