1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This class provides ITS SSD data handling
22 // Author: Oleksandr Borysov
24 ///////////////////////////////////////////////////////////////////////////////
26 #include <Riostream.h>
27 #include "AliITSHandleDaSSD.h"
33 #include "TObjArray.h"
35 #include "AliITSNoiseSSD.h"
36 #include "AliITSPedestalSSD.h"
37 #include "AliITSBadChannelsSSD.h"
38 #include "AliITSRawStreamSSD.h"
39 #include "AliRawReaderDate.h"
41 #include "AliITSChannelDaSSD.h"
44 ClassImp(AliITSHandleDaSSD)
49 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698; // Number of SSD modules in ITS
50 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerDdl = 108; // Number of SSD modules in DDL
51 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerSlot = 12; // Number of SSD modules in Slot
52 const Float_t AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0; // Defalt value for fPedestalThresholdFactor
53 const Float_t AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0; // Defalt value for fCmThresholdFactor
55 //______________________________________________________________________________
56 AliITSHandleDaSSD::AliITSHandleDaSSD() :
57 fRawDataFileName(NULL),
66 fPedestalThresholdFactor(fgkPedestalThresholdFactor),
67 fCmThresholdFactor(fgkCmThresholdFactor)
69 // Default constructor
73 //______________________________________________________________________________
74 AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) :
75 fRawDataFileName(NULL),
84 fPedestalThresholdFactor(fgkPedestalThresholdFactor) ,
85 fCmThresholdFactor(fgkCmThresholdFactor)
87 if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!");
91 //______________________________________________________________________________
92 AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) :
94 fRawDataFileName(ssdadldc.fRawDataFileName),
95 fNumberOfModules(ssdadldc.fNumberOfModules),
97 fModIndProcessed(ssdadldc.fModIndProcessed),
98 fModIndRead(ssdadldc.fModIndRead),
100 fNumberOfEvents(ssdadldc.fNumberOfEvents),
101 fLdcId(ssdadldc.fLdcId),
102 fRunId(ssdadldc.fRunId),
103 fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor),
104 fCmThresholdFactor(ssdadldc.fCmThresholdFactor)
107 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
108 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
110 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
111 if (ssdadldc.fModules[modind]) {
112 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
113 if (!fModules[modind]) {
114 AliError("AliITSHandleDaSSD: Error copy constructor");
115 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
120 } else fModules[modind] = NULL;
123 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
124 fNumberOfModules = 0;
131 //______________________________________________________________________________
132 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
134 // assignment operator
135 if (this == &ssdadldc) return *this;
137 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
141 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
142 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
143 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
145 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
146 if (ssdadldc.fModules[modind]) {
147 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
148 if (!fModules[modind]) {
149 AliError("AliITSHandleDaSSD: Error assignment operator");
150 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
155 } else fModules[modind] = NULL;
158 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
159 fNumberOfModules = 0;
167 //______________________________________________________________________________
168 AliITSHandleDaSSD::~AliITSHandleDaSSD()
170 // Default destructor
173 for (Int_t i = 0; i < fNumberOfModules; i++)
175 if (fModules[i]) delete fModules[i];
179 if (fModIndex) delete [] fModIndex;
184 //______________________________________________________________________________
185 void AliITSHandleDaSSD::Reset()
187 // Delete array of AliITSModuleDaSSD* objects.
189 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
193 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
194 fRawDataFileName = NULL;
195 fModIndProcessed = fModIndRead = 0;
198 fPedestalThresholdFactor = fgkPedestalThresholdFactor;
199 fCmThresholdFactor = fgkCmThresholdFactor;
204 //______________________________________________________________________________
205 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname, const Char_t *configfname)
207 // Read raw data file and set initial and configuration parameters
208 Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
209 Int_t nofeqipmentev, nofeqipment = 0, eqn = 0;
210 AliRawReaderDate *rawreaderdate = NULL;
211 UChar_t *data = NULL;
212 Long_t datasize = 0, eqbelsize = 1;
214 if (configfname) ReadConfigurationFile(configfname);
215 rawreaderdate = new AliRawReaderDate(rdfname, 0);
216 if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
217 AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
221 if (rawreaderdate->NextEvent()) {
222 fRunId = rawreaderdate->GetRunNumber();
223 rawreaderdate->RewindEvents();
224 } else { MakeZombie(); return kFALSE; }
225 if (fModules) Reset();
226 rawreaderdate->SelectEvents(-1);
228 while (rawreaderdate->NextEvent()) {
229 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
232 while (rawreaderdate->ReadNextData(data)) {
233 fLdcId = rawreaderdate->GetLDCId();
235 datasize = rawreaderdate->GetDataSize();
236 eqbelsize = rawreaderdate->GetEquipmentElementSize();
237 if ( (datasize % eqbelsize) || (eqbelsize != sizeof(long32)) ) {
238 AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %i is not an integer of equipment data size %i",
239 rdfname, datasize, eqbelsize));
243 nofstripsev += (Int_t) (datasize / eqbelsize);
245 if (physeventind++) {
246 if (nofstrips != nofstripsev) AliWarning("AliITSHandleDaSSD: number of strips varies from event to evnt");
247 if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to evnt");
249 nofstrips = nofstripsev;
250 nofeqipment = nofeqipmentev;
251 if (strn < nofstrips) strn = nofstrips;
252 if (eqn < nofeqipment) eqn = nofeqipment;
254 delete rawreaderdate;
255 if ((physeventind > 0) && (strn > 0))
257 fNumberOfEvents = physeventind;
258 fRawDataFileName = rdfname;
259 fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
261 for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1;
262 else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created",
263 rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
264 if (SetNumberOfModules(fgkNumberOfSSDModules)) {
265 TString str = TString::Format("Max number of equipment: %i, max number of channels: %i\n", eqn, strn);
266 DumpInitData(str.Data());
275 //______________________________________________________________________________
276 Bool_t AliITSHandleDaSSD::ReadConfigurationFile(const Char_t * /* configfname */)
278 // Dowload configuration parameters from configuration file or database
284 //______________________________________________________________________________
285 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
287 // Retrieve AliITSModuleDaSSD object from the array
288 if (!fModules) return NULL;
289 for (Int_t i = 0; i < fNumberOfModules; i++) {
291 if ( (fModules[i]->GetDdlId() == ddlID)
292 && (fModules[i]->GetAD() == ad)
293 && (fModules[i]->GetADC() == adc))
301 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
303 // Retrieve the position of AliITSModuleDaSSD object in the array
304 if (!fModules) return -1;
305 for (Int_t i = 0; i < fNumberOfModules; i++) {
307 if ( (fModules[i]->GetDdlId() == ddlID)
308 && (fModules[i]->GetAD() == ad)
309 && (fModules[i]->GetADC() == adc))
318 //______________________________________________________________________________
319 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
321 // Retrieve AliITSChannalDaSSD object from the array
322 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
323 if ( (fModules[modind]->GetDdlId() == ddlID)
324 && (fModules[modind]->GetAD() == ad)
325 && (fModules[modind]->GetADC() == adc) )
327 return fModules[modind]->GetStrip(stripID);
330 AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
331 ddlID, ad, adc, stripID));
337 //______________________________________________________________________________
338 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
340 // Assign array element with AliITSModuleDaSSD object
341 if ((index < fNumberOfModules) && (index >= 0))
343 if (fModules[index]) delete fModules[index];
344 fModules[index] = module;
352 //______________________________________________________________________________
353 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
355 // Allocates memory for AliITSModuleDaSSD objects
356 if (numberofmodules > fgkNumberOfSSDModules)
357 AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD",
358 numberofmodules, fgkNumberOfSSDModules));
360 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
364 fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
366 fNumberOfModules = numberofmodules;
367 memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
370 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
371 fNumberOfModules = 0;
379 //______________________________________________________________________________
380 Bool_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
382 // Reads raw data from file
383 AliRawReaderDate *rawreaderdate = NULL;
384 AliITSModuleDaSSD *module;
385 AliITSChannelDaSSD *strip;
386 Long_t datasize, eventind = 0;
387 Int_t nofstrips, eqbelsize;
391 if (!Init(fileName)){
392 AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
395 rawreaderdate = new AliRawReaderDate(fileName, 0);
396 rawreaderdate->SelectEvents(-1);
397 while (rawreaderdate->NextEvent()) {
398 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
399 fRunId = rawreaderdate->GetRunNumber();
401 while (rawreaderdate->ReadNextData(databyte)) {
402 fLdcId = rawreaderdate->GetLDCId();
403 data = reinterpret_cast<long32*>(databyte);
404 Int_t equipid = rawreaderdate->GetEquipmentId(); // EquipmentID required to access to rorc
405 Int_t equiptype = rawreaderdate->GetEquipmentType(); //
406 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID(); // GetDDLID(); index of DDL, ITS SSD: 33-48
407 datasize = rawreaderdate->GetDataSize();
408 eqbelsize = rawreaderdate->GetEquipmentElementSize();
409 if ( (datasize % eqbelsize) || (eqbelsize != sizeof(long32)) ) {
410 AliError(Form("AliITSHandleDaSSD: Error ReadCalibrationDataFile: event data size %i is not an integer of equipment data size %i",
411 datasize, eqbelsize));
414 nofstrips = (Int_t) (datasize / eqbelsize);
415 for (Int_t strind = 0; strind < nofstrips; strind++) {
416 UChar_t ad = (UChar_t) (data[strind] >> 28) & 0x0000000F; // index of AD module 0-9
417 UChar_t adc = (UChar_t) (data[strind] >> 24) & 0x0000000F; // index of ADC module 0-5, 8-13
418 UShort_t stripID = (UShort_t)(data[strind] >> 12) & 0x000007FF; // strip number 0-1535
419 Short_t signal = (Short_t)(data[strind] & 0x00000FFF);
420 signal = (signal > AliITSChannelDaSSD::GetUnderflowConst()) ? (signal - 2 * AliITSChannelDaSSD::GetUnderflowConst())
422 if (!(module = GetModule(ddlID, ad, adc))) {
423 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
424 if (!module->SetModuleIdData (ddlID, ad, adc, RetrieveModuleId(ddlID, ad, adc))) return kFALSE;
425 module->SetModuleRorcId (equipid, equiptype);
426 fModules[modind++] = module;
428 if (!(strip = module->GetStrip(stripID))) {
429 strip = new AliITSChannelDaSSD(stripID, eventsnumber);
430 module->SetStrip(strip, stripID);
432 strip->SetSignal(eventind, signal);
434 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
436 if (++eventind > eventsnumber) break;
438 delete rawreaderdate;
439 return RelocateModules();
444 //______________________________________________________________________________
445 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
447 // Reads raw data from file
448 AliRawReaderDate *rawreaderdate = NULL;
449 AliITSModuleDaSSD *module;
450 AliITSChannelDaSSD *strip;
451 Long_t datasize, eventind = 0;
452 Int_t nofstrips, eqbelsize, nofeqipmentev;
456 if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
458 AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
461 rawreaderdate->SelectEvents(-1);
463 while (rawreaderdate->NextEvent()) {
464 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
466 while (rawreaderdate->ReadNextData(databyte)) {
467 data = reinterpret_cast<long32*>(databyte);
468 Int_t equipid = rawreaderdate->GetEquipmentId(); // EquipmentID required to access to rorc
469 Int_t equiptype = rawreaderdate->GetEquipmentType(); //
470 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID(); // GetDDLID(); index of DDL, ITS SSD: 33-48
471 datasize = rawreaderdate->GetDataSize();
472 eqbelsize = rawreaderdate->GetEquipmentElementSize();
473 if ( (datasize % eqbelsize) || (eqbelsize != sizeof(long32)) ) {
474 AliError(Form("AliITSHandleDaSSD: Error ReadCalibrationDataFile: event data size %i is not an integer of equipment data size %i",
475 datasize, eqbelsize));
478 nofstrips = (Int_t) (datasize / eqbelsize);
479 for (Int_t strind = 0; strind < nofstrips; strind++) {
480 UChar_t ad = (UChar_t) (data[strind] >> 28) & 0x0000000F; // index of AD module 0-9
481 UChar_t adc = (UChar_t) (data[strind] >> 24) & 0x0000000F; // index of ADC module 0-5, 8-13
482 UShort_t stripID = (UShort_t)(data[strind] >> 12) & 0x000007FF; // strip number 0-1535
483 Short_t signal = (Short_t)(data[strind] & 0x00000FFF);
484 signal = (signal > AliITSChannelDaSSD::GetUnderflowConst()) ? (signal - 2 * AliITSChannelDaSSD::GetUnderflowConst())
487 Int_t indpos = (nofeqipmentev * fgkNumberOfSSDModulesPerDdl)
488 + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
489 Int_t modpos = fModIndex[indpos];
490 if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
491 if ((modpos < 0) && (modind < modulesnumber)) {
492 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
493 if (!module->SetModuleIdData (ddlID, ad, adc, RetrieveModuleId(ddlID, ad, adc))) return 0;
494 module->SetModuleRorcId (equipid, equiptype);
495 modpos = fModIndRead + modind;
497 fModules[modpos] = module;
498 fModIndex[indpos] = modpos;
500 if (!(strip = fModules[modpos]->GetStrip(stripID))) {
501 strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
502 fModules[modpos]->SetStrip(strip, stripID);
504 strip->SetSignal(eventind, signal);
508 if (++eventind > fNumberOfEvents) break;
510 delete rawreaderdate;
511 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
512 fModIndRead += modind;
513 if (modind < modulesnumber) RelocateModules();
519 //______________________________________________________________________________
520 Bool_t AliITSHandleDaSSD::RelocateModules()
522 // Relocate memory for AliITSModuleDaSSD object array
524 AliITSModuleDaSSD **marray = NULL;
525 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
526 if (fModules[modind]) nm += 1;
527 if (nm == fNumberOfModules) return kTRUE;
528 marray = new (nothrow) AliITSModuleDaSSD* [nm];
530 AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
534 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
535 if (fModules[modind]) marray[nm++] = fModules[modind];
538 fNumberOfModules = fModIndRead = nm;
544 //______________________________________________________________________________
545 Bool_t AliITSHandleDaSSD::CalculatePedestal(AliITSModuleDaSSD *const module)
547 // Calculates Pedestal
548 AliITSChannelDaSSD *strip;
549 Float_t pedestal, noise;
552 if (!module) return kFALSE;
553 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
554 if (!(strip = module->GetStrip(strind))) continue;
555 if (!(signal = strip->GetSignal())) {
556 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
557 module->GetModuleId(), strind));
560 //************* pedestal first pass ****************
563 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
564 if (SignalOutOfRange(signal[ev])) ovev += 1;
565 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
566 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
567 strip->SetPedestal(pedestal);
568 //************* noise *******************************
569 Double_t nsum = 0.0L;
571 for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
572 if (SignalOutOfRange(signal[ev])) ovev += 1;
573 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
575 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
576 else noise = AliITSChannelDaSSD::GetUndefinedValue();
577 strip->SetNoise(noise);
578 //************* pedestal second pass ****************
581 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
582 if ( SignalOutOfRange(signal[ev])
583 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
584 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
585 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
586 strip->SetPedestal(pedestal);
587 strip->SetOverflowNumber(ovev);
593 //______________________________________________________________________________
594 Bool_t AliITSHandleDaSSD::CalculateNoise(AliITSModuleDaSSD *const module)
597 AliITSChannelDaSSD *strip;
601 if (!module) return kFALSE;
602 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
603 if (!(strip = module->GetStrip(strind))) continue;
604 if (!(signal = strip->GetSignal())) {
605 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
606 AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
607 module->GetModuleId(), strind));
610 Double_t nsum = 0.0L;
612 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
613 if (SignalOutOfRange(signal[ev])) ovev += 1;
614 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
616 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
617 else noise = AliITSChannelDaSSD::GetUndefinedValue();
618 strip->SetNoise(noise);
625 //______________________________________________________________________________
626 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
628 // Calculates Noise with CM correction
629 AliITSChannelDaSSD *strip = NULL;
633 if (!CalculateCM(module)) {
634 AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
637 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
638 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
639 if (!(signal = strip->GetSignal())) {
640 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
641 AliError(Form("SSDDAModule: Error CalculateNoiseWithoutCM(): there are no events data for module[%i] strip[%i]->GetSignal()",
642 module->GetModuleId(), strind));
643 continue; //return kFALSE;
645 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
646 Double_t nsum = 0.0L;
648 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
649 if (SignalOutOfRange(signal[ev])) ovev += 1;
650 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
652 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
653 else noise = AliITSChannelDaSSD::GetUndefinedValue();
654 strip->SetNoiseCM(noise);
661 //______________________________________________________________________________
662 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
665 AliITSChannelDaSSD *strip = NULL;
669 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
670 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
671 stripind = chipind * module->GetStripsPerChip();
672 module->GetCm()[chipind].Set(fNumberOfEvents);
673 module->GetCm()[chipind].Reset(0.0f);
674 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
675 // calculate firs approximation of CM.
678 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
679 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
680 if (!(signal = strip->GetSignal())) {
681 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()",
682 module->GetModuleId(), strind));
685 if ((signal[ev] >= AliITSChannelDaSSD::GetOverflowConst()) ||
686 (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
687 else cm0 += (signal[ev] - strip->GetPedestal());
689 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
690 else { module->SetCM(0.0f, chipind, ev); continue; }
691 // calculate avarage (cm - (signal - pedestal)) over the chip
692 Double_t cmsigma = 0.0L;
694 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
695 if (!(strip = module->GetStrip(strind))) continue;
696 if (!(signal = strip->GetSignal())) {
697 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
698 module->GetModuleId(), strind));
701 if ((signal[ev] >= AliITSChannelDaSSD::GetOverflowConst()) ||
702 (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
703 else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
705 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = sqrt(cmsigma / (Float_t)(n));
706 else { module->SetCM(0.0f, chipind, ev); continue; }
707 // calculate cm with threshold
708 Double_t cmsum = 0.0L;
710 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
711 if (!(strip = module->GetStrip(strind))) continue;
712 signal = strip->GetSignal();
713 if ( (signal[ev] >= AliITSChannelDaSSD::GetOverflowConst())
714 || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
715 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
716 else cmsum += (signal[ev] - strip->GetPedestal());
718 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
720 if (!module->SetCM(cmsum, chipind, ev));
727 //______________________________________________________________________________
728 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread)
730 // Performs calculation of calibration parameters (pedestal, noise, ...)
732 if (nmread <= 0) return kFALSE;
733 if (!fModules) return kFALSE;
734 while ((nm = ReadModuleRawData(nmread)) > 0) {
735 cout << "Processing next " << nm << " modules;" << endl;
736 for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
737 if (!fModules[modind]) {
738 AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
742 CalculatePedestal(fModules[modind]);
743 CalculateNoise(fModules[modind]);
744 CalculateNoiseCM(fModules[modind]);
748 fModIndProcessed = fModIndRead;
749 cout << fModIndProcessed << " - done" << endl;
755 //______________________________________________________________________________
756 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
758 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
759 Int_t mddli = (ad - 1) * 12 + ((adc<6) ? adc : (adc-2));
760 if ((ddlID < AliITSRawStreamSSD::kDDLsNumber) && (mddli < AliITSRawStreamSSD::kModulesPerDDL)) {
761 mddli = AliITSRawStreamSSD::GetModuleNumber(ddlID, mddli);
762 if (mddli > SHRT_MAX) return SHRT_MAX;
763 else return (Short_t)mddli;
766 AliWarning(Form("Module index = %d or ddlID = %d is out of range -1 is rturned", ddlID, mddli));
773 //______________________________________________________________________________
774 TObjArray* AliITSHandleDaSSD::GetCalibrationSSDLDC() const
776 // Fill in the array for OCDB
778 TObject *modcalibobj;
779 if (!fModules) return NULL;
780 ldcc = new TObjArray(fNumberOfModules, 0);
781 for (Int_t i = 0; i < fNumberOfModules; i++) {
786 modcalibobj = dynamic_cast<TObject*>(fModules[i]->GetCalibrationNoise());
787 ldcc->AddAt(modcalibobj, i);
794 //______________________________________________________________________________
795 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname) const
797 // Save Calibration data locally
798 TObjArray *ldcn, *ldcp, *ldcbc;
799 TObject *modobjn, *modobjp, *modobjbc;
801 TString dadatafilename("");
802 if (!fModules) return kFALSE;
803 ldcn = new TObjArray(fNumberOfModules, 0);
804 ldcn->SetName("Noise");
805 ldcp = new TObjArray(fNumberOfModules, 0);
806 ldcp->SetName("Pedestal");
807 ldcbc = new TObjArray(fNumberOfModules, 0);
808 ldcbc->SetName("BadChannels");
809 for (Int_t i = 0; i < fNumberOfModules; i++) {
814 modobjn = dynamic_cast<TObject*>(fModules[i]->GetCalibrationNoise());
815 modobjp = dynamic_cast<TObject*>(fModules[i]->GetCalibrationPedestal());
816 modobjbc = dynamic_cast<TObject*>(fModules[i]->GetCalibrationBadChannels());
817 ldcn->AddAt(modobjn, i);
818 ldcp->AddAt(modobjp, i);
819 ldcbc->AddAt(modobjbc, i);
824 if (dafname) dadatafilename.Form("%s/", dafname);
825 dadatafilename += TString::Format("ITSSSDda_%i_%i.root", fLdcId, fRunId);
826 tmpfname = new Char_t[dadatafilename.Length()+1];
827 dafname = strcpy(tmpfname, dadatafilename.Data());
828 TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
829 if (fileRun->IsZombie()) {
830 AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
838 fileRun->WriteTObject(ldcn);
839 fileRun->WriteTObject(ldcp);
840 fileRun->WriteTObject(ldcbc);
852 //______________________________________________________________________________
853 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
855 // Dump calibration parameters
856 AliITSModuleDaSSD *mod;
857 AliITSChannelDaSSD *strip;
859 cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
862 cout << "Modules with MeanNoise > " << meannosethreshold << endl;
863 for (Int_t i = 0; i < fNumberOfModules; i++) {
864 if (!(mod = fModules[i])) continue;
865 Float_t maxnoise = 0.0f, meannoise = 0.0f;
866 Int_t maxstrind = 0, novfstr = 0;
867 for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
868 if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
869 if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
870 if (maxnoise < strip->GetNoiseCM()) {
871 maxnoise = strip->GetNoiseCM();
874 meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Float_t>(strind - novfstr + 1)
875 : strip->GetNoiseCM();
877 if (meannoise > meannosethreshold)
878 cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
879 << "; ADC: " << (int)mod->GetADC() << "; MeanNoise = " << meannoise
880 << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
887 //______________________________________________________________________________
888 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
890 // Print Module calibration data whether in file on in cout
891 AliITSChannelDaSSD *strip;
894 if (!fname) { outputfile = &cout; }
896 datafile.open(fname, ios::out);
897 if (datafile.fail()) return kFALSE;
898 outputfile = dynamic_cast<ostream*>(&datafile);
900 *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
901 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
902 if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
903 *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
904 << "; noise = " << strip->GetNoiseCM() << endl;
908 if (datafile.is_open()) datafile.close();
914 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
916 // Print general information retrieve from raw data file
917 cout << "Raw data file: " << fRawDataFileName << endl
918 << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
919 << "Number of physics events: " << fNumberOfEvents << endl
924 //______________________________________________________________________________
925 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
927 // Used to allocate simulated modules to test the performance
928 AliITSModuleDaSSD *module;
929 UChar_t ad, adc, ddlID;
930 ad = adc = ddlID = 0;
931 if (!(fModules[copymodind])) return kFALSE;
932 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
933 if (!fModules[modind]) {
934 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
935 if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
936 else if (adc == 5) adc = 8;
937 else if (adc == 13) {
945 if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
946 fModules[modind] = module;
947 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
948 AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
949 Long_t eventsnumber = cstrip->GetEventsNumber();
950 AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
951 for (Long_t evind = 0; evind < eventsnumber; evind++) {
952 Short_t sign = *cstrip->GetSignal(evind);
953 if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
955 module->SetStrip(strip, strind);
959 ddlID = fModules[modind]->GetDdlId();
960 ad = fModules[modind]->GetAD();
961 adc = fModules[modind]->GetADC();
964 for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);