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