Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:57:14

0001 void gainsMacro(){
0002 //proccess in batch mode. this takes a VERY long time out of batch mode
0003 gROOT->SetBatch();
0004 //contains several functions used in other macros as well
0005 gROOT->ProcessLine(".L GenFuncMacro.C");
0006 
0007 //get myFile. this is for batch processecing 
0008 //copies the name of any file beginning with "c" from the /tmp/csccalib directory. 
0009 char *myFileName;  //new file name for directory name
0010 char *myFilePath; //for accessing file by root 
0011 void *dirp = gSystem->OpenDirectory("/tmp/csccalib"); //read tmp directory
0012 char *afile; //temp file name
0013 while(afile = gSystem->GetDirEntry(dirp)) { //parse directory
0014    char *bfile[0] = afile[0]; //new temp file name
0015    if (bfile[0]=='c') { //if file begins with c
0016      printf("file: %s\n",afile); //check name
0017      myFileName = afile; //set for out of scope processing
0018    }
0019    myFilePath = Form("/tmp/csccalib/%s", myFileName);
0020 }
0021 
0022 //set global parameters
0023 int nDDU  = 1;
0024 int nCham =  1;
0025 int nLayer = 6;
0026 
0027 //style-ize all canvases
0028 gStyle->SetCanvasColor(0);
0029 gStyle->SetPadColor(0);
0030 gStyle->SetPadBorderMode(0);
0031 gStyle->SetCanvasBorderMode(0);
0032 gStyle->SetFrameBorderMode(0);
0033 gStyle->SetStatH(0.2);
0034 gStyle->SetStatW(0.3);
0035 
0036 directoryCheck();
0037 
0038 //open file generated from analyzer
0039 std::cout << "opening: " << myFileName << std::endl; 
0040 TFile *myFile = TFile::Open(myFilePath);
0041 
0042 Calibration->Draw("cham");
0043 int nCham = htemp->GetXaxis()->GetXmax();
0044 
0045 //system is in folder "test". check:  
0046 directoryCheck();
0047 
0048 //this is one big section of linux directory processing
0049 //if this is edited, be careful! it's easy to mess up. 
0050 gSystem->cd("/afs/cern.ch/cms/CSC/html/csccalib/");
0051 makeDirectory("images");
0052 gSystem->cd("images");
0053  //create subdirectory Gains
0054 makeDirectory("Gains");
0055 gSystem->cd("Gains/");
0056 //create subdirectory for run
0057 makeDirectory(myFileName);
0058 gSystem->cd(myFileName);
0059 gSystem->cd("../../../");
0060 
0061 SlopeFlagGraphs(myFileName);
0062 InterceptFlagGraphs(myFileName);
0063 gStyle->SetOptStat(0);
0064 gStyle->SetMarkerStyle(20);
0065 gStyle->SetMarkerSize(0.6);
0066 SlopeVsStrip(myFileName, nDDU,nCham,nLayer);
0067 InterceptVsStrip(myFileName, nDDU,nCham,nLayer);
0068 myFile->Close();
0069 gSystem->cd("/afs/cern.ch/user/c/csccalib/scratch0/CMSSW_1_1_1/src/OnlineDB/CSCCondDB/test");
0070 myFilePath = Form("/tmp/csccalib/%s", myFileName); 
0071 std::cout << "just before PulseGraphs" << std::endl;
0072 std::cout << " fileName: " << myFileName << std::endl;
0073 std::cout << " filePath: " << myFilePath << std::endl;
0074 GetADCCharge (myFileName, myFilePath);
0075 gStyle->SetOptStat(1);
0076 gROOT->ProcessLine(".q");
0077 } 
0078  
0079 //this creates an array which can then be accessed
0080 //proper usage: 
0081 //  int idArray[9];
0082 //  GetChamberIDs(idArray);
0083 //  std::cout << "id for chamber 0: " << idArray[0] << std::endl;
0084 void GetChamberIDs(int IDArray[9]){
0085 TCanvas *IDcanv = new TCanvas ("idGraph", "idGraph");
0086 IDcanv->cd();
0087 TH1F *idDummy = new TH1F("idDummy", "idDummy", 480, 111000, 250000);
0088 idDummy->Draw();
0089 for (int chamber=0; chamber<9; ++chamber){
0090   TString idCut = Form ("cham==%d", chamber);
0091   Calibration->Project("idDummy", "id", idCut);
0092   Int_t idNum = idDummy->GetMean();
0093   IDArray[chamber]=idNum;
0094 }
0095 }
0096 
0097 void GetADCCharge(TString myFileName, TString myFilePath){
0098 TFile *myFile = TFile::Open(myFilePath);
0099 
0100 TH1F *ADCCharge;  
0101 gSystem->cd("/afs/cern.ch/cms/CSC/html/csccalib/");
0102 TCanvas *ADCChargeCanvas = new TCanvas("ADC_Charge", "ADC_Charge",1100,700);
0103 ADCCharge = (TH1F*)myFile->Get("adcCharge");  
0104 ADCChargeCanvas->cd(); 
0105 ADCCharge->GetYaxis()->SetTitle("ADC Count"); 
0106 ADCCharge->GetXaxis()->SetTitle("Charge"); 
0107 ADCCharge->Draw();
0108 ADCChargeCanvas->Update();  
0109 
0110 gSystem->cd("images/Gains/");
0111 gSystem->cd(myFileName);
0112 PrintAsGif(ADCChargeCanvas, "ADC_Charge");
0113 gSystem->cd("../../../");
0114 directoryCheck(); 
0115 myFile->Close();
0116 }
0117 
0118 void SlopeVsStrip(TString myFileName, int nDDU, int nCham, int nLayer){
0119 gSystem->cd("images/Gains/");
0120 gSystem->cd(myFileName);
0121 makeDirectory("SlopeVsStripGraphs");
0122 gSystem->cd("SlopeVsStripGraphs");
0123 
0124 TH2F *slopeGraph;
0125 TCanvas *slopeCanv;
0126 for (int i=0; i<nDDU; ++i){
0127   int idArray[9];
0128   GetChamberIDs(idArray);
0129   for (int j=0; j<nCham; ++j){
0130     TString slopeCanvName = Form("Slope_per_strip_Chamber_%d_DDU_%d",idArray[j],i);
0131     slopeCanv = new TCanvas(slopeCanvName, slopeCanvName,200, 20, 1100,700);
0132     slopeCanv->Divide(3,2);
0133     for (int k=0; k<nLayer; ++k){
0134       TString slopeGraphName = Form("Layer_%d_Slope",k);
0135       slopeGraph = new TH2F(slopeGraphName,slopeGraphName,80,0,80,20,5,10); 
0136       slopeCanv->cd(k+1); 
0137       TString slopeGraphCut = Form("cham==%d&&layer==%d",j,k); 
0138       slopeGraph->SetName(slopeGraphName);
0139       slopeGraph->SetTitle(slopeGraphName);
0140       slopeGraph->GetXaxis()->SetTitle("strip");
0141       slopeGraph->GetXaxis()->SetTitleSize(0.06);
0142       slopeGraph->GetXaxis()->SetTitleOffset(0.7);
0143       slopeGraph->GetYaxis()->SetTitleSize(0.06);
0144       slopeGraph->GetYaxis()->SetTitleOffset(0.7);
0145       slopeGraph->GetYaxis()->SetTitle("slope");
0146       slopeGraph->Draw();
0147       Calibration->Project(slopeGraphName, "slope:strip", slopeGraphCut);      
0148       slopeCanv->Update(); 
0149     }//nLayer
0150     PrintAsGif(slopeCanv, slopeCanvName);
0151   }//nCham
0152 }//nDDU
0153 gSystem->cd("../../../../");
0154 directoryCheck();
0155 }//SlopeVsStrip
0156 
0157 void InterceptVsStrip(TString myFileName, int nDDU, int nCham, int nLayer){
0158 gSystem->cd("images/Gains/");
0159 gSystem->cd(myFileName);
0160 makeDirectory("InterceptVsStripGraphs");
0161 gSystem->cd("InterceptVsStripGraphs");
0162 
0163 TH2F *interceptGraph;
0164 TCanvas *interceptCanv;
0165 for (int i=0; i<nDDU; ++i){
0166   int idArray[9];
0167   GetChamberIDs(idArray);
0168   for (int j=0; j<nCham; ++j){
0169     TString interceptCanvName = Form("Intercept_per_strip_Chamber_%d_DDU_%d",idArray[j],i);
0170     interceptCanv = new TCanvas(interceptCanvName, interceptCanvName,200, 20, 1100,700);
0171     interceptCanv->Divide(3,2);
0172     for (int k=0; k<nLayer; ++k){
0173       TString interceptGraphName = Form("Layer_%d_Intercept",k);
0174       interceptGraph = new TH2F(interceptGraphName,interceptGraphName,80,0,80,20,-50,50); 
0175       interceptCanv->cd(k+1); 
0176       TString interceptGraphCut = Form("cham==%d&&layer==%d",j,k); 
0177       interceptGraph->SetName(interceptGraphName);
0178       interceptGraph->SetTitle(interceptGraphName);
0179       interceptGraph->GetXaxis()->SetTitle("strip");
0180       interceptGraph->GetXaxis()->SetTitleSize(0.06);
0181       interceptGraph->GetXaxis()->SetTitleOffset(0.7);
0182       interceptGraph->GetYaxis()->SetTitleSize(0.06);
0183       interceptGraph->GetYaxis()->SetTitleOffset(0.7);
0184       interceptGraph->GetYaxis()->SetTitle("intercept");
0185       interceptGraph->Draw();
0186       Calibration->Project(interceptGraphName, "intercept:strip", interceptGraphCut);      
0187       interceptCanv->Update(); 
0188     }//nLayer
0189     PrintAsGif(interceptCanv, interceptCanvName);
0190   }//nCham
0191 }//nDDU
0192 gSystem->cd("../../../../");
0193 directoryCheck();
0194 }//InterceptVsStrip
0195 
0196 void SlopeFlagGraphs(TString myFileName){
0197 gSystem->cd("images/Gains/");
0198 gSystem->cd(myFileName);
0199 
0200 TCanvas *flagGainCanv = new TCanvas("flagGainCanv", "flagGainCanv", 200,10,800,800);
0201 flagGainCanv->SetCanvasSize(1200,800);
0202 flagGainGraph_1D = new TH1F("flagGainGraph_1D", "flagGainGraph_1D", 5, 0, 5);
0203 flagGainGraph_1D->GetYaxis()->SetTitle("Number of flag of each type");
0204 flagGainGraph_1D->GetYaxis()->SetLabelSize(0.035);
0205 
0206 TLegend *LegGain = new TLegend(0.85,0.8,0.98,0.98);
0207 LegGain->SetHeader("Slope Flags Definitions");
0208 LegGain->SetFillColor(0);
0209 LegGain->SetTextSize(0);
0210 
0211 Calibration->UseCurrentStyle(); 
0212 Calibration->Draw("flagGain>>flagGainGraph_1D");
0213 
0214 LegGain->AddEntry("", "1: Good");
0215 LegGain->AddEntry("", "2: Low slope, fit fails");
0216 LegGain->AddEntry("", "3: High slope., fit fails");
0217 LegGain->Draw("same");
0218 
0219 flagGainCanv->Update();
0220 
0221 /////////////////////////////////       2D GRAPHS            ////////////////////////////////
0222 //no statistics shown
0223 gStyle->SetOptStat(0);
0224 
0225 ////////// Strip Flag Graphs///////////////
0226 //canvas
0227 TCanvas *flagGainStripCanv = new TCanvas("flagGainStripCanv", "flagGainStripCanv", 200,10,800,800);
0228 flagGainStripCanv->SetCanvasSize(1200,800);
0229 
0230 //create legend 
0231 TLegend *LegGainStrip = new TLegend(0.85,0.8,0.98,0.98);
0232 LegGainStrip->SetHeader("Slope Flags Definitions");
0233 LegGainStrip->SetFillColor(0);
0234 LegGainStrip->SetTextSize(0);
0235 
0236 //final histogram for display
0237 flagGainGraph_2D_Strip = new TH2F("flagGainGraph_2D_Strip", "flagGainGraph_2D_Strip", 80, 0, 80, 4, 0, 4);
0238 ///dummy histo to get bin maximum
0239 flagGainGraph_2D_Strip0 = new TH2F("flagGainGraph_2D_Strip0", "flagGainGraph_2D_Strip0", 80, 0, 80, 4, 0, 4);
0240 //one histo for each flag value. 
0241 flagGainGraph_2D_Strip1 = new TH2F("flagGainGraph_2D_Strip1", "flagGainGraph_2D_Strip1", 80, 0, 80, 4, 0, 4);
0242 flagGainGraph_2D_Strip2 = new TH2F("flagGainGraph_2D_Strip2", "flagGainGraph_2D_Strip2", 80, 0, 80, 4, 0, 4);
0243 flagGainGraph_2D_Strip3 = new TH2F("flagGainGraph_2D_Strip3", "flagGainGraph_2D_Strip3", 80, 0, 80, 4, 0, 4);
0244 flagGainGraph_2D_Strip4 = new TH2F("flagGainGraph_2D_Strip4", "flagGainGraph_2D_Strip4", 80, 0, 80, 4, 0, 4);
0245 
0246 //fill completley, get bin maximum, set it for overall graph
0247 Calibration->Project("flagGainGraph_2D_Strip0","flagGain:strip"); 
0248 Double_t binMaxValStrip = flagGainGraph_2D_Strip0->GetMaximum();
0249 //normalize each box appropriately, with respect to the most filled box
0250 flagGainGraph_2D_Strip->SetMaximum(binMaxValStrip);
0251 //fill each "bin"
0252 Calibration->Project("flagGainGraph_2D_Strip1","flagGain:strip", "flagGain==1","box"); 
0253 Calibration->Project("flagGainGraph_2D_Strip2","flagGain:strip", "flagGain==2","box"); 
0254 Calibration->Project("flagGainGraph_2D_Strip3","flagGain:strip", "flagGain==3","box"); 
0255 
0256 //set appropriate colors
0257 flagGainGraph_2D_Strip1->SetFillColor(1);//Black for eveything is OK
0258 flagGainGraph_2D_Strip2->SetFillColor(2);//red for VERY BAD
0259 flagGainGraph_2D_Strip3->SetFillColor(3);//Green for pretty good
0260 
0261 flagGainStripCanv->cd(); 
0262 flagGainGraph_2D_Strip->GetYaxis()->SetTitle("Flag");
0263 flagGainGraph_2D_Strip->GetXaxis()->SetTitle("Strip");
0264   
0265 //draw original histogram, empty
0266 flagGainGraph_2D_Strip->Draw("box");
0267 //overlay the individual "bin" graphs
0268 flagGainGraph_2D_Strip1->Draw("samebox");
0269 flagGainGraph_2D_Strip2->Draw("samebox");
0270 flagGainGraph_2D_Strip3->Draw("samebox");
0271 flagGainGraph_2D_Strip4->Draw("samebox");
0272 
0273 //set legend entries appropriately
0274 LegGainStrip->AddEntry(flagGainGraph_2D_Strip1, "Good", "f");
0275 LegGainStrip->AddEntry(flagGainGraph_2D_Strip2, "Low slope, fit fails", "f");
0276 LegGainStrip->AddEntry(flagGainGraph_2D_Strip3, "High slope, fit fails", "f");
0277 LegGainStrip->Draw("same");
0278 
0279 //print as gif
0280 PrintAsGif(flagGainStripCanv, "flagGainStrip");
0281 
0282 ///////// CHAMBER flag Graph ///////////////////////
0283 TCanvas *flagGainChamberCanv = new TCanvas("flagGainChamberCanv", "flagGainChamberCanv", 200,10,800,800);
0284 flagGainChamberCanv->SetCanvasSize(1200,800);
0285 
0286 //create legend 
0287 TLegend *LegGainChamber = new TLegend(0.85,0.8,0.98,0.98);
0288 LegGainChamber->SetHeader("Slope Flags Definitions");
0289 LegGainChamber->SetFillColor(0);
0290 LegGainChamber->SetTextSize(0);
0291 
0292 //final histogram for display
0293 flagGainGraph_2D_Chamber = new TH2F("flagGainGraph_2D_Chamber", "flagGainGraph_2D_Chamber", 9, 0, 9, 4, 0, 4);
0294 ///dummy histo to get bin maximum
0295 flagGainGraph_2D_Chamber0 = new TH2F("flagGainGraph_2D_Chamber0", "flagGainGraph_2D_Chamber0", 9, 0, 9, 4, 0, 4);
0296 //one histo for each flag value. 
0297 flagGainGraph_2D_Chamber1 = new TH2F("flagGainGraph_2D_Chamber1", "flagGainGraph_2D_Chamber1", 9, 0, 9, 4, 0, 4);
0298 flagGainGraph_2D_Chamber2 = new TH2F("flagGainGraph_2D_Chamber2", "flagGainGraph_2D_Chamber2", 9, 0, 9, 4, 0, 4);
0299 flagGainGraph_2D_Chamber3 = new TH2F("flagGainGraph_2D_Chamber3", "flagGainGraph_2D_Chamber3", 9, 0, 9, 4, 0, 4);
0300 flagGainGraph_2D_Chamber4 = new TH2F("flagGainGraph_2D_Chamber4", "flagGainGraph_2D_Chamber4", 9, 0, 9, 4, 0, 4);
0301 
0302 //fill completley, get bin maximum, set it for overall graph
0303 Calibration->Project("flagGainGraph_2D_Chamber0","flagGain:cham"); 
0304 Double_t binMaxValCham = flagGainGraph_2D_Chamber0->GetMaximum();
0305 //normalize each box appropriately, with respect to the most filled box
0306 flagGainGraph_2D_Chamber->SetMaximum(binMaxValCham);
0307 
0308 //fill each "bin"
0309 Calibration->Project("flagGainGraph_2D_Chamber1","flagGain:cham", "flagGain==1", "box"); 
0310 Calibration->Project("flagGainGraph_2D_Chamber2","flagGain:cham", "flagGain==2", "box"); 
0311 Calibration->Project("flagGainGraph_2D_Chamber3","flagGain:cham", "flagGain==3", "box"); 
0312 
0313 //set appropriate colors
0314 flagGainGraph_2D_Chamber1->SetFillColor(1);//Black for eveything is OK
0315 flagGainGraph_2D_Chamber2->SetFillColor(2);//red for VERY BAD
0316 flagGainGraph_2D_Chamber3->SetFillColor(3);//Green for pretty good
0317 
0318 int idArray[9];
0319 GetChamberIDs(idArray);
0320 for (int chamNum = 0; chamNum<9; ++chamNum){
0321 int chamNumPlus = chamNum + 1; //for bin access
0322 
0323 Int_t chamber_id_int = idArray[chamNum]; //set individual id as int
0324 std::stringstream chamber_id_stream;     //define variable in intermediate format
0325 chamber_id_stream << chamber_id_int;     //convert from int to intermediate "stringstream" format
0326 TString chamber_id_str = chamber_id_stream.str();  //convert from stream into string
0327  if (chamber_id_str.BeginsWith("220")==0 ){  //binary check, i.e. if the string doesn't begin with 220
0328    chamber_id_str=0;                         //clean out; set to 0.
0329  }else{
0330    chamber_id_str.Remove(8,8);               //remove 0 at end
0331    chamber_id_str.Remove(0,3);               //remove 220 at beginning 
0332  }
0333 flagGainGraph_2D_Chamber->GetXaxis()->SetBinLabel(chamNumPlus,chamber_id_str); //set bins to have chamber names
0334 }
0335 
0336 flagGainGraph_2D_Chamber->GetYaxis()->SetTitle("Flag");
0337 flagGainGraph_2D_Chamber->GetXaxis()->SetTitle("Chamber");
0338 
0339 flagGainChamberCanv->cd();  
0340 //draw original histogram, empty
0341 flagGainGraph_2D_Chamber->Draw("box");
0342 //overlay the individual "bin" graphs
0343 flagGainGraph_2D_Chamber1->Draw("samebox");
0344 flagGainGraph_2D_Chamber2->Draw("samebox");
0345 flagGainGraph_2D_Chamber3->Draw("samebox");
0346 flagGainGraph_2D_Chamber4->Draw("samebox");
0347 
0348 //set legend entries appropriately
0349 LegGainChamber->AddEntry(flagGainGraph_2D_Chamber1, "Good", "f");
0350 LegGainChamber->AddEntry(flagGainGraph_2D_Chamber2, "Low slope, fit fails", "f");
0351 LegGainChamber->AddEntry(flagGainGraph_2D_Chamber3, "High slope, fit fails", "f");
0352 LegGainChamber->Draw("same");
0353 
0354   //print as gif
0355 PrintAsGif(flagGainChamberCanv, "flagGainChamber");
0356 
0357 /////////////////////// Layer Graphs //////////////
0358 
0359 TCanvas *flagGainLayerCanv = new TCanvas("flagGainLayerCanv", "flagGainLayerCanv", 200,10,800,800);
0360 flagGainLayerCanv->SetCanvasSize(1200,800);
0361 
0362 //create legend 
0363 TLegend *LegGainLayer = new TLegend(0.85,0.8,0.98,0.98);
0364 LegGainLayer->SetHeader("Slope Flags Definitions");
0365 LegGainLayer->SetFillColor(0);
0366 LegGainLayer->SetTextSize(0);
0367 
0368 //final histogram for display
0369 flagGainGraph_2D_Layer = new TH2F("flagGainGraph_2D_Layer", "flagGainGraph_2D_Layer", 6, 0, 6, 4, 0, 4);
0370 ///dummy histo to get bin maximum
0371 flagGainGraph_2D_Layer0 = new TH2F("flagGainGraph_2D_Layer0", "flagGainGraph_2D_Layer0", 6, 0, 6, 4, 0, 4);
0372 //one histo for each flag value. 
0373 flagGainGraph_2D_Layer1 = new TH2F("flagGainGraph_2D_Layer1", "flagGainGraph_2D_Layer1", 6, 0, 6, 4, 0, 4);
0374 flagGainGraph_2D_Layer2 = new TH2F("flagGainGraph_2D_Layer2", "flagGainGraph_2D_Layer2", 6, 0, 6, 4, 0, 4);
0375 flagGainGraph_2D_Layer3 = new TH2F("flagGainGraph_2D_Layer3", "flagGainGraph_2D_Layer3", 6, 0, 6, 4, 0, 4);
0376 flagGainGraph_2D_Layer4 = new TH2F("flagGainGraph_2D_Layer4", "flagGainGraph_2D_Layer4", 6, 0, 6, 4, 0, 4);
0377 
0378 //fill completley, get bin maximum, set it for overall graph
0379 Calibration->Project("flagGainGraph_2D_Layer0","flagGain:layer"); 
0380 Double_t binMaxValLayer = flagGainGraph_2D_Layer0->GetMaximum();
0381 //normalize each box appropriately, with respect to the most filled box
0382 flagGainGraph_2D_Layer->SetMaximum(binMaxValLayer);
0383 
0384 //fill each "bin"
0385 Calibration->Project("flagGainGraph_2D_Layer1","flagGain:layer", "flagGain==1", "box"); 
0386 Calibration->Project("flagGainGraph_2D_Layer2","flagGain:layer", "flagGain==2", "box"); 
0387 Calibration->Project("flagGainGraph_2D_Layer3","flagGain:layer", "flagGain==3", "box"); 
0388 
0389 //set appropriate colors
0390 flagGainGraph_2D_Layer1->SetFillColor(1);//Black for eveything is OK
0391 flagGainGraph_2D_Layer2->SetFillColor(2);//red for VERY BAD
0392 flagGainGraph_2D_Layer3->SetFillColor(3);//Green for pretty good
0393 
0394 flagGainLayerCanv->cd(); 
0395 flagGainGraph_2D_Layer->GetYaxis()->SetTitle("Flag");
0396 flagGainGraph_2D_Layer->GetXaxis()->SetTitle("Layer");
0397   
0398 //draw original histogram, empty
0399 flagGainGraph_2D_Layer->Draw("box");
0400 //overlay the individual "bin" graphs
0401 flagGainGraph_2D_Layer1->Draw("samebox");
0402 flagGainGraph_2D_Layer2->Draw("samebox");
0403 flagGainGraph_2D_Layer3->Draw("samebox");
0404 flagGainGraph_2D_Layer4->Draw("samebox");
0405 
0406 //set legend entries appropriately
0407 LegGainLayer->AddEntry(flagGainGraph_2D_Layer1, "Good", "f");
0408 LegGainLayer->AddEntry(flagGainGraph_2D_Layer2, "Low slope, fit fails", "f");
0409 LegGainLayer->AddEntry(flagGainGraph_2D_Layer3, "High slope, fit fails", "f");
0410 LegGainLayer->Draw("same");
0411 
0412 //print as gif
0413 PrintAsGif(flagGainLayerCanv, "flagGainLayer");
0414 gSystem->cd("../../../");
0415 directoryCheck();
0416 gStyle->SetOptStat(1); 
0417 }
0418 
0419 void InterceptFlagGraphs(TString myFileName){
0420 gSystem->cd("images/Gains/");
0421 gSystem->cd(myFileName);
0422 
0423 TCanvas *flagInterceptCanv = new TCanvas("flagInterceptCanv", "flagInterceptCanv", 200,10,800,800);
0424 flagInterceptCanv->SetCanvasSize(1200,800);
0425 flagInterceptGraph_1D = new TH1F("flagInterceptGraph_1D", "flagInterceptGraph_1D", 5, 0, 5);
0426 flagInterceptGraph_1D->GetYaxis()->SetTitle("Number of flag of each type");
0427 flagInterceptGraph_1D->GetYaxis()->SetLabelSize(0.035);
0428 
0429 TLegend *LegGain = new TLegend(0.85,0.8,0.98,0.98);
0430 LegGain->SetHeader("Intercept Flags Definitions");
0431 LegGain->SetFillColor(0);
0432 LegGain->SetTextSize(0);
0433 
0434 Calibration->UseCurrentStyle(); 
0435 Calibration->Draw("flagIntercept>>flagInterceptGraph_1D");
0436 
0437 LegGain->AddEntry("", "1: Good");
0438 LegGain->AddEntry("", "2: Low intercept, fit fails");
0439 LegGain->AddEntry("", "3: High intercept., fit fails");
0440 LegGain->Draw("same");
0441 
0442 flagInterceptCanv->Update();
0443 
0444 /////////////////////////////////       2D GRAPHS            ////////////////////////////////
0445 //no statistics shown
0446 gStyle->SetOptStat(0);
0447 
0448 ////////// Strip Flag Graphs///////////////
0449 //canvas
0450 TCanvas *flagInterceptStripCanv = new TCanvas("flagInterceptStripCanv", "flagInterceptStripCanv", 200,10,800,800);
0451 flagInterceptStripCanv->SetCanvasSize(1200,800);
0452 
0453 //create legend 
0454 TLegend *LegGainStrip = new TLegend(0.85,0.8,0.98,0.98);
0455 LegGainStrip->SetHeader("Intercept Flags Definitions");
0456 LegGainStrip->SetFillColor(0);
0457 LegGainStrip->SetTextSize(0);
0458 
0459 //final histogram for display
0460 flagInterceptGraph_2D_Strip = new TH2F("flagInterceptGraph_2D_Strip", "flagInterceptGraph_2D_Strip", 80, 0, 80, 4, 0, 4);
0461 ///dummy histo to get bin maximum
0462 flagInterceptGraph_2D_Strip0 = new TH2F("flagInterceptGraph_2D_Strip0", "flagInterceptGraph_2D_Strip0", 80, 0, 80, 4, 0, 4);
0463 //one histo for each flag value. 
0464 flagInterceptGraph_2D_Strip1 = new TH2F("flagInterceptGraph_2D_Strip1", "flagInterceptGraph_2D_Strip1", 80, 0, 80, 4, 0, 4);
0465 flagInterceptGraph_2D_Strip2 = new TH2F("flagInterceptGraph_2D_Strip2", "flagInterceptGraph_2D_Strip2", 80, 0, 80, 4, 0, 4);
0466 flagInterceptGraph_2D_Strip3 = new TH2F("flagInterceptGraph_2D_Strip3", "flagInterceptGraph_2D_Strip3", 80, 0, 80, 4, 0, 4);
0467 flagInterceptGraph_2D_Strip4 = new TH2F("flagInterceptGraph_2D_Strip4", "flagInterceptGraph_2D_Strip4", 80, 0, 80, 4, 0, 4);
0468 
0469 //fill completley, get bin maximum, set it for overall graph
0470 Calibration->Project("flagInterceptGraph_2D_Strip0","flagIntercept:strip"); 
0471 Double_t binMaxValStrip = flagInterceptGraph_2D_Strip0->GetMaximum();
0472 //normalize each box appropriately, with respect to the most filled box
0473 flagInterceptGraph_2D_Strip->SetMaximum(binMaxValStrip);
0474 //fill each "bin"
0475 Calibration->Project("flagInterceptGraph_2D_Strip1","flagIntercept:strip", "flagIntercept==1","box"); 
0476 Calibration->Project("flagInterceptGraph_2D_Strip2","flagIntercept:strip", "flagIntercept==2","box"); 
0477 Calibration->Project("flagInterceptGraph_2D_Strip3","flagIntercept:strip", "flagIntercept==3","box"); 
0478 
0479 //set appropriate colors
0480 flagInterceptGraph_2D_Strip1->SetFillColor(1);//Black for eveything is OK
0481 flagInterceptGraph_2D_Strip2->SetFillColor(2);//red for VERY BAD
0482 flagInterceptGraph_2D_Strip3->SetFillColor(3);//Green for pretty good
0483 
0484 flagInterceptStripCanv->cd(); 
0485 flagInterceptGraph_2D_Strip->GetYaxis()->SetTitle("Flag");
0486 flagInterceptGraph_2D_Strip->GetXaxis()->SetTitle("Strip");
0487   
0488 //draw original histogram, empty
0489 flagInterceptGraph_2D_Strip->Draw("box");
0490 //overlay the individual "bin" graphs
0491 flagInterceptGraph_2D_Strip1->Draw("samebox");
0492 flagInterceptGraph_2D_Strip2->Draw("samebox");
0493 flagInterceptGraph_2D_Strip3->Draw("samebox");
0494 flagInterceptGraph_2D_Strip4->Draw("samebox");
0495 
0496 //set legend entries appropriately
0497 LegGainStrip->AddEntry(flagInterceptGraph_2D_Strip1, "Good", "f");
0498 LegGainStrip->AddEntry(flagInterceptGraph_2D_Strip2, "Low intercept, fit fails", "f");
0499 LegGainStrip->AddEntry(flagInterceptGraph_2D_Strip3, "High intercept, fit fails", "f");
0500 LegGainStrip->Draw("same");
0501 
0502 //print as gif
0503 PrintAsGif(flagInterceptStripCanv, "flagInterceptStrip");
0504 
0505 ///////// CHAMBER flag Graph ///////////////////////
0506 TCanvas *flagInterceptChamberCanv = new TCanvas("flagInterceptChamberCanv", "flagInterceptChamberCanv", 200,10,800,800);
0507 flagInterceptChamberCanv->SetCanvasSize(1200,800);
0508 
0509 //create legend 
0510 TLegend *LegGainChamber = new TLegend(0.85,0.8,0.98,0.98);
0511 LegGainChamber->SetHeader("Intercept Flags Definitions");
0512 LegGainChamber->SetFillColor(0);
0513 LegGainChamber->SetTextSize(0);
0514 
0515 //final histogram for display
0516 flagInterceptGraph_2D_Chamber = new TH2F("flagInterceptGraph_2D_Chamber", "flagInterceptGraph_2D_Chamber", 9, 0, 9, 4, 0, 4);
0517 ///dummy histo to get bin maximum
0518 flagInterceptGraph_2D_Chamber0 = new TH2F("flagInterceptGraph_2D_Chamber0", "flagInterceptGraph_2D_Chamber0", 9, 0, 9, 4, 0, 4);
0519 //one histo for each flag value. 
0520 flagInterceptGraph_2D_Chamber1 = new TH2F("flagInterceptGraph_2D_Chamber1", "flagInterceptGraph_2D_Chamber1", 9, 0, 9, 4, 0, 4);
0521 flagInterceptGraph_2D_Chamber2 = new TH2F("flagInterceptGraph_2D_Chamber2", "flagInterceptGraph_2D_Chamber2", 9, 0, 9, 4, 0, 4);
0522 flagInterceptGraph_2D_Chamber3 = new TH2F("flagInterceptGraph_2D_Chamber3", "flagInterceptGraph_2D_Chamber3", 9, 0, 9, 4, 0, 4);
0523 flagInterceptGraph_2D_Chamber4 = new TH2F("flagInterceptGraph_2D_Chamber4", "flagInterceptGraph_2D_Chamber4", 9, 0, 9, 4, 0, 4);
0524 
0525 //fill completley, get bin maximum, set it for overall graph
0526 Calibration->Project("flagInterceptGraph_2D_Chamber0","flagIntercept:cham"); 
0527 Double_t binMaxValCham = flagInterceptGraph_2D_Chamber0->GetMaximum();
0528 //normalize each box appropriately, with respect to the most filled box
0529 flagInterceptGraph_2D_Chamber->SetMaximum(binMaxValCham);
0530 
0531 //fill each "bin"
0532 Calibration->Project("flagInterceptGraph_2D_Chamber1","flagIntercept:cham", "flagIntercept==1", "box"); 
0533 Calibration->Project("flagInterceptGraph_2D_Chamber2","flagIntercept:cham", "flagIntercept==2", "box"); 
0534 Calibration->Project("flagInterceptGraph_2D_Chamber3","flagIntercept:cham", "flagIntercept==3", "box"); 
0535 
0536 //set appropriate colors
0537 flagInterceptGraph_2D_Chamber1->SetFillColor(1);//Black for eveything is OK
0538 flagInterceptGraph_2D_Chamber2->SetFillColor(2);//red for VERY BAD
0539 flagInterceptGraph_2D_Chamber3->SetFillColor(3);//Green for pretty good
0540 
0541 int idArray[9];
0542 GetChamberIDs(idArray);
0543 for (int chamNum = 0; chamNum<9; ++chamNum){
0544 int chamNumPlus = chamNum + 1; //for bin access
0545 
0546 Int_t chamber_id_int = idArray[chamNum]; //set individual id as int
0547 std::stringstream chamber_id_stream;     //define variable in intermediate format
0548 chamber_id_stream << chamber_id_int;     //convert from int to intermediate "stringstream" format
0549 TString chamber_id_str = chamber_id_stream.str();  //convert from stream into string
0550  if (chamber_id_str.BeginsWith("220")==0 ){  //binary check, i.e. if the string doesn't begin with 220
0551    chamber_id_str=0;                         //clean out; set to 0.
0552  }else{
0553    chamber_id_str.Remove(8,8);               //remove 0 at end
0554    chamber_id_str.Remove(0,3);               //remove 220 at beginning 
0555  }
0556 flagInterceptGraph_2D_Chamber->GetXaxis()->SetBinLabel(chamNumPlus,chamber_id_str); //set bins to have chamber names
0557 }
0558 
0559 flagInterceptGraph_2D_Chamber->GetYaxis()->SetTitle("Flag");
0560 flagInterceptGraph_2D_Chamber->GetXaxis()->SetTitle("Chamber");
0561 
0562 flagInterceptChamberCanv->cd(); 
0563  //draw original histogram, empty
0564 flagInterceptGraph_2D_Chamber->Draw("box");
0565 //overlay the individual "bin" graphs
0566 flagInterceptGraph_2D_Chamber1->Draw("samebox");
0567 flagInterceptGraph_2D_Chamber2->Draw("samebox");
0568 flagInterceptGraph_2D_Chamber3->Draw("samebox");
0569 flagInterceptGraph_2D_Chamber4->Draw("samebox");
0570 
0571 //set legend entries appropriately
0572 LegGainChamber->AddEntry(flagInterceptGraph_2D_Chamber1, "Good", "f");
0573 LegGainChamber->AddEntry(flagInterceptGraph_2D_Chamber2, "Low intercept, fit fails", "f");
0574 LegGainChamber->AddEntry(flagInterceptGraph_2D_Chamber3, "High intercept, fit fails", "f");
0575 LegGainChamber->Draw("same");
0576 
0577   //print as gif
0578 PrintAsGif(flagInterceptChamberCanv, "flagInterceptChamber");
0579 
0580 /////////////////////// Layer Graphs //////////////
0581 
0582 TCanvas *flagInterceptLayerCanv = new TCanvas("flagInterceptLayerCanv", "flagInterceptLayerCanv", 200,10,800,800);
0583 flagInterceptLayerCanv->SetCanvasSize(1200,800);
0584 
0585 //create legend 
0586 TLegend *LegGainLayer = new TLegend(0.85,0.8,0.98,0.98);
0587 LegGainLayer->SetHeader("Intercept Flags Definitions");
0588 LegGainLayer->SetFillColor(0);
0589 LegGainLayer->SetTextSize(0);
0590 
0591 //final histogram for display
0592 flagInterceptGraph_2D_Layer = new TH2F("flagInterceptGraph_2D_Layer", "flagInterceptGraph_2D_Layer", 6, 0, 6, 4, 0, 4);
0593 ///dummy histo to get bin maximum
0594 flagInterceptGraph_2D_Layer0 = new TH2F("flagInterceptGraph_2D_Layer0", "flagInterceptGraph_2D_Layer0", 6, 0, 6, 4, 0, 4);
0595 //one histo for each flag value. 
0596 flagInterceptGraph_2D_Layer1 = new TH2F("flagInterceptGraph_2D_Layer1", "flagInterceptGraph_2D_Layer1", 6, 0, 6, 4, 0, 4);
0597 flagInterceptGraph_2D_Layer2 = new TH2F("flagInterceptGraph_2D_Layer2", "flagInterceptGraph_2D_Layer2", 6, 0, 6, 4, 0, 4);
0598 flagInterceptGraph_2D_Layer3 = new TH2F("flagInterceptGraph_2D_Layer3", "flagInterceptGraph_2D_Layer3", 6, 0, 6, 4, 0, 4);
0599 flagInterceptGraph_2D_Layer4 = new TH2F("flagInterceptGraph_2D_Layer4", "flagInterceptGraph_2D_Layer4", 6, 0, 6, 4, 0, 4);
0600 
0601 //fill completley, get bin maximum, set it for overall graph
0602 Calibration->Project("flagInterceptGraph_2D_Layer0","flagIntercept:layer"); 
0603 Double_t binMaxValLayer = flagInterceptGraph_2D_Layer0->GetMaximum();
0604 //normalize each box appropriately, with respect to the most filled box
0605 flagInterceptGraph_2D_Layer->SetMaximum(binMaxValLayer);
0606 
0607 //fill each "bin"
0608 Calibration->Project("flagInterceptGraph_2D_Layer1","flagIntercept:layer", "flagIntercept==1", "box"); 
0609 Calibration->Project("flagInterceptGraph_2D_Layer2","flagIntercept:layer", "flagIntercept==2", "box"); 
0610 Calibration->Project("flagInterceptGraph_2D_Layer3","flagIntercept:layer", "flagIntercept==3", "box"); 
0611 
0612 //set appropriate colors
0613 flagInterceptGraph_2D_Layer1->SetFillColor(1);//Black for eveything is OK
0614 flagInterceptGraph_2D_Layer2->SetFillColor(2);//red for VERY BAD
0615 flagInterceptGraph_2D_Layer3->SetFillColor(3);//Green for pretty good
0616 
0617 flagInterceptLayerCanv->cd(); 
0618 flagInterceptGraph_2D_Layer->GetYaxis()->SetTitle("Flag");
0619 flagInterceptGraph_2D_Layer->GetXaxis()->SetTitle("Layer");
0620   
0621 //draw original histogram, empty
0622 flagInterceptGraph_2D_Layer->Draw("box");
0623 //overlay the individual "bin" graphs
0624 flagInterceptGraph_2D_Layer1->Draw("samebox");
0625 flagInterceptGraph_2D_Layer2->Draw("samebox");
0626 flagInterceptGraph_2D_Layer3->Draw("samebox");
0627 flagInterceptGraph_2D_Layer4->Draw("samebox");
0628 
0629 //set legend entries appropriately
0630 LegGainLayer->AddEntry(flagInterceptGraph_2D_Layer1, "Good", "f");
0631 LegGainLayer->AddEntry(flagInterceptGraph_2D_Layer2, "Low intercept, fit fails", "f");
0632 LegGainLayer->AddEntry(flagInterceptGraph_2D_Layer3, "High intercept, fit fails", "f");
0633 LegGainLayer->Draw("same");
0634 
0635 //print as gif
0636 PrintAsGif(flagInterceptLayerCanv, "flagInterceptLayer");
0637 gStyle->SetOptStat(1);
0638 gSystem->cd("../../../");
0639 directoryCheck();
0640 }