//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of class TpcPSATaskALICE // see TpcPSATaskALICE.hh for details // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Sebastian Neubert TUM (original author) // // //----------------------------------------------------------- // Panda Headers ---------------------- // This Class' Header ------------------ #include "TpcPSATaskALICE.h" // C/C++ Headers ---------------------- #include #include // Collaborating Class Headers -------- #include "FairRootManager.h" #include "TClonesArray.h" #include "TpcSample.h" #include "TpcDigi.h" #include "TpcDigiAge.h" #include "TpcSampleAge.h" #include "TpcFrontend.h" #include "TpcSimplePSAStrategy.h" #include "TpcPSA_TOT1.h" #include "TpcPSA_INT1.h" #include "TpcPSA_INT_ALICE.h" //#include "TpcPSA_AD1.h" #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "TpcDigiPar.h" #include "TpcT2KPulseshape.h" #include "TpcCRRCPulseshape.h" #include "TpcPadPlane.h" // Class Member definitions ----------- unsigned int TpcPSATaskALICE::GetPadRow (unsigned int padid){ if (padid < 68) return 0; else if (padid < 136) return 1; else if (padid < 204) return 2; else if (padid <272 ) return 3; else if (padid <342 ) return 4; else if (padid < 412) return 5; else if (padid < 482) return 6; else if (padid < 554) return 7; else if (padid <626 ) return 8; else if (padid <698 ) return 9; else if (padid <772 ) return 10; else if (padid <846 ) return 11; else if (padid <920 ) return 12; else if (padid <996 ) return 13; else if (padid <1072 ) return 14; else if (padid <1148 ) return 15; else if (padid <1226 ) return 16; else if (padid <1304 ) return 17; else if (padid <1382 ) return 18; else if (padid <1462 ) return 19; else if (padid <1542 ) return 20; else if (padid <1622 ) return 21; else if (padid <1704 ) return 22; else if (padid <1786 ) return 23; else if (padid <1868 ) return 24; else if (padid <1952 ) return 25; else if (padid <2036 ) return 26; else if (padid <2120 ) return 27; else if (padid <2206 ) return 28; else if (padid <2292 ) return 29; else if (padid <2378 ) return 30; else if (padid <2466 ) return 31; else if (padid < 2554) return 32; else if (padid <2642 ) return 33; else if (padid <2732 ) return 34; else if (padid <2822 ) return 35; else if (padid <2912 ) return 36; else if (padid <3004 ) return 37; else if ( padid < 3096) return 38; else if ( padid < 3188) return 39; else if ( padid < 3282) return 40; else if ( padid < 3376) return 41; else if ( padid < 3470) return 42; else if ( padid < 3566) return 43; else if ( padid < 3662) return 44; else if ( padid < 3758) return 45; else if ( padid < 3856) return 46; else if ( padid < 3954) return 47; else if ( padid < 4052) return 48; else if ( padid < 4152) return 49; else if ( padid < 4252) return 50; else if ( padid < 4352) return 51; else if ( padid < 4454) return 52; else if ( padid < 4556) return 53; else if ( padid < 4658) return 54; else if ( padid < 4762) return 55; else if ( padid < 4866) return 56; else if ( padid < 4970) return 57; else if ( padid < 5076) return 58; else if ( padid < 5182) return 59; else if ( padid < 5288) return 60; else if ( padid < 5396) return 61; else if ( padid < 5504) return 62; else return -1; } void TpcPSATaskALICE::SetParContainers() { if (fVerbose) { std::cout<<"TpcPSATaskALICE::SetParContainers"<GetRuntimeDb(); if ( ! db ) Fatal("SetParContainers", "No runtime database"); // Get Tpc digitisation parameter container fpar= (TpcDigiPar*) db->getContainer("TpcDigiPar"); if (! fpar ) Fatal("SetParContainers", "TpcDigiPar not found"); } TpcPSATaskALICE::TpcPSATaskALICE() : FairTask("TPC Pulse shape analyser"), fpersistence(kFALSE), fpeak(100), fopt(0), fPads(0), fSamplePersistence(kFALSE),fVerbose(kFALSE),fTrivialPSA(kFALSE), fTimeCut(kFALSE), fcutlow(0),fcuthigh(10000),fpadrowcut(0) { fsampleBranchName = "TpcSample"; fDigiOutName = "TpcDigi"; } TpcPSATaskALICE::~TpcPSATaskALICE() { if(ffrontend!=NULL)delete ffrontend; if(fpsa!=NULL)delete fpsa; clearSampleMap(); } InitStatus TpcPSATaskALICE::Init() { //Get ROOT Manager FairRootManager* ioman= FairRootManager::Instance(); fPadPlane = fpar->getPadPlane(); fPads = fPadPlane->GetNPads(); if(ioman==0) { Error("TpcPSATaskALICE::Init","RootManager not instantiated!"); return kERROR; } // Get input collection fsampleArray=(TClonesArray*) ioman->GetObject(fsampleBranchName); if(fsampleArray==0) { Error("TpcPSATaskALICE::Init","Sample-array not found!"); return kERROR; } // create and register output array fdigiArray = new TClonesArray("TpcDigi"); ioman->Register(fDigiOutName,"Tpc",fdigiArray,fpersistence); //TODO: Get this from Database // ffrontend= new TpcFrontend(10, // AdcThreshold // 2048, // adcmax // 11, // adcbits // 20, // SamplingFreq_Mhz // 0, // t0 // 16, // timebits // 10); // PSAthreshold ffrontend = (TpcFrontend*) fpar->getFrontend(); //fpulseshape= new TpcT2KPulseshape(fpeak); fpulseshape= new TpcCRRCPulseshape(ffrontend->tdiff(), ffrontend->tint(), ffrontend->tsig()); fVerbose = true; if( fpar->getPSA() == 0) { fpsa= new TpcSimplePSAStrategy(ffrontend->psaThreshold()); if (fVerbose) std::cout << "Using Simple PSA strategy!" << std::endl; } else if( fpar->getPSA() == 1){ fpsa= new TpcPSA_TOT1(); ((TpcPSA_TOT1*)fpsa)->setSamplePersistence(fSamplePersistence); ((TpcPSA_TOT1*)fpsa)->setSaturationThreshold(ffrontend->psaThreshold()); if (fVerbose) { std::cout << "Using PSA_TOT strategy!"; // if (fopt) {fpsa->setOpt(fopt); std::cout << " with " << fopt << "nb of empty samples allowed.";} std::cout << std::endl; } } else if( fpar->getPSA() == 2){ fpsa= new TpcPSA_INT_ALICE(); ((TpcPSA_INT_ALICE*)fpsa)->setSamplePersistence(fSamplePersistence); ((TpcPSA_INT_ALICE*)fpsa)->setSaturationThreshold(ffrontend->psaThreshold()); if (fVerbose) { std::cout << "Using PSA_INT_ALICE strategy!"; // if (fopt) {fpsa->setOpt(fopt); std::cout << " with " << fopt << "nb of empty samples allowed.";} std::cout << std::endl; } } else if( fpar->getPSA() == 3){ fpsa= new TpcPSA_INT1(); ((TpcPSA_INT1*)fpsa)->setSamplePersistence(fSamplePersistence); ((TpcPSA_INT1*)fpsa)->setSaturationThreshold(ffrontend->psaThreshold()); if (fVerbose) { std::cout << "Using PSA_INT strategy!"; // if (fopt) {fpsa->setOpt(fopt); std::cout << " with " << fopt << "nb of empty samples allowed.";} std::cout << std::endl; } } else return kERROR; return kSUCCESS; } void TpcPSATaskALICE::Exec(Option_t* opt) { if (fVerbose) std::cout<<"TpcPSATaskALICE::Exec"<Delete(); // delete Samples created by PresetNullSample while(!nullSamples.empty()) delete nullSamples.back(), nullSamples.pop_back(); // Sort samples according to padid (create several vectors of samples) Int_t ns=fsampleArray->GetEntriesFast(); for(Int_t is=0;isAt(is); // sort out bad pad ids, where only noise signals could be found unsigned int id=mysample->padId(); if(id<0 || id>fPads || id == 2271||id ==2272||id ==3057||id ==978||id ==754||id ==537 || id ==465){ continue; } // sort out bad rows if (fpadrowcut>0){ if(GetPadRow(id)<5 || GetPadRow(id)>60){ continue; } } // sort out intermediate rows if (fpadrowcut>1){ if(GetPadRow(id) == 9 || GetPadRow(id) == 17 || GetPadRow(id) == 25 || GetPadRow(id) == 32 || GetPadRow(id) == 39 || GetPadRow(id) == 45 || GetPadRow(id) == 51 || GetPadRow(id) == 57){ continue; } } // Time cut if(fTimeCut){ unsigned int time=mysample->t(); if(time>fcuthigh || timeamp(), mysample->t(), mysample->padId(), mysample->mcId(), (*fdigiArray).GetEntriesFast()); } // end trivial PSA if(fSampleMap[id]==NULL)fSampleMap[id]=new std::vector; fSampleMap[id]->push_back(mysample); } if(!fTrivialPSA){ if (fVerbose) std::cout<< "Found " << fSampleMap.size() << " hit pads" << std::endl; // output vector std::vector digis; // loop over pads std::map* >::iterator padit=fSampleMap.begin(); while(padit!=fSampleMap.end()){ // get vector of samples in first pad std::vector* vecSa=padit->second; // sort samples in time sort(vecSa->begin(),vecSa->end(),TpcSampleAge()); // display vector with samples after sorting // std::cout << "display vector after sorting: " << std::endl; // for (int i = 0; i < vecSa->size(); i++){ // std::cout << "element " << i << " of vector, index: " << vecSa->at(i)->index() << std::endl; // } // pass samplelist to psa unsigned int ndigibefore=digis.size(); if(vecSa->size()!=0) { // add an empty sample in front of the other samples // PresetNullSample(vecSa); // std::cout << "Pad " << padit->first // << ": Processing " << vecSa->size() << " samples with PSA ("; fpsa->Process(*vecSa,digis,ffrontend->psaThreshold()); unsigned int ndigiafter=digis.size(); // std::cout <psaThreshold() << ") -- " // << ndigiafter-ndigibefore << " Digis created."<index(idigi); delete digis[idigi]; // clean up temporay store } if (fVerbose) std::cout<GetEntriesFast()<<" Digis created"< *samplelist) { //set a zero sample before the first sample in the vector, so that the alternative psa will always //find the first maximum if(samplelist->size()>0) { TpcSample *pFirstSample=*(samplelist->begin()); int t=pFirstSample->t(); unsigned int PadID=pFirstSample->padId(); McIdCollection m=pFirstSample->mcId(); TpcSample *pS=new TpcSample(t-1,0,PadID,m); samplelist->insert(samplelist->begin(),pS); nullSamples.push_back(pS); } } void TpcPSATaskALICE::clearSampleMap(){ //delete vectors (but not TpcSamples) and clear sampleMaps std::map* >::iterator secIt=fSampleMap.begin(); while(secIt!=fSampleMap.end()){ (secIt->second)->clear(); delete secIt->second; ++secIt; } fSampleMap.clear(); } ClassImp(TpcPSATaskALICE)