Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:46

0001 void noiseMatrixMacro(){
0002 gROOT->SetBatch();
0003 gROOT->ProcessLine(".L GenFuncMacro.C");
0004 
0005 //get myFile. this is for batch processecing 
0006 //copies the name of any file beginning with "c" from the /tmp/csccalib directory. 
0007 char *myFileName;  //new file name for directory name
0008 char *myFilePath; //for accessing file by root 
0009 void *dirp = gSystem->OpenDirectory("/tmp/csccalib"); //read tmp directory
0010 char *afile; //temp file name
0011 while(afile = gSystem->GetDirEntry(dirp)) { //parse directory
0012    char *bfile[0] = afile[0]; //new temp file name
0013    if (bfile[0]=='c') { //if file begins with c
0014      printf("file: %s\n",afile); //check name
0015      myFileName = afile; //set for out of scope processing
0016    }
0017    myFilePath = Form("/tmp/csccalib/%s", myFileName);
0018 }
0019 
0020 //set global parameters
0021 int nDDU  = 1;
0022 int nCham =  1;
0023 int nLayer = 6;
0024 
0025 //style-ize all canvases
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 //get number of chambers per DDU, don't save graph. reatains value for NEntires. 
0037 Calibration->Draw("cham");
0038 int nCham = htemp->GetXaxis()->GetXmax();
0039 
0040 //this is one big section of linux directory processing
0041 //if this is edited, be careful! it's easy to mess up. 
0042 gSystem->cd("/afs/cern.ch/cms/CSC/html/csccalib/");
0043 
0044 //create "images" folder. 
0045 makeDirectory("images");
0046 gSystem->cd("images");
0047  //create subdirectory Gains
0048 makeDirectory("NoiseMatrix");
0049 gSystem->cd("NoiseMatrix");
0050 //create subdirectory for run
0051 makeDirectory(myFileName);
0052 gSystem->cd(myFileName);
0053 gSystem->cd("../../../");
0054 
0055 //be in test before processing
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 //void GetNoiseBounds(int nChamber, int minNoise, int maxNoise){
0080 //void GetNoiseBounds(Float_t boundsMinArray[108], Float_t boundsMaxArray[108], Float_t boundsChamMin[9], Float_t boundsChamMax[9]){
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    //GetNoiseBounds(BoundsMinArray, BoundsMaxArray, BoundsChamMin, BoundsChamMax);
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      }//nElements
0129      noiseCanv->Update();    
0130      PrintAsGif(noiseCanv, NoiseCanvName);
0131    }//nCham
0132  }//nDDU
0133  //gSystem->cd("../../../../");
0134 gSystem->cd("../");
0135 directoryCheck();
0136 }//NoiseMatrixGraphs
0137 
0138 void NoiseMatrixLayerGraphs(TString myFileName, int nDDU, int nCham, int nLayer){
0139   //gSystem->cd("images/NoiseMatrix");
0140   //gSystem->cd(myFileName);
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    //   Float_t BoundsMinArray[108];
0149    //   Float_t BoundsMaxArray[108];
0150    Float_t BoundsChamMin[9];
0151    Float_t BoundsChamMax[9];
0152    //GetNoiseBounds(BoundsMinArray, BoundsMaxArray, BoundsChamMin, BoundsChamMax);
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        }//nElements 
0172        noiseCanv->Update();    
0173        PrintAsGif(noiseCanv, NoiseCanvName); 
0174      }//nLayer
0175      gSystem->cd("../");
0176    }//nCham 
0177  }//nDDU 
0178 gSystem->cd("../../../"); 
0179 directoryCheck(); 
0180 }//NoiseMatrixGraphs 
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 ///////// CHAMBER flag Graph ///////////////////////
0211 gStyle->SetOptStat(0);
0212 TCanvas *flagNoiseMatrixChamberCanv = new TCanvas("flagNoiseMatrixChamberCanv", "flagNoiseMatrixChamberCanv", 200,10,800,800);
0213 flagNoiseMatrixChamberCanv->SetCanvasSize(1200,800);
0214 
0215 //create legend 
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 //final histogram for display
0222 flagNoiseMatrixGraph_2D_Chamber = new TH2F("flagNoiseMatrixGraph_2D_Chamber", "flagNoiseMatrixGraph_2D_Chamber", 9, 0, 9, 4, 0, 4);
0223 ///dummy histo to get bin maximum
0224 flagNoiseMatrixGraph_2D_Chamber0 = new TH2F("flagNoiseMatrixGraph_2D_Chamber0", "flagNoiseMatrixGraph_2D_Chamber0", 9, 0, 9, 4, 0, 4);
0225 //one histo for each flag value. 
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 //fill completley, get bin maximum, set it for overall graph
0232 Calibration->Project("flagNoiseMatrixGraph_2D_Chamber0", "flagMatrix:cham"); 
0233 Double_t binMaxValCham = flagNoiseMatrixGraph_2D_Chamber0->GetMaximum();
0234 //normalize each box appropriately, with respect to the most filled box
0235 flagNoiseMatrixGraph_2D_Chamber->SetMaximum(binMaxValCham);
0236 
0237 //fill each "bin"
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 //set appropriate colors
0243 flagNoiseMatrixGraph_2D_Chamber1->SetFillColor(1);//Black for eveything is OK
0244 flagNoiseMatrixGraph_2D_Chamber2->SetFillColor(2);//red for VERY BAD
0245 flagNoiseMatrixGraph_2D_Chamber3->SetFillColor(3);//Green for pretty good
0246 
0247 int idArray[9];
0248 GetChamberIDs(idArray);
0249 for (int chamNum = 0; chamNum<9; ++chamNum){
0250 int chamNumPlus = chamNum + 1; //for bin access
0251 
0252 Int_t chamber_id_int = idArray[chamNum]; //set individual id as int
0253 std::stringstream chamber_id_stream;     //define variable in intermediate format
0254 chamber_id_stream << chamber_id_int;     //convert from int to intermediate "stringstream" format
0255 TString chamber_id_str = chamber_id_stream.str();  //convert from stream into string
0256  if (chamber_id_str.BeginsWith("220")==0 ){  //binary check, i.e. if the string doesn't begin with 220
0257    chamber_id_str=0;                         //clean out; set to 0.
0258  }else{
0259    chamber_id_str.Remove(8,8);               //remove 0 at end
0260    chamber_id_str.Remove(0,3);               //remove 220 at beginning 
0261  }
0262 flagNoiseMatrixGraph_2D_Chamber->GetXaxis()->SetBinLabel(chamNumPlus,chamber_id_str); //set bins to have chamber names
0263 }
0264 
0265 flagNoiseMatrixGraph_2D_Chamber->GetYaxis()->SetTitle("Flag");
0266 flagNoiseMatrixGraph_2D_Chamber->GetXaxis()->SetTitle("Chamber");
0267 
0268 flagNoiseMatrixChamberCanv->cd();  
0269 //draw original histogram, empty
0270 flagNoiseMatrixGraph_2D_Chamber->Draw("box");
0271 //overlay the individual "bin" graphs
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 //set legend entries appropriately
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 //print as gif
0284 PrintAsGif(flagNoiseMatrixChamberCanv, "flagNoiseMatrixChamber");
0285 gStyle->SetOptStat(0);gSystem->cd("../../../");
0286 directoryCheck();
0287 }