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"
35 //_____________________________________________________________________
36 ClassImp(AliFMDBaseDA)
38 ; // Do not delete - to let Emacs for mat the code
41 //_____________________________________________________________________
43 AliFMDBaseDA::GetStripPath(UShort_t det,
49 return Form("%s%sFMD%d%c[%02d,%03d]",
50 (full ? GetSectorPath(det, ring, sec, full) : ""),
51 (full ? "/" : ""), det, ring, sec, str);
53 //_____________________________________________________________________
55 AliFMDBaseDA::GetSectorPath(UShort_t det,
60 return Form("%s%sFMD%d%c[%02d]",
61 (full ? GetRingPath(det, ring, full) : ""),
62 (full ? "/" : ""), det, ring, sec);
64 //_____________________________________________________________________
66 AliFMDBaseDA::GetRingPath(UShort_t det,
70 return Form("%s%sFMD%d%c",
71 (full ? GetDetectorPath(det, full) : ""),
72 (full ? "/" : ""), det, ring);
74 //_____________________________________________________________________
76 AliFMDBaseDA::GetDetectorPath(UShort_t det,
79 return Form("%s%sFMD%d",
80 (full ? fDiagnosticsFilename.Data() : ""),
81 (full ? ":/" : ""), det);
84 //_____________________________________________________________________
85 AliFMDBaseDA::AliFMDBaseDA() :
87 fDiagnosticsFilename("diagnosticsHistograms.root"),
90 fSaveHistograms(kFALSE),
97 fDetectorArray.SetOwner();
98 fConditionsFile.open("conditions.csv");
100 //_____________________________________________________________________
101 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
103 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
106 fSaveHistograms(baseDA.fSaveHistograms),
107 fDetectorArray(baseDA.fDetectorArray),
108 fPulseSize(baseDA.fPulseSize),
109 fPulseLength(baseDA.fPulseLength),
110 fRequiredEvents(baseDA.fRequiredEvents),
111 fCurrentEvent(baseDA.fCurrentEvent)
113 fDetectorArray.SetOwner();
118 //_____________________________________________________________________
119 AliFMDBaseDA::~AliFMDBaseDA()
124 //_____________________________________________________________________
125 void AliFMDBaseDA::Run(AliRawReader* reader)
129 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
132 WriteConditionsData();
134 InitContainer(diagFile);
140 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
141 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
143 reader->NextEvent(); // Read Start-of-Run event
144 reader->NextEvent(); // Read Start-of-Files event
145 int lastProgress = 0;
147 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
148 if(!reader->NextEvent()) continue;
150 SetCurrentEvent(*(reader->GetEventId()));
153 fmdReader->ReadAdcs(digitArray);
155 AliDebug(5, Form("In event # %d with %d entries",
156 *(reader->GetEventId()), digitArray->GetEntriesFast()));
158 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
159 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
164 int progress = int((n *100)/ GetRequiredEvents()) ;
165 if (progress <= lastProgress) continue;
166 lastProgress = progress;
167 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
170 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
173 for(UShort_t det=1;det<=3;det++) {
174 std::cout << "FMD" << det << std::endl;
175 UShort_t FirstRing = (det == 1 ? 1 : 0);
176 for (UShort_t ir = FirstRing; ir < 2; ir++) {
177 Char_t ring = (ir == 0 ? 'O' : 'I');
178 UShort_t nsec = (ir == 0 ? 40 : 20);
179 UShort_t nstr = (ir == 0 ? 256 : 512);
180 std::cout << " Ring " << ring << ": " << std::flush;
181 for(UShort_t sec =0; sec < nsec; sec++) {
182 for(UShort_t strip = 0; strip < nstr; strip++) {
183 Analyse(det,ring,sec,strip);
185 std::cout << '.' << std::flush;
189 std::cout << "done" << std::endl;
193 if(fOutputFile.is_open()) {
194 fOutputFile.write("# EOF\n",6);
198 if(fSaveHistograms ) {
199 AliInfo("Closing diagnostics file - please wait ...");
200 // diagFile->Write();
205 //_____________________________________________________________________
207 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
210 TObjArray* ringArray;
211 TObjArray* sectorArray;
213 TDirectory* savDir = gDirectory;
215 for(UShort_t det=1;det<=3;det++) {
216 detArray = new TObjArray();
217 detArray->SetOwner();
218 fDetectorArray.AddAtAndExpand(detArray,det);
220 TDirectory* detDir = 0;
223 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
226 UShort_t FirstRing = (det == 1 ? 1 : 0);
227 for (UShort_t ir = FirstRing; ir < 2; ir++) {
228 Char_t ring = (ir == 0 ? 'O' : 'I');
229 UShort_t nsec = (ir == 0 ? 40 : 20);
230 UShort_t nstr = (ir == 0 ? 256 : 512);
231 ringArray = new TObjArray();
232 ringArray->SetOwner();
233 detArray->AddAtAndExpand(ringArray,ir);
236 TDirectory* ringDir = 0;
239 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
243 for(UShort_t sec =0; sec < nsec; sec++) {
244 sectorArray = new TObjArray();
245 sectorArray->SetOwner();
246 ringArray->AddAtAndExpand(sectorArray,sec);
249 TDirectory* secDir = 0;
252 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
255 for(UShort_t strip = 0; strip < nstr; strip++) {
258 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
260 AddChannelContainer(sectorArray, det, ring, sec, strip);
268 //_____________________________________________________________________
269 void AliFMDBaseDA::WriteConditionsData()
271 AliFMDParameters* pars = AliFMDParameters::Instance();
272 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
274 // fConditionsFile.write("# Sample Rate, timebins \n",25);
278 UInt_t defSampleRate = 4;
279 UInt_t sampleRateFromSOD;
280 //UInt_t timebins = 544;
281 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
282 for(UShort_t det=1;det<=3;det++) {
283 UShort_t FirstRing = (det == 1 ? 1 : 0);
284 for (UShort_t ir = FirstRing; ir < 2; ir++) {
285 Char_t ring = (ir == 0 ? 'O' : 'I');
286 UShort_t nsec = (ir == 0 ? 40 : 20);
287 UShort_t nstr = (ir == 0 ? 256 : 512);
288 for(UShort_t sec =0; sec < nsec; sec++) {
289 for(UShort_t strip = 0; strip < nstr; strip++) {
290 sampleRateFromSOD = defSampleRate;
291 sampleRate->Set(det,ring,sec,strip,sampleRateFromSOD);
292 fConditionsFile << det << ','
296 << "samplerate" << ','
297 << sampleRateFromSOD << "\n";
303 pars->SetSampleRate(sampleRate);
309 // Gain Relevant stuff
311 UShort_t defPulseSize = 32 ;
312 UShort_t defPulseLength = 100 ;
313 UShort_t pulseSizeFromSOD;
314 UShort_t pulseLengthFromSOD;
316 fPulseSize.Reset(defPulseSize);
317 fPulseLength.Reset(defPulseLength);
319 for(UShort_t det=1;det<=3;det++)
320 for(UShort_t iring=0;iring<=1;iring++)
321 for(UShort_t board=0;board<=1;board++) {
322 pulseSizeFromSOD = defPulseSize;
323 pulseLengthFromSOD = defPulseLength;
325 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
326 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
330 // fConditionsFile << defSampleRate << ','
331 // << timebins <<"\n";
333 if(fConditionsFile.is_open()) {
335 fConditionsFile.write("# EOF\n",6);
336 fConditionsFile.close();
341 //_____________________________________________________________________
342 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
344 UShort_t iring = (ring == 'I' ? 1 : 0);
346 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
353 //_____________________________________________________________________