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"
32 #include "AliFMDRawReader.h"
33 #include "AliFMDCalibSampleRate.h"
34 #include "AliFMDCalibStripRange.h"
36 //_____________________________________________________________________
37 ClassImp(AliFMDBaseDA)
39 ; // Do not delete - to let Emacs for mat the code
42 //_____________________________________________________________________
44 AliFMDBaseDA::GetStripPath(UShort_t det,
50 return Form("%s%sFMD%d%c[%02d,%03d]",
51 (full ? GetSectorPath(det, ring, sec, full) : ""),
52 (full ? "/" : ""), det, ring, sec, str);
54 //_____________________________________________________________________
56 AliFMDBaseDA::GetSectorPath(UShort_t det,
61 return Form("%s%sFMD%d%c[%02d]",
62 (full ? GetRingPath(det, ring, full) : ""),
63 (full ? "/" : ""), det, ring, sec);
65 //_____________________________________________________________________
67 AliFMDBaseDA::GetRingPath(UShort_t det,
71 return Form("%s%sFMD%d%c",
72 (full ? GetDetectorPath(det, full) : ""),
73 (full ? "/" : ""), det, ring);
75 //_____________________________________________________________________
77 AliFMDBaseDA::GetDetectorPath(UShort_t det,
80 return Form("%s%sFMD%d",
81 (full ? fDiagnosticsFilename.Data() : ""),
82 (full ? ":/" : ""), det);
85 //_____________________________________________________________________
86 AliFMDBaseDA::AliFMDBaseDA() :
88 fDiagnosticsFilename("diagnosticsHistograms.root"),
91 fSaveHistograms(kFALSE),
98 fDetectorArray.SetOwner();
99 fConditionsFile.open("conditions.csv");
101 //_____________________________________________________________________
102 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
104 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
107 fSaveHistograms(baseDA.fSaveHistograms),
108 fDetectorArray(baseDA.fDetectorArray),
109 fPulseSize(baseDA.fPulseSize),
110 fPulseLength(baseDA.fPulseLength),
111 fRequiredEvents(baseDA.fRequiredEvents),
112 fCurrentEvent(baseDA.fCurrentEvent)
114 fDetectorArray.SetOwner();
119 //_____________________________________________________________________
120 AliFMDBaseDA::~AliFMDBaseDA()
125 //_____________________________________________________________________
126 void AliFMDBaseDA::Run(AliRawReader* reader)
130 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
133 WriteConditionsData();
135 InitContainer(diagFile);
141 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
142 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
144 reader->NextEvent(); // Read Start-of-Run event
145 reader->NextEvent(); // Read Start-of-Files event
146 int lastProgress = 0;
148 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
149 if(!reader->NextEvent()) continue;
151 SetCurrentEvent(*(reader->GetEventId()));
154 fmdReader->ReadAdcs(digitArray);
156 AliDebug(5, Form("In event # %d with %d entries",
157 *(reader->GetEventId()), digitArray->GetEntriesFast()));
159 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
160 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
165 int progress = int((n *100)/ GetRequiredEvents()) ;
166 if (progress <= lastProgress) continue;
167 lastProgress = progress;
168 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
171 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
174 for(UShort_t det=1;det<=3;det++) {
175 std::cout << "FMD" << det << std::endl;
176 UShort_t FirstRing = (det == 1 ? 1 : 0);
177 for (UShort_t ir = FirstRing; ir < 2; ir++) {
178 Char_t ring = (ir == 0 ? 'O' : 'I');
179 UShort_t nsec = (ir == 0 ? 40 : 20);
180 UShort_t nstr = (ir == 0 ? 256 : 512);
181 std::cout << " Ring " << ring << ": " << std::flush;
182 for(UShort_t sec =0; sec < nsec; sec++) {
183 for(UShort_t strip = 0; strip < nstr; strip++) {
184 Analyse(det,ring,sec,strip);
186 std::cout << '.' << std::flush;
190 std::cout << "done" << std::endl;
194 if(fOutputFile.is_open()) {
195 fOutputFile.write("# EOF\n",6);
199 if(fSaveHistograms ) {
203 AliInfo("Closing diagnostics file - please wait ...");
204 // diagFile->Write();
209 //_____________________________________________________________________
211 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
214 TObjArray* ringArray;
215 TObjArray* sectorArray;
217 TDirectory* savDir = gDirectory;
219 for(UShort_t det=1;det<=3;det++) {
220 detArray = new TObjArray();
221 detArray->SetOwner();
222 fDetectorArray.AddAtAndExpand(detArray,det);
224 TDirectory* detDir = 0;
227 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
230 UShort_t FirstRing = (det == 1 ? 1 : 0);
231 for (UShort_t ir = FirstRing; ir < 2; ir++) {
232 Char_t ring = (ir == 0 ? 'O' : 'I');
233 UShort_t nsec = (ir == 0 ? 40 : 20);
234 UShort_t nstr = (ir == 0 ? 256 : 512);
235 ringArray = new TObjArray();
236 ringArray->SetOwner();
237 detArray->AddAtAndExpand(ringArray,ir);
240 TDirectory* ringDir = 0;
243 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
247 for(UShort_t sec =0; sec < nsec; sec++) {
248 sectorArray = new TObjArray();
249 sectorArray->SetOwner();
250 ringArray->AddAtAndExpand(sectorArray,sec);
253 TDirectory* secDir = 0;
256 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
259 for(UShort_t strip = 0; strip < nstr; strip++) {
262 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
264 AddChannelContainer(sectorArray, det, ring, sec, strip);
272 //_____________________________________________________________________
273 void AliFMDBaseDA::WriteConditionsData()
275 AliFMDParameters* pars = AliFMDParameters::Instance();
276 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
278 // fConditionsFile.write("# Sample Rate, timebins \n",25);
282 UShort_t defSampleRate = 4;
283 UShort_t sampleRateFromSOD;
284 //UInt_t timebins = 544;
285 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
287 UShort_t firstStrip = 0;
288 UShort_t lastStrip = 127;
289 UShort_t firstStripSOD;
290 UShort_t lastStripSOD;
291 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
293 for(Int_t det=1;det<=3;det++) {
294 UShort_t FirstRing = (det == 1 ? 1 : 0);
295 for (UShort_t ir = FirstRing; ir < 2; ir++) {
296 Char_t ring = (ir == 0 ? 'O' : 'I');
297 UShort_t nsec = (ir == 0 ? 40 : 20);
298 for(UShort_t sec =0; sec < nsec; sec++) {
299 sampleRateFromSOD = defSampleRate;
300 sampleRate->Set(det,ring,sec,0,sampleRateFromSOD);
301 firstStripSOD = firstStrip;
302 lastStripSOD = lastStrip;
303 stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD);
309 sampleRate->WriteToFile(fConditionsFile);
310 stripRange->WriteToFile(fConditionsFile);
311 pars->SetSampleRate(sampleRate);
312 pars->SetStripRange(stripRange);
323 // Gain Relevant stuff
325 UShort_t defPulseSize = 32 ;
326 UShort_t defPulseLength = 100 ;
327 UShort_t pulseSizeFromSOD;
328 UShort_t pulseLengthFromSOD;
330 fPulseSize.Reset(defPulseSize);
331 fPulseLength.Reset(defPulseLength);
333 for(UShort_t det=1;det<=3;det++)
334 for(UShort_t iring=0;iring<=1;iring++)
335 for(UShort_t board=0;board<=1;board++) {
336 pulseSizeFromSOD = defPulseSize;
337 pulseLengthFromSOD = defPulseLength;
339 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
340 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
344 // fConditionsFile << defSampleRate << ','
345 // << timebins <<"\n";
347 if(fConditionsFile.is_open()) {
349 fConditionsFile.write("# EOF\n",6);
350 fConditionsFile.close();
355 //_____________________________________________________________________
356 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
358 UShort_t iring = (ring == 'I' ? 1 : 0);
360 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
367 //_____________________________________________________________________