]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDA.cxx
Updated RecoParam object for p-p data
[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 #include "AliFMDRawReader.h"
32 #include "AliFMDCalibSampleRate.h"
33 #include "AliFMDCalibStripRange.h"
34 #include "AliLog.h"
35 #include "AliRawEventHeaderBase.h"
36
37 //_____________________________________________________________________
38 ClassImp(AliFMDBaseDA)
39 #if 0 
40 ; // Do not delete  - to let Emacs for mat the code
41 #endif
42
43 //_____________________________________________________________________
44 const char*
45 AliFMDBaseDA::GetStripPath(UShort_t det, 
46                            Char_t   ring, 
47                            UShort_t sec, 
48                            UShort_t str, 
49                            Bool_t   full) const
50 {
51   return Form("%s%sFMD%d%c[%02d,%03d]", 
52               (full ? GetSectorPath(det, ring, sec, full) : ""), 
53               (full ? "/" : ""), det, ring, sec, str);
54 }
55 //_____________________________________________________________________
56 const char*
57 AliFMDBaseDA::GetSectorPath(UShort_t det, 
58                             Char_t   ring, 
59                             UShort_t sec, 
60                             Bool_t   full) const
61 {
62   return Form("%s%sFMD%d%c[%02d]", 
63               (full ? GetRingPath(det, ring, full) : ""), 
64               (full ? "/" : ""), det, ring, sec);
65 }
66 //_____________________________________________________________________
67 const char*
68 AliFMDBaseDA::GetRingPath(UShort_t det, 
69                           Char_t   ring, 
70                           Bool_t   full) const
71 {
72   return Form("%s%sFMD%d%c", 
73               (full ? GetDetectorPath(det, full) : ""), 
74               (full ? "/" : ""), det, ring);
75 }
76 //_____________________________________________________________________
77 const char*
78 AliFMDBaseDA::GetDetectorPath(UShort_t det, 
79                               Bool_t   full) const
80 {
81   return Form("%s%sFMD%d", 
82               (full ? fDiagnosticsFilename.Data() : ""), 
83               (full ? ":/" : ""), det);
84 }
85
86 //_____________________________________________________________________
87 AliFMDBaseDA::AliFMDBaseDA() : 
88   TNamed(),
89   fDiagnosticsFilename("diagnosticsHistograms.root"),
90   fOutputFile(),
91   fConditionsFile(),
92   fSaveHistograms(kFALSE),
93   fDetectorArray(),
94   fPulseSize(10),
95   fPulseLength(10),
96   fRequiredEvents(0),
97   fCurrentEvent(0)
98  {
99   fDetectorArray.SetOwner();
100   fConditionsFile.open("conditions.csv");
101 }
102 //_____________________________________________________________________
103 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) : 
104   TNamed(baseDA),
105   fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
106   fOutputFile(),
107   fConditionsFile(),
108   fSaveHistograms(baseDA.fSaveHistograms),
109   fDetectorArray(baseDA.fDetectorArray),
110   fPulseSize(baseDA.fPulseSize),
111   fPulseLength(baseDA.fPulseLength),
112   fRequiredEvents(baseDA.fRequiredEvents),
113   fCurrentEvent(baseDA.fCurrentEvent)
114 {
115   fDetectorArray.SetOwner();
116   
117 }
118
119
120 //_____________________________________________________________________
121 AliFMDBaseDA::~AliFMDBaseDA() 
122 {
123   //destructor
124 }
125
126 //_____________________________________________________________________
127 void AliFMDBaseDA::Run(AliRawReader* reader) 
128 {
129   TFile* diagFile = 0;
130   if (fSaveHistograms)
131     diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
132
133   
134   
135   
136   
137   reader->Reset();
138   
139   AliFMDRawReader* fmdReader  = new AliFMDRawReader(reader,0);
140   TClonesArray*    digitArray = new TClonesArray("AliFMDDigit",0);
141   
142   Bool_t SOD_read = kFALSE;
143   
144   for(Int_t i=0;i<3;i++) {
145     reader->NextEvent(); // Read Start-of-Run / Start-of-Files event
146     
147     UInt_t eventType = reader->GetType();
148     if(eventType == AliRawEventHeaderBase::kStartOfData || 
149        eventType == AliRawEventHeaderBase::kFormatError) { 
150       
151       WriteConditionsData(fmdReader);
152       Init();
153       SOD_read = kTRUE;
154       break;
155     }
156   }
157   
158   InitContainer(diagFile);
159   
160   if(!SOD_read) 
161     AliWarning("No SOD event detected!");
162   
163   int lastProgress = 0;
164   
165   
166   
167   for(Int_t n =1;n <= GetRequiredEvents(); n++) {
168     if(!reader->NextEvent()) continue;
169     SetCurrentEvent(n);
170     digitArray->Clear();
171     fmdReader->ReadAdcs(digitArray);
172     
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()));
176     
177     for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
178       AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
179       FillChannels(digit);
180     }
181     
182    
183     FinishEvent();
184     
185     int progress = int((n *100)/ GetRequiredEvents()) ;
186     if (progress <= lastProgress) continue;
187     lastProgress = progress;
188     std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
189     
190   }
191   
192   AliInfo(Form("Looped over %d events",GetCurrentEvent()));
193   WriteHeaderToFile();
194   
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);
206         }
207         std::cout << '.' << std::flush;
208       }
209       if(fSaveHistograms)
210         diagFile->Flush();
211       std::cout << "done" << std::endl;
212     }
213   }
214   
215   if(fOutputFile.is_open()) {
216     fOutputFile.write("# EOF\n",6);
217     fOutputFile.close();
218   }
219   
220   Terminate(diagFile);
221     
222   if(fSaveHistograms ) {
223     
224     AliInfo("Closing diagnostics file - please wait ...");
225     // diagFile->Write();
226     diagFile->Close();
227     AliInfo("done");
228     
229   }
230 }
231 //_____________________________________________________________________
232
233 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
234 {
235   TObjArray* detArray;
236   TObjArray* ringArray;
237   TObjArray* sectorArray;
238     
239   TDirectory* savDir   = gDirectory;
240
241   for(UShort_t det=1;det<=3;det++) {
242     detArray = new TObjArray();
243     detArray->SetOwner();
244     fDetectorArray.AddAtAndExpand(detArray,det);
245
246     TDirectory* detDir = 0;
247     if (diagFile) {
248       diagFile->cd();
249       detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
250     }
251
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);
260
261
262       TDirectory* ringDir = 0;
263       if (detDir) { 
264         detDir->cd();
265         ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
266       }
267       
268
269       for(UShort_t sec =0; sec < nsec;  sec++)  {
270         sectorArray = new TObjArray();
271         sectorArray->SetOwner();
272         ringArray->AddAtAndExpand(sectorArray,sec);
273
274
275         TDirectory* secDir = 0;
276         if (ringDir) { 
277           ringDir->cd();
278           secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
279         }
280         
281         for(UShort_t strip = 0; strip < nstr; strip++) {
282           if (secDir) { 
283             secDir->cd();
284             secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
285           }
286           AddChannelContainer(sectorArray, det, ring, sec, strip);
287         }
288       }
289     }
290   }
291   savDir->cd();
292 }
293
294 //_____________________________________________________________________ 
295 void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader) 
296 {
297   AliFMDParameters* pars       = AliFMDParameters::Instance();
298   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
299   
300   AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
301   AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
302   
303   fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength);
304   
305   // Sample Rate
306   /*
307     UShort_t defSampleRate = 4;
308     UShort_t sampleRateFromSOD;
309     
310   AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
311
312   UShort_t firstStrip = 0;
313   UShort_t lastStrip  = 127;
314   UShort_t firstStripSOD;
315   UShort_t lastStripSOD;
316   AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
317   
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);
329         
330       }
331     }
332   }
333   */
334   sampleRate->WriteToFile(fConditionsFile);
335   stripRange->WriteToFile(fConditionsFile);
336   //pars->SetSampleRate(sampleRate);
337   //pars->SetStripRange(stripRange);
338
339  
340   // Zero Suppresion
341   
342   // Strip Range
343   
344   fConditionsFile.write("# Gain Events \n",15);
345   
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++) {
351         
352         Int_t idx = GetHalfringIndex(det,ring,board);
353         
354         fConditionsFile << det                     << ','
355                         << ring                    << ','
356                         << board                   << ','
357                         << fPulseLength.At(idx)    << "\n";
358         
359       }
360     }
361   }
362   
363   fConditionsFile.write("# Gain Pulse \n",14);
364   
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++) {
370         
371         Int_t idx = GetHalfringIndex(det,ring,board);
372         
373         fConditionsFile << det                     << ','
374                         << ring                    << ','
375                         << board                   << ','
376                         << fPulseSize.At(idx)      << "\n";
377         
378       }
379     }
380   }
381   
382   
383
384   // Gain Relevant stuff
385   /*
386   UShort_t defPulseSize = 32 ; 
387   UShort_t defPulseLength = 100 ; 
388   UShort_t pulseSizeFromSOD;
389   UShort_t pulseLengthFromSOD;  
390   
391   fPulseSize.Reset(defPulseSize);
392   fPulseLength.Reset(defPulseLength);
393   
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;
399
400         fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
401         fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
402       }
403           
404   
405   //  fConditionsFile     << defSampleRate   << ',' 
406   //                  << timebins     <<"\n";
407   */
408   if(fConditionsFile.is_open()) {
409     
410     fConditionsFile.write("# EOF\n",6);
411     fConditionsFile.close();
412     
413   }
414   
415 }
416 //_____________________________________________________________________ 
417 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
418
419   UShort_t iring  =  (ring == 'I' ? 1 : 0);
420   
421   Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
422   
423   return index-2;
424   
425 }
426
427
428 //_____________________________________________________________________ 
429 //
430 // EOF
431 //