]>
Commit | Line | Data |
---|---|---|
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 | //_____________________________________________________________________ |
39 | ClassImp(AliFMDBaseDA) | |
e9c06036 | 40 | #if 0 |
41 | ; // Do not delete - to let Emacs for mat the code | |
42 | #endif | |
43 | ||
44 | //_____________________________________________________________________ | |
45 | const char* | |
46 | AliFMDBaseDA::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 | //_____________________________________________________________________ | |
57 | const char* | |
58 | AliFMDBaseDA::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 | //_____________________________________________________________________ | |
68 | const char* | |
69 | AliFMDBaseDA::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 | //_____________________________________________________________________ | |
78 | const char* | |
79 | AliFMDBaseDA::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 | 88 | AliFMDBaseDA::AliFMDBaseDA() : |
89 | TNamed(), | |
a0180e76 | 90 | fDiagnosticsFilename("diagnosticsHistograms.root"), |
91 | fOutputFile(), | |
ce5a8b1a | 92 | fConditionsFile(), |
a0180e76 | 93 | fSaveHistograms(kFALSE), |
94 | fDetectorArray(), | |
29b7c86f | 95 | fPulseSize(10), |
96 | fPulseLength(10), | |
97 | fRequiredEvents(0), | |
a0180e76 | 98 | fCurrentEvent(0) |
427e8f99 | 99 | { |
a0180e76 | 100 | fDetectorArray.SetOwner(); |
ce5a8b1a | 101 | fConditionsFile.open("conditions.csv"); |
a0180e76 | 102 | } |
103 | //_____________________________________________________________________ | |
104 | AliFMDBaseDA::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 | 122 | AliFMDBaseDA::~AliFMDBaseDA() |
123 | { | |
a0180e76 | 124 | //destructor |
a0180e76 | 125 | } |
126 | ||
127 | //_____________________________________________________________________ | |
e9c06036 | 128 | void 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); |
29b7c86f | 138 | //Init(); |
a0180e76 | 139 | |
e9c06036 | 140 | |
a0180e76 | 141 | reader->Reset(); |
ce5a8b1a | 142 | |
e9c06036 | 143 | AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0); |
144 | TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0); | |
3effc6e7 | 145 | |
29b7c86f | 146 | Bool_t SOD_read = kFALSE; |
200d06f9 | 147 | |
148 | for(Int_t i=0;i<3;i++) { | |
149 | reader->NextEvent(); // Read Start-of-Run / Start-of-Files event | |
29b7c86f | 150 | |
200d06f9 | 151 | UInt_t eventType = reader->GetType(); |
152 | if(eventType == AliRawEventHeaderBase::kStartOfData || | |
153 | eventType == AliRawEventHeaderBase::kFormatError) { | |
154 | ||
155 | WriteConditionsData(fmdReader); | |
156 | Init(); | |
157 | SOD_read = kTRUE; | |
158 | break; | |
159 | } | |
29b7c86f | 160 | } |
200d06f9 | 161 | |
162 | if(!SOD_read) | |
29b7c86f | 163 | AliWarning("No SOD event detected!"); |
3effc6e7 | 164 | |
1656783c | 165 | int lastProgress = 0; |
a0180e76 | 166 | |
e9c06036 | 167 | for(Int_t n =1;n <= GetRequiredEvents(); n++) { |
168 | if(!reader->NextEvent()) continue; | |
169 | ||
3effc6e7 | 170 | SetCurrentEvent(n); |
e9c06036 | 171 | digitArray->Clear(); |
172 | fmdReader->ReadAdcs(digitArray); | |
3effc6e7 | 173 | //std::cout<<"in event "<<*(reader->GetEventId())<<" "<<n<<std::endl; |
174 | //AliDebug(5, Form("In event # %d with %d entries", | |
175 | // *(reader->GetEventId()), digitArray->GetEntriesFast())); | |
e9c06036 | 176 | |
177 | for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) { | |
178 | AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i)); | |
179 | FillChannels(digit); | |
a0180e76 | 180 | } |
e9c06036 | 181 | |
182 | FinishEvent(); | |
183 | int progress = int((n *100)/ GetRequiredEvents()) ; | |
184 | if (progress <= lastProgress) continue; | |
185 | lastProgress = progress; | |
186 | std::cout << "Progress: " << lastProgress << " / 100 " << std::endl; | |
187 | } | |
188 | ||
a0180e76 | 189 | AliInfo(Form("Looped over %d events",GetCurrentEvent())); |
190 | WriteHeaderToFile(); | |
191 | ||
192 | for(UShort_t det=1;det<=3;det++) { | |
e9c06036 | 193 | std::cout << "FMD" << det << std::endl; |
a0180e76 | 194 | UShort_t FirstRing = (det == 1 ? 1 : 0); |
195 | for (UShort_t ir = FirstRing; ir < 2; ir++) { | |
196 | Char_t ring = (ir == 0 ? 'O' : 'I'); | |
197 | UShort_t nsec = (ir == 0 ? 40 : 20); | |
198 | UShort_t nstr = (ir == 0 ? 256 : 512); | |
e9c06036 | 199 | std::cout << " Ring " << ring << ": " << std::flush; |
a0180e76 | 200 | for(UShort_t sec =0; sec < nsec; sec++) { |
201 | for(UShort_t strip = 0; strip < nstr; strip++) { | |
202 | Analyse(det,ring,sec,strip); | |
a0180e76 | 203 | } |
e9c06036 | 204 | std::cout << '.' << std::flush; |
a0180e76 | 205 | } |
427e8f99 | 206 | if(fSaveHistograms) |
207 | diagFile->Flush(); | |
e9c06036 | 208 | std::cout << "done" << std::endl; |
a0180e76 | 209 | } |
210 | } | |
ce5a8b1a | 211 | |
a0180e76 | 212 | if(fOutputFile.is_open()) { |
a0180e76 | 213 | fOutputFile.write("# EOF\n",6); |
214 | fOutputFile.close(); | |
a0180e76 | 215 | } |
216 | ||
217 | if(fSaveHistograms ) { | |
f7f0b643 | 218 | |
219 | Terminate(diagFile); | |
220 | ||
e9c06036 | 221 | AliInfo("Closing diagnostics file - please wait ..."); |
222 | // diagFile->Write(); | |
ce5a8b1a | 223 | diagFile->Close(); |
e9c06036 | 224 | AliInfo("done"); |
a0180e76 | 225 | } |
226 | } | |
227 | //_____________________________________________________________________ | |
228 | ||
e9c06036 | 229 | void AliFMDBaseDA::InitContainer(TDirectory* diagFile) |
230 | { | |
a0180e76 | 231 | TObjArray* detArray; |
232 | TObjArray* ringArray; | |
233 | TObjArray* sectorArray; | |
234 | ||
e9c06036 | 235 | TDirectory* savDir = gDirectory; |
236 | ||
a0180e76 | 237 | for(UShort_t det=1;det<=3;det++) { |
238 | detArray = new TObjArray(); | |
239 | detArray->SetOwner(); | |
240 | fDetectorArray.AddAtAndExpand(detArray,det); | |
e9c06036 | 241 | |
242 | TDirectory* detDir = 0; | |
243 | if (diagFile) { | |
244 | diagFile->cd(); | |
245 | detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE)); | |
246 | } | |
247 | ||
a0180e76 | 248 | UShort_t FirstRing = (det == 1 ? 1 : 0); |
249 | for (UShort_t ir = FirstRing; ir < 2; ir++) { | |
250 | Char_t ring = (ir == 0 ? 'O' : 'I'); | |
251 | UShort_t nsec = (ir == 0 ? 40 : 20); | |
252 | UShort_t nstr = (ir == 0 ? 256 : 512); | |
253 | ringArray = new TObjArray(); | |
254 | ringArray->SetOwner(); | |
255 | detArray->AddAtAndExpand(ringArray,ir); | |
e9c06036 | 256 | |
257 | ||
258 | TDirectory* ringDir = 0; | |
259 | if (detDir) { | |
260 | detDir->cd(); | |
261 | ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE)); | |
262 | } | |
263 | ||
264 | ||
a0180e76 | 265 | for(UShort_t sec =0; sec < nsec; sec++) { |
266 | sectorArray = new TObjArray(); | |
267 | sectorArray->SetOwner(); | |
268 | ringArray->AddAtAndExpand(sectorArray,sec); | |
e9c06036 | 269 | |
270 | ||
271 | TDirectory* secDir = 0; | |
272 | if (ringDir) { | |
273 | ringDir->cd(); | |
274 | secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE)); | |
275 | } | |
276 | ||
a0180e76 | 277 | for(UShort_t strip = 0; strip < nstr; strip++) { |
e9c06036 | 278 | if (secDir) { |
279 | secDir->cd(); | |
280 | secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE)); | |
281 | } | |
a0180e76 | 282 | AddChannelContainer(sectorArray, det, ring, sec, strip); |
283 | } | |
284 | } | |
285 | } | |
286 | } | |
e9c06036 | 287 | savDir->cd(); |
a0180e76 | 288 | } |
ce5a8b1a | 289 | |
290 | //_____________________________________________________________________ | |
3effc6e7 | 291 | void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader) |
e9c06036 | 292 | { |
ce5a8b1a | 293 | AliFMDParameters* pars = AliFMDParameters::Instance(); |
294 | fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14); | |
427e8f99 | 295 | |
3effc6e7 | 296 | AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate(); |
297 | AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange(); | |
427e8f99 | 298 | |
3effc6e7 | 299 | fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength); |
ce5a8b1a | 300 | |
3effc6e7 | 301 | // Sample Rate |
302 | /* | |
303 | UShort_t defSampleRate = 4; | |
304 | UShort_t sampleRateFromSOD; | |
305 | ||
1656783c | 306 | AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate(); |
bd727bee | 307 | |
308 | UShort_t firstStrip = 0; | |
309 | UShort_t lastStrip = 127; | |
310 | UShort_t firstStripSOD; | |
311 | UShort_t lastStripSOD; | |
312 | AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange(); | |
313 | ||
314 | for(Int_t det=1;det<=3;det++) { | |
1656783c | 315 | UShort_t FirstRing = (det == 1 ? 1 : 0); |
316 | for (UShort_t ir = FirstRing; ir < 2; ir++) { | |
317 | Char_t ring = (ir == 0 ? 'O' : 'I'); | |
318 | UShort_t nsec = (ir == 0 ? 40 : 20); | |
1656783c | 319 | for(UShort_t sec =0; sec < nsec; sec++) { |
433a88bd | 320 | sampleRateFromSOD = defSampleRate; |
321 | sampleRate->Set(det,ring,sec,0,sampleRateFromSOD); | |
322 | firstStripSOD = firstStrip; | |
323 | lastStripSOD = lastStrip; | |
324 | stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD); | |
bd727bee | 325 | |
1656783c | 326 | } |
327 | } | |
328 | } | |
3effc6e7 | 329 | */ |
bd727bee | 330 | sampleRate->WriteToFile(fConditionsFile); |
433a88bd | 331 | stripRange->WriteToFile(fConditionsFile); |
3effc6e7 | 332 | //pars->SetSampleRate(sampleRate); |
333 | //pars->SetStripRange(stripRange); | |
bd727bee | 334 | |
335 | ||
427e8f99 | 336 | // Zero Suppresion |
337 | ||
338 | // Strip Range | |
339 | ||
29b7c86f | 340 | fConditionsFile.write("# Gain Events \n",15); |
bd727bee | 341 | |
29b7c86f | 342 | for(UShort_t det=1; det<=3;det++) { |
343 | UShort_t firstring = (det == 1 ? 1 : 0); | |
344 | for(UShort_t iring = firstring; iring <=1;iring++) { | |
345 | Char_t ring = (iring == 1 ? 'I' : 'O'); | |
346 | for(UShort_t board =0 ; board <=1; board++) { | |
347 | ||
348 | Int_t idx = GetHalfringIndex(det,ring,board); | |
349 | ||
350 | fConditionsFile << det << ',' | |
351 | << ring << ',' | |
352 | << board << ',' | |
353 | << fPulseLength.At(idx) << "\n"; | |
354 | ||
355 | } | |
356 | } | |
357 | } | |
bd727bee | 358 | |
29b7c86f | 359 | fConditionsFile.write("# Gain Pulse \n",14); |
bd727bee | 360 | |
29b7c86f | 361 | for(UShort_t det=1; det<=3;det++) { |
362 | UShort_t firstring = (det == 1 ? 1 : 0); | |
363 | for(UShort_t iring = firstring; iring <=1;iring++) { | |
364 | Char_t ring = (iring == 1 ? 'I' : 'O'); | |
365 | for(UShort_t board =0 ; board <=1; board++) { | |
366 | ||
367 | Int_t idx = GetHalfringIndex(det,ring,board); | |
368 | ||
369 | fConditionsFile << det << ',' | |
370 | << ring << ',' | |
371 | << board << ',' | |
372 | << fPulseSize.At(idx) << "\n"; | |
373 | ||
374 | } | |
375 | } | |
376 | } | |
377 | ||
378 | ||
379 | ||
427e8f99 | 380 | // Gain Relevant stuff |
3effc6e7 | 381 | /* |
427e8f99 | 382 | UShort_t defPulseSize = 32 ; |
383 | UShort_t defPulseLength = 100 ; | |
384 | UShort_t pulseSizeFromSOD; | |
385 | UShort_t pulseLengthFromSOD; | |
386 | ||
387 | fPulseSize.Reset(defPulseSize); | |
388 | fPulseLength.Reset(defPulseLength); | |
389 | ||
390 | for(UShort_t det=1;det<=3;det++) | |
391 | for(UShort_t iring=0;iring<=1;iring++) | |
392 | for(UShort_t board=0;board<=1;board++) { | |
393 | pulseSizeFromSOD = defPulseSize; | |
394 | pulseLengthFromSOD = defPulseLength; | |
395 | ||
396 | fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board)); | |
397 | fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board)); | |
398 | } | |
399 | ||
400 | ||
401 | // fConditionsFile << defSampleRate << ',' | |
402 | // << timebins <<"\n"; | |
3effc6e7 | 403 | */ |
1656783c | 404 | if(fConditionsFile.is_open()) { |
ce5a8b1a | 405 | |
427e8f99 | 406 | fConditionsFile.write("# EOF\n",6); |
1656783c | 407 | fConditionsFile.close(); |
408 | ||
409 | } | |
ce5a8b1a | 410 | |
411 | } | |
427e8f99 | 412 | //_____________________________________________________________________ |
413 | Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) { | |
414 | ||
415 | UShort_t iring = (ring == 'I' ? 1 : 0); | |
416 | ||
417 | Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0)); | |
418 | ||
29b7c86f | 419 | return index-2; |
427e8f99 | 420 | |
421 | } | |
422 | ||
ce5a8b1a | 423 | |
a0180e76 | 424 | //_____________________________________________________________________ |
425 | // | |
426 | // EOF | |
427 | // |