+//______________________________________________________________________
+Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
+{
+ //
+ // Converts RAW data to SDigits
+ //
+ // Get TreeS
+ //
+ Int_t last = -1;
+ Int_t size = AliITSgeomTGeo::GetNModules();
+ if(!fModA) {
+ fModA = new TClonesArray*[size];
+ for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
+ }
+ AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
+ if (!loader){
+ Error("Open","Can not get ITS loader from Run Loader");
+ return kFALSE;
+ }
+
+ TTree* tree = 0;
+ tree = loader->TreeS();
+ if (!tree){
+ loader->MakeTree("S");
+ tree = loader->TreeS();
+ }
+ //
+ // Array for SDigits
+ //
+ if(!fpSDigits){
+ fpSDigits = new TClonesArray("AliITSpListItem",10000);
+ }
+ TClonesArray& aSDigits = *fpSDigits;
+ Int_t bufsize = 32000;
+ tree->Branch("ITS", &fpSDigits, bufsize);
+ Int_t npx = 0;
+ //
+ // SPD
+ //
+ AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
+ if(!segSPD){
+ AliWarning("Set AliITS defaults");
+ SetDefaults();
+ segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
+ }
+ npx = segSPD->Npx();
+ Double_t thr, sigma;
+
+ Int_t countRW = -1; // RS counter for raw -> cluster ID's (used in embedding)
+ const TArrayI* rawID2clusID = fkRawID2ClusID[kSPD];
+ AliITSRawStreamSPD inputSPD(rawReader);
+ while(1){
+ Bool_t next = inputSPD.Next();
+ if (!next) break;
+
+ countRW++; // RS
+ Int_t module = inputSPD.GetModuleID();
+ Int_t column = inputSPD.GetColumn();
+ Int_t row = inputSPD.GetRow();
+ Int_t index = npx * column + row;
+
+ if (module >= size) continue;
+
+ last = (fModA[module])->GetEntries();
+ TClonesArray& dum = *fModA[module];
+ fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
+ thr += 1.;
+ int label = kMaxLabel;
+ if (rawID2clusID) { // RS If the raw->cluster ID is set (filled by cluster finder) store cluster ID's in SDigits
+ if (rawID2clusID->GetSize()<=countRW) {AliError(Form("The buffer of rawSPD to clusSPD ID's is shorter than current rawSPD ID=%d",countRW));}
+ else label = (*rawID2clusID)[countRW];
+ }
+ new (dum[last]) AliITSpListItem(label, -1, module, index, thr);
+ }
+ rawReader->Reset();
+
+ //
+ // SDD
+ //
+ AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
+ npx = segSDD->Npx();
+ Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
+ Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
+ Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
+ //
+ countRW = -1; // RS
+ rawID2clusID = fkRawID2ClusID[kSDD];
+ AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
+ for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
+ AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
+ Bool_t isZeroSupp=cal->GetZeroSupp();
+ if(isZeroSupp){
+ for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
+ }else{
+ for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
+ }
+ }
+
+ AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
+ inputSDD->SetDDLModuleMap(ddlmap);
+ while(inputSDD->Next()){
+ countRW++; // RS
+ if(inputSDD->IsCompletedModule()==kFALSE &&
+ inputSDD->IsCompletedDDL()==kFALSE){
+
+ Int_t module = inputSDD->GetModuleID();
+ Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
+ Int_t time = inputSDD->GetCoord2();
+ Int_t signal10 = inputSDD->GetSignal();
+ Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
+
+ if (module >= size) continue;
+ last = fModA[module]->GetEntries();
+ TClonesArray& dum = *fModA[module];
+ int label = kMaxLabel;
+ if (rawID2clusID) { // RS If the raw->cluster ID is set (filled by cluster finder) store cluster ID's in SDigits
+ if (rawID2clusID->GetSize()<=countRW) {AliError(Form("The buffer of rawSDD to clusSDD ID's is shorter than current rawSDD ID=%d",countRW));}
+ else label = (*rawID2clusID)[countRW];
+ }
+ new (dum[last]) AliITSpListItem(label, -1, module, index, Double_t(signal10));
+ ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
+ }
+ }
+ delete inputSDD;
+ rawReader->Reset();
+
+ //
+ // SSD
+ //
+ AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
+ npx = segSSD->Npx();
+ AliITSRawStreamSSD inputSSD(rawReader);
+ countRW = -1;
+ rawID2clusID = fkRawID2ClusID[kSSD];
+ while(1){
+ Bool_t next = inputSSD.Next();
+ if (!next) break;
+ countRW++; // RS
+ Int_t module = inputSSD.GetModuleID();
+ if(module<0)AliError(Form("Invalid SSD module %d \n",module));
+ if(module<0)continue;
+ Int_t side = inputSSD.GetSideFlag();
+ Int_t strip = inputSSD.GetStrip();
+ Int_t signal = inputSSD.GetSignal();
+ Int_t index = npx * side + strip;
+
+ if (module >= size) continue;
+
+ last = fModA[module]->GetEntries();
+ TClonesArray& dum = *fModA[module];
+ int label = kMaxLabel;
+ if (rawID2clusID) { // RS If the raw->cluster ID is set (filled by cluster finder) store cluster ID's in SDigits
+ if (rawID2clusID->GetSize()<=countRW) {AliError(Form("The buffer of rawSSD to clusSSD ID's is shorter than current rawSSD ID=%d",countRW));}
+ else label = (*rawID2clusID)[countRW];
+ }
+ new (dum[last]) AliITSpListItem(label, -1, module, index, Double_t(signal));
+ }
+ rawReader->Reset();
+ AliITSpListItem* sdig = 0;
+
+ Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
+ Double_t adcToEv = 1.;
+ for (Int_t mod = 0; mod < size; mod++)
+ {
+ if(mod>=firstssd) {
+ AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
+ adcToEv = 1./calssd->GetSSDDEvToADC(1.);
+ }
+ Int_t nsdig = fModA[mod]->GetEntries();
+ for (Int_t ie = 0; ie < nsdig; ie++) {
+ sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
+ Double_t digsig = sdig->GetSignal();
+ if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
+ new (aSDigits[ie]) AliITSpListItem(sdig->GetTrack(0), -1, mod, sdig->GetIndex(), digsig);
+ Float_t sig = sdig->GetSignalAfterElect();
+ if(mod>=firstssd) sig*=adcToEv;
+ if (sig > 0.) {
+ sdig = (AliITSpListItem*)aSDigits[ie];
+ sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
+ }
+ }
+
+ tree->Fill();
+ aSDigits.Clear();
+ fModA[mod]->Clear();
+ }
+ loader->WriteSDigits("OVERWRITE");
+ return kTRUE;
+}
+
+//______________________________________________________________________
+void AliITS::UpdateInternalGeometry(){
+ //reads new geometry from TGeo
+// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
+
+ AliITSVersion_t version = (AliITSVersion_t)IsVersion();
+ Int_t minor = 0;
+ AliITSInitGeometry initgeom;
+ AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
+ SetITSgeom(geom);
+}
+//______________________________________________________________________
+AliTriggerDetector* AliITS::CreateTriggerDetector() const {
+ // create an AliITSTrigger object (and set trigger conditions as input)
+ return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
+}
+//______________________________________________________________________
+void AliITS::WriteFOSignals(){
+// This method write FO signals in Digits tree both in Hits2Digits
+// or SDigits2Digits
+
+ fDetTypeSim->ProcessNoiseForFastOr();
+ fDetTypeSim->WriteFOSignals();
+}
+
+