Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:18

0001 #include <Riostream.h>
0002 #include <string>
0003 #include <sys/stat.h>
0004 
0005 #include "TH1F.h"
0006 #include "TH2F.h"
0007 #include "TCanvas.h"
0008 #include "TChain.h"
0009 #include "TFile.h"
0010 #include "TDirectory.h"
0011 
0012 
0013 bool CheckFileExistence(char *filename);
0014 void PlotTrackStats();
0015 
0016 void PlotTrackStats(){
0017 
0018   //define paths
0019   char basepath[128];
0020   sprintf(basepath,"./MONITORING/DQM");
0021   char filename[256];
0022 
0023   const int StartFile=1;//211;
0024   const int FinFile=999;
0025   int addedfiles=0;
0026 
0027   //create a chain with all the DQM histograms
0028   TChain *ch=new TChain("AlignmentTrackStats");
0029 
0030   for(int i=StartFile;i<=FinFile;++i){
0031     sprintf(filename,"%s/CTF/TkAlCaRecoSkimming.ALCARECOTkAlMinBias.ALCARECOTkAlMinBias_cfg.%d_TrackStats.root",basepath,i);
0032     // if(!CheckFileExistence(filename)){
0033     //  cout<<"Added to the chain "<<i-1<<" files"<<endl;
0034     //  break;
0035     // }
0036     if(CheckFileExistence(filename)){ch->Add(filename);addedfiles++;}
0037     if( (i%50==0) || (i==FinFile))cout<<"File: "<<i<<" "<<flush;
0038   }
0039   cout<<"\nAdded to the chain "<<addedfiles<<" files"<<endl;
0040 
0041   //create histograms with the TTree:Draw function
0042   ch->Draw("Chi2n>>hchi2n(600,0.0,12.0)","Ntracks>0","goff");
0043   TH1F *hchi2n=(TH1F*)gDirectory->Get("hchi2n");
0044   ch->Draw("Eta>>heta(60,-3.0,3.0)","Ntracks>0","goff");
0045   TH1F *heta=(TH1F*)gDirectory->Get("heta");
0046   ch->Draw("Phi>>hphi(628,-3.14,3.14)","Ntracks>0","goff");
0047   TH1F *hphi=(TH1F*)gDirectory->Get("hphi");
0048   ch->Draw("Nhits[][0]>>hnhits(40,0,40)","Ntracks>0","goff");
0049   TH1F *hnhits=(TH1F*)gDirectory->Get("hnhits");
0050   hnhits->SetTitle("Total # hits for CTFSkimmed");
0051   ch->Draw("P>>hmom(1005,0,1005.0)","Ntracks>0&&P<1000.0","goff");
0052   TH1F *hmom=(TH1F*)gDirectory->Get("hmom");
0053   ch->Draw("Ntracks>>hntrks(12,0,12.0)","","goff");
0054   TH1F *hntrks=(TH1F*)gDirectory->Get("hntrks");
0055   hchi2n->SetTitle("Normalised #chi^{2} (ALL TRKS)");
0056   hmom->SetTitle("Momentum distribution (ALL TRKS && P<1000 GeV)");
0057   heta->SetTitle("#eta distribution (ALL TRKS)");
0058   hphi->SetTitle("#phi distribution (ALL TRKS)");
0059   hntrks->SetTitle("Number of tracks in event passing cuts");
0060 
0061   ch->Draw("Chi2n>>hchi2nPXB(600,0.0,12.0)","Ntracks>0&&(Nhits[][1]>0||Nhits[][2]>0)","goff");
0062   TH1F *hchi2nPXB=(TH1F*)gDirectory->Get("hchi2nPXB");
0063   ch->Draw("Eta>>hetaPXB(60,-3.0,3.0)","Ntracks>0&&Nhits[][1]>0","goff");
0064   TH1F *hetaPXB=(TH1F*)gDirectory->Get("hetaPXB");
0065   ch->Draw("Phi>>hphiPXB(628,-3.14,3.14)","Ntracks>0&&Nhits[][1]>0","goff");
0066   TH1F *hphiPXB=(TH1F*)gDirectory->Get("hphiPXB");
0067   ch->Draw("Nhits[][1]>>hnhitsPXB(8,0,8)","Ntracks>0&&(Nhits[][1]>0||Nhits[][2]>0)","goff");
0068   TH1F *hnhitsPXB=(TH1F*)gDirectory->Get("hnhitsPXB");
0069   hnhitsPXB->SetTitle("Total # hits in PXB (TRKS >=1 PXB hits)");
0070   ch->Draw("Nhits[][0]>>hnhitstotPXB(40,0,40)","Ntracks>0&&(Nhits[][1]>0||Nhits[][2]>0)","goff");
0071   TH1F *hnhitstotPXB=(TH1F*)gDirectory->Get("hnhitstotPXB");
0072   hnhitstotPXB->SetTitle("Total # hits (TRKS >=1 PXB hits)");
0073   ch->Draw("P>>hmomPXB(1005,0,1005.0)","Ntracks>0&&P<1000.0&&(Nhits[][1]>0||Nhits[][2]>0)","goff");
0074   TH1F *hmomPXB=(TH1F*)gDirectory->Get("hmomPXB");
0075   hchi2nPXB->SetTitle("Normalised #chi^{2} (TRKS >=1 PXB hits)");
0076   hmomPXB->SetTitle("Momentum distribution (TRKS >=1 PXB hits && P<1000 GeV)");
0077   hetaPXB->SetTitle("#eta distribution (TRKS >=1 PXB hits)");
0078   hphiPXB->SetTitle("#phi distribution (TRKS >=1 PXB hits)");
0079 
0080 
0081   //plot them
0082   TCanvas *c1=new TCanvas("cantrkstats1","Track Stats 1",1000,1200);
0083   c1->Divide(2,3);
0084   c1->cd(1);
0085   hchi2n->Draw();
0086   c1->cd(2);
0087   heta->Draw();
0088   c1->cd(3);
0089   hphi->Draw();
0090   c1->cd(4);
0091   gPad->SetLogy();
0092   hmom->Draw();
0093   c1->cd(5);
0094   hnhits->Draw();
0095   c1->cd(6);
0096   hntrks->Draw();
0097 
0098 
0099   TCanvas *c2=new TCanvas("cantrkstats2","Track Stats PXB",1000,1200);
0100   c2->Divide(2,3);
0101   c2->cd(1);
0102   hchi2nPXB->Draw();
0103   c2->cd(2);
0104   hetaPXB->Draw();
0105   c2->cd(3);
0106   hphiPXB->Draw();
0107   c2->cd(4);
0108   gPad->SetLogy();
0109   hmomPXB->Draw();
0110   c2->cd(6);
0111   hnhitsPXB->Draw();
0112   c2->cd(5);
0113   hnhitstotPXB->Draw();
0114 
0115   //save png files
0116   c1->SaveAs("./ALCARECOTkAlMinBias_CTFSkimmed_TrackStats_ALLTRKS.png");
0117   c2->SaveAs("./ALCARECOTkAlMinBias_CTFSkimmed_TrackStats_PIXTRKS.png");
0118   delete c1;
0119   delete c2;
0120   
0121 
0122   cout<<"Total Events: "<<ch->Draw("Ntracks","","goff")<<endl;
0123   cout<<"Total tracks: "<<ch->Draw("Ntracks","Ntracks>0","goff")<<endl;
0124   cout<<"Tracks with P<1000.0 GeV: "<<ch->Draw("Ntracks","Ntracks>0&&P<1000.0","goff") <<endl;
0125   ch->Draw("Nhits[][0]:P>>hnhvsp(1000,0.0,1000.0,40,0,40)","Ntracks>0&&P<1000.0","goff");
0126   TH2F *hnhvsp=(TH2F*)gDirectory->Get("hnhvsp");
0127   hnhvsp->SetMarkerStyle(7);
0128   hnhvsp->SetXTitle("P (GeV)");
0129   hnhvsp->SetYTitle("# TOT hits");
0130   hnhvsp->SetTitle("Correlation momentum vs #hits of CTF tracks");
0131   TCanvas *can_nhvsp=new TCanvas("cnhvsp","cnhvsp",900,900);
0132   can_nhvsp->cd();
0133   //  cout<<"start draw"<<endl;
0134   hnhvsp->Draw("colz");
0135   //cout<<"start save"<<endl;
0136   can_nhvsp->SaveAs("./ALCARECOTkAlMinBias_CTFSkimmed_NhitsVsMom.ps");
0137 }
0138 
0139 bool CheckFileExistence(char *filename){
0140 
0141   // cout<<"Checking file "<<filename<<endl;
0142   bool flag = true;
0143   
0144   ifstream fin(filename,ios::in);
0145   if(fin.fail())flag=false;
0146   fin.close();
0147   return flag;
0148 }