]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCReconstructor.cxx
New Trigger class for PHOS
[u/mrichter/AliRoot.git] / ZDC / AliZDCReconstructor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // class for ZDC reconstruction                                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25 #include <TF1.h>
26
27 #include "AliRunLoader.h"
28 #include "AliRawReader.h"
29 #include "AliESD.h"
30 #include "AliZDCDigit.h"
31 #include "AliZDCRawStream.h"
32 #include "AliZDCReco.h"
33 #include "AliZDCReconstructor.h"
34 #include "AliZDCCalibData.h"
35
36
37 ClassImp(AliZDCReconstructor)
38
39
40 //_____________________________________________________________________________
41 AliZDCReconstructor:: AliZDCReconstructor()
42 {
43   // **** Default constructor
44   // if(!fStorage) fStorage =  AliCDBManager::Instance()->GetStorage("local://DBlocal");
45
46   //  ---      Number of generated spectator nucleons and impact parameter
47   // --------------------------------------------------------------------------------------------------
48   // [1] ### Results from a new production  -> 0<b<18 fm (Apr 2002)
49   // Fit results for neutrons (Nspectator n true vs. EZN)
50   fZNCen = new TF1("fZNCen",
51       "(-2.287920+sqrt(2.287920*2.287920-4*(-0.007629)*(11.921710-x)))/(2*(-0.007629))",0.,164.);
52   fZNPer = new TF1("fZNPer",
53       "(-37.812280-sqrt(37.812280*37.812280-4*(-0.190932)*(-1709.249672-x)))/(2*(-0.190932))",0.,164.);
54   // Fit results for protons (Nspectator p true vs. EZP)
55   fZPCen = new TF1("fZPCen",
56        "(-1.321353+sqrt(1.321353*1.321353-4*(-0.007283)*(3.550697-x)))/(2*(-0.007283))",0.,60.);
57   fZPPer = new TF1("fZPPer",
58       "(-42.643308-sqrt(42.643308*42.643308-4*(-0.310786)*(-1402.945615-x)))/(2*(-0.310786))",0.,60.);
59   // Fit results for total number of spectators (Nspectators true vs. EZDC)
60   fZDCCen = new TF1("fZDCCen",
61       "(-1.934991+sqrt(1.934991*1.934991-4*(-0.004080)*(15.111124-x)))/(2*(-0.004080))",0.,225.);
62   fZDCPer = new TF1("fZDCPer",
63       "(-34.380639-sqrt(34.380639*34.380639-4*(-0.104251)*(-2612.189017-x)))/(2*(-0.104251))",0.,225.);
64   // --------------------------------------------------------------------------------------------------
65   // Fit results for b (b vs. EZDC)
66   // [2] ### Results from a new production  -> 0<b<18 fm (Apr 2002)
67   fbCen = new TF1("fbCen","-0.056923+0.079703*x-0.0004301*x*x+0.000001366*x*x*x",0.,220.);
68   fbPer = new TF1("fbPer","17.943998-0.046846*x+0.000074*x*x",0.,220.);
69   // --------------------------------------------------------------------------------------------------
70   // Evaluating Nspectators and b from ZEM energy
71   // [2] ### Results from a new production  -> 0<b<18 fm (Apr 2002)
72   fZEMn  = new TF1("fZEMn","126.2-0.05399*x+0.000005679*x*x",0.,4000.);
73   fZEMp  = new TF1("fZEMp","82.49-0.03611*x+0.00000385*x*x",0.,4000.);
74   fZEMsp = new TF1("fZEMsp","208.7-0.09006*x+0.000009526*x*x",0.,4000.);
75   fZEMb  = new TF1("fZEMb","16.06-0.01633*x+1.44e-5*x*x-6.778e-9*x*x*x+1.438e-12*x*x*x*x-1.112e-16*x*x*x*x*x",0.,4000.);
76 }
77
78 //_____________________________________________________________________________
79 AliZDCReconstructor::AliZDCReconstructor(const AliZDCReconstructor& 
80                                          reconstructor):
81   AliReconstructor(reconstructor)
82 {
83 // copy constructor
84
85   Fatal("AliZDCReconstructor", "copy constructor not implemented");
86 }
87
88 //_____________________________________________________________________________
89 AliZDCReconstructor& AliZDCReconstructor::operator = 
90   (const AliZDCReconstructor& /*reconstructor*/)
91 {
92 // assignment operator
93
94   Fatal("operator =", "assignment operator not implemented");
95   return *this;
96 }
97
98 //_____________________________________________________________________________
99 AliZDCReconstructor::~AliZDCReconstructor()
100 {
101 // destructor
102
103   delete fZNCen;
104   delete fZNPer;
105   delete fZPCen;
106   delete fZPPer;
107   delete fZDCCen;
108   delete fZDCPer;
109   delete fbCen;
110   delete fbPer;
111   delete fZEMn;
112   delete fZEMp;
113   delete fZEMsp;
114   delete fZEMb;
115 }
116
117
118 //_____________________________________________________________________________
119 void AliZDCReconstructor::Reconstruct(AliRunLoader* runLoader) const
120 {
121   // *** Local ZDC reconstruction for digits
122   
123   // Get calibration data
124   int runNumber = 0;
125   AliZDCCalibData *calibda = GetCalibData(runNumber);  
126   
127   Float_t meanPed[47];
128   for(Int_t jj=0; jj<47; jj++) meanPed[jj] = calibda->GetMeanPed(jj);
129
130   AliLoader* loader = runLoader->GetLoader("ZDCLoader");
131   if (!loader) return;
132   loader->LoadDigits("read");
133   loader->LoadRecPoints("recreate");
134   AliZDCDigit digit;
135   AliZDCDigit* pdigit = &digit;
136
137   // Event loop
138   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
139     runLoader->GetEvent(iEvent);
140
141     // load digits
142     loader->LoadDigits();
143     TTree* treeD = loader->TreeD();
144     if (!treeD) continue;
145     treeD->SetBranchAddress("ZDC", &pdigit);
146
147     // loop over digits
148     Float_t zncorr=0, zpcorr=0, zemcorr=0;
149     for (Int_t iDigit = 0; iDigit < treeD->GetEntries(); iDigit++) {
150       treeD->GetEntry(iDigit);
151       if (!pdigit) continue;
152
153       if(digit.GetSector(0) == 1)
154          zncorr  += (Float_t) (digit.GetADCValue(0)-meanPed[digit.GetSector(1)]);          // ped 4 high gain ZN ADCs
155       else if(digit.GetSector(0) == 2)
156          zpcorr  += (Float_t) (digit.GetADCValue(0)-meanPed[digit.GetSector(1)+10]); // ped 4 high gain ZP ADCs
157       else if(digit.GetSector(0) == 3){
158          if(digit.GetSector(1)==1)      zemcorr += (Float_t) (digit.GetADCValue(0)-meanPed[digit.GetSector(1)+20]); // ped 4 high gain ZEM1 ADCs
159          else if(digit.GetSector(1)==2) zemcorr += (Float_t) (digit.GetADCValue(0)-meanPed[digit.GetSector(1)+22]); // ped 4 high gain ZEM2 ADCs
160       }
161     }
162     if(zncorr<0)  zncorr=0;
163     if(zpcorr<0)  zpcorr=0;
164     if(zemcorr<0) zemcorr=0;
165
166     // reconstruct the event
167     printf("\n \t ZDCReco from digits-> Ev.#%d ZN = %.0f, ZP = %.0f, ZEM = %.0f\n",iEvent,zncorr,zpcorr,zemcorr);
168     ReconstructEvent(loader, zncorr, zpcorr, zemcorr);
169   }
170
171   loader->UnloadDigits();
172   loader->UnloadRecPoints();
173 }
174
175 //_____________________________________________________________________________
176 void AliZDCReconstructor::Reconstruct(AliRunLoader* runLoader, 
177                                       AliRawReader* rawReader) const
178 {
179   // *** Local ZDC reconstruction for raw data
180   
181   // Calibration data
182   int runNumber = 0;
183   AliZDCCalibData *calibda = GetCalibData(runNumber);  
184   
185   Float_t meanPed[47];
186   for(Int_t jj=0; jj<47; jj++) meanPed[jj] = calibda->GetMeanPed(jj);
187
188   AliLoader* loader = runLoader->GetLoader("ZDCLoader");
189   if (!loader) return;
190   loader->LoadRecPoints("recreate");
191   // Event loop
192   Int_t iEvent = 0;
193   while (rawReader->NextEvent()) {
194     runLoader->GetEvent(iEvent++);
195
196     // loop over raw data digits
197     Float_t zncorr=0, zpcorr=0, zemcorr=0;
198     AliZDCRawStream digit(rawReader);
199     while (digit.Next()) {
200       if(digit.IsADCDataWord()){
201         if(digit.GetADCGain() == 0){
202           if(digit.GetSector(0) == 1)      zncorr  += (Float_t) (digit.GetADCValue()-meanPed[digit.GetSector(1)]); // pedestals for high gain ZN ADCs;
203           else if(digit.GetSector(0) == 2) zpcorr  += (Float_t) (digit.GetADCValue()-meanPed[digit.GetSector(1)+10]); // pedestals for high gain ZP ADCs;
204           else if(digit.GetSector(0) == 3) zemcorr += (Float_t) (digit.GetADCValue()-meanPed[digit.GetSector(1)+20]); // pedestals for high gain ZEM ADCs;
205         }
206       }
207     }
208     if(zncorr<0)  zncorr=0;
209     if(zpcorr<0)  zpcorr=0;
210     if(zemcorr<0) zemcorr=0;
211     
212     // reconstruct the event
213     printf("\n\t ZDCReco from raw-> Ev.#%d ZN = %.0f, ZP = %.0f, ZEM = %.0f\n",iEvent,zncorr,zpcorr,zemcorr);
214     ReconstructEvent(loader, zncorr, zpcorr, zemcorr);
215   }
216
217   loader->UnloadRecPoints();
218 }
219
220 //_____________________________________________________________________________
221 void AliZDCReconstructor::ReconstructEvent(AliLoader* loader, Float_t zncorr,
222         Float_t zpcorr, Float_t zemcorr) const
223 {
224   // ***** Reconstruct one event
225   
226   //  ---      ADCchannel -> photoelectrons
227   // NB-> PM gain = 10^(5), ADC resolution = 6.4*10^(-7)
228   // Move to V965 (E.S.,15/09/04) NB-> PM gain = 10^(5), ADC resolution = 8*10^(-7)
229   Float_t znphe, zpphe, zemphe, convFactor = 0.08;
230   znphe  = zncorr/convFactor;
231   zpphe  = zpcorr/convFactor;
232   zemphe = zemcorr/convFactor;
233   //if AliDebug(1,Form("\n    znphe = %f, zpphe = %f, zemphe = %f\n",znphe, zpphe, zemphe);
234   
235   //  ---      Energy calibration
236   // Conversion factors for hadronic ZDCs goes from phe yield to TRUE 
237   // incident energy (conversion from GeV to TeV is included); while for EM 
238   // calos conversion is from light yield to detected energy calculated by
239   // GEANT NB -> ZN and ZP conversion factors are constant since incident
240   // spectators have all the same energy, ZEM energy is obtained through a
241   // fit over the whole range of incident particle energies 
242   // (obtained with full HIJING simulations) 
243   Float_t znenergy, zpenergy, zemenergy, zdcenergy;
244   Float_t znphexTeV=329., zpphexTeV=369.;
245   znenergy  = znphe/znphexTeV;
246   zpenergy  = zpphe/zpphexTeV;
247   zdcenergy = znenergy+zpenergy;
248   zemenergy = -4.81+0.3238*zemphe;
249   if(zemenergy<0) zemenergy=0;
250   //  if AliDebug(1,Form("    znenergy = %f TeV, zpenergy = %f TeV, zdcenergy = %f GeV, "
251   //                       "\n          zemenergy = %f TeV\n", znenergy, zpenergy, 
252   //                       zdcenergy, zemenergy);
253   
254   //  if(zdcenergy==0)
255   //    if AliDebug(1,Form("\n\n        ###     ATTENZIONE!!! -> ev# %d: znenergy = %f TeV, zpenergy = %f TeV, zdcenergy = %f GeV, "
256   //                         " zemenergy = %f TeV\n\n", fMerger->EvNum(), znenergy, zpenergy, zdcenergy, zemenergy); 
257
258   //  ---      Number of incident spectator nucleons
259   Int_t nDetSpecN, nDetSpecP;
260   nDetSpecN = (Int_t) (znenergy/2.760);
261   nDetSpecP = (Int_t) (zpenergy/2.760);
262 //  if AliDebug(1,Form("\n    nDetSpecN = %d, nDetSpecP = %d\n",nDetSpecN, nDetSpecP);
263
264   Int_t nGenSpecN=0, nGenSpecP=0, nGenSpec=0;
265   Double_t impPar=0;
266   // Cut value for Ezem (GeV)
267   // [2] ### Results from a new production  -> 0<b<18 fm (Apr 2002)
268   Float_t eZEMCut = 420.;
269   Float_t deltaEZEMSup = 690.; 
270   Float_t deltaEZEMInf = 270.; 
271   if(zemenergy > (eZEMCut+deltaEZEMSup)){
272     nGenSpecN = (Int_t) (fZNCen->Eval(znenergy));
273     nGenSpecP = (Int_t) (fZPCen->Eval(zpenergy));
274     nGenSpec  = (Int_t) (fZDCCen->Eval(zdcenergy));
275     impPar    = fbCen->Eval(zdcenergy);
276   }
277   else if(zemenergy < (eZEMCut-deltaEZEMInf)){
278     nGenSpecN = (Int_t) (fZNPer->Eval(znenergy)); 
279     nGenSpecP = (Int_t) (fZPPer->Eval(zpenergy));
280     nGenSpec  = (Int_t) (fZDCPer->Eval(zdcenergy));
281     impPar    = fbPer->Eval(zdcenergy);
282   }
283   else if(zemenergy >= (eZEMCut-deltaEZEMInf) && zemenergy <= (eZEMCut+deltaEZEMSup)){
284     nGenSpecN = (Int_t) (fZEMn->Eval(zemenergy));
285     nGenSpecP = (Int_t) (fZEMp->Eval(zemenergy));
286     nGenSpec  = (Int_t)(fZEMsp->Eval(zemenergy));
287     impPar    =  fZEMb->Eval(zemenergy);
288   }
289   // [2] ### Results from a new production  -> 0<b<18 fm (Apr 2002)
290   if(znenergy>162.)  nGenSpecN = (Int_t) (fZEMn->Eval(zemenergy));
291   if(zpenergy>59.75)  nGenSpecP = (Int_t) (fZEMp->Eval(zemenergy));
292   if(zdcenergy>221.5) nGenSpec  = (Int_t)(fZEMsp->Eval(zemenergy));
293   if(zdcenergy>220.)  impPar    =  fZEMb->Eval(zemenergy);
294   
295   if(nGenSpecN>125)    nGenSpecN=125;
296   else if(nGenSpecN<0) nGenSpecN=0;
297   if(nGenSpecP>82)     nGenSpecP=82;
298   else if(nGenSpecP<0) nGenSpecP=0;
299   if(nGenSpec>207)     nGenSpec=207;
300   else if(nGenSpec<0)  nGenSpec=0;
301   
302   //  ---      Number of participants
303   Int_t nPart, nPartTot;
304   nPart = 207-nGenSpecN-nGenSpecP;
305   nPartTot = 207-nGenSpec;
306   printf("\t  ZDCeventReco-> ZNEn = %.0f GeV, ZPEn = %.0f GeV, ZEMEn = %.0f GeV\n",
307         znenergy, zpenergy, zemenergy);
308
309   // create the output tree
310   loader->MakeTree("R");
311   TTree* treeR = loader->TreeR();
312   AliZDCReco reco(znenergy, zpenergy, zdcenergy, zemenergy,
313                   nDetSpecN, nDetSpecP, nGenSpecN, nGenSpecP, nGenSpec,
314                   nPartTot, impPar);
315   AliZDCReco* preco = &reco;
316   const Int_t kBufferSize = 4000;
317   treeR->Branch("ZDC", "AliZDCReco", &preco, kBufferSize);
318
319   // write the output tree
320   treeR->Fill();
321   loader->WriteRecPoints("OVERWRITE");
322 }
323
324 //_____________________________________________________________________________
325 void AliZDCReconstructor::FillESD(AliRunLoader* runLoader, 
326                                   AliESD* esd) const
327 {
328 // fill energies and number of participants to the ESD
329
330   AliLoader* loader = runLoader->GetLoader("ZDCLoader");
331   if (!loader) return;
332   loader->LoadRecPoints();
333
334   TTree* treeR = loader->TreeR();
335   if (!treeR) return;
336   AliZDCReco reco;
337   AliZDCReco* preco = &reco;
338   treeR->SetBranchAddress("ZDC", &preco);
339
340   treeR->GetEntry(0);
341   esd->SetZDC(reco.GetZNenergy(), reco.GetZPenergy(), reco.GetZEMenergy(),
342               reco.GetNPart());
343
344   loader->UnloadRecPoints();
345 }
346
347 //_____________________________________________________________________________
348 AliZDCCalibData* AliZDCReconstructor::GetCalibData(int runNumber) const
349 {
350
351   //printf("\n\t AliZDCReconstructor::GetCalibData \n");
352   //fStorage->PrintSelectionList();
353   //AliCDBEntry *entry = fStorage->Get("DBlocal/ZDC/Calib/Data",runNumber);
354
355   
356   AliCDBStorage *fStorage = AliCDBManager::Instance()->GetStorage("local://$ALICE_ROOT");
357   AliCDBEntry  *entry = fStorage->Get("ZDC/Calib/Data",0);
358   
359   AliZDCCalibData *calibda = (AliZDCCalibData*) entry->GetObject();
360
361   //AliCDBManager::Instance()->Destroy();
362
363   return calibda;
364
365 }