Put LOGY in the histograms DrawOptions - so that AMORE will show these
[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"
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//_____________________________________________________________________
38ClassImp(AliFMDBaseDA)
e9c06036 39#if 0
40; // Do not delete - to let Emacs for mat the code
41#endif
42
43//_____________________________________________________________________
44const char*
45AliFMDBaseDA::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//_____________________________________________________________________
56const char*
57AliFMDBaseDA::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//_____________________________________________________________________
67const char*
68AliFMDBaseDA::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//_____________________________________________________________________
77const char*
78AliFMDBaseDA::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 87AliFMDBaseDA::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)
c5569fbc 98{
99 //Constructor
408bf2b4 100 fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE;
a0180e76 101 fDetectorArray.SetOwner();
ce5a8b1a 102 fConditionsFile.open("conditions.csv");
a0180e76 103}
104//_____________________________________________________________________
105AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
106 TNamed(baseDA),
a7e41e8d 107 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
a0180e76 108 fOutputFile(),
ce5a8b1a 109 fConditionsFile(),
a0180e76 110 fSaveHistograms(baseDA.fSaveHistograms),
111 fDetectorArray(baseDA.fDetectorArray),
427e8f99 112 fPulseSize(baseDA.fPulseSize),
113 fPulseLength(baseDA.fPulseLength),
a0180e76 114 fRequiredEvents(baseDA.fRequiredEvents),
115 fCurrentEvent(baseDA.fCurrentEvent)
116{
c5569fbc 117 //Copy constructor
408bf2b4 118 fSeenDetectors[0] = baseDA.fSeenDetectors[0];
119 fSeenDetectors[1] = baseDA.fSeenDetectors[1];
120 fSeenDetectors[2] = baseDA.fSeenDetectors[2];
121
a0180e76 122 fDetectorArray.SetOwner();
123
124}
125
82d71828 126
a0180e76 127//_____________________________________________________________________
e9c06036 128AliFMDBaseDA::~AliFMDBaseDA()
129{
a0180e76 130 //destructor
a0180e76 131}
132
133//_____________________________________________________________________
e9c06036 134void AliFMDBaseDA::Run(AliRawReader* reader)
135{
c5569fbc 136 //Run the FMD DA
e9c06036 137 TFile* diagFile = 0;
138 if (fSaveHistograms)
139 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
a0180e76 140
427e8f99 141
3effc6e7 142
427e8f99 143
7bce699b 144
a0180e76 145 reader->Reset();
ce5a8b1a 146
e9c06036 147 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
148 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
3effc6e7 149
c5569fbc 150 Bool_t sodread = kFALSE;
200d06f9 151
152 for(Int_t i=0;i<3;i++) {
153 reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
29b7c86f 154
200d06f9 155 UInt_t eventType = reader->GetType();
156 if(eventType == AliRawEventHeaderBase::kStartOfData ||
157 eventType == AliRawEventHeaderBase::kFormatError) {
158
159 WriteConditionsData(fmdReader);
160 Init();
c5569fbc 161 sodread = kTRUE;
200d06f9 162 break;
163 }
29b7c86f 164 }
200d06f9 165
7bce699b 166 InitContainer(diagFile);
167
c5569fbc 168 if(!sodread)
29b7c86f 169 AliWarning("No SOD event detected!");
3effc6e7 170
1656783c 171 int lastProgress = 0;
a0180e76 172
7bce699b 173
174
e9c06036 175 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
176 if(!reader->NextEvent()) continue;
3effc6e7 177 SetCurrentEvent(n);
e9c06036 178 digitArray->Clear();
179 fmdReader->ReadAdcs(digitArray);
7bce699b 180
e9c06036 181 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
182 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
408bf2b4 183 fSeenDetectors[digit->Detector()-1] = kTRUE;
e9c06036 184 FillChannels(digit);
a0180e76 185 }
e9c06036 186
7bce699b 187
e9c06036 188 FinishEvent();
7bce699b 189
e9c06036 190 int progress = int((n *100)/ GetRequiredEvents()) ;
191 if (progress <= lastProgress) continue;
192 lastProgress = progress;
193 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
7bce699b 194
e9c06036 195 }
7bce699b 196
a0180e76 197 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
198 WriteHeaderToFile();
199
200 for(UShort_t det=1;det<=3;det++) {
408bf2b4 201 if (!fSeenDetectors[det-1]) continue;
e9c06036 202 std::cout << "FMD" << det << std::endl;
c5569fbc 203 UShort_t firstRing = (det == 1 ? 1 : 0);
204 for (UShort_t ir = firstRing; ir < 2; ir++) {
a0180e76 205 Char_t ring = (ir == 0 ? 'O' : 'I');
206 UShort_t nsec = (ir == 0 ? 40 : 20);
207 UShort_t nstr = (ir == 0 ? 256 : 512);
e9c06036 208 std::cout << " Ring " << ring << ": " << std::flush;
a0180e76 209 for(UShort_t sec =0; sec < nsec; sec++) {
210 for(UShort_t strip = 0; strip < nstr; strip++) {
211 Analyse(det,ring,sec,strip);
a0180e76 212 }
e9c06036 213 std::cout << '.' << std::flush;
a0180e76 214 }
427e8f99 215 if(fSaveHistograms)
7bce699b 216 diagFile->Flush();
e9c06036 217 std::cout << "done" << std::endl;
a0180e76 218 }
219 }
7bce699b 220
a0180e76 221 if(fOutputFile.is_open()) {
a0180e76 222 fOutputFile.write("# EOF\n",6);
223 fOutputFile.close();
a0180e76 224 }
225
7bce699b 226 Terminate(diagFile);
227
a0180e76 228 if(fSaveHistograms ) {
f7f0b643 229
e9c06036 230 AliInfo("Closing diagnostics file - please wait ...");
231 // diagFile->Write();
ce5a8b1a 232 diagFile->Close();
e9c06036 233 AliInfo("done");
7bce699b 234
a0180e76 235 }
236}
237//_____________________________________________________________________
238
e9c06036 239void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
240{
c5569fbc 241 //Prepare container for diagnostics
a0180e76 242 TObjArray* detArray;
243 TObjArray* ringArray;
244 TObjArray* sectorArray;
245
e9c06036 246 TDirectory* savDir = gDirectory;
247
a0180e76 248 for(UShort_t det=1;det<=3;det++) {
249 detArray = new TObjArray();
250 detArray->SetOwner();
251 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 252
253 TDirectory* detDir = 0;
254 if (diagFile) {
255 diagFile->cd();
256 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
257 }
258
a0180e76 259 UShort_t FirstRing = (det == 1 ? 1 : 0);
260 for (UShort_t ir = FirstRing; ir < 2; ir++) {
261 Char_t ring = (ir == 0 ? 'O' : 'I');
262 UShort_t nsec = (ir == 0 ? 40 : 20);
263 UShort_t nstr = (ir == 0 ? 256 : 512);
264 ringArray = new TObjArray();
265 ringArray->SetOwner();
266 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 267
268
269 TDirectory* ringDir = 0;
270 if (detDir) {
271 detDir->cd();
272 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
273 }
274
275
a0180e76 276 for(UShort_t sec =0; sec < nsec; sec++) {
277 sectorArray = new TObjArray();
278 sectorArray->SetOwner();
279 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 280
281
282 TDirectory* secDir = 0;
283 if (ringDir) {
284 ringDir->cd();
285 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
286 }
287
a0180e76 288 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 289 if (secDir) {
290 secDir->cd();
291 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
292 }
a0180e76 293 AddChannelContainer(sectorArray, det, ring, sec, strip);
294 }
295 }
296 }
297 }
e9c06036 298 savDir->cd();
a0180e76 299}
ce5a8b1a 300
301//_____________________________________________________________________
3effc6e7 302void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
e9c06036 303{
c5569fbc 304 //Write the conditions data to file
ce5a8b1a 305 AliFMDParameters* pars = AliFMDParameters::Instance();
306 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
427e8f99 307
3effc6e7 308 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
309 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
427e8f99 310
408bf2b4 311 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
312 fSeenDetectors);
bd727bee 313
408bf2b4 314 sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
315 stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
bd727bee 316
317
427e8f99 318 // Zero Suppresion
319
320 // Strip Range
321
29b7c86f 322 fConditionsFile.write("# Gain Events \n",15);
bd727bee 323
29b7c86f 324 for(UShort_t det=1; det<=3;det++) {
408bf2b4 325 if (!fSeenDetectors[det-1]) {
326 continue;
327 }
29b7c86f 328 UShort_t firstring = (det == 1 ? 1 : 0);
329 for(UShort_t iring = firstring; iring <=1;iring++) {
330 Char_t ring = (iring == 1 ? 'I' : 'O');
331 for(UShort_t board =0 ; board <=1; board++) {
332
333 Int_t idx = GetHalfringIndex(det,ring,board);
334
335 fConditionsFile << det << ','
336 << ring << ','
337 << board << ','
338 << fPulseLength.At(idx) << "\n";
339
340 }
341 }
342 }
bd727bee 343
29b7c86f 344 fConditionsFile.write("# Gain Pulse \n",14);
bd727bee 345
29b7c86f 346 for(UShort_t det=1; det<=3;det++) {
408bf2b4 347 if (!fSeenDetectors[det-1]) {
348 continue;
349 }
29b7c86f 350 UShort_t firstring = (det == 1 ? 1 : 0);
351 for(UShort_t iring = firstring; iring <=1;iring++) {
352 Char_t ring = (iring == 1 ? 'I' : 'O');
353 for(UShort_t board =0 ; board <=1; board++) {
354
355 Int_t idx = GetHalfringIndex(det,ring,board);
356
357 fConditionsFile << det << ','
358 << ring << ','
359 << board << ','
360 << fPulseSize.At(idx) << "\n";
361
362 }
363 }
364 }
1656783c 365 if(fConditionsFile.is_open()) {
ce5a8b1a 366
427e8f99 367 fConditionsFile.write("# EOF\n",6);
1656783c 368 fConditionsFile.close();
369
370 }
ce5a8b1a 371
372}
427e8f99 373//_____________________________________________________________________
c5569fbc 374Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const {
427e8f99 375
376 UShort_t iring = (ring == 'I' ? 1 : 0);
377
378 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
379
29b7c86f 380 return index-2;
427e8f99 381
382}
383
ce5a8b1a 384
a0180e76 385//_____________________________________________________________________
386//
387// EOF
388//