#define musrAnalysis_cxx #include "musrAnalysis.hh" #include "musrTH.hh" //#include #include #include #include #include //#include 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; hInfo = new TH1D("hInfo","Different values that need to be passed to ploting program",10000,1.,10001.); ReadInInputParameters(v1190FileName); CreateHistograms(); nentries = fChain->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%100000==0) std::cout << "Analysing event nr. jentry=" << jentry << 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,1000,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"< 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 { 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="< 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,"rotFrameTime20")==0) { funct = new TF1("rotFrameTime20","[2]*exp(-x/2.19703)*cos(x*[0]+[1]) "); 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, 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.; sscanf(&line[0],"%d %s %s %g %d",&tmpChannel,tmpName,tmpType,&tmpThreshold,&tmpTimeShift); musrCounter* counter = new musrCounter(tmpChannel,tmpName,tmpType[0],tmpThreshold,tmpTimeShift); 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; //ckdel 20.9.2010 if ((maxChannels<=tmpChannel)||(maxChannels<=iCoinc)) { //ckdel 20.9.2010 std::cout<<" Channel number ("< S T O P"<(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)->GetCounterType(); if (DetectorType=='M') { (it->second)->SetMaxCoincidenceTimeWindow(pileupWindowBinMin); (it->second)->SetCoincidenceTimeWindow(pileupWindowBinMin,pileupWindowBinMax); (it->second)->SetCoincidenceTimeWindowOfAllCoincidenceDetectors(-mcoincwin,-mcoincwin,mcoincwin); } else if (DetectorType=='P') { (it->second)->SetMaxCoincidenceTimeWindow(dataWindowBinMin); (it->second)->SetCoincidenceTimeWindow(dataWindowBinMin,dataWindowBinMax); (it->second)->SetCoincidenceTimeWindowOfAllCoincidenceDetectors(-pcoincwin,-pcoincwin,pcoincwin); } else if (DetectorType=='V') { (it->second)->SetMaxCoincidenceTimeWindow(-vcoincwin); (it->second)->SetCoincidenceTimeWindow(-vcoincwin,vcoincwin); } int iChanNr = (it->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 (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); 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"); } 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"); } Long64_t numberOfMuonCandidates = mCounter->GetNumberOfMuonCandidates(); hInfo->Fill(5,(Double_t) numberOfMuonCandidates); // number of "triggers" //============================== // Write out the histograms std::cout<<"musrAnalysis::SaveHistograms()"<GetList()); while ( TObject *obj = next() ) { if (obj->InheritsFrom(TH1::Class()) ) {obj->Write();} } fHistograms->Close(); delete fHistograms; //============================== std::cout<<"==================================================================="<lastPreprocessedEntry)||(((nextUnfilledEventTime-currentTime)GetEntry(iiiEntry); InitialiseEvent(); // Loop over all interesting "moments", which are: // 1) any hit in the muon counter // 2) any new event (even if nothing was detected in the muon counter) Long64_t currentEventID = eventID; Double_t timeOfM0Hit; Long64_t evID; Bool_t thisEventAlreadyFilled = false; // std::cout<<"___________________\n"; // for (counterMapType::const_iterator it = allCounterMap.begin(); it!=allCounterMap.end(); ++it) { // (*it).second->myPrintThisCounter(eventID); // } FillHistograms(iiiEntry); currentTime+=timeToNextEvent*muonRateFactor; Long64_t currentTimeBin = Long64_t(currentTime/tdcresolution); if (!boolInfinitelyLowMuonRate) RemoveOldHitsFromCounters(currentTimeBin-1); // Remove all hits that can not influence the next event else RemoveOldHitsFromCounters(std::numeric_limits::max()/2); if (currentTimeBin>rewindTimeBins) { // When the time variables start to be too large, rewind the time info everywhere; RewindAllTimeInfo(rewindTimeBins); } } //================================================================ //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) { currentTime -= timeBinsToRewind*tdcresolution; nextUnfilledEventTime -= timeBinsToRewind*tdcresolution; numberOfRewinds++; // Loop over all timing information and rewind it by "timeToRewind"; // std::cout<<"musrAnalysis::RewindAllTimeInfo()"<RewindHitsInCounter(timeBinsToRewind); } } //================================================================ void musrAnalysis::FillHistograms(Int_t iiiEntry) { // std::cout<<"musrAnalysis::FillHistograms() event="<::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!!!"<GetBranch("weight") ) ? weight : 1.; } //================================================================ Double_t musrAnalysis::PreprocessEvent(Long64_t iEn) { // std::cout<<"musrAnalysis::PreprocessEvent()"<GetEntry(iEn); InitialiseEvent(); // std::cout<<"\n musrAnalysis::PreprocessEvent() Filling event "<::iterator it; it = allCounterMap.find(det_ID[i]); if (it==allCounterMap.end()) { // uncomment std::cout<<"Active detector with det_ID="<FillHitInCounter(det_edep[i],timeBin,timeBin2,iEn,eventID,i,det_ID[i]); } } // std::cout<<"lastPreprocessedEntry+1="<second)->GetNextGoodHitInThisEvent(evID,dataBinMin,dataBinMax,'P',tBin1,kEntry,idetP,idetP_ID,idetP_edep,doubleHit); Bool_t thereWasHit = (it->second)->GetNextGoodPositron(evID,dataBinMin,dataBinMax,tBin1,tBin2,kEntry,idetP,idetP_ID,idetP_edep,doubleHit); // std::cout<<"000000000000 tBin1="<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); }