// ------------------------------------------------------------------------- // ----- PndSdsStripClusterTask source file ----- // ------------------------------------------------------------------------- #include #include "TClonesArray.h" #include "TArrayD.h" #include "TGeoManager.h" #include "TGeoMatrix.h" #include "TCanvas.h" #include "FairRootManager.h" #include "FairRun.h" #include "FairRuntimeDb.h" #include "FairGeoNode.h" #include "FairGeoVector.h" #include "FairContFact.h" #include "PndStringSeparator.h" #include "PndSdsStripDigiPar.h" #include "PndSdsStripClusterTask.h" #include "PndSdsMCPoint.h" #include "PndSdsCalcStrip.h" #include "PndSdsDigiStrip.h" #include "PndSdsClusterStrip.h" #include "PndGeoHandling.h" #include "PndSdsSimpleStripClusterFinder.h" #include "PndSdsStripAdvClusterFinder.h" #include "PndSdsChargeWeightingAlgorithms.h" #include // ----- Default constructor ------------------------------------------- PndSdsStripClusterTask::PndSdsStripClusterTask() : FairTask("SDS Strip Clustertisation Task") { fChargeCut = 1.e8; // this reset dynamically fDigiParameterList = new TList(); fChargeDigiParameterList = new TList(); fPersistance = kTRUE; fGeoH=NULL; // just to be sure it's not junk } // ----- Named constructor ------------------------------------------- PndSdsStripClusterTask::PndSdsStripClusterTask(const char* name) : FairTask(name) { // TODO: fChargeCut in parameter database?? fChargeCut = 1.e8; // this ist really large and shall have no effect fDigiParameterList = new TList(); fChargeDigiParameterList = new TList(); fPersistance = kTRUE; fGeoH=NULL; // just to be sure it's not junk } // ----- Destructor ---------------------------------------------------- PndSdsStripClusterTask::~PndSdsStripClusterTask() { if(0!=fGeoH) delete fGeoH; if(0!=fDigiParameterList) delete fDigiParameterList; if(0!=fChargeDigiParameterList) delete fChargeDigiParameterList; // TODO: needs check: now cleared correctly? for( std::map::iterator it = fStripCalcTop.begin(); it != fStripCalcTop.end(); it++){ if(0 != it->second) delete it->second; it->second = 0; } for( std::map::iterator it = fStripCalcBot.begin(); it != fStripCalcBot.end(); it++){ if(0 != it->second) delete it->second; it->second = 0; } for(std::map::iterator it = fChargeAlgos.begin(); it != fChargeAlgos.end(); it++){ if(0 != it->second) delete it->second; it->second = 0; } for(std::map::iterator it = fChargeConverter.begin(); it != fChargeConverter.end(); it++){ if(0 != it->second) delete it->second; it->second = 0; } } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- void PndSdsStripClusterTask::SetParContainers() { if(fVerbose>1) Info("SetParContainers","make geohandler"); if(0==fGeoH) fGeoH = new PndGeoHandling(); else if(fVerbose>1) Warning("SetParContainers","ooops there was already a geohandler"); fGeoH->SetVerbose(fVerbose); if(fVerbose>1) Info("SetParContainers","done."); return; } // InitStatus PndSdsStripClusterTask::ReInit() { InitStatus stat=kERROR; SetParContainers(); SetCalculators(); stat=kSUCCESS; return stat; } void PndSdsStripClusterTask::SetCalculators() { // called at the enf of Init() // TODO: Implement more clusterfinders if (fVerbose>1) Info("SetCalculators","sds part"); TIter params(fDigiParameterList); while(PndSdsStripDigiPar* digipar=(PndSdsStripDigiPar*)params()){ if(0==digipar) { Error("SetCalculators()","A Digi Parameter Set does not exist properly."); continue; } const char* senstype = digipar->GetSensType(); if(fVerbose>1){ Info("SetCalculators()","Create a Parameter Set for %s sensors",senstype); std::cout<Print(); } fStripCalcTop[senstype]=new PndSdsCalcStrip(digipar,kTOP); fStripCalcTop[senstype]->SetVerboseLevel(fVerbose); fStripCalcBot[senstype]=new PndSdsCalcStrip(digipar,kBOTTOM); fStripCalcBot[senstype]->SetVerboseLevel(fVerbose); } } // ----- Public method Init -------------------------------------------- InitStatus PndSdsStripClusterTask::Init() { SetBranchNames(); SetClusterType(); FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { std::cout << "-E- PndSdsStripClusterTask::Init: " << "RootManager not instantiated!" << std::endl; return kFATAL; } // Get input array fDigiArray = (TClonesArray*) ioman->GetObject(fBranchName); if ( ! fDigiArray ) { std::cout << "-W- PndSdsStripClusterTask::Init: " << "No SDSDigi array!" << std::endl; return kERROR; } // set output arrays fHitArray = new TClonesArray("PndSdsHit"); ioman->Register(fHitBranchName, fFolderName, fHitArray, fPersistance); fClusterArray = new TClonesArray("PndSdsClusterStrip"); ioman->Register(fClustBranchName, fFolderName, fClusterArray, fPersistance); SetCalculators(); Info("Init","Initialisation successfull"); return kSUCCESS; } // ------------------------------------------------------------------------- // ----- Public method Exec -------------------------------------------- void PndSdsStripClusterTask::Exec(Option_t* opt) { if (fVerbose > 2) std::cout<<" **Starting PndSdsStripClusterTask::Exec()**"< digiStripArray; // Reset output array if ( ! fClusterArray ) Fatal("Exec", "No ClusterArray"); fClusterArray->Delete(); if ( ! fHitArray ) Fatal("Exec", "No HitArray"); fHitArray->Delete(); // when we have no digis, we can end the event here. if (fDigiArray->GetEntriesFast() == 0) return; // Setup FillClusterFinders(); std::vector< PndSdsClusterStrip > clusters; std::vector< Int_t > topclusters;// contains index to fClusterArray std::vector< Int_t > botclusters;// contains index to fClusterArray std::vector< Int_t > oneclustertop; std::vector< Int_t > oneclusterbot; std::vector< Int_t > leftDigis; Int_t detID, mcindex, clindex, botIndex, topIndex; Double_t mycharge; TVector2 meantopPoint, meanbotPoint, onsensorPoint; TVector3 hitPos,hitErr; Int_t clusterOffset = 0; // ------- SEARCH ------ TIter parsetiter(fDigiParameterList); while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() ) { // loop over all parameter sets and their filled finders (representing sensor types) SetCurrentCalculators(digipar); clusters = fCurrentClusterfinder->SearchClusters(); // fetch ids in 'clusters' to the top and bot side topclusters = fCurrentClusterfinder->GetTopClusterIDs(); botclusters = fCurrentClusterfinder->GetBotClusterIDs(); if(fVerbose > 2) { leftDigis = fCurrentClusterfinder->GetLeftDigiIDs(); if (0GetEntriesFast(); for(std::vector< PndSdsClusterStrip >::iterator clit= clusters.begin(); clit!=clusters.end(); ++clit) { clindex = fClusterArray->GetEntriesFast(); new((*fClusterArray)[clindex]) PndSdsClusterStrip(*clit); } //printout for checking if(fVerbose > 2) { std::cout<<"Check.. Offset: "<::iterator itTop = topclusters.begin(); itTop!=topclusters.end(); ++itTop) { std::cout<<*itTop<<" | "; } std::cout<::iterator itBot = botclusters.begin(); itBot!=botclusters.end(); ++itBot) { std::cout<<*itBot<<" | "; } std::cout<::iterator itTop = topclusters.begin(); itTop!=topclusters.end(); ++itTop) { topIndex= *itTop + clusterOffset; // index in fClusterArray Double_t topcharge = 0., meantopstrip=0.,meantoperr=0. ; oneclustertop = (clusters[*itTop]).GetClusterList(); if(oneclustertop.size()<1) continue; PndSdsDigiStrip* atopDigi = ((PndSdsDigiStrip*)fDigiArray->At(oneclustertop[0])); Int_t sensorIDtop = atopDigi->GetSensorID(); //if (kFALSE==SelectSensorParams(detName)) continue; // Invalid parameters, skip here. detID = atopDigi->GetDetID(); CalcMeanCharge(oneclustertop,meantopstrip,meantoperr,topcharge); if(oneclustertop.size()==1 && topcharge < fSingleStripChargeThreshold) { std::cout<<"-W- PndSdsClusterTask::Exec: Single strip charge falls below the threshold of "<GetNIndices();mcI++){ if (atopDigi->GetIndex(mcI) > -1) { mcindex = atopDigi->GetIndex(mcI); break; } } } fCurrentStripCalcTop->CalcStripPointOnLine(meantopstrip, meantopPoint); // loop on bottom side for (std::vector< Int_t>::iterator itBot = botclusters.begin(); itBot!=botclusters.end(); ++itBot) { botIndex = *itBot + clusterOffset; // index in fClusterArray Double_t botcharge = 0., meanbotstrip=0., meanboterr=0.; oneclusterbot = (clusters[*itBot]).GetClusterList(); if(oneclusterbot.size()<1)continue; PndSdsDigiStrip* abotDigi = ((PndSdsDigiStrip*)fDigiArray->At(oneclusterbot[0])); Int_t sensorIDbot = abotDigi->GetSensorID(); //go to the next cluster if we didn't hit the same sensor if(sensorIDbot != sensorIDtop) continue; CalcMeanCharge(oneclusterbot,meanbotstrip,meanboterr,botcharge); if(oneclusterbot.size() == 1 && botcharge < fSingleStripChargeThreshold) { std::cout<<"-W- PndSdsClusterTask::Exec: Single strip charge falls below the threshold of "< 2) { std::cout<<"Charges: Ctop = "<0 && fabs(botcharge-topcharge)CalcStripPointOnLine(meanbotstrip, meanbotPoint); if(mcindex < 0) {//look for the first digi from a MC point for(Int_t mcI = 0; mcIGetNIndices();mcI++){ if (abotDigi->GetIndex(mcI) > -1) { mcindex = abotDigi->GetIndex(mcI); break; } } } Bool_t test = Backmap(meantopPoint, meantoperr, meanbotPoint, meanboterr, hitPos, hitErr,sensorIDtop); if (kFALSE==test) continue; // --- add hit to list --- Int_t i = fHitArray->GetEntriesFast(); new((*fHitArray)[i]) PndSdsHit(detID,sensorIDtop,hitPos,hitErr, topIndex,mycharge,oneclusterbot.size()+oneclustertop.size(),mcindex); ((PndSdsHit*)((*fHitArray)[i]))->SetBotIndex(botIndex); ((PndSdsHit*)((*fHitArray)[i]))->SetLink(FairLink(fClusterType, topIndex)); ((PndSdsHit*)((*fHitArray)[i]))->AddLink(FairLink(fClusterType, botIndex)); } else if (fVerbose > 2) std::cout<<"Strip charge contents too differently"< 1) std::cout << "-I- PndSdsStripClusterTask: " << fClusterArray->GetEntriesFast() << " Mvd Clusters and " << fHitArray->GetEntriesFast()<<" Hits calculated." << " out of " <GetEntriesFast()<< " Digis"<< std::endl; return; } // ------------------------------------------------------------------------- Bool_t PndSdsStripClusterTask::SelectSensorParams(Int_t sensorID) { TString detpath = fGeoH->GetPath(sensorID); if( !(detpath.Contains("Strip")) ) return kFALSE; TIter parsetiter(fDigiParameterList); while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() ) { const char* sensortype = digipar->GetSensType(); if(detpath.Contains(sensortype)) { SetCurrentCalculators(digipar); return kTRUE; } } // no suiting object found if (fVerbose > 1) std::cout<<"detector name does not contain a valid parameter name."< 2) std::cout<<" DetName : "<GetSensType(); fCurrentStripCalcTop = fStripCalcTop[sensortype]; fCurrentStripCalcBot = fStripCalcBot[sensortype]; fCurrentClusterfinder = fClusterFinderList[sensortype]; fCurrentChargeConverter = fChargeConverter[sensortype]; fCurrentDigiPar = digipar; fCurrentChargeAlgos = fChargeAlgos[sensortype]; fCurrentChargeAlgos->SetCalcStrip(fCurrentStripCalcTop); fCurrentChargeAlgos->SetChargeConverter(fCurrentChargeConverter); fChargeCut = digipar->GetChargeCut(); fSingleStripChargeThreshold = digipar->GetSingleChargeCut(); return; } // ------------------------------------------------------------------------- void PndSdsStripClusterTask::ResetClusterFinders() { //recursively clean the digis in the clusterfinder objects each event for(std::map::iterator CFiter = fClusterFinderList.begin(); CFiter != fClusterFinderList.end(); CFiter++) { (CFiter->second)->Reinit(); } } // ------------------------------------------------------------------------- void PndSdsStripClusterTask::FillClusterFinders() { // Info("FillClusterFinders","Here! fCurrntClusterfinder:%p",fCurrentClusterfinder); ResetClusterFinders(); // a std::map is a SORTED container, it is sorted by the identifier Int_t sensorID; Int_t strip; SensorSide side; PndSdsDigiStrip* myDigi=0; // Sort Digi indice into the clusterfinder if (fDigiArray->GetEntriesFast() == 0) return; if(fVerbose>2) Info("FillClusterFinders","adding these digis to the finders:"); for (Int_t iDigi = 0; iDigi < fDigiArray->GetEntriesFast(); iDigi++) { // sort digis by sensor name and stripnumber myDigi = (PndSdsDigiStrip*)(fDigiArray->At(iDigi)); if(fVerbose>2) {std::cout<<"Digi "<Print();} sensorID = myDigi->GetSensorID(); if (kFALSE==SelectSensorParams(sensorID)) continue; // Invalid parameters, skip here. //we use the top side as "first" side fCurrentStripCalcTop->CalcFeChToStrip(myDigi->GetFE(), myDigi->GetChannel(), strip, side); fCurrentClusterfinder->AddDigi(sensorID,side,myDigi->GetTimestamp(),strip,iDigi); } } // ------------------------------------------------------------------------- TVector2 PndSdsStripClusterTask::CalcLineCross( TVector2 point1, TVector2 dir1, TVector2 point2, TVector2 dir2) const { Double_t dx, dy, s, M, x, y; dx = point2.X() - point1.X(); dy = point2.Y() - point1.Y(); M = dir1.X()*dir2.Y() - dir1.Y()*dir2.X(); if(M !=0.) { s = dir1.Y()*dx/M - dir1.X()*dy/M; x = point2.X() + dir2.X()*s; y = point2.Y() + dir2.Y()*s; } else { std::cout<<"Warning in PndSdsStripClusterTask::CalcLineCross(): M=0 setting (x,y) to 0"< &onecluster, Double_t &meanstrip, Double_t &meanerr, Double_t &charge) { //if (fMeanAlgo == 0) //{ // Calculate mean position in position channels weighted by the charges Int_t strip; SensorSide side; for (std::vector::iterator itDigi = onecluster.begin(); itDigi != onecluster.end(); ++itDigi) { // calculate the mean charge and stripnumber PndSdsDigiStrip* myDigi = (PndSdsDigiStrip*)fDigiArray->At(*itDigi); fCurrentStripCalcTop->CalcFeChToStrip(myDigi->GetFE(), myDigi->GetChannel(), strip, side); charge += fCurrentChargeConverter->DigiValueToCharge(*myDigi); meanstrip += fCurrentChargeConverter->DigiValueToCharge(*myDigi) * strip; meanerr += fCurrentChargeConverter->DigiValueToCharge(*myDigi)*fCurrentChargeConverter->DigiValueToCharge(*myDigi); } meanstrip = meanstrip/charge; // this error treatment is: dx = dpitch * sqrt(weigthsquares) meanerr = sqrt(meanerr/(charge*charge)); if(side==kTOP){ meanerr = meanerr * (fCurrentDigiPar->GetTopPitch()/sqrt(12.)); }else{ meanerr = meanerr * (fCurrentDigiPar->GetBotPitch()/sqrt(12.)); } //} else { // //TODO: Apply other clusterfinder mean & error algorithms // if(fVerbose>1)std::cout<<"-W- PndSdsStripClusterTask::CalcMeanCharge: Using a preliminary Chargeweighting, please set fMeanAlgo = 0 ."<center_of_gravity(onecluster); //} } Bool_t PndSdsStripClusterTask::Backmap( TVector2 meantopPoint, Double_t meantoperr, TVector2 meanbotPoint, Double_t meanboterr, TVector3 &hitPos, TVector3 &hitErr, Int_t &sensorID) { // BACKMAPPING // get the backmapped point TVector3 localpos, locDpos; Double_t t, b; Double_t errZ = 2.*fGeoH->GetSensorDimensionsShortId(sensorID).Z()/TMath::Sqrt(12.0); TVector2 onsensorPoint = CalcLineCross(meantopPoint, fCurrentStripCalcTop->GetStripDirection(), meanbotPoint, fCurrentStripCalcBot->GetStripDirection() ); // here we assume the sensor system to be in the _Middle_ of the volume localpos.SetXYZ( onsensorPoint.X(), onsensorPoint.Y(), 0.); // let's see if we're still on the sensor (cut combinations with noise off) if(fabs(localpos.X()) > fabs(fCurrentDigiPar->GetTopAnchor().X())) return kFALSE; if(fabs(localpos.Y()) > fabs(fCurrentDigiPar->GetTopAnchor().Y())) return kFALSE; //do the transformation from sensor to lab frame hitPos = fGeoH->LocalToMasterShortId(localpos,sensorID); // calculate the errors corresponding to a skewed system! t = meantoperr*fCurrentDigiPar->GetTopPitch()*cos(fCurrentDigiPar->GetOrient()); b = meanboterr*fCurrentDigiPar->GetBotPitch()*cos(fCurrentDigiPar->GetOrient()+fCurrentDigiPar->GetSkew()); locDpos.SetX( sqrt(t*t+b*b) ); t = meantoperr*fCurrentDigiPar->GetTopPitch()*sin(fCurrentDigiPar->GetOrient()); b = meanboterr*fCurrentDigiPar->GetBotPitch()*sin(fCurrentDigiPar->GetOrient()+fCurrentDigiPar->GetSkew()); locDpos.SetY( sqrt(t*t+b*b) ); locDpos.SetZ( errZ ); //do the transformation from sensor to lab frame hitErr = fGeoH->LocalToMasterErrorsShortId(locDpos,sensorID); return kTRUE; } ClassImp(PndSdsStripClusterTask);