1 //____________________________________________________________________
3 // $Id: DrawDigits.C 30718 2009-01-22 16:07:40Z cholm $
5 // Script that contains a class to draw eloss from hits, versus ADC
6 // counts from digits, using the AliFMDInputHits class in the util library.
8 // It draws the energy loss versus the p/(mq^2). It can be overlayed
9 // with the Bethe-Bloc curve to show how the simulation behaves
10 // relative to the expected.
12 // Use the script `Compile.C' to compile this class using ACLic.
26 #include <AliCDBManager.h>
27 #include <AliFMDDigit.h>
28 #include <AliFMDInput.h>
29 #include <AliFMDParameters.h>
30 #include <AliRawReader.h>
36 @brief Draw pedestal, noise, and both common mode noise corrected
39 Root> Compile("FindCommonModeNoise.C")
40 Root> FindCommonModeNoise fcmn("file");
44 If null is passed instead of a file, then a simulation of common
45 mode noise is run instead.
49 class FindCommonModeNoise : public AliFMDInput
56 Float_t fCmn; // Common mode noise component
59 TH1F* fCenteredPed; //
60 TH1F* fCorrectedNoise; //
63 TH1F* fSummedCenteredAdc; //
64 TH1F* fSummedCenteredAdc2; //
68 //__________________________________________________________________
69 FindCommonModeNoise(const char* file,
70 const char* calibDir=0)
76 if (calibDir) fCalibDir = calibDir;
84 TString outName(Form("histo_%s", gSystem->BaseName(fRawFile.Data())));
85 if (!outName.EndsWith(".root")) outName.Append(".root");
86 fOut = TFile::Open(outName.Data(),"RECREATE");
88 fPed = MakeHist("ped_dist","Pedestal Distribution");
89 fNoise = MakeHist("noise_dist",
90 "Noise Distribution (Not CMN corrected)");
91 fCenteredPed = MakeHist("cmn_ped_dist",
92 "Pedestal - Average Pedestal Distribution");
93 fCorrectedNoise = MakeHist("noise_corrected_dist",
94 "Noise Distribution (CMN corrected)");
95 fSummedAdc = MakeHist("sum_adc_dist","Sum ADC Distribution");
96 fSummedAdc2 = MakeHist("sum_adc2_dist",
97 "Sum ADC Squared Distribution");
98 fSummedCenteredAdc = MakeHist("sum_cmn_adc_dist",
99 "Sum CMN Adjusted ADC Distribution");
100 fSummedCenteredAdc2 = MakeHist("sum_cmn_adc2_dist",
101 "Sum CMN Adjusted ADC Squared Distribution");
102 fAdc = MakeHist("adc_dist","Current ADC Distribution");
104 //__________________________________________________________________
105 Int_t NEvents() const
107 Int_t nEv = (fReader ? fReader->GetNumberOfEvents() : -1);
108 if (nEv > 0) return TMath::Min(nEv, 1000);
111 //__________________________________________________________________
112 TH1F* MakeHist(const char* name, const char* title)
114 TH1F* h = new TH1F(name,title,51200,-0.5,51199.5);
115 h->SetXTitle("Strip number");
116 h->SetFillColor(kRed);
117 h->SetFillStyle(3001);
122 //__________________________________________________________________
125 AliCDBManager* cdb = AliCDBManager::Instance();
127 cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
129 AliFMDParameters* pars = AliFMDParameters::Instance();
130 if (fCalibDir.IsNull())
133 pars->Init(fCalibDir.Data(), kFALSE);
137 return AliFMDInput::Init();
140 //__________________________________________________________________
141 Bool_t Begin(Int_t e)
145 // Common mode noise generation
146 fShift = gRandom->Gaus(0, fCmn);
147 return AliFMDInput::Begin(e);
150 //__________________________________________________________________
151 Int_t BinCenter(UShort_t d, Char_t r, UShort_t s, UShort_t t) const
153 if (d == 1 && !(r == 'I' || r == 'i')) return -1;
157 case 1: idx = 0; break;
158 case 2: idx = 10240; break;
159 case 3: idx = 3 * 10240; break;
164 UShort_t q = (r == 'I' || r == 'i' ? 0 : 1);
165 // UShort_t nSec = (q == 0 ? 20 : 40);
166 UShort_t nStr = (q == 0 ? 512 : 256);
168 idx += (q == 0 ? 0 : 10240);
171 if (idx >= 51200) return -1;
175 //__________________________________________________________________
176 Int_t BinCenter(UShort_t chip, UShort_t strip) const
178 return chip * 128 + strip;
180 //__________________________________________________________________
181 Int_t BinNumber(UShort_t chip, UShort_t strip) const
183 return 1 + BinCenter(chip, strip);
185 //__________________________________________________________________
186 Float_t GetSignal(UShort_t d, Char_t, UShort_t s, UShort_t t)
188 // Calculate signal value. Only the first 256 strips of FMD are
190 if (d > 1 || s > 0 || t > 256) return 0;
192 Float_t x = (t % 128);
193 Float_t p = c * (64 * 64 - 128 * x + x * x) + 100;
194 Float_t n = (p-100)/40 + 1;
196 // In case we simulate a common mode noise component.
198 return fShift + gRandom->Gaus(p, n);
200 // In case all noise is uncorrelated.
201 return gRandom->Gaus(p, TMath::Sqrt(n*n + fCmn*fCmn));
203 //__________________________________________________________________
204 Bool_t ProcessRawDigit(AliFMDDigit* digit)
207 if (!digit) return kTRUE;
209 UShort_t d = digit->Detector();
210 Char_t r = digit->Ring();
211 UShort_t s = digit->Sector();
212 UShort_t t = digit->Strip();
213 return ProcessOne(d, r, s, t, digit->Counts());
215 //__________________________________________________________________
216 Bool_t ProcessUser(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
218 // From our simulator in GetValue
219 return ProcessOne(d, r, s, t, v);
221 //__________________________________________________________________
222 Bool_t ProcessOne(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
224 Int_t i = BinCenter(d, r, s, t);
226 std::cout << "Invalid index " << i << " returned for FMD"
227 << d << r << '[' << s << ',' << t << ']' << std::endl;
235 //__________________________________________________________________
238 // At the end of each event, fill the summed histograms.
239 for (UShort_t chip = 0; chip < 400; chip++) {
241 for (UShort_t strip = 0; strip < 128; strip++)
242 chipAv += fAdc->GetBinContent(1+BinCenter(chip, strip));
245 for (UShort_t strip = 0; strip < 128; strip++) {
246 Int_t i = BinCenter(chip, strip);
247 Double_t adc = fAdc->GetBinContent(i+1);
248 Double_t cAdc = chipAv - adc;
249 fSummedAdc->Fill(i, adc);
250 fSummedAdc2->Fill(i, adc * adc);
251 fSummedCenteredAdc->Fill(i, cAdc);
252 fSummedCenteredAdc2->Fill(i, cAdc*cAdc);
256 return AliFMDInput::End();
258 //__________________________________________________________________
261 if (fEventCount == 0) {
262 std::cerr << "No events!" << std::endl;
266 for (UInt_t bin = 1; bin <= 51200; bin++) {
267 if (bin % (51200 / 10) == 0)
268 std::cout << "Bin # " << bin << std::endl;
269 Double_t sumAdc = fSummedAdc->GetBinContent(bin);
270 Double_t sumAdc2 = fSummedAdc2->GetBinContent(bin);
271 Double_t avAdc = sumAdc / fEventCount;
272 Double_t avAdc2 = sumAdc2 / fEventCount;
273 Double_t noise2 = avAdc2 - avAdc * avAdc;
275 fPed->SetBinContent(bin, avAdc);
276 fNoise->SetBinContent(bin, noise2 >= 0 ? TMath::Sqrt(noise2) : 0);
278 Double_t sumCAdc = fSummedCenteredAdc->GetBinContent(bin);
279 Double_t sumCAdc2 = fSummedCenteredAdc2->GetBinContent(bin);
280 Double_t avCAdc = sumCAdc / fEventCount;
281 Double_t avCAdc2 = sumCAdc2 / fEventCount;
282 Double_t cNoise2 = avCAdc2 - avCAdc * avCAdc;
283 fCenteredPed->SetBinContent(bin, avCAdc);
284 fCorrectedNoise->SetBinContent(bin, TMath::Sqrt(cNoise2));
287 gStyle->SetPalette(1);
288 gStyle->SetOptTitle(0);
289 gStyle->SetCanvasColor(0);
290 gStyle->SetCanvasBorderSize(0);
291 gStyle->SetPadColor(0);
292 gStyle->SetPadBorderSize(0);
294 TCanvas* c = new TCanvas("c", "C", 800, 600);
299 c->SetBottomMargin(0);
302 TPad* p1 = static_cast<TPad*>(c->cd(1));
303 p1->SetTopMargin(0.05);
304 p1->SetRightMargin(0.05);
305 if (!fReader) fNoise->GetXaxis()->SetRangeUser(-0.5, 255.5);
306 fNoise->SetMinimum(0);
307 fNoise->SetMaximum(1.5*fNoise->GetMaximum());
309 fCorrectedNoise->SetMinimum(0);
310 fCorrectedNoise->SetFillColor(kBlue);
311 fCorrectedNoise->DrawCopy("same");
312 TLegend* l1 = new TLegend(0.2, 0.7, 0.945, 0.945);
315 l1->SetBorderSize(0);
316 l1->AddEntry(fNoise, "Noise", "f");
317 l1->AddEntry(fCorrectedNoise, "Corrected noise", "f");
321 TPad* p2 = static_cast<TPad*>(c->cd(2));
322 p2->SetTopMargin(0.05);
323 p2->SetRightMargin(0.05);
324 if (!fReader) fPed->GetXaxis()->SetRangeUser(-0.5, 255.5);
325 fPed->SetMinimum(fCenteredPed->GetMinimum());
326 fPed->SetMaximum(1.5*fPed->GetMaximum());
328 fCenteredPed->SetFillColor(kBlue);
329 fCenteredPed->DrawCopy("same");
330 TLegend* l2 = new TLegend(0.2, 0.7, 0.945, 0.945);
333 l2->SetBorderSize(0);
334 l2->AddEntry(fPed, "Pedestal", "f");
335 l2->AddEntry(fCenteredPed, "Pedestal - #bar{Pedestal}", "f");
344 std::cout << "Flusing to disk ... " << std::flush;
348 fCenteredPed->Write(); //
349 fCorrectedNoise->Write(); //
350 fSummedAdc->Write(); //
351 fSummedAdc2->Write(); //
352 fSummedCenteredAdc->Write(); //
353 fSummedCenteredAdc2->Write(); //
357 std::cout << "done" << std::endl;
362 ClassDef(FindCommonModeNoise,0);
365 //____________________________________________________________________