added debug for sample rates
[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"
bd727bee 34#include "AliFMDCalibStripRange.h"
a0180e76 35#include "AliLog.h"
36//_____________________________________________________________________
37ClassImp(AliFMDBaseDA)
e9c06036 38#if 0
39; // Do not delete - to let Emacs for mat the code
40#endif
41
42//_____________________________________________________________________
43const char*
44AliFMDBaseDA::GetStripPath(UShort_t det,
45 Char_t ring,
46 UShort_t sec,
47 UShort_t str,
48 Bool_t full) const
49{
50 return Form("%s%sFMD%d%c[%02d,%03d]",
51 (full ? GetSectorPath(det, ring, sec, full) : ""),
52 (full ? "/" : ""), det, ring, sec, str);
53}
54//_____________________________________________________________________
55const char*
56AliFMDBaseDA::GetSectorPath(UShort_t det,
57 Char_t ring,
58 UShort_t sec,
59 Bool_t full) const
60{
61 return Form("%s%sFMD%d%c[%02d]",
62 (full ? GetRingPath(det, ring, full) : ""),
63 (full ? "/" : ""), det, ring, sec);
64}
65//_____________________________________________________________________
66const char*
67AliFMDBaseDA::GetRingPath(UShort_t det,
68 Char_t ring,
69 Bool_t full) const
70{
71 return Form("%s%sFMD%d%c",
72 (full ? GetDetectorPath(det, full) : ""),
73 (full ? "/" : ""), det, ring);
74}
75//_____________________________________________________________________
76const char*
77AliFMDBaseDA::GetDetectorPath(UShort_t det,
78 Bool_t full) const
79{
80 return Form("%s%sFMD%d",
81 (full ? fDiagnosticsFilename.Data() : ""),
82 (full ? ":/" : ""), det);
83}
a0180e76 84
85//_____________________________________________________________________
427e8f99 86AliFMDBaseDA::AliFMDBaseDA() :
87 TNamed(),
a0180e76 88 fDiagnosticsFilename("diagnosticsHistograms.root"),
89 fOutputFile(),
ce5a8b1a 90 fConditionsFile(),
a0180e76 91 fSaveHistograms(kFALSE),
92 fDetectorArray(),
427e8f99 93 fPulseSize(16),
94 fPulseLength(16),
a0180e76 95 fRequiredEvents(0),
96 fCurrentEvent(0)
427e8f99 97 {
a0180e76 98 fDetectorArray.SetOwner();
ce5a8b1a 99 fConditionsFile.open("conditions.csv");
a0180e76 100}
101//_____________________________________________________________________
102AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
103 TNamed(baseDA),
a7e41e8d 104 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
a0180e76 105 fOutputFile(),
ce5a8b1a 106 fConditionsFile(),
a0180e76 107 fSaveHistograms(baseDA.fSaveHistograms),
108 fDetectorArray(baseDA.fDetectorArray),
427e8f99 109 fPulseSize(baseDA.fPulseSize),
110 fPulseLength(baseDA.fPulseLength),
a0180e76 111 fRequiredEvents(baseDA.fRequiredEvents),
112 fCurrentEvent(baseDA.fCurrentEvent)
113{
114 fDetectorArray.SetOwner();
115
116}
117
82d71828 118
a0180e76 119//_____________________________________________________________________
e9c06036 120AliFMDBaseDA::~AliFMDBaseDA()
121{
a0180e76 122 //destructor
a0180e76 123}
124
125//_____________________________________________________________________
e9c06036 126void AliFMDBaseDA::Run(AliRawReader* reader)
127{
128 TFile* diagFile = 0;
129 if (fSaveHistograms)
130 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
a0180e76 131
427e8f99 132
133 WriteConditionsData();
134
e9c06036 135 InitContainer(diagFile);
a0180e76 136 Init();
137
e9c06036 138
a0180e76 139 reader->Reset();
ce5a8b1a 140
e9c06036 141 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
142 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
427e8f99 143
e9c06036 144 reader->NextEvent(); // Read Start-of-Run event
145 reader->NextEvent(); // Read Start-of-Files event
1656783c 146 int lastProgress = 0;
a0180e76 147
e9c06036 148 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
149 if(!reader->NextEvent()) continue;
150
151 SetCurrentEvent(*(reader->GetEventId()));
152
153 digitArray->Clear();
154 fmdReader->ReadAdcs(digitArray);
155
156 AliDebug(5, Form("In event # %d with %d entries",
157 *(reader->GetEventId()), digitArray->GetEntriesFast()));
158
159 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
160 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
161 FillChannels(digit);
a0180e76 162 }
e9c06036 163
164 FinishEvent();
165 int progress = int((n *100)/ GetRequiredEvents()) ;
166 if (progress <= lastProgress) continue;
167 lastProgress = progress;
168 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
169 }
170
a0180e76 171 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
172 WriteHeaderToFile();
173
174 for(UShort_t det=1;det<=3;det++) {
e9c06036 175 std::cout << "FMD" << det << std::endl;
a0180e76 176 UShort_t FirstRing = (det == 1 ? 1 : 0);
177 for (UShort_t ir = FirstRing; ir < 2; ir++) {
178 Char_t ring = (ir == 0 ? 'O' : 'I');
179 UShort_t nsec = (ir == 0 ? 40 : 20);
180 UShort_t nstr = (ir == 0 ? 256 : 512);
e9c06036 181 std::cout << " Ring " << ring << ": " << std::flush;
a0180e76 182 for(UShort_t sec =0; sec < nsec; sec++) {
183 for(UShort_t strip = 0; strip < nstr; strip++) {
184 Analyse(det,ring,sec,strip);
a0180e76 185 }
e9c06036 186 std::cout << '.' << std::flush;
a0180e76 187 }
427e8f99 188 if(fSaveHistograms)
189 diagFile->Flush();
e9c06036 190 std::cout << "done" << std::endl;
a0180e76 191 }
192 }
ce5a8b1a 193
a0180e76 194 if(fOutputFile.is_open()) {
a0180e76 195 fOutputFile.write("# EOF\n",6);
196 fOutputFile.close();
a0180e76 197 }
198
199 if(fSaveHistograms ) {
f7f0b643 200
201 Terminate(diagFile);
202
e9c06036 203 AliInfo("Closing diagnostics file - please wait ...");
204 // diagFile->Write();
ce5a8b1a 205 diagFile->Close();
e9c06036 206 AliInfo("done");
a0180e76 207 }
208}
209//_____________________________________________________________________
210
e9c06036 211void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
212{
a0180e76 213 TObjArray* detArray;
214 TObjArray* ringArray;
215 TObjArray* sectorArray;
216
e9c06036 217 TDirectory* savDir = gDirectory;
218
a0180e76 219 for(UShort_t det=1;det<=3;det++) {
220 detArray = new TObjArray();
221 detArray->SetOwner();
222 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 223
224 TDirectory* detDir = 0;
225 if (diagFile) {
226 diagFile->cd();
227 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
228 }
229
a0180e76 230 UShort_t FirstRing = (det == 1 ? 1 : 0);
231 for (UShort_t ir = FirstRing; ir < 2; ir++) {
232 Char_t ring = (ir == 0 ? 'O' : 'I');
233 UShort_t nsec = (ir == 0 ? 40 : 20);
234 UShort_t nstr = (ir == 0 ? 256 : 512);
235 ringArray = new TObjArray();
236 ringArray->SetOwner();
237 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 238
239
240 TDirectory* ringDir = 0;
241 if (detDir) {
242 detDir->cd();
243 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
244 }
245
246
a0180e76 247 for(UShort_t sec =0; sec < nsec; sec++) {
248 sectorArray = new TObjArray();
249 sectorArray->SetOwner();
250 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 251
252
253 TDirectory* secDir = 0;
254 if (ringDir) {
255 ringDir->cd();
256 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
257 }
258
a0180e76 259 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 260 if (secDir) {
261 secDir->cd();
262 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
263 }
a0180e76 264 AddChannelContainer(sectorArray, det, ring, sec, strip);
265 }
266 }
267 }
268 }
e9c06036 269 savDir->cd();
a0180e76 270}
ce5a8b1a 271
272//_____________________________________________________________________
e9c06036 273void AliFMDBaseDA::WriteConditionsData()
274{
ce5a8b1a 275 AliFMDParameters* pars = AliFMDParameters::Instance();
276 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
427e8f99 277
278 // fConditionsFile.write("# Sample Rate, timebins \n",25);
279
280 // Sample Rate
ce5a8b1a 281
bd727bee 282 UShort_t defSampleRate = 4;
283 UShort_t sampleRateFromSOD;
427e8f99 284 //UInt_t timebins = 544;
1656783c 285 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
bd727bee 286
287 UShort_t firstStrip = 0;
288 UShort_t lastStrip = 127;
289 UShort_t firstStripSOD;
290 UShort_t lastStripSOD;
291 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
292
293 for(Int_t det=1;det<=3;det++) {
1656783c 294 UShort_t FirstRing = (det == 1 ? 1 : 0);
295 for (UShort_t ir = FirstRing; ir < 2; ir++) {
296 Char_t ring = (ir == 0 ? 'O' : 'I');
297 UShort_t nsec = (ir == 0 ? 40 : 20);
1656783c 298 for(UShort_t sec =0; sec < nsec; sec++) {
433a88bd 299 sampleRateFromSOD = defSampleRate;
300 sampleRate->Set(det,ring,sec,0,sampleRateFromSOD);
301 firstStripSOD = firstStrip;
302 lastStripSOD = lastStrip;
303 stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD);
bd727bee 304
1656783c 305 }
306 }
307 }
308
bd727bee 309 sampleRate->WriteToFile(fConditionsFile);
433a88bd 310 stripRange->WriteToFile(fConditionsFile);
bd727bee 311 pars->SetSampleRate(sampleRate);
433a88bd 312 pars->SetStripRange(stripRange);
bd727bee 313
314
427e8f99 315 // Zero Suppresion
316
317 // Strip Range
318
bd727bee 319
320
321
322
427e8f99 323 // Gain Relevant stuff
1656783c 324
427e8f99 325 UShort_t defPulseSize = 32 ;
326 UShort_t defPulseLength = 100 ;
327 UShort_t pulseSizeFromSOD;
328 UShort_t pulseLengthFromSOD;
329
330 fPulseSize.Reset(defPulseSize);
331 fPulseLength.Reset(defPulseLength);
332
333 for(UShort_t det=1;det<=3;det++)
334 for(UShort_t iring=0;iring<=1;iring++)
335 for(UShort_t board=0;board<=1;board++) {
336 pulseSizeFromSOD = defPulseSize;
337 pulseLengthFromSOD = defPulseLength;
338
339 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
340 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
341 }
342
343
344 // fConditionsFile << defSampleRate << ','
345 // << timebins <<"\n";
1656783c 346
347 if(fConditionsFile.is_open()) {
ce5a8b1a 348
427e8f99 349 fConditionsFile.write("# EOF\n",6);
1656783c 350 fConditionsFile.close();
351
352 }
ce5a8b1a 353
354}
427e8f99 355//_____________________________________________________________________
356Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
357
358 UShort_t iring = (ring == 'I' ? 1 : 0);
359
360 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
361
362 return index;
363
364}
365
ce5a8b1a 366
a0180e76 367//_____________________________________________________________________
368//
369// EOF
370//