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 #include "AliRawEventHeaderBase.h"
38 //_____________________________________________________________________
39 ClassImp(AliFMDBaseDA)
41 ; // Do not delete - to let Emacs for mat the code
44 //_____________________________________________________________________
46 AliFMDBaseDA::GetStripPath(UShort_t det,
52 return Form("%s%sFMD%d%c[%02d,%03d]",
53 (full ? GetSectorPath(det, ring, sec, full) : ""),
54 (full ? "/" : ""), det, ring, sec, str);
56 //_____________________________________________________________________
58 AliFMDBaseDA::GetSectorPath(UShort_t det,
63 return Form("%s%sFMD%d%c[%02d]",
64 (full ? GetRingPath(det, ring, full) : ""),
65 (full ? "/" : ""), det, ring, sec);
67 //_____________________________________________________________________
69 AliFMDBaseDA::GetRingPath(UShort_t det,
73 return Form("%s%sFMD%d%c",
74 (full ? GetDetectorPath(det, full) : ""),
75 (full ? "/" : ""), det, ring);
77 //_____________________________________________________________________
79 AliFMDBaseDA::GetDetectorPath(UShort_t det,
82 return Form("%s%sFMD%d",
83 (full ? fDiagnosticsFilename.Data() : ""),
84 (full ? ":/" : ""), det);
87 //_____________________________________________________________________
88 AliFMDBaseDA::AliFMDBaseDA() :
90 fDiagnosticsFilename("diagnosticsHistograms.root"),
93 fSaveHistograms(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 fDetectorArray.SetOwner();
121 //_____________________________________________________________________
122 AliFMDBaseDA::~AliFMDBaseDA()
127 //_____________________________________________________________________
128 void AliFMDBaseDA::Run(AliRawReader* reader)
132 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
137 InitContainer(diagFile);
143 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
144 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
146 //reader->NextEvent(); // Read Start-of-Run event
147 // reader->NextEvent(); // Read Start-of-Files event
149 // reader->NextEvent(); // Start-of-Data
152 int lastProgress = 0;
154 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
155 if(!reader->NextEvent()) continue;
157 UInt_t eventType = reader->GetType();
158 if(eventType == AliRawEventHeaderBase::kStartOfData ||
159 eventType == AliRawEventHeaderBase::kFormatError) {
161 WriteConditionsData(fmdReader);
164 if(eventType != AliRawEventHeaderBase::kPhysicsEvent) {
171 fmdReader->ReadAdcs(digitArray);
172 //std::cout<<"in event "<<*(reader->GetEventId())<<" "<<n<<std::endl;
173 //AliDebug(5, Form("In event # %d with %d entries",
174 // *(reader->GetEventId()), digitArray->GetEntriesFast()));
176 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
177 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
182 int progress = int((n *100)/ GetRequiredEvents()) ;
183 if (progress <= lastProgress) continue;
184 lastProgress = progress;
185 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
188 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
191 for(UShort_t det=1;det<=3;det++) {
192 std::cout << "FMD" << det << std::endl;
193 UShort_t FirstRing = (det == 1 ? 1 : 0);
194 for (UShort_t ir = FirstRing; ir < 2; ir++) {
195 Char_t ring = (ir == 0 ? 'O' : 'I');
196 UShort_t nsec = (ir == 0 ? 40 : 20);
197 UShort_t nstr = (ir == 0 ? 256 : 512);
198 std::cout << " Ring " << ring << ": " << std::flush;
199 for(UShort_t sec =0; sec < nsec; sec++) {
200 for(UShort_t strip = 0; strip < nstr; strip++) {
201 Analyse(det,ring,sec,strip);
203 std::cout << '.' << std::flush;
207 std::cout << "done" << std::endl;
211 if(fOutputFile.is_open()) {
212 fOutputFile.write("# EOF\n",6);
216 if(fSaveHistograms ) {
220 AliInfo("Closing diagnostics file - please wait ...");
221 // diagFile->Write();
226 //_____________________________________________________________________
228 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
231 TObjArray* ringArray;
232 TObjArray* sectorArray;
234 TDirectory* savDir = gDirectory;
236 for(UShort_t det=1;det<=3;det++) {
237 detArray = new TObjArray();
238 detArray->SetOwner();
239 fDetectorArray.AddAtAndExpand(detArray,det);
241 TDirectory* detDir = 0;
244 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
247 UShort_t FirstRing = (det == 1 ? 1 : 0);
248 for (UShort_t ir = FirstRing; ir < 2; ir++) {
249 Char_t ring = (ir == 0 ? 'O' : 'I');
250 UShort_t nsec = (ir == 0 ? 40 : 20);
251 UShort_t nstr = (ir == 0 ? 256 : 512);
252 ringArray = new TObjArray();
253 ringArray->SetOwner();
254 detArray->AddAtAndExpand(ringArray,ir);
257 TDirectory* ringDir = 0;
260 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
264 for(UShort_t sec =0; sec < nsec; sec++) {
265 sectorArray = new TObjArray();
266 sectorArray->SetOwner();
267 ringArray->AddAtAndExpand(sectorArray,sec);
270 TDirectory* secDir = 0;
273 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
276 for(UShort_t strip = 0; strip < nstr; strip++) {
279 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
281 AddChannelContainer(sectorArray, det, ring, sec, strip);
289 //_____________________________________________________________________
290 void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
292 AliFMDParameters* pars = AliFMDParameters::Instance();
293 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
295 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
296 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
298 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength);
302 UShort_t defSampleRate = 4;
303 UShort_t sampleRateFromSOD;
305 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
307 UShort_t firstStrip = 0;
308 UShort_t lastStrip = 127;
309 UShort_t firstStripSOD;
310 UShort_t lastStripSOD;
311 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
313 for(Int_t det=1;det<=3;det++) {
314 UShort_t FirstRing = (det == 1 ? 1 : 0);
315 for (UShort_t ir = FirstRing; ir < 2; ir++) {
316 Char_t ring = (ir == 0 ? 'O' : 'I');
317 UShort_t nsec = (ir == 0 ? 40 : 20);
318 for(UShort_t sec =0; sec < nsec; sec++) {
319 sampleRateFromSOD = defSampleRate;
320 sampleRate->Set(det,ring,sec,0,sampleRateFromSOD);
321 firstStripSOD = firstStrip;
322 lastStripSOD = lastStrip;
323 stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD);
329 sampleRate->WriteToFile(fConditionsFile);
330 stripRange->WriteToFile(fConditionsFile);
331 //pars->SetSampleRate(sampleRate);
332 //pars->SetStripRange(stripRange);
343 // Gain Relevant stuff
345 UShort_t defPulseSize = 32 ;
346 UShort_t defPulseLength = 100 ;
347 UShort_t pulseSizeFromSOD;
348 UShort_t pulseLengthFromSOD;
350 fPulseSize.Reset(defPulseSize);
351 fPulseLength.Reset(defPulseLength);
353 for(UShort_t det=1;det<=3;det++)
354 for(UShort_t iring=0;iring<=1;iring++)
355 for(UShort_t board=0;board<=1;board++) {
356 pulseSizeFromSOD = defPulseSize;
357 pulseLengthFromSOD = defPulseLength;
359 fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
360 fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
364 // fConditionsFile << defSampleRate << ','
365 // << timebins <<"\n";
367 if(fConditionsFile.is_open()) {
369 fConditionsFile.write("# EOF\n",6);
370 fConditionsFile.close();
375 //_____________________________________________________________________
376 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
378 UShort_t iring = (ring == 'I' ? 1 : 0);
380 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
387 //_____________________________________________________________________