Added new subdirectory (analysis package) "musrSimAna". This is a general analysis program that allows one to plot histograms out of the simulated trees. The detector setup of the veto and coincidence relations with the positron/muon counters is defined in *.v1190 files. Also the histograms that should be plotted/saved are defined in this file. Thus (at least in principle) the user does not need to write an analysis program dedicated for his/her instrument. One just needs to modify the *.v1190 file. The "musrSimAna" is still in the development phase, no documentation is available at this stage.
278 lines
15 KiB
C++
278 lines
15 KiB
C++
//#include <iostream>
|
|
#include "musrCounter.hh"
|
|
#include "TCanvas.h"
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
musrCounter::musrCounter(int CHANNEL_NR, char CHANNEL_NAME[200], char CHANNEL_TYPE, float E_THRESH, int TIME_SHIFT) {
|
|
// pointerToAnalysis=this;
|
|
counterNr = CHANNEL_NR;
|
|
strcpy(counterName,CHANNEL_NAME);
|
|
counterType = CHANNEL_TYPE;
|
|
couterEThreshold = E_THRESH;
|
|
counterTimeShift = (Long64_t) TIME_SHIFT;
|
|
std::cout<<"musrCounter::musrCounter: Creating counter "<<counterNr<<" "<<counterName<<" "<<counterType<<" "<<couterEThreshold<<" "<<counterTimeShift<<std::endl;
|
|
strcpy(TDC_histoName,"Unset");
|
|
TDC_t0=0;
|
|
TDC_t1=0;
|
|
TDC_t2=0;
|
|
TDC_histoNrAdd=0;
|
|
coincidenceTimeWindowMin=0;
|
|
coincidenceTimeWindowMax=0;
|
|
maxCoincidenceTimeWindow=0;
|
|
strcpy(TDC_histoNameAdd,"Unset");
|
|
doubleHitN=0;
|
|
numberOfMuonCandidates=0;
|
|
}
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
musrCounter::~musrCounter() {}
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
void musrCounter::SetTDChistogram(char hName[200],int t0,int t1,int t2,int hNr,char hNameAdd[200]) {
|
|
strcpy(TDC_histoName,hName);
|
|
TDC_t0=t0;
|
|
TDC_t1=t1;
|
|
TDC_t2=t2;
|
|
TDC_histoNrAdd=hNr;
|
|
strcpy(TDC_histoNameAdd,hNameAdd);
|
|
std::cout<<"TDC_histogram: "<<TDC_histoName<<" "<<TDC_t0<<" "<<TDC_t1<<" "<<TDC_t2<<" "<<TDC_histoNrAdd<<" "<<TDC_histoNameAdd<<std::endl;
|
|
histTDC = new TH1D(TDC_histoName,TDC_histoName,t2,0.,float(t2));
|
|
}
|
|
//================================================================
|
|
void musrCounter::FillTDChistogram(Double_t variable, Double_t vaha) {
|
|
histTDC->Fill(variable,vaha);
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::DrawTDChistogram() {
|
|
char canvasName[501];
|
|
sprintf(canvasName,"c%s",TDC_histoName);
|
|
TCanvas* cTmp = new TCanvas(canvasName,canvasName);
|
|
histTDC->Draw();
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::FillHitInCounter(Double_t edep, Long64_t timeBin, Long64_t timeBin2, Int_t kEntry, Int_t eveID, Int_t iDet, Int_t detectorID){
|
|
//cDEL std::cout<<"FillHitInCounter: timeBin="<<timeBin<<" timeBin2="<<timeBin2<<" counterTimeShift="<< counterTimeShift<<std::endl;
|
|
//cDEL std::cout<<" FillHitInCounter I: timeBin-counterTimeShift="<<timeBin-counterTimeShift<<" timeBin2-counterTimeShift="<<timeBin2-counterTimeShift<<std::endl;
|
|
// std::cout<<"musrCounter::FillHitInCounter:"<<counterNr<<std::endl;
|
|
if (edep>=couterEThreshold) {
|
|
|
|
hitInfo* hInfo = new hitInfo(kEntry,eveID,iDet,detectorID,edep,timeBin2-counterTimeShift);
|
|
//cDEL std::cout<<detectorID<<" FillHitInCounter II: timeBin-counterTimeShift="<<timeBin-counterTimeShift<<" timeBin2-counterTimeShift="<<timeBin2-counterTimeShift<<std::endl;
|
|
hitMap.insert( std::pair<Long64_t,hitInfo*>(timeBin-counterTimeShift,hInfo) );
|
|
}
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::RemoveHitsInCounter(Long64_t timeBinLimit) {
|
|
// Remove the obsolete hits (i.e. hits that happaned well before t0) from the Counter class
|
|
if (hitMap.empty()) return;
|
|
// myPrintThisCounter();
|
|
// if (counterNr==1) {std::cout<<"ooooo1 timeBinLimit="<<timeBinLimit<<std::endl; myPrintThisCounter();}
|
|
for (hitMap_TYPE::iterator it = hitMap.begin(); it != hitMap.end(); ++it) {
|
|
// std::cout<<"musrCounter::RemoveHitsInCounter: counterNr="<<counterNr<<" hitMap.size()="<<hitMap.size()<<" maxCoincidenceTimeWindow="<<maxCoincidenceTimeWindow<<" bins of tdcresolution."<<std::endl;
|
|
if ((it->first)>(timeBinLimit+maxCoincidenceTimeWindow-counterTimeShift)) return; //note that maxCoincidenceTimeWindow is usually negative number
|
|
else {
|
|
// std::cout<<" Deleting hit from counter "<<counterNr<<", time bin = "<<(it->first)<<std::endl;
|
|
delete (it->second);
|
|
hitMap.erase(it);
|
|
}
|
|
}
|
|
// if (counterNr==1) {std::cout<<"ooooo2"<<std::endl; myPrintThisCounter();}
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::RewindHitsInCounter(Long64_t timeBinsToRewind) {
|
|
// Reset time in hits from the Counter class
|
|
if (hitMap.empty()) return;
|
|
|
|
hitMap_TYPE hitMap_TMP;
|
|
for (hitMap_TYPE::iterator it = hitMap.begin(); it != hitMap.end(); ++it) {
|
|
// std::cout<<"musrCounter::RewindHitsInCounter: "<<std::endl;
|
|
Long64_t tempBinT = it->first;
|
|
// int tempEvnr= it->second;
|
|
// hitMap_TMP.insert( std::pair<Long64_t,int>(tempBinT-timeBinsToRewind,tempEvnr) );
|
|
hitInfo* tempEvnr= it->second;
|
|
tempEvnr->RewindTimeBin2(timeBinsToRewind);
|
|
hitMap_TMP.insert( std::pair<Long64_t,hitInfo*>(tempBinT-timeBinsToRewind,tempEvnr) );
|
|
}
|
|
hitMap.swap(hitMap_TMP);
|
|
}
|
|
|
|
//================================================================
|
|
Bool_t musrCounter::IsInCoincidence(Long64_t timeBin, Bool_t ignoreHitsAtBinZero, Long64_t timeBinMinimum, Long64_t timeBinMaximum){
|
|
// timeBin ... time bin, at which the coincidence is searched
|
|
// counterTimeShiftOfRequestingCounter ... time shift (in bin units) of the counter, for which the coincidence is searched
|
|
// ignoreHitsAtBinZero ... if "true", hits at timeBin will be ignored (needed for searching of coincidence of M counter
|
|
// with other M counters or P counters with other P counters)
|
|
// "false" should be used for coincidence detectors and vetos.
|
|
if (hitMap.empty()) return false;
|
|
// Long64_t timeBinToTest = timeBin + counterTimeShift - counterTimeShiftOfRequestingCounter;
|
|
Long64_t timeBinToTest = timeBin;
|
|
// If timeBinMinimum and timeBinMaximum are not specified, use internal time window of the detector (koincidence or veto detectors).
|
|
// Otherwise use timeBinMinimum and timeBinMaximum (e.g.coincidence of a positron counter with other positron counters).
|
|
Long64_t timeBinMin = (timeBinMinimum==-123456789) ? timeBinToTest + coincidenceTimeWindowMin : timeBinToTest + timeBinMinimum;
|
|
Long64_t timeBinMax = (timeBinMaximum==-123456789) ? timeBinToTest + coincidenceTimeWindowMax : timeBinToTest + timeBinMaximum;
|
|
for (hitMap_TYPE::iterator it = hitMap.begin(); it != hitMap.end(); ++it) {
|
|
Long64_t timeBinOfCount_tmp = it->first;
|
|
if ((timeBinOfCount_tmp >= timeBinMin) && (timeBinOfCount_tmp <= timeBinMax)) {
|
|
if ((timeBin!=timeBinOfCount_tmp)||(!ignoreHitsAtBinZero)) {
|
|
return true;
|
|
}
|
|
}
|
|
else if (timeBinOfCount_tmp > timeBinMax) return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//================================================================
|
|
Bool_t musrCounter::GetNextGoodMuon(Int_t evtID, Long64_t timeBinMin, Long64_t& timeBinOfNextHit, Int_t& kEntry, Int_t& idet, Int_t& idetID, Double_t& idetEdep, Bool_t& doubleHitFound) {
|
|
// This function searches for a good muon, i.e. the muon
|
|
// 1) belongs to the currently analysed event
|
|
// 2) is in coincidence with all required coincidence detectors
|
|
// 3) is not in coincidence with veto detectors
|
|
// 4) is not in coincidence with other muons (more precisely - with hits in m-counter).
|
|
// INPUT PARAMETERS: evtID, timeBinMin
|
|
// OUTPUT PARAMETERS: timeBinOfNextHit
|
|
//
|
|
// Loop over the hits in the counter
|
|
// std::cout<<" musrCounter::GetNextGoodMuon timeBinMin="<<timeBinMin<<std::endl;
|
|
if (hitMap.empty()) return false;
|
|
if (counterType!='M') {std::cout<<"\n!!! FATAL ERROR !!! musrCounter::GetNextGoodMuon: not the muon counter! ==> S T O P !!!\n"; exit(1);}
|
|
doubleHitFound = false;
|
|
for (hitMap_TYPE::iterator it = hitMap.begin(); it != hitMap.end(); ++it) {
|
|
|
|
Long64_t timeBinOfCount_tmp = it->first;
|
|
timeBinOfNextHit = timeBinOfCount_tmp;
|
|
if (timeBinOfCount_tmp <= timeBinMin) continue; // This hit was already processed previously ==> skip it
|
|
|
|
Int_t eventNumber = (it->second)->eventIDnumber;
|
|
if (eventNumber!=evtID) continue; // This trigger hit does not correspond to the currently processed event
|
|
// ==> skip it, becuase it was already proceesed or will be processed in future
|
|
numberOfMuonCandidates++;
|
|
// std::cout<<"*** "<<evtID<<" eventNumber="<<eventNumber<<" canditas="<<numberOfMuonCandidates<<std::endl;
|
|
// Hit candidate was found. Now check its coincidences and vetos
|
|
for (counterMapType::const_iterator itCounter = koincidenceCounterMap.begin(); itCounter!=koincidenceCounterMap.end(); ++itCounter) {
|
|
// if (!( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp,counterTimeShift) )) goto endOfThisHit; // no coincidence found ==> skip hit
|
|
if (!( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp) )) goto endOfThisHit; // no coincidence found ==> skip hit
|
|
}
|
|
for (counterMapType::const_iterator itCounter = vetoCounterMap.begin(); itCounter!=vetoCounterMap.end(); ++itCounter) {
|
|
// if ( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp,counterTimeShift) ) goto endOfThisHit; // coincidence with veto found ==> skip hit
|
|
if ( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp) ) goto endOfThisHit; // coincidence with veto found ==> skip hit
|
|
}
|
|
// Check coincidences with other hits in the M counter
|
|
// it is expected that there is only one M counter
|
|
// if (this->IsInCoincidence(timeBinOfCount_tmp,counterTimeShift,true) ) { // coincidence with another M-counter hit ==> skip hit
|
|
if (this->IsInCoincidence(timeBinOfCount_tmp,true) ) { // coincidence with another M-counter hit ==> skip hit
|
|
doubleHitFound = true;
|
|
// std::cout<<"UJGUR double hit found"<<std::endl;
|
|
goto endOfThisHit;
|
|
}
|
|
|
|
kEntry = (it->second)->eventEntry;
|
|
idet = (it->second)->det_i;
|
|
idetID = (it->second)->det_id;
|
|
idetEdep = (it->second)->det_edep;
|
|
// timeBinOfNextHit = timeBinOfCount_tmp;
|
|
return true;
|
|
|
|
endOfThisHit:
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//================================================================
|
|
Bool_t musrCounter::GetNextGoodPositron(Int_t evtID, Long64_t timeBinMin, Long64_t timeBinMax, Long64_t& timeBinOfNextGoodHit, Long64_t& timeBinOfNextGoodHit_phaseShifted, Int_t& kEntry, Int_t& idet, Int_t& idetID, Double_t& idetEdep, Bool_t& doubleHitFound) {
|
|
// INPUT PARAMETERS: evtID, timeBinMin
|
|
// OUTPUT PARAMETERS: timeBinOfNextGoodHit
|
|
//
|
|
// Loop over the hits in the counter
|
|
if (hitMap.empty()) return false;
|
|
if (counterType!='P') {std::cout<<"\n!!! FATAL ERROR !!! musrCounter::GetNextGoodPositron: not the positron counter! ==> S T O P !!!\n"; exit(1);}
|
|
doubleHitFound = false;
|
|
for (hitMap_TYPE::iterator it = hitMap.begin(); it != hitMap.end(); ++it) {
|
|
Int_t eventNumber = (it->second)->eventIDnumber;
|
|
Long64_t timeBinOfCount_tmp = it->first;
|
|
if ((timeBinOfCount_tmp <= timeBinMin) || (timeBinOfCount_tmp > timeBinMax)) continue; // This hit is out of the data interval ==> skip it
|
|
|
|
// Hit candidate was found. Now check its coincidences and vetos
|
|
for (counterMapType::const_iterator itCounter = koincidenceCounterMap.begin(); itCounter!=koincidenceCounterMap.end(); ++itCounter) {
|
|
// if (!( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp,counterTimeShift) )) goto endOfThisHit; // no coincidence found ==> skip hit
|
|
if (!( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp) )) goto endOfThisHit; // no coincidence found ==> skip hit
|
|
}
|
|
for (counterMapType::const_iterator itCounter = vetoCounterMap.begin(); itCounter!=vetoCounterMap.end(); ++itCounter) {
|
|
// if ( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp,counterTimeShift) ) goto endOfThisHit; // coincidence with veto found ==> skip hit
|
|
if ( (itCounter->second)->IsInCoincidence(timeBinOfCount_tmp) ) goto endOfThisHit; // coincidence with veto found ==> skip hit
|
|
}
|
|
// Check coincidences with other P counters
|
|
// Coincidences with other P counters must be checked in musrAnalysis.cxx
|
|
// if (this->IsInCoincidence(timeBinOfCount_tmp,counterTimeShift,true) ) { // coincidence with another P-counter hit ==> skip hit
|
|
// hovno
|
|
// ADD HERE THE CHECK THAT THE POSITRON IS FOUND WITHIN THE DATA INTERVAL, i.e. within <timeBinMin,timeBinMax>.
|
|
// AND ALSO CHECK THAT THIS IS TRUE FOR THE COINCIDENCE WITH OTHER POSITRON COUNTERS!!!
|
|
if (this->IsInCoincidence(timeBinOfCount_tmp,true,timeBinMin,timeBinMax) ) { // coincidence with another P-counter hit ==> skip hit
|
|
doubleHitFound = true;
|
|
// std::cout<<"tttttttttttttttttttt doubleHitN="<<doubleHitN++<<std::endl;
|
|
goto endOfThisHit;
|
|
}
|
|
|
|
kEntry = (it->second)->eventEntry;
|
|
idet = (it->second)->det_i;
|
|
idetID = (it->second)->det_id;
|
|
idetEdep = (it->second)->det_edep;
|
|
timeBinOfNextGoodHit = timeBinOfCount_tmp;
|
|
timeBinOfNextGoodHit_phaseShifted = (it->second) -> timeBin2;
|
|
//cDEL std::cout<<"timeBinOfNextGoodHit ="<<timeBinOfNextGoodHit<<" timeBinOfNextGoodHit_phaseShifted = "<<timeBinOfNextGoodHit_phaseShifted<<std::endl;
|
|
return true;
|
|
|
|
endOfThisHit:
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::SetCoincidenceTimeWindowOfAllCoincidenceDetectors(Long64_t maxCoinc, Long64_t min, Long64_t max) {
|
|
for (counterMapType::const_iterator it = koincidenceCounterMap.begin(); it!=koincidenceCounterMap.end(); ++it) {
|
|
if ( ( ((it->second)->GetMaxCoincidenceTimeWindow()) !=0) &&
|
|
( ((it->second)->GetMaxCoincidenceTimeWindow()) !=maxCoinc) ) {
|
|
std::cout<<" !!!! ERROR SetCoincidenceTimeWindowOfAllCoincidenceDetectors : coincidenceTimeWindow set multiple times! ==> S T O P !!!"<<std::endl;
|
|
exit(1);
|
|
}
|
|
(it->second)->SetMaxCoincidenceTimeWindow(maxCoinc);
|
|
(it->second)->SetCoincidenceTimeWindow(min,max);
|
|
}
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::SetCoincidenceTimeWindowOfAllVetoDetectors(Long64_t maxCoinc, Long64_t min, Long64_t max) {
|
|
for (counterMapType::const_iterator it = vetoCounterMap.begin(); it!=vetoCounterMap.end(); ++it) {
|
|
if ( ( ((it->second)->GetMaxCoincidenceTimeWindow()) !=0) &&
|
|
( ((it->second)->GetMaxCoincidenceTimeWindow()) !=maxCoinc) ) {
|
|
std::cout<<" !!!! ERROR SetCoincidenceTimeWindowOfAllVetoDetectors : coincidenceTimeWindow set multiple times! ==> S T O P !!!"<<std::endl;
|
|
exit(1);
|
|
}
|
|
(it->second)->SetMaxCoincidenceTimeWindow(maxCoinc);
|
|
(it->second)->SetCoincidenceTimeWindow(min,max);
|
|
}
|
|
}
|
|
|
|
//================================================================
|
|
void musrCounter::myPrintThisCounter(Int_t evtID) {
|
|
Bool_t eventMixing=false;
|
|
std::cout<<"musrCounter::myPrintThisCounter: counterNr="<<counterNr<<": ";
|
|
for (hitMap_TYPE::iterator it = hitMap.begin(); it != hitMap.end(); ++it) {
|
|
std::cout<<"\t"<<it->first<<" "<<(it->second)->eventIDnumber<<",";
|
|
if (evtID != (it->second)->eventIDnumber) {eventMixing=true;}
|
|
}
|
|
if (eventMixing) {std::cout<<" Potential event mmmmmmmmixing";}
|
|
std::cout<<std::endl;
|
|
}
|
|
|
|
//================================================================
|