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