Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:23

0001 //
0002 // Macro to read in geomdet positions and draw them
0003 //
0004 
0005 int plotDets( )
0006 {
0007 
0008   TString cut("");
0009   return plotDets( cut );
0010 
0011 }
0012 
0013 int plotDets( TString cut )
0014 {
0015 
0016   int showFlag = 3;
0017   float xmin = 0;
0018   float xmax = 0;
0019 
0020   return plotDets( cut, showFlag, xmin, xmax );
0021 }
0022 
0023 
0024 int plotDets( TString cut, int showFlag, float xmin, float xmax )
0025 {
0026 
0027   TCanvas* c1 = new TCanvas("c1","Misalignment validation",10,10,800,420);
0028   c1->Divide(2,1);
0029 
0030   int resolution = 1;
0031 
0032   TFile* alignedFile = new TFile("aligned.root");
0033   TTree* tmpTree     = (TTree*)alignedFile->Get("theTree");
0034   TTree* alignedTree = (TTree*)tmpTree->CopyTree(cut);
0035 
0036   TFile* misalignedFile = new TFile("misaligned.root");
0037   tmpTree        = (TTree*)misalignedFile->Get("theTree");
0038   TTree* misalignedTree = (TTree*)tmpTree->CopyTree(cut);
0039 
0040   // X-Y projection
0041   if ( fabs(xmax)<1e-12 ) xmax = TMath::Nint(alignedTree->GetMaximum("x")+1);
0042   if ( fabs(xmin)<1e-12 ) xmin = TMath::Nint(alignedTree->GetMinimum("x")-1);
0043   int nx = TMath::Nint(xmax-xmin)*resolution;
0044   TH2F* hRange1        = new TH2F("hRange1","X-Y Projection",nx,xmin,xmax,nx,xmin,xmax);
0045   TH2F* hAlignedXY    = new TH2F("hAlignedXY","X-Y Projection - Aligned",nx,xmin,xmax,nx,xmin,xmax);
0046   TH2F* hMisalignedXY = new TH2F("hMisalignedXY","X-Y Projection - Misaligned",
0047                                  nx,xmin,xmax,nx,xmin,xmax);
0048   hAlignedXY->SetMarkerColor(4);
0049   hAlignedXY->SetMarkerStyle(5);
0050   hMisalignedXY->SetMarkerColor(2);
0051   hMisalignedXY->SetMarkerStyle(5);
0052 
0053   alignedTree->Project("hAlignedXY","y:x");
0054   misalignedTree->Project("hMisalignedXY","y:x");
0055 
0056   c1->cd(1);
0057   hRange1->Draw();
0058   hRange1->SetXTitle("X");
0059   hRange1->SetYTitle("Y");
0060   if ( showFlag&1 ) hAlignedXY->Draw("same");
0061   if ( showFlag&(1<<1) ) hMisalignedXY->Draw("same");
0062 
0063   // R-Z projection
0064   xmin = 0;
0065   float zmax = TMath::Nint(alignedTree->GetMaximum("z")+1);
0066   float zmin = TMath::Nint(alignedTree->GetMinimum("z")-1);
0067   int nx = TMath::Nint(xmax-xmin)*resolution;
0068   int nz = TMath::Nint(zmax-zmin)*resolution;
0069   TH2F* hRange2       = new TH2F("hRange2","R-Z Projection",nz,zmin,zmax,nx,xmin,xmax);
0070   TH2F* hAlignedRZ    = new TH2F("hAlignedRZ","X-Y Projection - Aligned",nz,zmin,zmax,nx,xmin,xmax);
0071   TH2F* hMisalignedRZ = new TH2F("hMisalignedRZ","X-Y Projection - Misaligned",
0072                                  nz,zmin,zmax,nx,xmin,xmax);
0073 
0074   hAlignedRZ->SetMarkerColor(4);
0075   hMisalignedRZ->SetMarkerColor(2);
0076 
0077   alignedTree->Project("hAlignedRZ","sqrt(x^2+y^2):z");
0078   misalignedTree->Project("hMisalignedRZ","sqrt(x^2+y^2):z");
0079   std::cout << hAlignedRZ->GetEntries() << " aligned detectors selected" << std::endl;
0080   std::cout << hMisalignedRZ->GetEntries() << " misaligned detectors selected" << std::endl;
0081 
0082   c1->cd(2);
0083   hRange2->Draw();
0084   hRange2->SetYTitle("R");
0085   hRange2->SetXTitle("Z");
0086   if ( showFlag&1 ) hAlignedRZ->Draw("same");
0087   if ( showFlag&(1<<1) ) hMisalignedRZ->Draw("same");
0088 
0089   return 0;
0090 
0091 }