2 - Contact: - henrik.tydesjo@cern.ch
3 - Link: - http://tydes.home.cern.ch/tydes/doc/CalibrationOverview/CalibrationAlgorithms/
6 - Number of events needed:
7 - Input Files: - daq db config files: spd_physics_params , previous dead ref: ./calibResults/DeadReferenceTmp/* , previous dead lists: ./calibResults/DeadToFXS/*
8 - Output Files: - Ref Data: ./calibResults/NoisyReference/* , Ref Data: ./calibResults/DeadReference/* , noisy lists: ./calibResults/NoisyToFXS/* , persistent files: ./calibResults/DeadReferenceTmp/*,./calibResults/DeadToFXS/*
9 - Trigger types used: PHYSICS
12 ////////////////////////////////////////////////////////////////////////////////
13 // This program can be compiled in two modes. //
15 // 1. Online. With the DAQ DA framework. This is the default operating mode. //
17 // 2. Offline. Without the DAQ DA framework. Define the SPD_DA_OFF //
18 // environment var. Call this program with the name of the executable //
19 // followed by the runNr and the data files to process. //
21 ////////////////////////////////////////////////////////////////////////////////
30 #include "AliRawReaderDate.h"
31 #include "AliITSRawStreamSPD.h"
32 #include "AliITSOnlineSPDphys.h"
33 #include "AliITSOnlineSPDphysAnalyzer.h"
34 #include "AliITSOnlineCalibrationSPDhandler.h"
39 #include <TPluginManager.h>
40 #include <TObjArray.h>
43 int main(int argc, char **argv) {
45 printf("Wrong number of arguments\n");
49 // directory structure, hard coded
50 char *saveDirDead = "./calibResults/Dead"; // may NOT delete content
51 char *saveDirDeadToFXS = "./calibResults/DeadToFXS"; // may delete content
52 char *saveDirDeadRef = "./calibResults/DeadReference"; // may delete content
53 char *saveDirDeadRefTmp = "./calibResults/DeadReferenceTmp"; // may NOT delete content
54 char *saveDirNoisyToFXS = "./calibResults/NoisyToFXS"; // may delete content
55 char *saveDirNoisyRef = "./calibResults/NoisyReference"; // may delete content
56 char *saveDirIdsToFXS = "./calibResults/IdsToFXS"; // may delete content
57 char *configFilesDir = "./configFiles"; // may delete content
58 // make sure the directory structure is put up correctly:
59 system("mkdir ./calibResults >& /dev/null");
60 system("mkdir ./calibResults/Dead >& /dev/null");
61 system("mkdir ./calibResults/DeadToFXS >& /dev/null");
62 system("mkdir ./calibResults/DeadReference >& /dev/null");
63 system("mkdir ./calibResults/DeadReferenceTmp >& /dev/null");
64 system("mkdir ./calibResults/NoisyToFXS >& /dev/null");
65 system("mkdir ./calibResults/NoisyReference >& /dev/null");
66 system("mkdir ./calibResults/IdsToFXS >& /dev/null");
67 system("mkdir ./configFiles >& /dev/null");
68 // parameters config file
69 TString paramsFileName = Form("%s/physics_params.txt",configFilesDir);
71 // This line is needed in case of a stand-alone application w/o
72 // $ROOTSYS/etc/system.rootrc file
73 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
79 // turn off annoying warning messages
81 AliLog::Instance()->SetGlobalDebugLevel(-20);
84 // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters*********
85 UInt_t nrTuningParams = 0;
86 TObjArray paramNames; paramNames.SetOwner(kTRUE);
87 TObjArray paramVals; paramVals.SetOwner(kTRUE);
92 TString idp = "spd_physics_params";
93 par_status=daqDA_DB_getFile(idp.Data(),paramsFileName.Data());
95 printf("Failed to get config file %s: status=%d. Using default tuning parameters.\n",idp.Data(),par_status);
100 paramsFile.open(paramsFileName.Data(), ifstream::in);
101 if (paramsFile.fail()) {
102 printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
108 paramsFile >> paramN;
109 if (paramsFile.eof()) break;
110 paramsFile >> paramV;
111 TString* paramNS = new TString(paramN);
112 TString* paramVS = new TString(paramV);
113 paramNames.AddAtAndExpand((TObject*)paramNS,nrTuningParams);
114 paramVals.AddAtAndExpand((TObject*)paramVS,nrTuningParams);
116 if (paramsFile.eof()) break;
121 // for (UInt_t i=0; i<nrTuningParams; i++) {
122 // printf("Entry %d: N=%s , V=%s\n",i,((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data());
129 // ********* STEP 1: Produce phys container files (Reference Data). ***********************************
132 int runNr = atoi(getenv("DATE_RUN_NUMBER"));
134 int runNr = atoi(argv[1]);
140 AliITSOnlineSPDphys *physObj[20];
141 Bool_t bPhysInit[20];
142 for (UInt_t eqId=0; eqId<20; eqId++) {
144 bPhysInit[eqId]=kFALSE;
148 // loop over run segments in case of offline mode
150 for (int segNr=startSeg; segNr<argc; segNr++) {
155 /* define data source : */
157 status=monitorSetDataSource( argv[1] ); // should be "^SPD" in order to get full detector online
159 status=monitorSetDataSource( argv[segNr] );
162 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
165 /* declare monitoring program */
166 status=monitorDeclareMp("ITS_SPD_PHYS");
168 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
171 /* define wait event timeout - 1s max */
173 monitorSetNoWaitNetworkTimeout(1000);
178 /* main loop (infinite) */
181 struct eventHeaderStruct *event;
182 eventTypeType eventT;
184 /* check shutdown condition */
186 if (daqDA_checkShutdown()) {break;}
189 /* get next event (blocking call until timeout) */
190 status=monitorGetEventDynamic((void **)&event);
191 if (status==MON_ERR_EOF) {
192 printf ("End of File detected\n");
193 break; /* end of monitoring file has been reached */
197 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
201 /* retry if got no event */
206 eventT=event->eventType;
207 if (eventT == PHYSICS_EVENT){
210 // printf("eventNr %d\n",eventNr);
212 AliRawReader *reader = new AliRawReaderDate((void*)event);
213 AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader);
215 // for (UInt_t eqId=0; eqId<20; eqId++) {
217 // reader->Select("ITSSPD",eqId,eqId);
219 while (str->Next()) {
221 Int_t eqId = reader->GetDDLID();
222 if (eqId>=0 && eqId<20) {
223 if (!bPhysInit[eqId]) {
224 TString fileName = Form("%s/SPDphys_run_%d_eq_%d.root",saveDirNoisyRef,runNr,eqId);
225 physObj[eqId] = new AliITSOnlineSPDphys(fileName.Data());
226 physObj[eqId]->AddRunNr(runNr);
227 physObj[eqId]->SetEqNr(eqId);
228 bPhysInit[eqId]=kTRUE;
231 UInt_t hs = str->GetHalfStaveNr();
232 UInt_t chip = str->GetChipAddr();
233 physObj[eqId]->IncrementHits(hs,chip,str->GetChipCol(),str->GetChipRow());
238 for (UInt_t eqId=0; eqId<20; eqId++) {
239 if (bPhysInit[eqId]) {
240 physObj[eqId]->IncrementNrEvents();
258 printf("progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 ));
262 // clean up phys objects (also saves them)
263 for (UInt_t eqId=0; eqId<20; eqId++) {
264 if (physObj[eqId]!=NULL) delete physObj[eqId];
271 // ********* STEP 2: Analyze phys container files. ************************************************
273 // clear noisyToFXS dir:
275 command = Form("cd %s; rm -f *",saveDirNoisyToFXS);
276 system(command.Data());
277 // clear deadToFXS dir:
278 command = Form("cd %s; rm -f *",saveDirDeadToFXS);
279 system(command.Data());
282 // create calibration handler and read dead from previous calibrations
283 AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
284 handler->SetFileLocation(saveDirDead);
285 handler->ReadDeadFromFiles();
288 UInt_t firstRunNrDead = runNr;
291 UInt_t nrEnoughStatNoisy = 0;
292 UInt_t nrEqActiveNoisy = 0;
293 Bool_t eqActiveNoisy[20];
295 // *** *** *** start loop over equipments (eq_id)
296 for (UInt_t eqId=0; eqId<20; eqId++) {
297 eqActiveNoisy[eqId] = kFALSE;
299 // create analyzer for this eq
300 TString fileName = Form("%s/SPDphys_run_%d_eq_%d.root",saveDirNoisyRef,runNr,eqId);
301 AliITSOnlineSPDphysAnalyzer *noisyAnalyzer = new AliITSOnlineSPDphysAnalyzer(fileName.Data(),handler);
303 // check data in container
304 if (noisyAnalyzer->GetEqNr() != eqId) {
305 if (noisyAnalyzer->GetEqNr() != 999) {
306 printf("Error: Mismatching EqId in Container data and filename (%d!=%d). Skipping.\n",
307 noisyAnalyzer->GetEqNr(),eqId);
309 delete noisyAnalyzer;
314 eqActiveNoisy[eqId] = kTRUE;
316 // configure analyzer with tuning parameters etc:
317 for (UInt_t i=0; i<nrTuningParams; i++) {
318 noisyAnalyzer->SetParam(((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data());
321 printf("SPD phys STEP 2: Noisy search for eq %d\n",eqId);
323 // search for noisy pixels:
324 nrEnoughStatNoisy += noisyAnalyzer->ProcessNoisyPixels();
326 // copy this phys obj to temporary dead reference dir to process after noisy search
327 TString fileNameDead = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eqId);
328 AliITSOnlineSPDphys* physObj = new AliITSOnlineSPDphys(fileNameDead.Data());
329 physObj->AddPhys(noisyAnalyzer->GetOnlinePhys());
330 if (physObj->GetNrRuns()>0) {
331 UInt_t firstRunNr = physObj->GetRunNr(0);
332 if (firstRunNrDead>firstRunNr) {
333 firstRunNrDead=firstRunNr;
336 // remove noisy pixels from dead hitmap
337 for (UInt_t hs=0; hs<6; hs++) {
338 for (UInt_t chip=0; chip<10; chip++) {
339 for (UInt_t ind=0; ind<handler->GetNrNoisyC(eqId,hs,chip); ind++) {
340 UInt_t col = handler->GetNoisyColAtC(eqId,hs,chip,ind);
341 UInt_t row = handler->GetNoisyRowAtC(eqId,hs,chip,ind);
342 physObj->AddHits(hs,chip,col,row,-noisyAnalyzer->GetOnlinePhys()->GetHits(hs,chip,col,row));
348 delete noisyAnalyzer;
351 daqDA_progressReport((unsigned int)((eqId+1)*2.5));
353 printf("progress: %d\n",(unsigned int)(50+(eqId+1)*1.25));
356 // *** *** *** end loop over equipments (eq_id)
358 printf("Noisy search finished. %d noisy pixels found. %d chips (%d) had enough statistics.\n",
359 handler->GetNrNoisy(),nrEnoughStatNoisy,nrEqActiveNoisy*60);
360 handler->SetFileLocation(saveDirNoisyToFXS);
361 handler->WriteNoisyToFiles();
370 UInt_t nrEnoughStatChips = 0;
371 UInt_t nrDeadChips = 0;
372 UInt_t nrInefficientChips = 0;
373 UInt_t nrEqActiveDead = 0;
374 Bool_t eqActiveDead[20];
376 // *** *** *** start loop over equipments (eq_id)
377 for (UInt_t eqId=0; eqId<20; eqId++) {
378 eqActiveDead[eqId] = kFALSE;
380 // setup analyzer for dead search
381 TString fileNameDead = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eqId);
382 AliITSOnlineSPDphys* physObj = new AliITSOnlineSPDphys(fileNameDead.Data());
383 AliITSOnlineSPDphysAnalyzer* deadAnalyzer = new AliITSOnlineSPDphysAnalyzer(physObj,handler);
384 // check data in container
385 if (deadAnalyzer->GetEqNr() != eqId) {
386 if (deadAnalyzer->GetEqNr() != 999) {
387 printf("Error: Mismatching EqId in Dead Container data and filename (%d!=%d). Skipping.\n",
388 deadAnalyzer->GetEqNr(),eqId);
395 eqActiveDead[eqId] = kTRUE;
397 // configure analyzer with tuning parameters etc:
398 for (UInt_t i=0; i<nrTuningParams; i++) {
399 deadAnalyzer->SetParam(((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data());
402 printf("SPD phys STEP 2: Dead search for eq %d\n",eqId);
404 // search for dead pixels:
405 nrEnoughStatChips += deadAnalyzer->ProcessDeadPixels();
406 nrDeadChips += deadAnalyzer->GetNrDeadChips();
407 nrInefficientChips += deadAnalyzer->GetNrInefficientChips();
412 daqDA_progressReport((unsigned int)(50+(eqId+1)*2.5));
414 printf("progress: %d\n",(unsigned int)(75+(eqId+1)*1.25));
417 // *** *** *** end loop over equipments (eq_id)
420 printf("Dead search finished. %d dead pixels in total.\n%d chips (%d) had enough statistics. %d chips were dead. %d chips were inefficient.\n",handler->GetNrDead(),nrEnoughStatChips,nrEqActiveDead*60,nrDeadChips,nrInefficientChips);
421 handler->SetFileLocation(saveDirDead);
422 handler->WriteDeadToFilesAlways();
424 handler->SetFileLocation(saveDirDeadToFXS);
425 handler->WriteDeadToFilesAlways();
426 // *** old code (used if not all dead data should be uploaded)
427 // UInt_t nrDeadFilesToTar = 0;
428 // handler->SetFileLocation(saveDirDeadToFXS);
429 // for (UInt_t eqId=0; eqId<20; eqId++) {
430 // if (eqActiveDead[eqId]) {
431 // handler->WriteDeadToFile(eqId);
432 // nrDeadFilesToTar++;
437 TString idsFXSFileName = Form("%s/FXSids_run_%d.txt",saveDirIdsToFXS,runNr);
439 idsFXSfile.open(idsFXSFileName.Data());
442 // if there is no chip in category "needsMoreStat"
443 if (nrEnoughStatChips+nrDeadChips+nrInefficientChips == nrEqActiveDead*60) {
444 // calibration is complete
445 printf("Dead calibration is complete.\n");
449 // send reference data for dead pixels to FXS
450 TString tarFiles = "";
451 for (UInt_t eqId=0; eqId<20; eqId++) {
452 if (eqActiveDead[eqId]) {
453 // move file to ref dir
454 TString fileName = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eqId);
455 TString newFileName = Form("%s/SPDphys_dead_run_%d_%d_eq_%d.root",saveDirDeadRef,firstRunNrDead,runNr,eqId);
456 TString command = Form("mv -f %s %s",fileName.Data(),newFileName.Data());
457 system(command.Data());
459 tarFiles.Append(Form("SPDphys_dead_run_%d_%d_eq_%d.root ",firstRunNrDead,runNr,eqId));
462 TString send_command = Form("cd %s; tar -cf ref_phys_dead.tar %s",saveDirDeadRef,tarFiles.Data());
463 system(send_command.Data());
464 TString fileName = Form("%s/ref_phys_dead.tar",saveDirDeadRef);
465 TString id = "SPD_ref_phys_dead";
467 status = daqDA_FES_storeFile(fileName.Data(),id.Data());
469 printf("Failed to export file %s , status %d\n",fileName.Data(),status);
473 idsFXSfile << Form("%s\n",id.Data());
474 // for (UInt_t eqId=0; eqId<20; eqId++) { // OLD CODE NOT TARED
475 // if (eqActiveDead[eqId]) {
476 // TString fileName = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eqId);
477 // // move file to ref dir
478 // TString newFileName = Form("%s/SPDphys_dead_run_%d_%d_eq_%d.root",saveDirDeadRef,firstRunNrDead,runNr,eqId);
479 // TString command = Form("mv -f %s %s",fileName.Data(),newFileName.Data());
480 // system(command.Data());
481 // // send ref data to FXS
482 // TString id = Form("SPD_ref_phys_dead_%d",eqId);
484 // Int_t status = daqDA_FES_storeFile(newFileName.Data(),id.Data());
486 // printf("Failed to export file %s , status %d\n",newFileName.Data(),status);
490 // idsFXSfile << Form("%s\n",id.Data());
493 // TString command = Form("rm -f %s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eqId);
494 // system(command.Data());
500 // send reference data for this run to FXS
501 TString tarFiles = "";
502 for (UInt_t eqId=0; eqId<20; eqId++) {
503 if (eqActiveNoisy[eqId]) {
504 tarFiles.Append(Form("SPDphys_run_%d_eq_%d.root ",runNr,eqId));
507 TString send_command = Form("cd %s; tar -cf ref_phys.tar %s",saveDirNoisyRef,tarFiles.Data());
508 system(send_command.Data());
509 TString fileName = Form("%s/ref_phys.tar",saveDirNoisyRef);
510 TString id = "SPD_ref_phys";
512 status = daqDA_FES_storeFile(fileName.Data(),id.Data());
514 printf("Failed to export file %s , status %d\n",fileName.Data(),status);
518 idsFXSfile << Form("%s\n",id.Data());
521 // // send reference data for this run to FXS - OLD CODE NOT TARED
522 // for (UInt_t eqId=0; eqId<20; eqId++) {
523 // if (eqActiveNoisy[eqId]) {
524 // TString fileName = Form("%s/SPDphys_run_%d_eq_%d.root",saveDirNoisyRef,runNr,eqId);
525 // TString id = Form("SPD_ref_phys_%d",eqId);
527 // Int_t status = daqDA_FES_storeFile(fileName.Data(),id.Data());
529 // printf("Failed to export file %s , status %d\n",fileName.Data(),status);
532 // idsFXSfile << Form("%s\n",id.Data());
538 // send dead pixels to FXS
539 // if (nrDeadFilesToTar>0) { //*** old code (used if not all dead data should be uploaded)
540 // send a tared file of all the dead files
541 send_command = Form("cd %s; tar -cf dead_phys.tar *",saveDirDeadToFXS);
542 // printf("\n\n%s\n\n",command.Data());
543 system(send_command.Data());
544 fileName = Form("%s/dead_phys.tar",saveDirDeadToFXS);
545 id = "SPD_phys_dead";
547 Int_t send_status = daqDA_FES_storeFile(fileName.Data(),id.Data());
548 if (send_status!=0) {
549 printf("Failed to export file %s , status %d\n",fileName.Data(),send_status);
553 idsFXSfile << Form("%s\n",id.Data());
554 // } //*** old code (used if not all dead data should be uploaded)
557 // send noisy pixels to FXS
558 if (handler->GetNrNoisy()>0) { // there must be at least one file created
559 // send a tared file of all the noisy files
560 TString command = Form("cd %s; tar -cf noisy_phys.tar *",saveDirNoisyToFXS);
561 // printf("\n\n%s\n\n",command.Data());
562 system(command.Data());
563 TString fileName = Form("%s/noisy_phys.tar",saveDirNoisyToFXS);
564 TString id = "SPD_phys_noisy";
566 status = daqDA_FES_storeFile(fileName.Data(),id.Data());
568 printf("Failed to export file %s , status %d\n",fileName.Data(),status);
572 idsFXSfile << Form("%s\n",id.Data());
576 // send ids file to FXS
580 status = daqDA_FES_storeFile(idsFXSFileName.Data(),id.Data());
582 printf("Failed to export file %s , status %d\n",fileName.Data(),status);