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),
100 fSeenDetectors[0] = fSeenDetectors[1] = fSeenDetectors[2] = kFALSE;
101 fDetectorArray.SetOwner();
102 fConditionsFile.open("conditions.csv");
104 //_____________________________________________________________________
105 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
107 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
110 fSaveHistograms(baseDA.fSaveHistograms),
111 fDetectorArray(baseDA.fDetectorArray),
112 fPulseSize(baseDA.fPulseSize),
113 fPulseLength(baseDA.fPulseLength),
114 fRequiredEvents(baseDA.fRequiredEvents),
115 fCurrentEvent(baseDA.fCurrentEvent)
118 fSeenDetectors[0] = baseDA.fSeenDetectors[0];
119 fSeenDetectors[1] = baseDA.fSeenDetectors[1];
120 fSeenDetectors[2] = baseDA.fSeenDetectors[2];
122 fDetectorArray.SetOwner();
127 //_____________________________________________________________________
128 AliFMDBaseDA::~AliFMDBaseDA()
133 //_____________________________________________________________________
134 void AliFMDBaseDA::Run(AliRawReader* reader)
139 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
147 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
148 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
150 Bool_t sodread = kFALSE;
152 for(Int_t i=0;i<3;i++) {
153 reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
155 UInt_t eventType = reader->GetType();
156 if(eventType == AliRawEventHeaderBase::kStartOfData ||
157 eventType == AliRawEventHeaderBase::kFormatError) {
159 WriteConditionsData(fmdReader);
166 InitContainer(diagFile);
169 AliWarning("No SOD event detected!");
171 int lastProgress = 0;
175 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
176 if(!reader->NextEvent()) continue;
179 fmdReader->ReadAdcs(digitArray);
181 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
182 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
183 fSeenDetectors[digit->Detector()-1] = kTRUE;
190 int progress = int((n *100)/ GetRequiredEvents()) ;
191 if (progress <= lastProgress) continue;
192 lastProgress = progress;
193 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
197 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
200 for(UShort_t det=1;det<=3;det++) {
201 if (!fSeenDetectors[det-1]) continue;
202 std::cout << "FMD" << det << std::endl;
203 UShort_t firstRing = (det == 1 ? 1 : 0);
204 for (UShort_t ir = firstRing; ir < 2; ir++) {
205 Char_t ring = (ir == 0 ? 'O' : 'I');
206 UShort_t nsec = (ir == 0 ? 40 : 20);
207 UShort_t nstr = (ir == 0 ? 256 : 512);
208 std::cout << " Ring " << ring << ": " << std::flush;
209 for(UShort_t sec =0; sec < nsec; sec++) {
210 for(UShort_t strip = 0; strip < nstr; strip++) {
211 Analyse(det,ring,sec,strip);
213 std::cout << '.' << std::flush;
217 std::cout << "done" << std::endl;
221 if(fOutputFile.is_open()) {
222 fOutputFile.write("# EOF\n",6);
228 if(fSaveHistograms ) {
230 AliInfo("Closing diagnostics file - please wait ...");
231 // diagFile->Write();
237 //_____________________________________________________________________
239 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
241 //Prepare container for diagnostics
243 TObjArray* ringArray;
244 TObjArray* sectorArray;
246 TDirectory* savDir = gDirectory;
248 for(UShort_t det=1;det<=3;det++) {
249 detArray = new TObjArray();
250 detArray->SetOwner();
251 fDetectorArray.AddAtAndExpand(detArray,det);
253 TDirectory* detDir = 0;
256 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
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);
269 TDirectory* ringDir = 0;
272 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
276 for(UShort_t sec =0; sec < nsec; sec++) {
277 sectorArray = new TObjArray();
278 sectorArray->SetOwner();
279 ringArray->AddAtAndExpand(sectorArray,sec);
282 TDirectory* secDir = 0;
285 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
288 for(UShort_t strip = 0; strip < nstr; strip++) {
291 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
293 AddChannelContainer(sectorArray, det, ring, sec, strip);
301 //_____________________________________________________________________
302 void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
304 //Write the conditions data to file
305 AliFMDParameters* pars = AliFMDParameters::Instance();
306 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
308 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
309 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
311 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
314 sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
315 stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
322 fConditionsFile.write("# Gain Events \n",15);
324 for(UShort_t det=1; det<=3;det++) {
325 if (!fSeenDetectors[det-1]) {
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++) {
333 Int_t idx = GetHalfringIndex(det,ring,board);
335 fConditionsFile << det << ','
338 << fPulseLength.At(idx) << "\n";
344 fConditionsFile.write("# Gain Pulse \n",14);
346 for(UShort_t det=1; det<=3;det++) {
347 if (!fSeenDetectors[det-1]) {
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++) {
355 Int_t idx = GetHalfringIndex(det,ring,board);
357 fConditionsFile << det << ','
360 << fPulseSize.At(idx) << "\n";
365 if(fConditionsFile.is_open()) {
367 fConditionsFile.write("# EOF\n",6);
368 fConditionsFile.close();
373 //_____________________________________________________________________
374 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const {
376 UShort_t iring = (ring == 'I' ? 1 : 0);
378 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
385 //_____________________________________________________________________