4 Version for MUONTRKda MUON tracking
5 (A. Baldisseri, J.-L. Charvet & Ch. Finck)
8 Rem: AliMUON2DMap stores all channels, even those which are not connected
9 if pedMean == -1, channel not connected to a pad
20 #include <Riostream.h>
25 #include "AliMUONRawStreamTracker.h"
26 #include "AliMUONDspHeader.h"
27 #include "AliMUONBlockHeader.h"
28 #include "AliMUONBusStruct.h"
29 #include "AliMUONDDLTracker.h"
30 #include "AliMUONVStore.h"
31 #include "AliMUON2DMap.h"
32 #include "AliMUONCalibParamND.h"
33 #include "AliMpIntPair.h"
34 #include "AliMpConstants.h"
35 #include "AliRawReaderDate.h"
42 #include "TStopwatch.h"
44 #include "TTimeStamp.h"
45 #include "TGraphErrors.h"
48 #include "TPluginManager.h"
54 const Int_t gkNChannels = AliMpConstants::ManuNofChannels();
55 const Int_t gkADCMax = 4095;
57 AliMUONVStore* gPedestalStore = new AliMUON2DMap(kFALSE);
61 UInt_t gRunNumber = 0;
63 Int_t gNDateEvents = 0;
64 Int_t gPrintLevel = 1; // global printout variable
65 Int_t gPlotLevel = 0; // global plot variable
67 TH1F* gPedMeanHisto = 0x0;
68 TH1F* gPedSigmaHisto = 0x0;
69 Char_t gHistoFileName[256];
72 Char_t gHistoFileName_gain[256]="MuonTrkDA_data.root";
73 Char_t gRootFileName[256]="MuonTrkDA_gain.root";
74 Char_t filenam[256]="MuonTrkDA_gain.param"; // if gPrintLevel = 2
77 TString gCommand("ped");
83 Double_t funcLin(Double_t *x, Double_t *par)
85 return par[0] + par[1]*x[0];
89 Double_t funcParabolic(Double_t *x, Double_t *par)
91 return par[0]*x[0]*x[0];
95 Double_t funcCalib(Double_t *x, Double_t *par)
97 Double_t xLim= par[3];
99 if(x[0] <= xLim) return par[0] + par[1]*x[0];
101 Double_t yLim = par[0]+ par[1]*xLim;
102 return yLim + par[1]*(x[0] - xLim) + par[2]*(x[0] - xLim)*(x[0] - xLim);
107 // Double_t fitFunc(Double_t *x, Double_t *par)
109 // //fit function for gains
111 // Double_t xx = x[0];
115 // f = par[0] + par[1]*xx;
117 // f= par[0] + par[1]*xx + par[2]*xx*xx;
124 void MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
127 AliMUONVCalibParam* ped =
128 static_cast<AliMUONVCalibParam*>(gPedestalStore->FindObject(busPatchId, manuId));
132 ped = new AliMUONCalibParamND(2, gkNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
133 gPedestalStore->Add(ped);
137 ped->SetValueAsDouble(channelId, 0, 0.);
138 ped->SetValueAsDouble(channelId, 1, 0.);
141 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + charge;
142 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + charge*charge;
144 ped->SetValueAsDouble(channelId, 0, pedMean);
145 ped->SetValueAsDouble(channelId, 1, pedSigma);
150 void MakePedStore(TString flatOutputFile = "")
161 // sprintf(gHistoFileName,"mutrkped-%d.root",gRunNumber);
162 sprintf(gHistoFileName,"MuonTrkDA_%d_ped.root",gRunNumber);
163 TFile* histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
167 sprintf(name,"pedmean_allch");
168 sprintf(title,"Pedestal mean all channels");
172 gPedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
173 gPedMeanHisto->SetDirectory(histoFile);
175 sprintf(name,"pedsigma_allch");
176 sprintf(title,"Pedestal sigma all channels");
180 gPedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
181 gPedSigmaHisto->SetDirectory(histoFile);
183 TTree* tree = new TTree("t","Pedestal tree");
184 tree->Branch("bp",&busPatchId,"bp/I");
185 tree->Branch("manu",&manuId,",manu/I");
186 tree->Branch("channel",&channelId,",channel/I");
187 tree->Branch("pedMean",&pedMean,",pedMean/D");
188 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
190 if (!flatOutputFile.IsNull()) {
191 fileout.open(flatOutputFile.Data());
192 fileout<<"//===========================================================================" << endl;
193 fileout<<"// Pedestal file calculated by MUONTRKda"<<endl;
194 fileout<<"//===========================================================================" << endl;
195 fileout<<"// * Run : " << gRunNumber << endl;
196 fileout<<"// * Date : " << date.AsString("l") <<endl;
197 fileout<<"// * Statictics : " << gNEvents << endl;
198 fileout<<"// * # of MANUS : " << gNManu << endl;
199 fileout<<"// * # of channels : " << gNChannel << endl;
201 fileout<<"//---------------------------------------------------------------------------" << endl;
202 fileout<<"//---------------------------------------------------------------------------" << endl;
203 // fileout<<"//format : BUS_PATCH MANU_ID CHANNEL MEAN SIGMA"<<endl;
204 fileout<<"// BP MANU CH. MEAN SIGMA"<<endl;
205 fileout<<"//---------------------------------------------------------------------------" << endl;
209 // iterator over pedestal
210 TIter next(gPedestalStore->CreateIterator());
211 AliMUONVCalibParam* ped;
213 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
215 busPatchId = ped->ID0();
218 for (channelId = 0; channelId < ped->Size() ; ++channelId) {
220 pedMean = ped->ValueAsDouble(channelId, 0);
222 if (pedMean > 0) { // connected channels
224 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)gNEvents);
226 pedMean = ped->ValueAsDouble(channelId, 0);
227 pedSigma = ped->ValueAsDouble(channelId, 1);
229 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)gNEvents - pedMean*pedMean)));
231 pedMean = ped->ValueAsDouble(channelId, 0) + 0.5 ;
232 // pedMean = ped->ValueAsDouble(channelId, 0) ;
233 pedSigma = ped->ValueAsDouble(channelId, 1);
236 if (!flatOutputFile.IsNull()) {
237 fileout << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t"
238 << pedMean <<"\t"<< pedSigma << endl;
241 gPedMeanHisto->Fill(pedMean);
242 gPedSigmaHisto->Fill(pedSigma);
250 if (!flatOutputFile.IsNull())
259 // not usable need an update of DATE ->5.28, but it compiles
260 // uncomment when DATE version ok.
261 // setenv DATE_FES_PATH
262 // setenv DATE_RUN_NUMBER
263 // setenv DATE_ROLE_NAME
264 // setenv DATE_DETECTOR_CODE
266 // if (!flatOutputFile.IsNull()) {
268 // flatOutputFile.Prepend("./");
270 // status = daqDA_FES_storeFile(flatOutputFile.Data(),"MUONTRKda_results");
272 // printf("Failed to export file : %d\n",status);
280 void MakePedStoreForGain(Int_t injCharge)
282 // store pedestal map in root file
284 // Int_t injCharge = 200;
288 // compute and store pedestals
291 // store in root file
292 // sprintf(gHistoFileName,"mutrkgain.root");
294 TString mode("UPDATE");
296 if (gCommand.Contains("cre")) {
299 TFile* histoFile = new TFile(gHistoFileName_gain, mode.Data(), "MUON Tracking Gains");
301 // second argument should be the injected charge, taken from config crocus file
302 // put also info about run number could be usefull
303 AliMpIntPair* pair = new AliMpIntPair(gRunNumber, injCharge);
305 if (mode.CompareTo("UPDATE") == 0) {
306 tree = (TTree*)histoFile->Get("t");
307 tree->SetBranchAddress("run",&pair);
308 tree->SetBranchAddress("ped",&gPedestalStore);
311 tree = new TTree("t","Pedestal tree");
312 tree->Branch("run", "AliMpIntPair",&pair);
313 tree->Branch("ped", "AliMUON2DMap",&gPedestalStore);
314 tree->SetBranchAddress("run",&pair);
315 tree->SetBranchAddress("ped",&gPedestalStore);
320 tree->Write("t", TObject::kOverwrite); // overwrite the tree
327 void MakeGainStore(TString flatOutputFile)
329 Double_t goodA1Min = 0.5;
330 Double_t goodA1Max = 2.;
331 Double_t goodA2Min = -0.5E-03;
332 Double_t goodA2Max = 1.E-03;
334 // open file mutrkgain.root
335 // read again the pedestal for the calibration runs (9 runs ?)
336 // need the injection charge from config file (to be done)
337 // For each channel make a TGraphErrors (mean, sigma) vs injected charge
338 // Fit with a polynomial fct
339 // store the result in a flat file.
341 Double_t pedMean[11];
342 Double_t pedSigma[11];
343 Double_t injCharge[11];
344 Double_t injChargeErr[11];
351 // why 2 files ? (Ch. F.)
355 // Char_t filenam[256]="MuonTrkDA_gain.param";
356 cout << " fit parameter file = " << filenam << "\n";
357 pfilen = fopen (filenam,"w");
359 fprintf(pfilen,"//===================================================================\n");
360 fprintf(pfilen,"// BP MANU CH. a0 a1 a2 xlim P(chi2) P(chi2)2 Q\n");
361 fprintf(pfilen,"//===================================================================\n");
365 if (!flatOutputFile.IsNull())
367 pfilew = fopen (flatOutputFile.Data(),"w");
369 fprintf(pfilew,"//=================================================\n");
370 fprintf(pfilew,"// Calibration file calculated by MUONTRKda \n");
371 fprintf(pfilew,"//=================================================\n");
372 fprintf(pfilew,"// * Run : %d \n",gRunNumber);
373 fprintf(pfilew,"// * Date : %s \n",date.AsString("l"));
374 fprintf(pfilew,"// * Statictics : %d \n",gNEvents);
375 fprintf(pfilew,"// * # of MANUS : %d \n",gNManu);
376 fprintf(pfilew,"// * # of channels : %d \n",gNChannel);
377 fprintf(pfilew,"//-------------------------------------------------\n");
378 fprintf(pfilew,"//=======================================\n");
379 fprintf(pfilew,"// BP MANU CH. a1 a2 thres. Q\n");
380 fprintf(pfilew,"//=======================================\n");
385 // sprintf(gHistoFileName,"mutrkgain.root");
386 TFile* histoFile = new TFile(gHistoFileName_gain);
388 AliMUON2DMap* map[11];
389 AliMUONVCalibParam* ped[11];
390 AliMpIntPair* run[11];
394 TFile* gainFile = 0x0;
395 // sprintf(gRootFileName,"makegain.root");
396 gainFile = new TFile(gRootFileName,"RECREATE");
399 Double_t chi2P2 = 0.;
401 Double_t prChi2P2 =0;
409 TTree *tg = new TTree("tg","TTree avec class Manu_DiMu");
411 tg->Branch("bp",&busPatchId, "busPatchId/I");
412 tg->Branch("manu",&manuId, "manuId/I");
413 tg->Branch("channel",&channelId, "channelId/I");
415 tg->Branch("a0",&a0, "a0/D");
416 tg->Branch("a1",&a1, "a1/D");
417 tg->Branch("a2",&a2, "a2/D");
418 tg->Branch("Pchi2",&prChi2, "prChi2/D");
419 tg->Branch("Pchi2_2",&prChi2P2, "prChi2P2/D");
420 tg->Branch("Threshold",&threshold, "threshold/I");
421 tg->Branch("Q",&Q, "Q/I");
423 //read back from root file
424 TTree* tree = (TTree*)histoFile->Get("t");
425 Int_t nEntries = tree->GetEntries();
426 // tree->Branch("a1",&a1, "a1/D");
428 if(gPrintLevel) cout << " nEntries = " << nEntries << " DAC values \n" << endl;
431 for (Int_t i = 0; i < nEntries; ++i) {
434 tree->SetBranchAddress("ped",&map[i]);
435 tree->SetBranchAddress("run",&run[i]);
438 // std::cout << map[i] << " " << run[i] << std::endl;
442 TF1 *f1 = new TF1("f1",funcLin,0.,gkADCMax,2);
443 TF1 *f2 = new TF1("f2",funcParabolic,0.,gkADCMax,1);
447 // iterates over the first pedestal run
448 TIter next(map[0]->CreateIterator());
449 AliMUONVCalibParam* p;
452 Int_t nBadChannel = 0;
453 Double_t sumProbChi2 = 0.;
455 Double_t sumProbChi2P2 = 0.;
458 Double_t x[11], xErr[11], y[11], yErr[11];
460 while ( ( p = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
464 // Int_t busPatchId = p->ID0();
465 // Int_t manuId = p->ID1();
466 busPatchId = p->ID0();
469 // read back pedestal from the other runs for the given (bupatch, manu)
470 for (Int_t i = 1; i < nEntries; ++i) {
471 ped[i] = static_cast<AliMUONVCalibParam*>(map[i]->FindObject(busPatchId, manuId));
474 // compute for each channel the gain parameters
475 // for ( Int_t channelId = 0; channelId < ped[0]->Size() ; ++channelId ) {
476 for ( channelId = 0; channelId < ped[0]->Size() ; ++channelId ) {
479 for (Int_t i = 0; i < nEntries; ++i) {
481 if (!ped[i]) continue; //shouldn't happen.
482 pedMean[i] = ped[i]->ValueAsDouble(channelId, 0);
483 pedSigma[i] = ped[i]->ValueAsDouble(channelId, 1);
484 injCharge[i] = (Double_t)run[i]->GetSecond();
485 injChargeErr[i] = 0.01*injCharge[i];
486 if(injChargeErr[i] <= 1.) injChargeErr[i]=1.;
488 // if(n<2)cout << nEntries << " " << i << " " << injCharge[i] << endl;
490 // cout << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << n << " " << pedMean[i] << " " << pedSigma[i] << " " << injCharge[i] << " " << injChargeErr[i] << endl;
492 if (pedMean[i] < 0) continue; // not connected
494 if (pedSigma[i] <= 0) pedSigma[i] = 1.; // should not happen.
501 // Fit Method: Linear fit over 6 points + fit parabolic function over 3 points)
503 // 1. - linear fit over 6 points
505 Double_t par[4] = {0.,0.,0.,gkADCMax};
508 Int_t nbs = nEntries - nInit;
509 Int_t nbpf1 = 6; // linear fit over nbf1 points
511 for (Int_t j = 0; j < nbs; ++j)
515 xErr[j] = pedSigma[k];
517 yErr[j] = injChargeErr[k];
521 TGraph *graphErr = new TGraphErrors(nbpf1, x, y, xErr, yErr);
523 f1->SetParameters(0,0);
525 graphErr->Fit("f1","RQ");
527 chi2 = f1->GetChisquare();
528 f1->GetParameters(par);
530 prChi2 = TMath::Prob(chi2, nbpf1 - 2);
532 Double_t xLim = pedMean[nInit + nbpf1 - 1];
533 Double_t yLim = par[0]+par[1] * xLim;
541 // 2. - Translation : new origin (xLim, yLim) + parabolic fit over nbf2 points
543 Int_t nbpf2 = nEntries - (nInit + nbpf1) + 1;
547 for (Int_t j = 0; j < nbpf2; ++j)
549 Int_t k = j + (nInit + nbpf1) - 1;
550 x[j] = pedMean[k] - xLim;
551 xErr[j] = pedSigma[k];
553 y[j] = injCharge[k] - yLim - par[1]*x[j];
554 yErr[j] = injChargeErr[k];
558 TGraph *graphErr = new TGraphErrors(nbpf2, x, y, xErr, yErr);
560 graphErr->Fit(f2,"RQ");
561 chi2P2 = f2->GetChisquare();
562 f2->GetParameters(par);
564 prChi2P2 = TMath::Prob(chi2P2, nbpf2-1);
579 Int_t p1 = TMath::Nint(ceil(prChi2*15));
580 Int_t p2 = TMath::Nint(ceil(prChi2P2*15));
583 Double_t x0 = -par[0]/par[1]; // value of x corresponding to à 0 fC
584 threshold = TMath::Nint(ceil(par[3]-x0)); // linear if x < threshold
588 fprintf(pfilen,"%4i %4i %2i",busPatchId,manuId,channelId);
589 fprintf(pfilen," %6.2f %6.4f %10.3e %4.2f %5.3f %5.3f %x\n",
590 par[0], par[1], par[2], par[3], prChi2, prChi2P2, Q);
595 if(par[1]< goodA1Min || par[1]> goodA1Max )
599 cout << " !!!!!!!!!!!!! Bad Calib.: BP= " << busPatchId << " Manu_Id= " << manuId <<
600 " Ch.= " << channelId << ":";
601 cout << " a1 = " << par[1] << " out of limit : [" << goodA1Min << "," << goodA1Max <<
607 else if(par[2]< goodA2Min || par[2]> goodA2Max )
611 cout << " !!!!!!!!!!!!! Bad Calib.: BP= " << busPatchId << " Manu_Id= " << manuId
612 << " Ch.= " << channelId << ":";
613 cout << " a2 = " << par[2] << " out of limit : [" << goodA2Min << "," << goodA2Max
621 sumProbChi2 += prChi2;
623 sumProbChi2P2 += prChi2P2;
630 cout << " ** Warning ** Bad Fit : BP= " << busPatchId << " Manu_Id= " << manuId
631 << "Ch.= " << channelId << ":";
632 cout << " a1 = " << par[1] << " P(chi2)_lin = " << prChi2 << endl ;
636 cout << " ** Warning ** Bad Fit : BP= " << busPatchId << " Manu_Id= " << manuId
637 << " Ch.= " << channelId << ":";
638 cout << " a2 = " << par[2] << " P_(chi2)_parab = " << prChi2P2 << endl;
645 if (!flatOutputFile.IsNull())
647 fprintf(pfilew,"%4i %5i %2i %7.4f %10.3e %4i %2x\n",busPatchId,manuId,channelId,par[1],par[2],threshold,Q);
653 TF1 *f2Calib = new TF1("f2Calib",funcCalib,0.,gkADCMax,NFITPARAMS);
655 graphErr = new TGraphErrors(nEntries,pedMean,injCharge,pedSigma,injChargeErr);
657 sprintf(graphName,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
659 graphErr->SetTitle(graphName);
660 graphErr->SetMarkerColor(3);
661 graphErr->SetMarkerStyle(12);
662 graphErr->Write(graphName);
664 sprintf(graphName,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
665 f2Calib->SetTitle(graphName);
666 f2Calib->SetLineColor(4);
667 f2Calib->SetParameters(par);
668 f2Calib->Write(graphName);
677 // file outputs for gain
678 if (!flatOutputFile.IsNull())
690 cout << "\n Nb of Manu in raw data = " << nmanu << " (" << nmanu*64 << " channels)" << endl;
691 cout << "\n Nb of calibrated channels = " << nmanu*64 - nBadChannel << " (" << goodA1Min << "<a1<" << goodA1Max
692 << " and " << goodA2Min << "<a2<" << goodA2Max << ") " << endl;
693 cout << "\n Nb of UNcalibrated channels = " << nBadChannel << " (a1 or a2 out of range)\n" << endl;
695 Double_t meanA1 = sumA1/(nmanu*64 - nBadChannel);
696 Double_t meanProbChi2 = sumProbChi2/(nmanu*64 - nBadChannel);
697 Double_t meanA2 = sumA2/(nmanu*64 - nBadChannel);
698 Double_t meanProbChi2P2 = sumProbChi2P2/(nmanu*64 - nBadChannel);
700 Double_t capaManu = 0.2; // pF
701 cout << "\n linear fit : <a1> = " << meanA1 << "\t <gain> = " << 1./(meanA1*capaManu)
702 << " mV/fC (capa= " << capaManu << " pF)" << endl;
703 cout << " Prob(chi2)> = " << meanProbChi2 << endl;
704 cout << "\n parabolic fit: <a2> = " << meanA2 << endl;
705 cout << " Prob(chi2)> = " << meanProbChi2P2 << "\n" << endl;
709 //*************************************************************//
712 int main(Int_t argc, Char_t **argv)
715 // needed for streamer application
716 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
722 TFitter *minuitFit = new TFitter(NFITPARAMS);
723 TVirtualFitter::SetFitter(minuitFit);
725 Int_t skipEvents = 0;
726 Int_t maxEvents = 1000000;
727 Int_t MaxDateEvents = 1000000;
730 Int_t threshold = -1;
731 Char_t inputFile[256];
732 Char_t flatFile[256];
734 TString flatOutputFile;
735 TString crocusOutputFile;
736 TString crocusConfigFile;
740 // decode the input line
741 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
746 if (arg[0] != '-') continue;
751 sprintf(inputFile,argv[i]);
755 flatOutputFile = argv[i];
759 crocusOutputFile = argv[i];
763 crocusConfigFile = argv[i];
771 gPrintLevel=atoi(argv[i]);
775 gPlotLevel=atoi(argv[i]);
779 skipEvents=atoi(argv[i]);
783 injCharge=atoi(argv[i]);
787 sscanf(argv[i],"%d",&MaxDateEvents);
791 sscanf(argv[i],"%d",&maxEvents);
795 sscanf(argv[i],"%lf",&nSigma);
799 sprintf(gHistoFileName_gain,argv[i]);
803 sscanf(argv[i],"%d",&threshold);
807 printf("\n******************* %s usage **********************",argv[0]);
808 printf("\n%s -options, the available options are :",argv[0]);
809 printf("\n-h help (this screen)");
812 printf("\n-f <raw data file> (default = %s)",inputFile);
813 printf("\n-c <Crocus config. file> (default = %s)",crocusConfigFile.Data());
816 printf("\n-a <Flat ASCII file> (default = %s)",flatOutputFile.Data());
817 printf("\n-o <CROUCUS cmd file> (default = %s)",crocusOutputFile.Data());
819 printf("\n Options");
820 printf("\n-d <print level> (default = %d)",gPrintLevel);
821 printf("\n-g <plot level> (default = %d)",gPlotLevel);
822 printf("\n-l <DAC level> (default = %d)",injCharge);
823 printf("\n-m <max date events> (default = %d)",MaxDateEvents);
824 printf("\n-s <skip events> (default = %d)",skipEvents);
825 printf("\n-n <max events> (default = %d)",maxEvents);
826 printf("\n-p <n sigmas> (default = %f)",nSigma);
827 printf("\n-r root file data for gain(default = %s)",gHistoFileName_gain);
828 printf("\n-t <threshold (-1 = no)> (default = %d)",threshold);
829 printf("\n-e <execute ped/gain> (default = %s)",gCommand.Data());
830 printf("\n-e <gain create> make gain & create a new root file");
831 printf("\n-e <gain> make gain & update root file");
832 printf("\n-e <gain compute> make gain & compute gains");
837 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
838 argc = 2; exit(-1); // exit if error
842 // set gCommand to lower case
845 // decoding the events
848 Int_t nDateEvents = 0;
853 gPedSigmaHisto = 0x0;
859 // once we have a configuration file in db
860 // copy locally a file from daq detector config db
861 // The current detector is identified by detector code in variable
862 // DATE_DETECTOR_CODE. It must be defined.
863 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
864 // instead of the database. The usual environment variables are not needed.
865 if (!crocusConfigFile.IsNull()) {
866 status = daqDA_DB_getFile("myconfig", crocusConfigFile.Data());
868 printf("Failed to get config file : %d\n",status);
874 status = monitorSetDataSource(inputFile);
876 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
877 << " " << monitorDecodeError(status) << endl;
880 status = monitorDeclareMp("MUON Tracking monitoring");
882 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
883 << " " << monitorDecodeError(status) << endl;
887 cout << "MUONTRKda : Reading data from file " << inputFile <<endl;
896 if (gNDateEvents >= MaxDateEvents) break;
897 if (gNEvents >= maxEvents) break;
898 if (gNEvents && gNEvents % 100 == 0)
899 cout<<"Cumulated events " << gNEvents << endl;
901 // check shutdown condition
902 if (daqDA_checkShutdown())
905 // Skip Events if needed
907 status = monitorGetEventDynamic(&event);
912 status = monitorGetEventDynamic(&event);
914 cout<<"EOF found"<<endl;
920 // decoding rawdata headers
921 AliRawReader *rawReader = new AliRawReaderDate(event);
923 Int_t eventType = rawReader->GetType();
924 gRunNumber = rawReader->GetRunNumber();
926 if (eventType != PHYSICS_EVENT)
927 continue; // for the moment
931 // decoding MUON payload
932 AliMUONRawStreamTracker* rawStream = new AliMUONRawStreamTracker(rawReader);
936 while( (status = rawStream->Next(busPatchId, manuId, channelId, charge)) ) {
941 // if (gPrintLevel) printf("manuId: %d, channelId: %d charge: %d\n", manuId,
942 // channelId, charge);
944 MakePed(busPatchId, (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
955 if (gCommand.CompareTo("ped") == 0)
957 // sprintf(flatOutputFile,"MuonTrkDA_%d.ped",gRunNumber);
958 sprintf(flatFile,"MuonTrkDA_%d_ped.ped",gRunNumber);
959 if(flatOutputFile.IsNull())flatOutputFile=flatFile;
960 MakePedStore(flatOutputFile);
964 if(flatOutputFile.IsNull())flatOutputFile="MuonTrkDA_gain.par";
967 // option gain -> update root file with pedestal results
968 // gain + create -> recreate root file
969 // gain + comp -> update root file and compute gain parameters
971 if (gCommand.Contains("gain"))
972 MakePedStoreForGain(injCharge);
974 if (gCommand.Contains("comp"))
975 MakeGainStore(flatOutputFile);
978 delete gPedestalStore;
981 TVirtualFitter::SetFitter(0);
985 if (gCommand.CompareTo("comp") != 0)
987 cout << "MUONTRKda : Nb of DATE events = " << gNDateEvents << endl;
988 cout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
990 if (gCommand.CompareTo("ped") == 0)
992 if (!(crocusConfigFile.IsNull()))
993 cout << "MUONTRKda : CROCUS command file generated : " << crocusOutputFile.Data() << endl;
995 cout << "MUONTRKda : WARNING no CROCUS command file generated" << endl;
996 cout << "\nMUONTRKda : Histo file generated for pedestal : " << gHistoFileName << endl;
1000 cout << "\nMUONTRKda : Histo file generated for gain : " << gHistoFileName_gain << endl;
1001 cout << "MUONTRKda : Root file generated : " << gRootFileName << endl;
1004 cout << "MUONTRKda : Flat ASCII file generated : " << flatOutputFile << endl;
1005 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());