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
23 ///////////////////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
26 #include "AliITSHandleDaSSD.h"
32 #include "TObjArray.h"
34 #include "AliITSNoiseSSD.h"
35 #include "AliITSRawStreamSSD.h"
36 #include "AliRawReaderDate.h"
38 #include "AliITSChannelDaSSD.h"
41 ClassImp(AliITSHandleDaSSD)
46 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698; // Number of SSD modules in ITS
47 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerDdl = 108; // Number of SSD modules in ITS
48 const Float_t AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0; // Defalt value for fPedestalThresholdFactor
49 const Float_t AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0; // Defalt value for fCmThresholdFactor
51 //______________________________________________________________________________
52 AliITSHandleDaSSD::AliITSHandleDaSSD() :
53 fRawDataFileName(NULL),
61 fPedestalThresholdFactor(fgkPedestalThresholdFactor),
62 fCmThresholdFactor(fgkCmThresholdFactor)
64 // Default constructor
68 //______________________________________________________________________________
69 AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) :
70 fRawDataFileName(NULL),
78 fPedestalThresholdFactor(fgkPedestalThresholdFactor) ,
79 fCmThresholdFactor(fgkCmThresholdFactor)
81 if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!");
85 //______________________________________________________________________________
86 AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) :
88 fRawDataFileName(ssdadldc.fRawDataFileName),
89 fNumberOfModules(ssdadldc.fNumberOfModules),
91 fModIndProcessed(ssdadldc.fModIndProcessed),
92 fModIndRead(ssdadldc.fModIndRead),
93 fNumberOfEvents(ssdadldc.fNumberOfEvents),
94 fLdcId(ssdadldc.fLdcId),
95 fRunId(ssdadldc.fRunId),
96 fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor),
97 fCmThresholdFactor(ssdadldc.fCmThresholdFactor)
100 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
101 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
103 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
104 if (ssdadldc.fModules[modind]) {
105 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
106 if (!fModules[modind]) {
107 AliError("AliITSHandleDaSSD: Error copy constructor");
108 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
113 } else fModules[modind] = NULL;
116 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
117 fNumberOfModules = 0;
124 //______________________________________________________________________________
125 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
127 // assignment operator
128 if (this == &ssdadldc) return *this;
130 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
134 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
135 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
137 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
138 if (ssdadldc.fModules[modind]) {
139 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
140 if (!fModules[modind]) {
141 AliError("AliITSHandleDaSSD: Error assignment operator");
142 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
147 } else fModules[modind] = NULL;
150 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
151 fNumberOfModules = 0;
159 //______________________________________________________________________________
160 AliITSHandleDaSSD::~AliITSHandleDaSSD()
162 // Default destructor
165 for (Int_t i = 0; i < fNumberOfModules; i++)
167 if (fModules[i]) delete fModules[i];
175 //______________________________________________________________________________
176 void AliITSHandleDaSSD::Reset()
178 // Delete array of AliITSModuleDaSSD* objects.
180 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
184 fRawDataFileName = NULL;
185 fModIndProcessed = fModIndRead = 0;
188 fPedestalThresholdFactor = fgkPedestalThresholdFactor;
189 fCmThresholdFactor = fgkCmThresholdFactor;
194 //______________________________________________________________________________
195 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname, const Char_t *configfname)
197 // Read raw data file and set initial and configuration parameters
198 Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
199 Int_t nofeqipmentev, nofeqipment = 0, eqn = 0;
200 AliRawReaderDate *rawreaderdate = NULL;
201 UChar_t *data = NULL;
202 Long_t datasize = 0, eqbelsize = 1;
204 if (configfname) ReadConfigurationFile(configfname);
205 rawreaderdate = new AliRawReaderDate(rdfname, 0);
206 if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
207 AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
211 if (rawreaderdate->NextEvent()) {
212 fLdcId = rawreaderdate->GetLDCId();
213 fRunId = rawreaderdate->GetRunNumber();
214 rawreaderdate->RewindEvents();
215 } else { MakeZombie(); return kFALSE; }
216 if (fModules) Reset();
217 rawreaderdate->SelectEvents(-1);
219 while (rawreaderdate->NextEvent()) {
220 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
223 while (rawreaderdate->ReadNextData(data)) {
225 datasize = rawreaderdate->GetDataSize();
226 eqbelsize = rawreaderdate->GetEquipmentElementSize();
227 if ( (datasize % eqbelsize) || (eqbelsize != sizeof(long32)) ) {
228 AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %i is not an integer of equipment data size %i",
229 rdfname, datasize, eqbelsize));
233 nofstripsev += (Int_t) (datasize / eqbelsize);
235 if (physeventind++) {
236 if (nofstrips != nofstripsev) AliWarning("AliITSHandleDaSSD: number of strips varies from event to evnt");
237 if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to evnt");
239 nofstrips = nofstripsev;
240 nofeqipment = nofeqipmentev;
241 if (strn < nofstrips) strn = nofstrips;
242 if (eqn < nofeqipment) eqn = nofeqipment;
244 delete rawreaderdate;
245 if ((physeventind > 0) && (strn > 0))
247 fNumberOfEvents = physeventind;
248 fRawDataFileName = rdfname;
249 if (SetNumberOfModules(fgkNumberOfSSDModules)) {
250 TString str = TString::Format("Max number of equipment: %i, max number of channels: %i\n", eqn, strn);
251 DumpInitData(str.Data());
260 //______________________________________________________________________________
261 Bool_t AliITSHandleDaSSD::ReadConfigurationFile(const Char_t *configfname)
263 // Dowload configuration parameters from configuration file or database
269 //______________________________________________________________________________
270 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
272 // Retrieve AliITSModuleDaSSD object from the array
273 if (!fModules) return NULL;
274 for (Int_t i = 0; i < fNumberOfModules; i++) {
276 if ( (fModules[i]->GetDdlId() == ddlID)
277 && (fModules[i]->GetAD() == ad)
278 && (fModules[i]->GetADC() == adc))
286 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
288 // Retrieve the position of AliITSModuleDaSSD object in the array
289 if (!fModules) return -1;
290 for (Int_t i = 0; i < fNumberOfModules; i++) {
292 if ( (fModules[i]->GetDdlId() == ddlID)
293 && (fModules[i]->GetAD() == ad)
294 && (fModules[i]->GetADC() == adc))
303 //______________________________________________________________________________
304 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
306 // Retrieve AliITSChannalDaSSD object from the array
307 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
308 if ( (fModules[modind]->GetDdlId() == ddlID)
309 && (fModules[modind]->GetAD() == ad)
310 && (fModules[modind]->GetADC() == adc) )
312 return fModules[modind]->GetStrip(stripID);
315 AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
316 ddlID, ad, adc, stripID));
322 //______________________________________________________________________________
323 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
325 // Assign array element with AliITSModuleDaSSD object
326 if ((index < fNumberOfModules) && (index >= 0))
328 if (fModules[index]) delete fModules[index];
329 fModules[index] = module;
337 //______________________________________________________________________________
338 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
340 // Allocates memory for AliITSModuleDaSSD objects
341 if (numberofmodules > fgkNumberOfSSDModules)
342 AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD",
343 numberofmodules, fgkNumberOfSSDModules));
345 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
349 fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
351 fNumberOfModules = numberofmodules;
352 memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
355 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
356 fNumberOfModules = 0;
364 //______________________________________________________________________________
365 Bool_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
367 // Reads raw data from file
368 AliRawReaderDate *rawreaderdate = NULL;
369 AliITSModuleDaSSD *module;
370 AliITSChannelDaSSD *strip;
371 Long_t datasize, eventind = 0;
372 Int_t nofstrips, eqbelsize;
376 if (!Init(fileName)){
377 AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
380 rawreaderdate = new AliRawReaderDate(fileName, 0);
381 rawreaderdate->SelectEvents(-1);
382 while (rawreaderdate->NextEvent()) {
383 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
384 fLdcId = rawreaderdate->GetLDCId();
385 fRunId = rawreaderdate->GetRunNumber();
387 while (rawreaderdate->ReadNextData(databyte)) {
388 data = reinterpret_cast<long32*>(databyte);
389 Int_t equipid = rawreaderdate->GetEquipmentId(); // EquipmentID required to access to rorc
390 Int_t equiptype = rawreaderdate->GetEquipmentType(); //
391 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID(); // GetDDLID(); index of DDL, ITS SSD: 33-48
392 datasize = rawreaderdate->GetDataSize();
393 eqbelsize = rawreaderdate->GetEquipmentElementSize();
394 if ( (datasize % eqbelsize) || (eqbelsize != sizeof(long32)) ) {
395 AliError(Form("AliITSHandleDaSSD: Error ReadCalibrationDataFile: event data size %i is not an integer of equipment data size %i",
396 datasize, eqbelsize));
399 nofstrips = (Int_t) (datasize / eqbelsize);
400 for (Int_t strind = 0; strind < nofstrips; strind++) {
401 UChar_t ad = (UChar_t) (data[strind] >> 28) & 0x0000000F; // index of AD module 0-9
402 UChar_t adc = (UChar_t) (data[strind] >> 24) & 0x0000000F; // index of ADC module 0-5, 8-13
403 UShort_t stripID = (UShort_t)(data[strind] >> 12) & 0x000007FF; // strip number 0-1535
404 Short_t signal = (Short_t)(data[strind] & 0x00000FFF);
405 signal = (signal > AliITSChannelDaSSD::GetUnderflowConst()) ? (signal - 2 * AliITSChannelDaSSD::GetUnderflowConst())
407 if (!(module = GetModule(ddlID, ad, adc))) {
408 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
409 if (!module->SetModuleIdData (ddlID, ad, adc, RetrieveModuleId(ddlID, ad, adc))) return kFALSE;
410 module->SetModuleRorcId (equipid, equiptype);
411 fModules[modind++] = module;
413 if (!(strip = module->GetStrip(stripID))) {
414 strip = new AliITSChannelDaSSD(stripID, eventsnumber);
415 module->SetStrip(strip, stripID);
417 strip->SetSignal(eventind, signal);
419 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
421 if (++eventind > eventsnumber) break;
423 delete rawreaderdate;
424 return RelocateModules();
429 //______________________________________________________________________________
430 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
432 // Reads raw data from file
433 AliRawReaderDate *rawreaderdate = NULL;
434 AliITSModuleDaSSD *module;
435 AliITSChannelDaSSD *strip;
436 Long_t datasize, eventind = 0;
437 Int_t nofstrips, eqbelsize;
441 if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
443 AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
446 rawreaderdate->SelectEvents(-1);
448 while (rawreaderdate->NextEvent()) {
449 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
450 while (rawreaderdate->ReadNextData(databyte)) {
451 data = reinterpret_cast<long32*>(databyte);
452 Int_t equipid = rawreaderdate->GetEquipmentId(); // EquipmentID required to access to rorc
453 Int_t equiptype = rawreaderdate->GetEquipmentType(); //
454 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID(); // GetDDLID(); index of DDL, ITS SSD: 33-48
455 datasize = rawreaderdate->GetDataSize();
456 eqbelsize = rawreaderdate->GetEquipmentElementSize();
457 if ( (datasize % eqbelsize) || (eqbelsize != sizeof(long32)) ) {
458 AliError(Form("AliITSHandleDaSSD: Error ReadCalibrationDataFile: event data size %i is not an integer of equipment data size %i",
459 datasize, eqbelsize));
462 nofstrips = (Int_t) (datasize / eqbelsize);
463 for (Int_t strind = 0; strind < nofstrips; strind++) {
464 UChar_t ad = (UChar_t) (data[strind] >> 28) & 0x0000000F; // index of AD module 0-9
465 UChar_t adc = (UChar_t) (data[strind] >> 24) & 0x0000000F; // index of ADC module 0-5, 8-13
466 UShort_t stripID = (UShort_t)(data[strind] >> 12) & 0x000007FF; // strip number 0-1535
467 Short_t signal = (Short_t)(data[strind] & 0x00000FFF);
468 signal = (signal > AliITSChannelDaSSD::GetUnderflowConst()) ? (signal - 2 * AliITSChannelDaSSD::GetUnderflowConst())
470 Int_t modpos = GetModuleIndex(ddlID, ad, adc);
471 if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
472 if ((modpos < 0) && (modind < modulesnumber)) {
473 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
474 if (!module->SetModuleIdData (ddlID, ad, adc, RetrieveModuleId(ddlID, ad, adc))) return 0;
475 module->SetModuleRorcId (equipid, equiptype);
476 modpos = fModIndRead + modind;
478 fModules[modpos] = module;
480 if (!(strip = fModules[modpos]->GetStrip(stripID))) {
481 strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
482 fModules[modpos]->SetStrip(strip, stripID);
484 strip->SetSignal(eventind, signal);
487 if (++eventind > fNumberOfEvents) break;
489 delete rawreaderdate;
490 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
491 fModIndRead += modind;
492 if (modind < modulesnumber) RelocateModules();
498 //______________________________________________________________________________
499 Bool_t AliITSHandleDaSSD::RelocateModules()
501 // Relocate memory for AliITSModuleDaSSD object array
503 AliITSModuleDaSSD **marray = NULL;
504 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
505 if (fModules[modind]) nm += 1;
506 if (nm == fNumberOfModules) return kTRUE;
507 marray = new (nothrow) AliITSModuleDaSSD* [nm];
509 AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
513 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
514 if (fModules[modind]) marray[nm++] = fModules[modind];
517 fNumberOfModules = fModIndRead = nm;
523 //______________________________________________________________________________
524 Bool_t AliITSHandleDaSSD::CalculatePedestal(AliITSModuleDaSSD *const module)
526 // Calculates Pedestal
527 AliITSChannelDaSSD *strip;
528 Float_t pedestal, noise;
531 if (!module) return kFALSE;
532 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
533 if (!(strip = module->GetStrip(strind))) continue;
534 if (!(signal = strip->GetSignal())) {
535 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
536 module->GetModuleId(), strind));
539 //************* pedestal first pass ****************
542 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
543 if (SignalOutOfRange(signal[ev])) ovev += 1;
544 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
545 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
546 strip->SetPedestal(pedestal);
547 //************* noise *******************************
548 Double_t nsum = 0.0L;
550 for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
551 if (SignalOutOfRange(signal[ev])) ovev += 1;
552 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
554 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
555 else noise = AliITSChannelDaSSD::GetUndefinedValue();
556 strip->SetNoise(noise);
557 //************* pedestal second pass ****************
560 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
561 if ( SignalOutOfRange(signal[ev])
562 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
563 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
564 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
565 strip->SetPedestal(pedestal);
566 strip->SetOverflowNumber(ovev);
572 //______________________________________________________________________________
573 Bool_t AliITSHandleDaSSD::CalculateNoise(AliITSModuleDaSSD *const module)
576 AliITSChannelDaSSD *strip;
580 if (!module) return kFALSE;
581 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
582 if (!(strip = module->GetStrip(strind))) continue;
583 if (!(signal = strip->GetSignal())) {
584 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
585 AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
586 module->GetModuleId(), strind));
589 Double_t nsum = 0.0L;
591 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
592 if (SignalOutOfRange(signal[ev])) ovev += 1;
593 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
595 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
596 else noise = AliITSChannelDaSSD::GetUndefinedValue();
597 strip->SetNoise(noise);
604 //______________________________________________________________________________
605 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
607 // Calculates Noise with CM correction
608 AliITSChannelDaSSD *strip = NULL;
612 if (!CalculateCM(module)) {
613 AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
616 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
617 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
618 if (!(signal = strip->GetSignal())) {
619 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
620 AliError(Form("SSDDAModule: Error CalculateNoiseWithoutCM(): there are no events data for module[%i] strip[%i]->GetSignal()",
621 module->GetModuleId(), strind));
624 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
625 Double_t nsum = 0.0L;
627 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
628 if (SignalOutOfRange(signal[ev])) ovev += 1;
629 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
631 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
632 else noise = AliITSChannelDaSSD::GetUndefinedValue();
633 strip->SetNoiseCM(noise);
640 //______________________________________________________________________________
641 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
644 AliITSChannelDaSSD *strip = NULL;
648 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
649 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
650 stripind = chipind * module->GetStripsPerChip();
651 module->GetCm()[chipind].Set(fNumberOfEvents);
652 module->GetCm()[chipind].Reset(0.0f);
653 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
654 // calculate firs approximation of CM.
657 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
658 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
659 if (!(signal = strip->GetSignal())) {
660 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()",
661 module->GetModuleId(), strind));
664 if ((signal[ev] >= AliITSChannelDaSSD::GetOverflowConst()) ||
665 (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
666 else cm0 += (signal[ev] - strip->GetPedestal());
668 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
669 else { module->SetCM(0.0f, chipind, ev); continue; }
670 // calculate avarage (cm - (signal - pedestal)) over the chip
671 Double_t cmsigma = 0.0L;
673 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
674 if (!(strip = module->GetStrip(strind))) continue;
675 if (!(signal = strip->GetSignal())) {
676 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
677 module->GetModuleId(), strind));
680 if ((signal[ev] >= AliITSChannelDaSSD::GetOverflowConst()) ||
681 (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
682 else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
684 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = sqrt(cmsigma / (Float_t)(n));
685 else { module->SetCM(0.0f, chipind, ev); continue; }
686 // calculate cm with threshold
687 Double_t cmsum = 0.0L;
689 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
690 if (!(strip = module->GetStrip(strind))) continue;
691 signal = strip->GetSignal();
692 if ( (signal[ev] >= AliITSChannelDaSSD::GetOverflowConst())
693 || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
694 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
695 else cmsum += (signal[ev] - strip->GetPedestal());
697 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
699 if (!module->SetCM(cmsum, chipind, ev));
706 //______________________________________________________________________________
707 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread)
709 // Performs calculation of calibration parameters (pedestal, noise, ...)
711 if (nmread <= 0) return kFALSE;
712 if (!fModules) return kFALSE;
713 while ((nm = ReadModuleRawData(nmread)) > 0) {
714 cout << "Processing next " << nm << " modules;" << endl;
715 for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
716 if (!fModules[modind]) {
717 AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
721 CalculatePedestal(fModules[modind]);
722 CalculateNoise(fModules[modind]);
723 CalculateNoiseCM(fModules[modind]);
727 fModIndProcessed = fModIndRead;
728 cout << fModIndProcessed << " - done" << endl;
734 //______________________________________________________________________________
735 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
737 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
738 Int_t mddli = (ad - 1) * 12 + ((adc<6) ? adc : (adc-2));
739 if ((ddlID < AliITSRawStreamSSD::kDDLsNumber) && (mddli < AliITSRawStreamSSD::kModulesPerDDL)) {
740 mddli = AliITSRawStreamSSD::GetModuleNumber(ddlID, mddli);
741 if (mddli > SHRT_MAX) return SHRT_MAX;
742 else return (Short_t)mddli;
745 AliWarning(Form("Module index = %d or ddlID = %d is out of range -1 is rturned", ddlID, mddli));
752 //______________________________________________________________________________
753 TObjArray* AliITSHandleDaSSD::GetCalibrationSSDLDC() const
755 // Fill in the array for OCDB
757 TObject *modcalibobj;
758 if (!fModules) return NULL;
759 ldcc = new TObjArray(fNumberOfModules, 0);
760 for (Int_t i = 0; i < fNumberOfModules; i++) {
765 modcalibobj = dynamic_cast<TObject*>(fModules[i]->GetCalibrationSSDModule());
766 ldcc->AddAt(modcalibobj, i);
773 //______________________________________________________________________________
774 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname) const
776 // Save Calibration data locally
778 TObject *modcalibobj;
780 TString dadatafilename("");
781 if (!fModules) return kFALSE;
782 ldcc = new TObjArray(fNumberOfModules, 0);
783 for (Int_t i = 0; i < fNumberOfModules; i++) {
788 modcalibobj = dynamic_cast<TObject*>(fModules[i]->GetCalibrationSSDModule());
789 ldcc->AddAt(modcalibobj, i);
792 if (dafname) dadatafilename.Form("%s/", dafname);
793 dadatafilename += TString::Format("ITSSSDda_%i_%i.root", fLdcId, fRunId);
794 tmpfname = new Char_t[dadatafilename.Length()+1];
795 dafname = strcpy(tmpfname, dadatafilename.Data());
796 TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
797 if (fileRun->IsZombie()) {
798 AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
804 fileRun->WriteTObject(ldcc);
814 //______________________________________________________________________________
815 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
817 // Dump calibration parameters
818 AliITSModuleDaSSD *mod;
819 AliITSChannelDaSSD *strip;
821 cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
824 cout << "Modules with MeanNoise > " << meannosethreshold << endl;
825 for (Int_t i = 0; i < fNumberOfModules; i++) {
826 if (!(mod = fModules[i])) continue;
827 Float_t maxnoise = 0.0f, meannoise = 0.0f;
828 Int_t maxstrind = 0, novfstr = 0;
829 for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
830 if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
831 if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
832 if (maxnoise < strip->GetNoiseCM()) {
833 maxnoise = strip->GetNoiseCM();
836 meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Float_t>(strind - novfstr + 1)
837 : strip->GetNoiseCM();
839 if (meannoise > meannosethreshold)
840 cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
841 << "; ADC: " << (int)mod->GetADC() << "; MeanNoise = " << meannoise
842 << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
849 //______________________________________________________________________________
850 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
852 // Print Module calibration data whether in file on in cout
853 AliITSChannelDaSSD *strip;
856 if (!fname) { outputfile = &cout; }
858 datafile.open(fname, ios::out);
859 if (datafile.fail()) return kFALSE;
860 outputfile = dynamic_cast<ostream*>(&datafile);
862 *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
863 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
864 if (strip = GetStrip(ddlID, ad, adc, strind)) {
865 *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
866 << "; noise = " << strip->GetNoiseCM() << endl;
870 if (datafile.is_open()) datafile.close();
876 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
878 // Print general information retrieve from raw data file
879 cout << "Raw data file: " << fRawDataFileName << endl
880 << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
881 << "Number of physics events: " << fNumberOfEvents << endl
886 //______________________________________________________________________________
887 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
889 // Used to allocate simulated modules to test the performance
890 AliITSModuleDaSSD *module;
891 UChar_t ad, adc, ddlID;
892 ad = adc = ddlID = 0;
893 if (!(fModules[copymodind])) return kFALSE;
894 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
895 if (!fModules[modind]) {
896 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
897 if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
898 else if (adc == 5) adc = 8;
899 else if (adc == 13) {
907 if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
908 fModules[modind] = module;
909 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
910 AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
911 Long_t eventsnumber = cstrip->GetEventsNumber();
912 AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
913 for (Long_t evind = 0; evind < eventsnumber; evind++) {
914 Short_t sign = *cstrip->GetSignal(evind);
915 if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
917 module->SetStrip(strip, strind);
921 ddlID = fModules[modind]->GetDdlId();
922 ad = fModules[modind]->GetAD();
923 adc = fModules[modind]->GetADC();
926 for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);