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 fDetectorArray.SetOwner();
100 fConditionsFile.open("conditions.csv");
102 //_____________________________________________________________________
103 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
105 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
108 fSaveHistograms(baseDA.fSaveHistograms),
109 fDetectorArray(baseDA.fDetectorArray),
110 fPulseSize(baseDA.fPulseSize),
111 fPulseLength(baseDA.fPulseLength),
112 fRequiredEvents(baseDA.fRequiredEvents),
113 fCurrentEvent(baseDA.fCurrentEvent)
115 fDetectorArray.SetOwner();
120 //_____________________________________________________________________
121 AliFMDBaseDA::~AliFMDBaseDA()
126 //_____________________________________________________________________
127 void AliFMDBaseDA::Run(AliRawReader* reader)
131 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
139 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
140 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
142 Bool_t SOD_read = kFALSE;
144 for(Int_t i=0;i<3;i++) {
145 reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
147 UInt_t eventType = reader->GetType();
148 if(eventType == AliRawEventHeaderBase::kStartOfData ||
149 eventType == AliRawEventHeaderBase::kFormatError) {
151 WriteConditionsData(fmdReader);
158 InitContainer(diagFile);
161 AliWarning("No SOD event detected!");
163 int lastProgress = 0;
167 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
168 if(!reader->NextEvent()) continue;
171 fmdReader->ReadAdcs(digitArray);
173 //std::cout<<"in event "<<*(reader->GetEventId())<<" "<<n<<std::endl;
174 //AliDebug(5, Form("In event # %d with %d entries",
175 // *(reader->GetEventId()), digitArray->GetEntriesFast()));
177 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
178 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
185 int progress = int((n *100)/ GetRequiredEvents()) ;
186 if (progress <= lastProgress) continue;
187 lastProgress = progress;
188 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
192 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
195 for(UShort_t det=1;det<=3;det++) {
196 std::cout << "FMD" << det << std::endl;
197 UShort_t FirstRing = (det == 1 ? 1 : 0);
198 for (UShort_t ir = FirstRing; ir < 2; ir++) {
199 Char_t ring = (ir == 0 ? 'O' : 'I');
200 UShort_t nsec = (ir == 0 ? 40 : 20);
201 UShort_t nstr = (ir == 0 ? 256 : 512);
202 std::cout << " Ring " << ring << ": " << std::flush;
203 for(UShort_t sec =0; sec < nsec; sec++) {
204 for(UShort_t strip = 0; strip < nstr; strip++) {
205 Analyse(det,ring,sec,strip);
207 std::cout << '.' << std::flush;
211 std::cout << "done" << std::endl;
215 if(fOutputFile.is_open()) {
216 fOutputFile.write("# EOF\n",6);
222 if(fSaveHistograms ) {
224 AliInfo("Closing diagnostics file - please wait ...");
225 // diagFile->Write();
231 //_____________________________________________________________________
233 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
236 TObjArray* ringArray;
237 TObjArray* sectorArray;
239 TDirectory* savDir = gDirectory;
241 for(UShort_t det=1;det<=3;det++) {
242 detArray = new TObjArray();
243 detArray->SetOwner();
244 fDetectorArray.AddAtAndExpand(detArray,det);
246 TDirectory* detDir = 0;
249 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
252 UShort_t FirstRing = (det == 1 ? 1 : 0);
253 for (UShort_t ir = FirstRing; ir < 2; ir++) {
254 Char_t ring = (ir == 0 ? 'O' : 'I');
255 UShort_t nsec = (ir == 0 ? 40 : 20);
256 UShort_t nstr = (ir == 0 ? 256 : 512);
257 ringArray = new TObjArray();
258 ringArray->SetOwner();
259 detArray->AddAtAndExpand(ringArray,ir);
262 TDirectory* ringDir = 0;
265 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
269 for(UShort_t sec =0; sec < nsec; sec++) {
270 sectorArray = new TObjArray();
271 sectorArray->SetOwner();
272 ringArray->AddAtAndExpand(sectorArray,sec);
275 TDirectory* secDir = 0;
278 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
281 for(UShort_t strip = 0; strip < nstr; strip++) {
284 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
286 AddChannelContainer(sectorArray, det, ring, sec, strip);
294 //_____________________________________________________________________
295 void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
297 AliFMDParameters* pars = AliFMDParameters::Instance();
298 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
300 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
301 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
303 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength);
307 UShort_t defSampleRate = 4;
308 UShort_t sampleRateFromSOD;
310 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
312 UShort_t firstStrip = 0;
313 UShort_t lastStrip = 127;
314 UShort_t firstStripSOD;
315 UShort_t lastStripSOD;
316 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
318 for(Int_t det=1;det<=3;det++) {
319 UShort_t FirstRing = (det == 1 ? 1 : 0);
320 for (UShort_t ir = FirstRing; ir < 2; ir++) {
321 Char_t ring = (ir == 0 ? 'O' : 'I');
322 UShort_t nsec = (ir == 0 ? 40 : 20);
323 for(UShort_t sec =0; sec < nsec; sec++) {
324 sampleRateFromSOD = defSampleRate;
325 sampleRate->Set(det,ring,sec,0,sampleRateFromSOD);
326 firstStripSOD = firstStrip;
327 lastStripSOD = lastStrip;
328 stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD);
334 sampleRate->WriteToFile(fConditionsFile);
335 stripRange->WriteToFile(fConditionsFile);
336 //pars->SetSampleRate(sampleRate);
337 //pars->SetStripRange(stripRange);
344 fConditionsFile.write("# Gain Events \n",15);
346 for(UShort_t det=1; det<=3;det++) {
347 UShort_t firstring = (det == 1 ? 1 : 0);
348 for(UShort_t iring = firstring; iring <=1;iring++) {
349 Char_t ring = (iring == 1 ? 'I' : 'O');
350 for(UShort_t board =0 ; board <=1; board++) {
352 Int_t idx = GetHalfringIndex(det,ring,board);
354 fConditionsFile << det << ','
357 << fPulseLength.At(idx) << "\n";
363 fConditionsFile.write("# Gain Pulse \n",14);
365 for(UShort_t det=1; det<=3;det++) {
366 UShort_t firstring = (det == 1 ? 1 : 0);
367 for(UShort_t iring = firstring; iring <=1;iring++) {
368 Char_t ring = (iring == 1 ? 'I' : 'O');
369 for(UShort_t board =0 ; board <=1; board++) {
371 Int_t idx = GetHalfringIndex(det,ring,board);
373 fConditionsFile << det << ','
376 << fPulseSize.At(idx) << "\n";
384 // Gain Relevant stuff
386 UShort_t defPulseSize = 32 ;
387 UShort_t defPulseLength = 100 ;
388 UShort_t pulseSizeFromSOD;
389 UShort_t pulseLengthFromSOD;
391 fPulseSize.Reset(defPulseSize);
392 fPulseLength.Reset(defPulseLength);
394 for(UShort_t det=1;det<=3;det++)
395 for(UShort_t iring=0;iring<=1;iring++)
396 for(UShort_t board=0;board<=1;board++) {
397 pulseSizeFromSOD = defPulseSize;
398 pulseLengthFromSOD = defPulseLength;
400 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
401 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
405 // fConditionsFile << defSampleRate << ','
406 // << timebins <<"\n";
408 if(fConditionsFile.is_open()) {
410 fConditionsFile.write("# EOF\n",6);
411 fConditionsFile.close();
416 //_____________________________________________________________________
417 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
419 UShort_t iring = (ring == 'I' ? 1 : 0);
421 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
428 //_____________________________________________________________________