Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:19:50

0001 #include "TH1F.h"
0002 #include "TCanvas.h"
0003 #include "TObject.h"
0004 #include "TFile.h"
0005 #include "TPaveStats.h"
0006 #include "TGraphErrors.h"
0007 #include "TGaxis.h"
0008 #include "TROOT.h"
0009 #include "TF1.h"
0010 #include "TLegend.h"
0011 #include "TKey.h"
0012 #include "TClass.h"
0013 #include "iostream"
0014 #include "vector"
0015 #include "math.h"
0016 #include "map"
0017 
0018 void  displayBaselineMacro_2types(TString file,const  int limit = 20){
0019 
0020   TFile *f;//, *fo;
0021   TString BaseDir;
0022   TString dir[6];
0023   TString fullPath, title, subDet, genSubDet;
0024   TCanvas *C;
0025     C = new TCanvas();
0026     f = new TFile(file);
0027 //    fo = new TFile(ofile, "RECREATE");
0028     //BaseDir="DQMData/Results/SpyChannel/";
0029     dir[0]="baselineAna/ProcessedRawDigis";
0030     dir[1]="baselineAna/Baseline";
0031     dir[2]="baselineAna/Clusters";
0032     dir[3]="baselineAna/RawDigis";
0033     dir[4]="moddedbaselineAna/Baseline";
0034     dir[5]="moddedbaselineAna/Clusters";
0035     f->cd();
0036 //  fo->Write();
0037 //  fo->Close();
0038     f->cd(dir[0]);
0039     
0040     TIter nextkey(gDirectory->GetListOfKeys());
0041     TKey *key;
0042     int objcounter=1;
0043     int histolimit =0;
0044     while ((key = (TKey*)nextkey())) {
0045         if(histolimit< limit){ histolimit++;
0046           std::cout << histolimit << " " << limit << std::endl;
0047       TObject *obj = key->ReadObj();
0048       
0049 
0050       if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
0051     
0052     std::cout << "Found object n: " << objcounter << " Name: " << obj->GetName() << " Title: " << obj->GetTitle()<< std::endl;
0053     ++objcounter;
0054     //if (strstr(obj->GetTitle(),"470116592")!=NULL)
0055     //  continue;
0056 
0057     C->Clear();
0058     TH1F* h = (TH1F*)key->ReadObj();
0059 
0060     //TLegend leg(0.6,0.9,0.8,1,"");
0061     //leg.AddEntry(h,"VR - Ped - apvCM_{mean}","lep");
0062 
0063         h->SetLineColor(kBlack);
0064     h->SetLineWidth(1);
0065     h->SetXTitle("StripNumber");
0066     h->SetYTitle("Charge (ADC counts)");
0067     h->Draw("hist p l");
0068         h->SetStats(0);
0069         //h->GetYaxis()->SetRangeUser(-300,300);
0070         //h->GetXaxis()->SetRangeUser(256,512);
0071     f->cd();
0072     //f->cd(dir[1]);
0073     TH1F* hb = (TH1F*) f->Get(dir[1]+"/"+obj->GetName());
0074     
0075     if(hb!=0){
0076       hb->SetLineWidth(2);
0077       hb->SetLineStyle(1);
0078       hb->SetLineColor(kRed);
0079       //leg.AddEntry(hb,"clusters","lep");
0080       hb->Draw("hist p l same");
0081     }
0082     
0083     f->cd();
0084     //f->cd(dir[1]);
0085     TH1F* hc = (TH1F*) f->Get(dir[2]+"/"+obj->GetName());
0086         TH1F* offset = (TH1F*)hc->Clone("offset");  
0087         offset->Reset();
0088         for(int i = 0; i<offset->GetSize(); i++) offset->SetBinContent(i,-300);
0089         hc->Add(offset);
0090     if(hc!=0){
0091       hc->SetLineWidth(1);
0092       hc->SetLineStyle(1);
0093       hc->SetLineColor(kViolet);
0094       //leg.AddEntry(hb,"clusters","lep");
0095       hc->Draw("hist p l same");
0096     }
0097     TH1F* hd = (TH1F*) f->Get(dir[3]+"/"+obj->GetName());
0098     
0099     if(hd!=0){
0100       hd->SetLineWidth(1);
0101       hd->SetLineStyle(1);
0102       hd->SetLineColor(kGray);
0103       hd->SetMarkerColor(kGray);
0104       //leg.AddEntry(hb,"clusters","lep");
0105       hd->Draw("hist p l same");
0106           h->Draw("hist p l same");
0107           hb->Draw("hist p l same");
0108           hc->Draw("hist p l same");
0109     }
0110 
0111     TH1F* he = (TH1F*) f->Get(dir[4]+"/"+obj->GetName());
0112     if(he!=0){
0113       he->SetLineWidth(2);
0114       he->SetLineStyle(2);
0115           he->SetMarkerSize(-1);
0116       he->SetLineColor(kGreen);
0117       //leg.AddEntry(hb,"clusters","lep");
0118       he->Draw("hist l same");
0119     }
0120     
0121         TH1F* hf = (TH1F*) f->Get(dir[5]+"/"+obj->GetName());
0122         TH1F* offset2 = (TH1F*)hf->Clone("offset2");    
0123         offset2->Reset();
0124         for(int i = 0; i<offset2->GetSize(); i++) offset2->SetBinContent(i,-300);
0125         hf->Add(offset2);
0126     if(hf!=0){
0127       hf->SetLineWidth(1);
0128       hf->SetLineStyle(1);
0129           hf->SetMarkerSize(-1);
0130       hf->SetLineColor(kBlue);
0131       //leg.AddEntry(hb,"clusters","lep");
0132       hf->Draw("hist l same");
0133     }
0134     
0135     //else
0136     //  std::cout << "not found " << obj->GetName()<< std::endl;
0137     //leg.Draw();
0138     
0139     
0140     C->Update();
0141 //  fo->cd();
0142 //  C->Write();
0143     
0144     C->SaveAs(TString("img/")+obj->GetName()+TString(".png"));
0145     
0146     
0147       }
0148     }      
0149   }
0150 }
0151 
0152 void displayClusters(TString file){
0153   TFile * f = new TFile(file,"read");
0154   TH1F * h1[5];
0155   TH1F * h2[5];
0156   h1[0] = (TH1F*)f->Get("baselineAna/ClusterMult"); 
0157   h2[0] = (TH1F*)f->Get("moddedbaselineAna/ClusterMult"); 
0158   h1[1] = (TH1F*)f->Get("baselineAna/ClusterCharge"); 
0159   h2[1] = (TH1F*)f->Get("moddedbaselineAna/ClusterCharge"); 
0160   h1[2] = (TH1F*)f->Get("baselineAna/ClusterWidth"); 
0161   h2[2] = (TH1F*)f->Get("moddedbaselineAna/ClusterWidth");
0162 
0163   TCanvas * c1 = new TCanvas("c1","c1",800,800);
0164   h1[0]->SetLineColor(kRed);
0165   h2[0]->SetLineColor(kBlue);
0166   h1[0]->GetYaxis()->SetTitle("nEvents");
0167   h1[0]->GetXaxis()->SetTitle("nClusters");
0168   c1->SetLogx();
0169   //c1->SetLogy();
0170   h1[0]->SetStats(0);
0171   h1[0]->Draw();
0172   h2[0]->Draw("same"); 
0173   c1->SaveAs("img/ClusterMultComparison.png");  
0174   c1->SaveAs("img/ClusterMultComparison.pdf");  
0175 
0176   c1->Clear();
0177   h1[1]->SetLineColor(kRed);
0178   h2[1]->SetLineColor(kBlue);
0179   h2[1]->GetYaxis()->SetTitle("nClusters");
0180   h2[1]->GetXaxis()->SetTitle("Cluster Charge");
0181   h2[1]->GetXaxis()->SetRangeUser(0,10000);
0182   c1->SetLogy();
0183   h2[1]->SetStats(0);
0184   h2[1]->Draw();
0185   h1[1]->Draw("same");
0186   c1->SaveAs("img/ClusterChargeComparison.png");  
0187   c1->SaveAs("img/ClusterChargeComparison.pdf");  
0188   
0189   c1->Clear();
0190   h1[2]->SetLineColor(kRed);
0191   h2[2]->SetLineColor(kBlue);
0192   h2[2]->GetYaxis()->SetTitle("nClusters");
0193   h2[2]->GetXaxis()->SetTitle("Cluster Width");
0194   h2[2]->GetXaxis()->SetRangeUser(0,80);
0195   c1->SetLogx(0);
0196   h2[2]->SetStats(0);
0197   h2[2]->Draw();
0198   h1[2]->Draw("same");
0199   c1->SaveAs("img/ClusterWidthComparison.png");  
0200   c1->SaveAs("img/ClusterWidthComparison.pdf");  
0201   
0202  
0203 }