-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetGainMap.C
More file actions
282 lines (191 loc) · 9.16 KB
/
getGainMap.C
File metadata and controls
282 lines (191 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
void GetBinMinMax(const TH1 *hist, const Float_t frac, Int_t &bin1, Int_t &bin2)
{
const Int_t binMax=hist->GetMaximumBin();
const Double_t contMax=hist->GetBinContent(binMax);
bin1=binMax;
bin2=binMax;
while ( (bin1--)>binMax/3. ) if (hist->GetBinContent(bin1)<frac*contMax) break;
while ( (bin2++)<binMax*3. ) if (hist->GetBinContent(bin2)<frac*contMax) break;
}
void getGainMap(const char *filename){
gSystem->Load("~/GEMtest/code/libGEMEvent.so");
TFile *TreeFile = new TFile(Form("%s", filename));
TTree *tree = (TTree*)TreeFile->Get("GEM");
/* ============================================================
* ====================== Cut parameter =======================
* ============================================================ */
int TrPerEv = 1;
int nclCut = 32;
int CherCutLow = 40;
int CherCutHigh = 50;
int timebinLow = 25;
int timebinHigh = 90;
/* ============================================================
* ============= Define histograms and graphs =================
* ============================================================*/
//TH1D *hNclusters = new TH1D("hNclusters", ";Number of clusters; Counts", 65,0,65);
//TH1D *hNclustersUsed = new TH1D("hNclustersUsed", ";Number of clusters; Counts", 65,0,65);
//TH1D *hNIROCtracks = new TH1D("hNtracksIROC","; Number of tracks; # counts",10,0,10);
//TH1D *hNIROCtracksUsed = new TH1D("hNtracksIROCUsed","; Number of tracks; # counts",10,0,10);
//TH1D *hQtot = new TH1D("hQtot", "; Total cluster charge Q_{tot} [ADC counts]; # counts", 600,0,600);
//TH1D *hQtotUsed = new TH1D("hQtotUsed", "; Total cluster charge Q_{tot} [ADC counts]; # counts", 600,0,600);
//TH1D *hCherenkov = new TH1D("hCherenkov", "; ADC signal (corresponds to velocity); # counts", 90,20,196);
//TH2D *hPadOccupancy = new TH2D("hOcc", "; Row; Pad", 63,0,63,35,-5,30);
//TH2D *hPadOccupancyUsed = new TH2D("hOccUsed", "; Row; Pad", 63,0,63,35,-5,30);
//TH1D *hQtotSinglePad = new TH1D("QtotSinglePad", "; Q_{tot}; # counts", 100,0,600);
//TGraph *Chisquare = new TGraph();
TH1D *hChisquare = new TH1D("hChisquare", "; Chisquare Landau; # counts", 24,0,12);
TH2D *hGainMap = new TH2D("hGainMap", "; Row; Pad", 63,0,63,35,-5,30);
TH1D *hEntries = new TH1D("Entries", "; Entries; # counts",6,1,3000);
//TH1D *hResidualPad = new TH1D("hResPad", "; Residual; #Counts",100,0,100);
//TH2D *hQtotTimeBin = new TH2D("hQTime","; TimeBin; Q_{tot}",100,0,100,200,0,600);
//TH2D *hQtotTimeBinUsed = new TH2D("hQTimeUsed","; TimeBin; Q_{tot}",100,0,100,200,0,600);
/* initialize array of histograms used to get the gainmap */
const int nrows = 63;
const int npads = 30;
TH1D *hQtotPads[nrows][npads];
for(int irow=0; irow<nrows; ++irow) {
for (int ipad=0; ipad<npads; ++ipad) {
hQtotPads[irow][ipad] = new TH1D(Form("hQtotPad_%i_%i", irow, ipad), "", 50, 0, 50);
}
}
/* =============================================================================
* ================== Loop over events and apply all cuts ======================
* ======================= meanwhile fill histograms ===========================
* ============================================================================= */
GEMEvent *fEvent=0x0;
fEvent=0x0;
tree->SetBranchAddress("Events",&fEvent);
GEMTrack::SetRemoveRowsdEdx("9,17,25,32,39,45,51,57,58,59,60,61,62");
int usedTracks = 0;
int Tracks = 0;
int OneTrackEvents = 0;
int pions = 0;
int electrons = 0;
int usedcl = 0;
int onetrcl = 0;
for (int iev=0; iev<tree->GetEntries(); ++iev){
tree->GetEntry(iev);
int NTracks = fEvent->GetNumberOfTracks(0);
int CherenkovValue = fEvent->GetCherenkovValue();
Tracks += NTracks;
/*===========================================CUT=================================================*/
if (NTracks != TrPerEv){continue;} // only one-track events
++OneTrackEvents;
for (int itr=0; itr<NTracks; ++itr) {
GEMTrack *track = const_cast <GEMTrack*>(fEvent->GetTrack(itr));
/*===========================================CUT=================================================*/
if (track->GetROC() != 0) continue; // only ROC 0
int ncl = track->GetNumberOfClusters();
onetrcl += ncl;
bool isok = true;
int ncledge = 0;
/*===========================================CUT=================================================*/
if (ncl < nclCut){isok = false; continue;} // cut on number of clusters per track
/*===========================================CUT=================================================*/
if (CherenkovValue >= CherCutLow && CherenkovValue <= CherCutHigh){isok = false; continue;} // PID via Cherenkov
for (int icl = 0; icl < ncl; ++icl){ // make cuts on cluster properties
GEMCluster *cl = const_cast <GEMCluster*>(track->GetCluster(icl));
double timebin = cl->GetTimeBinW();
/*===========================================CUT=================================================*/
if (timebin < timebinLow || timebin > timebinHigh){isok = false; break;} // cut on time bins, only clusters from a certain range on z-axis can come from a particle
}
if (isok == true){ // track accepted
usedcl += ncl;
float dEdx = track->GetTruncatedMean(0.,.7,1,2);
if (CherenkovValue < CherCutLow){
++pions;
}
if (CherenkovValue > CherCutHigh){
++electrons;
}
++usedTracks;
for (int icl = 0; icl < ncl; ++icl){ // loop over the clusters of an accepted track
GEMCluster *cl = const_cast <GEMCluster*>(track->GetCluster(icl));
const int row = cl->GetRow();
const int cpad = int(cl->GetCPad());
double QTot = cl->GetQTot();
hQtotPads[row][cpad]->Fill(QTot/dEdx);
}
}
}
}
/* ======================================================================
* ========== Fit every histogram in array for MPV -> GainMap ===========
* ====================================================================== */
//TFile *GainMap = new TFile("GainMap.root","RECREATE");
//hGainMap->SetName("GainMap");
TF1 *MPVfit = new TF1("MPV","landau");
int means = 0;
int Landau = 0;
const Float_t frac=0.2;
Int_t bin1=0,bin2=0;
for (int irow=0; irow<nrows; ++irow){
for (int ipad=0; ipad<npads; ++ipad){
if (irow == 15 && ipad == 15){
//TCanvas *c1 = new TCanvas();
hQtotPads[irow][ipad]->Draw();
}
int entries = hQtotPads[irow][ipad]->GetEntries();
hEntries->Fill(entries);
if (entries > 100){
GetBinMinMax(hQtotPads[irow][ipad],frac,bin1,bin2);
hQtotPads[irow][ipad]->Fit("MPV","","", hQtotPads[irow][ipad]->GetXaxis()->GetBinLowEdge(bin1),hQtotPads[irow][ipad]->GetXaxis()->GetBinUpEdge(bin2));
float mpv = MPV->GetParameter(1);
float chisquare = MPV->GetChisquare()/MPV->GetNDF();
hChisquare->Fill(chisquare);
hGainMap->Fill(irow,ipad,mpv);
++Landau;
}
else if (entries <= 100 && entries != 0){
hGainMap->Fill(irow,ipad,hQtotPads[irow][ipad]->GetMean());
++means;
}
}
}
hGainMap->GetZaxis()->SetRangeUser(.5,1.2);
//hGainMap->Write();
//GainMap->Write();
//GainMap->Close();
/* ======================================================================
* ===================== Plot everything ================================
* ====================================================================== */
//TCanvas *c1 = new TCanvas();
//hNIROCtracksUsed->Draw();
//TCanvas *c2 = new TCanvas();
//hNIROCtracks->Draw();
//TCanvas *c3 = new TCanvas();
//hNclustersUsed->Draw();
//TCanvas *c4 = new TCanvas();
//hQtotTimeBin->Draw("colz");
//TCanvas *c5 = new TCanvas();
//hQtotTimeBinUsed->Draw("colz");
//TCanvas *c6 = new TCanvas();
//hQtot->Draw();
//TCanvas *c7 = new TCanvas();
//hQtotUsed->Draw();
//TCanvas *c8 = new TCanvas();
//hPadOccupancy->Draw("colz");
//TCanvas *c9 = new TCanvas();
//hPadOccupancyUsed->Draw("colz");
TCanvas *c10 = new TCanvas("GainMap");
hGainMap->Draw("colz");
TCanvas *c11 = new TCanvas();
hChisquare->Draw();
TCanvas *c12 = new TCanvas();
hEntries->Draw();
//c10->Update();
//c10->Print("GainMap.root","root");
/* ======================================================================
* ======================= Terminal output ==============================
* ====================================================================== */
cout<<"Number of tracks: "<<Tracks<<endl;
cout<<"Number of one-track-events: "<<OneTrackEvents<<endl;
cout<<"Number of used tracks: "<<usedTracks<<endl;
//cout<<"Number of one-track-clusters: "<<onetrcl<<endl;
//cout<<"Number of used clusters: "<<usedcl<<endl;
cout<<"Number of pions: "<<pions<<endl;
cout<<"Number of electrons: "<<electrons<<endl;
cout<<"Number of Landau fits: "<<Landau<<endl;
cout<<"Number of means: "<<means<<endl;
}