1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
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.
29 #include "AliFMDBaseDA.h"
31 #include "AliFMDRawReader.h"
32 #include "AliFMDCalibSampleRate.h"
33 #include "AliFMDCalibStripRange.h"
35 #include "AliRawEventHeaderBase.h"
37 //_____________________________________________________________________
38 ClassImp(AliFMDBaseDA)
40 ; // Do not delete - to let Emacs for mat the code
43 //_____________________________________________________________________
45 AliFMDBaseDA::GetStripPath(UShort_t det,
51 return Form("%s%sFMD%d%c[%02d,%03d]",
52 (full ? GetSectorPath(det, ring, sec, full) : ""),
53 (full ? "/" : ""), det, ring, sec, str);
55 //_____________________________________________________________________
57 AliFMDBaseDA::GetSectorPath(UShort_t det,
62 return Form("%s%sFMD%d%c[%02d]",
63 (full ? GetRingPath(det, ring, full) : ""),
64 (full ? "/" : ""), det, ring, sec);
66 //_____________________________________________________________________
68 AliFMDBaseDA::GetRingPath(UShort_t det,
72 return Form("%s%sFMD%d%c",
73 (full ? GetDetectorPath(det, full) : ""),
74 (full ? "/" : ""), det, ring);
76 //_____________________________________________________________________
78 AliFMDBaseDA::GetDetectorPath(UShort_t det,
81 return Form("%s%sFMD%d",
82 (full ? fDiagnosticsFilename.Data() : ""),
83 (full ? ":/" : ""), det);
86 //_____________________________________________________________________
87 AliFMDBaseDA::AliFMDBaseDA() :
89 fDiagnosticsFilename("diagnosticsHistograms.root"),
92 fSaveHistograms(kFALSE),
99 fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE;
100 fDetectorArray.SetOwner();
101 fConditionsFile.open("conditions.csv");
103 //_____________________________________________________________________
104 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
106 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
109 fSaveHistograms(baseDA.fSaveHistograms),
110 fDetectorArray(baseDA.fDetectorArray),
111 fPulseSize(baseDA.fPulseSize),
112 fPulseLength(baseDA.fPulseLength),
113 fRequiredEvents(baseDA.fRequiredEvents),
114 fCurrentEvent(baseDA.fCurrentEvent)
116 fSeenDetectors[0] = baseDA.fSeenDetectors[0];
117 fSeenDetectors[1] = baseDA.fSeenDetectors[1];
118 fSeenDetectors[2] = baseDA.fSeenDetectors[2];
120 fDetectorArray.SetOwner();
125 //_____________________________________________________________________
126 AliFMDBaseDA::~AliFMDBaseDA()
131 //_____________________________________________________________________
132 void AliFMDBaseDA::Run(AliRawReader* reader)
136 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
144 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
145 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
147 Bool_t SOD_read = kFALSE;
149 for(Int_t i=0;i<3;i++) {
150 reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
152 UInt_t eventType = reader->GetType();
153 if(eventType == AliRawEventHeaderBase::kStartOfData ||
154 eventType == AliRawEventHeaderBase::kFormatError) {
156 WriteConditionsData(fmdReader);
163 InitContainer(diagFile);
166 AliWarning("No SOD event detected!");
168 int lastProgress = 0;
172 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
173 if(!reader->NextEvent()) continue;
176 fmdReader->ReadAdcs(digitArray);
178 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
179 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
180 fSeenDetectors[digit->Detector()-1] = kTRUE;
187 int progress = int((n *100)/ GetRequiredEvents()) ;
188 if (progress <= lastProgress) continue;
189 lastProgress = progress;
190 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
194 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
197 for(UShort_t det=1;det<=3;det++) {
198 if (!fSeenDetectors[det-1]) continue;
199 std::cout << "FMD" << det << std::endl;
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);
205 std::cout << " Ring " << ring << ": " << std::flush;
206 for(UShort_t sec =0; sec < nsec; sec++) {
207 for(UShort_t strip = 0; strip < nstr; strip++) {
208 Analyse(det,ring,sec,strip);
210 std::cout << '.' << std::flush;
214 std::cout << "done" << std::endl;
218 if(fOutputFile.is_open()) {
219 fOutputFile.write("# EOF\n",6);
225 if(fSaveHistograms ) {
227 AliInfo("Closing diagnostics file - please wait ...");
228 // diagFile->Write();
234 //_____________________________________________________________________
236 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
239 TObjArray* ringArray;
240 TObjArray* sectorArray;
242 TDirectory* savDir = gDirectory;
244 for(UShort_t det=1;det<=3;det++) {
245 detArray = new TObjArray();
246 detArray->SetOwner();
247 fDetectorArray.AddAtAndExpand(detArray,det);
249 TDirectory* detDir = 0;
252 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
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);
265 TDirectory* ringDir = 0;
268 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
272 for(UShort_t sec =0; sec < nsec; sec++) {
273 sectorArray = new TObjArray();
274 sectorArray->SetOwner();
275 ringArray->AddAtAndExpand(sectorArray,sec);
278 TDirectory* secDir = 0;
281 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
284 for(UShort_t strip = 0; strip < nstr; strip++) {
287 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
289 AddChannelContainer(sectorArray, det, ring, sec, strip);
297 //_____________________________________________________________________
298 void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
300 AliFMDParameters* pars = AliFMDParameters::Instance();
301 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
303 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
304 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
306 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
309 sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
310 stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
317 fConditionsFile.write("# Gain Events \n",15);
319 for(UShort_t det=1; det<=3;det++) {
320 if (!fSeenDetectors[det-1]) {
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++) {
328 Int_t idx = GetHalfringIndex(det,ring,board);
330 fConditionsFile << det << ','
333 << fPulseLength.At(idx) << "\n";
339 fConditionsFile.write("# Gain Pulse \n",14);
341 for(UShort_t det=1; det<=3;det++) {
342 if (!fSeenDetectors[det-1]) {
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++) {
350 Int_t idx = GetHalfringIndex(det,ring,board);
352 fConditionsFile << det << ','
355 << fPulseSize.At(idx) << "\n";
360 if(fConditionsFile.is_open()) {
362 fConditionsFile.write("# EOF\n",6);
363 fConditionsFile.close();
368 //_____________________________________________________________________
369 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
371 UShort_t iring = (ring == 'I' ? 1 : 0);
373 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
380 //_____________________________________________________________________