]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONTRKda.cxx
Adding line with brief file description,
[u/mrichter/AliRoot.git] / MUON / MUONTRKda.cxx
CommitLineData
666b5407 1/**************************************************************************
53f515d3 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
666b5407 18/*-------------------------------------------------------------------------------
19/* 14/12/07 New version: MUONTRKda.cxx,v 1.10
20/*-------------------------------------------------------------------------------
3f637cfc 21
90293ba6 22Version for MUONTRKda MUON tracking
23(A. Baldisseri, J.-L. Charvet & Ch. Finck)
3f637cfc 24
25
26Rem: AliMUON2DMap stores all channels, even those which are not connected
27 if pedMean == -1, channel not connected to a pad
28
3f637cfc 29
30*/
31extern "C" {
32#include <daqDA.h>
33}
34
35#include "event.h"
36#include "monitor.h"
37
38#include <Riostream.h>
39#include <stdio.h>
40#include <stdlib.h>
41
42//AliRoot
96fa832f 43#include "AliMUONLogger.h"
3f637cfc 44#include "AliMUONRawStreamTracker.h"
45#include "AliMUONDspHeader.h"
46#include "AliMUONBlockHeader.h"
47#include "AliMUONBusStruct.h"
48#include "AliMUONDDLTracker.h"
2bf54af2 49#include "AliMUONVStore.h"
3f637cfc 50#include "AliMUON2DMap.h"
0aa03544 51#include "AliMUONCalibParamND.h"
3f637cfc 52#include "AliMpIntPair.h"
2bf54af2 53#include "AliMpConstants.h"
3f637cfc 54#include "AliRawReaderDate.h"
55
3f637cfc 56//ROOT
57#include "TFile.h"
53f515d3 58#include "TSystem.h"
3f637cfc 59#include "TTree.h"
60#include "TH1F.h"
61#include "TString.h"
62#include "TStopwatch.h"
63#include "TMath.h"
64#include "TTimeStamp.h"
65#include "TGraphErrors.h"
66#include "TF1.h"
fd99693f 67#include "TROOT.h"
68#include "TPluginManager.h"
a76f513d 69#include "TFitter.h"
3f637cfc 70
a76f513d 71#define NFITPARAMS 4
3f637cfc 72
73// global variables
90293ba6 74const Int_t gkNChannels = AliMpConstants::ManuNofChannels();
75const Int_t gkADCMax = 4095;
76
77AliMUONVStore* gPedestalStore = new AliMUON2DMap(kFALSE);
78
79Int_t gNManu = 0;
80Int_t gNChannel = 0;
81UInt_t gRunNumber = 0;
82Int_t gNEvents = 0;
83Int_t gNDateEvents = 0;
666b5407 84Int_t gPrintLevel = 1; // global printout variable (others: 2 and 3)
90293ba6 85Int_t gPlotLevel = 0; // global plot variable
86
87TH1F* gPedMeanHisto = 0x0;
88TH1F* gPedSigmaHisto = 0x0;
89Char_t gHistoFileName[256];
90
91// used by makegain
53f515d3 92Char_t gHistoFileName_gain[256]="MUONTRKda_gain_data.root";
93Char_t gRootFileName[256];
94Char_t gOutFolder[256]=".";
95Char_t filename[256];
96Char_t filenam[256]="MUONTRKda_gain";
53f515d3 97Char_t flatFile[256];
98
99ofstream filcout;
100
101TString flatOutputFile;
102TString logOutputFile;
90293ba6 103TString gCommand("ped");
53f515d3 104TTimeStamp date;
3f637cfc 105
106// funtions
107
90293ba6 108
109//________________
110Double_t funcLin(Double_t *x, Double_t *par)
111{
112 return par[0] + par[1]*x[0];
113}
114
3f637cfc 115//________________
90293ba6 116Double_t funcParabolic(Double_t *x, Double_t *par)
3f637cfc 117{
90293ba6 118 return par[0]*x[0]*x[0];
119}
3f637cfc 120
90293ba6 121//________________
122Double_t funcCalib(Double_t *x, Double_t *par)
123{
124 Double_t xLim= par[3];
3f637cfc 125
90293ba6 126 if(x[0] <= xLim) return par[0] + par[1]*x[0];
3f637cfc 127
90293ba6 128 Double_t yLim = par[0]+ par[1]*xLim;
129 return yLim + par[1]*(x[0] - xLim) + par[2]*(x[0] - xLim)*(x[0] - xLim);
3f637cfc 130}
131
132
3f637cfc 133//__________
134void MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
135{
136
137 AliMUONVCalibParam* ped =
90293ba6 138 static_cast<AliMUONVCalibParam*>(gPedestalStore->FindObject(busPatchId, manuId));
3f637cfc 139
140 if (!ped) {
90293ba6 141 gNManu++;
142 ped = new AliMUONCalibParamND(2, gkNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
143 gPedestalStore->Add(ped);
3f637cfc 144 }
145
53f515d3 146 if (gNEvents == 0) {
0aa03544 147 ped->SetValueAsDouble(channelId, 0, 0.);
148 ped->SetValueAsDouble(channelId, 1, 0.);
3f637cfc 149 }
150
0aa03544 151 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + charge;
152 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + charge*charge;
3f637cfc 153
0aa03544 154 ped->SetValueAsDouble(channelId, 0, pedMean);
155 ped->SetValueAsDouble(channelId, 1, pedSigma);
3f637cfc 156
157}
158
159//________________
160void MakePedStore(TString flatOutputFile = "")
161{
53f515d3 162// TTimeStamp date;
0aa03544 163 Double_t pedMean;
164 Double_t pedSigma;
3f637cfc 165 ofstream fileout;
166 Int_t busPatchId;
167 Int_t manuId;
168 Int_t channelId;
169
170 // histo
53f515d3 171 TFile* histoFile = 0;
172 TTree* tree = 0;
173 if (gCommand.CompareTo("ped") == 0)
174 {
175 sprintf(gHistoFileName,"%s/MUONTRKda_ped_%d.root",gOutFolder,gRunNumber);
176 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
3f637cfc 177
666b5407 178 Char_t name[255];
179 Char_t title[255];
180 sprintf(name,"pedmean_allch");
181 sprintf(title,"Pedestal mean all channels");
182 Int_t nx = 4096;
183 Int_t xmin = 0;
184 Int_t xmax = 4095;
185 gPedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
186 gPedMeanHisto->SetDirectory(histoFile);
187
188 sprintf(name,"pedsigma_allch");
189 sprintf(title,"Pedestal sigma all channels");
190 nx = 201;
191 xmin = 0;
192 xmax = 200;
193 gPedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
194 gPedSigmaHisto->SetDirectory(histoFile);
195
196 tree = new TTree("t","Pedestal tree");
197 tree->Branch("bp",&busPatchId,"bp/I");
198 tree->Branch("manu",&manuId,",manu/I");
199 tree->Branch("channel",&channelId,",channel/I");
200 tree->Branch("pedMean",&pedMean,",pedMean/D");
201 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
53f515d3 202 }
203
3f637cfc 204 if (!flatOutputFile.IsNull()) {
205 fileout.open(flatOutputFile.Data());
206 fileout<<"//===========================================================================" << endl;
207 fileout<<"// Pedestal file calculated by MUONTRKda"<<endl;
208 fileout<<"//===========================================================================" << endl;
90293ba6 209 fileout<<"// * Run : " << gRunNumber << endl;
3f637cfc 210 fileout<<"// * Date : " << date.AsString("l") <<endl;
90293ba6 211 fileout<<"// * Statictics : " << gNEvents << endl;
212 fileout<<"// * # of MANUS : " << gNManu << endl;
213 fileout<<"// * # of channels : " << gNChannel << endl;
3f637cfc 214 fileout<<"//"<<endl;
215 fileout<<"//---------------------------------------------------------------------------" << endl;
216 fileout<<"//---------------------------------------------------------------------------" << endl;
90293ba6 217 fileout<<"// BP MANU CH. MEAN SIGMA"<<endl;
3f637cfc 218 fileout<<"//---------------------------------------------------------------------------" << endl;
219
220 }
221
222 // iterator over pedestal
90293ba6 223 TIter next(gPedestalStore->CreateIterator());
2bf54af2 224 AliMUONVCalibParam* ped;
3f637cfc 225
2bf54af2 226 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
3f637cfc 227 {
2bf54af2 228 busPatchId = ped->ID0();
229 manuId = ped->ID1();
3f637cfc 230
231 for (channelId = 0; channelId < ped->Size() ; ++channelId) {
232
0aa03544 233 pedMean = ped->ValueAsDouble(channelId, 0);
3f637cfc 234
235 if (pedMean > 0) { // connected channels
236
90293ba6 237 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)gNEvents);
3f637cfc 238
0aa03544 239 pedMean = ped->ValueAsDouble(channelId, 0);
240 pedSigma = ped->ValueAsDouble(channelId, 1);
3f637cfc 241
90293ba6 242 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)gNEvents - pedMean*pedMean)));
3f637cfc 243
0aa03544 244 pedMean = ped->ValueAsDouble(channelId, 0) + 0.5 ;
90293ba6 245// pedMean = ped->ValueAsDouble(channelId, 0) ;
0aa03544 246 pedSigma = ped->ValueAsDouble(channelId, 1);
3f637cfc 247
248
249 if (!flatOutputFile.IsNull()) {
250 fileout << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t"
251 << pedMean <<"\t"<< pedSigma << endl;
252 }
253
666b5407 254 if (gCommand.CompareTo("ped") == 0)
255 {
256 gPedMeanHisto->Fill(pedMean);
257 gPedSigmaHisto->Fill(pedSigma);
3f637cfc 258
666b5407 259 tree->Fill();
260 }
53f515d3 261 }
3f637cfc 262 }
3f637cfc 263 }
264
265 // file outputs
666b5407 266 if (!flatOutputFile.IsNull()) fileout.close();
3f637cfc 267
53f515d3 268 if (gCommand.CompareTo("ped") == 0)
269 {
270 histoFile->Write();
271 histoFile->Close();
272 }
3f637cfc 273
274// delete tree;
275
3f637cfc 276}
277
278//________________
90293ba6 279void MakePedStoreForGain(Int_t injCharge)
3f637cfc 280{
281 // store pedestal map in root file
282
90293ba6 283// Int_t injCharge = 200;
3f637cfc 284
285 TTree* tree = 0x0;
286
287 // compute and store pedestals
53f515d3 288 sprintf(flatFile,"%s/%s_%d_DAC_%d.ped",gOutFolder,filenam,gRunNumber,injCharge);
666b5407 289 cout << "\nMUONTRKda : Flat file generated : " << flatFile << "\n";
53f515d3 290 MakePedStore(flatFile);
3f637cfc 291
292 TString mode("UPDATE");
293
90293ba6 294 if (gCommand.Contains("cre")) {
3f637cfc 295 mode = "RECREATE";
296 }
90293ba6 297 TFile* histoFile = new TFile(gHistoFileName_gain, mode.Data(), "MUON Tracking Gains");
3f637cfc 298
299 // second argument should be the injected charge, taken from config crocus file
300 // put also info about run number could be usefull
90293ba6 301 AliMpIntPair* pair = new AliMpIntPair(gRunNumber, injCharge);
3f637cfc 302
303 if (mode.CompareTo("UPDATE") == 0) {
304 tree = (TTree*)histoFile->Get("t");
305 tree->SetBranchAddress("run",&pair);
90293ba6 306 tree->SetBranchAddress("ped",&gPedestalStore);
3f637cfc 307
308 } else {
309 tree = new TTree("t","Pedestal tree");
310 tree->Branch("run", "AliMpIntPair",&pair);
90293ba6 311 tree->Branch("ped", "AliMUON2DMap",&gPedestalStore);
3f637cfc 312 tree->SetBranchAddress("run",&pair);
90293ba6 313 tree->SetBranchAddress("ped",&gPedestalStore);
3f637cfc 314
315 }
316
317 tree->Fill();
318 tree->Write("t", TObject::kOverwrite); // overwrite the tree
319 histoFile->Close();
320
321 delete pair;
322}
323
324//________________
53f515d3 325// void MakeGainStore(TString flatOutputFile)
326void MakeGainStore()
3f637cfc 327{
90293ba6 328 Double_t goodA1Min = 0.5;
329 Double_t goodA1Max = 2.;
330 Double_t goodA2Min = -0.5E-03;
331 Double_t goodA2Max = 1.E-03;
332
3f637cfc 333 // open file mutrkgain.root
334 // read again the pedestal for the calibration runs (9 runs ?)
335 // need the injection charge from config file (to be done)
336 // For each channel make a TGraphErrors (mean, sigma) vs injected charge
337 // Fit with a polynomial fct
338 // store the result in a flat file.
339
53f515d3 340
341 TFile* histoFile = new TFile(gHistoFileName_gain);
342
343 AliMUON2DMap* map[11];
344 AliMUONVCalibParam* ped[11];
345 AliMpIntPair* run[11];
346
347 //read back from root file
348 TTree* tree = (TTree*)histoFile->Get("t");
349 Int_t nEntries = tree->GetEntries();
350
351 // read back info
352 for (Int_t i = 0; i < nEntries; ++i) {
353 map[i] = 0x0;
354 run[i] = 0x0;
355 tree->SetBranchAddress("ped",&map[i]);
356 tree->SetBranchAddress("run",&run[i]);
357 tree->GetEvent(i);
358// std::cout << map[i] << " " << run[i] << std::endl;
359 }
96fa832f 360 gRunNumber=(UInt_t)run[0]->GetFirst();
53f515d3 361
362 // some print
363 cout<<"\n ******** MUONTRKda for Gain computing (Run = " << gRunNumber << ")\n" << endl;
364 cout<<" * Date : " << date.AsString("l") << "\n" << endl;
365 cout << " Entries = " << nEntries << " DAC values \n" << endl;
366 for (Int_t i = 0; i < nEntries; ++i) {
367 cout<< " Run = " << (Double_t)run[i]->GetFirst() << " DAC = " << (Double_t)run[i]->GetSecond() << endl;
368 }
369 cout << "" << endl;
370
371
90293ba6 372 Double_t pedMean[11];
373 Double_t pedSigma[11];
374 Double_t injCharge[11];
375 Double_t injChargeErr[11];
3f637cfc 376
90293ba6 377// full print out
378
53f515d3 379 sprintf(filename,"%s/%s_%d.log",gOutFolder,filenam,gRunNumber);
380 logOutputFile=filename;
381
382 filcout.open(logOutputFile.Data());
383 filcout<<"//====================================================" << endl;
384 filcout<<"// MUONTRKda for Gain computing (Run = " << gRunNumber << ")" << endl;
385 filcout<<"//====================================================" << endl;
386 filcout<<"// * Date : " << date.AsString("l") << "\n" << endl;
387
53f515d3 388
389
390
90293ba6 391 // why 2 files ? (Ch. F.)
392 FILE *pfilen = 0;
53f515d3 393 FILE *pfilef = 0;
394 if(gPrintLevel>=2)
90293ba6 395 {
53f515d3 396 sprintf(filename,"%s/%s_%d.param",gOutFolder,filenam,gRunNumber);
397 cout << " fit parameter file = " << filename << "\n";
398 pfilen = fopen (filename,"w");
3f637cfc 399
90293ba6 400 fprintf(pfilen,"//===================================================================\n");
401 fprintf(pfilen,"// BP MANU CH. a0 a1 a2 xlim P(chi2) P(chi2)2 Q\n");
402 fprintf(pfilen,"//===================================================================\n");
53f515d3 403 fprintf(pfilen,"// * Run : %d \n",gRunNumber);
404 fprintf(pfilen,"//===================================================================\n");
405
406 sprintf(filename,"%s/%s_%d.bad",gOutFolder,filenam,gRunNumber);
407 cout << " Bad channel file = " << filename << "\n";
408 pfilef = fopen (filename,"w");
409
410 fprintf(pfilef,"//=================================================\n");
411 fprintf(pfilef,"// Bad Channel file calculated by MUONTRKda \n");
412 fprintf(pfilef,"//=================================================\n");
413 fprintf(pfilef,"// * Run : %d \n",gRunNumber);
414 fprintf(pfilef,"// * Date : %s \n",date.AsString("l"));
415 fprintf(pfilef,"//=======================================\n");
416 fprintf(pfilef,"// BP MANU CH. a1 a2 thres. Q\n");
417 fprintf(pfilef,"//=======================================\n");
3f637cfc 418 }
419
90293ba6 420 FILE *pfilew=0;
53f515d3 421 if(flatOutputFile.IsNull())
422 {
423 sprintf(filename,"%s_%d.par",filenam,gRunNumber);
424 flatOutputFile=filename;
425 }
426 if(!flatOutputFile.IsNull())
90293ba6 427 {
428 pfilew = fopen (flatOutputFile.Data(),"w");
429
430 fprintf(pfilew,"//=================================================\n");
431 fprintf(pfilew,"// Calibration file calculated by MUONTRKda \n");
432 fprintf(pfilew,"//=================================================\n");
433 fprintf(pfilew,"// * Run : %d \n",gRunNumber);
434 fprintf(pfilew,"// * Date : %s \n",date.AsString("l"));
435 fprintf(pfilew,"// * Statictics : %d \n",gNEvents);
436 fprintf(pfilew,"// * # of MANUS : %d \n",gNManu);
437 fprintf(pfilew,"// * # of channels : %d \n",gNChannel);
438 fprintf(pfilew,"//-------------------------------------------------\n");
439 fprintf(pfilew,"//=======================================\n");
440 fprintf(pfilew,"// BP MANU CH. a1 a2 thres. Q\n");
441 fprintf(pfilew,"//=======================================\n");
442 }
443
53f515d3 444 FILE *pfilep = 0;
445 if(gPrintLevel==3)
446 {
447 sprintf(filename,"%s/%s_%d.peak",gOutFolder,filenam,gRunNumber);
448 cout << " File containing Peak mean values = " << filename << "\n";
449 pfilep = fopen (filename,"w");
450
451 fprintf(pfilep,"//===============================================================================================================================\n");
452 fprintf(pfilep,"// * Run : %d \n",gRunNumber);
453 fprintf(pfilep,"//===============================================================================================================================\n");
454 fprintf(pfilep,"// BP MANU CH. Ped. <0> <1> <2> <3> <4> <5> <6> <7> <8> <9> <10> \n");
455// 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]);
456// 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]);
457 fprintf(pfilep,"//===============================================================================================================================\n");
458 }
90293ba6 459
460
3f637cfc 461
90293ba6 462// plot out
3f637cfc 463
90293ba6 464 TFile* gainFile = 0x0;
53f515d3 465 sprintf(gRootFileName,"%s/%s_%d.root",gOutFolder,filenam,gRunNumber);
90293ba6 466 gainFile = new TFile(gRootFileName,"RECREATE");
467
468 Double_t chi2 = 0.;
469 Double_t chi2P2 = 0.;
470 Double_t prChi2 = 0;
471 Double_t prChi2P2 =0;
472 Double_t a0,a1,a2;
473 Int_t busPatchId ;
474 Int_t manuId ;
475 Int_t channelId ;
476 Int_t threshold = 0;
477 Int_t Q = 0;
53f515d3 478 Int_t p1 ;
479 Int_t p2 ;
480 Double_t gain;
481 Double_t capa=0.2; // internal capacitor (pF)
90293ba6 482
483 TTree *tg = new TTree("tg","TTree avec class Manu_DiMu");
484
485 tg->Branch("bp",&busPatchId, "busPatchId/I");
486 tg->Branch("manu",&manuId, "manuId/I");
487 tg->Branch("channel",&channelId, "channelId/I");
488
489 tg->Branch("a0",&a0, "a0/D");
490 tg->Branch("a1",&a1, "a1/D");
491 tg->Branch("a2",&a2, "a2/D");
492 tg->Branch("Pchi2",&prChi2, "prChi2/D");
493 tg->Branch("Pchi2_2",&prChi2P2, "prChi2P2/D");
494 tg->Branch("Threshold",&threshold, "threshold/I");
495 tg->Branch("Q",&Q, "Q/I");
53f515d3 496 tg->Branch("p1",&p1, "p1/I");
497 tg->Branch("p2",&p2, "p2/I");
498 tg->Branch("gain",&gain, "gain/D");
499
500// bad BusPatch and manu
501 Int_t num_tot_BP=800;
502 Int_t num_tot_Manu=1500;
503// Int_t bad_channel[num_tot_BP][num_tot_Manu];
504 Int_t bad_channel[800][1500];
505 for ( Int_t i = 0; i < num_tot_BP ; i++ )
506 { for ( Int_t j = 0; j < num_tot_Manu ; j++ ) bad_channel[i][j]=0;}
3f637cfc 507
3f637cfc 508
90293ba6 509 char graphName[256];
3f637cfc 510
511 // iterates over the first pedestal run
0aa03544 512 TIter next(map[0]->CreateIterator());
2bf54af2 513 AliMUONVCalibParam* p;
3f637cfc 514
90293ba6 515 Int_t nmanu = 0;
53f515d3 516 Int_t nGoodChannel = 0;
517 Int_t nGoodChannel_a1 = 0;
90293ba6 518 Int_t nBadChannel = 0;
53f515d3 519 Int_t nBadChannel_a1 = 0;
520 Int_t nBadChannel_a2 = 0;
521 Int_t nplot=0;
90293ba6 522 Double_t sumProbChi2 = 0.;
523 Double_t sumA1 = 0.;
524 Double_t sumProbChi2P2 = 0.;
525 Double_t sumA2 = 0.;
526
527 Double_t x[11], xErr[11], y[11], yErr[11];
53f515d3 528 Double_t xp[11], xpErr[11], yp[11], ypErr[11];
90293ba6 529
2bf54af2 530 while ( ( p = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
3f637cfc 531 {
2bf54af2 532 ped[0] = p;
3f637cfc 533
90293ba6 534 busPatchId = p->ID0();
535 manuId = p->ID1();
3f637cfc 536
537 // read back pedestal from the other runs for the given (bupatch, manu)
3f637cfc 538 for (Int_t i = 1; i < nEntries; ++i) {
0aa03544 539 ped[i] = static_cast<AliMUONVCalibParam*>(map[i]->FindObject(busPatchId, manuId));
3f637cfc 540 }
541
542 // compute for each channel the gain parameters
90293ba6 543 for ( channelId = 0; channelId < ped[0]->Size() ; ++channelId ) {
3f637cfc 544
53f515d3 545 gain=0.4;
546
3f637cfc 547 Int_t n = 0;
548 for (Int_t i = 0; i < nEntries; ++i) {
549
550 if (!ped[i]) continue; //shouldn't happen.
0aa03544 551 pedMean[i] = ped[i]->ValueAsDouble(channelId, 0);
552 pedSigma[i] = ped[i]->ValueAsDouble(channelId, 1);
553 injCharge[i] = (Double_t)run[i]->GetSecond();
90293ba6 554 injChargeErr[i] = 0.01*injCharge[i];
555 if(injChargeErr[i] <= 1.) injChargeErr[i]=1.;
556
fd99693f 557 if (pedMean[i] < 0) continue; // not connected
3f637cfc 558
559 if (pedSigma[i] <= 0) pedSigma[i] = 1.; // should not happen.
560 n++;
561 }
562
53f515d3 563
564 // print_peak_mean_values
565 if(gPrintLevel==3)
566 {
567
568 fprintf(pfilep,"%4i%5i%5i%10.3f",busPatchId,manuId,channelId,0.);
569 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]);
570 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]);
571 }
572
573 // makegain
90293ba6 574
575
576 // Fit Method: Linear fit over 6 points + fit parabolic function over 3 points)
577
578 // 1. - linear fit over 6 points
579
580 Double_t par[4] = {0.,0.,0.,gkADCMax};
581
582 Int_t nInit = 1;
583 Int_t nbs = nEntries - nInit;
584 Int_t nbpf1 = 6; // linear fit over nbf1 points
585
586 for (Int_t j = 0; j < nbs; ++j)
587 {
588 Int_t k = j + nInit;
589 x[j] = pedMean[k];
590 xErr[j] = pedSigma[k];
591 y[j] = injCharge[k];
592 yErr[j] = injChargeErr[k];
593
594 }
595
53f515d3 596 TF1 *f1 = new TF1("f1",funcLin,0.,gkADCMax,2);
597 TGraphErrors *graphErr = new TGraphErrors(nbpf1, x, y, xErr, yErr);
90293ba6 598
599 f1->SetParameters(0,0);
600
601 graphErr->Fit("f1","RQ");
602
603 chi2 = f1->GetChisquare();
604 f1->GetParameters(par);
605
53f515d3 606 delete graphErr;
607 graphErr=0;
608 delete f1;
609
90293ba6 610 prChi2 = TMath::Prob(chi2, nbpf1 - 2);
611
612 Double_t xLim = pedMean[nInit + nbpf1 - 1];
613 Double_t yLim = par[0]+par[1] * xLim;
614
615 a0 = par[0];
616 a1 = par[1];
617
90293ba6 618 // 2. - Translation : new origin (xLim, yLim) + parabolic fit over nbf2 points
619
620 Int_t nbpf2 = nEntries - (nInit + nbpf1) + 1;
621
622 if(nbpf2 > 1)
623 {
53f515d3 624 for (Int_t j = 0; j < nbpf2; j++)
90293ba6 625 {
626 Int_t k = j + (nInit + nbpf1) - 1;
53f515d3 627 xp[j] = pedMean[k] - xLim;
628 xpErr[j] = pedSigma[k];
90293ba6 629
53f515d3 630 yp[j] = injCharge[k] - yLim - par[1]*xp[j];
631 ypErr[j] = injChargeErr[k];
90293ba6 632
3f637cfc 633 }
90293ba6 634
53f515d3 635 TF1 *f2 = new TF1("f2",funcParabolic,0.,gkADCMax,1);
636 TGraphErrors *graphErr = new TGraphErrors(nbpf2, xp, yp, xpErr, ypErr);
90293ba6 637
638 graphErr->Fit(f2,"RQ");
639 chi2P2 = f2->GetChisquare();
640 f2->GetParameters(par);
641
53f515d3 642 delete graphErr;
643 graphErr=0;
644 delete f2;
645
90293ba6 646 prChi2P2 = TMath::Prob(chi2P2, nbpf2-1);
647
53f515d3 648
649 // ------------- print out in log file
650// if (busPatchId == 6 && manuId == 116 && ( channelId >= 17 && channelId <= 20) )
651// {
652// filcout << " \n ********! Print_out.: BP= " << busPatchId << " Manu_Id= " << manuId
653// << " Ch.= " << channelId << ":" << endl;
654
655// for (Int_t j = 0; j < nbpf1; ++j)
656// {filcout << j << " " << x[j] << " " << xErr[j] << " " << y[j] << " " << yErr[j] << endl;}
657// filcout << " a0,a1 = " << a0 << " , " << a1 << " pr_chi2 = " << prChi2 << endl ;
658
659// for (Int_t j = 0; j < nbpf2; ++j)
660// {filcout << j << " " << xp[j] << " " << xpErr[j] << " " << yp[j] << " " << ypErr[j] << endl;}
661// filcout << " a2 = " << par[0] << " pr_chi2_2 = " << prChi2P2 << endl;
662
663// }
664 // ------------------------------------------
665
666
667
90293ba6 668 a2 = par[0];
669
670 par[0] = a0;
671 par[1] = a1;
672 par[2] = a2;
673 par[3] = xLim;
674
53f515d3 675// delete graphErr;
90293ba6 676
3f637cfc 677 }
678
90293ba6 679 // Prints
680
53f515d3 681 p1 = TMath::Nint(ceil(prChi2*14))+1;
682 p2 = TMath::Nint(ceil(prChi2P2*14))+1;
90293ba6 683
684 Double_t x0 = -par[0]/par[1]; // value of x corresponding to à 0 fC
685 threshold = TMath::Nint(ceil(par[3]-x0)); // linear if x < threshold
686
53f515d3 687 if(gPrintLevel>=2)
90293ba6 688 {
689 fprintf(pfilen,"%4i %4i %2i",busPatchId,manuId,channelId);
53f515d3 690 fprintf(pfilen," %6.2f %6.4f %10.3e %4.2f %5.3f %x %5.3f %x\n",
691 par[0], par[1], par[2], par[3], prChi2, p1, prChi2P2, p2);
90293ba6 692 }
693
694 // some tests
695
53f515d3 696 if(par[1]< goodA1Min || par[1]> goodA1Max)
90293ba6 697 {
53f515d3 698 p1=0;
699 nBadChannel_a1++;
700 if (gPrintLevel && nBadChannel_a1 < 1)
90293ba6 701 {
53f515d3 702 cout << " !!!!! " << nBadChannel_a1 << " !!!!!!!! Bad Calib.: BP= " << busPatchId << " Manu_Id= " << manuId <<
90293ba6 703 " Ch.= " << channelId << ":";
704 cout << " a1 = " << par[1] << " out of limit : [" << goodA1Min << "," << goodA1Max <<
705 "]" << endl;
706 }
90293ba6 707 }
53f515d3 708
709 if(par[2]< goodA2Min || par[2]> goodA2Max)
90293ba6 710 {
53f515d3 711 p2=0;
712 nBadChannel_a2++;
713 if (gPrintLevel && nBadChannel_a2 < 1)
90293ba6 714 {
53f515d3 715 cout << " !!!!! " << nBadChannel_a2 << " !!!!!!!! Bad Calib.: BP= " << busPatchId << " Manu_Id= " << manuId
90293ba6 716 << " Ch.= " << channelId << ":";
717 cout << " a2 = " << par[2] << " out of limit : [" << goodA2Min << "," << goodA2Max
718 << "]" << endl;
53f515d3 719
720 for (Int_t j = 0; j < nbpf2; ++j)
721 {cout << j << " " << x[j] << " " << xErr[j] << " " << y[j] << " " << yErr[j] << endl;}
90293ba6 722 }
90293ba6 723 }
90293ba6 724
53f515d3 725 Q = p1*16 + p2; // fit quality
726 if(p1==0)Q=0; // bad linear fit <=> bad calibration
727
728 if(p1>0 && p2>0)
90293ba6 729 {
53f515d3 730 nGoodChannel++;
731 sumProbChi2P2 += prChi2P2;
732 sumA2 += par[2];
733 }
734 else
735 {
736 nBadChannel++;
737 if(busPatchId < num_tot_BP && manuId < num_tot_Manu) bad_channel[busPatchId][manuId]++;
738 else{cout << " Warning : busPatch = " << busPatchId << " Manu = " << manuId << endl;}
739 if(gPrintLevel>=2)fprintf(pfilef,"%4i %5i %2i %7.4f %10.3e %4i %2x\n",busPatchId,manuId,channelId,par[1],par[2],threshold,Q);
90293ba6 740 }
53f515d3 741
742
743 if(p1>0)
744 {
745 nGoodChannel_a1++;
746 sumProbChi2 += prChi2;
747 sumA1 += par[1];
748 gain=1./(par[1]*capa);
749 }
750
90293ba6 751
752 tg->Fill();
753
754 if (!flatOutputFile.IsNull())
755 {
756 fprintf(pfilew,"%4i %5i %2i %7.4f %10.3e %4i %2x\n",busPatchId,manuId,channelId,par[1],par[2],threshold,Q);
757 }
758
759 // Plots
760
761 if(gPlotLevel){
53f515d3 762 if(Q==0 and nplot < 100)
763// if(p1>1 && p2==0 and nplot < 100)
764// if(p1>1 && p2>1 and nplot < 100)
765 {
766 nplot++;
767 TF1 *f2Calib = new TF1("f2Calib",funcCalib,0.,gkADCMax,NFITPARAMS);
768
769 TGraphErrors *graphErr = new TGraphErrors(nEntries,pedMean,injCharge,pedSigma,injChargeErr);
770
771 sprintf(graphName,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
772
773 graphErr->SetTitle(graphName);
774 graphErr->SetMarkerColor(3);
775 graphErr->SetMarkerStyle(12);
776 graphErr->Write(graphName);
777
778 sprintf(graphName,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
779 f2Calib->SetTitle(graphName);
780 f2Calib->SetLineColor(4);
781 f2Calib->SetParameters(par);
782 f2Calib->Write(graphName);
783
784 delete graphErr;
785 delete f2Calib;
786 }
90293ba6 787 }
3f637cfc 788 }
90293ba6 789 nmanu++;
53f515d3 790 if(fmod(nmanu,100)==0)std::cout << " Nb manu = " << nmanu << std::endl;
3f637cfc 791 }
792
793 // file outputs for gain
53f515d3 794 if (!flatOutputFile.IsNull()) fclose(pfilew);
795 if(gPrintLevel==2){ fclose(pfilen); fclose(pfilef);}
796 if(gPrintLevel==3) fclose(pfilep);
90293ba6 797
798 tg->Write();
799 histoFile->Close();
3f637cfc 800
90293ba6 801 //OutPut
802 if (gPrintLevel)
803 {
53f515d3 804 filcout << "\n List of problematic BusPatch and Manu " << endl;
805 filcout << " ========================================" << endl;
806 filcout << " BP Manu Nb Channel " << endl ;
807 filcout << " ========================================" << endl;
808 for ( Int_t i = 0 ; i < num_tot_BP ; i++ )
809 { for ( Int_t j = 0 ; j < num_tot_Manu ; j++ )
810 if (bad_channel[i][j] != 0 ) filcout << "\t" << i << "\t " << j << "\t\t" << bad_channel[i][j] << endl;}
811 filcout << " ========================================" << endl;
812
813
814 filcout << "\n Nb of channels in raw data = " << nmanu*64 << " (" << nmanu << " Manu)" << endl;
815 filcout << "\n Nb of fully calibrated channel = " << nGoodChannel << " (" << goodA1Min << "<a1<" << goodA1Max
90293ba6 816 << " and " << goodA2Min << "<a2<" << goodA2Max << ") " << endl;
53f515d3 817 filcout << "\n Nb of Bad channel = " << nBadChannel << endl;
818
819 filcout << "\n Nb of Good a1 channels = " << nGoodChannel_a1 << " (" << goodA1Min << "<a1<" << goodA1Max << ") " << endl;
90293ba6 820
53f515d3 821 Double_t meanA1 = sumA1/(nGoodChannel_a1);
822 Double_t meanProbChi2 = sumProbChi2/(nGoodChannel_a1);
823 Double_t meanA2 = sumA2/(nGoodChannel);
824 Double_t meanProbChi2P2 = sumProbChi2P2/(nGoodChannel);
90293ba6 825
826 Double_t capaManu = 0.2; // pF
53f515d3 827 filcout << "\n linear fit : <a1> = " << meanA1 << "\t <gain> = " << 1./(meanA1*capaManu)
90293ba6 828 << " mV/fC (capa= " << capaManu << " pF)" << endl;
53f515d3 829 filcout << " Prob(chi2)> = " << meanProbChi2 << endl;
830 filcout << "\n parabolic fit: <a2> = " << meanA2 << endl;
831 filcout << " Prob(chi2)> = " << meanProbChi2P2 << "\n" << endl;
832
833 }
834
835
836 return ;
837
3f637cfc 838}
839
840//*************************************************************//
841
842// main routine
843int main(Int_t argc, Char_t **argv)
844{
845
fd99693f 846 // needed for streamer application
847 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
848 "*",
849 "TStreamerInfo",
850 "RIO",
851 "TStreamerInfo()");
852
a76f513d 853 TFitter *minuitFit = new TFitter(NFITPARAMS);
854 TVirtualFitter::SetFitter(minuitFit);
fd99693f 855
3f637cfc 856 Int_t skipEvents = 0;
857 Int_t maxEvents = 1000000;
90293ba6 858 Int_t MaxDateEvents = 1000000;
859 Int_t injCharge = 0;
0aa03544 860 Double_t nSigma = 3;
3f637cfc 861 Int_t threshold = -1;
862 Char_t inputFile[256];
90293ba6 863
666b5407 864 Int_t gGlitchErrors= 0;
865 Int_t gParityErrors= 0;
866 Int_t gPaddingErrors= 0;
867
53f515d3 868 TString fesOutputFile;
3f637cfc 869 TString crocusOutputFile;
870 TString crocusConfigFile;
871
3f637cfc 872// option handler
873
874 // decode the input line
875 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
876 {
877 Char_t* arg;
878
879 arg = argv[i];
880 if (arg[0] != '-') continue;
881 switch (arg[1])
882 {
883 case 'f' :
884 i++;
885 sprintf(inputFile,argv[i]);
886 break;
887 case 'a' :
888 i++;
889 flatOutputFile = argv[i];
890 break;
53f515d3 891 case 'b' :
892 i++;
893 sprintf(gOutFolder,argv[i]);
894 break;
3f637cfc 895 case 'o' :
896 i++;
897 crocusOutputFile = argv[i];
898 break;
899 case 'c' :
900 i++;
901 crocusConfigFile = argv[i];
902 break;
903 case 'e' :
904 i++;
90293ba6 905 gCommand = argv[i];
3f637cfc 906 break;
907 case 'd' :
908 i++;
90293ba6 909 gPrintLevel=atoi(argv[i]);
910 break;
911 case 'g' :
912 i++;
913 gPlotLevel=atoi(argv[i]);
3f637cfc 914 break;
915 case 's' :
916 i++;
917 skipEvents=atoi(argv[i]);
918 break;
90293ba6 919 case 'l' :
920 i++;
921 injCharge=atoi(argv[i]);
922 break;
923 case 'm' :
924 i++;
925 sscanf(argv[i],"%d",&MaxDateEvents);
926 break;
3f637cfc 927 case 'n' :
928 i++;
929 sscanf(argv[i],"%d",&maxEvents);
930 break;
931 case 'p' :
932 i++;
0aa03544 933 sscanf(argv[i],"%lf",&nSigma);
3f637cfc 934 break;
90293ba6 935 case 'r' :
936 i++;
937 sprintf(gHistoFileName_gain,argv[i]);
938 break;
3f637cfc 939 case 't' :
940 i++;
941 sscanf(argv[i],"%d",&threshold);
942 break;
943 case 'h' :
944 i++;
945 printf("\n******************* %s usage **********************",argv[0]);
946 printf("\n%s -options, the available options are :",argv[0]);
947 printf("\n-h help (this screen)");
948 printf("\n");
949 printf("\n Input");
950 printf("\n-f <raw data file> (default = %s)",inputFile);
951 printf("\n-c <Crocus config. file> (default = %s)",crocusConfigFile.Data());
952 printf("\n");
953 printf("\n Output");
954 printf("\n-a <Flat ASCII file> (default = %s)",flatOutputFile.Data());
53f515d3 955 printf("\n-o <CROCUS cmd file> (default = %s)",crocusOutputFile.Data());
3f637cfc 956 printf("\n");
957 printf("\n Options");
53f515d3 958 printf("\n-b <output directory> (default = %s)",gOutFolder);
90293ba6 959 printf("\n-d <print level> (default = %d)",gPrintLevel);
960 printf("\n-g <plot level> (default = %d)",gPlotLevel);
961 printf("\n-l <DAC level> (default = %d)",injCharge);
962 printf("\n-m <max date events> (default = %d)",MaxDateEvents);
3f637cfc 963 printf("\n-s <skip events> (default = %d)",skipEvents);
964 printf("\n-n <max events> (default = %d)",maxEvents);
965 printf("\n-p <n sigmas> (default = %f)",nSigma);
90293ba6 966 printf("\n-r root file data for gain(default = %s)",gHistoFileName_gain);
3f637cfc 967 printf("\n-t <threshold (-1 = no)> (default = %d)",threshold);
90293ba6 968 printf("\n-e <execute ped/gain> (default = %s)",gCommand.Data());
3f637cfc 969 printf("\n-e <gain create> make gain & create a new root file");
970 printf("\n-e <gain> make gain & update root file");
971 printf("\n-e <gain compute> make gain & compute gains");
972
973 printf("\n\n");
974 exit(-1);
975 default :
976 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
977 argc = 2; exit(-1); // exit if error
978 } // end of switch
979 } // end of for i
980
90293ba6 981 // set gCommand to lower case
982 gCommand.ToLower();
3f637cfc 983
53f515d3 984
3f637cfc 985 // decoding the events
986
987 Int_t status;
3f637cfc 988 void* event;
989
90293ba6 990 gPedMeanHisto = 0x0;
991 gPedSigmaHisto = 0x0;
3f637cfc 992
993 TStopwatch timers;
994
995 timers.Start(kTRUE);
996
997 // once we have a configuration file in db
998 // copy locally a file from daq detector config db
999 // The current detector is identified by detector code in variable
1000 // DATE_DETECTOR_CODE. It must be defined.
1001 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
1002 // instead of the database. The usual environment variables are not needed.
1003 if (!crocusConfigFile.IsNull()) {
1004 status = daqDA_DB_getFile("myconfig", crocusConfigFile.Data());
1005 if (status) {
1006 printf("Failed to get config file : %d\n",status);
1007 return -1;
1008 }
1009 }
1010
1011
1012 status = monitorSetDataSource(inputFile);
1013 if (status) {
1014 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
1015 << " " << monitorDecodeError(status) << endl;
1016 return -1;
1017 }
1018 status = monitorDeclareMp("MUON Tracking monitoring");
1019 if (status) {
1020 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
1021 << " " << monitorDecodeError(status) << endl;
1022 return -1;
1023 }
1024
0aa03544 1025 Int_t busPatchId;
1026 UShort_t manuId;
1027 UChar_t channelId;
1028 UShort_t charge;
96fa832f 1029 TString key("MUONTRKda :");
666b5407 1030
1031 AliMUONRawStreamTracker* rawStream = 0;
1032
96fa832f 1033
53f515d3 1034 if (gCommand.CompareTo("comp") != 0)
1035 {
1036 cout << "\nMUONTRKda : Reading data from file " << inputFile <<endl;
3f637cfc 1037
53f515d3 1038 while(1)
1039 {
1040 if (gNDateEvents >= MaxDateEvents) break;
1041 if (gNEvents >= maxEvents) break;
1042 if (gNEvents && gNEvents % 100 == 0)
666b5407 1043 cout<<"Cumulated: DATE events = " << gNDateEvents << " Used events = " << gNEvents << endl;
53f515d3 1044
1045 // check shutdown condition
1046 if (daqDA_checkShutdown())
1047 break;
1048
1049 // Skip Events if needed
1050 while (skipEvents) {
1051 status = monitorGetEventDynamic(&event);
1052 skipEvents--;
1053 }
3f637cfc 1054
53f515d3 1055 // starts reading
1056 status = monitorGetEventDynamic(&event);
1057 if (status < 0) {
1058 cout<<"EOF found"<<endl;
1059 break;
1060 }
1061
53f515d3 1062 // decoding rawdata headers
1063 AliRawReader *rawReader = new AliRawReaderDate(event);
3f637cfc 1064
53f515d3 1065 Int_t eventType = rawReader->GetType();
1066 gRunNumber = rawReader->GetRunNumber();
1067
1068 // Output log file initialisations
1069
1070 if(gNDateEvents==0)
1071 {
1072 if (gCommand.CompareTo("ped") == 0){
1073 sprintf(flatFile,"%s/MUONTRKda_ped_%d.log",gOutFolder,gRunNumber);
1074 logOutputFile=flatFile;
1075
1076 filcout.open(logOutputFile.Data());
1077 filcout<<"//=================================================" << endl;
1078 filcout<<"// MUONTRKda for Pedestal run = " << gRunNumber << endl;
1079 cout<<"\n ******** MUONTRKda for Pedestal run = " << gRunNumber << "\n" << endl;
1080 }
1081
1082 if (gCommand.Contains("gain")){
1083 sprintf(flatFile,"%s/%s_%d_DAC_%d.log",gOutFolder,filenam,gRunNumber,injCharge);
1084 logOutputFile=flatFile;
1085
1086 filcout.open(logOutputFile.Data());
1087 filcout<<"//=================================================" << endl;
1088 filcout<<"// MUONTRKda for Gain run = " << gRunNumber << " (DAC=" << injCharge << ")" << endl;
1089 cout<<"\n ******** MUONTRKda for Gain run = " << gRunNumber << " (DAC=" << injCharge << ")\n" << endl;
1090 }
1091
1092 filcout<<"//=================================================" << endl;
1093 filcout<<"// * Date : " << date.AsString("l") << "\n" << endl;
1094 cout<<" * Date : " << date.AsString("l") << "\n" << endl;
1095
1096 }
1097
1098 gNDateEvents++;
1099
3f637cfc 1100
3f637cfc 1101
53f515d3 1102 if (eventType != PHYSICS_EVENT)
1103 continue; // for the moment
3f637cfc 1104
53f515d3 1105 // decoding MUON payload
666b5407 1106// AliMUONRawStreamTracker* rawStream = new AliMUONRawStreamTracker(rawReader);
1107 rawStream = new AliMUONRawStreamTracker(rawReader);
96fa832f 1108 rawStream->DisableWarnings();
3f637cfc 1109
666b5407 1110// // loops over DDL
1111// rawStream->First(); // if GlitchError ? what we are doing ?
1112// while( (status = rawStream->Next(busPatchId, manuId, channelId, charge)) )
1113// {
0aa03544 1114
666b5407 1115// if (gNEvents == 0) gNChannel++;
1116
1117// MakePed(busPatchId, (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
3f637cfc 1118
666b5407 1119// } // Next digit
1120
1121// if (!rawStream->IsErrorMessage()) {
1122// gNEvents++;
1123// }
1124
1125 // loops over DDL to find good events (Alberto 11/12/07)
1126 rawStream->First(); // if GlitchError ? what we are doing ?
1127 while( (status = rawStream->Next(busPatchId, manuId, channelId, charge)) ) {
53f515d3 1128 } // Next digit
1129
96fa832f 1130 if (!rawStream->IsErrorMessage()) {
666b5407 1131 // loops over DDL to find good events
1132 rawStream->First(); // if GlitchError ? what we are doing ?
1133 while( (status = rawStream->Next(busPatchId, manuId, channelId, charge)) ) {
1134
1135 if (gNEvents == 0)
1136 gNChannel++;
1137
1138 MakePed(busPatchId, (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
1139 } // Next digit
1140 gNEvents++;
1141 }
1142 else
1143 {
1144 filcout<<"Event # "<<*(rawReader->GetEventId())<<" rejected"<<endl;
1145 }
96fa832f 1146 if (rawStream->GetPayLoad()->GetGlitchErrors()) gGlitchErrors++;
1147 if (rawStream->GetPayLoad()->GetParityErrors()) gParityErrors++;
1148 if (rawStream->GetPayLoad()->GetPaddingErrors()) gPaddingErrors++;
1149
1150 AliMUONLogger* log = rawStream->GetPayLoad()->GetErrorLogger();
1151 log->Print(key, filcout);
53f515d3 1152
1153 delete rawReader;
1154 delete rawStream;
3f637cfc 1155
53f515d3 1156 } // while (1)
1157 }
3f637cfc 1158
3f637cfc 1159
90293ba6 1160
1161 if (gCommand.CompareTo("ped") == 0)
1162 {
53f515d3 1163 sprintf(flatFile,"MUONTRKda_ped_%d.ped",gRunNumber);
90293ba6 1164 if(flatOutputFile.IsNull())flatOutputFile=flatFile;
1165 MakePedStore(flatOutputFile);
1166 }
3f637cfc 1167
1168 // option gain -> update root file with pedestal results
1169 // gain + create -> recreate root file
1170 // gain + comp -> update root file and compute gain parameters
1171
53f515d3 1172 if (gCommand.Contains("gain"))
1173 {
1174 MakePedStoreForGain(injCharge);
1175 }
3f637cfc 1176
53f515d3 1177 if (gCommand.Contains("comp"))
1178 {
1179
1180// if(flatOutputFile.IsNull())flatOutputFile="MUONTRKda_gain.par";
1181// MakeGainStore(flatOutputFile);
1182 MakeGainStore();
1183 }
3f637cfc 1184
1185
90293ba6 1186 delete gPedestalStore;
3f637cfc 1187
a76f513d 1188 delete minuitFit;
1189 TVirtualFitter::SetFitter(0);
1190
3f637cfc 1191 timers.Stop();
1192
90293ba6 1193 if (gCommand.CompareTo("comp") != 0)
1194 {
666b5407 1195 cout << "\nMUONTRKda : Nb of DATE events = " << gNDateEvents << endl;
1196 cout << "MUONTRKda : Nb of Glitch errors = " << gGlitchErrors << endl;
1197 cout << "MUONTRKda : Nb of Parity errors = " << gParityErrors << endl;
1198 cout << "MUONTRKda : Nb of Padding errors = " << gPaddingErrors << endl;
90293ba6 1199 cout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
53f515d3 1200
666b5407 1201 filcout << "\nMUONTRKda : Nb of DATE events = " << gNDateEvents << endl;
1202 filcout << "MUONTRKda : Nb of Glitch errors = " << gGlitchErrors << endl;
1203 filcout << "MUONTRKda : Nb of Parity errors = " << gParityErrors << endl;
1204 filcout << "MUONTRKda : Nb of Padding errors = " << gPaddingErrors << endl;
53f515d3 1205 filcout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
1206
90293ba6 1207 }
53f515d3 1208
1209
666b5407 1210 cout << "\nMUONTRKda : Output logfile generated : " << logOutputFile << endl;
53f515d3 1211
90293ba6 1212 if (gCommand.CompareTo("ped") == 0)
1213 {
1214 if (!(crocusConfigFile.IsNull()))
666b5407 1215 cout << "MUONTRKda : CROCUS command file generated : " << crocusOutputFile.Data() << endl;
90293ba6 1216 else
1217 cout << "MUONTRKda : WARNING no CROCUS command file generated" << endl;
666b5407 1218 cout << "MUONTRKda : Pedestal Histo file : " << gHistoFileName << endl;
1219 cout << "MUONTRKda : Flat pedestal file (to SHUTTLE) : " << flatOutputFile << endl;
90293ba6 1220 }
3f637cfc 1221 else
90293ba6 1222 {
666b5407 1223 cout << "MUONTRKda : Data file for gain calculation : " << gHistoFileName_gain << endl;
53f515d3 1224 }
1225
1226 if (gCommand.CompareTo("comp") == 0)
1227 {
666b5407 1228 cout << "MUONTRKda : Root Histo. file generated : " << gRootFileName << endl;
1229 cout << "MUONTRKda : Flat gain file (to SHUTTLE) : " << flatOutputFile << endl;
53f515d3 1230 }
1231
1232
1233
1234 // Store IN FES
1235
1236 if (gCommand.CompareTo("comp") == 0 || gCommand.CompareTo("ped") == 0)
1237 {
1238 printf("\n ***** STORE FILE in FES ****** \n");
1239
1240 // to be sure that env variable is set
666b5407 1241// gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
53f515d3 1242
1243 if (!flatOutputFile.IsNull())
1244 {
1245
1246 // flatOutputFile.Prepend("./");
666b5407 1247 if (gCommand.CompareTo("ped") == 0)
1248 status = daqDA_FES_storeFile(flatOutputFile.Data(),"PEDESTALS");
1249 else
1250 status = daqDA_FES_storeFile(flatOutputFile.Data(),"GAINS");
1251
1252 if (status)
53f515d3 1253 {
1254 printf(" Failed to export file : %d\n",status);
1255 }
1256 else if(gPrintLevel) printf("Export file: %s\n",flatOutputFile.Data());
1257 }
90293ba6 1258 }
3f637cfc 1259
53f515d3 1260 filcout.close();
90293ba6 1261 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
3f637cfc 1262
1263 return status;
666b5407 1264}