1+ #include <TCanvas.h>
2+ #include <TFile.h>
3+ #include <TH1F.h>
4+ #include <TH2F.h>
5+ #include <TNtuple.h>
6+ #include <TString.h>
7+ #include <TTree.h>
8+ #include <TROOT.h>
9+ #include <TStyle.h>
10+
11+ // ### required input file: CheckClusters.root, which is the output of CheckClusters.C macro
12+ void CheckClusterSizeVsEta (const std ::string & strFileInput = "CheckClusters.root" )
13+ {
14+ gStyle -> SetOptStat (0 );
15+
16+ TFile * fileInput = new TFile (strFileInput .c_str ());
17+ TTree * tree = (TTree * )fileInput -> Get ("ntc" );
18+
19+ std ::cout << "Opened tree: " << tree -> GetName ()
20+ << ", entries = " << tree -> GetEntries () << std ::endl ;
21+
22+ // set branch addresses
23+ Float_t event ;
24+ Float_t mcTrackID ;
25+ Float_t hitLocX , hitLocZ ;
26+ Float_t hitGlobX , hitGlobY , hitGlobZ ;
27+ Float_t clusGlobX , clusGlobY , clusGlobZ ;
28+ Float_t clusLocX , clusLocZ ;
29+ Float_t rofFrame ;
30+ Float_t clusSize ;
31+ Float_t chipID ;
32+ Float_t layer ;
33+ Float_t disk ;
34+ Float_t subdet ;
35+ Float_t row , col ;
36+ Float_t pt ;
37+
38+ // set branch addresses
39+ tree -> SetBranchAddress ("event" , & event );
40+ tree -> SetBranchAddress ("mcTrackID" , & mcTrackID );
41+ tree -> SetBranchAddress ("hitLocX" , & hitLocX );
42+ tree -> SetBranchAddress ("hitLocZ" , & hitLocZ );
43+ tree -> SetBranchAddress ("hitGlobX" , & hitGlobX );
44+ tree -> SetBranchAddress ("hitGlobY" , & hitGlobY );
45+ tree -> SetBranchAddress ("hitGlobZ" , & hitGlobZ );
46+ tree -> SetBranchAddress ("clusGlobX" , & clusGlobX );
47+ tree -> SetBranchAddress ("clusGlobY" , & clusGlobY );
48+ tree -> SetBranchAddress ("clusGlobZ" , & clusGlobZ );
49+ tree -> SetBranchAddress ("clusLocX" , & clusLocX );
50+ tree -> SetBranchAddress ("clusLocZ" , & clusLocZ );
51+ tree -> SetBranchAddress ("rofFrame" , & rofFrame );
52+ tree -> SetBranchAddress ("clusSize" , & clusSize );
53+ tree -> SetBranchAddress ("chipID" , & chipID );
54+ tree -> SetBranchAddress ("layer" , & layer );
55+ tree -> SetBranchAddress ("disk" , & disk );
56+ tree -> SetBranchAddress ("subdet" , & subdet );
57+ tree -> SetBranchAddress ("row" , & row );
58+ tree -> SetBranchAddress ("col" , & col );
59+ tree -> SetBranchAddress ("pt" , & pt );
60+
61+ // Some QA histograms
62+ TH1F * hPt = new TH1F ("hPt" , "p_{T};p_{T};Entries" , 100 , 0. , 10. );
63+ TH1F * hClusSize = new TH1F ("hClusSize" , "Cluster size;clusSize;Entries" , 20 , 0. , 20. );
64+ TH1F * hLayer = new TH1F ("hLayer" , "Layer;layer;Entries" , 20 , -0.5 , 19.5 );
65+ TH1F * hDxGlob = new TH1F ("hDxGlob" , "clusGlobX - hitGlobX;#DeltaX [global];Entries" , 200 , -1. , 1. );
66+ TH1F * hDzGlob = new TH1F ("hDzGlob" , "clusGlobZ - hitGlobZ;#DeltaZ [global];Entries" , 200 , -1. , 1. );
67+ TH2F * hHitXY = new TH2F ("hHitXY" , "Hit global XY;hitGlobX;hitGlobY" , 200 , -20. , 20. , 200 , -20. , 20. );
68+ TH2F * hClusVsHitX = new TH2F ("hClusVsHitX" , "clusGlobX vs hitGlobX;hitGlobX;clusGlobX" , 200 , -20. , 20. , 200 , -20. , 20. );
69+
70+ // histograms for cluster size vs eta for each layer (ML and OT barrel layers):
71+ const int nLayers = 8 ; // ML and OT barrel layers only
72+ TH2F * hClustSizePerLayerVsEta [nLayers ];
73+ for (int i = 0 ; i < nLayers ; i ++ )
74+ {
75+ hClustSizePerLayerVsEta [i ] = new TH2F (Form ("hClustSizePerLayerVsEta_Lay%d" , i ), Form ("Cluster size vs eta for layer %d;#eta;Cluster size" , i ), 160 , -4 , 4 , 101 , -0.5 , 100.5 );
76+ }
77+
78+ // Loop over entries
79+ const Long64_t nEntries = tree -> GetEntries ();
80+ for (Long64_t i = 0 ; i < nEntries ; ++ i )
81+ {
82+ tree -> GetEntry (i );
83+
84+ // Fill QA histograms
85+ float dXGlob = clusGlobX - hitGlobX ;
86+ float dZGlob = clusGlobZ - hitGlobZ ;
87+ hPt -> Fill (pt );
88+ hClusSize -> Fill (clusSize );
89+ hLayer -> Fill (layer );
90+ hDxGlob -> Fill (dXGlob );
91+ hDzGlob -> Fill (dZGlob );
92+ hHitXY -> Fill (hitGlobX , hitGlobY );
93+ hClusVsHitX -> Fill (hitGlobX , clusGlobX );
94+
95+ // cls size vs eta:
96+ float clustR = sqrt (clusGlobX * clusGlobX + clusGlobY * clusGlobY );
97+ float clustPhi = atan2 (clusGlobY , clusGlobX );
98+ float clustTheta = atan2 (clustR , clusGlobZ );
99+ float clustEta = - log (tan (clustTheta / 2 ));
100+
101+ // !!! important: to avoid VD layers (numeration for ML starts from 0, while VD layers are also numbered as 0,1,2)
102+ if (clustR > 5 ) // cm
103+ hClustSizePerLayerVsEta [(int )layer ]-> Fill (clustEta , clusSize );
104+
105+ // progress print
106+ if ((i + 1 ) % 200000 == 0 )
107+ {
108+ std ::cout << "Processed " << (i + 1 ) << " / " << nEntries << " entries" << std ::endl ;
109+ }
110+ }
111+
112+ // Save histograms to file
113+ TFile * fout = TFile ::Open ("clusterSizes_vs_eta.root" , "RECREATE" );
114+ hPt -> Write ();
115+ hClusSize -> Write ();
116+ hLayer -> Write ();
117+ hDxGlob -> Write ();
118+ hDzGlob -> Write ();
119+ hHitXY -> Write ();
120+ hClusVsHitX -> Write ();
121+
122+ // draw some QA histograms
123+ TCanvas * c1 = new TCanvas ("canv_clusters_QA" , "Clusters QA" , 1200 , 800 );
124+ c1 -> Divide (2 , 2 );
125+ c1 -> cd (1 );
126+ hPt -> Draw ();
127+ c1 -> cd (2 );
128+ hClusSize -> Draw ();
129+ c1 -> cd (3 );
130+ hDxGlob -> Draw ();
131+ c1 -> cd (4 );
132+ hHitXY -> Draw ("COLZ" );
133+
134+ TCanvas * canv_clsSize_vs_eta [nLayers ];
135+ TProfile * profPerLayerVsEta [nLayers ];
136+ for (int i = 0 ; i < nLayers ; i ++ )
137+ {
138+ canv_clsSize_vs_eta [i ] = new TCanvas (Form ("canv_clsSize_vs_eta_Lay%d" , i ), Form ("Cluster size vs eta for layer %d" , i ), 800 , 600 );
139+ hClustSizePerLayerVsEta [i ]-> Draw ("COLZ" );
140+ gPad -> SetLogz ();
141+ profPerLayerVsEta [i ] = hClustSizePerLayerVsEta [i ]-> ProfileX ();
142+ profPerLayerVsEta [i ]-> DrawCopy ("same" );
143+
144+ hClustSizePerLayerVsEta [i ]-> Write ();
145+ profPerLayerVsEta [i ]-> Write ();
146+ }
147+
148+ // canvas with profiles for all layers together
149+ TCanvas * canv_av_clsSize_vs_eta_all_layers = new TCanvas ("canv_clsSize_vs_eta_all_layers" , "Cluster size vs eta for all layers" , 800 , 600 );
150+ TLegend * legLayers = new TLegend (0.3 , 0.52 , 0.65 , 0.89 );
151+ int colors [] = {kRed , kBlue , kMagenta + 1 , kCyan + 1 , kGray + 2 , kRed , kBlue , kMagenta + 1 , kCyan , kAzure + 1 , kOrange - 9 , kRed + 2 , kBlue + 2 , kMagenta + 2 };
152+ for (int i = 0 ; i < nLayers ; i ++ )
153+ {
154+ profPerLayerVsEta [i ]-> SetLineColor (colors [i ]);
155+ profPerLayerVsEta [i ]-> SetMarkerColor (colors [i ]);
156+ profPerLayerVsEta [i ]-> SetMarkerStyle (i < 5 ? 20 : 24 );
157+ profPerLayerVsEta [i ]-> SetTitle (";#eta;#LTcluster size#GT" );
158+ profPerLayerVsEta [i ]-> GetYaxis ()-> SetRangeUser (0. , 12.5 );
159+ profPerLayerVsEta [i ]-> DrawCopy (i == 0 ? "P" : "P same" );
160+ legLayers -> AddEntry (profPerLayerVsEta [i ], Form ("Layer %d" , i ), "P" );
161+ }
162+
163+ legLayers -> Draw ();
164+ gPad -> SetGrid ();
165+ canv_av_clsSize_vs_eta_all_layers -> SaveAs ("clsSize_vs_eta_all_layers.png" );
166+ canv_av_clsSize_vs_eta_all_layers -> Write ();
167+
168+ // fout->Close();
169+ }
0 commit comments