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