#include #include #include #include // COMET Include Files #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* This application creates hits from digits applying calibration. The digits can be taken from two sources: - From the root file directly, if they have been created previously. In this case no additional geometry file is required RunCalibGlobal.exe rootfile.root -o outputfile.root - From the digit factories after unpacking the input midas file. In this case an additional root file containing the geometry must be provided RunCalibGlobal.exe -G geometry.root -m midasfile -o outputfile.root Writting the digits to the output file is optional (-O D). I'm not sure it works. For MC we have added extra options to allow the digits to be dropped. The logic for saving MC digits is - if we have real data then save digits - if we have MC and fSaveDigitIFraction <= 0 then don't save digits. - otherwise, save digits for every fSaveDigitIFraction event. */ namespace { /// Check is this is simulated data. bool CheckMC(COMET::ICOMETContext context){ int partition = context.GetPartition(); // Check for MC partition; make sure it is not invalid. if(partition & COMET::ICOMETContext::kMCData && (unsigned int)partition != 0xdeadbeef ) return true; return false; } }; class IRunCalibGlobalLoop: public COMET::ICOMETEventLoopFunction { protected: public: IRunCalibGlobalLoop(); virtual ~IRunCalibGlobalLoop() {} bool operator () (COMET::ICOMETEvent& event); void BeginFile(COMET::IVInputFile* const input); void Initialize(void); bool SetOption(std::string option, std::string value=""); void Usage(); private: COMET::IUnpackOptionManager fUnpackOptMan; COMET::IParametersOptionManager fParOptMan; COMET::ITriggerFilter fTriggerFilter; bool fRunTpcCalib; bool fRunFgdCalib; bool fRunEcalCalib; bool fRunP0DCalib; bool fRunSmrdCalib; bool fRunIngridCalib; bool fRunTpcCalibForMC; bool fRunFgdCalibForMC; bool fRunEcalCalibForMC; bool fRunP0DCalibForMC; bool fRunSmrdCalibForMC; bool fRunIngridCalibForMC; /// This is the inverse fraction of events for which we want /// to save digits; ie, if fSaveDigitIFraction is 100, /// then we will save the digits for 1 in 100 events. /// This flag will be set from parameter file, if it is /// not overriden by command-line arguments int fSaveDigitIFraction; /// Also need to keep track of how many events we processed. int fNumberEvents; }; //************************************************* IRunCalibGlobalLoop::IRunCalibGlobalLoop() : fUnpackOptMan(), fParOptMan(), fTriggerFilter() { //************************************************* COMET::ICalibManager::Get(); // Set the default output level COMET::ICOMETLog::SetLogLevel("oaUnpack",COMET::ICOMETLog::QuietLevel); COMET::ICOMETLog::SetLogLevel("CalibGlobal", COMET::ICOMETLog::QuietLevel); fSaveDigitIFraction = COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.SaveDigitIFraction"); fNumberEvents = 0; } //************************************************* bool IRunCalibGlobalLoop::SetOption(std::string option, std::string value) { //************************************************* if (option == "v"){ int value2 = atoi(value.c_str()); if (value2 == 1) { COMET::ICOMETLog::SetLogLevel("CalibGlobal",COMET::ICOMETLog::LogLevel); } else if (value2 == 2) { COMET::ICOMETLog::SetLogLevel("CalibGlobal",COMET::ICOMETLog::InfoLevel); } else if (value2 >= 3) { COMET::ICOMETLog::SetLogLevel("CalibGlobal",COMET::ICOMETLog::VerboseLevel); } } else if (option == "vu"){ int value2 = atoi(value.c_str()); if (value2 == 1) { COMET::ICOMETLog::SetLogLevel("oaUnpack",COMET::ICOMETLog::LogLevel); } else if (value2 == 2) { COMET::ICOMETLog::SetLogLevel("oaUnpack",COMET::ICOMETLog::InfoLevel); } else if (value2 >= 3) { COMET::ICOMETLog::SetLogLevel("oaUnpack",COMET::ICOMETLog::VerboseLevel); } } else if (option == "D"){ COMET::IOADatabase::Get().Digits().PersistentDigits(); } else if (option == "save_all_digits"){ fSaveDigitIFraction = 1; } else if (option == "save_no_digits"){ fSaveDigitIFraction = -1; } else if (fParOptMan.IsRelevantOption(option)){ fParOptMan.UseRelevantOption(value); } //Forward any options we diddn't understand to the UnpackOptionManager else return fUnpackOptMan.SetOption(option, value); return true; } //************************************************* void IRunCalibGlobalLoop::Initialize(void){ //************************************************* // These flags determine whether to run calibration for a particular sub-detector (for real or sim data). fRunTpcCalib = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunTpcCalib"); fRunFgdCalib = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunFgdCalib"); fRunEcalCalib = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunEcalCalib"); fRunP0DCalib = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunP0DCalib"); fRunSmrdCalib = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunSmrdCalib"); fRunIngridCalib = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunIngridCalib"); // These flags determine whether to run calibration for a particular sub-detector for simulated data only. fRunTpcCalibForMC = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunTpcCalibForMC"); fRunFgdCalibForMC = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunFgdCalibForMC"); fRunEcalCalibForMC = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunEcalCalibForMC"); fRunP0DCalibForMC = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunP0DCalibForMC"); fRunSmrdCalibForMC = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunSmrdCalibForMC"); fRunIngridCalibForMC = (bool)COMET::IOARuntimeParameters::Get().GetParameterI("CalibGlobal.RunIngridCalibForMC"); // Check what we have defined for when to save MC digits. if(fSaveDigitIFraction == 1) COMETLog("CalibGlobal: will save all MC digits to output."); else if(fSaveDigitIFraction <= 0) COMETLog("CalibGlobal: will not save any MC digits to output."); else COMETLog("CalibGlobal: will save MC digits for 1 in " << fSaveDigitIFraction << " events."); return; } //************************************************* void IRunCalibGlobalLoop::BeginFile(COMET::IVInputFile* const){ //************************************************* // Add channel calibrators. This creates THits from TDigits // The TXXXChannelCalibrator needs the geometry file if(fRunTpcCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::ITPCChannelCalibrator()); if(fRunFgdCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::IFGDChannelCalibrator()); if(fRunEcalCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::IECalChannelCalibrator("ecal")); if(fRunP0DCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::ITFBChannelCalibrator("p0d")); if(fRunSmrdCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::ITFBChannelCalibrator("smrd")); if(fRunSmrdCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::ITFBChannelCalibrator("mrd")); if(fRunIngridCalib) COMET::ICalibManager::Get().AddCalibrator(new COMET::ITFBChannelCalibrator("ingrid")); //Get a new trigger filter for this file fTriggerFilter = fUnpackOptMan.GetTriggerFilter(); } //***************************************************************************** bool IRunCalibGlobalLoop::operator () (COMET::ICOMETEvent& event){ //***************************************************************************** if(COMET::ICOMETLog::GetLogLevel("CalibGlobal") >= COMET::ICOMETLog::LogLevel) std::cout << "event # " << event.GetContext().GetEvent() << std::endl; //Step straight over the event if it fails the filter if (fTriggerFilter.Skip(event)) return false; //Initialise the geometry for this event COMET::IOADatabase::Get().Geometry(); // Check if this is simulated data. bool isMC = CheckMC(event.GetContext()); // Now make a decision about whether to save digits for this event. // The logic for saving digits is // - if we have real data then save digits // - if we have MC and fSaveDigitIFraction <= 0 then don't save digits. // - otherwise, save digits for every fSaveDigitIFraction event. bool saveDigits = true; if(isMC){ if(fSaveDigitIFraction <= 0){ saveDigits = false; }else{ if(fNumberEvents%fSaveDigitIFraction == 0) saveDigits = true; else saveDigits = false; } } COMET::ICalibManager::Get().SetSaveDigit(saveDigits); // Decode (implicit) and create THits from TDigits. // Only do the calibration iff the following conditions are met // i) The flag fRun???Calib is true // AND // ii) The flag fRun???CalibForMC is true OR we are dealing with real data if(fRunTpcCalib && (fRunTpcCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("tpc"); if(fRunFgdCalib && (fRunFgdCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("fgd"); if(fRunEcalCalib && (fRunEcalCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("ecal"); if(fRunP0DCalib && (fRunP0DCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("p0d"); if(fRunSmrdCalib && (fRunSmrdCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("smrd"); if(fRunSmrdCalib && (fRunSmrdCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("mrd"); if(fRunIngridCalib && (fRunIngridCalibForMC || !isMC)) COMET::ICalibManager::Get().Calibrate("ingrid"); // Now erase the digits, if so desired. if(!saveDigits){ COMET::IHandle digits = event.Get("digits"); if (digits) { event.erase(digits); COMET::IDatum* h = COMET::GetPointer(digits); if (h) delete h; event.AddDatum(new COMET::IDataVector("digits", "Uncalibrated digit data")); } } fNumberEvents++; return true; } //********************************************************************** void IRunCalibGlobalLoop::Usage() //********************************************************************** { fParOptMan.Usage(); fUnpackOptMan.Usage(); return; } //********************************************** int main(int argc, char *argv[]) { //********************************************** IRunCalibGlobalLoop userCode; cometEventLoop(argc,argv,userCode); }