]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDBaseDA.cxx
Fixing minor typo.
[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 ) {
e9c06036 199 AliInfo("Closing diagnostics file - please wait ...");
200 // diagFile->Write();
ce5a8b1a 201 diagFile->Close();
e9c06036 202 AliInfo("done");
a0180e76 203 }
204}
205//_____________________________________________________________________
206
e9c06036 207void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
208{
a0180e76 209 TObjArray* detArray;
210 TObjArray* ringArray;
211 TObjArray* sectorArray;
212
e9c06036 213 TDirectory* savDir = gDirectory;
214
a0180e76 215 for(UShort_t det=1;det<=3;det++) {
216 detArray = new TObjArray();
217 detArray->SetOwner();
218 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 219
220 TDirectory* detDir = 0;
221 if (diagFile) {
222 diagFile->cd();
223 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
224 }
225
a0180e76 226 UShort_t FirstRing = (det == 1 ? 1 : 0);
227 for (UShort_t ir = FirstRing; ir < 2; ir++) {
228 Char_t ring = (ir == 0 ? 'O' : 'I');
229 UShort_t nsec = (ir == 0 ? 40 : 20);
230 UShort_t nstr = (ir == 0 ? 256 : 512);
231 ringArray = new TObjArray();
232 ringArray->SetOwner();
233 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 234
235
236 TDirectory* ringDir = 0;
237 if (detDir) {
238 detDir->cd();
239 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
240 }
241
242
a0180e76 243 for(UShort_t sec =0; sec < nsec; sec++) {
244 sectorArray = new TObjArray();
245 sectorArray->SetOwner();
246 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 247
248
249 TDirectory* secDir = 0;
250 if (ringDir) {
251 ringDir->cd();
252 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
253 }
254
a0180e76 255 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 256 if (secDir) {
257 secDir->cd();
258 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
259 }
a0180e76 260 AddChannelContainer(sectorArray, det, ring, sec, strip);
261 }
262 }
263 }
264 }
e9c06036 265 savDir->cd();
a0180e76 266}
ce5a8b1a 267
268//_____________________________________________________________________
e9c06036 269void AliFMDBaseDA::WriteConditionsData()
270{
ce5a8b1a 271 AliFMDParameters* pars = AliFMDParameters::Instance();
272 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
427e8f99 273
274 // fConditionsFile.write("# Sample Rate, timebins \n",25);
275
276 // Sample Rate
ce5a8b1a 277
1656783c 278 UInt_t defSampleRate = 4;
427e8f99 279 UInt_t sampleRateFromSOD;
280 //UInt_t timebins = 544;
1656783c 281 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
282 for(UShort_t det=1;det<=3;det++) {
283 UShort_t FirstRing = (det == 1 ? 1 : 0);
284 for (UShort_t ir = FirstRing; ir < 2; ir++) {
285 Char_t ring = (ir == 0 ? 'O' : 'I');
286 UShort_t nsec = (ir == 0 ? 40 : 20);
287 UShort_t nstr = (ir == 0 ? 256 : 512);
288 for(UShort_t sec =0; sec < nsec; sec++) {
289 for(UShort_t strip = 0; strip < nstr; strip++) {
427e8f99 290 sampleRateFromSOD = defSampleRate;
291 sampleRate->Set(det,ring,sec,strip,sampleRateFromSOD);
292 fConditionsFile << det << ','
293 << ring << ','
294 << sec << ','
295 << strip << ','
296 << "samplerate" << ','
297 << sampleRateFromSOD << "\n";
1656783c 298 }
299 }
300 }
301 }
302
303 pars->SetSampleRate(sampleRate);
304
427e8f99 305 // Zero Suppresion
306
307 // Strip Range
308
309 // Gain Relevant stuff
1656783c 310
427e8f99 311 UShort_t defPulseSize = 32 ;
312 UShort_t defPulseLength = 100 ;
313 UShort_t pulseSizeFromSOD;
314 UShort_t pulseLengthFromSOD;
315
316 fPulseSize.Reset(defPulseSize);
317 fPulseLength.Reset(defPulseLength);
318
319 for(UShort_t det=1;det<=3;det++)
320 for(UShort_t iring=0;iring<=1;iring++)
321 for(UShort_t board=0;board<=1;board++) {
322 pulseSizeFromSOD = defPulseSize;
323 pulseLengthFromSOD = defPulseLength;
324
325 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
326 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
327 }
328
329
330 // fConditionsFile << defSampleRate << ','
331 // << timebins <<"\n";
1656783c 332
333 if(fConditionsFile.is_open()) {
ce5a8b1a 334
427e8f99 335 fConditionsFile.write("# EOF\n",6);
1656783c 336 fConditionsFile.close();
337
338 }
ce5a8b1a 339
340}
427e8f99 341//_____________________________________________________________________
342Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
343
344 UShort_t iring = (ring == 'I' ? 1 : 0);
345
346 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
347
348 return index;
349
350}
351
ce5a8b1a 352
a0180e76 353//_____________________________________________________________________
354//
355// EOF
356//