]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/AliZDCPreprocessor.cxx
Second ZDC module. More ZDC information included in the ESD and AOD classes (Chiara)
[u/mrichter/AliRoot.git] / ZDC / AliZDCPreprocessor.cxx
CommitLineData
31af5828 1// --- ROOT system
2#include <TFile.h>
79563ba1 3#include <TClonesArray.h>
4#include <TList.h>
5#include <TObjString.h>
31af5828 6#include <TTimeStamp.h>
64a7c78d 7
31af5828 8#include "AliZDCPreprocessor.h"
9#include "AliCDBManager.h"
10#include "AliCDBEntry.h"
64a7c78d 11#include "AliCDBMetaData.h"
12#include "AliDCSValue.h"
79563ba1 13#include "AliAlignObj.h"
90dbf5fb 14#include "AliAlignObjParams.h"
64a7c78d 15#include "AliLog.h"
16#include "AliZDCDataDCS.h"
6024ec85 17#include "AliZDCPedestals.h"
18#include "AliZDCCalib.h"
19#include "AliZDCRecParam.h"
64a7c78d 20
d5e687c2 21/////////////////////////////////////////////////////////////////////
22// //
23// Class implementing ZDC pre-processor. //
24// It takes data from DCS and passes it to the class AliZDCDataDCS //
25// The class is then written to the CDB. //
26// //
27/////////////////////////////////////////////////////////////////////
64a7c78d 28
29ClassImp(AliZDCPreprocessor)
30
31//______________________________________________________________________________________________
857ece97 32AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
33 AliPreprocessor("ZDC", shuttle),
64a7c78d 34 fData(0)
35{
36 // constructor
37}
38
39//______________________________________________________________________________________________
40AliZDCPreprocessor::~AliZDCPreprocessor()
41{
42 // destructor
43}
44
7a78280f 45
64a7c78d 46//______________________________________________________________________________________________
47void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime,
48 UInt_t endTime)
49{
50 // Creates AliZDCDataDCS object
51
52 AliPreprocessor::Initialize(run, startTime, endTime);
53
79563ba1 54 Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
64a7c78d 55 TTimeStamp(startTime).AsString(),
56 TTimeStamp(endTime).AsString()));
57
79563ba1 58 fRun = run;
59 fStartTime = startTime;
60 fEndTime = endTime;
61
64a7c78d 62 fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime);
63}
64
65//______________________________________________________________________________________________
66UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
67{
79563ba1 68 // *************** From DCS ******************
64a7c78d 69 // Fills data into a AliZDCDataDCS object
f181c9b8 70 if(!dcsAliasMap) return 1;
64a7c78d 71
72 // The processing of the DCS input data is forwarded to AliZDCDataDCS
d5e687c2 73 Float_t dcsValues[28]; // DCSAliases=28
74 fData->ProcessData(*dcsAliasMap, dcsValues);
e1ea0c63 75 //dcsAliasMap->Print("");
31af5828 76 //
79563ba1 77 // --- Writing ZDC table positions into alignment object
90dbf5fb 78 TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
79563ba1 79 TClonesArray &alobj = *array;
90dbf5fb 80 AliAlignObjParams a;
79563ba1 81 Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
cb50c7c8 82 // Vertical table position in mm from DCS
d5e687c2 83 Double_t dyZN1 = (Double_t) (dcsValues[0]/10.);
84 Double_t dyZP1 = (Double_t) (dcsValues[1]/10.);
85 Double_t dyZN2 = (Double_t) (dcsValues[2]/10.);
86 Double_t dyZP2 = (Double_t) (dcsValues[3]/10.);
87 const char *n1ZDC="ZDC/NeutronZDC1";
88 const char *p1ZDC="ZDC/ProtonZDC1";
89 const char *n2ZDC="ZDC/NeutronZDC2";
90 const char *p2ZDC="ZDC/ProtonZDC2";
79563ba1 91 UShort_t iIndex=0;
ae079791 92 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
93 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
79563ba1 94 //
d5e687c2 95 new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
96 new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
97 new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
98 new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
79563ba1 99 // save in CDB storage
100 AliCDBMetaData md;
101 md.SetResponsible("Chiara Oppedisano");
102 md.SetComment("Alignment object for ZDC");
0ce2858d 103 Bool_t resultAl = kTRUE;
cb50c7c8 104 resultAl = Store("Align","Data", array, &md, 0, 0);
79563ba1 105
028eb4a1 106// *************** From DAQ ******************
0ce2858d 107Bool_t resPedCal = kTRUE, resECal = kTRUE, resRecPar = kTRUE;
028eb4a1 108// *****************************************************
109// [a] PEDESTALS -> Pedestal subtraction
110// *****************************************************
06db4c54 111TString runType = GetRunType();
028eb4a1 112printf("\n\t AliZDCPreprocessor -> runType detected %s\n\n",runType.Data());
b12033ab 113if(runType == "PEDESTAL_RUN"){
cb50c7c8 114 TList* daqSources = GetFileSources(kDAQ, "PEDESTALS");
115 if(!daqSources){
116 Log(Form("No source for PEDESTALS run %d !", fRun));
c58c7e82 117 return 1;
79563ba1 118 }
119 Log("\t List of sources for PEDESTALS");
cb50c7c8 120 daqSources->Print();
79563ba1 121 //
cb50c7c8 122 TIter iter(daqSources);
123 TObjString* source = 0;
79563ba1 124 Int_t i=0;
cb50c7c8 125 while((source = dynamic_cast<TObjString*> (iter.Next()))){
79563ba1 126 Log(Form("\n\t Getting file #%d\n",++i));
cb50c7c8 127 TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName());
128 if(stringPedFileName.Length() <= 0){
129 Log(Form("No PEDESTAL file from source %s!", source->GetName()));
c58c7e82 130 return 1;
cb50c7c8 131 }
6024ec85 132 // --- Initializing pedestal calibration object
133 AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
134 // --- Reading file with pedestal calibration data
d5e687c2 135 const char* pedFileName = stringPedFileName.Data();
c0aec6f6 136 // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
d5e687c2 137 const Int_t knZDCch = 48;
138 if(pedFileName){
79563ba1 139 FILE *file;
d5e687c2 140 if((file = fopen(pedFileName,"r")) == NULL){
141 printf("Cannot open file %s \n",pedFileName);
c58c7e82 142 return 1;
79563ba1 143 }
d5e687c2 144 Log(Form("File %s connected to process pedestal data", pedFileName));
145 Float_t pedVal[(3*knZDCch)][2];
146 for(Int_t i=0; i<(3*knZDCch); i++){
79563ba1 147 for(Int_t j=0; j<2; j++){
d5e687c2 148 fscanf(file,"%f",&pedVal[i][j]);
149 //if(j==1) printf("pedVal[%d] -> %f, %f \n",i,pedVal[i][0],pedVal[i][1]);
79563ba1 150 }
d5e687c2 151 if(i<knZDCch){
6024ec85 152 pedCalib->SetMeanPed(i,pedVal[i][0]);
153 pedCalib->SetMeanPedWidth(i,pedVal[i][1]);
79563ba1 154 }
d5e687c2 155 else if(i>=knZDCch && i<(2*knZDCch)){
6024ec85 156 pedCalib->SetOOTPed(i-knZDCch,pedVal[i][0]);
157 pedCalib->SetOOTPedWidth(i-knZDCch,pedVal[i][1]);
79563ba1 158 }
d5e687c2 159 else if(i>=(2*knZDCch) && i<(3*knZDCch)){
6024ec85 160 pedCalib->SetPedCorrCoeff(i-(2*knZDCch),pedVal[i][0],pedVal[i][1]);
79563ba1 161 }
162 }
e1ea0c63 163 }
79563ba1 164 else{
d5e687c2 165 Log(Form("File %s not found", pedFileName));
c58c7e82 166 return 1;
e1ea0c63 167 }
79563ba1 168 //
6024ec85 169 //pedCalib->Print("");
170 //
171 AliCDBMetaData metaData;
172 metaData.SetBeamPeriod(0);
173 metaData.SetResponsible("Chiara");
174 metaData.SetComment("Filling AliZDCPedestals object");
175 //
176 resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, 1);
64a7c78d 177 }
cb50c7c8 178 delete daqSources; daqSources = 0;
04bd7caa 179}
028eb4a1 180// *****************************************************
181// [b] EMD EVENTS -> Energy calibration and equalization
182// *****************************************************
183else if(runType == "PULSER_RUN"){
184 TList* daqSources = GetFileSources(kDAQ, "EMDCALIB");
cb50c7c8 185 if(!daqSources){
028eb4a1 186 AliError(Form("No sources for PULSER_RUN run %d !", fRun));
c58c7e82 187 return 1;
64a7c78d 188 }
028eb4a1 189 Log("\t List of sources for PULSER_RUN");
cb50c7c8 190 daqSources->Print();
e1ea0c63 191 //
cb50c7c8 192 TIter iter2(daqSources);
06db4c54 193 TObjString* source = 0;
79563ba1 194 Int_t j=0;
cb50c7c8 195 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
79563ba1 196 Log(Form("\n\t Getting file #%d\n",++j));
028eb4a1 197 TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName());
cb50c7c8 198 if(stringEMDFileName.Length() <= 0){
028eb4a1 199 Log(Form("No EMDCALIB file from source %s!", source->GetName()));
c58c7e82 200 return 1;
cb50c7c8 201 }
6024ec85 202 // --- Initializing pedestal calibration object
203 AliZDCCalib *eCalib = new AliZDCCalib("ZDC");
204 // --- Reading file with pedestal calibration data
d5e687c2 205 const char* emdFileName = stringEMDFileName.Data();
206 if(emdFileName){
79563ba1 207 FILE *file;
d5e687c2 208 if((file = fopen(emdFileName,"r")) == NULL){
209 printf("Cannot open file %s \n",emdFileName);
c58c7e82 210 return 1;
79563ba1 211 }
d5e687c2 212 Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
b12033ab 213 //
214 Float_t fitValEMD[6]; Float_t equalCoeff[5][4];
d5e687c2 215 Float_t calibVal[4];
028eb4a1 216 for(Int_t j=0; j<10; j++){
217 if(j<6){
218 fscanf(file,"%f",&fitValEMD[j]);
219 if(j<4){
d5e687c2 220 calibVal[j] = fitValEMD[j]/2.76;
6024ec85 221 eCalib->SetEnCalib(j,calibVal[j]);
028eb4a1 222 }
6024ec85 223 else eCalib->SetEnCalib(j,fitValEMD[j]);
028eb4a1 224 }
225 else{
226 for(Int_t k=0; k<5; k++){
227 fscanf(file,"%f",&equalCoeff[j][k]);
6024ec85 228 if(j==6) eCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
229 else if(j==7) eCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
230 else if(j==8) eCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
231 else if(j==9) eCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);
028eb4a1 232 }
233 }
79563ba1 234 }
79563ba1 235 }
236 else{
d5e687c2 237 Log(Form("File %s not found", emdFileName));
c58c7e82 238 return 1;
79563ba1 239 }
240 //calibdata->Print("");
6024ec85 241 //
242 AliCDBMetaData metaData;
243 metaData.SetBeamPeriod(0);
244 metaData.SetResponsible("Chiara");
245 metaData.SetComment("Filling AliZDCCalib object");
246 //
247 resECal = Store("Calib","Calib",eCalib, &metaData, 0, 1);
79563ba1 248 }
b12033ab 249}
250// ********************************************************
251// [c] PHYSICS RUNS -> Parameters needed for reconstruction
252// ********************************************************
253else if(runType == "PHYSICS"){
254 TList* daqSources = GetFileSources(kDAQ, "PHYSICS");
255 if(!daqSources){
256 AliError(Form("No sources for PHYSICS run %d !", fRun));
257 return 1;
258 }
259 Log("\t List of sources for PHYSICS");
260 daqSources->Print();
261 //
262 TIter iter2(daqSources);
263 TObjString* source = 0;
264 Int_t j=0;
265 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
266 Log(Form("\n\t Getting file #%d\n",++j));
267 TString stringPHYSFileName = GetFile(kDAQ, "PHYSICS", source->GetName());
268 if(stringPHYSFileName.Length() <= 0){
269 Log(Form("No PHYSICS file from source %s!", source->GetName()));
270 return 1;
271 }
6024ec85 272 // --- Initializing pedestal calibration object
273 AliZDCRecParam *recCalib = new AliZDCRecParam("ZDC");
274 // --- Reading file with pedestal calibration data
d5e687c2 275 const char* physFileName = stringPHYSFileName.Data();
276 if(physFileName){
b12033ab 277 FILE *file;
d5e687c2 278 if((file = fopen(physFileName,"r")) == NULL){
279 printf("Cannot open file %s \n",physFileName);
b12033ab 280 return 1;
281 }
d5e687c2 282 Log(Form("File %s connected to process data from PHYSICS runs", physFileName));
b12033ab 283 //
d5e687c2 284 Float_t physRecParam[10];
285 for(Int_t j=0; j<10; j++) fscanf(file,"%f",&physRecParam[j]);
6024ec85 286 recCalib->SetZEMEndValue(physRecParam[0]);
287 recCalib->SetZEMCutFraction(physRecParam[1]);
288 recCalib->SetDZEMSup(physRecParam[2]);
289 recCalib->SetDZEMInf(physRecParam[3]);
290 recCalib->SetEZN1MaxValue(physRecParam[4]);
291 recCalib->SetEZP1MaxValue(physRecParam[5]);
292 recCalib->SetEZDC1MaxValue(physRecParam[6]);
293 recCalib->SetEZN2MaxValue(physRecParam[7]);
294 recCalib->SetEZP2MaxValue(physRecParam[8]);
295 recCalib->SetEZDC2MaxValue(physRecParam[9]);
b12033ab 296 }
297 else{
d5e687c2 298 Log(Form("File %s not found", physFileName));
b12033ab 299 return 1;
300 }
301 //calibdata->Print("");
6024ec85 302 //
303 AliCDBMetaData metaData;
304 metaData.SetBeamPeriod(0);
305 metaData.SetResponsible("Chiara");
306 metaData.SetComment("Filling AliZDCCalib object");
307 //
308 resRecPar = Store("Calib","RecParam",recCalib, &metaData, 0, 1);
b12033ab 309 }
c58c7e82 310}
311else {
bff168f8 312 Log(Form("Nothing to do: run type is %s", runType.Data()));
313 return 0;
c58c7e82 314}
028eb4a1 315
e1ea0c63 316 // note that the parameters are returned as character strings!
317 const char* nEvents = GetRunParameter("totalEvents");
79563ba1 318 if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents));
319 else Log(Form("Number of events not put in logbook!"));
79563ba1 320
cb50c7c8 321 UInt_t result = 0;
6024ec85 322 if(resultAl==kFALSE || resPedCal==kFALSE || resECal==kFALSE || resRecPar==kFALSE){
323 if(resultAl == kFALSE) result = 1;
324 else if(resPedCal == kFALSE) result = 2;
325 else if(resECal == kFALSE) result = 3;
326 else if(resRecPar == kFALSE) result = 4;
cb50c7c8 327 }
328
64a7c78d 329 return result;
cb50c7c8 330
64a7c78d 331}