2 Contact: Jean-Luc Charvet <jean-luc.charvet@cea.fr>
3 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_Mchda
4 Run Type: PEDESTAL, CALIBRATION
6 Number of events needed: 400 events for pedestal and each calibration run
7 Input Files: Rawdata file (DATE format)
8 Output Files: local dir (not persistent) -> MUONTRKda_ped_<run#>.ped , MUONTRKda_gain_<run#>.par
9 FXS -> run<#>_MCH_<ldc>_PEDESTALS, run<#>_MCH_<ldc>_GAINS
13 /**************************************************************************
14 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
16 * Author: The ALICE Off-line Project. *
17 * Contributors are mentioned in the code where appropriate. *
19 * Permission to use, copy, modify and distribute this software and its *
20 * documentation strictly for non-commercial purposes is hereby granted *
21 * without fee, provided that the above copyright notice appears in all *
22 * copies and that both the copyright notice and this permission notice *
23 * appear in the supporting documentation. The authors make no claims *
24 * about the suitability of this software for any purpose. It is *
25 * provided "as is" without express or implied warranty. *
26 **************************************************************************/
31 -------------------------------------------------------------------------
32 2008-04-16 New version: MUONTRKda.cxx,v 1.12
33 -------------------------------------------------------------------------
35 Version for MUONTRKda MUON tracking
36 (A. Baldisseri, J.-L. Charvet & Ch. Finck)
39 Rem: AliMUON2DMap stores all channels, even those which are not connected
40 if pedMean == -1, channel not connected to a pad
51 #include <Riostream.h>
57 #include "AliMUONLogger.h"
58 #include "AliMUONRawStreamTracker.h"
59 #include "AliMUONDspHeader.h"
60 #include "AliMUONBlockHeader.h"
61 #include "AliMUONBusStruct.h"
62 #include "AliMUONDDLTracker.h"
63 #include "AliMUONVStore.h"
64 #include "AliMUON2DMap.h"
65 #include "AliMUONCalibParamND.h"
66 #include "AliMpIntPair.h"
67 #include "AliMpConstants.h"
68 #include "AliRawReaderDate.h"
76 #include "TStopwatch.h"
78 #include "TTimeStamp.h"
79 #include "TGraphErrors.h"
82 #include "TPluginManager.h"
88 const Int_t gkNChannels = AliMpConstants::ManuNofChannels();
89 const Int_t gkADCMax = 4095;
91 AliMUONVStore* gPedestalStore = new AliMUON2DMap(kFALSE);
95 UInt_t gRunNumber = 0;
97 Int_t gNDateEvents = 0;
98 Int_t gPrintLevel = 1; // global printout variable (others: 2 and 3)
99 Int_t gPlotLevel = 0; // global plot variable
100 Int_t gFES = 1; // by default FES is used
102 TH1F* gPedMeanHisto = 0x0;
103 TH1F* gPedSigmaHisto = 0x0;
104 Char_t gHistoFileName[256];
106 // used for computing gain parameters
107 Int_t nbpf1 = 6; // linear fit over nbf1 points
109 //Char_t gHistoFileName_gain[256]="MUONTRKda_gain_data.root";
110 Char_t gHistoFileName_gain[256]="MUONTRKda_gain.data";
111 Char_t gRootFileName[256];
112 Char_t gOutFolder[256]=".";
113 Char_t filename[256];
114 Char_t filenam[256]="MUONTRKda_gain";
115 Char_t flatFile[256]="";
119 TString flatOutputFile;
120 TString logOutputFile;
121 TString logOutputFile_comp;
122 TString gCommand("ped");
129 Double_t funcLin(Double_t *x, Double_t *par)
131 return par[0] + par[1]*x[0];
135 Double_t funcParabolic(Double_t *x, Double_t *par)
137 return par[0]*x[0]*x[0];
141 Double_t funcCalib(Double_t *x, Double_t *par)
143 Double_t xLim= par[3];
145 if(x[0] <= xLim) return par[0] + par[1]*x[0];
147 Double_t yLim = par[0]+ par[1]*xLim;
148 return yLim + par[1]*(x[0] - xLim) + par[2]*(x[0] - xLim)*(x[0] - xLim);
153 void MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
156 AliMUONVCalibParam* ped =
157 static_cast<AliMUONVCalibParam*>(gPedestalStore->FindObject(busPatchId, manuId));
161 ped = new AliMUONCalibParamND(2, gkNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
162 gPedestalStore->Add(ped);
166 ped->SetValueAsDouble(channelId, 0, 0.);
167 ped->SetValueAsDouble(channelId, 1, 0.);
170 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + charge;
171 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + charge*charge;
173 ped->SetValueAsDouble(channelId, 0, pedMean);
174 ped->SetValueAsDouble(channelId, 1, pedSigma);
179 void MakePedStore(TString flatOutputFile = "")
190 TFile* histoFile = 0;
192 if (gCommand.CompareTo("ped") == 0)
194 sprintf(gHistoFileName,"%s/MUONTRKda_ped_%d.root",gOutFolder,gRunNumber);
195 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
199 sprintf(name,"pedmean_allch");
200 sprintf(title,"Pedestal mean all channels");
204 gPedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
205 gPedMeanHisto->SetDirectory(histoFile);
207 sprintf(name,"pedsigma_allch");
208 sprintf(title,"Pedestal sigma all channels");
212 gPedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
213 gPedSigmaHisto->SetDirectory(histoFile);
215 tree = new TTree("t","Pedestal tree");
216 tree->Branch("bp",&busPatchId,"bp/I");
217 tree->Branch("manu",&manuId,",manu/I");
218 tree->Branch("channel",&channelId,",channel/I");
219 tree->Branch("pedMean",&pedMean,",pedMean/D");
220 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
223 if (!flatOutputFile.IsNull()) {
224 fileout.open(flatOutputFile.Data());
225 fileout<<"//===========================================================================" << endl;
226 fileout<<"// Pedestal file calculated by MUONTRKda"<<endl;
227 fileout<<"//===========================================================================" << endl;
228 fileout<<"// * Run : " << gRunNumber << endl;
229 fileout<<"// * Date : " << date.AsString("l") <<endl;
230 fileout<<"// * Statictics : " << gNEvents << endl;
231 fileout<<"// * # of MANUS : " << gNManu << endl;
232 fileout<<"// * # of channels : " << gNChannel << endl;
234 fileout<<"//---------------------------------------------------------------------------" << endl;
235 fileout<<"//---------------------------------------------------------------------------" << endl;
236 fileout<<"// BP MANU CH. MEAN SIGMA"<<endl;
237 fileout<<"//---------------------------------------------------------------------------" << endl;
241 // iterator over pedestal
242 TIter next(gPedestalStore->CreateIterator());
243 AliMUONVCalibParam* ped;
245 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
247 busPatchId = ped->ID0();
250 for (channelId = 0; channelId < ped->Size() ; ++channelId) {
252 pedMean = ped->ValueAsDouble(channelId, 0);
254 if (pedMean > 0) { // connected channels
256 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)gNEvents);
258 pedMean = ped->ValueAsDouble(channelId, 0);
259 pedSigma = ped->ValueAsDouble(channelId, 1);
261 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)gNEvents - pedMean*pedMean)));
263 pedMean = ped->ValueAsDouble(channelId, 0) + 0.5 ;
264 // pedMean = ped->ValueAsDouble(channelId, 0) ;
265 pedSigma = ped->ValueAsDouble(channelId, 1);
268 if (!flatOutputFile.IsNull()) {
269 fileout << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t"
270 << pedMean <<"\t"<< pedSigma << endl;
273 if (gCommand.CompareTo("ped") == 0)
275 gPedMeanHisto->Fill(pedMean);
276 gPedSigmaHisto->Fill(pedSigma);
285 if (!flatOutputFile.IsNull()) fileout.close();
287 if (gCommand.CompareTo("ped") == 0)
298 void MakePedStoreForGain(Int_t injCharge)
300 // store pedestal map in root file
302 // Int_t injCharge = 200;
307 if (gCommand.Contains("gain") && !gCommand.Contains("comp")) {
308 if(flatOutputFile.IsNull())
310 sprintf(filename,"%s_%d_DAC_%d.par",filenam,gRunNumber,injCharge);
311 flatOutputFile=filename;
313 if(!flatOutputFile.IsNull())
315 pfilew = fopen (flatOutputFile.Data(),"w");
317 fprintf(pfilew,"//DUMMY FILE (to prevent Shuttle failure)\n");
318 fprintf(pfilew,"//================================================\n");
319 fprintf(pfilew,"// MUONTRKda: Calibration run \n");
320 fprintf(pfilew,"//=================================================\n");
321 fprintf(pfilew,"// * Run : %d \n",gRunNumber);
322 fprintf(pfilew,"// * Date : %s \n",date.AsString("l"));
323 fprintf(pfilew,"// * DAC : %d \n",injCharge);
324 fprintf(pfilew,"//-------------------------------------------------\n");
331 // compute and store pedestals
332 sprintf(flatFile,"%s/%s_%d_DAC_%d.ped",gOutFolder,filenam,gRunNumber,injCharge);
333 cout << "\nMUONTRKda : Flat file generated : " << flatFile << "\n";
334 MakePedStore(flatFile);
339 TString mode("UPDATE");
341 if (gCommand.Contains("cre")) {
344 TFile* histoFile = new TFile(gHistoFileName_gain, mode.Data(), "MUON Tracking Gains");
346 // second argument should be the injected charge, taken from config crocus file
347 // put also info about run number could be usefull
348 AliMpIntPair* pair = new AliMpIntPair(gRunNumber, injCharge);
350 if (mode.CompareTo("UPDATE") == 0) {
351 tree = (TTree*)histoFile->Get("t");
352 tree->SetBranchAddress("run",&pair);
353 tree->SetBranchAddress("ped",&gPedestalStore);
356 tree = new TTree("t","Pedestal tree");
357 tree->Branch("run", "AliMpIntPair",&pair);
358 tree->Branch("ped", "AliMUON2DMap",&gPedestalStore);
359 tree->SetBranchAddress("run",&pair);
360 tree->SetBranchAddress("ped",&gPedestalStore);
365 tree->Write("t", TObject::kOverwrite); // overwrite the tree
372 // void MakeGainStore(TString flatOutputFile)
377 Double_t goodA1Min = 0.5;
378 Double_t goodA1Max = 2.;
379 // Double_t goodA1Min = 0.7;
380 // Double_t goodA1Max = 1.7;
381 Double_t goodA2Min = -0.5E-03;
382 Double_t goodA2Max = 1.E-03;
384 Int_t num_RUN[15],val_DAC[15];
386 // open file mutrkgain.root
387 // read again the pedestal for the calibration runs (9 runs ?)
388 // need the injection charge from config file (to be done)
389 // For each channel make a TGraphErrors (mean, sigma) vs injected charge
390 // Fit with a polynomial fct
391 // store the result in a flat file.
394 TFile* histoFile = new TFile(gHistoFileName_gain);
396 AliMUON2DMap* map[11];
397 AliMUONVCalibParam* ped[11];
398 AliMpIntPair* run[11];
400 //read back from root file
401 TTree* tree = (TTree*)histoFile->Get("t");
402 Int_t nEntries = tree->GetEntries();
405 for (Int_t i = 0; i < nEntries; ++i) {
408 tree->SetBranchAddress("ped",&map[i]);
409 tree->SetBranchAddress("run",&run[i]);
411 // std::cout << map[i] << " " << run[i] << std::endl;
413 //jlc_feb_08 modif: gRunNumber=(UInt_t)run[0]->GetFirst();
414 gRunNumber=(UInt_t)run[nEntries-1]->GetFirst();
415 // sscanf(getenv("DATE_RUN_NUMBER"),"%d",&gRunNumber);
419 cout<<"\n ******** MUONTRKda for Gain computing (Run = " << gRunNumber << ")\n" << endl;
420 cout<<" * Date : " << date.AsString("l") << "\n" << endl;
421 cout << " Entries = " << nEntries << " DAC values \n" << endl;
422 for (Int_t i = 0; i < nEntries; ++i) {
423 cout<< " Run = " << (Double_t)run[i]->GetFirst() << " DAC = " << (Double_t)run[i]->GetSecond() << endl;
424 num_RUN[i]=(Double_t)run[i]->GetFirst();
425 val_DAC[i]=(Double_t)run[i]->GetSecond();
430 Double_t pedMean[11];
431 Double_t pedSigma[11];
432 Double_t injCharge[11];
433 Double_t injChargeErr[11];
437 sprintf(filename,"%s/%s_%d.log",gOutFolder,filenam,gRunNumber);
438 logOutputFile_comp=filename;
440 filcouc.open(logOutputFile_comp.Data());
441 filcouc<<"//====================================================" << endl;
442 filcouc<<"// MUONTRKda for Gain computing (Run = " << gRunNumber << ")" << endl;
443 filcouc<<"//====================================================" << endl;
444 filcouc<<"// * Date : " << date.AsString("l") << "\n" << endl;
448 // why 2 files ? (Ch. F.)
453 sprintf(filename,"%s/%s_%d.param",gOutFolder,filenam,gRunNumber);
454 cout << " fit parameter file = " << filename << "\n";
455 pfilen = fopen (filename,"w");
457 fprintf(pfilen,"//===================================================================\n");
458 fprintf(pfilen,"// BP MANU CH. a0 a1 a2 xlim P(chi2) P(chi2)2 Q\n");
459 fprintf(pfilen,"//===================================================================\n");
460 fprintf(pfilen,"// * Run : %d \n",gRunNumber);
461 fprintf(pfilen,"//===================================================================\n");
463 sprintf(filename,"%s/%s_%d.bad",gOutFolder,filenam,gRunNumber);
464 cout << " Bad channel file = " << filename << "\n";
465 pfilef = fopen (filename,"w");
467 fprintf(pfilef,"//=================================================\n");
468 fprintf(pfilef,"// Bad Channel file calculated by MUONTRKda \n");
469 fprintf(pfilef,"//=================================================\n");
470 fprintf(pfilef,"// * Run : %d \n",gRunNumber);
471 fprintf(pfilef,"// * Date : %s \n",date.AsString("l"));
472 fprintf(pfilef,"//=======================================\n");
473 fprintf(pfilef,"// BP MANU CH. a1 a2 thres. Q\n");
474 fprintf(pfilef,"//=======================================\n");
478 if(flatOutputFile.IsNull())
480 sprintf(filename,"%s_%d.par",filenam,gRunNumber);
481 flatOutputFile=filename;
483 if(!flatOutputFile.IsNull())
485 pfilew = fopen (flatOutputFile.Data(),"w");
487 fprintf(pfilew,"//================================================\n");
488 fprintf(pfilew,"// Calibration file calculated by MUONTRKda \n");
489 fprintf(pfilew,"//=================================================\n");
490 fprintf(pfilew,"// * Run : %d \n",gRunNumber);
491 fprintf(pfilew,"// * Date : %s \n",date.AsString("l"));
492 fprintf(pfilew,"// * Statictics : %d \n",gNEvents);
493 fprintf(pfilew,"// * # of MANUS : %d \n",gNManu);
494 fprintf(pfilew,"// * # of channels : %d \n",gNChannel);
495 fprintf(pfilew,"//-------------------------------------------------\n");
496 fprintf(pfilew,"// %d DAC values \n",nEntries);
497 fprintf(pfilew,"// RUN DAC \n");
498 fprintf(pfilew,"//-----------------\n");
499 for (Int_t i = 0; i < nEntries; ++i) {
500 tree->SetBranchAddress("run",&run[i]);
501 fprintf(pfilew,"// %d %d \n",num_RUN[i],val_DAC[i]);
503 fprintf(pfilew,"//=======================================\n");
504 fprintf(pfilew,"// BP MANU CH. a1 a2 thres. Q\n");
505 fprintf(pfilew,"//=======================================\n");
511 sprintf(filename,"%s/%s_%d.peak",gOutFolder,filenam,gRunNumber);
512 cout << " File containing Peak mean values = " << filename << "\n";
513 pfilep = fopen (filename,"w");
515 fprintf(pfilep,"//===============================================================================================================================\n");
516 fprintf(pfilep,"// * Run : %d \n",gRunNumber);
517 fprintf(pfilep,"//===============================================================================================================================\n");
518 fprintf(pfilep,"// BP MANU CH. Ped. <0> <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> \n");
519 // fprintf(pfilep,"// %9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f fC\n",level_fC[0],level_fC[1],level_fC[2],level_fC[3],level_fC[4],level_fC[5],level_fC[6],level_fC[7],level_fC[8],level_fC[9],level_fC[10]);
520 // fprintf(pfilep,"// %9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f\n",level_err[0],level_err[1],level_err[2],level_err[3],level_err[4],level_err[5],level_err[6],level_err[7],level_err[8],level_err[9],level_err[10]);
521 fprintf(pfilep,"//===============================================================================================================================\n");
528 TFile* gainFile = 0x0;
529 sprintf(gRootFileName,"%s/%s_%d.root",gOutFolder,filenam,gRunNumber);
530 gainFile = new TFile(gRootFileName,"RECREATE");
533 Double_t chi2P2 = 0.;
535 Double_t prChi2P2 =0;
536 Double_t a0=0.,a1=1.,a2=0.;
545 Double_t capa=0.2; // internal capacitor (pF)
547 TTree *tg = new TTree("tg","TTree avec class Manu_DiMu");
549 tg->Branch("bp",&busPatchId, "busPatchId/I");
550 tg->Branch("manu",&manuId, "manuId/I");
551 tg->Branch("channel",&channelId, "channelId/I");
553 tg->Branch("a0",&a0, "a0/D");
554 tg->Branch("a1",&a1, "a1/D");
555 tg->Branch("a2",&a2, "a2/D");
556 tg->Branch("Pchi2",&prChi2, "prChi2/D");
557 tg->Branch("Pchi2_2",&prChi2P2, "prChi2P2/D");
558 tg->Branch("Threshold",&threshold, "threshold/I");
559 tg->Branch("Q",&Q, "Q/I");
560 tg->Branch("p1",&p1, "p1/I");
561 tg->Branch("p2",&p2, "p2/I");
562 tg->Branch("gain",&gain, "gain/D");
564 // bad BusPatch and manu
565 Int_t num_tot_BP=800;
566 Int_t num_tot_Manu=1500;
567 // Int_t bad_channel[num_tot_BP][num_tot_Manu];
568 Int_t bad_channel[800][1500];
569 for ( Int_t i = 0; i < num_tot_BP ; i++ )
570 { for ( Int_t j = 0; j < num_tot_Manu ; j++ ) bad_channel[i][j]=0;}
575 // iterates over the first pedestal run
576 TIter next(map[0]->CreateIterator());
577 AliMUONVCalibParam* p;
580 Int_t nGoodChannel = 0;
581 Int_t nGoodChannel_a1 = 0;
582 Int_t nBadChannel = 0;
583 Int_t nBadChannel_a1 = 0;
584 Int_t nBadChannel_a2 = 0;
586 Double_t sumProbChi2 = 0.;
588 Double_t sumProbChi2P2 = 0.;
591 Double_t x[11], xErr[11], y[11], yErr[11];
592 Double_t xp[11], xpErr[11], yp[11], ypErr[11];
594 while ( ( p = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
598 busPatchId = p->ID0();
601 // read back pedestal from the other runs for the given (bupatch, manu)
602 for (Int_t i = 1; i < nEntries; ++i) {
603 ped[i] = static_cast<AliMUONVCalibParam*>(map[i]->FindObject(busPatchId, manuId));
606 // compute for each channel the gain parameters
607 for ( channelId = 0; channelId < ped[0]->Size() ; ++channelId ) {
612 for (Int_t i = 0; i < nEntries; ++i) {
614 if (!ped[i]) continue; //shouldn't happen.
615 pedMean[i] = ped[i]->ValueAsDouble(channelId, 0);
616 pedSigma[i] = ped[i]->ValueAsDouble(channelId, 1);
617 injCharge[i] = (Double_t)run[i]->GetSecond();
618 injChargeErr[i] = 0.01*injCharge[i];
619 if(injChargeErr[i] <= 1.) injChargeErr[i]=1.;
621 if (pedMean[i] < 0) continue; // not connected
623 if (pedSigma[i] <= 0) pedSigma[i] = 1.; // should not happen.
628 // print_peak_mean_values
632 fprintf(pfilep,"%4i%5i%5i%10.3f",busPatchId,manuId,channelId,0.);
633 fprintf(pfilep,"%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f mV\n",pedMean[0],pedMean[1],pedMean[2],pedMean[3],pedMean[4],pedMean[5],pedMean[6],pedMean[7],pedMean[8],pedMean[9],pedMean[10]);
634 fprintf(pfilep," %9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f \n",pedSigma[0],pedSigma[1],pedSigma[2],pedSigma[3],pedSigma[4],pedSigma[5],pedSigma[6],pedSigma[7],pedSigma[8],pedSigma[9],pedSigma[10]);
640 // Fit Method: Linear fit over 6 points + fit parabolic function over 3 points)
642 // 1. - linear fit over 6 points
644 Double_t par[4] = {0.,0.,0.,gkADCMax};
647 Int_t nbs = nEntries - nInit;
648 // Int_t nbpf1 = 6; // define as global variable
649 if(nbs < nbpf1)nbpf1=nbs;
651 for (Int_t j = 0; j < nbs; ++j)
655 xErr[j] = pedSigma[k];
657 yErr[j] = injChargeErr[k];
661 TF1 *f1 = new TF1("f1",funcLin,0.,gkADCMax,2);
662 TGraphErrors *graphErr = new TGraphErrors(nbpf1, x, y, xErr, yErr);
664 f1->SetParameters(0,0);
666 graphErr->Fit("f1","RQ");
668 chi2 = f1->GetChisquare();
669 f1->GetParameters(par);
675 prChi2 = TMath::Prob(chi2, nbpf1 - 2);
677 Double_t xLim = pedMean[nInit + nbpf1 - 1];
678 Double_t yLim = par[0]+par[1] * xLim;
683 // 2. - Translation : new origin (xLim, yLim) + parabolic fit over nbf2 points
685 Int_t nbpf2 = nEntries - (nInit + nbpf1) + 1;
689 for (Int_t j = 0; j < nbpf2; j++)
691 Int_t k = j + (nInit + nbpf1) - 1;
692 xp[j] = pedMean[k] - xLim;
693 xpErr[j] = pedSigma[k];
695 yp[j] = injCharge[k] - yLim - par[1]*xp[j];
696 ypErr[j] = injChargeErr[k];
700 TF1 *f2 = new TF1("f2",funcParabolic,0.,gkADCMax,1);
701 TGraphErrors *graphErr = new TGraphErrors(nbpf2, xp, yp, xpErr, ypErr);
703 graphErr->Fit(f2,"RQ");
704 chi2P2 = f2->GetChisquare();
705 f2->GetParameters(par);
711 prChi2P2 = TMath::Prob(chi2P2, nbpf2-1);
714 // ------------- print out in log file
715 // if (busPatchId == 6 && manuId == 116 && ( channelId >= 17 && channelId <= 20) )
717 // filcouc << " \n ********! Print_out.: BP= " << busPatchId << " Manu_Id= " << manuId
718 // << " Ch.= " << channelId << ":" << endl;
720 // for (Int_t j = 0; j < nbpf1; ++j)
721 // {filcouc << j << " " << x[j] << " " << xErr[j] << " " << y[j] << " " << yErr[j] << endl;}
722 // filcouc << " a0,a1 = " << a0 << " , " << a1 << " pr_chi2 = " << prChi2 << endl ;
724 // for (Int_t j = 0; j < nbpf2; ++j)
725 // {filcouc << j << " " << xp[j] << " " << xpErr[j] << " " << yp[j] << " " << ypErr[j] << endl;}
726 // filcouc << " a2 = " << par[0] << " pr_chi2_2 = " << prChi2P2 << endl;
729 // ------------------------------------------
747 p1 = TMath::Nint(ceil(prChi2*14))+1;
748 p2 = TMath::Nint(ceil(prChi2P2*14))+1;
750 Double_t x0 = -par[0]/par[1]; // value of x corresponding to à 0 fC
751 threshold = TMath::Nint(ceil(par[3]-x0)); // linear if x < threshold
755 fprintf(pfilen,"%4i %4i %2i",busPatchId,manuId,channelId);
756 fprintf(pfilen," %6.2f %6.4f %10.3e %4.2f %5.3f %x %5.3f %x\n",
757 par[0], par[1], par[2], par[3], prChi2, p1, prChi2P2, p2);
762 if(par[1]< goodA1Min || par[1]> goodA1Max)
766 if (gPrintLevel && nBadChannel_a1 < 1)
768 cout << " !!!!! " << nBadChannel_a1 << " !!!!!!!! Bad Calib.: BP= " << busPatchId << " Manu_Id= " << manuId <<
769 " Ch.= " << channelId << ":";
770 cout << " a1 = " << par[1] << " out of limit : [" << goodA1Min << "," << goodA1Max <<
775 if(par[2]< goodA2Min || par[2]> goodA2Max)
779 if (gPrintLevel && nBadChannel_a2 < 1)
781 cout << " !!!!! " << nBadChannel_a2 << " !!!!!!!! Bad Calib.: BP= " << busPatchId << " Manu_Id= " << manuId
782 << " Ch.= " << channelId << ":";
783 cout << " a2 = " << par[2] << " out of limit : [" << goodA2Min << "," << goodA2Max
786 for (Int_t j = 0; j < nbpf2; ++j)
787 {cout << j << " " << x[j] << " " << xErr[j] << " " << y[j] << " " << yErr[j] << endl;}
791 Q = p1*16 + p2; // fit quality
792 if(p1==0)Q=0; // bad linear fit <=> bad calibration
797 sumProbChi2P2 += prChi2P2;
803 if(busPatchId < num_tot_BP && manuId < num_tot_Manu) bad_channel[busPatchId][manuId]++;
804 else{cout << " Warning : busPatch = " << busPatchId << " Manu = " << manuId << endl;}
805 if(gPrintLevel>=2)fprintf(pfilef,"%4i %5i %2i %7.4f %10.3e %4i %2x\n",busPatchId,manuId,channelId,par[1],par[2],threshold,Q);
812 sumProbChi2 += prChi2;
814 gain=1./(par[1]*capa);
820 if (!flatOutputFile.IsNull())
822 fprintf(pfilew,"%4i %5i %2i %7.4f %10.3e %4i %2x\n",busPatchId,manuId,channelId,par[1],par[2],threshold,Q);
828 // if(Q==0 and nplot < 100)
829 // if(p1>1 && p2==0 and nplot < 100)
830 // if(p1>1 && p2>1 and nplot < 100)
831 if(p1>=1 and p1<=2 and nplot < 100)
834 // cout << " nplot = " << nplot << endl;
835 TF1 *f2Calib = new TF1("f2Calib",funcCalib,0.,gkADCMax,NFITPARAMS);
837 TGraphErrors *graphErr = new TGraphErrors(nEntries,pedMean,injCharge,pedSigma,injChargeErr);
839 sprintf(graphName,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
841 graphErr->SetTitle(graphName);
842 graphErr->SetMarkerColor(3);
843 graphErr->SetMarkerStyle(12);
844 graphErr->Write(graphName);
846 sprintf(graphName,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
847 f2Calib->SetTitle(graphName);
848 f2Calib->SetLineColor(4);
849 f2Calib->SetParameters(par);
850 f2Calib->Write(graphName);
858 if(fmod(nmanu,100)==0)std::cout << " Nb manu = " << nmanu << std::endl;
861 // file outputs for gain
862 if (!flatOutputFile.IsNull()) fclose(pfilew);
863 if(gPrintLevel==2){ fclose(pfilen); fclose(pfilef);}
864 if(gPrintLevel==3) fclose(pfilep);
872 filcouc << "\n List of problematic BusPatch and Manu " << endl;
873 filcouc << " ========================================" << endl;
874 filcouc << " BP Manu Nb Channel " << endl ;
875 filcouc << " ========================================" << endl;
876 for ( Int_t i = 0 ; i < num_tot_BP ; i++ )
877 { for ( Int_t j = 0 ; j < num_tot_Manu ; j++ )
878 if (bad_channel[i][j] != 0 ) filcouc << "\t" << i << "\t " << j << "\t\t" << bad_channel[i][j] << endl;}
879 filcouc << " ========================================" << endl;
882 filcouc << "\n Nb of channels in raw data = " << nmanu*64 << " (" << nmanu << " Manu)" << endl;
883 filcouc << "\n Nb of calibrated channel = " << nGoodChannel << " (" << goodA1Min << "<a1<" << goodA1Max
884 << " and " << goodA2Min << "<a2<" << goodA2Max << ") " << endl;
885 filcouc << "\n Nb of Bad channel = " << nBadChannel << endl;
887 filcouc << "\n Nb of Good a1 channels = " << nGoodChannel_a1 << " (" << goodA1Min << "<a1<" << goodA1Max << ") " << endl;
889 cout << "\n Nb of channels in raw data = " << nmanu*64 << " (" << nmanu << " Manu)" << endl;
890 cout << " Nb of calibrated channel = " << nGoodChannel << " (" << goodA1Min << "<a1<" << goodA1Max
891 << " and " << goodA2Min << "<a2<" << goodA2Max << ") " << endl;
892 cout << " Nb of Bad channel = " << nBadChannel << endl;
894 Double_t meanA1 = sumA1/(nGoodChannel_a1);
895 Double_t meanProbChi2 = sumProbChi2/(nGoodChannel_a1);
896 Double_t meanA2 = sumA2/(nGoodChannel);
897 Double_t meanProbChi2P2 = sumProbChi2P2/(nGoodChannel);
899 Double_t capaManu = 0.2; // pF
900 filcouc << "\n linear fit : <a1> = " << meanA1 << "\t <gain> = " << 1./(meanA1*capaManu)
901 << " mV/fC (capa= " << capaManu << " pF)" << endl;
902 filcouc << " Prob(chi2)> = " << meanProbChi2 << endl;
903 filcouc << "\n parabolic fit: <a2> = " << meanA2 << endl;
904 filcouc << " Prob(chi2)> = " << meanProbChi2P2 << "\n" << endl;
906 cout << "\n <gain> = " << 1./(meanA1*capaManu)
907 << " mV/fC (capa= " << capaManu << " pF)"
908 << " Prob(chi2)> = " << meanProbChi2 << endl;
917 //*************************************************************//
920 int main(Int_t argc, Char_t **argv)
923 // needed for streamer application
924 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
930 TFitter *minuitFit = new TFitter(NFITPARAMS);
931 TVirtualFitter::SetFitter(minuitFit);
935 Int_t skipEvents = 0;
936 Int_t maxEvents = 1000000;
937 Int_t MaxDateEvents = 1000000;
939 Char_t inputFile[256]="";
941 Int_t gGlitchErrors= 0;
942 Int_t gParityErrors= 0;
943 Int_t gPaddingErrors= 0;
945 TString fesOutputFile;
949 // decode the input line
950 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
955 if (arg[0] != '-') continue;
960 sprintf(inputFile,argv[i]);
964 flatOutputFile = argv[i];
968 sprintf(gOutFolder,argv[i]);
976 gPrintLevel=atoi(argv[i]);
984 gPlotLevel=atoi(argv[i]);
992 skipEvents=atoi(argv[i]);
996 injCharge=atoi(argv[i]);
1000 sscanf(argv[i],"%d",&MaxDateEvents);
1004 sscanf(argv[i],"%d",&maxEvents);
1008 sprintf(gHistoFileName_gain,argv[i]);
1012 printf("\n******************* %s usage **********************",argv[0]);
1013 printf("\n%s -options, the available options are :",argv[0]);
1014 printf("\n-h help (this screen)");
1017 printf("\n-f <raw data file> (default = %s)",inputFile);
1019 printf("\n Output");
1020 printf("\n-a <Flat ASCII file> (default = %s)",flatOutputFile.Data());
1022 printf("\n Options");
1023 printf("\n-b <output directory> (default = %s)",gOutFolder);
1024 printf("\n-c <FES switch> (default = %d)",gFES);
1025 printf("\n-d <print level> (default = %d)",gPrintLevel);
1026 printf("\n-g <plot level> (default = %d)",gPlotLevel);
1027 printf("\n-i <nb linear points> (default = %d)",nbpf1);
1029 printf("\n-l <DAC level> (default = %d)",injCharge);
1030 printf("\n-m <max date events> (default = %d)",MaxDateEvents);
1031 printf("\n-s <skip events> (default = %d)",skipEvents);
1032 printf("\n-n <max events> (default = %d)",maxEvents);
1033 printf("\n-r root file data for gain(default = %s)",gHistoFileName_gain);
1034 printf("\n-e <execute ped/gain> (default = %s)",gCommand.Data());
1035 printf("\n-e <gain create> make gain & create a new root file");
1036 printf("\n-e <gain> make gain & update root file");
1037 printf("\n-e <gain compute> make gain & compute gains");
1042 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
1043 argc = 2; exit(-1); // exit if error
1047 // set gCommand to lower case
1051 // decoding the events
1056 gPedMeanHisto = 0x0;
1057 gPedSigmaHisto = 0x0;
1061 timers.Start(kTRUE);
1067 TString key("MUONTRKda :");
1069 AliMUONRawStreamTracker* rawStream = 0;
1072 if (gCommand.CompareTo("comp") != 0)
1075 status = monitorSetDataSource(inputFile);
1077 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
1078 << " " << monitorDecodeError(status) << endl;
1081 status = monitorDeclareMp("MUON Tracking monitoring");
1083 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
1084 << " " << monitorDecodeError(status) << endl;
1089 cout << "\nMUONTRKda : Reading data from file " << inputFile <<endl;
1093 if (gNDateEvents >= MaxDateEvents) break;
1094 if (gNEvents >= maxEvents) break;
1095 if (gNDateEvents>0 && gNDateEvents % 100 == 0)
1096 cout<<"Cumulated: DATE events = " << gNDateEvents << " Used events = " << gNEvents << endl;
1098 // check shutdown condition
1099 if (daqDA_checkShutdown())
1102 // Skip Events if needed
1103 while (skipEvents) {
1104 status = monitorGetEventDynamic(&event);
1109 status = monitorGetEventDynamic(&event);
1111 cout<<"EOF found"<<endl;
1115 // decoding rawdata headers
1116 AliRawReader *rawReader = new AliRawReaderDate(event);
1118 Int_t eventType = rawReader->GetType();
1119 gRunNumber = rawReader->GetRunNumber();
1121 // Output log file initialisations
1125 if (gCommand.CompareTo("ped") == 0){
1126 sprintf(flatFile,"%s/MUONTRKda_ped_%d.log",gOutFolder,gRunNumber);
1127 logOutputFile=flatFile;
1129 filcout.open(logOutputFile.Data());
1130 filcout<<"//=================================================" << endl;
1131 filcout<<"// MUONTRKda for Pedestal run = " << gRunNumber << endl;
1132 cout<<"\n ******** MUONTRKda for Pedestal run = " << gRunNumber << "\n" << endl;
1135 if (gCommand.Contains("gain")){
1136 sprintf(flatFile,"%s/%s_%d_DAC_%d.log",gOutFolder,filenam,gRunNumber,injCharge);
1137 logOutputFile=flatFile;
1139 filcout.open(logOutputFile.Data());
1140 filcout<<"//=================================================" << endl;
1141 filcout<<"// MUONTRKda for Gain run = " << gRunNumber << " (DAC=" << injCharge << ")" << endl;
1142 cout<<"\n ******** MUONTRKda for Gain run = " << gRunNumber << " (DAC=" << injCharge << ")\n" << endl;
1145 filcout<<"//=================================================" << endl;
1146 filcout<<"// * Date : " << date.AsString("l") << "\n" << endl;
1147 cout<<" * Date : " << date.AsString("l") << "\n" << endl;
1153 if (eventType != PHYSICS_EVENT)
1154 continue; // for the moment
1156 // decoding MUON payload
1157 rawStream = new AliMUONRawStreamTracker(rawReader);
1158 rawStream->DisableWarnings();
1160 // loops over DDL to find good events (Alberto 11/12/07)
1161 rawStream->First(); // if GlitchError ? what we are doing ?
1162 while( (status = rawStream->Next(busPatchId, manuId, channelId, charge)) ) {
1165 if (!rawStream->IsErrorMessage()) {
1166 // loops over DDL to find good events
1167 rawStream->First(); // if GlitchError ? what we are doing ?
1168 while( (status = rawStream->Next(busPatchId, manuId, channelId, charge)) ) {
1173 MakePed(busPatchId, (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
1179 filcout<<"Event # "<<*(rawReader->GetEventId())<<" rejected"<<endl;
1181 if (rawStream->GetPayLoad()->GetGlitchErrors()) gGlitchErrors++;
1182 if (rawStream->GetPayLoad()->GetParityErrors()) gParityErrors++;
1183 if (rawStream->GetPayLoad()->GetPaddingErrors()) gPaddingErrors++;
1185 AliMUONLogger* log = rawStream->GetPayLoad()->GetErrorLogger();
1186 log->Print(key, filcout);
1195 if (gCommand.CompareTo("ped") == 0)
1197 sprintf(flatFile,"MUONTRKda_ped_%d.ped",gRunNumber);
1198 if(flatOutputFile.IsNull())flatOutputFile=flatFile;
1199 MakePedStore(flatOutputFile);
1202 // option gain -> update root file with pedestal results
1203 // gain + create -> recreate root file
1204 // gain + comp -> update root file and compute gain parameters
1206 if (gCommand.Contains("gain"))
1208 MakePedStoreForGain(injCharge);
1212 delete gPedestalStore;
1215 TVirtualFitter::SetFitter(0);
1219 cout << "\nMUONTRKda : Nb of DATE events = " << gNDateEvents << endl;
1220 cout << "MUONTRKda : Nb of Glitch errors = " << gGlitchErrors << endl;
1221 cout << "MUONTRKda : Nb of Parity errors = " << gParityErrors << endl;
1222 cout << "MUONTRKda : Nb of Padding errors = " << gPaddingErrors << endl;
1223 cout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
1225 filcout << "\nMUONTRKda : Nb of DATE events = " << gNDateEvents << endl;
1226 filcout << "MUONTRKda : Nb of Glitch errors = " << gGlitchErrors << endl;
1227 filcout << "MUONTRKda : Nb of Parity errors = " << gParityErrors << endl;
1228 filcout << "MUONTRKda : Nb of Padding errors = " << gPaddingErrors << endl;
1229 filcout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
1231 cout << "\nMUONTRKda : Output logfile : " << logOutputFile << endl;
1233 if (gCommand.CompareTo("ped") == 0)
1236 cout << "MUONTRKda : Pedestal Histo file : " << gHistoFileName << endl;
1237 cout << "MUONTRKda : Flat pedestal file (to SHUTTLE) : " << flatOutputFile << endl;
1241 cout << "MUONTRKda : DAC data (root file) : " << gHistoFileName_gain << endl;
1242 cout << "MUONTRKda : Dummy file (to SHUTTLE) : " << flatOutputFile << endl;
1247 // Compute gain parameters
1250 if (gCommand.Contains("comp"))
1256 cout << "\nMUONTRKda : Output logfile : " << logOutputFile_comp << endl;
1257 cout << "MUONTRKda : Root Histo. file : " << gRootFileName << endl;
1258 cout << "MUONTRKda : Gain file (to SHUTTLE) : " << flatOutputFile << endl;
1262 if(gFES) // Store IN FES
1264 printf("\n ***** STORE FILE in FES ****** \n");
1266 // be sure that env variable DAQDALIB_PATH is set in script file
1267 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
1269 if (!flatOutputFile.IsNull())
1271 if (gCommand.CompareTo("ped") == 0)
1272 status = daqDA_FES_storeFile(flatOutputFile.Data(),"PEDESTALS");
1274 status = daqDA_FES_storeFile(flatOutputFile.Data(),"GAINS");
1278 printf(" Failed to export file : %d\n",status);
1280 else if(gPrintLevel) printf(" %s successfully exported to FES \n",flatOutputFile.Data());
1286 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());