]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDBaseDA.cxx
New features, summary plots etc. The DA's now write out calibration parameters in...
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
CommitLineData
a0180e76 1/**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/** @file AliFMDBaseDA.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Wed Mar 26 11:30:45 2008
19 @brief Base class for detector algorithms.
20*/
21//
e9c06036 22// This is the implementation of the (virtual) base class for the FMD
23// detector algorithms(DA). It implements the creation of the relevant
24// containers and handles the loop over the raw data. The derived
25// classes can control the parameters and action to be taken making
26// this the base class for the Pedestal, Gain and Physics DA.
a0180e76 27//
28
29#include "AliFMDBaseDA.h"
30#include "iostream"
31
32#include "AliFMDRawReader.h"
1656783c 33#include "AliFMDCalibSampleRate.h"
a0180e76 34#include "AliLog.h"
35//_____________________________________________________________________
36ClassImp(AliFMDBaseDA)
e9c06036 37#if 0
38; // Do not delete - to let Emacs for mat the code
39#endif
40
41//_____________________________________________________________________
42const char*
43AliFMDBaseDA::GetStripPath(UShort_t det,
44 Char_t ring,
45 UShort_t sec,
46 UShort_t str,
47 Bool_t full) const
48{
49 return Form("%s%sFMD%d%c[%02d,%03d]",
50 (full ? GetSectorPath(det, ring, sec, full) : ""),
51 (full ? "/" : ""), det, ring, sec, str);
52}
53//_____________________________________________________________________
54const char*
55AliFMDBaseDA::GetSectorPath(UShort_t det,
56 Char_t ring,
57 UShort_t sec,
58 Bool_t full) const
59{
60 return Form("%s%sFMD%d%c[%02d]",
61 (full ? GetRingPath(det, ring, full) : ""),
62 (full ? "/" : ""), det, ring, sec);
63}
64//_____________________________________________________________________
65const char*
66AliFMDBaseDA::GetRingPath(UShort_t det,
67 Char_t ring,
68 Bool_t full) const
69{
70 return Form("%s%sFMD%d%c",
71 (full ? GetDetectorPath(det, full) : ""),
72 (full ? "/" : ""), det, ring);
73}
74//_____________________________________________________________________
75const char*
76AliFMDBaseDA::GetDetectorPath(UShort_t det,
77 Bool_t full) const
78{
79 return Form("%s%sFMD%d",
80 (full ? fDiagnosticsFilename.Data() : ""),
81 (full ? ":/" : ""), det);
82}
a0180e76 83
84//_____________________________________________________________________
427e8f99 85AliFMDBaseDA::AliFMDBaseDA() :
86 TNamed(),
a0180e76 87 fDiagnosticsFilename("diagnosticsHistograms.root"),
88 fOutputFile(),
ce5a8b1a 89 fConditionsFile(),
a0180e76 90 fSaveHistograms(kFALSE),
91 fDetectorArray(),
427e8f99 92 fPulseSize(16),
93 fPulseLength(16),
a0180e76 94 fRequiredEvents(0),
95 fCurrentEvent(0)
427e8f99 96 {
a0180e76 97 fDetectorArray.SetOwner();
ce5a8b1a 98 fConditionsFile.open("conditions.csv");
a0180e76 99}
100//_____________________________________________________________________
101AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
102 TNamed(baseDA),
a7e41e8d 103 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
a0180e76 104 fOutputFile(),
ce5a8b1a 105 fConditionsFile(),
a0180e76 106 fSaveHistograms(baseDA.fSaveHistograms),
107 fDetectorArray(baseDA.fDetectorArray),
427e8f99 108 fPulseSize(baseDA.fPulseSize),
109 fPulseLength(baseDA.fPulseLength),
a0180e76 110 fRequiredEvents(baseDA.fRequiredEvents),
111 fCurrentEvent(baseDA.fCurrentEvent)
112{
113 fDetectorArray.SetOwner();
114
115}
116
82d71828 117
a0180e76 118//_____________________________________________________________________
e9c06036 119AliFMDBaseDA::~AliFMDBaseDA()
120{
a0180e76 121 //destructor
a0180e76 122}
123
124//_____________________________________________________________________
e9c06036 125void AliFMDBaseDA::Run(AliRawReader* reader)
126{
127 TFile* diagFile = 0;
128 if (fSaveHistograms)
129 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
a0180e76 130
427e8f99 131
132 WriteConditionsData();
133
e9c06036 134 InitContainer(diagFile);
a0180e76 135 Init();
136
e9c06036 137
a0180e76 138 reader->Reset();
ce5a8b1a 139
e9c06036 140 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
141 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
427e8f99 142
e9c06036 143 reader->NextEvent(); // Read Start-of-Run event
144 reader->NextEvent(); // Read Start-of-Files event
1656783c 145 int lastProgress = 0;
a0180e76 146
e9c06036 147 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
148 if(!reader->NextEvent()) continue;
149
150 SetCurrentEvent(*(reader->GetEventId()));
151
152 digitArray->Clear();
153 fmdReader->ReadAdcs(digitArray);
154
155 AliDebug(5, Form("In event # %d with %d entries",
156 *(reader->GetEventId()), digitArray->GetEntriesFast()));
157
158 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
159 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
160 FillChannels(digit);
a0180e76 161 }
e9c06036 162
163 FinishEvent();
164 int progress = int((n *100)/ GetRequiredEvents()) ;
165 if (progress <= lastProgress) continue;
166 lastProgress = progress;
167 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
168 }
169
a0180e76 170 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
171 WriteHeaderToFile();
172
173 for(UShort_t det=1;det<=3;det++) {
e9c06036 174 std::cout << "FMD" << det << std::endl;
a0180e76 175 UShort_t FirstRing = (det == 1 ? 1 : 0);
176 for (UShort_t ir = FirstRing; ir < 2; ir++) {
177 Char_t ring = (ir == 0 ? 'O' : 'I');
178 UShort_t nsec = (ir == 0 ? 40 : 20);
179 UShort_t nstr = (ir == 0 ? 256 : 512);
e9c06036 180 std::cout << " Ring " << ring << ": " << std::flush;
a0180e76 181 for(UShort_t sec =0; sec < nsec; sec++) {
182 for(UShort_t strip = 0; strip < nstr; strip++) {
183 Analyse(det,ring,sec,strip);
a0180e76 184 }
e9c06036 185 std::cout << '.' << std::flush;
a0180e76 186 }
427e8f99 187 if(fSaveHistograms)
188 diagFile->Flush();
e9c06036 189 std::cout << "done" << std::endl;
a0180e76 190 }
191 }
ce5a8b1a 192
a0180e76 193 if(fOutputFile.is_open()) {
a0180e76 194 fOutputFile.write("# EOF\n",6);
195 fOutputFile.close();
a0180e76 196 }
197
198 if(fSaveHistograms ) {
f7f0b643 199
200 Terminate(diagFile);
201
e9c06036 202 AliInfo("Closing diagnostics file - please wait ...");
203 // diagFile->Write();
ce5a8b1a 204 diagFile->Close();
e9c06036 205 AliInfo("done");
a0180e76 206 }
207}
208//_____________________________________________________________________
209
e9c06036 210void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
211{
a0180e76 212 TObjArray* detArray;
213 TObjArray* ringArray;
214 TObjArray* sectorArray;
215
e9c06036 216 TDirectory* savDir = gDirectory;
217
a0180e76 218 for(UShort_t det=1;det<=3;det++) {
219 detArray = new TObjArray();
220 detArray->SetOwner();
221 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 222
223 TDirectory* detDir = 0;
224 if (diagFile) {
225 diagFile->cd();
226 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
227 }
228
a0180e76 229 UShort_t FirstRing = (det == 1 ? 1 : 0);
230 for (UShort_t ir = FirstRing; ir < 2; ir++) {
231 Char_t ring = (ir == 0 ? 'O' : 'I');
232 UShort_t nsec = (ir == 0 ? 40 : 20);
233 UShort_t nstr = (ir == 0 ? 256 : 512);
234 ringArray = new TObjArray();
235 ringArray->SetOwner();
236 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 237
238
239 TDirectory* ringDir = 0;
240 if (detDir) {
241 detDir->cd();
242 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
243 }
244
245
a0180e76 246 for(UShort_t sec =0; sec < nsec; sec++) {
247 sectorArray = new TObjArray();
248 sectorArray->SetOwner();
249 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 250
251
252 TDirectory* secDir = 0;
253 if (ringDir) {
254 ringDir->cd();
255 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
256 }
257
a0180e76 258 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 259 if (secDir) {
260 secDir->cd();
261 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
262 }
a0180e76 263 AddChannelContainer(sectorArray, det, ring, sec, strip);
264 }
265 }
266 }
267 }
e9c06036 268 savDir->cd();
a0180e76 269}
ce5a8b1a 270
271//_____________________________________________________________________
e9c06036 272void AliFMDBaseDA::WriteConditionsData()
273{
ce5a8b1a 274 AliFMDParameters* pars = AliFMDParameters::Instance();
275 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
427e8f99 276
277 // fConditionsFile.write("# Sample Rate, timebins \n",25);
278
279 // Sample Rate
ce5a8b1a 280
1656783c 281 UInt_t defSampleRate = 4;
427e8f99 282 UInt_t sampleRateFromSOD;
283 //UInt_t timebins = 544;
1656783c 284 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
285 for(UShort_t det=1;det<=3;det++) {
286 UShort_t FirstRing = (det == 1 ? 1 : 0);
287 for (UShort_t ir = FirstRing; ir < 2; ir++) {
288 Char_t ring = (ir == 0 ? 'O' : 'I');
289 UShort_t nsec = (ir == 0 ? 40 : 20);
290 UShort_t nstr = (ir == 0 ? 256 : 512);
291 for(UShort_t sec =0; sec < nsec; sec++) {
292 for(UShort_t strip = 0; strip < nstr; strip++) {
427e8f99 293 sampleRateFromSOD = defSampleRate;
294 sampleRate->Set(det,ring,sec,strip,sampleRateFromSOD);
295 fConditionsFile << det << ','
296 << ring << ','
297 << sec << ','
298 << strip << ','
299 << "samplerate" << ','
300 << sampleRateFromSOD << "\n";
1656783c 301 }
302 }
303 }
304 }
305
306 pars->SetSampleRate(sampleRate);
307
427e8f99 308 // Zero Suppresion
309
310 // Strip Range
311
312 // Gain Relevant stuff
1656783c 313
427e8f99 314 UShort_t defPulseSize = 32 ;
315 UShort_t defPulseLength = 100 ;
316 UShort_t pulseSizeFromSOD;
317 UShort_t pulseLengthFromSOD;
318
319 fPulseSize.Reset(defPulseSize);
320 fPulseLength.Reset(defPulseLength);
321
322 for(UShort_t det=1;det<=3;det++)
323 for(UShort_t iring=0;iring<=1;iring++)
324 for(UShort_t board=0;board<=1;board++) {
325 pulseSizeFromSOD = defPulseSize;
326 pulseLengthFromSOD = defPulseLength;
327
328 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
329 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
330 }
331
332
333 // fConditionsFile << defSampleRate << ','
334 // << timebins <<"\n";
1656783c 335
336 if(fConditionsFile.is_open()) {
ce5a8b1a 337
427e8f99 338 fConditionsFile.write("# EOF\n",6);
1656783c 339 fConditionsFile.close();
340
341 }
ce5a8b1a 342
343}
427e8f99 344//_____________________________________________________________________
345Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
346
347 UShort_t iring = (ring == 'I' ? 1 : 0);
348
349 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
350
351 return index;
352
353}
354
ce5a8b1a 355
a0180e76 356//_____________________________________________________________________
357//
358// EOF
359//