AliRoot Core  edcc906 (edcc906)
DrawCalibRaw.C
Go to the documentation of this file.
1 //____________________________________________________________________
2 //
3 // $Id: DrawDigits.C 30718 2009-01-22 16:07:40Z cholm $
4 //
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.
7 //
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.
11 //
12 // Use the script `Compile.C' to compile this class using ACLic.
13 //
14 #include <TH1D.h>
15 #include <AliCDBManager.h>
16 #include <AliFMDHit.h>
17 #include <AliFMDDigit.h>
18 #include <AliFMDInput.h>
19 #include <AliFMDEdepMap.h>
20 #include <AliFMDParameters.h>
21 #include <AliFMDCalibStripRange.h>
22 #include <AliFMDCalibSampleRate.h>
23 #include <AliFMDCalibGain.h>
24 #include <AliFMDCalibPedestal.h>
25 #include <AliFMDRawReader.h>
26 #include <iostream>
27 #include <fstream>
28 #include <TStyle.h>
29 #include <TArrayF.h>
30 #include <AliLog.h>
31 #include <TSystem.h>
32 #include <TFile.h>
33 
45 class DrawCalibRaw : public AliFMDInput
46 {
47 private:
48  Double_t fFactor;
49  TString fCalibDir;
50  TH1D* fELoss; // Histogram
52  TFile* fOut;
53  Bool_t fHasData;
54  Int_t fGotNEvents;
55 
56 public:
57  //__________________________________________________________________
58  DrawCalibRaw(const char* file,
59  const char* calibDir = 0,
60  Double_t noiseFactor = 5,
61  Bool_t save = kTRUE,
62  Int_t m = 420,
63  Double_t mmin = -0.5,
64  Double_t mmax = 20.5)
65  : AliFMDInput(),
66  fFactor(noiseFactor),
67  fCalibDir(""),
68  fELoss(0),
69  fDets(0),
70  fOut(0),
71  fHasData(kFALSE),
72  fGotNEvents(0)
73  {
74  if (calibDir) fCalibDir = calibDir;
76  fELoss = new TH1D("eLoss", "Scaled Energy loss", m, mmin, mmax);
77  fELoss->SetXTitle("#Delta E/#Delta E_{mip}");
78  fELoss->Sumw2();
79  fELoss->SetDirectory(0);
80 
81  SetRawFile(file);
82 
83  if (!save) return;
84  fDets = new TObjArray(3);
85 
86  }
87  //__________________________________________________________________
88  Bool_t CheckFile(const char* prefix, int number, TString& f)
89  {
90  f = (Form("%s%d.csv", prefix, number));
91  f = gSystem->Which(fCalibDir.Data(), f.Data());
92  return !f.IsNull();
93  }
94 
95  //__________________________________________________________________
96  Bool_t Init()
97  {
99  cdb->SetRun(0);
100  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
101 
103  AliFMDCalibSampleRate* rate = 0;
104  AliFMDCalibPedestal* peds = 0;
105  AliFMDCalibGain* gains = 0;
106  for (Int_t i = 1; i <= 3; i++) {
107  TString f;
108  if (CheckFile("conditions", i, f)) {
109  Info("Init", "Reading conditions for FMD%d from %s", i, f.Data());
110  if (!range) range = new AliFMDCalibStripRange;
111  if (!rate) rate = new AliFMDCalibSampleRate;
112  std::ifstream in(f.Data());
113  range->ReadFromFile(in);
114  rate->ReadFromFile(in);
115  }
116  if (CheckFile("peds", i, f)) {
117  Info("Init", "Reading pedestals for FMD%d from %s", i, f.Data());
118  if (!peds) peds = new AliFMDCalibPedestal;
119  std::ifstream in(f.Data());
120  peds->ReadFromFile(in);
121  }
122  if (CheckFile("gains", i, f)) {
123  Info("Init", "Reading gains for FMD%d from %s", i, f.Data());
124  if (!gains) gains = new AliFMDCalibGain;
125  std::ifstream in(f.Data());
126  gains->ReadFromFile(in);
127  }
128  }
129 
130  Int_t mask = (AliFMDParameters::kDeadMap|
133 
134  if (!range) mask |= AliFMDParameters::kStripRange;
135  if (!rate) mask |= AliFMDParameters::kSampleRate;
136  if (!peds) mask |= AliFMDParameters::kPedestal;
137  if (!gains) mask |= AliFMDParameters::kPulseGain;
138 
140  pars->Init(kFALSE, mask);
141 
142  if (range) pars->SetStripRange(range);
143  if (rate) pars->SetSampleRate(rate);
144  if (peds) pars->SetPedestal(peds);
145  if (gains) pars->SetGain(gains);
146 
147  Bool_t ret = AliFMDInput::Init();
148 
149  if (!fDets) return ret;
150 
151  fOut = TFile::Open(Form("histo_%s", fRawFile.Data()), "RECREATE");
152 
153  Int_t m = fELoss->GetXaxis()->GetNbins();
154  Int_t mmin = fELoss->GetXaxis()->GetXmin();
155  Int_t mmax = fELoss->GetXaxis()->GetXmax();
156  for (Int_t d = 1; d <= 3; d++) {
157  Int_t nRng = (d == 1 ? 1 : 2);
158  TObjArray* det = 0;
159  fDets->AddAt(det = new TObjArray(nRng), d-1);
160  det->SetName(Form("FMD%d", d));
161  TDirectory* detD = fOut->mkdir(det->GetName());
162  for (Int_t q = 0; q < nRng; q++) {
163  Char_t r = q == 0 ? 'I' : 'O';
164  Int_t nSec = q == 0 ? 20 : 40;
165  Int_t nStr = q == 0 ? 512 : 256;
166  TObjArray* rng = 0;
167  det->AddAt(rng = new TObjArray(nSec), q);
168  rng->SetName(Form("FMD%d%c", d, r));
169  TDirectory* rngD = detD->mkdir(rng->GetName());
170  for (Int_t s = 0; s < nSec; s++) {
171  TObjArray* sec = 0;
172  rng->AddAt(sec = new TObjArray(nStr), s);
173  sec->SetName(Form("FMD%d%c_%02d", d, r, s));
174  TDirectory* secD = rngD->mkdir(sec->GetName());
175  for (Int_t t = 0; t < nStr; t++) {
176  secD->cd();
177  TH1* str = new TH1D(Form("FMD%d%c_%02d_%03d", d, r, s, t),
178  Form("Scaled energy loss in FMD%d%c[%2d,%3d]",
179  d, r, s, t), m, mmin, mmax);
180  str->SetXTitle("#Delta E/#Delta E_{mip}");
181  // str->SetDirectory(secD);
182  sec->AddAt(str, t);
183  }
184  }
185  }
186  }
187 
188  return ret;
189  }
190 
191  //__________________________________________________________________
192  Bool_t Begin(Int_t e)
193  {
194  fHasData = kFALSE;
195  return AliFMDInput::Begin(e);
196  }
197 
198  //__________________________________________________________________
200  {
201  if (!digit) return kTRUE;
202 
204  UShort_t d = digit->Detector();
205  Char_t r = digit->Ring();
206  UShort_t s = digit->Sector();
207  UShort_t t = digit->Strip();
208  Double_t gain = parm->GetPulseGain(d, r, s, t);
209  Double_t ped = parm->GetPedestal(d, r, s, t);
210  Double_t pedW = parm->GetPedestalWidth(d, r, s, t);
211  Double_t adc = digit->Counts();
212  Double_t threshold = pedW * fFactor;
213  if (gain < 0.1 || gain > 10) return kTRUE;
214  if (pedW > 10) {
215  Warning("ProcessRawCalibDigit", "FMD%d%c[%2d,%3d] is noisy: %f",
216  d, r, s, t, pedW);
217  return kTRUE;
218  }
219 
221  adc += fFMDReader->NoiseFactor(d-1) * pedW;
222  else
223  threshold += ped;
224 
225  if (adc < threshold) return kTRUE;
226 
227  Double_t mult = (adc-ped) / (gain * parm->GetDACPerMIP());
228 
229  fHasData = kTRUE;
230  fELoss->Fill(mult);
231 
232  // if (t >= 10) return kTRUE;
233  TObjArray* det = static_cast<TObjArray*>(fDets->At(d-1));
234  TObjArray* rng = static_cast<TObjArray*>(det->At(r == 'I' ? 0 : 1));
235  TObjArray* sec = static_cast<TObjArray*>(rng->At(s));
236  TH1* str = static_cast<TH1*>(sec->At(t));
237  str->Fill(mult);
238 
239  return kTRUE;
240  }
241  //__________________________________________________________________
242  Bool_t End()
243  {
244  if (fHasData) fGotNEvents++;
245  return AliFMDInput::End();
246  }
247  //__________________________________________________________________
248  Bool_t Finish()
249  {
250  std::cout << "A total of " << fGotNEvents << " with data" << std::endl;
251  gStyle->SetPalette(1);
252  gStyle->SetOptTitle(0);
253  gStyle->SetCanvasColor(0);
254  gStyle->SetCanvasBorderSize(0);
255  gStyle->SetPadColor(0);
256  gStyle->SetPadBorderSize(0);
257  fELoss->SetStats(kFALSE);
258  fELoss->SetFillColor(kRed);
259  fELoss->SetFillStyle(3001);
260  fELoss->Scale(1. / fELoss->GetEntries());
261  fELoss->DrawCopy("e1 bar");
262 
263  if (fDets && fOut) {
264  std::cout << "Flusing to disk ... " << std::flush;
265  fOut->cd();
266  fELoss->Write();
267  fOut->Write();
268  fOut->Close();
269  std::cout << "done" << std::endl;
270  }
271  return kTRUE;
272  }
273 
274  ClassDef(DrawCalibRaw,0);
275 };
276 
277 //____________________________________________________________________
278 //
279 // EOF
280 //
class for digits
Definition: AliFMDDigit.h:28
Float_t GetDACPerMIP() const
TFile * Open(const char *filename, Long64_t &nevents)
Bool_t ProcessRawCalibDigit(AliFMDDigit *digit)
Definition: DrawCalibRaw.C:199
TStyle * gStyle
Hit in the FMD.
UShort_t NoiseFactor(UShort_t ddl) const
#define TObjArray
Digits for the FMD.
FMD utility classes for reading FMD data.
UShort_t Sector() const
Char_t Ring() const
Per strip map of energy deposited and number of hits.
void ReadFromFile(std::istream &inFile)
This class is a singleton that handles various parameters of the FMD detectors. This class reads from...
Manager of FMD parameters.
Float_t GetPulseGain(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Per digitizer card pulser calibration.
Bool_t ReadFromFile(std::istream &inFile)
virtual Bool_t Begin(Int_t event)
void SetSampleRate(UShort_t r=2)
Bool_t End()
Definition: DrawCalibRaw.C:242
Per strip pedestal calibration.
Gain value and width for each strip in the FMD.
Per digitizer card pulser calibration.
AliFMDRawReader * fFMDReader
Definition: AliFMDInput.h:419
Per digitizer card pulser calibration.
Bool_t IsZeroSuppressed(UShort_t ddl) const
Int_t fGotNEvents
Definition: DrawCalibRaw.C:54
virtual Bool_t Init()
Bool_t CheckFile(const char *prefix, int number, TString &f)
Definition: DrawCalibRaw.C:88
void SetStripRange(UShort_t min=0, UShort_t max=127)
Per strip gain calibration.
char * prefix
TString fRawFile
Definition: AliFMDInput.h:441
Bool_t ReadFromFile(std::istream &inFile)
UShort_t Strip() const
Float_t range[5]
virtual void AddLoad(ETrees tree)
Definition: AliFMDInput.h:134
static AliFMDParameters * Instance()
void SetRun(Int_t run)
Double_t fFactor
Definition: DrawCalibRaw.C:48
Class to read raw data.
TF1 * f
Definition: interpolTest.C:21
void SetDefaultStorage(const char *dbString)
Bool_t Begin(Int_t e)
Definition: DrawCalibRaw.C:192
Bool_t Init()
Definition: DrawCalibRaw.C:96
Base class for reading in various FMD data. The class loops over all found events. For each event the specified data is read in. The class then loops over all elements of the read data, and process these with user defined code.
Definition: AliFMDInput.h:106
TFile * fOut
Definition: DrawCalibRaw.C:52
void SetGain(AliFMDCalibGain *g)
virtual Bool_t End()
Per digitizer card pulser calibration.
void SetPedestal(Float_t p=100)
DrawCalibRaw(const char *file, const char *calibDir=0, Double_t noiseFactor=5, Bool_t save=kTRUE, Int_t m=420, Double_t mmin=-0.5, Double_t mmax=20.5)
Definition: DrawCalibRaw.C:58
void ReadFromFile(std::istream &)
TObjArray * fDets
Definition: DrawCalibRaw.C:51
UShort_t Detector() const
Bool_t Finish()
Definition: DrawCalibRaw.C:248
TH1D * fELoss
Definition: DrawCalibRaw.C:50
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
UShort_t Counts() const
Definition: AliFMDDigit.h:147
Float_t GetPedestal(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Float_t GetPedestalWidth(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
TString fCalibDir
Definition: DrawCalibRaw.C:49
Pedestal value and width for each strip in the FMD.
UShort_t Init(Bool_t forceReInit=kFALSE, UInt_t what=kAll)
void SetRawFile(const char *file)
Definition: AliFMDInput.h:318
Bool_t fHasData
Definition: DrawCalibRaw.C:53