69 #include "TObjString.h"
79 #include <ext/hash_map>
86 using namespace __gnu_cxx;
87 using __gnu_cxx::hash_map;
131 virtual void algoEndJob ()
override;
134 int statCollectionFromMode(
const char*
tag)
const;
135 void bookDQMHistos(
const char* dqm_dir,
const char* tag);
138 void swapBFieldMode(
void);
141 void algoAnalyzeTheTree();
142 void algoComputeMPVandGain();
145 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
146 bool IsGoodLandauFit(
double* FitResults);
148 void MakeCalibrationMap();
149 bool produceTagFilter();
226 unsigned int eventnumber =0;
266 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
270 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >
APVsColl;
276 std::vector<string>::const_iterator it=dqm_tag_.begin();
277 while(it!=dqm_tag_.end()) {
278 if(*it==
std::string(tag))
return it-dqm_tag_.begin();
288 if(A->GetNbinsX() == B->GetNbinsX()){
291 for(
int x=0;
x<=B->GetNbinsX()+1;
x++){
292 for(
int y=0;y<=B->GetNbinsY()+1; y++){
293 A->SetBinContent(
x,y,A->GetBinContent(
x,y)+B->GetBinContent(
x,y));
393 EventPrefix_ = evtinfo_pset.getUntrackedParameter<
string>(
"prefix");
394 EventSuffix_ = evtinfo_pset.getUntrackedParameter<
string>(
"suffix");
399 TrackPrefix_ = track_pset.getUntrackedParameter<
string>(
"prefix");
400 TrackSuffix_ = track_pset.getUntrackedParameter<
string>(
"suffix");
415 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Setting " << dqm_dir <<
"in DQM and booking histograms for tag "
418 if ( strcmp(booked_dir.c_str(),dqm_dir)!=0 ) {
419 booked_dir = dqm_dir;
420 dbe->setCurrentFolder(dqm_dir);
424 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
439 Charge_Vs_Index[elepos] =
dbe->book2S(cvi.c_str() , cvi.c_str() , 88625, 0 , 88624,2000,0,4000);
458 const char * dqm_dir =
"AlCaReco/SiStripGainsHarvesting/";
465 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: "
476 auto const &
Det = tkGeom->dets();
480 unsigned int Index=0;
481 for(
unsigned int i=0;
i<
Det.size();
i++){
489 if(!DetUnit)
continue;
492 unsigned int NAPV = Topo.
nstrips()/128;
494 for(
unsigned int j=0;
j<NAPV;
j++){
510 APV->
x = DetUnit->position().basicVector().x();
511 APV->
y = DetUnit->position().basicVector().y();
512 APV->
z = DetUnit->position().basicVector().z();
513 APV->
Eta = DetUnit->position().basicVector().eta();
514 APV->
Phi = DetUnit->position().basicVector().phi();
515 APV->
R = DetUnit->position().basicVector().transverse();
516 APV->
Thickness = DetUnit->surface().bounds().thickness();
528 for(
unsigned int i=0;
i<
Det.size();
i++){
533 if(!DetUnit)
continue;
536 unsigned int NROCRow = Topo.
nrows()/(80.);
537 unsigned int NROCCol = Topo.
ncolumns()/(52.);
539 for(
unsigned int j=0;
j<NROCRow;
j++){
540 for(
unsigned int i=0;
i<NROCCol;
i++){
555 APV->
x = DetUnit->position().basicVector().x();
556 APV->
y = DetUnit->position().basicVector().y();
557 APV->
z = DetUnit->position().basicVector().z();
558 APV->
Eta = DetUnit->position().basicVector().eta();
559 APV->
Phi = DetUnit->position().basicVector().phi();
560 APV->
R = DetUnit->position().basicVector().transverse();
561 APV->
Thickness = DetUnit->surface().bounds().thickness();
591 double average_current = runInfo.
product()->m_avg_current;
595 return ( (isOn && !is0T) || (!isOn && is0T) );
613 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: "
630 if(gainHandle->getNumberOfTags()!=2){
edm::LogError(
"SiStripGainFromCalibTree")<<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";fflush(stdout);
exit(0);};
631 float newPreviousGain = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 1),1);
635 float newPreviousGainTick = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 0),1);
656 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Starting harvesting statistics" << std::endl;
664 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
698 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvi.c_str()
699 <<
", statistics will not be summed!" << std::endl;
702 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Harvesting "
703 << (
Charge_Vs_Index[elepos])->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
712 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIB.c_str()
713 <<
", statistics will not be summed!" << std::endl;
717 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTOB.c_str()
718 <<
", statistics will not be summed!" << std::endl;
722 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDP.c_str()
723 <<
", statistics will not be summed!" << std::endl;
727 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDM.c_str()
728 <<
", statistics will not be summed!" << std::endl;
732 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP1.c_str()
733 <<
", statistics will not be summed!" << std::endl;
737 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP2.c_str()
738 <<
", statistics will not be summed!" << std::endl;
742 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM1.c_str()
743 <<
", statistics will not be summed!" << std::endl;
747 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM2.c_str()
748 <<
", statistics will not be summed!" << std::endl;
759 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Analyzing calibration tree" << std::endl;
771 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Saving summary into root file" << std::endl;
797 FitResults[0] = -0.5;
799 FitResults[2] = -0.5;
801 FitResults[4] = -0.5;
807 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
808 MyLandau->SetParameter(1,300);
809 InputHisto->Fit(MyLandau,
"0QR WW");
812 FitResults[0] = MyLandau->GetParameter(1);
813 FitResults[1] = MyLandau->GetParError(1);
814 FitResults[2] = MyLandau->GetParameter(2);
815 FitResults[3] = MyLandau->GetParError(2);
816 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
817 FitResults[5] = MyLandau->GetParameter(0);
823 if(FitResults[0] <= 0 )
return false;
843 unsigned int FirstAmplitude=0;
844 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
845 FirstAmplitude+=(*nstrips)[
i];
846 int TI = (*trackindex)[
i];
880 bool Saturation =
false;
881 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
882 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
886 if(StripCharge>1024){
889 }
else if(StripCharge>254){
893 Charge += StripCharge;
897 Charge = (*charge)[
i];
899 Charge = (*charge)[
i]/265.0;
904 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
906 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
923 }
else if(APV->
Eta>0){
936 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
938 TString tree_path = TString::Format(
"gainCalibrationTree%s/tree",
m_calibrationMode.c_str());
939 TTree*
tree =
dynamic_cast<TTree*
> (tfile->Get(tree_path.Data()));
970 unsigned int nentries = tree->GetEntries();
971 printf(
"Number of Events = %i + %i = %i\n",
NEvent,nentries,(
NEvent+nentries));
972 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
973 printf(
"Looping on the Tree :");
974 int TreeStep = nentries/50;
if(TreeStep<=1)TreeStep=1;
975 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
976 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
977 tree->GetEntry(ientry);
988 double FitResults[6];
989 double MPVmean = 300;
994 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not execute algoComputeMPVandGain method because "
996 <<
"Please check if input contains "
1004 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
1005 printf(
"Fitting Charge Distribution :");
1008 if(I%TreeStep==0){printf(
".");fflush(stdout);}
1010 if(APV->
Bin<0) APV->
Bin = chvsidx->GetXaxis()->FindBin(APV->
Index);
1014 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->
Index),chvsidx->GetXaxis()->FindBin(APV->
Index),
"e"));
1019 int SecondAPVId = APV->
APVId;
1020 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
1022 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1023 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1024 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1026 for(
unsigned int i=0;
i<16;
i++){
1027 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >::iterator tmpit;
1032 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1033 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1034 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1042 APV->
FitMPV = FitResults[0];
1048 APV->
NEntries = Proj->GetEntries();
1067 unsigned int tree_Index;
1068 unsigned int tree_Bin;
1069 unsigned int tree_DetId;
1070 unsigned char tree_APVId;
1071 unsigned char tree_SubDet;
1078 float tree_Thickness;
1080 float tree_FitMPVErr;
1081 float tree_FitWidth;
1082 float tree_FitWidthErr;
1083 float tree_FitChi2NDF;
1086 double tree_PrevGain;
1087 double tree_PrevGainTick;
1088 double tree_NEntries;
1092 MyTree = tfs->
make<TTree> (
"APVGain",
"APVGain");
1093 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
1094 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
1095 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
1096 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
1097 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
1098 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
1099 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
1100 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
1101 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
1102 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
1103 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
1104 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
1105 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
1106 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
1107 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
1108 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
1109 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
1110 MyTree->Branch(
"FitNorm" ,&tree_FitNorm ,
"FitNorm/F");
1111 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
1112 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
1113 MyTree->Branch(
"PrevGainTick" ,&tree_PrevGainTick,
"PrevGainTick/D");
1114 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
1115 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
1118 FILE* Gains = stdout;
1119 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1120 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1123 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1124 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1128 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1129 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1132 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1133 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1140 if(APV==
NULL)
continue;
1144 tree_Index = APV->
Index;
1146 tree_DetId = APV->
DetId;
1147 tree_APVId = APV->
APVId;
1148 tree_SubDet = APV->
SubDet;
1152 tree_Eta = APV->
Eta;
1154 tree_Phi = APV->
Phi;
1156 tree_FitMPV = APV->
FitMPV;
1160 tree_FitChi2NDF = APV->
FitChi2;
1162 tree_Gain = APV->
Gain;
1169 if(tree_DetId==402673324){
1170 printf(
"%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
1176 if(Gains)fclose(Gains);
1187 edm::LogError(
"SiStripGainFromCalibTree") <<
"produceTagFilter -> Return false: could not retrieve the "
1189 <<
"Please check if input contains "
1199 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << endl;
1205 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << endl;
1217 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << endl;
1223 std::vector<float>* theSiStripVector =
NULL;
1224 unsigned int PreviousDetId = 0;
1227 if(APV==
NULL){ printf(
"Bug\n");
continue; }
1228 if(APV->
SubDet<=2)
continue;
1229 if(APV->
DetId != PreviousDetId){
1230 if(theSiStripVector!=
NULL){
1232 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1234 theSiStripVector =
new std::vector<float>;
1235 PreviousDetId = APV->
DetId;
1237 theSiStripVector->push_back(APV->
Gain);
1239 if(theSiStripVector!=
NULL){
1241 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1255 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
1258 unsigned int tree_DetId;
1259 unsigned char tree_APVId;
1262 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
1263 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
1264 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
1266 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
1267 t1->GetEntry(ientry);
edm::EDGetTokenT< std::vector< int > > trackindex_token_
std::vector< MonitorElement * > Charge_Vs_Index
T getParameter(std::string const &) const
EventNumber_t event() const
void swapBFieldMode(void)
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
std::vector< string > dqm_tag_
const std::vector< float > * trackp
unsigned int MinTrackHits
edm::EDGetTokenT< std::vector< double > > tracketa_token_
edm::EDGetTokenT< std::vector< unsigned char > > amplitude_token_
const std::vector< double > * chargeoverpath
edm::EDGetTokenT< std::vector< unsigned int > > rawid_token_
const std::vector< unsigned char > * amplitude
bool isBFieldConsistentWithMode(const edm::EventSetup &iSetup) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
SiStripApvGain * getNewObject() override
virtual int ncolumns() const =0
const std::vector< double > * localdirz
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::vector< double > * trackchi2ndof
virtual void algoBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< double > * localdirx
~SiStripGainFromCalibTree()
dispatcher processEvent(e, inputTag, standby)
#define DEFINE_FWK_MODULE(type)
unsigned int NClusterPixel
virtual void algoEndRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< unsigned int > * rawid
edm::EDGetTokenT< std::vector< bool > > overlapping_token_
double tagCondition_GoodFrac
SiStripGainFromCalibTree(const edm::ParameterSet &)
edm::Handle< T > connect(const T *&ptr, edm::EDGetTokenT< T > token, const edm::Event &evt)
virtual int nrows() const =0
const std::vector< int > * trackalgo
std::vector< MonitorElement * > Charge_Vs_PathlengthTOB
void storeOnTree(TFileService *tfs)
T * make(const Args &...args) const
make new ROOT object
const std::vector< float > * trackpt
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM1
const std::vector< unsigned int > * trackhitsvalid
void MakeCalibrationMap()
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM2
double MaxTrackChiOverNdf
edm::EDGetTokenT< std::vector< bool > > farfromedge_token_
bool put(const uint32_t &detID, Range input)
uint32_t rawId() const
get the raw id
edm::EDGetTokenT< std::vector< unsigned int > > trackhitsvalid_token_
T x() const
Cartesian x coordinate.
std::vector< stAPVGain * > APVsCollOrdered
__gnu_cxx::hash_map< unsigned int, stAPVGain *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
edm::EDGetTokenT< std::vector< double > > path_token_
void algoComputeMPVandGain()
edm::EDGetTokenT< std::vector< int > > trackalgo_token_
edm::EDGetTokenT< std::vector< float > > trackp_token_
bool IsGoodLandauFit(double *FitResults)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void algoBeginJob(const edm::EventSetup &iSetup) override
std::pair< ContainerIterator, ContainerIterator > Range
edm::EDGetTokenT< std::vector< bool > > TrigTech_token_
edm::EDGetTokenT< std::vector< double > > chargeoverpath_token_
const std::complex< double > I
const std::vector< double > * gainused
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP1
edm::EDGetTokenT< std::vector< double > > localdirz_token_
const std::vector< unsigned short > * firststrip
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDM
const std::vector< double > * localdiry
edm::EDGetTokenT< std::vector< unsigned int > > charge_token_
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Integral< F, X >::type integral(const F &f)
vector< string > VInputFiles
virtual void algoEndJob() override
edm::EDGetTokenT< std::vector< unsigned short > > nstrips_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP2
const std::vector< int > * trackindex
int statCollectionFromMode(const char *tag) const
std::vector< MonitorElement * > Charge_Vs_PathlengthTIB
edm::EDGetTokenT< std::vector< unsigned short > > firststrip_token_
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< std::vector< float > > trackpt_token_
T const * product() const
const std::vector< bool > * overlapping
const std::vector< bool > * saturation
bool merge(LuminosityBlockRange &lh, LuminosityBlockRange &rh)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
T const * product() const
void algoAnalyzeTheTree()
const std::vector< bool > * farfromedge
const std::vector< bool > * TrigTech
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
double tagCondition_NClusters
edm::EDGetTokenT< std::vector< double > > localdirx_token_
edm::EDGetTokenT< std::vector< bool > > saturation_token_
edm::EDGetTokenT< std::vector< double > > trackchi2ndof_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDP
edm::EDGetTokenT< std::vector< double > > localdiry_token_
volatile std::atomic< bool > shutdown_flag false
const std::vector< unsigned int > * charge
const std::vector< double > * path
const std::vector< double > * trackphi
const std::vector< unsigned short > * nstrips
edm::EDGetTokenT< std::vector< double > > gainused_token_
void bookDQMHistos(const char *dqm_dir, const char *tag)
edm::EDGetTokenT< std::vector< double > > trackphi_token_
const std::vector< double > * tracketa
unsigned int NClusterStrip
void merge(TH2 *A, TH2 *B)