1 /*********************************************************************************
2 - Contact: Brigitte Cheynis b.cheynis@ipnl.in2p3.fr
5 - Reference run number : 137366
8 - Number of events needed: >=2000
9 - Input Files: argument list
10 - Output Files: FXS file V0_EqualizationFactors.dat (Channel equalization factors)
11 - Trigger types used: PHYSICS_EVENT
12 **********************************************************************************/
14 /**********************************************************************************
16 * VZERO Detector Algorithm for extracting channel equalization factors for Pb-Pb *
19 ***********************************************************************************/
27 #include <AliVZERORawStream.h>
28 #include <AliRawReaderDate.h>
29 #include <AliRawReader.h>
38 #include "TPluginManager.h"
43 Int_t GetOfflineChannel(Int_t channel);
45 /* Main routine --- Arguments: monitoring data source */
47 int main(int argc, char **argv) {
49 /* magic line from Cvetan */
50 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
57 printf("Wrong number of arguments\n");
61 //___________________________________________________
62 // Get parameters from V00DAEqualFactors.config file
63 Int_t neventsMin = 2000;
65 Int_t kStartClock = 9; // First clock in the search for max adc
66 Int_t kEndClock = 11; // Last clock in the search for max adc
67 Int_t kNPreClocks = 6; // Number of clock before max used in the charge sum
68 Int_t kNPostClocks = 1; // Number of clock after max used in the charge sum
70 UChar_t kNFlagsCut = 63;// Minimum number of TDC flags requested, replaces the trigger selection
75 status = daqDA_DB_getFile("V00DAEqualFactors.config","./V00DAEqualFactors.config");
77 printf("Failed to get Config file (V00DAEqualFactors.config) from DAQ DB, status=%d\n", status);
78 printf("Take default values of parameters for pedestal calculation \n");
80 /* open the config file and retrieve cuts */
81 FILE *fpConfig = fopen("V00DAEqualFactors.config","r");
82 int res = fscanf(fpConfig,"%d %d %d %d %d %hhu %d %f",
83 &neventsMin,&kStartClock,&kEndClock,&kNPreClocks,&kNPostClocks,&kNFlagsCut,&kNBins,&kRange);
85 printf("Failed to get values from Config file (V00DAEqualFactors.config): wrong file format - 7 integers and 1 float are expected - \n");
90 printf("Minimum number of events to process = %d; First LHC Clock = %d; Last LHC Clock = %d; N Pre Clock = %d; N Post Clock = %d; Minimum number of TDC flags = %hhu; Number of histogram bins = %d; Histogram range = %.3f\n",
91 neventsMin,kStartClock, kEndClock, kNPreClocks, kNPostClocks, kNFlagsCut, kNBins, kRange);
94 for(Int_t j = 0; j < 64; ++j) fMedian[j] = new TH1D(Form("fMedian_%d",j),"Slopes weighted median, channel par channel",kNBins,0,kRange);
96 Bool_t fFirst = kTRUE;
97 Float_t fPrevTotCharge = 0;
99 for(Int_t j = 0; j < 64; ++j) fPrevadc[j] = 0;
101 //___________________________________________________
103 /* define data source : this is argument 1 */
104 status=monitorSetDataSource( argv[1] );
106 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
110 /* declare monitoring program */
111 status=monitorDeclareMp( __FILE__ );
113 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
117 /* define wait event timeout - 1s max */
119 monitorSetNoWaitNetworkTimeout(1000);
121 /* init counters on events */
122 int neventsPhysicsAll=0;
123 int neventsPhysics=0;
127 /* loop on events (infinite) */
129 struct eventHeaderStruct *event;
130 eventTypeType eventT;
132 /* check shutdown condition */
133 if (daqDA_checkShutdown()) {break;}
135 /* get next event (blocking call until timeout) */
136 status=monitorGetEventDynamic((void **)&event);
137 if (status==MON_ERR_EOF) {
138 printf ("End of File detected\n");
139 break; /* end of monitoring file has been reached */
143 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
147 /* retry if got no event */
148 if (event==NULL) continue;
151 eventT=event->eventType;
153 switch (event->eventType){
159 printf("End Of Run detected\n");
164 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
166 AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
167 if (rawStream->Next()) {
169 UShort_t triggers = rawStream->GetTriggerInputs();
171 for(Int_t i = 0; i < 64; ++i) {
172 if (rawStream->GetBBFlag(i,10)) nFlags++;
174 if (nFlags >= kNFlagsCut) { // Check if the number of minimum number of TDC flags is reached (trigger selection)
179 Float_t totCharge = 0.;
180 for(Int_t i = 0; i < 64; ++i) {
184 for(Int_t j = kStartClock; j <= kEndClock; ++j) {
185 Float_t charge = (Float_t)(rawStream->GetPedestal(i,j));
193 Int_t start = imax - kNPreClocks;
194 if (start < 0) start = 0;
195 Int_t end = imax + kNPostClocks;
196 if (end > 20) end = 20;
197 for(Int_t iClock = start; iClock <= end; iClock++) {
198 adc[i] += (Float_t)(rawStream->GetPedestal(i,iClock));
206 fPrevTotCharge = totCharge;
207 for(int i = 0; i < 64; ++i) fPrevadc[i] = adc[i];
211 Float_t deltaTotCharge = totCharge - fPrevTotCharge;
212 Float_t weight = deltaTotCharge*deltaTotCharge;
214 for(int i = 0; i < 64; ++i) {
215 fMedian[i]->Fill((adc[i]-fPrevadc[i])/deltaTotCharge,weight);
221 } // End : if rawstream
226 } // end of switch on event type
232 /* exit when last event received, no need to wait for TERM signal */
233 if (eventT==END_OF_RUN) {
234 printf("End Of Run event detected\n");
238 } // loop over events
240 printf("%d physics events processed (out of %d physics and %d total events)\n",neventsPhysics,neventsPhysicsAll,neventsTotal);
242 //___________________________________________________________________________
243 // Computes regression parameters
244 // charge_i = p0 + charge_tot * p1
246 if(neventsPhysics>neventsMin){
247 /* open result file to be exported to FES */
249 fp=fopen("./V0_EqualizationFactors.dat","w");
251 printf("Failed to open local result file\n");
256 for(int i = 0; i < 64; ++i) fMedian[i]->GetQuantiles(1,&beta[i],&q);
258 for(Int_t i=0; i<64; i++) {
259 fprintf(fp," %d %.5f\n",GetOfflineChannel(i), beta[i]*64.);
260 printf(" %d %.5f\n",GetOfflineChannel(i), beta[i]*64.);
263 /* close local result file and FXS result file*/
266 /* export result file to FES */
267 status=daqDA_FES_storeFile("./V0_EqualizationFactors.dat","V00DAEqualFactors");
269 printf("Failed to export file : %d\n",status);
272 /* store result file into Online DB */
273 status=daqDA_DB_storeFile("./V0_EqualizationFactors.dat","V00DAEqualFactors");
275 printf("Failed to store file into Online DB: %d\n",status);
279 // Take the last run's file from the DB
280 status=daqDA_DB_getFile("V00DAEqualFactors","./V0_EqualizationFactors.dat");
282 printf("Failed to get file from Online DB: %d\n",status);
285 /* export result file to FES */
286 status=daqDA_FES_storeFile("./V0_EqualizationFactors.dat","V00DAEqualFactors");
288 printf("Failed to export file : %d\n",status);
295 Int_t GetOfflineChannel(Int_t channel) {
297 // Channel mapping Online - Offline:
299 Int_t fOfflineChannel[64] = {39, 38, 37, 36, 35, 34, 33, 32,
300 47, 46, 45, 44, 43, 42, 41, 40,
301 55, 54, 53, 52, 51, 50, 49, 48,
302 63, 62, 61, 60, 59, 58, 57, 56,
303 7, 6, 5, 4, 3, 2, 1, 0,
304 15, 14, 13, 12, 11, 10, 9, 8,
305 23, 22, 21, 20, 19, 18, 17, 16,
306 31, 30, 29, 28, 27, 26, 25, 24};
307 return fOfflineChannel[channel];