]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDA.cxx
Allowed for seperate gain analysis on the ten halfrings and expanded the SOD information
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
1 /**************************************************************************
2  * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
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.
20 */
21 //
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.
27 //
28
29 #include "AliFMDBaseDA.h"
30 #include "iostream"
31
32 #include "AliFMDRawReader.h"
33 #include "AliFMDCalibSampleRate.h"
34 #include "AliLog.h"
35 //_____________________________________________________________________
36 ClassImp(AliFMDBaseDA)
37 #if 0 
38 ; // Do not delete  - to let Emacs for mat the code
39 #endif
40
41 //_____________________________________________________________________
42 const char*
43 AliFMDBaseDA::GetStripPath(UShort_t det, 
44                            Char_t   ring, 
45                            UShort_t sec, 
46                            UShort_t str, 
47                            Bool_t   full) const
48 {
49   return Form("%s%sFMD%d%c[%02d,%03d]", 
50               (full ? GetSectorPath(det, ring, sec, full) : ""), 
51               (full ? "/" : ""), det, ring, sec, str);
52 }
53 //_____________________________________________________________________
54 const char*
55 AliFMDBaseDA::GetSectorPath(UShort_t det, 
56                             Char_t   ring, 
57                             UShort_t sec, 
58                             Bool_t   full) const
59 {
60   return Form("%s%sFMD%d%c[%02d]", 
61               (full ? GetRingPath(det, ring, full) : ""), 
62               (full ? "/" : ""), det, ring, sec);
63 }
64 //_____________________________________________________________________
65 const char*
66 AliFMDBaseDA::GetRingPath(UShort_t det, 
67                           Char_t   ring, 
68                           Bool_t   full) const
69 {
70   return Form("%s%sFMD%d%c", 
71               (full ? GetDetectorPath(det, full) : ""), 
72               (full ? "/" : ""), det, ring);
73 }
74 //_____________________________________________________________________
75 const char*
76 AliFMDBaseDA::GetDetectorPath(UShort_t det, 
77                               Bool_t   full) const
78 {
79   return Form("%s%sFMD%d", 
80               (full ? fDiagnosticsFilename.Data() : ""), 
81               (full ? ":/" : ""), det);
82 }
83
84 //_____________________________________________________________________
85 AliFMDBaseDA::AliFMDBaseDA() : 
86   TNamed(),
87   fDiagnosticsFilename("diagnosticsHistograms.root"),
88   fOutputFile(),
89   fConditionsFile(),
90   fSaveHistograms(kFALSE),
91   fDetectorArray(),
92   fPulseSize(16),
93   fPulseLength(16),
94   fRequiredEvents(0),
95   fCurrentEvent(0)
96  {
97   fDetectorArray.SetOwner();
98   fConditionsFile.open("conditions.csv");
99 }
100 //_____________________________________________________________________
101 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) : 
102   TNamed(baseDA),
103   fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
104   fOutputFile(),
105   fConditionsFile(),
106   fSaveHistograms(baseDA.fSaveHistograms),
107   fDetectorArray(baseDA.fDetectorArray),
108   fPulseSize(baseDA.fPulseSize),
109   fPulseLength(baseDA.fPulseLength),
110   fRequiredEvents(baseDA.fRequiredEvents),
111   fCurrentEvent(baseDA.fCurrentEvent)
112 {
113   fDetectorArray.SetOwner();
114   
115 }
116
117
118 //_____________________________________________________________________
119 AliFMDBaseDA::~AliFMDBaseDA() 
120 {
121   //destructor
122 }
123
124 //_____________________________________________________________________
125 void AliFMDBaseDA::Run(AliRawReader* reader) 
126 {
127   TFile* diagFile = 0;
128   if (fSaveHistograms)
129     diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
130
131   
132   WriteConditionsData();
133   
134   InitContainer(diagFile);
135   Init();
136
137
138   reader->Reset();
139   
140   AliFMDRawReader* fmdReader  = new AliFMDRawReader(reader,0);
141   TClonesArray*    digitArray = new TClonesArray("AliFMDDigit",0);
142     
143   reader->NextEvent(); // Read Start-of-Run event
144   reader->NextEvent(); // Read Start-of-Files event
145   int lastProgress = 0;
146   
147   for(Int_t n =1;n <= GetRequiredEvents(); n++) {
148     if(!reader->NextEvent()) continue;
149     
150     SetCurrentEvent(*(reader->GetEventId()));
151     
152     digitArray->Clear();
153     fmdReader->ReadAdcs(digitArray);
154     
155     AliDebug(5, Form("In event # %d with %d entries", 
156                      *(reader->GetEventId()), digitArray->GetEntriesFast()));
157     
158     for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
159       AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
160       FillChannels(digit);
161     }
162     
163     FinishEvent();
164     int progress = int((n *100)/ GetRequiredEvents()) ;
165     if (progress <= lastProgress) continue;
166     lastProgress = progress;
167     std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
168   }
169
170   AliInfo(Form("Looped over %d events",GetCurrentEvent()));
171   WriteHeaderToFile();
172   
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);
184         }
185         std::cout << '.' << std::flush;
186       }
187       if(fSaveHistograms)
188         diagFile->Flush();
189       std::cout << "done" << std::endl;
190     }
191   }
192
193   if(fOutputFile.is_open()) {
194     fOutputFile.write("# EOF\n",6);
195     fOutputFile.close();
196   }
197   
198   if(fSaveHistograms ) {
199     AliInfo("Closing diagnostics file - please wait ...");
200     // diagFile->Write();
201     diagFile->Close();
202     AliInfo("done");
203   }
204 }
205 //_____________________________________________________________________
206
207 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
208 {
209   TObjArray* detArray;
210   TObjArray* ringArray;
211   TObjArray* sectorArray;
212     
213   TDirectory* savDir   = gDirectory;
214
215   for(UShort_t det=1;det<=3;det++) {
216     detArray = new TObjArray();
217     detArray->SetOwner();
218     fDetectorArray.AddAtAndExpand(detArray,det);
219
220     TDirectory* detDir = 0;
221     if (diagFile) {
222       diagFile->cd();
223       detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
224     }
225
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);
234
235
236       TDirectory* ringDir = 0;
237       if (detDir) { 
238         detDir->cd();
239         ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
240       }
241       
242
243       for(UShort_t sec =0; sec < nsec;  sec++)  {
244         sectorArray = new TObjArray();
245         sectorArray->SetOwner();
246         ringArray->AddAtAndExpand(sectorArray,sec);
247
248
249         TDirectory* secDir = 0;
250         if (ringDir) { 
251           ringDir->cd();
252           secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
253         }
254         
255         for(UShort_t strip = 0; strip < nstr; strip++) {
256           if (secDir) { 
257             secDir->cd();
258             secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
259           }
260           AddChannelContainer(sectorArray, det, ring, sec, strip);
261         }
262       }
263     }
264   }
265   savDir->cd();
266 }
267
268 //_____________________________________________________________________ 
269 void AliFMDBaseDA::WriteConditionsData() 
270 {
271   AliFMDParameters* pars       = AliFMDParameters::Instance();
272   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
273   
274   // fConditionsFile.write("# Sample Rate, timebins \n",25);
275   
276   // Sample Rate
277   
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                 << ',' 
293                           << ring                << ','
294                           << sec                 << ','
295                           << strip               << ','
296                           << "samplerate"        << ','
297                           << sampleRateFromSOD   << "\n";
298         }
299       }
300     }
301   }
302   
303   pars->SetSampleRate(sampleRate);
304   
305   // Zero Suppresion
306   
307   // Strip Range
308   
309   // Gain Relevant stuff
310   
311   UShort_t defPulseSize = 32 ; 
312   UShort_t defPulseLength = 100 ; 
313   UShort_t pulseSizeFromSOD;
314   UShort_t pulseLengthFromSOD;  
315   
316   fPulseSize.Reset(defPulseSize);
317   fPulseLength.Reset(defPulseLength);
318   
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;
324
325         fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
326         fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
327       }
328           
329   
330   //  fConditionsFile     << defSampleRate   << ',' 
331   //                  << timebins     <<"\n";
332   
333   if(fConditionsFile.is_open()) {
334     
335     fConditionsFile.write("# EOF\n",6);
336     fConditionsFile.close();
337     
338   }
339   
340 }
341 //_____________________________________________________________________ 
342 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
343
344   UShort_t iring  =  (ring == 'I' ? 1 : 0);
345   
346   Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
347   
348   return index;
349   
350 }
351
352
353 //_____________________________________________________________________ 
354 //
355 // EOF
356 //