#define musrAnalysis_cxx #include "musrAnalysis.hh" #include "musrTH.hh" //#include #include #include #include #include //#include musrWriteDump* musrAnalysis::myWriteDump = NULL; void musrAnalysis::Loop(char* runChar, char* v1190FileName, Int_t nrEvents) { // In a ROOT session, you can do: // Root > .L musrAnalysis.C // Root > musrAnalysis t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; std::cerr<<"musrSimAnalysis::Loop() : Analysing run "<GetEntriesFast(); if (nrEvents!=0) nentries = nrEvents; Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentryGetEntry(jentry); InitialiseEvent(); nbytes += nb; // if (Cut(ientry) < 0) continue; if (jentry%10000==0) std::cout << "Analysing event nr. jentry=" << jentry << " and found " << numberOfGoodMuons << " muons so far" << std::endl; AnalyseEvent(jentry); } SaveHistograms(runChar,v1190FileName); } //================================================================ void musrAnalysis::ReadInInputParameters(char* charV1190FileName) { std::cout<<"musrAnalysis::ReadInInputParameters()"< tmpCoincidenceMultimap; // for (int i=0; i("a", 1)); // // } // } while (!feof(fSteeringFile)) { fgets(line,10000,fSteeringFile); if ((line[0]!='#')&&(line[0]!='\n')&&(line[0]!='\r')&&(line[0]!='$')&&(line[0]!='!')) { char tmpString0[200]="Unset"; char tmpString1[200]="Unset"; sscanf(&line[0],"%s",tmpString0); if (strncmp(tmpString0,"INSTRUMENT=",strlen("INSTRUMENT="))==0) { instrument=&line[strlen("INSTRUMENT=")]; } else if (strncmp(tmpString0,"DESCRIPTION=",strlen("DESCRIPTION="))==0) { description=&line[strlen("DESCRIPTION=")]; } else if (strncmp(tmpString0,"TYPE=",strlen("TYPE="))==0) { tdchwtype=&line[strlen("TYPE=")]; } else if (strncmp(tmpString0,"RESOLUTION=",strlen("RESOLUTION="))==0) { sscanf(&line[strlen("RESOLUTION=")],"%g",&tmpfvar); tdcresolution = tmpfvar * picosecond; if (tdcresolution<1*picosecond) { std::cout<<"\n !!! ERROR !!! Time resolution of TDC must be larger than 1 ps (you requested "< too low time resolution might lead to numerical problems in musrCounter ==> S T O P"<(ichannel_orig_tmp,ichannel_new_tmp)); } else if (strcmp(tmpString0,"DEBUGEVENT")==0) { int ieventToDebug_tmp, iLevelToDebug_tmp; sscanf(&line[0],"%*s %d %d",&ieventToDebug_tmp,&iLevelToDebug_tmp); bool_debugingRequired=true; if (ieventToDebug_tmp>-1) { debugEventMap.insert(std::pair(ieventToDebug_tmp,iLevelToDebug_tmp)); } else { for (int j=0; j<=-ieventToDebug_tmp;j++) { debugEventMap.insert(std::pair(j,iLevelToDebug_tmp)); } } } else if (strcmp(tmpString0,"WRITE_OUT_DUMP_FILE")==0) { int clock_channelID; int max_timeBin_jitter; // int clock_interval_tmp; // sscanf(&line[0],"%*s %s %d %d",tmpString1,&clock_channelID_tmp,&clock_interval_tmp); sscanf(&line[0],"%*s %s %d %d",tmpString1,&clock_channelID,&max_timeBin_jitter); // clock_channelID = clock_channelID_tmp; // clock_interval = clock_interval_tmp; musrCounter::bool_WriteDataToDumpFile = true; // std::cout<<"tmpString1="< STOP !!!"< S T O P !!!"< ignored, histogram not defined! S T O P !!!"< ignored, histogram not defined! S T O P !!!"<second; if (strcmp(tmpString0,"musrTH1D")==0) { // std::cout<<"pointerToVariable1="<SetRotatingReferenceFrame(rot_ref_frequency, rot_ref_phase); hInfo->Fill(21, rot_ref_frequency); // value may be overwritten - just the last rot. ref. frame will be saved hInfo->Fill(22, rot_ref_phase); // value may be overwritten - just the last rot. ref. frame will be saved } else if (strcmp(furtherOption,"correctexpdecay")==0) { myTH->SetExpDecayCorrection(); } } else { Double_t* pointerToVariable2 = iter2->second; musrTH* myTH = new musrTH("2D",histoName,histoTitle,nrBinsX,minX,maxX,nrBinsY,minY,maxY,pointerToVariable1,pointerToVariable2); listOfAllHistograms2D.push_back(myTH); } } else if (strncmp(tmpString0,"humanDecayHistograms",strlen("humanDecayHistograms"))==0) { char motherHistoName[200]; char motherHistoPileupName[200]; sscanf(&line[0],"%*s %s %s",motherHistoName,motherHistoPileupName); std::cout<<" Defining humanDecayHistograms (motherHistoName="<::const_iterator it = listOfAllHistograms1D.begin(); it != listOfAllHistograms1D.end(); ++it) { if ((*it)->IsThisHistoNamed(motherHistoName)) { motherOfHumanDecayHistograms = *it; } if ((*it)->IsThisHistoNamed(motherHistoPileupName)) { motherOfHumanDecayPileupHistograms = *it; } } if (motherOfHumanDecayHistograms==NULL) { std::cout<<"\n\nmusrAnalysis::ReadInInputParameters Mother histogram (motherOfHumanDecayHistograms)" <<"of the \"Human decay histogram\" not found!"< S T O P "< S T O P "<second)==(std::string) NAME1) { nameDefined = true; iBinHuman = it->first; } } if (!nameDefined) { nBinHuman++; iBinHuman=nBinHuman; humanDecayMap.insert(std::pair(iBinHuman,NAME1)); } humanDecayMultimap.insert(std::pair(iBinHuman,N1)); char* pch2 = strstr(pch,NAME1)+strlen(NAME1); pch=pch2; nscan = sscanf(pch,"%d %s",&N1,NAME1); // indexHuman++; } while (nscan==2); Int_t nrBinsHumanHist=humanDecayMap.size(); // Int_t nrBinsHumanHist=0; // std::string oldString="blaBlaoldStringUndefiNED"; // for (humanDecayMultimapType::const_iterator it = humanDecayMultimap.begin(); it!=humanDecayMultimap.end(); ++it) { // if (oldString!=(it->first)) nrBinsHumanHist++; // } std::cout<<"\nnrBinsHumanHist="<SetBinLabel1D(k+1,sHumanDecayArray[k]); // } // oldString="blaBlaoldStringUndefiNED"; for (humanDecayMapType::const_iterator it = humanDecayMap.begin(); it!=humanDecayMap.end(); ++it) { humanDecayHistograms -> SetBinLabel1D(it->first,it->second); humanDecayPileupHistograms -> SetBinLabel1D(it->first,it->second); } } else if (strncmp(tmpString0,"condition",strlen("condition"))==0) { // Selection of the predefined conditions to be applied int iConditionTMP; char conditionNameTMP[200]; sscanf(&line[0],"%*s %d %s",&iConditionTMP,conditionNameTMP); if (iConditionTMP<0) { std::cout<<" !!! ERROR: Condition number must be >= 0 (not "<=nrConditions) { std::cout<<" !!! ERROR: Condition number must be < "< Add it in the musrAnalysis.cxx S T O P !!!"<= -1 (not "<=nrConditions) { std::cout<<" !!! ERROR: draw: condition number must be < "<::const_iterator it = listOfAllHistograms1D.begin(); it != listOfAllHistograms1D.end(); ++it) { if ((*it)->IsThisHistoNamed(histoNameTMP)) { (*it)->SetDrawListOfHistograms(iConditionTMP); } } for(std::list::const_iterator it = listOfAllHistograms2D.begin(); it != listOfAllHistograms2D.end(); ++it) { if ((*it)->IsThisHistoNamed(histoNameTMP)) { (*it)->SetDrawListOfHistograms(iConditionTMP); } } if (humanDecayHistograms->IsThisHistoNamed(histoNameTMP)) { humanDecayHistograms->SetDrawListOfHistograms(iConditionTMP); } if (humanDecayPileupHistograms->IsThisHistoNamed(histoNameTMP)) { humanDecayPileupHistograms->SetDrawListOfHistograms(iConditionTMP); } } else if (strcmp(tmpString0,"counterPhaseShifts")==0) { int nscan; int N1; float PHASE_SHIFT; char NAME1[100]; char NAME2[100]; char *pch = line + strlen("counterPhaseShifts"); do { nscan = sscanf(pch,"%d %g",&N1,&PHASE_SHIFT); phaseShiftMap.insert(std::pair(N1,PHASE_SHIFT/180*pi)); std::cout<<"N1="< S T O P F O R C E D"<::const_iterator it=SampleDetIDList.begin(); it!=SampleDetIDList.end(); ++it) { std::cout<<" "<< *it; } std::cout< S T O P "< S T O P "<second; counter->SetAntiCoincidenceTimeWindowMin(lmin); counter->SetAntiCoincidenceTimeWindowMax(lmax); } else if (strcmp(tmpString0,"artificiallyChangeMuDecayTime")==0) { float min, max, mmmin, mmmax; sscanf(&line[0],"%*s %g %g %g %g %g %g %g",&min,&max,&mmmin,&mmmax); bool_muDecayTimeTransformation = true; muDecayTime_t_min = min; muDecayTime_t_max = max; muDecayTime_Transformation_min = mmmin; muDecayTime_Transformation_max = mmmax; if ((muDecayTime_t_max <= muDecayTime_t_min) || (muDecayTime_Transformation_max <= muDecayTime_Transformation_min)) { std::cout<<" ERROR! musrAnalysis: error when setting the \"artificiallyChangeMuDecayTime\" parameters! Min > Max !!!"< S T O P "< SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); funct -> SetParameter(3,p3); funct -> FixParameter(4,xMin); } else if (strcmp(functionName,"funct2")==0) { funct = new TF1("funct2","[3]*exp(([4]-x)/2.19703)*(1+[2]*cos(x*[0]+[1]))+[5]"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); funct -> SetParameter(3,p3); funct -> FixParameter(4,xMin); funct -> SetParameter(5,p4); } else if (strcmp(functionName,"funct3")==0) { funct = new TF1("funct3","[3]*exp(([4]-x)/2.19703)*(1+[2]*cos(x*[0]+[1]))+[5]"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); funct -> SetParameter(3,p3); funct -> FixParameter(4,xMin); funct -> FixParameter(5,p4); } else if (strcmp(functionName,"funct4")==0) { funct = new TF1("funct4","[3]*exp(-x/2.19703)*(1+[2]*cos(x*[0]+[1]))+[4]"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); funct -> SetParameter(3,p3); funct -> SetParameter(4,p4); } else if (strcmp(functionName,"pol0")==0) { funct = new TF1("pol0","pol0"); } else if (strcmp(functionName,"simpleExpoPLUSconst")==0) { funct = new TF1("simpleExpoPLUSconst","[0]*exp(-x/2.19703)+[1]"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); } else if (strcmp(functionName,"TFieldCosPLUSbg")==0) { funct = new TF1("TFieldCosPLUSbg","[3]*(1+[2]*cos(x*[0]+[1]))+[4]*exp(x/2.19703)"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); funct -> SetParameter(3,p3); funct -> SetParameter(4,p4); } else if (strcmp(functionName,"TFieldCos")==0) { funct = new TF1("TFieldCos","[3]*(1+[2]*cos(x*[0]+[1]))"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); funct -> SetParameter(3,p3); } else if (strcmp(functionName,"rotFrameTime20")==0) { // funct = new TF1("rotFrameTime20","[2]*exp(-x/2.19703)*cos(x*[0]+[1]) "); funct = new TF1("rotFrameTime20","[2]*cos(x*[0]+[1]) "); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); } else if (strcmp(functionName,"gaus")==0) { funct = new TF1("gaus","gaus"); funct -> SetParameter(0,p0); funct -> SetParameter(1,p1); funct -> SetParameter(2,p2); } else { std::cout<<"musrAnalysis::ReadInInputParameters: function \""< S T O P"<::const_iterator it = listOfAllHistograms1D.begin(); it != listOfAllHistograms1D.end(); ++it) { if ((*it)->IsThisHistoNamed(histoName)) { tmpHistograms = *it; } } if (tmpHistograms==NULL) { std::cout<<"\n\nmusrAnalysis::ReadInInputParameters: Fit required, but the corresponding histogram " <<"not found!"< S T O P "<AssignFunction(funct, functOption, xMin, xMax); } else { //------------------------------------------------------------------ // Second part of the configuration file // // Replace spaces between quotation marks by '_' // and remove quatation marks and semicolon by ' '. // Remember position of the beginning and end of the defintion of the coincidence counters int nrOfSemicolons=0, beginningOfCoincidenceArray=0, endOfCoincidenceArray =0; for (Int_t i=0; i<(int)strlen(line); i++) { if (line[i]=='"') { line[i] = ' '; Int_t ii=i; do { ii++; if (isspace(line[ii])) line[ii] = '_'; } while (line[ii]!='"'); line[ii]= ' '; } else if (line[i] == ';') { line[i] = ' '; nrOfSemicolons++; if (nrOfSemicolons==5) beginningOfCoincidenceArray=i; if (nrOfSemicolons==6) endOfCoincidenceArray=i; } } // Read in the values from the configuration file int tmpChannel=-1, tmpTimeShift=0; char tmpName[200], tmpType[200]; float tmpThreshold =0.; Bool_t tmp_keep=(musrMode=='P'); // JSL: keep the small pulses in case different events add up to a big one sscanf(&line[0],"%d %s %s %g %d",&tmpChannel,tmpName,tmpType,&tmpThreshold,&tmpTimeShift); if(commonThreshold>0.0) { tmpThreshold=commonThreshold; } musrCounter* counter = new musrCounter(tmpChannel,tmpName,tmpType[0],tmpThreshold,tmpTimeShift, detRecoveryTime / tdcresolution, tmp_keep); if (tmpType[0]=='M') {mCounter =counter; allCounterMap[tmpChannel]=counter; overallBinDelay=tmpTimeShift;} else if (tmpType[0]=='P') {pCounterMap[tmpChannel]=counter; allCounterMap[tmpChannel]=counter;} else if (tmpType[0]=='K') {kCounterMap[tmpChannel]=counter; allCounterMap[tmpChannel]=counter;} else if (tmpType[0]=='V') {vCounterMap[tmpChannel]=counter; allCounterMap[tmpChannel]=counter;} // Read in the values for the coincidence detectors // (Tricky while the number of detectors in coincidence is not known) if ((endOfCoincidenceArray>0)&&(endOfCoincidenceArray!=beginningOfCoincidenceArray)) { char tmpCoinc[100]; strcpy(tmpCoinc,"987654321"); int jj=beginningOfCoincidenceArray; do { do {jj++;} while (isspace(line[jj])); // skip space characters; if (jj>endOfCoincidenceArray) {break;} sscanf(&line[jj],"%s",tmpCoinc); jj+=strlen(tmpCoinc); int iCoinc=atoi(tmpCoinc); if (iCoinc==987654321) continue; tmpCoincidenceMultimap.insert(std::pair(tmpChannel,iCoinc)); // tmpCoincidenceMultimap[tmpChannel][abs(iCoinc)]=iCoinc; } while (jjSetTDChistogram(tmpHistoName,tmpT0,tmpT1,tmpT2,tmpHistoaddNr,tmpHistoNameAdd); } } } // std::cout << line; } } std::cout << "INSTRUMENT=" << instrument << std::endl; std::cout << "DESCRIPTION=" << description << std::endl; std::cout << "TYPE=" << tdchwtype << std::endl; std::cout << "RESOLUTION="<second)->GetCounterNr(); for (std::multimap::iterator itCoinc = tmpCoincidenceMultimap.begin(); itCoinc != tmpCoincidenceMultimap.end(); ++itCoinc) { if ((*itCoinc).first == iChanNr) { int iChn2 = itCoinc->second; counterMapType::const_iterator itTwo = allCounterMap.find(abs(iChn2)); if (itTwo==allCounterMap.end()) { std::cout<<" Pointer to coincidence counter ("< S T O P"<second)->SetCoincidenceCounter(itTwo->second,iChn2); } } } } for (counterMapType::const_iterator it = allCounterMap.begin(); it!=allCounterMap.end(); ++it) { char DetectorType = (it->second)->GetCounterType(); if (DetectorType=='M') { (it->second)->SetMaxCoincidenceTimeWindow(pileupWindowBinMin); // (it->second)->SetCoincidenceTimeWindow_M(pileupWindowBinMin,pileupWindowBinMax); (it->second)->SetCoincidenceTimeWindowOfAllCoincidenceDetectors('M',-mcoincwin+pileupWindowBinMin,-mcoincwin,mcoincwin); (it->second)->SetCoincidenceTimeWindowOfAllVetoDetectors(-mcoincwin+pileupWindowBinMin,-vcoincwin,vcoincwin); } else if (DetectorType=='P') { (it->second)->SetMaxCoincidenceTimeWindow(dataWindowBinMin); // (it->second)->SetCoincidenceTimeWindow_P(dataWindowBinMin,dataWindowBinMax); (it->second)->SetCoincidenceTimeWindowOfAllCoincidenceDetectors('P',-pcoincwin+dataWindowBinMin,-pcoincwin,pcoincwin); (it->second)->SetCoincidenceTimeWindowOfAllVetoDetectors(-pcoincwin+dataWindowBinMin,-vcoincwin,vcoincwin); } // else if (DetectorType=='V') { // (it->second)->SetMaxCoincidenceTimeWindow(-vcoincwin); // (it->second)->SetCoincidenceTimeWindow(-vcoincwin,vcoincwin); // } } // for (int j=0; j::iterator itCoinc = tmpCoincidenceMultimap.begin(); itCoinc != tmpCoincidenceMultimap.end(); ++itCoinc) { // std::cout << " houby [" << (*itCoinc).first << ", " << (*itCoinc).second << "]" << std::endl; // // if (tmpCoincidenceMultimap[iChanNr][j]!=0) { // int j = (*itCoinc).first; // counterMapType::const_iterator itTwo = allCounterMap.find(j); // if (itTwo==allCounterMap.end()) { // std::cout<<" Pointer to coincidence counter ("< S T O P"<second; // (it->second)->SetCoincidenceCounter(itTwo->second,iChn); // } // // } // } // } // // // char tmpString1[100]="Unset",tmpString2[100]="Unset",tmpString3[100]="Unset"; // sscanf(&line[0],"%*s %s %s",tmpString1,tmpString2); } //================================================================ void musrAnalysis::CreateHistograms() { std::cout<<"musrAnalysis::CreateHistograms()"<pileupWindowMax)? 3*dataWindowMax: 3*pileupWindowMax; std::cout<<"musrAnalysis::CreateHistograms(): safeTimeWindow = "<GetEntry(1); InitialiseEvent(); Double_t fieldValue = fieldNomVal[0]; if (nFieldNomVal>1) fieldValue += fieldNomVal[1]; // omega = 851.372*fabs(fieldValue); // omega = 851.372*fieldValue; // value set originally in this program // omega = 850.62*fieldValue; // value used in Geant ? omega = 851.610*fieldValue; // value from the fits of the data hInfo->Fill(1, fieldValue); hInfo->Fill(6, runID); hInfo->Fill(7, hGeantParameters->GetBinContent(7)); std::cout<<"musrAnalysis::CreateHistograms(): fieldValue="<DrawTH1D("hist",0); // (*it)->DrawTH1D("hist",1); } for(std::list::const_iterator it = listOfAllHistograms2D.begin(); it != listOfAllHistograms2D.end(); ++it) { (*it)->DrawTH2DdrawList("hist"); } if(musrMode == 'D') { for (counterMapType::const_iterator it = pCounterMap.begin(); it!=pCounterMap.end(); ++it) { (it->second)->DrawTDChistogram(); } } if (humanDecayHistograms) { // humanDecayHistograms->FillHumanDecayArray(motherOfHumanDecayHistograms,indexHuman,nHumanDecayArray); humanDecayHistograms->FillHumanDecayArray(motherOfHumanDecayHistograms,humanDecayMap,humanDecayMultimap); humanDecayHistograms->DrawTH1DdrawList("text"); humanDecayPileupHistograms->FillHumanDecayArray(motherOfHumanDecayPileupHistograms,humanDecayMap,humanDecayMultimap); humanDecayPileupHistograms->DrawTH1DdrawList("text"); } // need to re-define these for Pulsed acquisition (and anything else) Long64_t numberOfMuonCandidates; Long64_t numberOfMuonCandidatesAfterVK; Long64_t numberOfMuonCandidatesAfterVKandDoubleHitRemoval; Double_t durationOfExperiment; if(musrMode=='D') { numberOfMuonCandidates = mCounter->GetNumberOfMuonCandidates(); numberOfMuonCandidatesAfterVK = mCounter->GetNumberOfMuonCandidatesAfterVK(); numberOfMuonCandidatesAfterVKandDoubleHitRemoval = mCounter->GetNumberOfMuonCandidatesAfterVKandDoubleHitRemoval(); durationOfExperiment = (numberOfRewinds*rewindTimeBins*tdcresolution+currentTime)/1000000; hInfo->Fill(5,(Double_t) numberOfMuonCandidates); // number of "triggers" hInfo->Fill(4,(Double_t) numberOfMuonCandidatesAfterVK); // number of "triggers" hInfo->Fill(3,durationOfExperiment); hInfo->Fill(8,(Double_t) numberOfMuonCandidatesAfterVKandDoubleHitRemoval); } //============================== // Write out the histograms std::cout<<"musrAnalysis::SaveHistograms()"<GetList()); while ( TObject *obj = next() ) { if (obj->InheritsFrom(TH1::Class()) ) {obj->Write();} } fHistograms->Close(); delete fHistograms; // if (musrCounter::bool_WriteDataToDumpFile==true) { // musrCounter::dumpFile.close(); // } if (musrCounter::bool_WriteDataToDumpFile) { if (myWriteDump!=NULL) { delete myWriteDump; } } // condition counts std::cout << "Number of times each condition was recorded" << std::endl; for(int i=0; i0) {std::cout<<"DEBUGEVENT "<lastPreprocessedEntry)||((nextUnfilledEventTime=nentries) && (nextUnfilledEventTimelastPreprocessedEntry)||(((nextUnfilledEventTime-currentTime)GetEntry(iiiEntry); InitialiseEvent(); if (bool_debugingRequired) { if (debugEventMap[eventID]>2) PrintHitsInAllCounters(); // if (debugEventMap[eventID]>1) {std::cout<<"DEBUGEVENT "<myPrintThisCounter(eventID); // } if (bool_debugingRequired) { if (debugEventMap[eventID]>1) {std::cout<<"DEBUGEVENT "<1) {std::cout<<"DEBUGEVENT "<1) {std::cout<<"____________________________________________________________________"<0)) { nextUnfilledEventTime=0.0; // std::cout << "resetting NextUnfilledEventTime"<::max()/2); if (currentTimeBin>rewindTimeBins) { // When the time variables start to be too large, rewind the time info everywhere; // RewindAllTimeInfo(rewindTimeBins); RewindAllTimeInfo(); } } } //================================================================ //void musrAnalysis::RemoveOldHitsFromCounters(Double_t timeLimit) { void musrAnalysis::RemoveOldHitsFromCounters(Long64_t timeBinLimit) { // Loop over all Counters and remove hits that happen at or before the "timeBinLimit". // std::cout<<"musrAnalysis::RemoveOldHitsFromCounters: timeBinLimit="<RemoveHitsInCounter(timeBinLimit); } } //================================================================ //void musrAnalysis::RewindAllTimeInfo(Double_t timeToRewind) { //void musrAnalysis::RewindAllTimeInfo(Long64_t timeBinsToRewind) { void musrAnalysis::RewindAllTimeInfo() { Long64_t timeBinsToRewind = rewindTimeBins; if (musrCounter::bool_WriteDataToDumpFile) { // Long64_t currentTimeBin = Long64_t(currentTime/tdcresolution); // mCounter->CheckClockInfo(currentTimeBin); mCounter->WriteRewindIntoDumpFile(); // musrCounter::previousClock -= timeBinsToRewind; } currentTime -= timeBinsToRewind*tdcresolution; nextUnfilledEventTime -= timeBinsToRewind*tdcresolution; numberOfRewinds++; // Loop over all timing information and rewind it by "timeToRewind"; // std::cout<<"musrAnalysis::RewindAllTimeInfo()"<RewindHitsInCounter(timeBinsToRewind); (*it).second->RewindHitsInCounter(); } } //================================================================ void musrAnalysis::PrintHitsInAllCounters() { // std::cout<<"___________________\n"; for (counterMapType::const_iterator it = allCounterMap.begin(); it!=allCounterMap.end(); ++it) { (*it).second->myPrintThisCounter(eventID,0); } } //================================================================ void musrAnalysis::FillHistograms(Int_t iiiEntry) { // std::cout<<"musrAnalysis::FillHistograms() event="< dataBinMax !!! pCounterHitExistsForThisEventID = PositronCounterHit(eventID,dataBinMin,dataBinMax,positronBinMax,timeBin1,timeBin2,timeBinDoubleHit,posEntry,idetP,idetP_ID,idetP_edep,pos_detID_doubleHit_INT); pos_detID = Double_t(idetP_ID); pos_detID_doubleHit = Double_t(pos_detID_doubleHit_INT); if (debugEventMap[eventID]>2) { if (pCounterHitExistsForThisEventID) {std::cout<<"FillHistograms: GOOD positron candidate found: timeBin1="< -1000; muonTriggered_gen_AND_muonDecayedInSample_gen = muonTriggered_gen && muonDecayedInSample_gen; muonTriggered_det = mCounterHitExistsForThisEventID; positronHit_det = pCounterHitExistsForThisEventID; goodEvent_det = muonTriggered_det && positronHit_det; goodEvent_gen = (muDecayTime>-999)&&(muM0Time>-999); goodEvent_det_AND_goodEvent_gen = goodEvent_det && goodEvent_gen; pileupEventCandidate = ((kEntry>0)&&(posEntry>0)&&(kEntry!=posEntry)) ? true:false; pileupEvent = pileupEventCandidate&&goodEvent_det; goodEvent_det_AND_muonDecayedInSample_gen = goodEvent_det && muonDecayedInSample_gen; // posCounterList_Iterator = find(F_posCounterList.begin(), F_posCounterList.end(), idetP_ID); // goodEvent_F_det = posCounterList_Iterator != F_posCounterList.end() goodEvent_F_det = goodEvent_det && ( (find(F_posCounterList.begin(), F_posCounterList.end(), idetP_ID)) != F_posCounterList.end() ); goodEvent_B_det = goodEvent_det && ( (find(B_posCounterList.begin(), B_posCounterList.end(), idetP_ID)) != B_posCounterList.end() ); goodEvent_U_det = goodEvent_det && ( (find(U_posCounterList.begin(), U_posCounterList.end(), idetP_ID)) != U_posCounterList.end() ); goodEvent_D_det = goodEvent_det && ( (find(D_posCounterList.begin(), D_posCounterList.end(), idetP_ID)) != D_posCounterList.end() ); goodEvent_L_det = goodEvent_det && ( (find(L_posCounterList.begin(), L_posCounterList.end(), idetP_ID)) != L_posCounterList.end() ); goodEvent_R_det = goodEvent_det && ( (find(R_posCounterList.begin(), R_posCounterList.end(), idetP_ID)) != R_posCounterList.end() ); // std::cout<<"goodEvent_F_det="<::const_iterator it = listOfAllHistograms1D.begin(); it != listOfAllHistograms1D.end(); ++it) { (*it)->FillTH1D(wght,&condition[0]); } for(std::list::const_iterator it = listOfAllHistograms2D.begin(); it != listOfAllHistograms2D.end(); ++it) { (*it)->FillTH2D(wght,&condition[0]); } if ((goodEvent_det)&&(pCounterHitExistsForThisEventID)) { // musrCounter* pCounterHitInThisEvent counterMapType::const_iterator itPcounterHitInThisEvent = pCounterMap.find(idetP_ID); if (itPcounterHitInThisEvent==pCounterMap.end()) { std::cout<<" ERROR! musrAnalysis: itPcounterHitInThisEvent not found ==> This should never happen!!!"< unrecordedEventMap; // unrecordedEventMap unrecordedEvents; // unrecordedEventMap::const_iterator it2; typedef std::multimap sortedByEventMap; sortedByEventMap sortedByEvent; sortedByEventMap::const_iterator it3; hitInfo* theEvent; // new improved // start with empty multimap of hits (key=entry num) // loop through counters // scan time order // "copy" events to map // initialise iterator into sorted map // loop through event numbers in range // if events to be processed then do them (1st=OnceOnly) // else do OnceOnly with no hit // // hitInfo needs PositronQuality field (filled in during GetNextGoodPositronPulsed() and timeBin1 ) // GetNextGoodPositronPulsed() now returns ptr to the hitInfo (or NULL)..? // std::cout << "starting FHP; map contents=" << sortedByEvent.size() << std::endl; for (counterMapType::const_iterator it = pCounterMap.begin(); it != pCounterMap.end(); ++it) { Long64_t dataBinMin = dataWindowBinMin; Long64_t dataBinMax = dataWindowBinMax; timeBin1 = -100000000; timeBin2 = -100000000; do { positronQuality = (it->second)->GetNextGoodPositronPulsed(iiiEntry1,iiiEntry2,dataBinMin,dataBinMax,timeBin1,timeBin2,posEntry,idetP,idetP_ID,idetP_edep,idetFirstMulti,theEvent); if(positronQuality != -1000) { // std::cout << "pushing event " << posEntry << " det " << idetP_ID << std::endl; sortedByEvent.insert(std::pair(posEntry,theEvent)); } } while (positronQuality != -1000); } it3=sortedByEvent.begin(); // std::cout << "now processing sorted list" << std:: endl; //for(Int_t i=iiiEntry1; i<=iiiEntry2; i++) { // unrecordedEvents.insert(std::pair(i,true)); //} // std::cout<<" FillHistograms: timeBinOfThePreviouslyProcessedHit = "<GetNextGoodHitInThisEvent(eventID,timeBinOfThePreviouslyProcessedHit,0,'M',timeBin0,kEntry,idetM,idetM_ID,idetM_edep,doubleHitM); // mCounterHitExistsForThisEventID = mCounter->GetNextGoodMuon(eventID,timeBinOfThePreviouslyProcessedHit,timeBin0,kEntry,idetM,idetM_ID,idetM_edep,doubleHitM); // mCounterHitExistsForThisEventID = MuonCounterHit(eventID,timeBinOfThePreviouslyProcessedHit,timeBin0,kEntry,idetM,idetM_ID,idetM_edep); // not needed (JSL) mCounterHitExistsForThisEventID = mCounter->GetNextGoodMuon(eventID,timeBinOfThePreviouslyProcessedHit,timeBin0,kEntry,idetM,idetM_ID,idetM_edep); // timeBinOfThePreviouslyProcessedHit = timeBin0; //___________________________________________________________ // loop through all good P counters and then one extra go with it==pCounterMap.end() to tidy up unrecorded events // for (counterMapType::const_iterator it = pCounterMap.begin(); ; ++it) { for(Int_t iec=iiiEntry1; iec<=iiiEntry2; iec++) { oncePerEvent=true; fChain->GetEntry(iec); InitialiseEvent(); // now opening each event once only and in order! (as well as once for inserting hits in counters) // positronQuality = (it->second)->GetNextGoodPositron(evID,dataBinMin,dataBinMax,tBin1,tBin2,kEntry,idetP,idetP_ID,idetP_edep); // std::cout<<" timeBin0 ="< dataBinMax !!! // GetNextGoodPositronPulsed(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) { while (oncePerEvent || positronQuality != -1000) { // does the next hit in sortedByEvent belong to this? if(it3!=sortedByEvent.end() && it3->first == iec) { positronQuality=it3->second->posQual; timeBin1=it3->second->timeBin1; timeBin2=it3->second->timeBin2; posEntry=it3->second->eventEntry; idetP=it3->second->det_i; idetP_ID=it3->second->det_id; idetP_edep=it3->second->det_edep; if(((it3->second)->multiHitCtr > 1) && (it3->second)->firstMulti) { idetFirstMulti = (it3->second)->firstMulti->det_i; } else { idetFirstMulti = -1000; // not a second or subsequent multi hit, or not recorded for some reason } // std::cout << "processing hit in det " << idetP_ID << " for event " << iec << std::endl; it3++; } else { if(!oncePerEvent) { // std::cout << "run out of hits for event " << iec << std::endl; break; } positronQuality=-1000; posEntry=iec; timeBin1=-100000000; timeBin2=-100000000; idetP=-1000; idetP_ID=-1000; idetP_edep=-1000; idetFirstMulti=-1000; // std::cout << "processing non-hit for event " << iec << std::endl; } // if(it == pCounterMap.end()) { // while((it2 != unrecordedEvents.end()) && (!it2->second)) { it2++; } // if(it2 == unrecordedEvents.end()) { break; } // positronQuality=-1000; // posEntry=it2->first; // timeBin1=-1000; // timeBin2=-1000; // idetP=-1000; // idetP_ID=-1000; // idetP_edep=-1000; // idetFirstMulti=-1000; // // std::cout << "found entry " << posEntry << " with no hits" << std::endl; // } else { // if((positronQuality = (it->second)->GetNextGoodPositronPulsed(iiiEntry1,iiiEntry2,dataBinMin,dataBinMax,timeBin1,timeBin2,posEntry,idetP,idetP_ID,idetP_edep,idetFirstMulti)) == -1000 ) { break; } // // std::cout << "found a hit in detector " << idetP_ID << " from event " << posEntry << " with quality=" << positronQuality << std::endl; // } // // std::cout << "searching entry " << iiiEntry << " and found a hit in detector " << idetP_ID << " with quality=" << positronQuality << std::endl; // fChain->GetEntry(posEntry); InitialiseEvent(); // oncePerEvent=unrecordedEvents[posEntry]; // unrecordedEvents[posEntry] = false; if (muTargetTime != -1000.0) { timeBin0 = Long64_t(muTargetTime / tdcresolution); } else { timeBin0=-100000000; } pos_detID = Double_t(idetP_ID); if (debugEventMap[eventID]>2) { std::cout<<"FillHistograms: GOOD positron candidate found: timeBin1="< -1000; // muonTriggered_gen_AND_muonDecayedInSample_gen = muonTriggered_gen && muonDecayedInSample_gen; // muonTriggered_det = mCounterHitExistsForThisEventID; // positronHit_det = pCounterHitExistsForThisEventID; goodEvent_det = (positronQuality >= -1); if(goodEvent_det) numberOfGoodMuons++; goodEvent_gen = (positronQuality== -3 || positronQuality== -2 || positronQuality==0 || positronQuality==1); goodEvent_det_AND_goodEvent_gen = goodEvent_det && goodEvent_gen; // pileupEventCandidate = ((kEntry>0)&&(posEntry>0)&&(kEntry!=posEntry)) ? true:false; // pileupEvent = pileupEventCandidate&&goodEvent_det; goodEvent_det_AND_muonDecayedInSample_gen = goodEvent_det && muonDecayedInSample_gen; // posCounterList_Iterator = find(F_posCounterList.begin(), F_posCounterList.end(), idetP_ID); // goodEvent_F_det = posCounterList_Iterator != F_posCounterList.end() Bool_t event_F = ( (find(F_posCounterList.begin(), F_posCounterList.end(), idetP_ID)) != F_posCounterList.end() ); Bool_t event_B = ( (find(B_posCounterList.begin(), B_posCounterList.end(), idetP_ID)) != B_posCounterList.end() ); Bool_t event_U = ( (find(U_posCounterList.begin(), U_posCounterList.end(), idetP_ID)) != U_posCounterList.end() ); Bool_t event_D = ( (find(D_posCounterList.begin(), D_posCounterList.end(), idetP_ID)) != D_posCounterList.end() ); Bool_t event_L = ( (find(L_posCounterList.begin(), L_posCounterList.end(), idetP_ID)) != L_posCounterList.end() ); Bool_t event_R = ( (find(R_posCounterList.begin(), R_posCounterList.end(), idetP_ID)) != R_posCounterList.end() ); bank_this = (event_F ? 1:0) + (event_B ? 2:0) + (event_U ? 3:0) + (event_D ? 4:0) + (event_L ? 5:0) + (event_R ? 6:0) ; if(idetFirstMulti >= 0) { det_multi_interval = det_time_start[idetP]-det_time_start[idetFirstMulti]; pos_detID_doubleHit = det_ID[idetFirstMulti]; // pos_doubleHit_dPhi: difference in detector phases between this and the first multi hit, plus 10*first-bank + 60*second-bank bank_multi = (( (find(F_posCounterList.begin(), F_posCounterList.end(), det_ID[idetFirstMulti])) != F_posCounterList.end() ) ? 1:0) + (( (find(B_posCounterList.begin(), B_posCounterList.end(), det_ID[idetFirstMulti])) != B_posCounterList.end() ) ? 2:0) + (( (find(U_posCounterList.begin(), U_posCounterList.end(), det_ID[idetFirstMulti])) != U_posCounterList.end() ) ? 3:0) + (( (find(D_posCounterList.begin(), D_posCounterList.end(), det_ID[idetFirstMulti])) != D_posCounterList.end() ) ? 4:0) + (( (find(L_posCounterList.begin(), L_posCounterList.end(), det_ID[idetFirstMulti])) != L_posCounterList.end() ) ? 5:0) + (( (find(R_posCounterList.begin(), R_posCounterList.end(), det_ID[idetFirstMulti])) != R_posCounterList.end() ) ? 6:0); pos_doubleHit_dPhi= deltaAngle(phaseShiftMap[det_ID[idetFirstMulti]]*180/pi,phaseShiftMap[idetP_ID]*180/pi) + bank_this*1000 + bank_multi*6000; } else { det_multi_interval = -1000; pos_detID_doubleHit = -1000; pos_doubleHit_dPhi= -1000; } goodEvent_F_det = goodEvent_det && event_F; goodEvent_B_det = goodEvent_det && event_B; goodEvent_U_det = goodEvent_det && event_U; goodEvent_D_det = goodEvent_det && event_D; goodEvent_L_det = goodEvent_det && event_L; goodEvent_R_det = goodEvent_det && event_R; // for better assignment of backgrounds versus useful signal goodEvent_F_det_AND_muonDecayedInSample_gen = goodEvent_F_det && muonDecayedInSample_gen; goodEvent_B_det_AND_muonDecayedInSample_gen = goodEvent_B_det && muonDecayedInSample_gen; goodEvent_U_det_AND_muonDecayedInSample_gen = goodEvent_U_det && muonDecayedInSample_gen; goodEvent_D_det_AND_muonDecayedInSample_gen = goodEvent_D_det && muonDecayedInSample_gen; goodEvent_L_det_AND_muonDecayedInSample_gen = goodEvent_L_det && muonDecayedInSample_gen; goodEvent_R_det_AND_muonDecayedInSample_gen = goodEvent_R_det && muonDecayedInSample_gen; // std::cout<<"goodEvent_F_det="<promptPeakWindowMin) && (det_time10 -1000 && positronQuality<=-2); // a good positron missed because of dead time goodEvent_F_det_AND_pileupEvent = pileupEvent && event_F; goodEvent_B_det_AND_pileupEvent = pileupEvent && event_B; goodEvent_U_det_AND_pileupEvent = pileupEvent && event_U; goodEvent_D_det_AND_pileupEvent = pileupEvent && event_D; goodEvent_L_det_AND_pileupEvent = pileupEvent && event_L; goodEvent_R_det_AND_pileupEvent = pileupEvent && event_R; doubleHitEvent_gen = (positronQuality>1 || (positronQuality>-1000 && positronQuality<-3)); // any double hits doubleHit = (positronQuality>1); // counted double hits only goodEvent_F_det_AND_doubleHit = doubleHit && event_F; goodEvent_B_det_AND_doubleHit = doubleHit && event_B; goodEvent_U_det_AND_doubleHit = doubleHit && event_U; goodEvent_D_det_AND_doubleHit = doubleHit && event_D; goodEvent_L_det_AND_doubleHit = doubleHit && event_L; goodEvent_R_det_AND_doubleHit = doubleHit && event_R; singleHitEvent_gen = (positronQuality==0); stackedEvent_gen = (positronQuality == -1); // if (bool_debugingRequired && muonTriggered_det) { // std::cout<<"DEBUG: goodEvent_det: eventID="<::const_iterator it = listOfAllHistograms1D.begin(); it != listOfAllHistograms1D.end(); ++it) { (*it)->FillTH1D(wght,&condition[0]); } for(std::list::const_iterator it = listOfAllHistograms2D.begin(); it != listOfAllHistograms2D.end(); ++it) { (*it)->FillTH2D(wght,&condition[0]); } // JSL don't plot the individual histograms - too many of them! // if ((goodEvent_det)&&(pCounterHitExistsForThisEventID)) { // musrCounter* pCounterHitInThisEvent // counterMapType::const_iterator itPcounterHitInThisEvent = pCounterMap.find(idetP_ID); // if (itPcounterHitInThisEvent==pCounterMap.end()) { // std::cout<<" ERROR! musrAnalysis: itPcounterHitInThisEvent not found ==> This should never happen!!!"<GetBranch("weight") ) ? weight : 1.; } //================================================================ Double_t musrAnalysis::PreprocessEvent(Long64_t iEn) { // std::cout<<"musrAnalysis::PreprocessEvent()"<GetEntry(iEn); InitialiseEvent(); // Clone some channels into different one, if requested by user // (This is usefull when e.g. user splits a signal from a veto // and uses it in two different ways - e.g. once for vetoing // muons, and second (with a different threshold) for validating // a positron candidate. This is initiated by the // keyword "CLONECHANNEL" in the *.v1190 file if (bool_clonedChannelsMultimap_NotEmpty) { // std::cout<<"det_n="< ret = clonedChannelsMultimap.equal_range(chNumTMP); for (clonedChannelsMultimapType::const_iterator ittt=ret.first; ittt!=ret.second; ++ittt) { // std::cout << " ittt->second=" << ittt->second; int chNumNewTMP = ittt->second; det_ID[det_n] = chNumNewTMP; det_edep[det_n] = det_edep[i]; det_edep_el[det_n] = det_edep_el[i]; det_edep_pos[det_n] = det_edep_pos[i]; det_edep_gam[det_n] = det_edep_gam[i]; det_edep_mup[det_n] = det_edep_mup[i]; det_nsteps[det_n] = det_nsteps[i]; det_length[det_n] = det_length[i]; det_time_start[det_n] = det_time_start[i]; det_time_end[det_n] = det_time_end[i]; det_x[det_n] = det_x[i]; det_y[det_n] = det_y[i]; det_z[det_n] = det_z[i]; det_kine[det_n] = det_kine[i]; det_VrtxKine[det_n] = det_VrtxKine[i]; det_VrtxX[det_n] = det_VrtxX[i]; det_VrtxY[det_n] = det_VrtxY[i]; det_VrtxZ[det_n] = det_VrtxZ[i]; det_VrtxVolID[det_n] = det_VrtxVolID[i]; det_VrtxProcID[det_n] = det_VrtxProcID[i]; det_VrtxTrackID[det_n] = det_VrtxTrackID[i]; det_VrtxParticleID[det_n]= det_VrtxParticleID[i]; det_VvvKine[det_n] = det_VvvKine[i]; det_VvvX[det_n] = det_VvvX[i]; det_VvvY[det_n] = det_VvvY[i]; det_VvvZ[det_n] = det_VvvZ[i]; det_VvvVolID[det_n] = det_VvvVolID[i]; det_VvvProcID[det_n] = det_VvvProcID[i]; det_VvvTrackID[det_n] = det_VvvTrackID[i]; det_VvvParticleID[det_n] = det_VvvParticleID[i]; det_n++; } } } } // std::cout<<"\n musrAnalysis::PreprocessEvent() Filling event "<(det_time_start[i],i)); } for(doubleHitSorterType::const_iterator dhi = doubleHitSorter.begin(); dhi != doubleHitSorter.end(); dhi++) { Int_t i=dhi->second; // // Int_t detID=det_ID[i]; std::map::iterator it; it = allCounterMap.find(det_ID[i]); if (it==allCounterMap.end()) { std::cout<<"Active detector with det_ID="<FillHitInCounter(det_edep[i],timeBin,timeBin2,iEn,eventID,i,det_ID[i],eventID, multiCtr); // std::cout << "pushed event into counter "<GetNextGoodMuon(evID,timeBinMin,timeBin0,kEntry,idet,idetID,idetEdep); // if (!mCounterHitCanditateExists) return false; // // Check for other muons within the pileup window: // if ( mCounter->CheckForPileupMuons(timeBin0,kEntry) ) return false; // This muon candidate is killed due to a double hit rejection. // return true; //} // //================================================================ Bool_t musrAnalysis::PositronCounterHit(Int_t evID, Long64_t dataBinMin, Long64_t dataBinMax, Long64_t positronBinMax, Long64_t& tBin1, Long64_t& tBin2, Long64_t& tBinDoubleHit, Int_t& kEntry, Int_t& idetP, Int_t& idetP_ID, Double_t& idetP_edep, Int_t& idetP_ID_doubleHit) { if (bool_debugingRequired) { if (debugEventMap[eventID]>4) {std::cout<<"PositronCounterHit: pCounterMap.size()="<second)->GetNextGoodPositron(evID,dataBinMin,dataBinMax,tBin1,tBin2,kEntry,idetP,idetP_ID,idetP_edep); positronQuality = (it->second)->GetNextGoodPositron(evID,dataBinMin,positronBinMax,tBin1,tBin2,kEntry,idetP,idetP_ID,idetP_edep); if (positronQuality==3) { // double hit was found in the same counter if (debugEventMap[eventID]>3) {std::cout<<"PositronCounterHit: positron candidate killed - double hit in the same counter"<3) {std::cout<<"PositronCounterHit: positron candidate killed - double hit in a different counter"<first; } std::cout<second); } std::cout<-1000.00001) ) return -1000.; if ( (x<-999.99999) && (x>-1000.00001) ) return -1000.; if ( (x==0) && (y==0) ) return -1000.; return atan2(y,x); } //================================================================ Double_t musrAnalysis::deltaAngle(Double_t alpha, Double_t beta) { // Calculates the difference between angle alpha and beta. // The angles alpha and beta are in degrees. // The difference will be in the range of (-180,180> degrees. if ((alpha<-998.)||(beta<-998.)) {return -1001.;} // one of the angles was undefined; Double_t delta = alpha - beta; if (delta<=-180) {delta+=360;} else {if (delta>180) delta-=360;} return delta; } //================================================================